#4321: Unexpected stack overflow prevented by superfluous type annotation
---------------------------------+------------------------------------------
Reporter: bjpop | Owner:
Type: bug | Status: new
Priority: normal | Component: Compiler
Version: 6.13 | Keywords:
Testcase: | Blockedby:
Os: Unknown/Multiple | Blocking:
Architecture: Unknown/Multiple | Failure: None/Unknown
---------------------------------+------------------------------------------
GHC versions affected:
6.13.20100915
6.13.20090922
6.12.1
6.10.4
OS versions tested:
OS X Snow Leopard
Ubuntu Linux 9.10 - Karmic Koala
Description:
The attached program computes Pi by integrating 4/(1+x*x) between 0 and 1.
The important line of code is this one:
h * (sum (map area [1..n]))
If you compile the program as it is, with this command:
ghc --make -O2 Pi.hs
it runs out of stack space when run like so:
./Pi 1000000
Stack space overflow: current size 8388608 bytes.
Use `+RTS -Ksize -RTS' to increase it.
For GHC versions 6.10.4, 6.12.1 and 6.13.20090922
However, if you add what appears to be a superfluous type annotation to
the line of code, like so:
h * ((sum (map area [1..n])) :: Double)
The program runs to completion with no stack overflow:
./Pi 1000000
3.1415926535897643
Indeed it works just fine for even larger inputs.
However version 6.13.20100915 overflows the stack regardless of whether
the type annotation is present or not.
I don't think the type annotation should make any difference to the
generated code because GHC should infer that the annotated expression is
of type Double anyway (if you put an erroneous type in the same place, GHC
complains that it should be a Double).
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4321>
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