ghc-lib-parser-9.14.1.20251220: The GHC API, decoupled from GHC versions

Safe Haskell | Ignore
Language | GHC2021

GHC.Core.Predicate

Contents

- Well-scoped free variables

Synopsis

- data Pred
  - = ClassPred Class [Type]
  - | EqPred EqRel Type Type
  - | IrredPred PredType
  - | ForAllPred [TyVar] [PredType] PredType
- classifyPredType :: HasDebugCallStack => PredType -> Pred
- isPredTy :: Type -> Bool
- isSimplePredTy :: HasDebugCallStack => Type -> Bool
- data EqRel
  - = NomEq
  - | ReprEq
- eqRelRole :: EqRel -> Role
- isEqPred :: PredType -> Bool
- isReprEqPred :: PredType -> Bool
- isEqClassPred :: PredType -> Bool
- isCoVarType :: Type -> Bool
- getEqPredTys :: PredType -> (Type, Type)
- getEqPredTys_maybe :: PredType -> Maybe (Role, Type, Type)
- getEqPredRole :: PredType -> Role
- predTypeEqRel :: PredType -> EqRel
- pprPredType :: PredType -> SDoc
- mkNomEqPred :: Type -> Type -> Type
- mkReprEqPred :: Type -> Type -> Type
- mkEqPred :: EqRel -> Type -> Type -> PredType
- mkEqPredRole :: Role -> Type -> Type -> PredType
- mkClassPred :: Class -> [Type] -> PredType
- isDictTy :: Type -> Bool
- typeDeterminesValue :: PredType -> Bool
- isClassPred :: PredType -> Bool
- isEqualityClass :: Class -> Bool
- isCTupleClass :: Class -> Bool
- isUnaryClass :: Class -> Bool
- getClassPredTys :: HasDebugCallStack => PredType -> (Class, [Type])
- getClassPredTys_maybe :: PredType -> Maybe (Class, [Type])
- classMethodTy :: Id -> Type
- classMethodInstTy :: Id -> [Type] -> Type
- couldBeIPLike :: Type -> Bool
- mightMentionIP :: (Type -> Bool) -> (Type -> Bool) -> Class -> [Type] -> Bool
- isIPTyCon :: TyCon -> Bool
- isIPClass :: Class -> Bool
- decomposeIPPred :: Type -> (Id, [Type])
- isCallStackTy :: Type -> Bool
- isCallStackPred :: Class -> [Type] -> Maybe FastString
- isCallStackPredTy :: Type -> Bool
- isExceptionContextPred :: Class -> [Type] -> Maybe FastString
- isExceptionContextTy :: Type -> Bool
- isIPPred_maybe :: Class -> [Type] -> Maybe (Type, Type)
- type DictId = EvId
- isEvId :: Var -> Bool
- isDictId :: Id -> Bool
- scopedSort :: [Var] -> [Var]
- tyCoVarsOfTypeWellScoped :: Type -> [TyVar]
- tyCoVarsOfTypesWellScoped :: [Type] -> [TyVar]
- data CanEqLHS
  - = TyVarLHS TyVar
  - | TyFamLHS TyCon [Type]
- canEqLHS_maybe :: Type -> Maybe CanEqLHS
- canTyFamEqLHS_maybe :: Type -> Maybe CanEqLHS
- canEqLHSKind :: CanEqLHS -> Kind
- canEqLHSType :: CanEqLHS -> Type
- eqCanEqLHS :: CanEqLHS -> CanEqLHS -> Bool

# Documentation

data Pred #

A predicate in the solver. The solver tries to prove Wanted predicates from Given ones.

Constructors

