
#11383: CAFs lose sharing due to implicit call stacks
-------------------------------------+-------------------------------------
Reporter: simonmar | Owner: gridaphobe
Type: bug | Status: new
Priority: normal | Milestone: 8.0.1
Component: Compiler | Version: 8.0.1-rc1
Keywords: | Operating System: Unknown/Multiple
Architecture: | Type of failure: None/Unknown
Unknown/Multiple |
Test Case: | Blocked By:
Blocking: | Related Tickets:
Differential Rev(s): | Wiki Page:
-------------------------------------+-------------------------------------
The implicit call stack machinery adds a constraint to CAFs, which loses
sharing in some cases. The regression is fixed by -O (actually `-ffull-
laziness`), but it is surprising nonetheless, and might cause problems for
people using GHCi or other places where -O is turned off.
For example:
{{{
{-# LANGUAGE NoMonomorphismRestriction #-}
module Main where
import System.Environment
fib :: Integer -> Integer
fib n = if n < 2 then 1 else fib (n-1) + fib (n-2)
x = if fib 3 > 20 then error "x" else fib 30
main = do
[n] <- getArgs
case n of
"a" -> print (x + x)
"b" -> print x
}}}
Try it as follows (requires 8.0+):
{{{
$ ghc imp.hs -fforce-recomp -O -fno-full-laziness
$ ./imp a +RTS -t
2692538
<