Safe Haskell | None |
---|---|
Language | GHC2021 |
Substitution into types and coercions.
Synopsis
- data Subst = Subst InScopeSet IdSubstEnv TvSubstEnv CvSubstEnv
- type TvSubstEnv = TyVarEnv Type
- type CvSubstEnv = CoVarEnv Coercion
- type IdSubstEnv = IdEnv CoreExpr
- emptyIdSubstEnv :: IdSubstEnv
- emptyTvSubstEnv :: TvSubstEnv
- emptyCvSubstEnv :: CvSubstEnv
- composeTCvSubst :: Subst -> Subst -> Subst
- emptySubst :: Subst
- mkEmptySubst :: InScopeSet -> Subst
- isEmptyTCvSubst :: Subst -> Bool
- isEmptySubst :: Subst -> Bool
- mkTCvSubst :: InScopeSet -> TvSubstEnv -> CvSubstEnv -> Subst
- mkTvSubst :: InScopeSet -> TvSubstEnv -> Subst
- mkCvSubst :: InScopeSet -> CvSubstEnv -> Subst
- mkIdSubst :: InScopeSet -> IdSubstEnv -> Subst
- getTvSubstEnv :: Subst -> TvSubstEnv
- getIdSubstEnv :: Subst -> IdSubstEnv
- getCvSubstEnv :: Subst -> CvSubstEnv
- getSubstInScope :: Subst -> InScopeSet
- setInScope :: Subst -> InScopeSet -> Subst
- getSubstRangeTyCoFVs :: Subst -> VarSet
- isInScope :: Var -> Subst -> Bool
- elemSubst :: Var -> Subst -> Bool
- notElemSubst :: Var -> Subst -> Bool
- zapSubst :: Subst -> Subst
- extendSubstInScope :: Subst -> Var -> Subst
- extendSubstInScopeList :: Subst -> [Var] -> Subst
- extendSubstInScopeSet :: Subst -> VarSet -> Subst
- extendTCvSubst :: Subst -> TyCoVar -> Type -> Subst
- extendTCvSubstWithClone :: Subst -> TyCoVar -> TyCoVar -> Subst
- extendCvSubst :: Subst -> CoVar -> Coercion -> Subst
- extendCvSubstWithClone :: Subst -> CoVar -> CoVar -> Subst
- extendTvSubst :: Subst -> TyVar -> Type -> Subst
- extendTvSubstWithClone :: Subst -> TyVar -> TyVar -> Subst
- extendTvSubstList :: Subst -> [(TyVar, Type)] -> Subst
- extendTvSubstAndInScope :: Subst -> TyVar -> Type -> Subst
- extendTCvSubstList :: Subst -> [Var] -> [Type] -> Subst
- unionSubst :: Subst -> Subst -> Subst
- zipTyEnv :: HasDebugCallStack => [TyVar] -> [Type] -> TvSubstEnv
- zipCoEnv :: HasDebugCallStack => [CoVar] -> [Coercion] -> CvSubstEnv
- zipTvSubst :: HasDebugCallStack => [TyVar] -> [Type] -> Subst
- zipCvSubst :: HasDebugCallStack => [CoVar] -> [Coercion] -> Subst
- zipTCvSubst :: HasDebugCallStack => [TyCoVar] -> [Type] -> Subst
- mkTvSubstPrs :: [(TyVar, Type)] -> Subst
- substTyWith :: HasDebugCallStack => [TyVar] -> [Type] -> Type -> Type
- substTyWithCoVars :: [CoVar] -> [Coercion] -> Type -> Type
- substTysWith :: HasDebugCallStack => [TyVar] -> [Type] -> [Type] -> [Type]
- substTysWithCoVars :: HasDebugCallStack => [CoVar] -> [Coercion] -> [Type] -> [Type]
- substCoWith :: HasDebugCallStack => [TyVar] -> [Type] -> Coercion -> Coercion
- substTy :: HasDebugCallStack => Subst -> Type -> Type
- substTyAddInScope :: HasDebugCallStack => Subst -> Type -> Type
- substScaledTy :: HasDebugCallStack => Subst -> Scaled Type -> Scaled Type
- substTyUnchecked :: Subst -> Type -> Type
- substTysUnchecked :: Subst -> [Type] -> [Type]
- substScaledTysUnchecked :: Subst -> [Scaled Type] -> [Scaled Type]
- substThetaUnchecked :: Subst -> ThetaType -> ThetaType
- substTyWithUnchecked :: [TyVar] -> [Type] -> Type -> Type
- substScaledTyUnchecked :: HasDebugCallStack => Subst -> Scaled Type -> Scaled Type
- substCoUnchecked :: Subst -> Coercion -> Coercion
- substCoWithUnchecked :: [TyVar] -> [Type] -> Coercion -> Coercion
- substTyWithInScope :: HasDebugCallStack => InScopeSet -> [TyVar] -> [Type] -> Type -> Type
- substTys :: HasDebugCallStack => Subst -> [Type] -> [Type]
- substScaledTys :: HasDebugCallStack => Subst -> [Scaled Type] -> [Scaled Type]
- substTheta :: HasDebugCallStack => Subst -> ThetaType -> ThetaType
- lookupTyVar :: Subst -> TyVar -> Maybe Type
- substCo :: HasDebugCallStack => Subst -> Coercion -> Coercion
- substCos :: HasDebugCallStack => Subst -> [Coercion] -> [Coercion]
- substCoVar :: Subst -> CoVar -> Coercion
- substCoVars :: Subst -> [CoVar] -> [Coercion]
- lookupCoVar :: Subst -> Var -> Maybe Coercion
- cloneTyVarBndr :: Subst -> TyVar -> Unique -> (Subst, TyVar)
- cloneTyVarBndrs :: Subst -> [TyVar] -> UniqSupply -> (Subst, [TyVar])
- substVarBndr :: HasDebugCallStack => Subst -> TyCoVar -> (Subst, TyCoVar)
- substVarBndrs :: HasDebugCallStack => Subst -> [TyCoVar] -> (Subst, [TyCoVar])
- substTyVarBndr :: HasDebugCallStack => Subst -> TyVar -> (Subst, TyVar)
- substTyVarBndrs :: HasDebugCallStack => Subst -> [TyVar] -> (Subst, [TyVar])
- substCoVarBndr :: HasDebugCallStack => Subst -> CoVar -> (Subst, CoVar)
- substDCoVarSet :: Subst -> DCoVarSet -> DCoVarSet
- substTyVar :: Subst -> TyVar -> Type
- substTyVars :: Subst -> [TyVar] -> [Type]
- substTyVarToTyVar :: HasDebugCallStack => Subst -> TyVar -> TyVar
- substTyCoVars :: Subst -> [TyCoVar] -> [Type]
- substTyCoBndr :: Subst -> PiTyBinder -> (Subst, PiTyBinder)
- substForAllCoBndr :: Subst -> TyCoVar -> KindCoercion -> (Subst, TyCoVar, Coercion)
- substVarBndrUsing :: (Subst -> Type -> Type) -> Subst -> TyCoVar -> (Subst, TyCoVar)
- substForAllCoBndrUsing :: SwapFlag -> (Coercion -> Coercion) -> Subst -> TyCoVar -> KindCoercion -> (Subst, TyCoVar, KindCoercion)
- checkValidSubst :: HasDebugCallStack => Subst -> [Type] -> [Coercion] -> a -> a
- isValidTCvSubst :: Subst -> Bool
Substitutions
Type & coercion & id substitution
The Subst data type defined in this module contains substitution for tyvar, covar and id. However, operations on IdSubstEnv (mapping from Id to CoreExpr) that require the definition of the Expr data type are defined in GHC.Core.Subst to avoid circular module dependency.
Instances
composeTCvSubst :: Subst -> Subst -> Subst Source #
Composes two substitutions, applying the second one provided first, like in function composition. This function leaves IdSubstEnv untouched because IdSubstEnv is not used during substitution for types.
emptySubst :: Subst Source #
mkEmptySubst :: InScopeSet -> Subst Source #
isEmptyTCvSubst :: Subst -> Bool Source #
Checks whether the tyvar and covar environments are empty.
This function should be used over isEmptySubst
when substituting
for types, because types currently do not contain expressions; we can
safely disregard the expression environment when deciding whether
to skip a substitution. Using isEmptyTCvSubst
gives us a non-trivial
performance boost (up to 70% less allocation for T18223)
isEmptySubst :: Subst -> Bool Source #
mkTCvSubst :: InScopeSet -> TvSubstEnv -> CvSubstEnv -> Subst Source #
mkTvSubst :: InScopeSet -> TvSubstEnv -> Subst Source #
Make a TCvSubst with specified tyvar subst and empty covar subst
mkCvSubst :: InScopeSet -> CvSubstEnv -> Subst Source #
Make a TCvSubst with specified covar subst and empty tyvar subst
mkIdSubst :: InScopeSet -> IdSubstEnv -> Subst Source #
getTvSubstEnv :: Subst -> TvSubstEnv Source #
getIdSubstEnv :: Subst -> IdSubstEnv Source #
getCvSubstEnv :: Subst -> CvSubstEnv Source #
getSubstInScope :: Subst -> InScopeSet Source #
Find the in-scope set: see Note [The substitution invariant]
setInScope :: Subst -> InScopeSet -> Subst Source #
getSubstRangeTyCoFVs :: Subst -> VarSet Source #
Returns the free variables of the types in the range of a substitution as a non-deterministic set.
zapSubst :: Subst -> Subst Source #
Remove all substitutions that might have been built up while preserving the in-scope set originally called zapSubstEnv
extendSubstInScopeList :: Subst -> [Var] -> Subst Source #
Add the Var
s to the in-scope set: see also extendInScope
extendSubstInScopeSet :: Subst -> VarSet -> Subst Source #
Add the Var
s to the in-scope set: see also extendInScope
extendTvSubstList :: Subst -> [(TyVar, Type)] -> Subst Source #
Adds multiple TyVar
substitutions to the Subst
: see also extendTvSubst
zipTyEnv :: HasDebugCallStack => [TyVar] -> [Type] -> TvSubstEnv Source #
The InScopeSet is just a thunk so with a bit of luck it'll never be evaluated
zipCoEnv :: HasDebugCallStack => [CoVar] -> [Coercion] -> CvSubstEnv Source #
zipTvSubst :: HasDebugCallStack => [TyVar] -> [Type] -> Subst Source #
Generates the in-scope set for the Subst
from the types in the incoming
environment. No CoVars or Ids, please!
zipCvSubst :: HasDebugCallStack => [CoVar] -> [Coercion] -> Subst Source #
Generates the in-scope set for the Subst
from the types in the incoming
environment. No TyVars, please!
zipTCvSubst :: HasDebugCallStack => [TyCoVar] -> [Type] -> Subst Source #
mkTvSubstPrs :: [(TyVar, Type)] -> Subst Source #
Generates the in-scope set for the TCvSubst
from the types in the
incoming environment. No CoVars, please! The InScopeSet is just a thunk
so with a bit of luck it'll never be evaluated
substTyWith :: HasDebugCallStack => [TyVar] -> [Type] -> Type -> Type Source #
Type substitution, see zipTvSubst
substTysWith :: HasDebugCallStack => [TyVar] -> [Type] -> [Type] -> [Type] Source #
Type substitution, see zipTvSubst
substTysWithCoVars :: HasDebugCallStack => [CoVar] -> [Coercion] -> [Type] -> [Type] Source #
Type substitution, see zipTvSubst
substCoWith :: HasDebugCallStack => [TyVar] -> [Type] -> Coercion -> Coercion Source #
Coercion substitution, see zipTvSubst
substTy :: HasDebugCallStack => Subst -> Type -> Type Source #
Substitute within a Type
The substitution has to satisfy the invariants described in
Note [The substitution invariant].
substTyAddInScope :: HasDebugCallStack => Subst -> Type -> Type Source #
Substitute within a Type
after adding the free variables of the type
to the in-scope set. This is useful for the case when the free variables
aren't already in the in-scope set or easily available.
See also Note [The substitution invariant].
substScaledTy :: HasDebugCallStack => Subst -> Scaled Type -> Scaled Type Source #
substTyUnchecked :: Subst -> Type -> Type Source #
Substitute within a Type
disabling the sanity checks.
The problems that the sanity checks in substTy catch are described in
Note [The substitution invariant].
The goal of #11371 is to migrate all the calls of substTyUnchecked to
substTy and remove this function. Please don't use in new code.
substTysUnchecked :: Subst -> [Type] -> [Type] Source #
Substitute within several Type
s disabling the sanity checks.
The problems that the sanity checks in substTys catch are described in
Note [The substitution invariant].
The goal of #11371 is to migrate all the calls of substTysUnchecked to
substTys and remove this function. Please don't use in new code.
substThetaUnchecked :: Subst -> ThetaType -> ThetaType Source #
Substitute within a ThetaType
disabling the sanity checks.
The problems that the sanity checks in substTys catch are described in
Note [The substitution invariant].
The goal of #11371 is to migrate all the calls of substThetaUnchecked to
substTheta and remove this function. Please don't use in new code.
substTyWithUnchecked :: [TyVar] -> [Type] -> Type -> Type Source #
Type substitution, see zipTvSubst
. Disables sanity checks.
The problems that the sanity checks in substTy catch are described in
Note [The substitution invariant].
The goal of #11371 is to migrate all the calls of substTyUnchecked to
substTy and remove this function. Please don't use in new code.
substScaledTyUnchecked :: HasDebugCallStack => Subst -> Scaled Type -> Scaled Type Source #
substCoUnchecked :: Subst -> Coercion -> Coercion Source #
Substitute within a Coercion
disabling sanity checks.
The problems that the sanity checks in substCo catch are described in
Note [The substitution invariant].
The goal of #11371 is to migrate all the calls of substCoUnchecked to
substCo and remove this function. Please don't use in new code.
substCoWithUnchecked :: [TyVar] -> [Type] -> Coercion -> Coercion Source #
Coercion substitution, see zipTvSubst
. Disables sanity checks.
The problems that the sanity checks in substCo catch are described in
Note [The substitution invariant].
The goal of #11371 is to migrate all the calls of substCoUnchecked to
substCo and remove this function. Please don't use in new code.
substTyWithInScope :: HasDebugCallStack => InScopeSet -> [TyVar] -> [Type] -> Type -> Type Source #
Substitute tyvars within a type using a known InScopeSet
.
Pre-condition: the in_scope
set should satisfy Note [The substitution
invariant]; specifically it should include the free vars of tys
,
and of ty
minus the domain of the subst.
substTys :: HasDebugCallStack => Subst -> [Type] -> [Type] Source #
Substitute within several Type
s
The substitution has to satisfy the invariants described in
Note [The substitution invariant].
substScaledTys :: HasDebugCallStack => Subst -> [Scaled Type] -> [Scaled Type] Source #
substTheta :: HasDebugCallStack => Subst -> ThetaType -> ThetaType Source #
Substitute within a ThetaType
The substitution has to satisfy the invariants described in
Note [The substitution invariant].
substCo :: HasDebugCallStack => Subst -> Coercion -> Coercion Source #
Substitute within a Coercion
The substitution has to satisfy the invariants described in
Note [The substitution invariant].
substCos :: HasDebugCallStack => Subst -> [Coercion] -> [Coercion] Source #
Substitute within several Coercion
s
The substitution has to satisfy the invariants described in
Note [The substitution invariant].
cloneTyVarBndrs :: Subst -> [TyVar] -> UniqSupply -> (Subst, [TyVar]) Source #
substVarBndr :: HasDebugCallStack => Subst -> TyCoVar -> (Subst, TyCoVar) Source #
substVarBndrs :: HasDebugCallStack => Subst -> [TyCoVar] -> (Subst, [TyCoVar]) Source #
substTyVarBndr :: HasDebugCallStack => Subst -> TyVar -> (Subst, TyVar) Source #
substTyVarBndrs :: HasDebugCallStack => Subst -> [TyVar] -> (Subst, [TyVar]) Source #
substCoVarBndr :: HasDebugCallStack => Subst -> CoVar -> (Subst, CoVar) Source #
substDCoVarSet :: Subst -> DCoVarSet -> DCoVarSet Source #
Perform a substitution within a DVarSet
of free variables,
returning the shallow free coercion variables.
substTyVarToTyVar :: HasDebugCallStack => Subst -> TyVar -> TyVar Source #
substTyCoBndr :: Subst -> PiTyBinder -> (Subst, PiTyBinder) Source #
substForAllCoBndr :: Subst -> TyCoVar -> KindCoercion -> (Subst, TyCoVar, Coercion) Source #
substForAllCoBndrUsing :: SwapFlag -> (Coercion -> Coercion) -> Subst -> TyCoVar -> KindCoercion -> (Subst, TyCoVar, KindCoercion) Source #
checkValidSubst :: HasDebugCallStack => Subst -> [Type] -> [Coercion] -> a -> a Source #
This checks if the substitution satisfies the invariant from Note [The substitution invariant].