GHC: Ticket #5569: Ineffective seq/BangPatterns
http://ghc.haskell.org/trac/ghc/ticket/5569
<p>
This could be related to <a class="closed ticket" href="http://ghc.haskell.org/trac/ghc/ticket/5557" title="#5557: bug: Code using seq has wrong strictness (too lazy) (closed: fixed)">#5557</a>, but it might be something else.
7.2.1 was very picky about where you placed your bangs/seqs, for example
</p>
<pre class="wiki">{-# LANGUAGE BangPatterns #-}
module Main (main) where
main :: IO ()
main = print (f 1000000)
f :: Integer -> Integer
f n = go n 0
where
go 0 !sm = sm
go k acc = go (k-1) (acc+k)
OR
module Main (main) where
main :: IO ()
main = print (f 1000000)
f :: Integer -> Integer
f n = go n 0
where
go a b | a `seq` b `seq` False = undefined
go k acc
| k == 0 = acc
| otherwise = go (k-1) (acc+k)
</pre><p>
gave a stack overflow when compiled with ghc -O2. You have to place the bang/seq on the second equation for it to work. Older ghc versions treated it well, as does HEAD, so it seems fixed, but perhaps a regression test is in order?
</p>
en-usGHChttp://ghc.haskell.org/trac/ghc/chrome/site/ghc_logo.png
http://ghc.haskell.org/trac/ghc/ticket/5569
Trac 1.2.2daniel.is.fischerThu, 20 Oct 2011 11:02:27 GMTfailure changed
http://ghc.haskell.org/trac/ghc/ticket/5569#comment:1
http://ghc.haskell.org/trac/ghc/ticket/5569#comment:1
<ul>
<li><strong>failure</strong>
changed from <em>None/Unknown</em> to <em>Runtime performance bug</em>
</li>
</ul>
TicketiglooFri, 11 Nov 2011 23:15:45 GMTowner, milestone set
http://ghc.haskell.org/trac/ghc/ticket/5569#comment:2
http://ghc.haskell.org/trac/ghc/ticket/5569#comment:2
<ul>
<li><strong>owner</strong>
set to <em>igloo</em>
</li>
<li><strong>milestone</strong>
set to <em>7.4.1</em>
</li>
</ul>
<p>
The bang on the first equation is redundant: Pattern matching is left-to-right, so <code>sm</code> is only forced if the first argument is <code>0</code>.
</p>
<p>
But with your code I'm getting a stack overflow with release builds, but not validate builds, of 7.2.2. We should investigate.
</p>
TicketiglooWed, 16 Nov 2011 21:45:40 GMTstatus changed; resolution set
http://ghc.haskell.org/trac/ghc/ticket/5569#comment:3
http://ghc.haskell.org/trac/ghc/ticket/5569#comment:3
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
</ul>
<p>
I can't reproduce the above problem with the HEAD, so marking this as fixed.
</p>
Ticket