[GHC] #1038: selector thunks not working? space leak in standard example

GHC trac at galois.com
Tue Dec 5 21:09:24 EST 2006


#1038: selector thunks not working? space leak in standard example
-----------------------------------+----------------------------------------
    Reporter:  tullsen at galois.com  |       Owner:          
        Type:  bug                 |      Status:  new     
    Priority:  normal              |   Milestone:          
   Component:  Runtime System      |     Version:  6.6     
    Severity:  normal              |    Keywords:          
  Difficulty:  Unknown             |    Testcase:          
Architecture:  x86                 |          Os:  Multiple
-----------------------------------+----------------------------------------
I thought that GHC evaluates "THUNK_SELECTORS" and thus eliminates the
 space leak in this infamous example [Hughes83][Wadler87][Sparud93]:
 {{{
 module Main where

 surprise xs = b1 ++ [0,0] ++ b2
               where
               (b1,b2) = break (==0) xs

 strictFromTo :: Int -> Int -> [Int]
 strictFromTo i m = takeWhile (<= m) $ strictFrom i

 strictFrom :: Int -> [Int]
 strictFrom x = let x' = x + 1 in seq x' $ x' : strictFrom x'

 main = print (length $ surprise $ strictFromTo (-1000000) 1)
        -- space leak, w/ or w/o optimization
 main2 = print (length $ strictFromTo (-1000000) 1)
        -- runs in constant space, w/ or w/o optimization
 }}}
 However, this program does not run in constant space, even with -O2.
 I get the same results on
  GHC6.6  Mac OS X  Intel
  GHC6.2.1 Linux Intel
  GHC6.4.1 Linux Intel

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1038>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the Glasgow-haskell-bugs mailing list