ghc-9.13: The GHC API
Safe HaskellNone
LanguageGHC2021

GHC.Tc.Utils.Unify

Description

Type subsumption and unification

Synopsis

Documentation

tcSubType Source #

Arguments

:: CtOrigin 
-> UserTypeCtxt 
-> TcSigmaType

Actual

-> ExpRhoType

Expected

-> TcM HsWrapper 

checkConstraints :: SkolemInfoAnon -> [TcTyVar] -> [EvVar] -> TcM result -> TcM (TcEvBinds, result) Source #

checkTvConstraints :: SkolemInfo -> [TcTyVar] -> TcM result -> TcM result Source #

data DeepSubsumptionFlag Source #

Constructors

Deep 
Shallow 

Instances

Instances details
Outputable DeepSubsumptionFlag Source # 
Instance details

Defined in GHC.Tc.Utils.Unify

tcSkolemiseCompleteSig :: TcCompleteSig -> ([ExpPatType] -> TcRhoType -> TcM result) -> TcM (HsWrapper, result) Source #

The wrapper has type: spec_ty ~> expected_ty See Note [Skolemisation] for the differences between tcSkolemiseCompleteSig and tcTopSkolemise

unifyType Source #

Arguments

:: Maybe TypedThing

If present, the thing that has type ty1

-> TcTauType 
-> TcTauType 
-> TcM TcCoercionN 

checkTopShape :: MetaInfo -> TcType -> Bool Source #

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

makeTypeConcrete :: FastString -> ConcreteTvOrigin -> TcType -> TcM (TcCoercion, Cts) Source #

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

tcInfer :: (ExpSigmaType -> TcM a) -> TcM (a, TcSigmaType) Source #

Infer a type using a fresh ExpType See also Note [ExpType] in GHC.Tc.Utils.TcMType

Use tcInferFRR if you require the type to have a fixed runtime representation.

matchExpectedFunTys :: ExpectedFunTyOrigin -> UserTypeCtxt -> VisArity -> ExpSigmaType -> ([ExpPatType] -> ExpRhoType -> TcM a) -> TcM (HsWrapper, a) Source #

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

matchExpectedFunKind Source #

Arguments

:: TypedThing

type, only for errors

-> Arity

n: number of desired arrows

-> TcKind

fun_kind

-> TcM Coercion

co :: fun_kind ~ (arg1 -> ... -> argn -> res)

Breaks apart a function kind into its pieces.

matchActualFunTy Source #

Arguments

:: ExpectedFunTyOrigin

See Note [Herald for matchExpectedFunTys]

-> Maybe TypedThing

The thing with type TcSigmaType

-> (Arity, TcType)

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

-> TcRhoType

Type to analyse: a TcRhoType

-> TcM (HsWrapper, 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].

matchActualFunTys Source #

Arguments

:: ExpectedFunTyOrigin

See Note [Herald for matchExpectedFunTys]

-> CtOrigin 
-> Arity 
-> TcSigmaType 
-> TcM (HsWrapper, [Scaled TcSigmaTypeFRR], TcRhoType) 

Like matchExpectedFunTys, but used when you have an "actual" type, for example in function application.

INVARIANT: the returned argument types 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].

data PuResult a b Source #

Constructors

PuFail CheckTyEqResult 
PuOK (Bag a) b 

Instances

Instances details
Applicative (PuResult a) Source # 
Instance details

Defined in GHC.Tc.Utils.Unify

Methods

pure :: a0 -> PuResult a a0 #

(<*>) :: PuResult a (a0 -> b) -> PuResult a a0 -> PuResult a b #

liftA2 :: (a0 -> b -> c) -> PuResult a a0 -> PuResult a b -> PuResult a c #

(*>) :: PuResult a a0 -> PuResult a b -> PuResult a b #

(<*) :: PuResult a a0 -> PuResult a b -> PuResult a a0 #

Functor (PuResult a) Source # 
Instance details

Defined in GHC.Tc.Utils.Unify

Methods

fmap :: (a0 -> b) -> PuResult a a0 -> PuResult a b #

(<$) :: a0 -> PuResult a b -> PuResult a a0 #

Foldable (PuResult a) Source # 
Instance details

Defined in GHC.Tc.Utils.Unify

Methods

fold :: Monoid m => PuResult a m -> m #

foldMap :: Monoid m => (a0 -> m) -> PuResult a a0 -> m #

foldMap' :: Monoid m => (a0 -> m) -> PuResult a a0 -> m #

foldr :: (a0 -> b -> b) -> b -> PuResult a a0 -> b #

foldr' :: (a0 -> b -> b) -> b -> PuResult a a0 -> b #

