HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleghc-9.10.3GHC2021

GHC.Core.TyCo.Subst

Substitution into types and coercions.

  • 4 types
  • 84 values
  • Packageghc-9.10.3
  • Exports88
  • LanguageGHC2021
  • LicenceBSD-3-Clause
  • SourceSubst.hs

Substitutions

88 declarations
datadata Subst
#

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.

Instances1Outputable
valuecomposeTCvSubst :: Subst -> Subst -> Subst
#

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.

valueisEmptyTCvSubst :: Subst -> Bool
#

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)

valuezapSubst :: Subst -> Subst
#

Remove all substitutions that might have been built up while preserving the in-scope set originally called zapSubstEnv

valueextendTvSubst :: Subst -> TyVar -> Type -> Subst
#

Add a substitution for a TyVar to the Subst The TyVar *must* be a real TyVar, and not a CoVar You must ensure that the in-scope set is such that Note [The substitution invariant] holds after extending the substitution like this.

valuemkTvSubstPrs :: [(TyVar, Type)] -> Subst
#

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

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].

valuesubstTyUnchecked :: Subst -> Type -> Type
#

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.

valuesubstTysUnchecked :: Subst -> [Type] -> [Type]
#

Substitute within several Types 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.

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.

valuesubstTyWithUnchecked :: [TyVar] -> [Type] -> Type -> Type
#

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.

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.

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.

valueisValidTCvSubst :: Subst -> Bool
#

When calling substTy it should be the case that the in-scope set in the substitution is a superset of the free vars of the range of the substitution. See also Note [The substitution invariant]. TODO: take into account ids and rename as isValidSubst