#4978: Continuation passing style loop doesn't compile into a loop
---------------------------------+------------------------------------------
Reporter: tibbe | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.0.1
Keywords: | Testcase:
Blockedby: | Difficulty:
Os: Unknown/Multiple | Blocking:
Architecture: Unknown/Multiple | Failure: None/Unknown
---------------------------------+------------------------------------------
Comment(by simonpj):
Thank you for digging into the perf problem. (This one doesn't look like
a regression btw; I think 6.12.3 behaves the same.)
I'm not sure what you mean by "SAT the original continuation".
To me the bad thing is that `test4` gets arity 2. We'd like it to have
arity 3. That is, we want to eta-expand `test4`.
And it's not hard to make it so. I made this 1-line change:
{{{
empty = Builder (\ k n -> k n)
}}}
Then I get
{{{
Main.main5 [Occ=LoopBreaker]
:: [GHC.Types.Int]
-> (GHC.Types.Int -> GHC.Types.Int)
-> GHC.Types.Int
-> GHC.Types.Int
[GblId, Arity=3, Caf=NoCafRefs, Str=DmdType SC(S)L]
Main.main5 =
\ (ds_dpE :: [GHC.Types.Int])
(eta_B1 :: GHC.Types.Int -> GHC.Types.Int)
(eta1_X2 :: GHC.Types.Int) ->
case ds_dpE of _ {
[] -> eta_B1 eta1_X2;
: x_abU xs_abV ->
Main.main5
xs_abV
eta_B1
(case eta1_X2 of _ { GHC.Types.I# x1_aq7 ->
GHC.Types.I# (GHC.Prim.+# x1_aq7 1)
})
}
}}}
Much better! And indeed the program allocates less. With an input list
of 100,000 (rather than 100), I get 19Mbytes of allocation before and
14Mbytes after.
Why is this? When compiling `test4` GHC is worried that you might say
{{{
test4 [] (error "urk") `seq` True
}}}
Now if we eta-expand `test4` the before and after would behave
differently.
The root of it is that `f` and `(\y. f x)` aren't the same, because `seq`
can distinguish them.
Humph. See `Note [Dealing with bottom]` in `CoreArity`. In fact I ''do''
eta-expand bottoms because not doing so is a massive lose. But I do not
eta-expand variables (as above). Maybe I should. Interesting.
First thing: is the transformation above what you were hoping for? If
not, what? Write it by hand so we can see!
Simon
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4978#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs