Moduleghc-10.0.0.20260917GHC2024
GHC.Tc.Utils.Unify
Type subsumption and unification
- 13 types
- 61 values
- Packageghc-10.0.0.20260917
- Exports74
- LanguageGHC2024
- LicenceBSD-3-Clause
- SourceUnify.hs
tcWrapResultMono :: HasDebugCallStack=> HsExpr GhcRn-> HsExpr GhcTc-> TcRhoTypeActual; a rho-type, not a sigma-type
-> ExpRhoTypeExpected
-> TcM (HsExpr GhcTc)
A version of tcWrapResult to use when the actual type is a rho-type, so nothing to instantiate; just go straight to unify. It means we don't need to pass in a CtOrigin.
tcSubType :: CtOriginUsed when instantiating
-> UserTypeCtxtUsed when skolemising
-> Maybe TypedThingThe expression that has type
actual(if known)-> TcSigmaTypeActual type
-> ExpRhoTypeExpected type
-> TcM HsWrapper
Checks that the actual type is more polymorphic than the expected type.
Connect up the inferred type of an application with the expected type. This is usually just a unification, but with deep subsumption there is more to do.
tcSubTypeHoleFit :: DeepSubsumptionFlag-> CtOrigin-> TcSigmaTypeCandidate expression type
-> TcSigmaTypeExpected type (= hole type)
-> TcM HsWrapper
Constructors
ShallowShallow subsumption; don't instantiate under arrows
forall a. a->a forall b. [b]-[b]Deep DeepSubsumptionDepthDo deep subsumption up to the specified depth.
See
recurInArgumentDSFlag.
Instances1Outputable
Outputable DeepSubsumptionFlagDefined in ghc-10.0.0.20260917 · GHC.Tc.Utils.Unify
Constructors
TopSubTop-level subsumption: instantiate under top-level covariant arrows only
Int -> forall a. a->a (Int - forall b. [b] -> [b])DeepSubDeep subsumption: instantiate under all arrows (covariant and contravariant)
(forall b. [b] -> [b]) -> Int (forall a. a-a) -> Int
Variant of getDeepSubsumptionFlag which enables a top-level subsumption in order to implement the plan of Note [Typechecking data constructors].
The wrapper has type: spec_ty ~~> expected_ty See Note [Skolemisation] for the differences between tcSkolemiseCompleteSig and tcTopSkolemise
unifyType :: Maybe TypedThingIf present, the thing that has type ty1
-> TcTauType-> TcTauType-> TcM TcCoercionN
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
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].
Constructors
UEu_role :: Roleu_loc :: CtLocu_rewriters :: CoHoleSetu_given_eq_lvl :: TcLevelu_defer :: TcRef (Bag Ct)u_what :: WhatUnifications
Instances1Outputable
Outputable WhatUnificationsDefined in ghc-10.0.0.20260917 · GHC.Tc.Utils.Unify
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 :: TypedThingtype, only for errors
-> Arityn: number of desired arrows
-> TcKindfun_kind
-> TcM Coercionco :: fun_kind ~ (arg1 -> ... -> argn -> res)
Breaks apart a function kind into its pieces.
matchActualFunTy :: ExpectedFunTyCtxtSee Note [Herald for matchExpectedFunTys]
-> Maybe TypedThingThe 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)
-> TcRhoTypeType to analyse: a TcRhoType
-> 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].
matchActualFunTys :: ExpectedFunTyCtxtSee 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].
Perform the checks specified by the TyEqFlags on the RHS, in order to enforce the unification preconditions of Note [Unification preconditions].
See Note [checkTyEqRhs].
Constructors
PuFail CheckTyEqResultPure unifier failure.
Invariant: the CheckTyEqResult is not cteOK; that it, it specifies a problem.
PuOK (Bag a) bPure unifier success.
Instances5Functor, Applicative, Foldable, Traversable, Outputable
Functor (PuResult a)Defined in ghc-10.0.0.20260917 · GHC.Tc.Utils.UnifyApplicative (PuResult a)Defined in ghc-10.0.0.20260917 · GHC.Tc.Utils.UnifyFoldable (PuResult a)Defined in ghc-10.0.0.20260917 · GHC.Tc.Utils.UnifyTraversable (PuResult a)Defined in ghc-10.0.0.20260917 · GHC.Tc.Utils.Unify(Outputable a, Outputable b) => Outputable (PuResult a b)Defined in ghc-10.0.0.20260917 · GHC.Tc.Utils.Unify
Options describing how to deal with a type equality in the eager unifier. See checkTyEqRhs
Constructors
TEFTyFamTFTyFam: LHS is a type family application Invariant: we are not unifying; see notUnifying_TEFTask
tefTyFam_occursCheck :: CheckTyEqProblemThe CheckTyEqProblem to report for occurs-check failures (soluble or insoluble)
tefTyFam_tyCon :: TyContefTyFam_args :: [Type]tef_fam_app :: TyEqFamApp m aHow to deal with type family applications
TEFTyVarTEFTyVar: LHS is a TyVar.
tefTyVar_occursCheck :: OccursCheckOccurs check
tefTyVar_levelCheck :: LevelCheck mLevel check
tefTyVar_concreteCheck :: ConcreteCheck mConcreteness check
tef_fam_app :: TyEqFamApp m aHow to deal with type family applications
Instances1Outputable
Outputable (TyEqFlags m a)Defined in ghc-10.0.0.20260917 · GHC.Tc.Utils.Unify
TyEqFlags for a pure call of checkTyEqRhs.
A call to checkTyEqRhs with these TyEqFlags will perform an optimistic check: it will return PuFail if there is definitely a problem, but it might return PuOK if it isn't entirely sure.
Constructors
OC_None :: OccursCheckNo occurs check.
OC_Check :: Name -> CheckTyEqProblem -> OccursCheckDo an occurs check between the LHS tyvar and the RHS.
occurs_tv_name :: NameThe Name to perform an occurs-check on
occurs_problem :: CheckTyEqProblemWhich CheckTyEqProblem to report for occurs-check failures (soluble or insoluble)
Instances1Outputable
Outputable OccursCheckDefined in ghc-10.0.0.20260917 · GHC.Tc.Utils.Unify
What level check to perform, in a call to the pure unifier?
A defunctionalisation of the possible level-check functions
Interpreter: tyVarLevelCheck
Constructors
LC_None :: LevelCheck mNo level check.
LC_Check :: TcLevel -> Bool -> LevelCheck mDo a level check between the LHS tyvar and the occurrence tyvar.
Fail if the level check fails.
True = lenient check, e.g. the levels have a chance of working out after promotion.
lc_lvlc :: TcLevellc_lenient :: Bool
LC_Promote :: TcLevel -> Bool -> LevelCheck (IOEnv (Env TcGblEnv TcLclEnv))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.
Instances1Outputable
Outputable (LevelCheck m)Defined in ghc-10.0.0.20260917 · GHC.Tc.Utils.Unify
Constructors
CC_None :: ConcreteCheck mNo concreteness check.
CC_Check :: ConcreteCheck mSimple check for concreteness, leniently returning
OKif concreteness could be achieved after promotion.CC_Promote :: ConcreteTvOrigin -> ConcreteCheck (IOEnv (Env TcGblEnv TcLclEnv))Proper concreteness check: promote non-concrete metavariables, failing if there are any problems.
Instances1Outputable
Outputable (ConcreteCheck m)Defined in ghc-10.0.0.20260917 · GHC.Tc.Utils.Unify
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_Recurse :: TyEqFamApp m aJust recurse
TEFA_Break :: FamAppBreaker a -> TyEqFamApp (IOEnv (Env TcGblEnv TcLclEnv)) aRecurse, but replace with cycle breaker if that fails, using the specified FamAppBreaker
Instances1Outputable
Outputable (TyEqFamApp m a)Defined in ghc-10.0.0.20260917 · GHC.Tc.Utils.Unify
A defunctionalisation of family application breaker functions.
Interpreter: famAppBreaker
Constructors
BreakGiven :: FamAppBreaker (TcTyVar, TcType)BreakWanted :: CtEvidence -> TcTyVar -> FamAppBreaker Ct
Instances1Outputable
Outputable (FamAppBreaker a)Defined in ghc-10.0.0.20260917 · GHC.Tc.Utils.Unify
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
The result type of simpleUnifyCheck.
Constructors
SUC_CannotUnifyDefinitely cannot unify (untouchable variable or incompatible top-shape)
SUC_NotSureThe variable is touchable and the top-shape test passed, but it may or may not be OK to unify
SUC_CanUnifyDefinitely OK to unify
Instances5Eq, Ord, Show, Semigroup, Outputable
Eq SimpleUnifyResultDefined in ghc-10.0.0.20260917 · GHC.Tc.Utils.UnifyOrd SimpleUnifyResultDefined in ghc-10.0.0.20260917 · GHC.Tc.Utils.UnifyShow SimpleUnifyResultDefined in ghc-10.0.0.20260917 · GHC.Tc.Utils.UnifySemigroup SimpleUnifyResultDefined in ghc-10.0.0.20260917 · GHC.Tc.Utils.UnifyOutputable SimpleUnifyResultDefined in ghc-10.0.0.20260917 · GHC.Tc.Utils.Unify
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
t2is at the same level as given by the ir_lvl field.FRR invariant. Whenever the ir_frr field is IFRR_Check,
t2is guaranteed to have a syntactically fixed RuntimeRep, in the sense of Note [Fixed RuntimeRep] in GHC.Tc.Utils.Concrete.