Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data Subst = Subst InScopeSet IdSubstEnv TvSubstEnv CvSubstEnv
- type TvSubstEnv = TyVarEnv Type
- type IdSubstEnv = IdEnv CoreExpr
- data InScopeSet
- deShadowBinds :: CoreProgram -> CoreProgram
- substRuleInfo :: Subst -> Id -> RuleInfo -> RuleInfo
- substRulesForImportedIds :: Subst -> [CoreRule] -> [CoreRule]
- substTy :: Subst -> Type -> Type
- substCo :: HasCallStack => Subst -> Coercion -> Coercion
- substExpr :: HasDebugCallStack => Subst -> CoreExpr -> CoreExpr
- substExprSC :: HasDebugCallStack => Subst -> CoreExpr -> CoreExpr
- substBind :: HasDebugCallStack => Subst -> CoreBind -> (Subst, CoreBind)
- substBindSC :: HasDebugCallStack => Subst -> CoreBind -> (Subst, CoreBind)
- substUnfolding :: Subst -> Unfolding -> Unfolding
- substUnfoldingSC :: Subst -> Unfolding -> Unfolding
- lookupIdSubst :: HasDebugCallStack => Subst -> Id -> CoreExpr
- substIdType :: Subst -> Id -> Id
- substIdOcc :: Subst -> Id -> Id
- substTickish :: Subst -> CoreTickish -> CoreTickish
- substDVarSet :: HasDebugCallStack => Subst -> DVarSet -> DVarSet
- substIdInfo :: Subst -> Id -> IdInfo -> Maybe IdInfo
- 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 :: TCvSubst -> TyCoVar -> Type -> TCvSubst
- extendTvSubstList :: Subst -> [(TyVar, Type)] -> Subst
- extendSubst :: Subst -> Var -> CoreArg -> Subst
- extendSubstList :: Subst -> [(Var, CoreArg)] -> Subst
- extendSubstWithVar :: Subst -> Var -> Var -> Subst
- zapSubstEnv :: Subst -> Subst
- extendSubstInScope :: Subst -> Var -> Subst
- extendSubstInScopeList :: Subst -> [Var] -> Subst
- extendSubstInScopeSet :: Subst -> VarSet -> Subst
- isInScope :: Var -> Subst -> Bool
- setInScope :: Subst -> InScopeSet -> Subst
- getTCvSubst :: Subst -> TCvSubst
- extendTvSubst :: Subst -> TyVar -> Type -> Subst
- extendCvSubst :: Subst -> CoVar -> Coercion -> Subst
- delBndr :: Subst -> Var -> Subst
- delBndrs :: Subst -> [Var] -> Subst
- substBndr :: Subst -> Var -> (Subst, Var)
- substBndrs :: Subst -> [Var] -> (Subst, [Var])
- substRecBndrs :: Subst -> [Id] -> (Subst, [Id])
- substTyVarBndr :: Subst -> TyVar -> (Subst, TyVar)
- substCoVarBndr :: Subst -> CoVar -> (Subst, CoVar)
- 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])
Main data types
A substitution environment, containing Id
, TyVar
, and CoVar
substitutions.
Some invariants apply to how you use the substitution:
- Note [The substitution invariant] in GHC.Core.TyCo.Subst
- Note [Substitutions apply only once] in GHC.Core.TyCo.Subst
Instances
data InScopeSet Source #
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.
Instances
Outputable InScopeSet Source # | |
Defined in GHC.Types.Var.Env ppr :: InScopeSet -> SDoc Source # |
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
substExpr :: HasDebugCallStack => Subst -> CoreExpr -> CoreExpr Source #
substExpr applies a substitution to an entire CoreExpr
. Remember,
you may only apply the substitution once:
See Note [Substitutions apply only once] in GHC.Core.TyCo.Subst
Do *not* attempt to short-cut in the case of an empty substitution! See Note [Extending the Subst]
substExprSC :: HasDebugCallStack => Subst -> CoreExpr -> CoreExpr Source #
substBindSC :: HasDebugCallStack => Subst -> CoreBind -> (Subst, CoreBind) Source #
substUnfolding :: Subst -> Unfolding -> Unfolding Source #
Substitutes for the Id
s 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
substUnfoldingSC :: Subst -> Unfolding -> Unfolding Source #
Substitutes for the Id
s 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
lookupIdSubst :: HasDebugCallStack => Subst -> Id -> CoreExpr Source #
substTickish :: Subst -> CoreTickish -> CoreTickish Source #
substDVarSet :: HasDebugCallStack => Subst -> DVarSet -> DVarSet Source #
Operations on substitutions
emptySubst :: Subst Source #
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 GHC.Core.TyCo.Subst Note [The substitution invariant]
isEmptySubst :: Subst -> Bool Source #
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
extendSubst :: Subst -> Var -> CoreArg -> Subst Source #
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
.
zapSubstEnv :: Subst -> Subst Source #
extendSubstInScopeList :: Subst -> [Var] -> Subst Source #
Add the Expr
s to the in-scope set: see also extendInScope
extendSubstInScopeSet :: Subst -> VarSet -> Subst Source #
Add the Expr
s to the in-scope set: see also extendInScope
setInScope :: Subst -> InScopeSet -> Subst Source #
getTCvSubst :: Subst -> TCvSubst Source #
extendTvSubst :: Subst -> TyVar -> Type -> Subst Source #
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
GHC.Core.TyCo.Subst Note [The substitution invariant] holds
after extending the substitution like this.
extendCvSubst :: Subst -> CoVar -> Coercion -> Subst Source #
Add a substitution from a CoVar
to a Expr
to the Subst
:
you must ensure that the in-scope set satisfies
GHC.Core.TyCo.Subst Note [The substitution invariant]
after extending the substitution like this
Substituting and cloning binders
substRecBndrs :: Subst -> [Id] -> (Subst, [Id]) Source #
Substitute in a mutually recursive group of Id
s
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 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