Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#5203 closed bug (invalid)

Stack overflow in criterion

Reported by: rl Owned by: simonpj
Priority: normal Milestone: 7.2.1
Component: Compiler Version: 7.1
Keywords: Cc: johan.tibell@…, bos@…
Operating System: MacOS X Architecture: Unknown/Multiple
Type of failure: Runtime crash Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

Test program:

import Criterion.Main
main = defaultMain [bench "id" $ whnf id ()]

When I compile and run this with 7.1.20110517, I get:

warming up
estimating clock resolution...
mean is 2.896519 us (320001 iterations)
Stack space overflow: current size 8388608 bytes.
Use `+RTS -Ksize -RTS' to increase it.

This doesn't happen with 7.0.3.

Attachments (5)

q.hs (448 bytes) - added by igloo 9 years ago.
W.hs (3.7 KB) - added by igloo 9 years ago.
q.2.hs (331 bytes) - added by igloo 9 years ago.
q2.hs (332 bytes) - added by igloo 9 years ago.
W2.hs (1.4 KB) - added by igloo 9 years ago.

Download all attachments as: .zip

Change History (15)

comment:1 Changed 9 years ago by simonmar

Milestone: 7.2.1
Priority: normalhighest

Regression; we should fix before 7.2.1.

comment:2 Changed 9 years ago by simonpj

Owner: set to igloo

Ian can you look at this please?

Simon

comment:3 Changed 9 years ago by tibbe

Cc: johan.tibell@… added

Changed 9 years ago by igloo

Attachment: q.hs added

Changed 9 years ago by igloo

Attachment: W.hs added

comment:4 Changed 9 years ago by igloo

q.hs and W.hs is a cut-down version, but it still depends on primitive + vector. Unfortunately, eliminating the vector dep is tricky as it has several modules that use the same set of names.

Changed 9 years ago by igloo

Attachment: q.2.hs added

Changed 9 years ago by igloo

Attachment: q2.hs added

Changed 9 years ago by igloo

Attachment: W2.hs added

comment:5 Changed 9 years ago by igloo

Smaller testcase (q2.hs, W2.hs) attached. Still depends on vector (and therefore transitively primitive), although they are part of a normal GHC tree anyway.

$ ghc --make q2 -O -Wall -fforce-recomp -dcore-lint -dcmm-lint
[1 of 2] Compiling W2               ( W2.hs, W2.o )
[2 of 2] Compiling Main             ( q2.hs, q2.o )
Linking q2 ...
$ ./q2
W1
mean
159999
"A"
"B"
"C"
W3
$ ghc --make q2 -O -Wall -fforce-recomp -dcore-lint -dcmm-lint -DBREAK
[1 of 2] Compiling W2               ( W2.hs, W2.o )
[2 of 2] Compiling Main             ( q2.hs, q2.o )
Linking q2 ...
$ ./q2
W1
mean
Stack space overflow: current size 8388608 bytes.
Use `+RTS -Ksize -RTS' to increase it.

comment:6 Changed 9 years ago by igloo

Cc: bos@… added
Owner: changed from igloo to simonpj
Priority: highestnormal

OK, I don't think this is actually a GHC bug at all.

When it works, we get code like this:

$wfoldlM_loop_s1u9 =
    \ [...] ->
    case [...] {
        [...] ->
            $wfoldlM_loop_s1u9 [...evaluated things...]
    }

and when it doesn't, we get code like this:

foldlM_loop_s1uP =
    \ [...] ->
    foldlM_loop_s1uP
        (case [...] { [...] -> [...] })

i.e. we are passing a thunk to the recursive call.

The problem, as far as I can see, is simply that Criterion.Analysis.classifyOutliers calls U.foldl rather than U.foldl'.

Simon, I'm assigning to you in case you want to take a look at why GHC now produces different code, but otherwise we can just close the ticket.

comment:7 Changed 9 years ago by simonpj

Could you let me know how to reproduce the problem? Ie see the offending code with old ghc (wfoldm_loop) and with new GHC (foldm_loop)? Thanks. What is "old" here? Presumably "new" is both 7.0.4 and master.

Simon

comment:8 Changed 9 years ago by bos

Actually, this space leak does occur intermittently with 7.0.3 - I've seen it myself. I figured it was probably my fault, but hadn't gotten around to diagnosing or fixing it because most runs would complete successfully.

I've replaced the use of foldl with foldl' in criterion, and just now released 0.5.0.10. Please let me know if that cures the problem for you. And thank you for CCing me on this bug! Much easier to fix when someone else finds the problem :-)

comment:9 in reply to:  7 Changed 9 years ago by igloo

Resolution: invalid
Status: newclosed

Replying to simonpj:

Could you let me know how to reproduce the problem? Ie see the offending code with old ghc (wfoldm_loop) and with new GHC (foldm_loop)? Thanks. What is "old" here? Presumably "new" is both 7.0.4 and master.

I wasn't actually comparing different GHC versions, but slightly different sources, i.e.:

ghc --make q2 -O -Wall -fforce-recomp -dcore-lint -dcmm-lint -DBREAK

vs

ghc --make q2 -O -Wall -fforce-recomp -dcore-lint -dcmm-lint

I've just taken a look at the 7.0.2 core, and it looks like it has the same problem. I guess the difference is just a matter of how big the stack frames are or something, so I'll close the ticket.

comment:10 Changed 9 years ago by simonpj

Let me check:

  • The original report said that 7.0.3 had a stack-overflow problem that 7.0.2 didn't have
  • But you are claiming that actually 7.0.2 had exactly the same problem, but it didn't show up because the stack frame was a little smaller, so the overflow happens a little later.

Is that right? So 7.0.2 would fall over if the stack was a bit smaller? Is it worth checking?

Simon

Note: See TracTickets for help on using tickets.