Strictness analysis regression
The sum function from the Prelude relies on GHC's strictness analysis.
Here's a run on GHC 7.6.2 where I kill it partway through - max resident memory is over 6 GB. Everything works perfectly if I replace sum
with foldl' (+) 0.0
.
Chris Done also tested this on 7.4.2; in that case the memory leak is not present and the code runs fine.
---------------------------
chad@chad-desktop:~$ cat norm.hs
norm :: [Double] -> Double
norm = sqrt . sum . map (\x -> x*x)
main :: IO ()
main = print . norm $ enumFromTo 0 100000000
---------------------------
chad@chad-desktop:~$ ghc -V
The Glorious Glasgow Haskell Compilation System, version 7.6.2
---------------------------
chad@chad-desktop:~$ ghc -O2 norm.hs
[1 of 1] Compiling Main ( norm.hs, norm.o )
Linking norm ...
---------------------------
chad@chad-desktop:~$ /usr/bin/time ./norm
^CCommand terminated by signal 2
21.68user 2.72system 0:24.51elapsed 99%CPU (0avgtext+0avgdata 6370516maxresident)k
0inputs+0outputs (0major+1592762minor)pagefaults 0swaps
---------------------------
Trac metadata
Trac field | Value |
---|---|
Version | 7.6.2 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | Unknown/Multiple |
Architecture |