id,summary,reporter,owner,description,type,status,priority,milestone,component,version,resolution,keywords,cc,os,architecture,failure,difficulty,testcase,blockedby,blocking,related
5920,stack overflow in strict function depending on return type,ben0x539,simonpj,"With `-O` or up, but not with `-fno-strictness`, the following program terminates with a stack overflow:

{{{
goInt :: Integer -> Integer -> Int
goInt 500 250000 = 0
goInt   x 250000 = goInt (x+1) 1
goInt   x      y = goInt x     (y+1)

main = do 
  print $ goInt 1 1
}}}

In contrast, the following program runs just fine even though the differences should not impact strictness:

{{{
import Debug.Trace

goInteger  :: Integer -> Integer -> Integer
goInteger  500 250000 = 0
goInteger    x 250000 = goInteger (x+1) 1
goInteger    x      y = goInteger x     (y+1)

goIntTrace :: Integer -> Integer -> Int
goIntTrace 500 250000 = 0
goIntTrace   x 250000 = goIntTrace (x+1) 1
goIntTrace   x      y = (if y < 0 then trace """" else id) goIntTrace x (y+1)

main = do
  print $ goInteger 1 1
  print $ goIntTrace 1 1
}}}

`goInteger` does not overflow the stack even though it only differs in the type of the return value.

`goIntTrace` does not overflow the stack even though `goInt` is already strict in `y`. Trying to make `goInt` ""stricter"" via `seq`s or bangs instead does not seem to have the same effect without the threat of IO.

The behavior could be reproduced on at least ghc 7.0.1 and 7.4.1, linux x86_64.",bug,closed,normal,7.4.2,Compiler,7.4.1,fixed,,,Unknown/Multiple,Unknown/Multiple,Runtime crash,Unknown,simplCore/should_run/T5920,,,