foldl :: (b -> a0 -> b) -> b -> PuResult a a0 -> b #

foldl' :: (b -> a0 -> b) -> b -> PuResult a a0 -> b #

foldr1 :: (a0 -> a0 -> a0) -> PuResult a a0 -> a0 #

foldl1 :: (a0 -> a0 -> a0) -> PuResult a a0 -> a0 #

toList :: PuResult a a0 -> [a0] #

null :: PuResult a a0 -> Bool #

length :: PuResult a a0 -> Int #

elem :: Eq a0 => a0 -> PuResult a a0 -> Bool #

maximum :: Ord a0 => PuResult a a0 -> a0 #

minimum :: Ord a0 => PuResult a a0 -> a0 #

sum :: Num a0 => PuResult a a0 -> a0 #

product :: Num a0 => PuResult a a0 -> a0 #

Traversable (PuResult a) Source # 
Instance details

Defined in GHC.Tc.Utils.Unify

Methods

traverse :: Applicative f => (a0 -> f b) -> PuResult a a0 -> f (PuResult a b) #

sequenceA :: Applicative f => PuResult a (f a0) -> f (PuResult a a0) #

mapM :: Monad m => (a0 -> m b) -> PuResult a a0 -> m (PuResult a b) #

sequence :: Monad m => PuResult a (m a0) -> m (PuResult a a0) #

(Outputable a, Outputable b) => Outputable (PuResult a b) Source # 
Instance details

Defined in GHC.Tc.Utils.Unify

Methods

ppr :: PuResult a b -> SDoc Source #

data TyEqFlags a Source #

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

Constructors

TEF 

Fields

Instances

Instances details
Outputable (TyEqFlags a) Source # 
Instance details

Defined in GHC.Tc.Utils.Unify

Methods

ppr :: TyEqFlags a -> SDoc Source #

data TEFTask Source #

The structure of the LHS and which checks to perform in checkTyEqRhs, for an equality lhs ~# rhs.

See Note [TEFTask].

Constructors

TEFTyFam

LHS is a type family application; we are not unifying.

Fields

TEFTyVar

LHS is a TyVar.

Fields

Instances

Instances details
Outputable TEFTask Source # 
Instance details

Defined in GHC.Tc.Utils.Unify

Methods

ppr :: TEFTask -> SDoc Source #

notUnifying_TEFTask :: CheckTyEqProblem -> CanEqLHS -> TEFTask Source #

Create a "not unifying" TEFTask from a CanEqLHS.

See use-case (1) in Note [TEFTask].

unifyingLHSMetaTyVar_TEFTask :: TyVar -> LevelCheck -> TEFTask Source #

Create "unifying" TEFTask from a TyVarLHS.

Invariant: the argument TyVar is a MetaTv.

data LevelCheck Source #

What level check to perform, in a call to the pure unifier?

Constructors

LC_Check

Do a level check between the LHS tyvar and the occurrence tyvar.

Fail if the level check fails.

LC_Promote Bool

Do a level check between the LHS tyvar and the occurrence tyvar.

If the level check fails, and the occurrence is a unification variable, promote it.

  • False = don't promote under type families (the common case)
  • True = promote even under type families (see Note [Defaulting equalities] in GHC.Tc.Solver)

Instances

Instances details
Outputable LevelCheck Source # 
Instance details

Defined in GHC.Tc.Utils.Unify

Methods

ppr :: LevelCheck -> SDoc Source #

data TyEqFamApp a Source #

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

TEFA_Fail

Always fail

TEFA_Recurse

Just recurse

TEFA_Break (FamAppBreaker a)

Recurse, but replace with cycle breaker if fails, using the FamAppBreaker

Instances

Instances details
Outputable (TyEqFamApp a) Source # 
Instance details

Defined in GHC.Tc.Utils.Unify

Methods

ppr :: TyEqFamApp a -> SDoc Source #

famAppArgFlags :: TyEqFlags a -> TyEqFlags a Source #

Adjust the TyEqFlags when going undter a type family:

  1. Only the outer family application gets the loop-breaker treatment
  2. Weaken level checks for tyvar promotion. For example, in [W] alpha[2] ~ Maybe (F beta[3]), do not promote beta[3], instead promote (F beta[3]).
  3. Occurs checks become potentially soluble (after additional type family reductions).

fillInferResult :: TcType -> InferResult -> TcM TcCoercionN Source #

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 not Nothing, t2 is guaranteed to have a syntactically fixed RuntimeRep, in the sense of Note [Fixed RuntimeRep] in GHC.Tc.Utils.Concrete.