X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2FcoreSyn%2FCoreSubst.lhs;h=1c81d8859a4fc433980423ccdf9da349fa6266d8;hb=bf2f000a552e025ec156010d52aee282bdfcf7a4;hp=321ea8fc3603a37936a9a8ea9db6983815cc956a;hpb=94b170a053c161d1e0cc4418b37a6a4807872a5f;p=ghc-hetmet.git diff --git a/compiler/coreSyn/CoreSubst.lhs b/compiler/coreSyn/CoreSubst.lhs index 321ea8f..1c81d88 100644 --- a/compiler/coreSyn/CoreSubst.lhs +++ b/compiler/coreSyn/CoreSubst.lhs @@ -16,7 +16,8 @@ module CoreSubst ( emptySubst, mkEmptySubst, mkSubst, substInScope, isEmptySubst, extendIdSubst, extendIdSubstList, extendTvSubst, extendTvSubstList, - extendInScope, extendInScopeIds, + extendSubstList, zapSubstEnv, + extendInScope, extendInScopeList, extendInScopeIds, isInScope, -- Binders @@ -44,6 +45,8 @@ import Outputable import PprCore () -- Instances import Util import FastTypes + +import Data.List \end{code} @@ -56,6 +59,7 @@ import FastTypes \begin{code} data Subst = Subst InScopeSet -- Variables in in scope (both Ids and TyVars) + -- *after* applying the substitution IdSubstEnv -- Substitution for Ids TvSubstEnv -- Substitution for TyVars @@ -144,8 +148,8 @@ mkSubst in_scope tvs ids = Subst in_scope ids tvs substInScope :: Subst -> InScopeSet substInScope (Subst in_scope _ _) = in_scope --- zapSubstEnv :: Subst -> Subst --- zapSubstEnv (Subst in_scope _ _) = Subst in_scope emptyVarEnv emptyVarEnv +zapSubstEnv :: Subst -> Subst +zapSubstEnv (Subst in_scope _ _) = Subst in_scope emptyVarEnv emptyVarEnv -- ToDo: add an ASSERT that fvs(subst-result) is already in the in-scope set extendIdSubst :: Subst -> Id -> CoreExpr -> Subst @@ -160,6 +164,14 @@ extendTvSubst (Subst in_scope ids tvs) v r = Subst in_scope ids (extendVarEnv tv extendTvSubstList :: Subst -> [(TyVar,Type)] -> Subst extendTvSubstList (Subst in_scope ids tvs) prs = Subst in_scope ids (extendVarEnvList tvs prs) +extendSubstList :: Subst -> [(Var,CoreArg)] -> Subst +extendSubstList subst [] + = subst +extendSubstList (Subst in_scope ids tvs) ((tv,Type ty):prs) + = ASSERT( isTyVar tv ) extendSubstList (Subst in_scope ids (extendVarEnv tvs tv ty)) prs +extendSubstList (Subst in_scope ids tvs) ((id,expr):prs) + = ASSERT( isId id ) extendSubstList (Subst in_scope (extendVarEnv ids id expr) tvs) prs + lookupIdSubst :: Subst -> Id -> CoreExpr lookupIdSubst (Subst in_scope ids tvs) v | not (isLocalId v) = Var v @@ -181,6 +193,11 @@ extendInScope (Subst in_scope ids tvs) v = Subst (in_scope `extendInScopeSet` v) (ids `delVarEnv` v) (tvs `delVarEnv` v) +extendInScopeList :: Subst -> [Var] -> Subst +extendInScopeList (Subst in_scope ids tvs) vs + = Subst (in_scope `extendInScopeSetList` vs) + (ids `delVarEnvList` vs) (tvs `delVarEnvList` vs) + extendInScopeIds :: Subst -> [Id] -> Subst extendInScopeIds (Subst in_scope ids tvs) vs = Subst (in_scope `extendInScopeSetList` vs) @@ -292,6 +309,7 @@ substRecBndrs subst bndrs substIdBndr :: Subst -- Substitution to use for the IdInfo -> Subst -> Id -- Substitition and Id to transform -> (Subst, Id) -- Transformed pair + -- NB: unfolding may be zapped substIdBndr rec_subst subst@(Subst in_scope env tvs) old_id = (Subst (in_scope `extendInScopeSet` new_id) new_env tvs, new_id) @@ -309,6 +327,7 @@ substIdBndr rec_subst subst@(Subst in_scope env tvs) old_id -- rec_subst, when dealing with a mutually-recursive group new_id = maybeModifyIdInfo mb_new_info id2 mb_new_info = substIdInfo rec_subst (idInfo id2) + -- NB: unfolding info may be zapped -- Extend the substitution if the unique has changed -- See the notes with substTyVarBndr for the delVarEnv