- data Subst
- type TvSubstEnv = TyVarEnv Type
- type IdSubstEnv = IdEnv CoreExpr
- data InScopeSet
- deShadowBinds :: [CoreBind] -> [CoreBind]
- substSpec :: Subst -> Id -> SpecInfo -> SpecInfo
- substRulesForImportedIds :: Subst -> [CoreRule] -> [CoreRule]
- substTy :: Subst -> Type -> Type
- substExpr :: SDoc -> Subst -> CoreExpr -> CoreExpr
- substExprSC :: SDoc -> Subst -> CoreExpr -> CoreExpr
- substBind :: Subst -> CoreBind -> (Subst, CoreBind)
- substBindSC :: Subst -> CoreBind -> (Subst, CoreBind)
- substUnfolding :: Subst -> Unfolding -> Unfolding
- substUnfoldingSC :: Subst -> Unfolding -> Unfolding
- substUnfoldingSource :: Subst -> UnfoldingSource -> UnfoldingSource
- lookupIdSubst :: SDoc -> Subst -> Id -> CoreExpr
- lookupTvSubst :: Subst -> TyVar -> Type
- substIdOcc :: Subst -> Id -> Id
- emptySubst :: Subst
- mkEmptySubst :: InScopeSet -> Subst
- mkSubst :: InScopeSet -> TvSubstEnv -> IdSubstEnv -> Subst
- mkOpenSubst :: InScopeSet -> [(Var, CoreArg)] -> Subst
- substInScope :: Subst -> InScopeSet
- isEmptySubst :: Subst -> Bool
- extendIdSubst :: Subst -> Id -> CoreExpr -> Subst
- extendIdSubstList :: Subst -> [(Id, CoreExpr)] -> Subst
- extendTvSubst :: Subst -> TyVar -> Type -> Subst
- extendTvSubstList :: Subst -> [(TyVar, Type)] -> Subst
- extendSubst :: Subst -> Var -> CoreArg -> Subst
- extendSubstList :: Subst -> [(Var, CoreArg)] -> Subst
- zapSubstEnv :: Subst -> Subst
- extendInScope :: Subst -> Var -> Subst
- extendInScopeList :: Subst -> [Var] -> Subst
- extendInScopeIds :: Subst -> [Id] -> Subst
- isInScope :: Var -> Subst -> Bool
- substBndr :: Subst -> Var -> (Subst, Var)
- substBndrs :: Subst -> [Var] -> (Subst, [Var])
- substRecBndrs :: Subst -> [Id] -> (Subst, [Id])
- cloneIdBndr :: Subst -> UniqSupply -> Id -> (Subst, Id)
- cloneIdBndrs :: Subst -> UniqSupply -> [Id] -> (Subst, [Id])
- cloneRecIdBndrs :: Subst -> UniqSupply -> [Id] -> (Subst, [Id])
- simpleOptPgm :: DynFlags -> [CoreBind] -> [CoreRule] -> IO ([CoreBind], [CoreRule])
- simpleOptExpr :: CoreExpr -> CoreExpr
Main data types
A substitution environment, containing both Id
and TyVar
substitutions.
Some invariants apply to how you use the substitution:
- The in-scope set contains at least those
Id
s andTyVar
s that will be in scope after applying the substitution to a term. Precisely, the in-scope set must be a superset of the free vars of the substitution range that might possibly clash with locally-bound variables in the thing being substituted in. - You may apply the substitution only once
There are various ways of setting up the in-scope set such that the first of these invariants hold:
- Arrange that the in-scope set really is all the things in scope
- Arrange that it's the free vars of the range of the substitution
- Make it empty, if you know that all the free vars of the substitution are fresh, and hence can't possibly clash
type IdSubstEnv = IdEnv CoreExprSource
An environment for substituting for Id
s
Substituting into expressions and related types
deShadowBinds :: [CoreBind] -> [CoreBind]Source
De-shadowing the program is sometimes a useful pre-pass. It can be done simply by running over the bindings with an empty substitution, becuase 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
substRulesForImportedIds :: Subst -> [CoreRule] -> [CoreRule]Source
substUnfolding :: Subst -> Unfolding -> UnfoldingSource
substUnfoldingSC :: Subst -> Unfolding -> UnfoldingSource
Substitutes for the Id
s within an unfolding
substIdOcc :: Subst -> Id -> IdSource
Operations on substitutions
mkSubst :: InScopeSet -> TvSubstEnv -> IdSubstEnv -> SubstSource
mkOpenSubst :: InScopeSet -> [(Var, CoreArg)] -> SubstSource
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
substInScope :: Subst -> InScopeSetSource
Find the in-scope set: see CoreSubst
isEmptySubst :: Subst -> BoolSource
extendIdSubstList :: Subst -> [(Id, CoreExpr)] -> SubstSource
Adds multiple Id
substitutions to the Subst
: see also extendIdSubst
extendTvSubstList :: Subst -> [(TyVar, Type)] -> SubstSource
Adds multiple TyVar
substitutions to the Subst
: see also extendTvSubst
extendSubst :: Subst -> Var -> CoreArg -> SubstSource
Add a substitution for a TyVar
or Id
as appropriate to the Var
being added. See also
extendIdSubst
and extendTvSubst
extendSubstList :: Subst -> [(Var, CoreArg)] -> SubstSource
Add a substitution for a TyVar
or Id
as appropriate to all the Var
s being added. See also extendSubst
zapSubstEnv :: Subst -> SubstSource
extendInScope :: Subst -> Var -> SubstSource
Add the Var
to the in-scope set: as a side effect, removes any existing substitutions for it
extendInScopeList :: Subst -> [Var] -> SubstSource
Add the Var
s to the in-scope set: see also extendInScope
extendInScopeIds :: Subst -> [Id] -> SubstSource
Optimized version of extendInScopeList
that can be used if you are certain
all the things being added are Id
s and hence none are TyVar
s
Substituting and cloning binders
substRecBndrs :: Subst -> [Id] -> (Subst, [Id])Source
Substitute in a mutually recursive group of Id
s
cloneIdBndr :: Subst -> UniqSupply -> Id -> (Subst, Id)Source
cloneIdBndrs :: Subst -> UniqSupply -> [Id] -> (Subst, [Id])Source
Applies cloneIdBndr
to a number of Id
s, accumulating a final
substitution from left to right
cloneRecIdBndrs :: Subst -> UniqSupply -> [Id] -> (Subst, [Id])Source
Clone a mutually recursive group of Id
s