[project @ 2003-07-30 10:01:46 by simonmar]
authorsimonmar <unknown>
Wed, 30 Jul 2003 10:01:46 +0000 (10:01 +0000)
committersimonmar <unknown>
Wed, 30 Jul 2003 10:01:46 +0000 (10:01 +0000)
Throw away an SCC on a single variable.  This seems to be justified:
there can be no work to attribute to the current cost centre when
evaluating a lone variable, other than the act of entering the
closure, and possibly returning immediately if it is a variable.

This also fixes a bug in profiling, which showed up as incorrect
transformations made by the simplifier resulting in extra strictness.
The simplifier assumes (in Simplify.simplLazyBind) that (let x = e in
x) will have been turned into x, but this isn't true if there's an SCC
around the x.

ghc/compiler/coreSyn/CoreUtils.lhs

index 5c26e0d..7e5fbb4 100644 (file)
@@ -214,7 +214,12 @@ mkCoerce2 to_ty from_ty expr
 mkSCC :: CostCentre -> Expr b -> Expr b
        -- Note: Nested SCC's *are* preserved for the benefit of
        --       cost centre stack profiling
+       -- Note2: We throw away an SCC on a single variable.  If the
+       --       variable is a value, then there is no work to do in
+       --       evaluating it, and if it is a thunk, then it will be
+       --       attributed to its own CCS anyhow.
 mkSCC cc (Lit lit)         = Lit lit
+mkSCC cc (Var v)           = Var v
 mkSCC cc (Lam x e)         = Lam x (mkSCC cc e)  -- Move _scc_ inside lambda
 mkSCC cc (Note (SCC cc') e) = Note (SCC cc) (Note (SCC cc') e)
 mkSCC cc (Note n e)        = Note n (mkSCC cc e) -- Move _scc_ inside notes