[GHC] #7994: Make foldl into a good consumer
GHC
ghc-devs at haskell.org
Wed Jan 22 13:47:26 UTC 2014
#7994: Make foldl into a good consumer
-------------------------------------+------------------------------------
Reporter: simonpj | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.6.3
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture: Unknown/Multiple
Type of failure: None/Unknown | Difficulty: Unknown
Test Case: | Blocked By:
Blocking: | Related Tickets:
-------------------------------------+------------------------------------
Comment (by nomeata):
I gave it a shot, analysing the body and the rhs of a let in alternation
until a fixed point is found with regard to
* demand on the rhs
* rhs’s demand type
* body’s demand type
and as expected, the resulting core looks good:
{{{
$wgo_s1oi [Occ=LoopBreaker]
:: GHC.Prim.Int#
-> GHC.Prim.Double#
-> GHC.Prim.Double#
-> Data.Complex.Complex GHC.Types.Double
[LclId, Arity=3, Str=DmdType <S,U><L,U><L,U>]
$wgo_s1oi =
\ (w_s1o3 :: GHC.Prim.Int#)
(ww1_s1oa :: GHC.Prim.Double#)
(ww2_s1of :: GHC.Prim.Double#) ->
case Foo.f (GHC.Types.I# w_s1o3)
of _ [Occ=Dead] { Data.Complex.:+ ww4_s1nS ww5_s1nX ->
case ww4_s1nS of _ [Occ=Dead] { GHC.Types.D# ww7_s1re ->
case ww5_s1nX of _ [Occ=Dead] { GHC.Types.D# ww9_s1rg ->
case GHC.Prim.tagToEnum#
@ GHC.Types.Bool (GHC.Prim.==# w_s1o3 ww_s1om)
of _ [Occ=Dead] {
GHC.Types.False ->
$wgo_s1oi
(GHC.Prim.+# w_s1o3 1)
(GHC.Prim.+## ww1_s1oa ww7_s1re)
(GHC.Prim.+## ww2_s1of ww9_s1rg);
GHC.Types.True ->
Data.Complex.:+
@ GHC.Types.Double
(GHC.Types.D# (GHC.Prim.+## ww1_s1oa ww7_s1re))
(GHC.Types.D# (GHC.Prim.+## ww2_s1of ww9_s1rg))
}
}
}
}; } in
$wgo_s1oi 1 0.0 0.0;
}}}
But also as expected, for other code, with more nested lets, compilation
time becomes unacceptably large.
Has anyone considered doing the fixed-pointing not locally for every let,
but across the whole top-level-binding? I.e. initialize all demands and
strictness signatures with their strongest possible value (`absDmd` and
`botDmdType`), and then analyse the whole expression in repeated passes
over all of it, until nothing changes any more. (Or, a variant: Do that
initialisation, but also do local fixed-pointing, starting from the stored
values, so that when an inner let is re-analysed, but nothing has changed,
then there is only one iteration.)
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/7994#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list