CSE can create space leaks by increasing sharing
|Reported by:||guest||Owned by:|
|Type of failure:||Runtime performance bug||Test Case:|
|Related Tickets:||Differential Rev(s):|
The following program exhibits a space leak on GHC6.6.1. "noleak" doesn't exhibit the leak. The only difference is choosing to use $ (leaky) instead of () (non-leaky).
No leak happens if optimizations are off.
Compiled with c:\haskell> ghc -O2 --make fibsquares.hs
module Main where fibs a b = a : fibs b (a+b) odds (x:xs) = evens xs evens (x:xs) = x : odds xs square x = x*x sumSucc xs = zipWith (+) xs (tail xs) main = spaceleak spaceleak = mapM_ print $ zip [0..] $ takeWhile id $ zipWith (==) (odds $ fibs 0 1) $ sumSucc $ map square $ fibs 0 1 noleak = mapM_ print $ zip [0..] $ takeWhile id $ zipWith (==) (odds $ fibs 0 1) (sumSucc $ map square $ fibs 0 1)