HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleghc-9.10.3GHC2021

GHC.Plugins

This module is not used by GHC itself. Rather, it exports all of the functions and types you are likely to need when writing a plugin for GHC. So authors of plugins can probably get away simply with saying "import GHC.Plugins".

Particularly interesting modules for plugin writers include GHC.Core and GHC.Core.Opt.Monad.

  • 79 types
  • 4 classes
  • 1017 values
  • Packageghc-9.10.3
  • Exports1104
  • LanguageGHC2021
  • LicenceBSD-3-Clause
  • SourcePlugins.hs
datadata OccName
#

Occurrence Name

In this context that means: "classified (i.e. as a type name, value name, etc) but not qualified and not yet resolved"

Instances8Eq, Data, Ord, NFData, Outputable, Binary, …
classclass HasOccName name where
#

Other names in the compiler add additional information to an OccName. This class provides a consistent way to access the underlying OccName.

Methods

Instances12HasOccName, …
valueisSymOcc :: OccName -> Bool
#

Test if the OccName is that for any operator (whether it is a data constructor or variable or whatever)

valuenonDetFoldOccEnv :: (a -> b -> b) -> b -> OccEnv a -> b
#

Fold over an OccEnv. Non-deterministic, unless the folding function is commutative (i.e. a1 f ( a2 f b ) == a2 f ( a1 f b ) for all a1, a2, b).

typetype FastStringEnv a = UniqFM FastString a
#

A non-deterministic set of FastStrings. See Note [Deterministic UniqFM] in GHC.Types.Unique.DFM for explanation why it's not deterministic and why it matters. Use DFastStringEnv if the set eventually gets converted into a list or folded over in a way where the order changes the generated code.

Test for definitions internally generated by GHC. This predicate is used to suppress printing of internal definitions in some debug prints

valueisValOcc :: OccName -> Bool
#

Value OccNamess are those that are either in the variable, field name or data constructor namespaces

valuemkDFunOcc
  1. :: String

    Typically the class and type glommed together e.g. OrdMaybe. Only used in debug mode, for extra clarity

  2. -> Bool

    Is this a hs-boot instance DFun?

  3. -> OccSet

    avoid these Occs

  4. -> OccName

    E.g. $f3OrdMaybe

#
valuemkInstTyTcOcc
  1. :: String

    Family name, e.g. Map

  2. -> OccSet

    avoid these Occs

  3. -> OccName
    R:Map
#

Derive a name for the representation type constructor of a data/newtype instance.

valuemkOccEnv_C
  1. :: (a -> a -> a)

    old -> new -> result

  2. -> [(OccName, a)]
  3. -> OccEnv a
#

Create an OccEnv from a list, combining different values with the same OccName using the combining function.

Haskell 98 encourages compilers to suppress warnings about unused names in a pattern if they start with _: this implements that test

datadata Name
#

A unique, unambiguous name for something, containing information about where that thing originated.

Instances14Eq, Data, Ord, NFData, NamedThing, Outputable, …
classclass NamedThing a where
#

A class allowing convenient access to the Name of various datatypes

Methods

Instances20NamedThing, …
datadata OccName
#

Occurrence Name

In this context that means: "classified (i.e. as a type name, value name, etc) but not qualified and not yet resolved"

Instances8Eq, Data, Ord, NFData, Outputable, Binary, …
classclass HasOccName name where
#

Other names in the compiler add additional information to an OccName. This class provides a consistent way to access the underlying OccName.

Methods

Instances12HasOccName, …
valueisSymOcc :: OccName -> Bool
#

Test if the OccName is that for any operator (whether it is a data constructor or variable or whatever)

valuenonDetFoldOccEnv :: (a -> b -> b) -> b -> OccEnv a -> b
#

Fold over an OccEnv. Non-deterministic, unless the folding function is commutative (i.e. a1 f ( a2 f b ) == a2 f ( a1 f b ) for all a1, a2, b).

typetype FastStringEnv a = UniqFM FastString a
#

A non-deterministic set of FastStrings. See Note [Deterministic UniqFM] in GHC.Types.Unique.DFM for explanation why it's not deterministic and why it matters. Use DFastStringEnv if the set eventually gets converted into a list or folded over in a way where the order changes the generated code.

Test for definitions internally generated by GHC. This predicate is used to suppress printing of internal definitions in some debug prints

valueisValOcc :: OccName -> Bool
#

