diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2014-03-11 11:13:31 +0000 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2014-03-11 11:15:55 +0000 |
commit | ef44a429af4a630a153b5774d0e19dbcad8328d5 (patch) | |
tree | c32a11d7a36d9308f4fc2f8aba583dbb29799927 /compiler/coreSyn | |
parent | a10ed3e64336e272137e1743c36970b36f7076c7 (diff) | |
download | haskell-ef44a429af4a630a153b5774d0e19dbcad8328d5.tar.gz |
Make SetLevels do substitution properly (fixes Trac #8714)
Nowadays SetLevels floats case expressions as well as let-bindings,
and case expressions bind type variables. We need to clone all such
floated binders, to avoid accidental name capture. But I'd forgotten
to substitute for the cloned type variables, causing #8714. (In the
olden days only Ids were cloned, from let-bindings.)
This patch fixes the bug and does quite a bit of clean-up refactoring
as well, by putting the context level in the LvlEnv.
There is no effect on performance, except that nofib 'rewrite' improves
allocations by 3%. On investigation I think it was a fluke to do with
loop-cutting in big letrec nests. But at least it's a fluke in the
right direction.
Program Size Allocs Runtime Elapsed TotalMem
--------------------------------------------------------------------------------
Min -0.4% -3.0% -19.4% -19.4% -26.7%
Max -0.0% +0.0% +17.9% +17.9% 0.0%
Geometric Mean -0.1% -0.0% -0.7% -0.7% -0.4%
Diffstat (limited to 'compiler/coreSyn')
-rw-r--r-- | compiler/coreSyn/CoreSubst.lhs | 2 | ||||
-rw-r--r-- | compiler/coreSyn/CoreSyn.lhs | 21 |
2 files changed, 21 insertions, 2 deletions
diff --git a/compiler/coreSyn/CoreSubst.lhs b/compiler/coreSyn/CoreSubst.lhs index d1fc056b23..95dccc2f7d 100644 --- a/compiler/coreSyn/CoreSubst.lhs +++ b/compiler/coreSyn/CoreSubst.lhs @@ -23,7 +23,7 @@ module CoreSubst ( substTy, substCo, substExpr, substExprSC, substBind, substBindSC, substUnfolding, substUnfoldingSC, lookupIdSubst, lookupTvSubst, lookupCvSubst, substIdOcc, - substTickish, + substTickish, substVarSet, -- ** Operations on substitutions emptySubst, mkEmptySubst, mkSubst, mkOpenSubst, substInScope, isEmptySubst, diff --git a/compiler/coreSyn/CoreSyn.lhs b/compiler/coreSyn/CoreSyn.lhs index 3dc8eeb31f..47a993ed46 100644 --- a/compiler/coreSyn/CoreSyn.lhs +++ b/compiler/coreSyn/CoreSyn.lhs @@ -18,7 +18,7 @@ module CoreSyn ( -- * Main data types Expr(..), Alt, Bind(..), AltCon(..), Arg, Tickish(..), CoreProgram, CoreExpr, CoreAlt, CoreBind, CoreArg, CoreBndr, - TaggedExpr, TaggedAlt, TaggedBind, TaggedArg, TaggedBndr(..), + TaggedExpr, TaggedAlt, TaggedBind, TaggedArg, TaggedBndr(..), deTagExpr, -- ** 'Expr' construction mkLets, mkLams, @@ -1106,6 +1106,25 @@ instance Outputable b => OutputableBndr (TaggedBndr b) where pprBndr _ b = ppr b -- Simple pprInfixOcc b = ppr b pprPrefixOcc b = ppr b + +deTagExpr :: TaggedExpr t -> CoreExpr +deTagExpr (Var v) = Var v +deTagExpr (Lit l) = Lit l +deTagExpr (Type ty) = Type ty +deTagExpr (Coercion co) = Coercion co +deTagExpr (App e1 e2) = App (deTagExpr e1) (deTagExpr e2) +deTagExpr (Lam (TB b _) e) = Lam b (deTagExpr e) +deTagExpr (Let bind body) = Let (deTagBind bind) (deTagExpr body) +deTagExpr (Case e (TB b _) ty alts) = Case (deTagExpr e) b ty (map deTagAlt alts) +deTagExpr (Tick t e) = Tick t (deTagExpr e) +deTagExpr (Cast e co) = Cast (deTagExpr e) co + +deTagBind :: TaggedBind t -> CoreBind +deTagBind (NonRec (TB b _) rhs) = NonRec b (deTagExpr rhs) +deTagBind (Rec prs) = Rec [(b, deTagExpr rhs) | (TB b _, rhs) <- prs] + +deTagAlt :: TaggedAlt t -> CoreAlt +deTagAlt (con, bndrs, rhs) = (con, [b | TB b _ <- bndrs], deTagExpr rhs) \end{code} |