HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleghc-9.10.3GHC2021

GHC.Core.Subst

  • 4 types
  • 52 values
  • Packageghc-9.10.3
  • Exports56
  • LanguageGHC2021
  • LicenceBSD-3-Clause
  • SourceSubst.hs

Main data types

4 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
newtypenewtype InScopeSet
#

A set of variables that are in scope at some point.

Note that this is a superset of the variables that are currently in scope. See Note [The InScopeSet invariant].

"Secrets of the Glasgow Haskell Compiler inliner" Section 3.2 provides the motivation for this abstraction.

Instances1Outputable

Substituting into expressions and related types

De-shadowing the program is sometimes a useful pre-pass. It can be done simply by running over the bindings with an empty substitution, because substitution returns a result that has no-shadowing guaranteed.

(Actually, within a single type there might still be shadowing, because substTy is a no-op for the empty substitution, but that's probably OK.)

Aug 09

This function is not used in GHC at the moment, but seems so short and simple that I'm going to leave it here

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.

Substitutes for the Ids within an unfolding NB: substUnfolding discards any unfolding without without a Stable source. This is usually what we want, but it may be a bit unexpected

Substitutes for the Ids within an unfolding NB: substUnfolding discards any unfolding without without a Stable source. This is usually what we want, but it may be a bit unexpected

Operations on substitutions

valuemkOpenSubst :: InScopeSet -> [(Var, CoreArg)] -> Subst
#

Simultaneously substitute for a bunch of variables No left-right shadowing ie the substitution for (x y. e) a1 a2 so neither x nor y scope over a1 a2

valueextendIdSubst :: Subst -> Id -> CoreExpr -> Subst
#

Add a substitution for an Id to the Subst: you must ensure that the in-scope set is such that TyCoSubst Note [The substitution invariant] holds after extending the substitution like this

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.

valuezapSubst :: Subst -> Subst
#

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

Substituting and cloning binders

valuesubstBndr :: Subst -> Var -> (Subst, Var)
#

Substitutes a Var for another one according to the Subst given, returning the result and an updated Subst that should be used by subsequent substitutions. IdInfo is preserved by this process, although it is substituted into appropriately.