Value OccNamess are those that are either in the variable, field name or data constructor namespaces

valuemkDFunOcc
  1. :: String

    Typically the class and type glommed together e.g. OrdMaybe. Only used in debug mode, for extra clarity

  2. -> Bool

    Is this a hs-boot instance DFun?

  3. -> OccSet

    avoid these Occs

  4. -> OccName

    E.g. $f3OrdMaybe

#
valuemkInstTyTcOcc
  1. :: String

    Family name, e.g. Map

  2. -> OccSet

    avoid these Occs

  3. -> OccName
    R:Map
#

Derive a name for the representation type constructor of a data/newtype instance.

valuemkOccEnv_C
  1. :: (a -> a -> a)

    old -> new -> result

  2. -> [(OccName, a)]
  3. -> OccEnv a
#

Create an OccEnv from a list, combining different values with the same OccName using the combining function.

Haskell 98 encourages compilers to suppress warnings about unused names in a pattern if they start with _: this implements that test

valuenameIsLocalOrFrom :: Module -> Name -> Bool
#

Returns True if the name is (a) Internal (b) External but from the specified module (c) External but from the interactive package

The key idea is that False means: the entity is defined in some other module you can find the details (type, fixity, instances) in some interface file those details will be stored in the EPT or HPT

True means: the entity is defined in this module or earlier in the GHCi session you can find details (type, fixity, instances) in the TcGblEnv or TcLclEnv

The isInteractiveModule part is because successive interactions of a GHCi session each give rise to a fresh module (Ghci1, Ghci2, etc), but they all come from the magic interactive package; and all the details are kept in the TcLclEnv, TcGblEnv, NOT in the HPT or EPT. See Note [The interactive package] in GHC.Runtime.Context

valuenameStableString :: Name -> String
#

Get a string representation of a Name that's unique and stable across recompilations. Used for deterministic generation of binds for derived instances. eg. "$aeson_70dylHtv1FFGeai1IoxcQr$Data.Aeson.Types.Internal$String"

valuepprTickyName :: Module -> Name -> SDoc
#

Print a ticky ticky styled name

Module argument is the module to use for internal and system names. When printing the name in a ticky profile, the module name is included even for local things. However, ticky uses the format "x (M)" rather than "M.x". Hence, this function provides a separation from normal styling.

valuestableNameCmp :: Name -> Name -> Ordering
#

Compare Names lexicographically This only works for Names that originate in the source code or have been tidied.

datadata Var
#

Variable

Essentially a typed Name, that may also contain some additional information about the Var and its use sites.

Instances15Data, Ord, NamedThing, Outputable, Uniquable, HasOccName, …
typetype Id = Var
#

Identifier

valueisImplicitId :: Id -> Bool
#

isImplicitId tells whether an Ids info is implied by other declarations, so we don't need to put its signature in an interface file, even if it's mentioned in some other interface unfolding.

valueisId :: Var -> Bool
#

Is this a value-level (i.e., computationally relevant) Identifier? Satisfies isId = not . isTyVar.

valuehasNoBinding :: Id -> Bool
#

Returns True of an Id which may not have a binding, even though it is defined in this module.

valueidDataCon :: Id -> DataCon
#

Get from either the worker or the wrapper Id to the DataCon. Currently used only in the desugarer.

INVARIANT: idDataCon (dataConWrapId d) = d: remember, dataConWrapId can return either the wrapper or the worker

valueidFunRepArity :: Id -> RepArity
#

This function counts all arguments post-unarisation, which includes arguments with no runtime representation -- see Note [Unarisation and arity]

valueisStrictId :: Id -> Bool
#

isStrictId says whether either (a) the Id has a strict demand placed on it or (b) definitely has a "strict type", such that it can always be evaluated strictly (i.e an unlifted type) We need to check (b) as well as (a), because when the demand for the given id hasn't been computed yet but id has a strict type, we still want `isStrictId id` to be True. Returns False if the type is levity polymorphic; False is always safe.

valueisWorkerLikeId :: Id -> Bool
#

An Id for which we might require all callers to pass strict arguments properly tagged + evaluated.

See Note [CBV Function Ids]

valuemkExportedLocalId :: IdDetails -> Name -> Type -> Id
#

Create a local Id that is marked as exported. This prevents things attached to it from being removed as dead code. See Note [Exported LocalIds]

valuemkTemplateLocal :: Int -> Type -> Id
#

Create a template local: a family of system local Ids in bijection with Ints, typically used in unfoldings

