ghc-lib-parser-0.20191201: The GHC API, decoupled from GHC versions

CoreSubst

Synopsis

Main data types

data Subst Source #

A substitution environment, containing Id, TyVar, and CoVar substitutions.

Some invariants apply to how you use the substitution:

1. Note [The substitution invariant] in TyCoSubst
2. Note [Substitutions apply only once] in TyCoSubst

Constructors

 Subst InScopeSet IdSubstEnv TvSubstEnv CvSubstEnv
Instances
 Source # Instance detailsDefined in CoreSubst Methods

A substitution of Types for TyVars and Kinds for KindVars

An environment for substituting for Ids

A set of variables that are in scope at some point "Secrets of the Glasgow Haskell Compiler inliner" Section 3.2 provides the motivation for this abstraction.

Instances
 Source # Instance detailsDefined in VarEnv Methods

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

Substitutes for the Ids within the WorkerInfo given the new function Id

See substTy

See substCo

Apply a substitution to an entire CoreExpr. Remember, you may only apply the substitution once: See Note [Substitutions apply only once] in TyCoSubst

Do *not* attempt to short-cut in the case of an empty substitution! See Note [Extending the Subst]

Apply a substitution to an entire CoreBind, additionally returning an updated Subst that should be used by subsequent substitutions.

Apply a substitution to an entire CoreBind, additionally returning an updated Subst that should be used by subsequent substitutions.

Substitutes for the Ids within an unfolding

Substitutes for the Ids within an unfolding

Find the substitution for an Id in the Subst

Find the substitution for a TyVar in the Subst

Substitute into some IdInfo with regard to the supplied new Id.

Operations on substitutions

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

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

Find the in-scope set: see TyCoSubst Note [The substitution invariant]

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

extendIdSubstList :: Subst -> [(Id, CoreExpr)] -> Subst Source #

Adds multiple Id substitutions to the Subst: see also extendIdSubst

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

Adds multiple TyVar substitutions to the Subst: see also extendTvSubst

Add a substitution appropriate to the thing being substituted (whether an expression, type, or coercion). See also extendIdSubst, extendTvSubst, extendCvSubst

extendSubstList :: Subst -> [(Var, CoreArg)] -> Subst Source #

Add a substitution as appropriate to each of the terms being substituted (whether expressions, types, or coercions). See also extendSubst.

Remove all substitutions for Ids and Exprs that might have been built up while preserving the in-scope set

Add the Expr to the in-scope set, but do not remove any existing substitutions for it

Add the Expr to the in-scope set: as a side effect, and remove any existing substitutions for it

extendInScopeList :: Subst -> [Var] -> Subst Source #

Add the Exprs to the in-scope set: see also extendInScope

extendInScopeIds :: Subst -> [Id] -> Subst Source #

Optimized version of extendInScopeList that can be used if you are certain all the things being added are Ids and hence none are TyVars or CoVars

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 TyCoSubst Note [The substitution invariant] holds after extending the substitution like this.

Add a substitution from a CoVar to a Expr to the Subst: you must ensure that the in-scope set satisfies TyCoSubst Note [The substitution invariant] after extending the substitution like this

Substituting and cloning binders

substBndr :: Subst -> Var -> (Subst, Var) Source #

Substitutes a Expr 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.

substBndrs :: Subst -> [Var] -> (Subst, [Var]) Source #

Applies substBndr to a number of Exprs, accumulating a new Subst left-to-right

substRecBndrs :: Subst -> [Id] -> (Subst, [Id]) Source #

Substitute in a mutually recursive group of Ids

cloneIdBndr :: Subst -> UniqSupply -> Id -> (Subst, Id) Source #

Very similar to substBndr, but it always allocates a new Unique for each variable in its output. It substitutes the IdInfo though.

cloneIdBndrs :: Subst -> UniqSupply -> [Id] -> (Subst, [Id]) Source #

Applies cloneIdBndr to a number of Ids, accumulating a final substitution from left to right

cloneRecIdBndrs :: Subst -> UniqSupply -> [Id] -> (Subst, [Id]) Source #

Clone a mutually recursive group of Ids