[GHC] #5205: Control.Monad.forever leaks space
GHC
cvs-ghc at haskell.org
Thu Jun 9 21:51:37 CEST 2011
#5205: Control.Monad.forever leaks space
---------------------------------+------------------------------------------
Reporter: akio | Owner: igloo
Type: bug | Status: new
Priority: highest | Milestone: 7.2.1
Component: libraries/base | Version: 7.0.3
Keywords: | Testcase:
Blockedby: | Difficulty:
Os: Unknown/Multiple | Blocking:
Architecture: Unknown/Multiple | Failure: Runtime performance bug
---------------------------------+------------------------------------------
Changes (by simonpj):
* owner: simonpj => igloo
Comment:
I've made 'forever' INLINABLE, and added a SPECIALISE pragma in GHC.ST.
{{{
commit ae10342b49b95393b09ffee8df8c847409699968
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date: Thu Jun 9 20:44:21 2011 +0100
Make 'forever' inlinable (fixes Trac #5205)
See Note [Make forever INLINABLE] in Control.Monad
>---------------------------------------------------------------
Control/Monad.hs | 18 ++++++++++++++++++
GHC/ST.lhs | 4 ++++
2 files changed, 22 insertions(+), 0 deletions(-)
}}}
That fixes the bug, but only with `-O`. Without `-O` you still get the
leak, and I don't really think its unreasonable. You have
{{{
x = forever (return ())
}}}
which expands to
{{{
x = return () >> return () >> return () >> ....etc....
}}}
If `(>>)` was expensive when applied to two args, then it'd be right to
hang onto the computed result. In the case of IO it isn't expensive, and
it's best to recompute (and save space) but only the optimiser can reveal
that.
Ian: can you add a perf/ test please, then close?
Simon
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5205#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list