valuesetIdType :: Id -> Type -> Id
#

Not only does this set the Id Type, it also evaluates the type to try and reduce space usage

valuezapIdUnfolding :: Id -> Id
#

Similar to trimUnfolding, but also removes evaldness info.

module GHC.Core

valueextendTvSubst :: Subst -> TyVar -> Type -> Subst
#

Add a substitution for a TyVar to the Subst The TyVar *must* be a real TyVar, and not a CoVar You must ensure that the in-scope set is such that Note [The substitution invariant] holds after extending the substitution like this.

datadata Subst
#

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.

Instances1Outputable
newtypenewtype InScopeSet
#

A set of variables that are in scope at some point.

Note that this is a superset of the variables that are currently in scope. See Note [The InScopeSet invariant].

"Secrets of the Glasgow Haskell Compiler inliner" Section 3.2 provides the motivation for this abstraction.

Instances1Outputable
valuesubstTyUnchecked :: Subst -> Type -> Type
#

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.

valuezapSubst :: Subst -> Subst
#

Remove all substitutions that might have been built up while preserving the in-scope set originally called zapSubstEnv

De-shadowing the program is sometimes a useful pre-pass. It can be done simply by running over the bindings with an empty substitution, because substitution returns a result that has no-shadowing guaranteed.

(Actually, within a single type there might still be shadowing, because substTy is a no-op for the empty substitution, but that's probably OK.)

Aug 09

This function is not used in GHC at the moment, but seems so short and simple that I'm going to leave it here

valueextendIdSubst :: Subst -> Id -> CoreExpr -> Subst
#

Add a substitution for an Id to the Subst: you must ensure that the in-scope set is such that TyCoSubst Note [The substitution invariant] holds after extending the substitution like this

valuemkOpenSubst :: InScopeSet -> [(Var, CoreArg)] -> Subst
#

Simultaneously substitute for a bunch of variables No left-right shadowing ie the substitution for (x y. e) a1 a2 so neither x nor y scope over a1 a2

valuesubstBndr :: Subst -> Var -> (Subst, Var)
#

Substitutes a Var for another one according to the Subst given, returning the result and an updated Subst that should be used by subsequent substitutions. IdInfo is preserved by this process, although it is substituted into appropriately.

Substitutes for the Ids within an unfolding NB: substUnfolding discards any unfolding without without a Stable source. This is usually what we want, but it may be a bit unexpected

Substitutes for the Ids within an unfolding NB: substUnfolding discards any unfolding without without a Stable source. This is usually what we want, but it may be a bit unexpected

datadata Var
#

Variable

Essentially a typed Name, that may also contain some additional information about the Var and its use sites.

Instances15Data, Ord, NamedThing, Outputable, Uniquable, HasOccName, …
datadata Subst
#

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.

Instances1Outputable
datadata Type
#
Instances3Data, Outputable, Eq
typetype TyVar = Var
#

Type or kind Variable

typetype Kind = Type
#

The key type representing kinds in the compiler.

typetype Mult = Type
#

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.

datadata Scaled a
#

A shorthand for data with an attached Mult element (the multiplicity).

Instances2Data, Outputable
datadata ForAllTyFlag
#

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

Instances7Eq, Data, Ord, NFData, Binary, Outputable, …
datadata FunTyFlag
#

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

Instances5Eq, Data, Ord, Outputable, Binary
datadata Specificity
#

Whether an Invisible argument may appear in source Haskell.

Constructors

  • InferredSpec

    the argument may not appear in source Haskell, it is only inferred.

  • SpecifiedSpec

    the argument may appear in source Haskell, but isn't required.

Instances10Eq, Data, Ord, NFData, Binary, OutputableBndrFlag, …
datadata PiTyBinder
#

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
valueisTyVar :: Var -> Bool
#

Is this a type-level (i.e., computationally irrelevant, thus erasable) variable? Satisfies isTyVar = not . isId.

typetype TyCoVar = Id
#

Type or Coercion Variable

valueisCoVarType :: Type -> 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

valuemightBeLiftedType :: Type -> Bool
#

Returns:

  • False if the type is guaranteed unlifted or

  • True if it lifted, OR we aren't sure (e.g. in a representation-polymorphic case)

valuemkForAllTy :: ForAllTyBinder -> Type -> Type
#

Like mkTyCoForAllTy, but does not check the occurrence of the binder See Note [Unused coercion variable in ForAllTy]

Given 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

typetype KindOrType = Type
#

The key representation of types within the compiler

typetype KnotTied (ty :: k) = ty
#

A type labeled KnotTied might have knot-tied tycons in it. See Note [Type checking recursive type and class declarations] in GHC.Tc.TyCl

valuesubstTysUnchecked :: Subst -> [Type] -> [Type]
#

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.

valuetymult :: a -> Scaled a
#

Scale a payload by Many; used for type arguments in core

valuesubstTyUnchecked :: Subst -> Type -> Type
#

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.

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

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.

valueisFunTy :: Type -> Bool
#

Is this a function? Note: `forall {b}. Show b => b -> IO b` will not be considered a function by this function. It would merely be a forall wrapping a function type.

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 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.

valuepiResultTys :: HasDebugCallStack => Type -> [Type] -> Type
#

(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.

valuescopedSort :: [TyCoVar] -> [TyCoVar]
#

Do a topological sort on a list of tyvars, so that binders occur before occurrences E.g. given [ a::k, k::*, b::k ] it'll return a well-scoped list [ k::*, 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

valuetyCoFVsOfType :: Type -> FV
#

The worker for tyCoFVsOfType and tyCoFVsOfTypeList. The previous implementation used unionVarSet which is O(n+m) and can make the function quadratic. It's exported, so that it can be composed with other functions that compute free variables. See Note [FV naming conventions] in GHC.Utils.FV.

Eta-expanded because that makes it run faster (apparently) See Note [FV eta expansion] in GHC.Utils.FV for explanation.

valuecoreView :: Type -> Maybe Type
#

This 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

valuezapSubst :: Subst -> Subst
#

Remove all substitutions that might have been built up while preserving the in-scope set originally called zapSubstEnv

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.

valuecloseOverKindsList :: [TyVar] -> [TyVar]
#

Add the kind variables free in the kinds of the tyvars in the given set. Returns a deterministically ordered list.

All type constructors occurring in the type; looking through type synonyms, but not newtypes. When it finds a Class, it returns the class TyCon.

typetype PredType = Type
#

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"

valuecomposeTCvSubst :: Subst -> Subst -> Subst
#

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.

valueisEmptyTCvSubst :: Subst -> Bool
#

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)

valuemkTvSubstPrs :: [(TyVar, Type)] -> Subst
#

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

Substitute within a Coercion disabling sanity checks. The problems that the sanity checks in substCo catch are described in Note [The substitution invariant]. The goal of #11371 is to migrate all the calls of substCoUnchecked to substCo and remove this function. Please don't use in new code.

Coercion substitution, see zipTvSubst. Disables sanity checks. The problems that the sanity checks in substCo catch are described in Note [The substitution invariant]. The goal of #11371 is to migrate all the calls of substCoUnchecked to substCo 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.

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].

