CSE can create space leaks by increasing sharing
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)
Trac metadata
Trac field | Value |
---|---|
Version | 6.6.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture | Multiple |