Moduleghc-10.0.0.20260917GHC2024
GHC.Core.Type
Main functions for manipulating types and type-related things
- 25 types
- 300 values
- Packageghc-10.0.0.20260917
- Exports329
- LanguageGHC2024
- LicenceBSD-3-Clause
- SourceType.hs
Main data types representing Types
21 declarationsTypes are any, but at least one, of:
- Boxed
Iff its representation is a pointer to an object on the GC'd heap. Operationally, heap objects can be entered as a means of evaluation.
- Lifted
Iff it has bottom as an element: An instance of a lifted type might diverge when evaluated. GHC Haskell's unboxed types are unlifted. An unboxed, but lifted type is not very useful. (Example: A byte-represented type, where evaluating 0xff computes the 12345678th collatz number modulo 0xff.) Only lifted types may be unified with a type variable.
- Algebraic
Iff it is a type with one or more constructors, whether declared with
dataor
newtype. An algebraic type is one that can be deconstructed with a case expression. There are algebraic types that are not lifted types, like unlifted data types or unboxed tuples.
- Data
Iff it is a type declared with
data, or a boxed tuple. There are also
unlifted
data types.
- Primitive
Iff it is a built-in type that can't be expressed in Haskell.
- Unlifted
Anything that isn't lifted is considered unlifted.
Currently, all primitive types are unlifted, but that's not necessarily
the case: for example, Int could be primitive.
Some primitive types are unboxed, such as Int#, whereas some are boxed
but unlifted (such as ByteArray#). The only primitive types that we
classify as algebraic are the unboxed tuples.
Some examples of type classifications that may make this a bit clearer are:
Type primitive boxed lifted algebraic
-----------------------------------------------------------------------------
Int# Yes No No No
ByteArray# Yes Yes No No
(# a, b #) Yes No No Yes
(# a | b #) Yes No No Yes
( a, b ) No Yes Yes Yes
[a] No Yes Yes Yes
A source type is a type that is a separate type as far as the type checker is concerned, but which has a more low-level representation as far as Core-to-Core passes and the rest of the back end is concerned.
You don't normally have to worry about this, as the utility functions in
this module will automatically convert a source into a representation type
if they are spotted, to the best of its abilities. If you don't want this
to happen, use the equivalent functions from the TcType module.
ForAllTyFlag
Is something required to appear in source Haskell (Required), permitted by request (Specified) (visible type application), or prohibited entirely from appearing in source Haskell (Inferred)? See Note [VarBndrs, ForAllTyBinders, TyConBinders, and visibility] in GHC.Core.TyCo.Rep
Constructors
Instances8Eq, Data, Ord, NFData, Binary, OutputableBndrFlag, …
Eq ForAllTyFlagDefined in ghc-10.0.0.20260917 · Language.Haskell.Syntax.SpecificityData ForAllTyFlagDefined in ghc-10.0.0.20260917 · Language.Haskell.Syntax.SpecificityOrd ForAllTyFlagDefined in ghc-10.0.0.20260917 · Language.Haskell.Syntax.SpecificityNFData ForAllTyFlagDefined in ghc-10.0.0.20260917 · GHC.Hs.Specificity · orphanOutputable ForAllTyFlagDefined in ghc-10.0.0.20260917 · GHC.Hs.Specificity · orphanBinary ForAllTyFlagDefined in ghc-10.0.0.20260917 · GHC.Hs.Specificity · orphanOutputableBndrFlag ForAllTyFlag pDefined in ghc-10.0.0.20260917 · GHC.Hs.TypeOutputable tv => Outputable (VarBndr tv ForAllTyFlag)Defined in ghc-10.0.0.20260917 · GHC.Types.Var
The non-dependent version of ForAllTyFlag. See Note [FunTyFlag] Appears here partly so that it's together with its friends ForAllTyFlag and ForallVisFlag, but also because it is used in IfaceType, rather early in the compilation chain
Instances6Eq, Data, Ord, NFData, Outputable, Binary
Eq FunTyFlagDefined in ghc-10.0.0.20260917 · GHC.Types.VarData FunTyFlagDefined in ghc-10.0.0.20260917 · GHC.Types.VarOrd FunTyFlagDefined in ghc-10.0.0.20260917 · GHC.Types.VarNFData FunTyFlagDefined in ghc-10.0.0.20260917 · GHC.Types.VarOutputable FunTyFlagDefined in ghc-10.0.0.20260917 · GHC.Types.VarBinary FunTyFlagDefined in ghc-10.0.0.20260917 · GHC.Types.Var
Whether an Invisible argument may appear in source Haskell.
Constructors
InferredSpecthe argument may not appear in source Haskell, it is only inferred.
SpecifiedSpecthe argument may appear in source Haskell, but isn't required.
Instances10Eq, Data, Ord, NFData, Binary, OutputableBndrFlag, …
Eq SpecificityDefined in ghc-10.0.0.20260917 · Language.Haskell.Syntax.SpecificityData SpecificityDefined in ghc-10.0.0.20260917 · Language.Haskell.Syntax.SpecificityOrd SpecificityDefined in ghc-10.0.0.20260917 · Language.Haskell.Syntax.SpecificityNFData SpecificityDefined in ghc-10.0.0.20260917 · GHC.Hs.Specificity · orphanBinary SpecificityDefined in ghc-10.0.0.20260917 · GHC.Hs.Specificity · orphanOutputableBndrFlag Specificity pDefined in ghc-10.0.0.20260917 · GHC.Hs.TypeRepTV Specificity SpecificityDefined in ghc-10.0.0.20260917 · GHC.HsToCore.QuoteReifyFlag Specificity SpecificityDefined in ghc-10.0.0.20260917 · GHC.Tc.Gen.SpliceCvtFlag Specificity SpecificityDefined in ghc-10.0.0.20260917 · GHC.ThToHsOutputable tv => Outputable (VarBndr tv Specificity)Defined in ghc-10.0.0.20260917 · GHC.Types.Var
The key representation of types within the compiler
A type of the form p of constraint kind represents a value whose type is
the Haskell predicate p, where a predicate is what occurs before
the => in a Haskell type.
We use PredType as documentation to mark those types that we guarantee to have this kind.
It can be expanded into its representation, but:
The type checker must treat it as opaque
The rest of the compiler treats it as transparent
Consider these examples:
f :: (Eq a) => a -> Int
g :: (?x :: Int -> Int) => a -> Int
h :: (r\l) => {r} => {l::Int | r}Here the Eq a and ?x :: Int -> Int and rl are all called "predicates"
A collection of PredTypes
Instances15Data, Ord, NamedThing, Outputable, Uniquable, HasOccName, …
Eq VarDefined in ghc-10.0.0.20260917 · GHC.Types.VarData VarDefined in ghc-10.0.0.20260917 · GHC.Types.VarOrd VarDefined in ghc-10.0.0.20260917 · GHC.Types.VarNamedThing VarDefined in ghc-10.0.0.20260917 · GHC.Types.VarOutputable VarDefined in ghc-10.0.0.20260917 · GHC.Types.VarUniquable VarDefined in ghc-10.0.0.20260917 · GHC.Types.VarOutputableBndr VarDefined in ghc-10.0.0.20260917 · GHC.Core.Ppr · orphanHasOccName VarDefined in ghc-10.0.0.20260917 · GHC.Types.VarModifyState IdDefined in ghc-10.0.0.20260917 · GHC.Iface.Ext.AstEq (DeBruijn CoreAlt)Defined in ghc-10.0.0.20260917 · GHC.Core.Map.Expr · orphanEq (DeBruijn CoreExpr)Defined in ghc-10.0.0.20260917 · GHC.Core.Map.Expr · orphanEq (DeBruijn Var)Defined in ghc-10.0.0.20260917 · GHC.Core.Map.TypeToHie (Context (Located Var))Defined in ghc-10.0.0.20260917 · GHC.Iface.Ext.AstOutputableBndr (Id, TagSig)Defined in ghc-10.0.0.20260917 · GHC.Stg.EnforceEpt.TagSigtype Anno Id = SrcSpanAnnNDefined in ghc-10.0.0.20260917 · GHC.Hs.Extension · orphan
Type or kind Variable
Is this a type-level (i.e., computationally irrelevant, thus erasable)
variable? Satisfies isTyVar = not . isId.
Type or Coercion Variable
A PiTyBinder represents an argument to a function. PiTyBinders can be dependent (Named) or nondependent (Anon). They may also be visible or not. See Note [PiTyBinders]
Instances2Data, Outputable
Data PiTyBinderDefined in ghc-10.0.0.20260917 · GHC.Types.VarOutputable PiTyBinderDefined in ghc-10.0.0.20260917 · GHC.Types.Var
Variable Binder
A ForAllTyBinder is the binder of a ForAllTy It's convenient to define this synonym here rather its natural home in GHC.Core.TyCo.Rep, because it's used in GHC.Core.DataCon.hs-boot See Note [VarBndrs, ForAllTyBinders, TyConBinders, and visibility]
A TyVarBinder is a binder with only TyVar
Mult is a type alias for Type.
Mult must contain Type because multiplicity variables are mere type variables (of kind Multiplicity) in Haskell. So the simplest implementation is to make Mult be Type.
Multiplicities can be formed with: - One: GHC.Types.One (= oneDataCon) - Many: GHC.Types.Many (= manyDataCon) - Multiplication: GHC.Types.MultMul (= multMulTyCon)
So that Mult feels a bit more structured, we provide pattern synonyms and smart constructors for these.
A shorthand for data with an attached Mult element (the multiplicity).
Instances2Data, Outputable
Data a => Data (Scaled a)Defined in ghc-10.0.0.20260917 · GHC.Core.TyCo.RepOutputable a => Outputable (Scaled a)Defined in ghc-10.0.0.20260917 · GHC.Core.TyCo.Rep
A type labeled KnotTied might have knot-tied tycons in it. See Note [Type checking recursive type and class declarations] in GHC.Tc.TyCl
Type synonym used for types of kind RuntimeRep.
Constructing and deconstructing types
Attempts to obtain the type variable underlying a Type, and panics with the given message if this is not a type variable type. See also getTyVar_maybe
Attempts to obtain the type variable underlying a Type
Attempts to obtain the type variable underlying a Type, without any expansion
If the type is a tyvar, possibly under a cast, returns it, along with the coercion. Thus, the co is :: kind tv ~N kind ty
The type or kind of the Var in question
Applies a type to another, as in e.g. k a
Attempts to take a type application apart, as in splitAppTy_maybe, and panics if this is not possible
Recursively splits a type as far as is possible, leaving a residual type being applied to and the type arguments applied to it. Never fails, even if that means returning an empty list of type applications.
Like splitAppTys, but doesn't look through type synonyms
Attempt to take a type application apart, whether it is a function, type constructor, or plain type application. Note that type family applications are NEVER unsaturated by this!
Does the AppTy split as in splitAppTy_maybe, but assumes that any coreView stuff is already done.
Just like splitAppTyNoView_maybe, but does not split (c => t).
See Note [Decomposing fat arrow c=>t]
Make nested arrow types | Special, common, case: Arrow type with mult Many
Attempts to extract the multiplicity, argument and result types from a type, and panics if that is not possible. See also splitFunTy_maybe
Attempts to extract the multiplicity, argument and result types from a type
Works on visible function types only (t1 -> t2), and returns t1 and t2, but not the multiplicity
Extract the function result type and panic if that is not possible
Extract the function argument type and panic if that is not possible
Just like piResultTys but for a single argument Try not to iterate piResultTy, because it's inefficient to substitute one variable at a time; instead use 'piResultTys"
Given the components of a FunTy figure out the corresponding TyConApp.
Return Just if this TyConApp should be represented as a FunTy
Return Just if this TyConAppCo should be represented as a FunCo
This one works out the FunTyFlag from the argument type See GHC.Types.Var Note [FunTyFlag]
Like mkFunctionType, compute the FunTyFlag from the arguments
See GHC.Types.Var Note [FunTyFlag]
(mkTyConTy tc) returns (TyConApp tc []) but arranges to share that TyConApp among all calls See Note [Sharing nullary TyConApps] So it's just an alias for tyConNullaryTy!
The same as fst . splitTyConApp
We can short-cut the FunTy case
Retrieve the tycon heading this type, if there is one. Does not look through synonyms.
The same as snd . splitTyConApp
Attempts to tease a type apart into a type constructor and the application of a number of arguments to that constructor
Attempts to tease a type apart into a type constructor and the application of a number of arguments to that constructor. Panics if that is not possible. See also splitTyConApp_maybe
tcSplitTyConApp_maybe splits a type constructor application into its type constructor and applied types.
Differs from splitTyConApp_maybe in that it does *not* split types headed with (=>), as that's not a TyCon in the type-checker.
Note that this may fail (in funTyConAppTy_maybe) in the case
of a FunTy with an argument of unknown kind FunTy
(e.g. `FunTy (a :: k) Int`, since the kind of a isn't of
the form `TYPE rep`. This isn't usually a problem but may
be temporarily the case during canonicalization:
see Note [Decomposing FunTy] in GHC.Tc.Solver.Equality
and Note [The Purely Kinded Type Invariant (PKTI)] in GHC.Tc.Gen.HsType,
Wrinkle around FunTy
Consequently, you may need to zonk your type before using this function.
Like mkTyCoForAllTy, but does not check the occurrence of the binder
See Note [Unused coercion variable in ForAllTy]
Wraps foralls over the type using the provided TyCoVars from left to right
Wraps foralls over the type using the provided InvisTVBinders from left to right
Like mkForAllTys, but assumes all variables are dependent and Inferred, a common case
Like mkForAllTy, but assumes the variable is dependent and Specified, a common case
Like mkForAllTys, but assumes all variables are dependent and Specified, a common case
Like mkForAllTys, but assumes all variables are dependent and visible
Make a dependent forall over a TyCoVar
Make a dependent forall over a TyCoVar
Make a dependent forall over an Inferred variable
Like mkTyCoInvForAllTy, but tv should be a tyvar
Like mkTyCoInvForAllTys, but tvs should be a list of tyvar
Take a ForAllTy apart, returning the list of tycovars and the result type. This always succeeds, even if it returns only an empty list. Note that the result type returned may have free variables that were bound by a forall.
Like splitForAllTyCoVars, but split only for tyvars. This always succeeds, even if it returns only an empty list. Note that the result type returned may have free variables that were bound by a forall.
Like splitForAllTyCoVars, but only splits ForAllTys with Required type
variable binders. Furthermore, each returned tyvar is annotated with ().
Like splitForAllTyCoVars, but only splits ForAllTys with Invisible type variable binders. Furthermore, each returned tyvar is annotated with its Specificity.
Take a ForAllTy apart, returning the binders and result type
Attempts to take a ForAllTy apart, returning the full ForAllTyBinder
Attempts to take a ForAllTy apart, returning the Var
Take a forall type apart, or panics if that is not possible.
Attempts to take a ForAllTy apart, but only if the binder is a TyVar
Like splitForAllTyCoVar_maybe, but only returns Just if it is a covar binder.
Attempts to take a forall type apart; works with proper foralls and functions
Takes a forall type apart, or panics
Split off all PiTyBinders to a type, splitting both proper foralls and functions
Extracts a list of run-time arguments from a function type, looking through newtypes to the right of arrows.
Examples:
newtype Identity a = I a
getRuntimeArgTys (Int -> Bool -> Double) == [(Int, FTF_T_T), (Bool, FTF_T_T)]
getRuntimeArgTys (Identity Int -> Bool -> Double) == [(Identity Int, FTF_T_T), (Bool, FTF_T_T)]
getRuntimeArgTys (Int -> Identity (Bool -> Identity Double)) == [(Int, FTF_T_T), (Bool, FTF_T_T)]
getRuntimeArgTys (forall a. Show a => Identity a -> a -> Int -> Bool)
== [(Show a, FTF_C_T), (Identity a, FTF_T_T),(a, FTF_T_T),(Int, FTF_T_T)]
Note that, in the last case, the returned types might mention an out-of-scope type variable. This function is used only when we really care about the kinds of the returned types, so this is OK.
*Warning**: this function can return an infinite list. For example:
newtype N a = MkN (a -> N a)
getRuntimeArgTys (N a) == repeat (a, FTF_T_T)
mkTyConBindersPreferAnon :: [TyVar]binders
-> TyCoVarSetfree variables of result
-> [TyConBinder]
Given a list of type-level vars and the free vars of a result kind, makes PiTyBinders, preferring anonymous binders if the variable is, in fact, not dependent. e.g. mkTyConBindersPreferAnon (k:*),(b:k),(c:k) We want (k:*) Named, (b:k) Anon, (c:k) Anon
All non-coercion binders are visible.
(piResultTys f_ty [ty1, .., tyn]) gives the type of (f ty1 .. tyn)
where f :: f_ty
piResultTys is interesting because:
1. f_ty may have more for-alls than there are args
2. Less obviously, it may have fewer for-alls
For case 2. think of:
piResultTys (forall a.a) [forall b.b, Int]
This really can happen, but only (I think) in situations involving
undefined. For example:
undefined :: forall a. a
Term: undefined (forall b. b->b) Int
This term should have type (Int -> Int), but notice that
there are more type args than foralls in undefineds type.
Drops all ForAllTys
Given a family instance TyCon and its arg types, return the corresponding family type. E.g:
data family T a
data instance T (Maybe b) = MkT bWhere the instance tycon is :RTL, so:
mkFamilyTyConApp :RTL Int = T (Maybe Int)Is this a numeric literal. We also look through type synonyms.
Is this a symbol literal. We also look through type synonyms.
Is this a char literal? We also look through type synonyms.
Is this a type literal (symbol, numeric, or char)?
Extract the RuntimeRep classifier of a type. For instance,
getRuntimeRep_maybe Int = LiftedRep. Panics if this is not possible.
(splitRuntimeRep_maybe rr) takes a Type rr :: RuntimeRep, and
returns the (TyCon,[Type]) for the RuntimeRep, if possible, where
the TyCon is one of the promoted DataCons of RuntimeRep.
Remember: the unique on TyCon that is a a promoted DataCon is the
same as the unique on the DataCon
See Note [Promoted data constructors] in GHC.Core.TyCon
May not be possible if rr is a type variable or type
family application
Given a kind (TYPE rr) or (CONSTRAINT rr), extract its RuntimeRep classifier rr.
For example, kindRep_maybe * = Just LiftedRep
Returns Nothing if the kind is not of form (TYPE rr)
Extract the RuntimeRep classifier of a type from its kind. For example,
kindRep * = LiftedRep; Panics if this is not possible.
Treats * and Constraint as the same
Extract the Levity of a type. For example, getLevity Int = Lifted,
or getLevity (Array# Int) = Unlifted.
Panics if this is not possible. Does not look through type family applications.
levityType_maybe takes a Type of kind Levity, and returns its levity May not be possible for a type variable or type family application
Make a CastTy. The Coercion must be nominal. Checks the
Coercion for reflexivity, dropping it if it's reflexive.
See Note [Respecting definitional equality] in GHC.Core.TyCo.Rep
A type of kind ErrorMessage (from the GHC.TypeError module).
Render a type corresponding to a user type error into a SDoc.
Get the type on the LHS of a coercion induced by a type/data family instance.
Like splitPiTys, but returns only *invisible* binders, including constraints. Stops at the first visible binder.
Same as splitInvisPiTys, but stop when
- you have found n PiTyBinders,
- or you run out of invisible binders
Given a list of things paired with their visibilities, partition the things into (invisible things, visible things).
Given a TyCon and a list of argument types to which the TyCon is applied, determine each argument's visibility (Inferred, Specified, or Required).
Wrinkle: consider the following scenario:
T :: forall k. k -> k
tyConForAllTyFlags T [forall m. m -> m -> m, S, R, Q]After substituting, we get
T (forall m. m -> m -> m) :: (forall m. m -> m -> m) -> forall n. n -> n -> nThus, the first argument is invisible, S is visible, R is invisible again,
and Q is visible.
Given a Type and a list of argument types to which the Type is applied, determine each argument's visibility (Inferred, Specified, or Required).
Most of the time, the arguments will be Required, but not always. Consider
f :: forall a. a -> Type. In f Type Bool, the first argument (Type) is
Specified and the second argument (Bool) is Required. It is precisely
this sort of higher-rank situation in which appTyForAllTyFlags comes in handy,
since f Type Bool would be represented in Core using AppTys.
(See also #15792).
Analyzing types
This describes how a "map" operation over a type/coercion should behave
Constructors
TyCoMappertcm_tyvar :: env -> TyVar -> m Typetcm_covar :: env -> CoVar -> m Coerciontcm_hole :: env -> CoercionHole -> m CoercionWhat to do with coercion holes. See Note [Coercion holes] in GHC.Core.TyCo.Rep.
tcm_tycobinder :: forall r. env -> TyCoVar -> ForAllTyFlag -> (env -> TyCoVar -> m r) -> m rThe returned env is used in the extended scope
tcm_tycon :: TyCon -> m TyConThis is used only for TcTyCons a) To zonk TcTyCons b) To turn TcTyCons into TyCons. See Note [Type checking recursive type and class declarations] in GHC.Tc.TyCl
Constructors
TyCoFoldertcf_view :: Type -> Maybe Typetcf_tyvar :: TyVar -> atcf_covar :: CoVar -> atcf_hole :: CoercionHole -> aWhat to do with coercion holes. See Note [Coercion holes] in GHC.Core.TyCo.Rep.
tcf_tycobinder :: TyCoVar -> a -> aThe returned env is used in the extended scope
A view function that looks through nothing.
Unwrap one layer of newtype on a type constructor and its
arguments, using an eta-reduced version of the newtype if possible.
This requires tys to have at least newTyConInstArity tycon elements.
Binders
Make a named binder
Make many named binders
Make a named binder
var should be a type variable
Make many named binders Input vars should be type variables
Does this binder bind a variable that is not erased? Returns True for anonymous binders.
Extract a relevant type, if there is one.
Does this ForAllTyFlag classify an argument that is written in Haskell?
Does this ForAllTyFlag classify an argument that is not written in Haskell?
Does this binder bind a visible argument?
Does this binder bind an invisible argument?
Predicates on types
Is this type a function type (e.g. X -> Y or X => Y),
after expanding type synonyms?
Note:
Does not look through newtypes, so isFunTy is False for
IO (), despite the latter being operationally a function (after expanding newtypes).Does not reduce type family applications, so isFunTy is False for
Id (Int -> Bool)(where Id is the identity type family).Does not consider
ForAllTyto be a function type (even when the argument is a required argument), nor does it look through foralls. Hence both isFunTy is False for bothforall b. Show b => b -> band forforall a -> Int.
See also mightBeFunTy, when you want to know whether something could
be a function (taking a value argument) at runtime.
Checks whether this is a proper forall (with a named binder)
Like isForAllTy, but returns True only if it is a tyvar binder
Like isForAllTy, but returns True only if it is a covar binder
Like isForAllTy, but returns True only if it is an inferred tyvar binder
Is this type a FunTy or a ForAllTy, after expanding type synonyms?
Does not look through newtypes nor reduce type family applications.
Determine whether a type could be the type of a join point of given total
arity, according to the polymorphism rule. A join point cannot be polymorphic
in its return type, since given
join j a b x y z = e1 in e2,
the types of e1 and e2 must be the same, and a and b are not in scope for e2.
(See Note [The polymorphism rule of join points] in GHC.Core.) Returns False
also if the type simply doesn't have enough arguments.
Note that we need to know how many arguments (type *and* value) the putative join point takes; for instance, if j :: forall a. a -> Int then j could be a binary join point returning an Int, but it could *not* be a unary join point returning a -> Int.
TODO: See Note [Excess polymorphism and join points]
tyConAppNeedsKindSig :: BoolShould specified binders count towards injective positions in the kind of the TyCon? (If you're using visible kind applications, then you want True here.)
-> TyCon-> IntThe number of args the TyCon is applied to.
-> BoolDoes
T t_1 ... t_nneed a kind signature? (Wherenis the number of arguments)
Does a TyCon (that is applied to some number of arguments) need to be
ascribed with an explicit kind signature to resolve ambiguity if rendered as
a source-syntax type?
(See Note [When does a tycon application need an explicit kind signature?]
for a full explanation of what this function checks for.)
Space-saving construction
8 declarationsGiven a RuntimeRep, applies TYPE to it.
On the fly it rewrites
TYPE LiftedRep --> liftedTypeKind (a synonym)
TYPE UnliftedRep --> unliftedTypeKind (ditto)
TYPE ZeroBitRep --> zeroBitTypeKind (ditto)
NB: no need to check for TYPE (BoxedRep Lifted), TYPE (BoxedRep Unlifted)
because those inner types should already have been rewritten
to LiftedRep and UnliftedRep respectively, by mkTyConApp
see Note [TYPE and CONSTRAINT] in GHC.Builtin.Types.Prim. See Note [Using synonyms to compress types] in GHC.Core.Type
Just like mkTYPEapp
Just like mkTYPEapp_maybe
Given a `[RuntimeRep]`, apply TupleRep to it
On the fly, rewrite
TupleRep [] -> zeroBitRepTy (a synonym)
See Note [TYPE and CONSTRAINT] in GHC.Builtin.Types.Prim.
See Note [Using synonyms to compress types] in GHC.Core.Type
Levity and boxity
Returns True if the argument is (lifted) Type or Constraint See Note [TYPE and CONSTRAINT] in GHC.Builtin.Types.Prim
Returns True if the kind classifies unlifted types (like Int#) and False
otherwise. Note that this returns False for representation-polymorphic
kinds, which may be specialized to a kind that classifies unlifted types.
Check whether a type of kind RuntimeRep is lifted.
True of
LiftedRep :: RuntimeRepFalse of type variables, type family applications, and of other reps such as
IntRep :: RuntimeRep.
Check whether a type of kind RuntimeRep is unlifted.
True of definitely unlifted RuntimeReps such as
UnliftedRep, IntRep, FloatRep, ...False of
LiftedRep,False for type variables and type family applications.
Check whether a type (usually of kind RuntimeRep) is lifted, unlifted, or unknown. Returns Nothing if the type isn't of kind RuntimeRep.
`runtimeRepLevity_maybe rr` returns:
See isBoxedRuntimeRep_maybe.
Is the given type definitely unlifted?
See Type#type_classification for what an unlifted type is.
Panics on representation-polymorphic types; See mightBeUnliftedType for a more approximate predicate that behaves better in the presence of representation polymorphism.
See Type#type_classification for what a boxed type is.
Panics on representation-polymorphic types; See mightBeUnliftedType for
a more approximate predicate that behaves better in the presence of
representation polymorphism.
See Type#type_classification for what an algebraic type is.
Should only be applied to types, as opposed to e.g. partially
saturated type constructors
Check whether a type is a data family type
Returns true of types that are opaque to Haskell.
Computes whether an argument (or let right hand side) should be computed strictly or lazily, based only on its type. Currently, it's just isUnliftedType. Panics on representation-polymorphic types.
True = a term of this type cannot be bottom This identifies the types described by Note [NON-BOTTOM-DICTS invariant] in GHC.Core NB: unlifted types are not terminating types! e.g. you can write a term (loop 1)::Int# that diverges.
Is this the type Levity?
Is a tyvar of type Levity?
Is this the type RuntimeRep?
Is a tyvar of type RuntimeRep?
Is this a type of kind RuntimeRep? (e.g. LiftedRep)
Drops prefix of RuntimeRep constructors in TyConApps. Useful for e.g. dropping 'LiftedRep arguments of unboxed tuple TyCon applications:
dropRuntimeRepArgs [ 'LiftedRep, 'IntRep , String, Int# ] == [String, Int#]
Multiplicity
13 declarationsIs this the type Multiplicity?
Is a tyvar of type Multiplicity?
Scale a payload by Many
Scale a payload by One
Scale a payload by Many; used for type arguments in core
Main data types representing Kinds
1 declarationThe key type representing kinds in the compiler.
Finding the kind of a type
Returns True if a type has a syntactically fixed runtime rep, as per Note [Fixed RuntimeRep] in GHC.Tc.Utils.Concrete.
This function is equivalent to `isFixedRuntimeRepKind . typeKind` but much faster.
Precondition: The type has kind (TYPE blah)
Is this kind equivalent to Type i.e. TYPE LiftedRep?
Is this kind equivalent to TYPE (BoxedRep l) for some l :: Levity?
Is this kind equivalent to TYPE r (for some unknown r)?
This considers Constraint to be distinct from *.
Common Kind
Type free variables
12 declarationstyCoVarsOfTypeDSet that returns deep free variables of a type in a deterministic set. For explanation of why using VarSet is not deterministic see Note [Deterministic FV] in GHC.Types.Var.FV.
Expand out all type synonyms. Actually, it'd suffice to expand out just the ones that discard type variables (e.g. type Funny a = Int) But we don't know which those are currently, so we just expand all.
expandTypeSynonyms only expands out type synonyms mentioned in the type, not in the kinds of any TyCon or TyVar mentioned in the type.
Keep this synchronized with synonymTyConsOfType
expandSynTyConApp_maybe tc tys expands the RHS of type synonym tc
instantiated at arguments tys, or returns Nothing if tc is not a
synonym.
Closing over kinds
Add the kind variables free in the kinds of the tyvars in the given set. Returns a deterministic set.
Forcing evaluation of types
2 declarationsOther views onto Types
4 declarationsThis function strips off the top layer only of a type synonym application (if any) its underlying representation type. Returns Nothing if there is nothing to look through.
This function does not look through type family applications.
By being non-recursive and inlined, this case analysis gets efficiently joined onto the case analysis that the caller is already doing
Iterates coreView until there is no more to synonym to expand. NB: coreFullView is non-recursive and can be inlined; core_full_view is the recursive one See Note [Inlining coreView].
All type constructors occurring in the type; looking through type synonyms, but not newtypes. When it finds a Class, it returns the class TyCon.
Main type substitution data types
3 declarationsA substitution of Exprs for non-coercion Ids
Type & coercion & id substitution
The Subst data type defined in this module contains substitution
for tyvar, covar and id. However, operations on IdSubstEnv (mapping
from Id to CoreExpr) that require the definition of the Expr
data type are defined in GHC.Core.Subst to avoid circular module
dependency.
Constructors
Instances1Outputable
Outputable SubstDefined in ghc-10.0.0.20260917 · GHC.Core.TyCo.Subst
Manipulating type substitutions
Generates the in-scope set for the Subst from the types in the incoming environment. No CoVars or Ids, please!
Generates the in-scope set for the TCvSubst from the types in the
incoming environment. No CoVars, please! The InScopeSet is just a thunk
so with a bit of luck it'll never be evaluated
Remove all substitutions that might have been built up while preserving the in-scope set originally called zapSubstEnv
Find the in-scope set: see Note [The substitution invariant]
Returns the deep free variables of the types in the range of a substitution as a non-deterministic set.
Add the Var to the in-scope set
Add the Vars to the in-scope set: see also extendInScope
Add the Vars to the in-scope set: see also extendInScope
Adds multiple TyVar substitutions to the Subst: see also extendTvSubst
Composes two substitutions, applying the second one provided first, like in function composition. This function leaves IdSubstEnv untouched because IdSubstEnv is not used during substitution for types.
The InScopeSet is just a thunk so with a bit of luck it'll never be evaluated
Checks whether the tyvar and covar environments are empty. This function should be used over isEmptySubst when substituting for types, because types currently do not contain expressions; we can safely disregard the expression environment when deciding whether to skip a substitution. Using isEmptyTCvSubst gives us a non-trivial performance boost (up to 70% less allocation for T18223)
Performing substitution on types and kinds
Substitute within a Type The substitution has to satisfy the invariants described in Note [The substitution invariant].
Substitute within several Types The substitution has to satisfy the invariants described in Note [The substitution invariant].
Type substitution, see zipTvSubst
Type substitution, see zipTvSubst
Substitute within a ThetaType The substitution has to satisfy the invariants described in Note [The substitution invariant].
Substitute within a Type after adding the free variables of the type to the in-scope set. This is useful for the case when the free variables aren't already in the in-scope set or easily available. See also Note [The substitution invariant].
Substitute within a Type disabling the sanity checks. The problems that the sanity checks in substTy catch are described in Note [The substitution invariant]. The goal of #11371 is to migrate all the calls of substTyUnchecked to substTy and remove this function. Please don't use in new code.
Substitute within several Types disabling the sanity checks. The problems that the sanity checks in substTys catch are described in Note [The substitution invariant]. The goal of #11371 is to migrate all the calls of substTysUnchecked to substTys and remove this function. Please don't use in new code.
Substitute within a ThetaType disabling the sanity checks. The problems that the sanity checks in substTys catch are described in Note [The substitution invariant]. The goal of #11371 is to migrate all the calls of substThetaUnchecked to substTheta and remove this function. Please don't use in new code.
Type substitution, see zipTvSubst. Disables sanity checks. The problems that the sanity checks in substTy catch are described in Note [The substitution invariant]. The goal of #11371 is to migrate all the calls of substTyUnchecked to substTy and remove this function. Please don't use in new code.
Substitute within a Coercion The substitution has to satisfy the invariants described in Note [The substitution invariant].
Coercion substitution, see zipTvSubst
Kinds
3 declarationsDoes this classify a type allowed to have values? Responds True to things like *, TYPE Lifted, TYPE IntRep, TYPE v, Constraint.
True of a kind `TYPE _` or `CONSTRAINT _`
Tests whether the given type is concrete, i.e. it whether it consists only of concrete type constructors, concrete type variables, and applications.
See Note [Concrete types] in GHC.Tc.Utils.Concrete.
Checks that a kind of the form Type, Constraint
or 'TYPE r is concrete. See isConcreteType.
Precondition: The type has kind `TYPE blah` or `CONSTRAINT blah`