| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
CoreSubst
Contents
- data Subst = Subst InScopeSet IdSubstEnv TvSubstEnv CvSubstEnv
- type TvSubstEnv = TyVarEnv Type
- type IdSubstEnv = IdEnv CoreExpr
- data InScopeSet
- deShadowBinds :: CoreProgram -> CoreProgram
- substSpec :: Subst -> Id -> RuleInfo -> RuleInfo
- substRulesForImportedIds :: Subst -> [CoreRule] -> [CoreRule]
- substTy :: Subst -> Type -> Type
- substCo :: Subst -> Coercion -> Coercion
- 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
- lookupIdSubst :: SDoc -> Subst -> Id -> CoreExpr
- lookupTCvSubst :: Subst -> TyVar -> Type
- substIdOcc :: Subst -> Id -> Id
- substTickish :: Subst -> Tickish Id -> Tickish Id
- substDVarSet :: Subst -> DVarSet -> DVarSet
- emptySubst :: Subst
- mkEmptySubst :: InScopeSet -> Subst
- mkSubst :: InScopeSet -> TvSubstEnv -> CvSubstEnv -> IdSubstEnv -> Subst
- mkOpenSubst :: InScopeSet -> [(Var, CoreArg)] -> Subst
- substInScope :: Subst -> InScopeSet
- isEmptySubst :: Subst -> Bool
- extendIdSubst :: Subst -> Id -> CoreExpr -> Subst
- extendIdSubstList :: Subst -> [(Id, CoreExpr)] -> Subst
- extendTCvSubst :: Subst -> TyVar -> Type -> Subst
- extendTCvSubstList :: Subst -> [(TyVar, Type)] -> Subst
- extendSubst :: Subst -> Var -> CoreArg -> Subst
- extendSubstList :: Subst -> [(Var, CoreArg)] -> Subst
- extendSubstWithVar :: Subst -> Var -> Var -> Subst
- zapSubstEnv :: Subst -> Subst
- addInScopeSet :: Subst -> VarSet -> Subst
- extendInScope :: Subst -> Var -> Subst
- extendInScopeList :: Subst -> [Var] -> Subst
- extendInScopeIds :: Subst -> [Id] -> Subst
- isInScope :: Var -> Subst -> Bool
- setInScope :: Subst -> InScopeSet -> Subst
- delBndr :: Subst -> Var -> Subst
- delBndrs :: Subst -> [Var] -> Subst
- substBndr :: Subst -> Var -> (Subst, Var)
- substBndrs :: Subst -> [Var] -> (Subst, [Var])
- substRecBndrs :: Subst -> [Id] -> (Subst, [Id])
- cloneBndr :: Subst -> Unique -> Var -> (Subst, Var)
- cloneBndrs :: Subst -> UniqSupply -> [Var] -> (Subst, [Var])
- cloneIdBndr :: Subst -> UniqSupply -> Id -> (Subst, Id)
- cloneIdBndrs :: Subst -> UniqSupply -> [Id] -> (Subst, [Id])
- cloneRecIdBndrs :: Subst -> UniqSupply -> [Id] -> (Subst, [Id])
- simpleOptPgm :: DynFlags -> Module -> CoreProgram -> [CoreRule] -> [CoreVect] -> IO (CoreProgram, [CoreRule], [CoreVect])
- simpleOptExpr :: CoreExpr -> CoreExpr
- simpleOptExprWith :: Subst -> InExpr -> OutExpr
- exprIsConApp_maybe :: InScopeEnv -> CoreExpr -> Maybe (DataCon, [Type], [CoreExpr])
- exprIsLiteral_maybe :: InScopeEnv -> CoreExpr -> Maybe Literal
- exprIsLambda_maybe :: InScopeEnv -> CoreExpr -> Maybe (Var, CoreExpr, [Tickish Id])
Main data types
A substitution environment, containing Id, TyVar, and CoVar
substitutions.
Some invariants apply to how you use the substitution:
- The in-scope set contains at least those
Ids andTyVars 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
Constructors
| Subst InScopeSet IdSubstEnv TvSubstEnv CvSubstEnv |
Instances
type IdSubstEnv = IdEnv CoreExpr Source
An environment for substituting for Ids
data InScopeSet Source
A set of variables that are in scope at some point "Secrets of the Glasgow Haskell Compiler inliner" Section 3. provides the motivation for this abstraction.
Instances
Substituting into expressions and related types
deShadowBinds :: CoreProgram -> CoreProgram 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, 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
substRulesForImportedIds :: Subst -> [CoreRule] -> [CoreRule] Source
substUnfoldingSC :: Subst -> Unfolding -> Unfolding Source
Substitutes for the Ids within an unfolding
substIdOcc :: Subst -> Id -> Id Source
substDVarSet :: Subst -> DVarSet -> DVarSet Source
Operations on substitutions
mkEmptySubst :: InScopeSet -> Subst Source
mkSubst :: InScopeSet -> TvSubstEnv -> CvSubstEnv -> IdSubstEnv -> Subst Source
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
substInScope :: Subst -> InScopeSet Source
Find the in-scope set: see CoreSubst
isEmptySubst :: Subst -> Bool Source
extendIdSubstList :: Subst -> [(Id, CoreExpr)] -> Subst Source
Adds multiple Id substitutions to the Subst: see also extendIdSubst
extendTCvSubstList :: Subst -> [(TyVar, Type)] -> Subst Source
Adds multiple TyVar substitutions to the Subst: see also extendTCvSubst
extendSubst :: Subst -> Var -> CoreArg -> Subst Source
Add a substitution appropriate to the thing being substituted
(whether an expression, type, or coercion). See also
extendIdSubst, extendTCvSubst
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.
zapSubstEnv :: Subst -> Subst Source
addInScopeSet :: Subst -> VarSet -> Subst Source
Add the Var to the in-scope set, but do not remove
any existing substitutions for it
extendInScope :: Subst -> Var -> Subst Source
Add the Var to the in-scope set: as a side effect,
and remove any existing substitutions for it
extendInScopeList :: Subst -> [Var] -> Subst Source
Add the Vars 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
setInScope :: Subst -> InScopeSet -> Subst Source
Substituting and cloning binders
substRecBndrs :: Subst -> [Id] -> (Subst, [Id]) Source
Substitute in a mutually recursive group of Ids
cloneBndrs :: Subst -> UniqSupply -> [Var] -> (Subst, [Var]) Source
cloneIdBndr :: Subst -> UniqSupply -> Id -> (Subst, Id) Source
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
Simple expression optimiser
simpleOptPgm :: DynFlags -> Module -> CoreProgram -> [CoreRule] -> [CoreVect] -> IO (CoreProgram, [CoreRule], [CoreVect]) Source
simpleOptExpr :: CoreExpr -> CoreExpr Source
simpleOptExprWith :: Subst -> InExpr -> OutExpr Source
exprIsConApp_maybe :: InScopeEnv -> CoreExpr -> Maybe (DataCon, [Type], [CoreExpr]) Source
Returns Just (dc, [t1..tk], [x1..xn]) if the argument expression is
a *saturated* constructor application of the form dc t1..tk x1 .. xn,
where t1..tk are the *universally-qantified* type args of dc
exprIsLiteral_maybe :: InScopeEnv -> CoreExpr -> Maybe Literal Source
exprIsLambda_maybe :: InScopeEnv -> CoreExpr -> Maybe (Var, CoreExpr, [Tickish Id]) Source