Skip to content

Optimizer creates space leak on simple code

The following code should run in constant space:

{-# LANGUAGE BangPatterns #-}
go (x:xs) !n !k = go xs 0 (n+k+1)
main = print (go (repeat 'x') 0 0 :: Int)

However, when compiled with -O2, it rapidly eats up the heap. If n and k are forced to be Int rather than Integer, the problem disappears.

Core for the above with -O2 is here: http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8268 [[BR]] The original code from which this was taken is here: http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8266

Trac metadata
Trac field Value
Version 6.10.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information