valuetidyVarBndrs :: TidyEnv -> [TyCoVar] -> (TidyEnv, [TyCoVar])
#

This tidies up a type for printing in an error message, or in an interface file.

It doesn't change the uniques at all, just the print names.

valuemkTyConTy :: TyCon -> Type
#

(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!

valueappTyForAllTyFlags :: Type -> [Type] -> [ForAllTyFlag]
#

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).

valuecoAxNthLHS :: CoAxiom br -> Int -> Type
#

Get the type on the LHS of a coercion induced by a type/data family instance.

valuecoreFullView :: Type -> Type
#

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].

valuedropRuntimeRepArgs :: [Type] -> [Type]
#

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#]

valueexpandTypeSynonyms :: Type -> Type
#

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

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"

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.

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)
valueisAlgType :: Type -> Bool
#

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

valueisBoxedType :: Type -> Bool
#

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.

valueisConcreteType :: Type -> Bool
#

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.

valueisForAllTy :: Type -> Bool
#

Checks whether this is a proper forall (with a named binder)

valueisLiftedTypeKind :: Kind -> Bool
#

Returns True if the argument is (lifted) Type or Constraint See Note [TYPE and CONSTRAINT] in GHC.Builtin.Types.Prim

valueisLinearType :: Type -> Bool
#

isLinear t returns True of a if t is a type of (curried) function where at least one argument is linear (or otherwise non-unrestricted). We use this function to check whether it is safe to eta reduce an Id in CorePrep. It is always safe to return True, because True deactivates the optimisation.

valueisTYPEorCONSTRAINT :: Kind -> Bool
#