ClassPred Class [Type] | A typeclass predicate.
EqPred EqRel Type Type | A type equality predicate, (t1 ~#N t2) or (t1 ~#R t2)
IrredPred PredType | An irreducible predicate.
ForAllPred [TyVar] [PredType] PredType | A quantified predicate. See Note [Quantified constraints] in GHC.Tc.Solver.Solve

classifyPredType :: HasDebugCallStack => PredType -> Pred #

isPredTy :: Type -> Bool #

isSimplePredTy :: HasDebugCallStack => Type -> Bool #

data EqRel #

A choice of equality relation. This is separate from the type `Role` because `Phantom` does not define a (non-trivial) equality relation.

Constructors

NomEq |
ReprEq |

#### Instances

Instances details

Outputable EqRel # |
Instance details Defined in GHC.Core.Predicate Methods ppr :: EqRel -> SDoc #
Eq EqRel # |
Instance details Defined in GHC.Core.Predicate Methods (==) :: EqRel -> EqRel -> Bool # (/=) :: EqRel -> EqRel -> Bool #
Ord EqRel # |
Instance details Defined in GHC.Core.Predicate Methods compare :: EqRel -> EqRel -> Ordering # (<) :: EqRel -> EqRel -> Bool # (<=) :: EqRel -> EqRel -> Bool # (>) :: EqRel -> EqRel -> Bool # (>=) :: EqRel -> EqRel -> Bool # max :: EqRel -> EqRel -> EqRel # min :: EqRel -> EqRel -> EqRel #

eqRelRole :: EqRel -> Role #

isEqPred :: PredType -> Bool #

Does this type classify a core (unlifted) Coercion? At either role nominal or representational (t1 ~# t2) or (t1 ~R# t2) See Note [Types for coercions, predicates, and evidence] in GHC.Core.TyCo.Rep

isReprEqPred :: PredType -> Bool #

isEqClassPred :: PredType -> Bool #

isCoVarType :: Type -> Bool #

getEqPredTys :: PredType -> (Type, Type) #

getEqPredTys_maybe :: PredType -> Maybe (Role, Type, Type) #

getEqPredRole :: PredType -> Role #

predTypeEqRel :: PredType -> EqRel #

Get the equality relation relevant for a pred type Returns NomEq for dictionary predicates, etc

pprPredType :: PredType -> SDoc #

mkNomEqPred :: Type -> Type -> Type #

Creates a primitive nominal type equality predicate. t1 ~# t2 Invariant: the types are not Coercions

mkReprEqPred :: Type -> Type -> Type #

Creates a primitive representational type equality predicate. t1 ~R# t2 Invariant: the types are not Coercions

mkEqPred :: EqRel -> Type -> Type -> PredType #

Makes a lifted equality predicate at the given role

mkEqPredRole :: Role -> Type -> Type -> PredType #

Makes a lifted equality predicate at the given role

mkClassPred :: Class -> [Type] -> PredType #

isDictTy :: Type -> Bool #

typeDeterminesValue :: PredType -> Bool #

Is the type *guaranteed* to determine the value? Might say No even if the type does determine the value. See Note [Type determines value]

isClassPred :: PredType -> Bool #

isEqualityClass :: Class -> Bool #

isCTupleClass :: Class -> Bool #

isUnaryClass :: Class -> Bool #

getClassPredTys :: HasDebugCallStack => PredType -> (Class, [Type]) #

getClassPredTys_maybe :: PredType -> Maybe (Class, [Type]) #

classMethodTy :: Id -> Type #

classMethodInstTy :: Id -> [Type] -> Type #

couldBeIPLike :: Type -> Bool #

mightMentionIP #

Arguments

:: (Type -> Bool) | predicate on the string
-> (Type -> Bool) | predicate on the type
-> Class |
-> [Type] |
-> Bool |

``mightMentionIP` str_cond ty_cond cls tys` returns `True` if:

- `cls tys` is of the form `IP str ty`, where `str_cond str` and `ty_cond ty` are both `True`,
- or any superclass of `cls tys` has this property.

See Note [Local implicit parameters]

isIPTyCon :: TyCon -> Bool #

isIPClass :: Class -> Bool #

decomposeIPPred :: Type -> (Id, [Type]) #

Take a type (IP sym ty), where IP is the built in IP class and return (ip, MkIP, [sym,ty]), where `ip` is the class-op for class IP `MkIP` is the data constructor for class IP

isCallStackTy :: Type -> Bool #

Is a type a `CallStack`?

isCallStackPred :: Class -> [Type] -> Maybe FastString #

Is a `PredType` a `CallStack` implicit parameter?

If so, return the name of the parameter.

isCallStackPredTy :: Type -> Bool #

isExceptionContextPred :: Class -> [Type] -> Maybe FastString #

Is a `PredType` an `ExceptionContext` implicit parameter?

If so, return the name of the parameter.

isExceptionContextTy :: Type -> Bool #

Is a type an `ExceptionContext`?

isIPPred_maybe :: Class -> [Type] -> Maybe (Type, Type) #

Decomposes a predicate if it is an implicit parameter. Does not look in superclasses. See also [Local implicit parameters].

type DictId = EvId #

Dictionary Identifier

isEvId :: Var -> Bool #

isDictId :: Id -> Bool #

# Well-scoped free variables

scopedSort :: [Var] -> [Var] #

Do a topological sort on a list of tyvars, so that binders occur before occurrences E.g. given `[ a::k, k::Type, b::k ]` it'll return a well-scoped list `[ k::Type, a::k, b::k ]`.

This is a deterministic sorting operation (that is, doesn't depend on Uniques).

It is also meant to be stable: that is, variables should not be reordered unnecessarily. This is specified in Note [ScopedSort] See also Note [Ordering of implicit variables] in GHC.Rename.HsType

tyCoVarsOfTypeWellScoped :: Type -> [TyVar] #

Get the free vars of a type in scoped order

tyCoVarsOfTypesWellScoped :: [Type] -> [TyVar] #

Get the free vars of types in scoped order

data CanEqLHS #

A `CanEqLHS` is a type that can appear on the left of a canonical equality: a type variable or exactly-saturated type family application.

Constructors

TyVarLHS TyVar |
TyFamLHS |

Fields

- TyCon

  TyCon of the family

- [Type]

  Arguments, exactly saturating the family

#### Instances

Instances details

Outputable CanEqLHS # |
Instance details Defined in GHC.Core.Predicate Methods ppr :: CanEqLHS -> SDoc #

canEqLHS_maybe :: Type -> Maybe CanEqLHS #

Is a type a canonical LHS? That is, is it a tyvar or an exactly-saturated type family application? Does not look through type synonyms.

canTyFamEqLHS_maybe :: Type -> Maybe CanEqLHS #

canEqLHSKind :: CanEqLHS -> Kind #

Retrieve the kind of a `CanEqLHS`

canEqLHSType :: CanEqLHS -> Type #

Convert a `CanEqLHS` back into a `Type`

eqCanEqLHS :: CanEqLHS -> CanEqLHS -> Bool #

Are two `CanEqLHS`s equal?