HORIZON HASKELLDocslts/ghc-10.0.xaa25b892026-10-10Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · aa25b89 · 2026-10-10

Moduleghc-10.0.0.20260917GHC2024

GHC.Tc.Utils.Unify

Type subsumption and unification

  • 13 types
  • 61 values
datadata DeepSubsumptionDepth
#

Constructors

  • TopSub

    Top-level subsumption: instantiate under top-level covariant arrows only

    Int -> forall a. a->a  (Int - forall b. [b] -> [b])
  • DeepSub

    Deep subsumption: instantiate under all arrows (covariant and contravariant)

    (forall b. [b] -> [b]) -> Int  (forall a. a-a) -> Int

This is the key test for untouchability: See Note [Unification preconditions] in GHC.Tc.Utils.Unify and Note [Solve by unification] in GHC.Tc.Solver.Equality

True = the variable is touchable

valuecheckTopShape :: MetaInfo -> TcType -> Bool
#

checkTopShape checks (TYVAR-TV) Note [Unification preconditions]; returns True if these conditions are satisfied. But see the Note for other preconditions, too.

Try to turn the provided type into a concrete type, by ensuring unfilled metavariables are appropriately marked as concrete.

Returns a coercion whose RHS is a zonked type which is "as concrete as possible", and a collection of Wanted equality constraints that are necessary to make the type concrete.

For example, for an input TYPE a[sk] we will return a coercion with RHS TYPE gamma[conc] together with the Wanted equality constraint a ~# gamma.

INVARIANT: the RHS type of the returned coercion is equal to the input type, up to zonking and the returned Wanted equality constraints.

INVARIANT: if this function returns an empty list of constraints then the RHS type of the returned coercion is concrete, in the sense of Note [Concrete types].

Use this function to split off arguments types when you have an "expected" type.

This function skolemises at each polytype.

Invariant: this function only applies the provided function to a list of argument types which all have a syntactically fixed RuntimeRep in the sense of Note [Fixed RuntimeRep] in GHC.Tc.Utils.Concrete. See Note [Return arguments with a fixed RuntimeRep].

valuematchActualFunTy
  1. :: ExpectedFunTyCtxt

    See Note [Herald for matchExpectedFunTys]

  2. -> Maybe TypedThing

    The thing with type TcSigmaType

  3. -> (Arity, TcType)

    Total number of value args in the call, and the original function type (Both are used only for error messages)

  4. -> TcRhoType

    Type to analyse: a TcRhoType

  5. -> TcM (TcCoercion, Scaled TcSigmaTypeFRR, TcSigmaType)
#

matchActualFunTy looks for just one function arrow, returning an uninstantiated sigma-type.

Invariant: the returned argument type has a syntactically fixed RuntimeRep in the sense of Note [Fixed RuntimeRep] in GHC.Tc.Utils.Concrete.

See Note [Return arguments with a fixed RuntimeRep].

datadata PuResult a b
#

Constructors

Instances5Functor, Applicative, Foldable, Traversable, Outputable
datadata TyEqFlags (m :: Type -> Type) a
#

Options describing how to deal with a type equality in the eager unifier. See checkTyEqRhs

Constructors

Instances1Outputable
datadata LevelCheck (m :: Type -> Type) where
#

What level check to perform, in a call to the pure unifier? A defunctionalisation of the possible level-check functions Interpreter: tyVarLevelCheck

Constructors

Instances1Outputable
datadata ConcreteCheck (m :: Type -> Type) where
#

Constructors

Instances1Outputable
datadata TyEqFamApp (m :: Type -> Type) a where
#

What to do when encountering a type-family application while processing a type equality in the pure unifier.

See Note [Family applications in canonical constraints]

Constructors

Instances1Outputable

A fast check for unification. May return "not sure", in which case unification might still be OK, but it'll take more work to do (use the full checkTypeEq).

  • Rejects if lhs_tv occurs in rhs_ty (occurs check)

  • Rejects foralls unless lhs_tv is RuntimeUnk (used by GHCi debugger) or is a QL instantiation variable

  • Rejects a non-concrete type if lhs_tv is concrete

  • Rejects type families unless fam_ok=True

  • Does a level-check for type variables, to avoid skolem escape

This function is pretty heavily used, so it's optimised not to allocate

datadata SimpleUnifyResult
#

The result type of simpleUnifyCheck.

Constructors

  • SUC_CannotUnify

    Definitely cannot unify (untouchable variable or incompatible top-shape)

  • SUC_NotSure

    The variable is touchable and the top-shape test passed, but it may or may not be OK to unify

  • SUC_CanUnify

    Definitely OK to unify

Instances5Eq, Ord, Show, Semigroup, Outputable

Fill an InferResult with the given type.

If co = fillInferResult t1 infer_res, then co :: t1 ~# t2, where t2 is the type stored in the ir_ref field of infer_res.

This function enforces the following invariants:

  • Level invariant. The stored type t2 is at the same level as given by the ir_lvl field.

  • FRR invariant. Whenever the ir_frr field is IFRR_Check, t2 is guaranteed to have a syntactically fixed RuntimeRep, in the sense of Note [Fixed RuntimeRep] in GHC.Tc.Utils.Concrete.