Does 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 _`

valueisTypeLikeKind :: Kind -> Bool
#

Is this kind equivalent to TYPE r (for some unknown r)?

This considers Constraint to be distinct from *.

valueisUnliftedTypeKind :: Kind -> Bool
#

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.

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]

Check whether a kind is of the form `TYPE (BoxedRep Lifted)` or `TYPE (BoxedRep Unlifted)`.

Returns:

  • `Just Lifted` for `TYPE (BoxedRep Lifted)` and Type,

  • `Just Unlifted` for `TYPE (BoxedRep Unlifted)` and UnliftedType,

  • Nothing for anything else, e.g. `TYPE IntRep`, `TYPE (BoxedRep l)`, etc.

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

Given a Levity, apply BoxedRep to it On the fly, rewrite BoxedRep Lifted --> liftedRepTy (a synonym) BoxedRep Unlifted --> unliftedRepTy (ditto) See Note [TYPE and CONSTRAINT] in GHC.Builtin.Types.Prim. See Note [Using synonyms to compress types] in GHC.Core.Type

valuemkFamilyTyConApp :: TyCon -> [Type] -> Type
#

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 b

Where the instance tycon is :RTL, so:

mkFamilyTyConApp :RTL Int  =  T (Maybe Int)

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

valuemkTyConBindersPreferAnon
  1. :: [TyVar]

    binders

  2. -> TyCoVarSet

    free variables of result

  3. -> [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.

valuenewTyConInstRhs :: TyCon -> [Type] -> Type
#

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.

valuepartitionInvisibles :: [(a, ForAllTyFlag)] -> ([a], [a])
#

Given a list of things paired with their visibilities, partition the things into (invisible things, visible things).

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:

  • `Just Lifted` if rr is `LiftedRep :: RuntimeRep`

  • `Just Unlifted` if rr is definitely unlifted, e.g. IntRep

  • Nothing if not known (e.g. it's a type variable or a type family application).

valuesplitAppTy_maybe :: Type -> Maybe (Type, Type)
#

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!

valuesplitAppTys :: HasDebugCallStack => Type -> (Type, [Type])
#

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.

valuesplitForAllTyCoVars :: Type -> ([TyCoVar], Type)
#

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.

valuesplitForAllTyVars :: Type -> ([TyVar], Type)
#

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.

(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

valuesplitTyConApp :: Type -> (TyCon, [Type])
#

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

valuetyConAppNeedsKindSig
  1. :: Bool

    Should specified binders count towards injective positions in the kind of the TyCon? (If you're using visible kind applications, then you want True here.

  2. -> TyCon
  3. -> Int

    The number of args the TyCon is applied to.

  4. -> Bool

    Does T t_1 ... t_n need a kind signature? (Where n is 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.)

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 -> n

Thus, the first argument is invisible, S is visible, R is invisible again, and Q is visible.

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)

typetype ErrorMsgType = Type
#

A type of kind ErrorMessage (from the GHC.TypeError module).

datadata TyCoMapper env (m :: Type -> Type)
#

This describes how a "map" operation over a type/coercion should behave

Constructors

datadata Var
#

Variable

Essentially a typed Name, that may also contain some additional information about the Var and its use sites.

Instances15Data, Ord, NamedThing, Outputable, Uniquable, HasOccName, …
typetype CoVar = Id
#

Coercion Variable

typetype TyCoVar = Id
#

Type or Coercion Variable

valuemkPrimEqPred :: Type -> Type -> Type
#

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

datadata Role
#

See Note [Roles] in GHC.Core.Coercion

Order of constructors matters: the Ord instance coincides with the *super*typing relation on roles.

Instances7Eq, Data, Ord, Outputable, Binary, Anno, …
  • Eq RoleDefined in ghc-9.10.3 · Language.Haskell.Syntax.Basic
  • Data RoleDefined in ghc-9.10.3 · Language.Haskell.Syntax.Basic
  • Ord RoleDefined in ghc-9.10.3 · Language.Haskell.Syntax.Basic
  • Outputable RoleDefined in ghc-9.10.3 · GHC.Core.Coercion.Axiom · orphan
  • Binary RoleDefined in ghc-9.10.3 · GHC.Core.Coercion.Axiom · orphan
  • type Anno (Maybe Role) = EpAnnCODefined in ghc-9.10.3 · GHC.Hs.Decls · orphan
  • type Anno (Maybe Role) = EpAnnCODefined in ghc-9.10.3 · GHC.Hs.Decls · orphan
valueisReflCo :: Coercion -> Bool
#

Tests if this coercion is obviously reflexive. Guaranteed to work very quickly. Sometimes a coercion can be reflexive, but not obviously so. c.f. isReflexiveCo

datadata UnivCoProvenance
#

For simplicity, we have just one UnivCo that represents a coercion from some type to some other type, with (in general) no restrictions on the type. The UnivCoProvenance specifies more exactly what the coercion really is and why a program should (or shouldn't!) trust the coercion. It is reasonable to consider each constructor of UnivCoProvenance as a totally independent coercion form; their only commonality is that they don't tell you what types they coercion between. (That info is in the UnivCo constructor of Coercion.

Instances2Data, Outputable

Extract a covar, if possible. This check is dirty. Be ashamed of yourself. (It's dirty because it cares about the structure of a coercion, which is morally reprehensible.)

valuemkSymCo :: Coercion -> Coercion
#

Create a symmetric version of the given Coercion that asserts equality between the same types but in the other "direction", so a kind of t1 ~ t2 becomes the kind t2 ~ t1.

If it is the case that

c :: (t1 ~ t2)

i.e. the kind of c relates t1 and t2, then coercionKind c = Pair t1 t2.

valueisReflexiveCo :: Coercion -> Bool
#

Slowly checks if the coercion is reflexive. Don't call this in a loop, as it walks over the entire coercion.

valuemkAppCo
  1. :: Coercion

    :: t1 ~r t2

  2. -> Coercion

    :: s1 ~N s2, where s1 :: k1, s2 :: k2

  3. -> Coercion

    :: t1 s1 ~r t2 s2

#

Apply a Coercion to another Coercion. The second coercion must be Nominal, unless the first is Phantom. If the first is Phantom, then the second can be either Phantom or Nominal.

Build a function Coercion from two other Coercions. That is, given co1 :: a ~ b and co2 :: x ~ y produce co :: (a -> x) ~ (b -> y) or (a => x) ~ (b => y), depending on the kind of a/b. This (most common) version takes a single FunTyFlag, which is used for both fco_afl and ftf_afr of the FunCo

Sometimes we want to look through a newtype and get its associated coercion. This function strips off newtype layers enough to reveal something that isn't a newtype. Specifically, here's the invariant:

topNormaliseNewType_maybe rec_nts ty = Just (co, ty')

then (a) co : ty ~R ty'. (b) ty' is not a newtype.

The function returns Nothing for non-newtypes, or unsaturated applications

This function does *not* look through type families, because it has no access to the type family environment. If you do have that at hand, consider to use topNormaliseType_maybe, which should be a drop-in replacement for topNormaliseNewType_maybe If topNormliseNewType_maybe ty = Just (co, ty'), then co : ty ~R ty'

datadata NormaliseStepResult ev
#

The result of stepping in a normalisation function. See topNormaliseTypeX.

Constructors

  • NS_Done

    Nothing more to do

  • NS_Abort

    Utter failure. The outer function should fail too.

  • NS_Step RecTcChecker Type ev

    We stepped, yielding new bits; ^ ev is evidence; Usually a co :: old type ~ new type

Instances2Functor, Outputable
valuebuildCoercion :: Type -> Type -> CoercionN
#

Assuming that two types are the same, ignoring coercions, find a nominal coercion between the types. This is useful when optimizing transitivity over coercion applications, where splitting two AppCos might yield different kinds. See Note [EtaAppCo] in GHC.Core.Coercion.Opt.

Creates a new coercion with both of its types casted by different casts castCoercionKind g h1 h2, where g :: t1 ~r t2, has type (t1 |> h1) ~r (t2 |> h2). h1 and h2 must be nominal. It calls coercionKindRole, so it's quite inefficient (which I stands for) Use castCoercionKind2 instead if t1, t2, and r are known beforehand.

castCoercionKind1 g r t1 t2 h = coercionKind g r t1 t2 h h That is, it's a specialised form of castCoercionKind, where the two kind coercions are identical castCoercionKind1 g r t1 t2 h, where g :: t1 ~r t2, has type (t1 |> h) ~r (t2 |> h). h must be nominal. See Note [castCoercionKind1]

valuegetNthFun
  1. :: FunSel
  2. -> a

    multiplicity

  3. -> a

    argument

  4. -> a

    result

  5. -> a

    One of the above three

#

Extract the nth field of a FunCo

valuehasCoercionHoleTy :: Type -> Bool
#

Is there a hetero-kind coercion hole in this type? (That is, a coercion hole with ch_hetero_kind=True.) See wrinkle (EIK2) of Note [Equalities with incompatible kinds] in GHC.Tc.Solver.Equality

valueisGReflCo :: Coercion -> Bool
#

Tests if this coercion is obviously a generalized reflexive coercion. Guaranteed to work very quickly.

valueisGReflMCo :: MCoercion -> Bool
#

Tests if this MCoercion is obviously generalized reflexive Guaranteed to work very quickly.

liftCoSubst role lc ty produces a coercion (at role role) that coerces between lc_left(ty) and lc_right(ty), where lc_left is a substitution mapping type variables to the left-hand types of the mapped coercions in lc, and similar for lc_right.

valuemkNomPrimEqPred :: Kind -> Type -> Type -> Type
#

Creates a primitive nominal type equality predicate with an explicit (but homogeneous) kind: (~#) k k ty1 ty2

valuemkPhantomCo :: Coercion -> Type -> Type -> Coercion
#

Make a phantom coercion between two types. The coercion passed in must be a nominal coercion between the kinds of the types.

valuemkReprPrimEqPred :: Type -> Type -> Type
#

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

Given a coercion `co :: (t1 :: TYPE r1) ~ (t2 :: TYPE r2)` produce a coercion `rep_co :: r1 ~ r2` But actually it is possible that co :: (t1 :: CONSTRAINT r1) ~ (t2 :: CONSTRAINT r2) or co :: (t1 :: TYPE r1) ~ (t2 :: CONSTRAINT r2) or co :: (t1 :: CONSTRAINT r1) ~ (t2 :: TYPE r2) See Note [mkRuntimeRepCo]

valuetopNormaliseTypeX
  1. :: NormaliseStepper ev
  2. -> ev -> ev -> ev
  3. -> Type
  4. -> Maybe (ev, Type)
#

A general function for normalising the top-level of a type. It continues to use the provided NormaliseStepper until that function fails, and then this function returns. The roles of the coercions produced by the NormaliseStepper must all be the same, which is the role returned from the call to topNormaliseTypeX.

Typically ev is Coercion.

If topNormaliseTypeX step plus ty = Just (ev, ty') then ty ~ev1~ t1 ~ev2~ t2 ... ~evn~ ty' and ev = ev1 plus ev2 plus ... plus evn If it returns Nothing then no newtype unwrapping could happen

newtypenewtype Unique
#

Unique identifier.

The type of unique identifiers that are used in many places in GHC for fast ordering and equality tests. You should generate these with the functions from the UniqSupply module

These are sometimes also referred to as "keys" in comments in GHC.

Instances4Eq, Show, Outputable, Uniquable
classclass Uniquable a where
#

Class of things that we can obtain a Unique from

Methods

Instances36Uniquable, …
newtypenewtype Messages e
#

A collection of messages emitted by GHC during error reporting. A diagnostic message is typically a warning or an error. See Note [Messages].

INVARIANT: All the messages in this collection must be relevant, i.e. their Severity should not be SevIgnore. The smart constructor mkMessages will filter out any message which Severity is SevIgnore.

Instances7Functor, Foldable, Traversable, Semigroup, Monoid, Outputable, …

Getting Names

2 declarations

Attempt to convert a Template Haskell name to one that GHC can understand. Original TH names such as those you get when you use the 'foo syntax will be translated to their equivalent GHC name exactly. Qualified or unqualified TH names will be dynamically bound to names in the module being compiled, if possible. Exact TH names will be bound to the name they represent, exactly.

Attempt to convert a Template Haskell name to one that GHC can understand. Original TH names such as those you get when you use the 'foo syntax will be translated to their equivalent GHC name exactly. Qualified or unqualified TH names will be dynamically bound to names in the module being compiled, if possible. Exact TH names will be bound to the name they represent, exactly.

One must be careful to consistently use the same NameCache to create identifier that might be compared. (C.f. how the ST Monad enforces that variables from separate runST invocations are never intermingled; it would be valid to use the same tricks for Names and NameCaches.)

For now, the easiest and recommended way to ensure a consistent NameCache is used it to retrieve the preexisting one from an active HscEnv. A single HscEnv is created per GHC "session", and this ensures everything in that session will get the same name cache.

Orphan instances

1 instance