| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
GHC.Tc.Utils.TcMType
Contents
Description
Monadic type operations
This module contains monadic operations over types that contain mutable type variables.
Synopsis
- type TcTyVar = Var
- type TcKind = Kind
- type TcType = Type
- type TcTauType = TcType
- type TcThetaType = ThetaType
- type TcTyVarSet = TyVarSet
- newFlexiTyVar :: Kind -> TcM TcTyVar
- newNamedFlexiTyVar :: FastString -> Kind -> TcM TcTyVar
- newFlexiTyVarTy :: Kind -> TcM TcType
- newFlexiTyVarTys :: Int -> Kind -> TcM [TcType]
- newOpenFlexiTyVar :: TcM TcTyVar
- newOpenFlexiTyVarTy :: TcM TcType
- newOpenTypeKind :: TcM TcKind
- newOpenFlexiFRRTyVar :: FixedRuntimeRepContext -> TcM TcTyVar
- newOpenFlexiFRRTyVarTy :: FixedRuntimeRepContext -> TcM TcType
- newOpenBoxedTypeKind :: TcM TcKind
- newMetaKindVar :: TcM TcKind
- newMetaKindVars :: Int -> TcM [TcKind]
- newMetaTyVarTyAtLevel :: TcLevel -> TcKind -> TcM TcType
- newConcreteTyVarTyAtLevel :: ConcreteTvOrigin -> TcLevel -> TcKind -> TcM TcType
- substConcreteTvOrigin :: Subst -> Type -> ConcreteTvOrigin -> ConcreteTvOrigin
- newAnonMetaTyVar :: MetaInfo -> Kind -> TcM TcTyVar
- newConcreteTyVar :: HasDebugCallStack => ConcreteTvOrigin -> FastString -> TcKind -> TcM TcTyVar
- cloneMetaTyVar :: TcTyVar -> TcM TcTyVar
- cloneMetaTyVarWithInfo :: MetaInfo -> TcLevel -> TcTyVar -> TcM TcTyVar
- newCycleBreakerTyVar :: TcKind -> TcM TcTyVar
- newMultiplicityVar :: TcM TcType
- readMetaTyVar :: MonadIO m => TyVar -> m MetaDetails
- writeMetaTyVar :: HasDebugCallStack => TcTyVar -> TcType -> ZonkM ()
- writeMetaTyVarRef :: HasDebugCallStack => TcTyVar -> TcRef MetaDetails -> TcType -> ZonkM ()
- newTauTvDetailsAtLevel :: TcLevel -> TcM TcTyVarDetails
- newMetaDetails :: MetaInfo -> TcM TcTyVarDetails
- newMetaTyVarName :: FastString -> TcM Name
- isFilledMetaTyVar_maybe :: TcTyVar -> TcM (Maybe Type)
- isFilledMetaTyVar :: TyVar -> TcM Bool
- isUnfilledMetaTyVar :: TyVar -> TcM Bool
- newEvVar :: TcPredType -> TcRnIf gbl lcl EvVar
- newEvVars :: TcThetaType -> TcM [EvVar]
- newDict :: Class -> [TcType] -> TcM DictId
- newWantedWithLoc :: CtLoc -> PredType -> TcM CtEvidence
- newWanted :: CtOrigin -> Maybe TypeOrKind -> PredType -> TcM CtEvidence
- newWanteds :: CtOrigin -> ThetaType -> TcM [CtEvidence]
- cloneWanted :: Ct -> TcM Ct
- cloneWC :: WantedConstraints -> TcM WantedConstraints
- cloneWantedCtEv :: CtEvidence -> TcM CtEvidence
- emitWanted :: CtOrigin -> TcPredType -> TcM EvTerm
- emitWantedEq :: CtOrigin -> TypeOrKind -> Role -> TcType -> TcType -> TcM Coercion
- emitWantedEvVar :: CtOrigin -> TcPredType -> TcM EvVar
- emitWantedEqs :: CtOrigin -> [(TcType, TcType)] -> TcM ()
- newTcEvBinds :: TcM EvBindsVar
- newNoTcEvBinds :: TcM EvBindsVar
- addTcEvBind :: EvBindsVar -> EvBind -> TcM ()
- emitNewExprHole :: RdrName -> Type -> TcM HoleExprRef
- newCoercionHole :: TcPredType -> TcM CoercionHole
- fillCoercionHole :: CoercionHole -> Coercion -> TcM ()
- isFilledCoercionHole :: CoercionHole -> ZonkM Bool
- checkCoercionHole :: CoVar -> Coercion -> ZonkM Coercion
- newImplication :: TcM Implication
- newMetaTyVars :: [TyVar] -> TcM (Subst, [TcTyVar])
- newMetaTyVarX :: Subst -> TyVar -> TcM (Subst, TcTyVar)
- newMetaTyVarsX :: Subst -> [TyVar] -> TcM (Subst, [TcTyVar])
- newMetaTyVarBndrsX :: Subst -> [VarBndr TyVar vis] -> TcM (Subst, [VarBndr TcTyVar vis])
- newMetaTyVarTyVarX :: Subst -> TyVar -> TcM (Subst, TcTyVar)
- newTyVarTyVar :: Name -> Kind -> TcM TcTyVar
- cloneTyVarTyVar :: Name -> Kind -> TcM TcTyVar
- newConcreteTyVarX :: ConcreteTvOrigin -> Subst -> TyVar -> TcM (Subst, TcTyVar)
- newPatTyVar :: Name -> Kind -> TcM TcTyVar
- newSkolemTyVar :: SkolemInfo -> Name -> Kind -> TcM TcTyVar
- newWildCardX :: Subst -> TyVar -> TcM (Subst, TcTyVar)
- data ExpType
- = Check TcType
- | Infer !InferResult
- type ExpSigmaType = ExpType
- type ExpRhoType = ExpType
- mkCheckExpType :: TcType -> ExpType
- newInferExpType :: InferInstFlag -> TcM ExpType
- newInferExpTypeFRR :: InferInstFlag -> FixedRuntimeRepContext -> TcM ExpTypeFRR
- runInfer :: InferInstFlag -> InferFRRFlag -> (ExpSigmaType -> TcM a) -> TcM (a, TcSigmaType)
- runInferRho :: (ExpRhoType -> TcM a) -> TcM (a, TcRhoType)
- runInferSigma :: (ExpSigmaType -> TcM a) -> TcM (a, TcSigmaType)
- runInferKind :: (ExpSigmaType -> TcM a) -> TcM (a, TcSigmaType)
- runInferRhoFRR :: FixedRuntimeRepContext -> (ExpRhoTypeFRR -> TcM a) -> TcM (a, TcRhoTypeFRR)
- runInferSigmaFRR :: FixedRuntimeRepContext -> (ExpSigmaTypeFRR -> TcM a) -> TcM (a, TcSigmaTypeFRR)
- readExpType :: MonadIO m => ExpType -> m TcType
- readExpType_maybe :: MonadIO m => ExpType -> m (Maybe TcType)
- readScaledExpType :: MonadIO m => Scaled ExpType -> m (Scaled Type)
- expTypeToType :: ExpType -> TcM TcType
- scaledExpTypeToType :: Scaled ExpType -> TcM (Scaled TcType)
- checkingExpType_maybe :: ExpType -> Maybe TcType
- checkingExpType :: ExpType -> TcType
- inferResultToType :: InferResult -> TcM Type
- ensureMonoType :: TcType -> TcM ()
- promoteTcType :: TcLevel -> TcType -> TcM (TcCoercionN, TcType)
- tcCheckUsage :: Name -> Mult -> TcM a -> TcM a
- defaultTyVar :: DefaultingStrategy -> TcTyVar -> TcM Bool
- promoteMetaTyVarTo :: HasDebugCallStack => TcLevel -> TcTyVar -> TcM Bool
- promoteTyVarSet :: HasDebugCallStack => TcTyVarSet -> TcM Bool
- quantifyTyVars :: SkolemInfo -> NonStandardDefaultingStrategy -> CandidatesQTvs -> TcM [TcTyVar]
- doNotQuantifyTyVars :: CandidatesQTvs -> (TidyEnv -> ZonkM (TidyEnv, UninferrableTyVarCtx)) -> TcM ()
- zonkAndSkolemise :: SkolemInfo -> TcTyCoVar -> ZonkM TcTyCoVar
- skolemiseQuantifiedTyVar :: SkolemInfo -> TcTyVar -> ZonkM TcTyVar
- candidateQTyVarsOfType :: TcType -> TcM CandidatesQTvs
- candidateQTyVarsOfKind :: TcKind -> TcM CandidatesQTvs
- candidateQTyVarsOfTypes :: [Type] -> TcM CandidatesQTvs
- candidateQTyVarsOfKinds :: [TcKind] -> TcM CandidatesQTvs
- candidateQTyVarsWithBinders :: [TyVar] -> Type -> TcM CandidatesQTvs
- weedOutCandidates :: (DTyVarSet -> DTyVarSet) -> CandidatesQTvs -> CandidatesQTvs
- data CandidatesQTvs = DV {}
- delCandidates :: CandidatesQTvs -> [Var] -> CandidatesQTvs
- candidateKindVars :: CandidatesQTvs -> TyVarSet
- partitionCandidates :: CandidatesQTvs -> (TyVar -> Bool) -> (TyVarSet, CandidatesQTvs)
- checkTypeHasFixedRuntimeRep :: FixedRuntimeRepProvenance -> Type -> TcM ()
- mkHsDictLet :: TcEvBinds -> LHsExpr GhcTc -> LHsExpr GhcTc
- mkHsApp :: forall (id :: Pass). LHsExpr (GhcPass id) -> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
- mkHsAppTy :: forall (p :: Pass). LHsType (GhcPass p) -> LHsType (GhcPass p) -> LHsType (GhcPass p)
- mkHsCaseAlt :: forall (p :: Pass) body. (Anno (GRHS (GhcPass p) (LocatedA (body (GhcPass p)))) ~ EpAnn NoEpAnns, Anno (Match (GhcPass p) (LocatedA (body (GhcPass p)))) ~ SrcSpanAnnA) => LPat (GhcPass p) -> LocatedA (body (GhcPass p)) -> LMatch (GhcPass p) (LocatedA (body (GhcPass p)))
- tcShortCutLit :: HsOverLit GhcRn -> ExpRhoType -> TcM (Maybe (HsOverLit GhcTc))
- shortCutLit :: Platform -> OverLitVal -> TcType -> Maybe (HsExpr GhcTc)
- hsOverLitName :: OverLitVal -> Name
- conLikeResTy :: ConLike -> [Type] -> Type
Documentation
type TcThetaType = ThetaType #
type TcTyVarSet = TyVarSet #
newFlexiTyVar :: Kind -> TcM TcTyVar #
newNamedFlexiTyVar :: FastString -> Kind -> TcM TcTyVar #
Create a new flexi ty var with a specific name
newFlexiTyVarTy :: Kind -> TcM TcType #
newOpenFlexiTyVarTy :: TcM TcType #
Create a tyvar that can be a lifted or unlifted type.
Returns alpha :: TYPE kappa, where both alpha and kappa are fresh.
Note: you should use newOpenFlexiFRRTyVarTy if you also need to ensure
that the representation is concrete, in the sense of Note [Concrete types]
in GHC.Tc.Utils.Concrete.
newOpenFlexiFRRTyVar :: FixedRuntimeRepContext -> TcM TcTyVar #
Like newOpenFlexiTyVar, but ensures the type variable has a
syntactically fixed RuntimeRep in the sense of Note [Fixed RuntimeRep]
in GHC.Tc.Utils.Concrete.
newMetaKindVar :: TcM TcKind #
newMetaKindVars :: Int -> TcM [TcKind] #
newConcreteTyVarTyAtLevel :: ConcreteTvOrigin -> TcLevel -> TcKind -> TcM TcType #
substConcreteTvOrigin :: Subst -> Type -> ConcreteTvOrigin -> ConcreteTvOrigin #
newConcreteTyVar :: HasDebugCallStack => ConcreteTvOrigin -> FastString -> TcKind -> TcM TcTyVar #
Create a new metavariable, of the given kind, which can only be unified with a concrete type.
Invariant: the kind must be concrete, as per Note [ConcreteTv]. This is checked with an assertion.
cloneMetaTyVar :: TcTyVar -> TcM TcTyVar #
newCycleBreakerTyVar :: TcKind -> TcM TcTyVar #
Make a new cycle-breaker type variable. See Note [Type equality cycles] in GHC.Tc.Solver.Equality.
readMetaTyVar :: MonadIO m => TyVar -> m MetaDetails #
Arguments
| :: HasDebugCallStack | |
| => TcTyVar | the type varfiable to write to |
| -> TcType | the type to write into the mutable reference |
| -> ZonkM () |
Write into a currently-empty MetaTyVar.
Works with both type and kind variables.
Arguments
| :: HasDebugCallStack | |
| => TcTyVar | for debug assertions only; |
| -> TcRef MetaDetails | ref cell must be for the same tyvar |
| -> TcType | the type to write to the mutable reference |
| -> ZonkM () |
Write into the MetaDetails mutable references of a MetaTv.
newMetaDetails :: MetaInfo -> TcM TcTyVarDetails #
newMetaTyVarName :: FastString -> TcM Name #
isFilledMetaTyVar :: TyVar -> TcM Bool #
isUnfilledMetaTyVar :: TyVar -> TcM Bool #
newEvVar :: TcPredType -> TcRnIf gbl lcl EvVar #
newEvVars :: TcThetaType -> TcM [EvVar] #
newWantedWithLoc :: CtLoc -> PredType -> TcM CtEvidence #
Create a new Wanted constraint with the given CtLoc.
newWanted :: CtOrigin -> Maybe TypeOrKind -> PredType -> TcM CtEvidence #
newWanteds :: CtOrigin -> ThetaType -> TcM [CtEvidence] #
cloneWanted :: Ct -> TcM Ct #
cloneWantedCtEv :: CtEvidence -> TcM CtEvidence #
emitWanted :: CtOrigin -> TcPredType -> TcM EvTerm #
Emits a new Wanted. Deals with both equalities and non-equalities.
emitWantedEq :: CtOrigin -> TypeOrKind -> Role -> TcType -> TcType -> TcM Coercion #
Emits a new equality constraint
emitWantedEvVar :: CtOrigin -> TcPredType -> TcM EvVar #
Creates a new EvVar and immediately emits it as a Wanted. No equality predicates here.
newNoTcEvBinds :: TcM EvBindsVar #
Creates an EvBindsVar incapable of holding any bindings. It still tracks covar usages (see comments on ebv_tcvs in GHC.Tc.Types.Evidence), thus must be made monadically
addTcEvBind :: EvBindsVar -> EvBind -> TcM () #
emitNewExprHole :: RdrName -> Type -> TcM HoleExprRef #
Emit a new wanted expression hole
fillCoercionHole :: CoercionHole -> Coercion -> TcM () #
Put a value in a coercion hole
isFilledCoercionHole :: CoercionHole -> ZonkM Bool #
Is a coercion hole filled in?
checkCoercionHole :: CoVar -> Coercion -> ZonkM Coercion #
Debugging-only! Check that a coercion is appropriate for filling a hole. (The hole itself is needed only for printing.)
Always returns the checked coercion, but this return value is necessary so that the input coercion is forced only when the output is forced.
newImplication :: TcM Implication #
Create a new Implication with as many sensible defaults for its fields
as possible. Note that the ic_tclvl, ic_binds, and ic_info fields do
not have sensible defaults, so they are initialized with lazy thunks that
will panic if forced, so one should take care to initialize these fields
after creation.
This is monadic to look up the TcLclEnv, which is used to initialize
ic_env, and to set the -Winaccessible-code flag. See
Note [Avoid -Winaccessible-code when deriving] in GHC.Tc.TyCl.Instance.
newConcreteTyVarX :: ConcreteTvOrigin -> Subst -> TyVar -> TcM (Subst, TcTyVar) #
Like newMetaTyVarX, but for concrete type variables.
newSkolemTyVar :: SkolemInfo -> Name -> Kind -> TcM TcTyVar #
An expected type to check against during type-checking. See Note [ExpType] in GHC.Tc.Utils.TcMType, where you'll also find manipulators.
Constructors
| Check TcType | |
| Infer !InferResult |
Instances
| Outputable ExpType # | |
Defined in GHC.Tc.Utils.TcType | |
type ExpSigmaType = ExpType #
type ExpRhoType = ExpType #
mkCheckExpType :: TcType -> ExpType #
Make an ExpType suitable for checking.
newInferExpType :: InferInstFlag -> TcM ExpType #
runInfer :: InferInstFlag -> InferFRRFlag -> (ExpSigmaType -> TcM a) -> TcM (a, TcSigmaType) #
runInferRho :: (ExpRhoType -> TcM a) -> TcM (a, TcRhoType) #
runInferSigma :: (ExpSigmaType -> TcM a) -> TcM (a, TcSigmaType) #
Infer a type using a fresh ExpType See also Note [ExpType] in GHC.Tc.Utils.TcMType
Use runInferFRR if you require the type to have a fixed
runtime representation.
runInferKind :: (ExpSigmaType -> TcM a) -> TcM (a, TcSigmaType) #
runInferRhoFRR :: FixedRuntimeRepContext -> (ExpRhoTypeFRR -> TcM a) -> TcM (a, TcRhoTypeFRR) #
Like runInferRho, except it ensures that the resulting type
has a syntactically fixed RuntimeRep as per Note [Fixed RuntimeRep] in
GHC.Tc.Utils.Concrete.
runInferSigmaFRR :: FixedRuntimeRepContext -> (ExpSigmaTypeFRR -> TcM a) -> TcM (a, TcSigmaTypeFRR) #
readExpType :: MonadIO m => ExpType -> m TcType #
Extract a type out of an ExpType. Otherwise, panics.
readExpType_maybe :: MonadIO m => ExpType -> m (Maybe TcType) #
Extract a type out of an ExpType, if one exists. But one should always exist. Unless you're quite sure you know what you're doing.
readScaledExpType :: MonadIO m => Scaled ExpType -> m (Scaled Type) #
Same as readExpType, but for Scaled ExpTypes
expTypeToType :: ExpType -> TcM TcType #
Extracts the expected type if there is one, or generates a new TauTv if there isn't.
checkingExpType_maybe :: ExpType -> Maybe TcType #
Returns the expected type when in checking mode.
checkingExpType :: ExpType -> TcType #
Returns the expected type when in checking mode. Panics if in inference mode.
inferResultToType :: InferResult -> TcM Type #
ensureMonoType :: TcType -> TcM () #
promoteTcType :: TcLevel -> TcType -> TcM (TcCoercionN, TcType) #
tcCheckUsage :: Name -> Mult -> TcM a -> TcM a #
tcCheckUsage name mult thing_inside runs thing_inside, checks that the
usage of name is a submultiplicity of mult, and removes name from the
usage environment.
defaultTyVar :: DefaultingStrategy -> TcTyVar -> TcM Bool #
Default a type variable using the given defaulting strategy.
See Note [Type variable defaulting options] in GHC.Types.Basic.
promoteMetaTyVarTo :: HasDebugCallStack => TcLevel -> TcTyVar -> TcM Bool #
promoteTyVarSet :: HasDebugCallStack => TcTyVarSet -> TcM Bool #
quantifyTyVars :: SkolemInfo -> NonStandardDefaultingStrategy -> CandidatesQTvs -> TcM [TcTyVar] #
Arguments
| :: CandidatesQTvs | |
| -> (TidyEnv -> ZonkM (TidyEnv, UninferrableTyVarCtx)) | like "the class context (D a b, E foogle)" |
| -> TcM () |
zonkAndSkolemise :: SkolemInfo -> TcTyCoVar -> ZonkM TcTyCoVar #
skolemiseQuantifiedTyVar :: SkolemInfo -> TcTyVar -> ZonkM TcTyVar #
candidateQTyVarsOfType :: TcType -> TcM CandidatesQTvs #
Gathers free variables to use as quantification candidates (in
quantifyTyVars). This might output the same var
in both sets, if it's used in both a type and a kind.
The variables to quantify must have a TcLevel strictly greater than
the ambient level. (See Wrinkle in Note [Naughty quantification candidates])
See Note [CandidatesQTvs determinism and order]
See Note [Dependent type variables]
candidateQTyVarsOfKind :: TcKind -> TcM CandidatesQTvs #
Like candidateQTyVarsOfType, but consider every free variable
to be dependent. This is appropriate when generalizing a *kind*,
instead of a type. (That way, -XNoPolyKinds will default the variables
to Type.)
candidateQTyVarsOfTypes :: [Type] -> TcM CandidatesQTvs #
Like candidateQTyVarsOfType, but over a list of types
The variables to quantify must have a TcLevel strictly greater than
the ambient level. (See Wrinkle in Note [Naughty quantification candidates])
candidateQTyVarsOfKinds :: [TcKind] -> TcM CandidatesQTvs #
candidateQTyVarsWithBinders :: [TyVar] -> Type -> TcM CandidatesQTvs #
weedOutCandidates :: (DTyVarSet -> DTyVarSet) -> CandidatesQTvs -> CandidatesQTvs #
data CandidatesQTvs #
Instances
| Outputable CandidatesQTvs # | |
Defined in GHC.Tc.Utils.TcMType Methods ppr :: CandidatesQTvs -> SDoc # | |
| Monoid CandidatesQTvs # | |
Defined in GHC.Tc.Utils.TcMType Methods mempty :: CandidatesQTvs Source # mappend :: CandidatesQTvs -> CandidatesQTvs -> CandidatesQTvs Source # mconcat :: [CandidatesQTvs] -> CandidatesQTvs Source # | |
| Semigroup CandidatesQTvs # | |
Defined in GHC.Tc.Utils.TcMType Methods (<>) :: CandidatesQTvs -> CandidatesQTvs -> CandidatesQTvs Source # sconcat :: NonEmpty CandidatesQTvs -> CandidatesQTvs Source # stimes :: Integral b => b -> CandidatesQTvs -> CandidatesQTvs Source # | |
delCandidates :: CandidatesQTvs -> [Var] -> CandidatesQTvs #
partitionCandidates :: CandidatesQTvs -> (TyVar -> Bool) -> (TyVarSet, CandidatesQTvs) #
checkTypeHasFixedRuntimeRep :: FixedRuntimeRepProvenance -> Type -> TcM () #
Check that the specified type has a fixed runtime representation.
If it isn't, throw a representation-polymorphism error appropriate
for the context (as specified by the FixedRuntimeRepProvenance).
Unlike the other representation polymorphism checks, which can emit new Wanted constraints to be solved by the constraint solver, this function does not emit any constraints: it has enough information to immediately make a decision.
See (1) in Note [Representation polymorphism checking] in GHC.Tc.Utils.Concrete
Other HsSyn functions
mkHsApp :: forall (id :: Pass). LHsExpr (GhcPass id) -> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id) #
mkHsAppTy :: forall (p :: Pass). LHsType (GhcPass p) -> LHsType (GhcPass p) -> LHsType (GhcPass p) #
mkHsCaseAlt :: forall (p :: Pass) body. (Anno (GRHS (GhcPass p) (LocatedA (body (GhcPass p)))) ~ EpAnn NoEpAnns, Anno (Match (GhcPass p) (LocatedA (body (GhcPass p)))) ~ SrcSpanAnnA) => LPat (GhcPass p) -> LocatedA (body (GhcPass p)) -> LMatch (GhcPass p) (LocatedA (body (GhcPass p))) #
A simple case alternative with a single pattern, no binds, no guards; pre-typechecking
tcShortCutLit :: HsOverLit GhcRn -> ExpRhoType -> TcM (Maybe (HsOverLit GhcTc)) #
shortCutLit :: Platform -> OverLitVal -> TcType -> Maybe (HsExpr GhcTc) #
hsOverLitName :: OverLitVal -> Name #
conLikeResTy :: ConLike -> [Type] -> Type #
Returns the type of the whole pattern