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.Tc.Utils.TcType

Types used in the typechecker

This module provides the Type interface for front-end parts of the compiler. These parts

  • treat "source types" as opaque: newtypes, and predicates are meaningful.

  • look through usage types

  • 51 types
  • 269 values
  • Packageghc-9.10.3
  • Exports322
  • LanguageGHC2021
  • LicenceBSD-3-Clause
  • SourceTcType.hs
typetype TcTypeFRR = TcType
#

A type which has a syntactically fixed RuntimeRep as per Note [Fixed RuntimeRep] in GHC.Tc.Utils.Concrete.

A TcSigmaTypeFRR is a TcSigmaType which has a syntactically fixed RuntimeRep in the sense of Note [Fixed RuntimeRep] in GHC.Tc.Utils.Concrete.

In particular, this means that:

This property is important in functions such as matchExpectedFunTys, where we want to provide argument types which have a known runtime representation. See Note [Return arguments with a fixed RuntimeRep.

typetype TcTyVar = Var
#

Type variable that might be a metavariable

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

datadata InferResult
#

Constructors

  • IR
    • ir_uniq :: Unique

      This Unique is for debugging only

    • ir_lvl :: TcLevel

      See Note [TcLevel of ExpType] in GHC.Tc.Utils.TcMType

    • ir_frr :: Maybe FixedRuntimeRepContext

      See Note [FixedRuntimeRep context in ExpType] in GHC.Tc.Utils.TcMType

    • ir_ref :: IORef (Maybe TcType)

      The type that fills in this hole should be a Type, that is, its kind should be TYPE rr for some rr :: RuntimeRep.

      Additionally, if the ir_frr field is Just frr_orig then rr must be concrete, in the sense of Note [Concrete types] in GHC.Tc.Utils.Concrete.

Instances1Outputable
datadata SyntaxOpType
#

What to expect for an argument to a rebindable-syntax operator. Quite like Type, but allows for holes to be filled in by tcSyntaxOp. The callback called from tcSyntaxOp gets a list of types; the meaning of these types is determined by a left-to-right depth-first traversal of the SyntaxOpType tree. So if you pass in

SynAny `SynFun` (SynList `SynFun` SynType Int) `SynFun` SynAny

you'll get three types back: one for the first SynAny, the element type of the list, and one for the last SynAny. You don't get anything for the SynType, because you've said positively that it should be an Int, and so it shall be.

You'll also get three multiplicities back: one for each function arrow. See also Note [Linear types] in Multiplicity.

This is defined here to avoid defining it in GHC.Tc.Gen.Expr boot file.

Constructors

datadata MetaInfo
#

What restrictions are on this metavariable around unification? These are checked in GHC.Tc.Utils.Unify.checkTopShape

Constructors

  • TauTv

    This MetaTv is an ordinary unification variable A TauTv is always filled in with a tau-type, which never contains any ForAlls.

  • TyVarTv

    A variant of TauTv, except that it should not be unified with a type, only with a type variable See Note [TyVarTv] in GHC.Tc.Utils.TcMType

  • RuntimeUnkTv

    A unification variable used in the GHCi debugger. It is allowed to unify with a polytype, unlike TauTv

  • CycleBreakerTv
  • ConcreteTv ConcreteTvOrigin

    A unification variable that can only be unified with a concrete type, in the sense of Note [Concrete types] in GHC.Tc.Utils.Concrete. See Note [ConcreteTv] in GHC.Tc.Utils.Concrete. See also Note [The Concrete mechanism] in GHC.Tc.Utils.Concrete for an overview of how this works in context.

Instances1Outputable

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.

valuetcSplitSigmaTy :: Type -> ([TyVar], ThetaType, Type)
#

Split a sigma type into its parts. This only splits invisible type variable binders, as these are the only forms of binder that the typechecker will implicitly instantiate.

valueisFloatingPrimTy :: Type -> Bool
#

Is the type inhabited by machine floating-point numbers?

Used to check that we don't use floating-point literal patterns in Core.

See #9238 and Note [Rules for floating-point comparisons] in GHC.Core.Opt.ConstantFold.

valueeqType :: Type -> Type -> Bool
#

Type equality on source types. Does not look through newtypes, PredTypes or type families, but it does look through type synonyms. This first checks that the kinds of the types are equal and then checks whether the types are equal, ignoring casts and coercions. (The kind check is a recursive call, but since all kinds have type Type, there is no need to check the types of kinds.) See also Note [Non-trivial definitional equality] in GHC.Core.TyCo.Rep.

valueeqTypes :: [Type] -> [Type] -> Bool
#

Type equality on lists of types, looking through type synonyms but not newtypes.

valuemayLookIdentical :: Type -> Type -> Bool
#

Returns True if the visible part of the types might look equal, even if they are really unequal (in the invisible bits)

This function is very similar to tc_eq_type but it is much more heuristic. Notably, it is always safe to return True, even with types that might (in truth) be unequal -- this affects error messages only (Originally there were one function with an extra flag, but the result was hard to understand.)

valuetcEqTyConApps :: TyCon -> [Type] -> TyCon -> [Type] -> Bool
#

Check whether two TyConApps are the same; if the number of arguments are different, just checks the common prefix of arguments.

valueambigTkvsOfTy :: TcType -> ([Var], [Var])
#

Returns the (kind, type) variables in a type that are as-yet-unknown: metavariables and RuntimeUnks

Finding type instances

4 declarations
valuetcTyFamInsts :: Type -> [(TyCon, [Type])]
#

Finds outermost type-family applications occurring in a type, after expanding synonyms. In the list (F, tys) that is returned we guarantee that tys matches F's arity. For example, given type family F a :: * -> * (arity 1) calling tcTyFamInsts on (Maybe (F Int Bool) will return (F, [Int]), not (F, [Int,Bool])

This is important for its use in deciding termination of type instances (see #11581). E.g. type instance G [Int] = ...(F Int <big type>)... we don't need to take <big type> into account when asking if the calls on the RHS are smaller than the LHS

valuetcTyFamInstsAndVis :: Type -> [(Bool, TyCon, [Type])]
#

Like tcTyFamInsts, except that the output records whether the type family and its arguments occur as an invisible argument in some type application. This information is useful because it helps GHC know when to turn on -fprint-explicit-kinds during error reporting so that users can actually see the type family being mentioned.

As an example, consider:

class C a
data T (a :: k)
type family F a :: k
instance C (T @(F Int) (F Bool))

There are two occurrences of the type family F in that C instance, so tcTyFamInstsAndVis (C (T @(F Int) (F Bool))) will return:

[ (True,  F, [Int])
, (False, F, [Bool]) ]

F Int is paired with True since it appears as an invisible argument to C, whereas F Bool is paired with False since it appears an a visible argument to C.

See also Note [Showing invisible bits of types in error messages] in GHC.Tc.Errors.Ppr.

valueisTyFamFree :: Type -> Bool
#

Check that a type does not contain any type family applications.

Finding "exact" (non-dead) type variables

141 declarations
datadata PatersonSize
#

The Paterson size of a given type, in the sense of Note [Paterson conditions] in GHC.Tc.Validity

  • after expanding synonyms,

  • ignoring coercions (as they are not user written).

Constructors

  • PS_TyFam TyCon

    The type mentions a type family, so the size could be anything.

  • PS_Vanilla

    The type does not mention a type family.

    • ps_tvs :: [TyVar]

      free tyvars, including repetitions;

    • ps_size :: Int

      number of type constructors and variables

Instances1Outputable
datadata PatersonCondFailure
#

Why did the Paterson conditions fail; that is, why was the context P not Paterson-smaller than the head H?

See Note [Paterson conditions] in GHC.Tc.Validity.

Constructors

  • PCF_TyVar [TyVar]

    Some type variables occur more often in P than in H. See (PC1) in Note [Paterson conditions] in GHC.Tc.Validity.

  • PCF_Size
  • PCF_TyFam TyCon

    P contains a type family. See (PC3) in Note [Paterson conditions] in GHC.Tc.Validity.

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

When this says True, ignore this class constraint during a termination check See (PS1) in Note [The PatersonSize of a type]

typetype Kind = Type
#

The key type representing kinds in the compiler.

valueisLiftedTypeKind :: Kind -> Bool
#

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

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.

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

datadata Type
#
Instances3Data, Outputable, Eq
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"

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
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
valuemkForAllTy :: ForAllTyBinder -> Type -> Type
#

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

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!

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

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.

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

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.

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.

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.

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.

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.

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.

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

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.

Returns free variables of types, including kind variables as a deterministic set. For type synonyms it does not expand the synonym.

valuetyCoVarsOfTypesList :: [Type] -> [TyCoVar]
#

Returns free variables of types, including kind variables as a deterministically ordered list. For type synonyms it does not expand the synonym.

valuetyConVisibilities :: TyCon -> [Bool]
#

For every arg a tycon can take, the returned list says True if the argument is taken visibly, and False otherwise. Ends with an infinite tail of Trues to allow for oversaturation.

valueisNextArgVisible :: TcType -> Bool
#

Should this type be applied to a visible argument? E.g. (s t): is t a visible argument of s?