GHC.Core.TyCo.Subst
Substitution into types and coercions.
Substitutions
Type & coercion substitution
The following invariants must hold of a TCvSubst
:
- The in-scope set is needed only to guide the generation of fresh uniques
- In particular, the kind of the type variables in the in-scope set is not relevant
- The substitution is only applied ONCE! This is because in general such application will not reach a fixed point.
Constructors
TCvSubst InScopeSet TvSubstEnv CvSubstEnv |
Instances
composeTCvSubstEnv :: InScopeSet -> (TvSubstEnv, CvSubstEnv) -> (TvSubstEnv, CvSubstEnv) -> (TvSubstEnv, CvSubstEnv) Source #
(compose env1 env2)(x)
is env1(env2(x))
; i.e. apply env2
then env1
.
It assumes that both are idempotent.
Typically, env1
is the refinement to a base substitution env2
composeTCvSubst :: TCvSubst -> TCvSubst -> TCvSubst Source #
Composes two substitutions, applying the second one provided first, like in function composition.
mkEmptyTCvSubst :: InScopeSet -> TCvSubst Source #
isEmptyTCvSubst :: TCvSubst -> Bool Source #
mkTCvSubst :: InScopeSet -> (TvSubstEnv, CvSubstEnv) -> TCvSubst Source #
mkTvSubst :: InScopeSet -> TvSubstEnv -> TCvSubst Source #
Make a TCvSubst with specified tyvar subst and empty covar subst
mkCvSubst :: InScopeSet -> CvSubstEnv -> TCvSubst Source #
Make a TCvSubst with specified covar subst and empty tyvar subst
getTvSubstEnv :: TCvSubst -> TvSubstEnv Source #
getCvSubstEnv :: TCvSubst -> CvSubstEnv Source #
getTCvInScope :: TCvSubst -> InScopeSet Source #
getTCvSubstRangeFVs :: TCvSubst -> VarSet Source #
Returns the free variables of the types in the range of a substitution as a non-deterministic set.
setTvSubstEnv :: TCvSubst -> TvSubstEnv -> TCvSubst Source #
setCvSubstEnv :: TCvSubst -> CvSubstEnv -> TCvSubst Source #
zapTCvSubst :: TCvSubst -> TCvSubst Source #
extendTvSubstBinderAndInScope :: TCvSubst -> TyCoBinder -> Type -> TCvSubst Source #
zipTyEnv :: HasDebugCallStack => [TyVar] -> [Type] -> TvSubstEnv Source #
zipCoEnv :: HasDebugCallStack => [CoVar] -> [Coercion] -> CvSubstEnv Source #
zipTvSubst :: HasDebugCallStack => [TyVar] -> [Type] -> TCvSubst Source #
Generates the in-scope set for the TCvSubst
from the types in the incoming
environment. No CoVars, please!
zipCvSubst :: HasDebugCallStack => [CoVar] -> [Coercion] -> TCvSubst Source #
Generates the in-scope set for the TCvSubst
from the types in the incoming
environment. No TyVars, please!
zipTCvSubst :: HasDebugCallStack => [TyCoVar] -> [Type] -> TCvSubst Source #
mkTvSubstPrs :: [(TyVar, Type)] -> TCvSubst Source #
Generates the in-scope set for the TCvSubst
from the types in the
incoming environment. No CoVars, please!
substTyWith :: HasDebugCallStack => [TyVar] -> [Type] -> Type -> Type Source #
Type substitution, see zipTvSubst
substTysWith :: [TyVar] -> [Type] -> [Type] -> [Type] Source #
Type substitution, see zipTvSubst
substTysWithCoVars :: [CoVar] -> [Coercion] -> [Type] -> [Type] Source #
Type substitution, see zipTvSubst
substCoWith :: HasDebugCallStack => [TyVar] -> [Type] -> Coercion -> Coercion Source #
Coercion substitution, see zipTvSubst
substTy :: HasDebugCallStack => TCvSubst -> Type -> Type Source #
Substitute within a Type
The substitution has to satisfy the invariants described in
Note [The substitution invariant].
substTyAddInScope :: TCvSubst -> 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 => TCvSubst -> Scaled Type -> Scaled Type Source #
substTyUnchecked :: TCvSubst -> 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 :: TCvSubst -> [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 :: TCvSubst -> 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 => TCvSubst -> Scaled Type -> Scaled Type Source #
substCoUnchecked :: TCvSubst -> 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 :: 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 => TCvSubst -> [Type] -> [Type] Source #
Substitute within several Type
s
The substitution has to satisfy the invariants described in
Note [The substitution invariant].
substScaledTys :: HasDebugCallStack => TCvSubst -> [Scaled Type] -> [Scaled Type] Source #
substTheta :: HasDebugCallStack => TCvSubst -> ThetaType -> ThetaType Source #
Substitute within a ThetaType
The substitution has to satisfy the invariants described in
Note [The substitution invariant].
substCo :: HasDebugCallStack => TCvSubst -> Coercion -> Coercion Source #
Substitute within a Coercion
The substitution has to satisfy the invariants described in
Note [The substitution invariant].
substCos :: HasDebugCallStack => TCvSubst -> [Coercion] -> [Coercion] Source #
Substitute within several Coercion
s
The substitution has to satisfy the invariants described in
Note [The substitution invariant].
cloneTyVarBndrs :: TCvSubst -> [TyVar] -> UniqSupply -> (TCvSubst, [TyVar]) Source #
substVarBndr :: HasDebugCallStack => TCvSubst -> TyCoVar -> (TCvSubst, TyCoVar) Source #
substVarBndrs :: HasDebugCallStack => TCvSubst -> [TyCoVar] -> (TCvSubst, [TyCoVar]) Source #
substTyVarBndr :: HasDebugCallStack => TCvSubst -> TyVar -> (TCvSubst, TyVar) Source #
substTyVarBndrs :: HasDebugCallStack => TCvSubst -> [TyVar] -> (TCvSubst, [TyVar]) Source #
substCoVarBndr :: HasDebugCallStack => TCvSubst -> CoVar -> (TCvSubst, CoVar) Source #
substTyCoBndr :: TCvSubst -> TyCoBinder -> (TCvSubst, TyCoBinder) Source #
substForAllCoBndr :: TCvSubst -> TyCoVar -> KindCoercion -> (TCvSubst, TyCoVar, Coercion) Source #
substVarBndrUsing :: (TCvSubst -> Type -> Type) -> TCvSubst -> TyCoVar -> (TCvSubst, TyCoVar) Source #
substForAllCoBndrUsing :: Bool -> (Coercion -> Coercion) -> TCvSubst -> TyCoVar -> KindCoercion -> (TCvSubst, TyCoVar, KindCoercion) Source #
checkValidSubst :: HasDebugCallStack => TCvSubst -> [Type] -> [Coercion] -> a -> a Source #
This checks if the substitution satisfies the invariant from Note [The substitution invariant].