#1752: space leak caused by $ vs. () with -O2
-------------------------+--------------------------------------------------
Reporter: guest | Owner:
Type: bug | Status: new
Priority: low | Milestone: _|_
Component: Compiler | Version: 6.6.1
Severity: normal | Resolution:
Keywords: | Difficulty: Unknown
Os: Windows | Testcase:
Architecture: Multiple |
-------------------------+--------------------------------------------------
Changes (by simonpj):
* priority: normal => low
* milestone: => _|_
Comment:
I don't think it's anything to do with the "$"; both versions leak in GHC
6.6.1 and 6.8. Heres is a boiled-down version:
{{{
module Main(main) where
fibs a b = a : fibs b (a+b)
odds (x:y:ys) = x : odds ys
main = print $ zipWith (==) (odds (fibs 0 1))
(fibs 0 1)
}}}
Try compiling with -O and running with
{{{
./leak +RTS -Sstderr > /dev/null
}}}
What happens is that GHC does commmon-subexpression on the `(fibs 0 1)` to
give:
{{{
fibs01 = fibs 0 1
main = print $ zipWith (==) (odds fibs01)
fibs01
}}}
Now the left argument of `zipWith` marches down the infinite twice as fast
as the right argument, so there's an ever-increasing chunk in between the
two. See the chapter on pragmatics in my 1987 book.
If you switch off common sub-expression `-fno-cse` then all is happy
again.
I don't know how to fix this. We also get bug reports about unexpected
''lack'' of commmon sub-expression, so it's a difficult transformation to
get right!
I'll leave it as low priority for now.
Simon
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1752#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs