Safe Haskell | None |
---|---|
Language | Haskell2010 |
GHC.Tc.Utils.TcMType
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]
- newOpenFlexiTyVarTy :: TcM TcType
- newOpenTypeKind :: TcM TcKind
- newMetaKindVar :: TcM TcKind
- newMetaKindVars :: Int -> TcM [TcKind]
- newMetaTyVarTyAtLevel :: TcLevel -> TcKind -> TcM TcType
- cloneMetaTyVar :: TcTyVar -> TcM TcTyVar
- newFmvTyVar :: TcType -> TcM TcTyVar
- newFskTyVar :: TcType -> TcM TcTyVar
- newMultiplicityVar :: TcM TcType
- readMetaTyVar :: TyVar -> TcM MetaDetails
- writeMetaTyVar :: TcTyVar -> TcType -> TcM ()
- writeMetaTyVarRef :: TcTyVar -> TcRef MetaDetails -> TcType -> TcM ()
- 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
- newWanted :: CtOrigin -> Maybe TypeOrKind -> PredType -> TcM CtEvidence
- newWanteds :: CtOrigin -> ThetaType -> TcM [CtEvidence]
- cloneWanted :: Ct -> TcM Ct
- cloneWC :: WantedConstraints -> TcM WantedConstraints
- emitWanted :: CtOrigin -> TcPredType -> TcM EvTerm
- emitWantedEq :: CtOrigin -> TypeOrKind -> Role -> TcType -> TcType -> TcM Coercion
- emitWantedEvVar :: CtOrigin -> TcPredType -> TcM EvVar
- emitWantedEvVars :: CtOrigin -> [TcPredType] -> TcM [EvVar]
- emitDerivedEqs :: CtOrigin -> [(TcType, TcType)] -> TcM ()
- newTcEvBinds :: TcM EvBindsVar
- newNoTcEvBinds :: TcM EvBindsVar
- addTcEvBind :: EvBindsVar -> EvBind -> TcM ()
- emitNewExprHole :: OccName -> Id -> Type -> TcM ()
- newCoercionHole :: BlockSubstFlag -> TcPredType -> TcM CoercionHole
- fillCoercionHole :: CoercionHole -> Coercion -> TcM ()
- isFilledCoercionHole :: CoercionHole -> TcM Bool
- unpackCoercionHole :: CoercionHole -> TcM Coercion
- unpackCoercionHole_maybe :: CoercionHole -> TcM (Maybe Coercion)
- checkCoercionHole :: CoVar -> Coercion -> TcM Coercion
- newImplication :: TcM Implication
- newMetaTyVars :: [TyVar] -> TcM (TCvSubst, [TcTyVar])
- newMetaTyVarX :: TCvSubst -> TyVar -> TcM (TCvSubst, TcTyVar)
- newMetaTyVarsX :: TCvSubst -> [TyVar] -> TcM (TCvSubst, [TcTyVar])
- newMetaTyVarTyVarX :: TCvSubst -> TyVar -> TcM (TCvSubst, TcTyVar)
- newTyVarTyVar :: Name -> Kind -> TcM TcTyVar
- cloneTyVarTyVar :: Name -> Kind -> TcM TcTyVar
- newPatSigTyVar :: Name -> Kind -> TcM TcTyVar
- newSkolemTyVar :: Name -> Kind -> TcM TcTyVar
- newWildCardX :: TCvSubst -> TyVar -> TcM (TCvSubst, TcTyVar)
- data ExpType
- = Check TcType
- | Infer !InferResult
- type ExpSigmaType = ExpType
- type ExpRhoType = ExpType
- mkCheckExpType :: TcType -> ExpType
- newInferExpType :: TcM ExpType
- tcInfer :: (ExpSigmaType -> TcM a) -> TcM (a, TcSigmaType)
- readExpType :: ExpType -> TcM TcType
- readExpType_maybe :: ExpType -> TcM (Maybe TcType)
- readScaledExpType :: Scaled ExpType -> TcM (Scaled Type)
- expTypeToType :: ExpType -> TcM TcType
- scaledExpTypeToType :: Scaled ExpType -> TcM (Scaled TcType)
- checkingExpType_maybe :: ExpType -> Maybe TcType
- checkingExpType :: String -> ExpType -> TcType
- inferResultToType :: InferResult -> TcM Type
- fillInferResult :: TcType -> InferResult -> TcM TcCoercionN
- promoteTcType :: TcLevel -> TcType -> TcM (TcCoercionN, TcType)
- promoteTyVar :: TcTyVar -> TcM Bool
- promoteTyVarSet :: TcTyVarSet -> TcM Bool
- zonkTidyTcType :: TidyEnv -> TcType -> TcM (TidyEnv, TcType)
- zonkTidyTcTypes :: TidyEnv -> [TcType] -> TcM (TidyEnv, [TcType])
- zonkTidyOrigin :: TidyEnv -> CtOrigin -> TcM (TidyEnv, CtOrigin)
- tidyEvVar :: TidyEnv -> EvVar -> EvVar
- tidyCt :: TidyEnv -> Ct -> Ct
- tidyHole :: TidyEnv -> Hole -> Hole
- tidySkolemInfo :: TidyEnv -> SkolemInfo -> SkolemInfo
- zonkTcTyVar :: TcTyVar -> TcM TcType
- zonkTcTyVars :: [TcTyVar] -> TcM [TcType]
- zonkTcTyVarToTyVar :: HasDebugCallStack => TcTyVar -> TcM TcTyVar
- zonkInvisTVBinder :: VarBndr TcTyVar spec -> TcM (VarBndr TyVar spec)
- zonkTyCoVarsAndFV :: TyCoVarSet -> TcM TyCoVarSet
- zonkTcTypeAndFV :: TcType -> TcM DTyCoVarSet
- zonkDTyCoVarSetAndFV :: DTyCoVarSet -> TcM DTyCoVarSet
- zonkTyCoVarsAndFVList :: [TyCoVar] -> TcM [TyCoVar]
- candidateQTyVarsOfType :: TcType -> TcM CandidatesQTvs
- candidateQTyVarsOfKind :: TcKind -> TcM CandidatesQTvs
- candidateQTyVarsOfTypes :: [Type] -> TcM CandidatesQTvs
- candidateQTyVarsOfKinds :: [TcKind] -> TcM CandidatesQTvs
- data CandidatesQTvs = DV {}
- delCandidates :: CandidatesQTvs -> [Var] -> CandidatesQTvs
- candidateKindVars :: CandidatesQTvs -> TyVarSet
- partitionCandidates :: CandidatesQTvs -> (TyVar -> Bool) -> (TyVarSet, CandidatesQTvs)
- zonkAndSkolemise :: TcTyCoVar -> TcM TcTyCoVar
- skolemiseQuantifiedTyVar :: TcTyVar -> TcM TcTyVar
- defaultTyVar :: Bool -> TcTyVar -> TcM Bool
- quantifyTyVars :: CandidatesQTvs -> TcM [TcTyVar]
- isQuantifiableTv :: TcLevel -> TcTyVar -> Bool
- zonkTcType :: TcType -> TcM TcType
- zonkTcTypes :: [TcType] -> TcM [TcType]
- zonkCo :: Coercion -> TcM Coercion
- zonkTyCoVarKind :: TyCoVar -> TcM TyCoVar
- zonkTyCoVarKindBinder :: VarBndr TyCoVar fl -> TcM (VarBndr TyCoVar fl)
- zonkEvVar :: EvVar -> TcM EvVar
- zonkWC :: WantedConstraints -> TcM WantedConstraints
- zonkImplication :: Implication -> TcM Implication
- zonkSimples :: Cts -> TcM Cts
- zonkId :: TcId -> TcM TcId
- zonkCoVar :: CoVar -> TcM CoVar
- zonkCt :: Ct -> TcM Ct
- zonkSkolemInfo :: SkolemInfo -> TcM SkolemInfo
- skolemiseUnboundMetaTyVar :: TcTyVar -> TcM TyVar
- ensureNotLevPoly :: Type -> SDoc -> TcM ()
- checkForLevPoly :: SDoc -> Type -> TcM ()
- checkForLevPolyX :: Monad m => (SDoc -> m ()) -> SDoc -> Type -> m ()
- formatLevPolyErr :: Type -> SDoc
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
newMetaKindVar :: TcM TcKind #
newMetaKindVars :: Int -> TcM [TcKind] #
cloneMetaTyVar :: TcTyVar -> TcM TcTyVar #
newFmvTyVar :: TcType -> TcM TcTyVar #
newFskTyVar :: TcType -> TcM TcTyVar #
readMetaTyVar :: TyVar -> TcM MetaDetails #
writeMetaTyVar :: TcTyVar -> TcType -> TcM () #
writeMetaTyVarRef :: TcTyVar -> TcRef MetaDetails -> TcType -> TcM () #
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] #
newWanted :: CtOrigin -> Maybe TypeOrKind -> PredType -> TcM CtEvidence #
newWanteds :: CtOrigin -> ThetaType -> TcM [CtEvidence] #
cloneWanted :: Ct -> TcM Ct #
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.
emitWantedEvVars :: CtOrigin -> [TcPredType] -> TcM [EvVar] #
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 () #
newCoercionHole :: BlockSubstFlag -> TcPredType -> TcM CoercionHole #
fillCoercionHole :: CoercionHole -> Coercion -> TcM () #
Put a value in a coercion hole
isFilledCoercionHole :: CoercionHole -> TcM Bool #
Is a coercion hole filled in?
unpackCoercionHole :: CoercionHole -> TcM Coercion #
Retrieve the contents of a coercion hole. Panics if the hole is unfilled
unpackCoercionHole_maybe :: CoercionHole -> TcM (Maybe Coercion) #
Retrieve the contents of a coercion hole, if it is filled
checkCoercionHole :: CoVar -> Coercion -> TcM Coercion #
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.
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 |
type ExpSigmaType = ExpType #
type ExpRhoType = ExpType #
mkCheckExpType :: TcType -> ExpType #
Make an ExpType
suitable for checking.
tcInfer :: (ExpSigmaType -> TcM a) -> TcM (a, TcSigmaType) #
Infer a type using a fresh ExpType See also Note [ExpType] in GHC.Tc.Utils.TcMType
readExpType :: ExpType -> TcM TcType #
Extract a type out of an ExpType. Otherwise, panics.
readExpType_maybe :: ExpType -> TcM (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 :: Scaled ExpType -> TcM (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 :: String -> ExpType -> TcType #
Returns the expected type when in checking mode. Panics if in inference mode.
inferResultToType :: InferResult -> TcM Type #
fillInferResult :: TcType -> InferResult -> TcM TcCoercionN #
promoteTcType :: TcLevel -> TcType -> TcM (TcCoercionN, TcType) #
promoteTyVar :: TcTyVar -> TcM Bool #
promoteTyVarSet :: TcTyVarSet -> TcM Bool #
tidySkolemInfo :: TidyEnv -> SkolemInfo -> SkolemInfo #
zonkTcTyVar :: TcTyVar -> TcM TcType #
zonkTcTyVars :: [TcTyVar] -> TcM [TcType] #
zonkTcTyVarToTyVar :: HasDebugCallStack => TcTyVar -> TcM TcTyVar #
zonkTcTypeAndFV :: TcType -> TcM DTyCoVarSet #
zonkTyCoVarsAndFVList :: [TyCoVar] -> TcM [TyCoVar] #
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 #
data CandidatesQTvs #
Instances
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 # | |
Monoid CandidatesQTvs # | |
Defined in GHC.Tc.Utils.TcMType Methods mempty :: CandidatesQTvs Source # mappend :: CandidatesQTvs -> CandidatesQTvs -> CandidatesQTvs Source # mconcat :: [CandidatesQTvs] -> CandidatesQTvs Source # | |
Outputable CandidatesQTvs # | |
Defined in GHC.Tc.Utils.TcMType |
delCandidates :: CandidatesQTvs -> [Var] -> CandidatesQTvs #
partitionCandidates :: CandidatesQTvs -> (TyVar -> Bool) -> (TyVarSet, CandidatesQTvs) #
zonkAndSkolemise :: TcTyCoVar -> TcM TcTyCoVar #
quantifyTyVars :: CandidatesQTvs -> TcM [TcTyVar] #
isQuantifiableTv :: TcLevel -> TcTyVar -> Bool #
zonkTcType :: TcType -> TcM TcType #
zonkTcTypes :: [TcType] -> TcM [TcType] #
zonkTyCoVarKind :: TyCoVar -> TcM TyCoVar #
zonkSimples :: Cts -> TcM Cts #
zonkSkolemInfo :: SkolemInfo -> TcM SkolemInfo #
ensureNotLevPoly :: Type -> SDoc -> TcM () #
According to the rules around representation polymorphism (see https://gitlab.haskell.org/ghc/ghc/wikis/no-sub-kinds), no binder can have a representation-polymorphic type. This check ensures that we respect this rule. It is a bit regrettable that this error occurs in zonking, after which we should have reported all errors. But it's hard to see where else to do it, because this can be discovered only after all solving is done. And, perhaps most importantly, this isn't really a compositional property of a type system, so it's not a terrible surprise that the check has to go in an awkward spot.
checkForLevPoly :: SDoc -> Type -> TcM () #
formatLevPolyErr :: Type -> SDoc #