[GHC] #12620: Allow the user to prevent floating and CSE
GHC
ghc-devs at haskell.org
Thu Sep 29 23:20:48 UTC 2016
#12620: Allow the user to prevent floating and CSE
-------------------------------------+-------------------------------------
Reporter: nomeata | Owner:
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: #9520, #8457 | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by edsko):
Replying to [comment:9 tomjaguarpaw]:
> I'm very glad to see full laziness getting some attention (...) I have
even asked whether it is an optimization worth performing at all, though I
conclude that it is:
>
> * https://stackoverflow.com/questions/35115172/why-is-full-laziness-a
-default-optimization/35115664
Yup, I cite this in the blog post :)
> However I do not think this suggestion is the right approach. (...)
The proposed `nofloat` keyword is just adding additional complexity over a
transformation which itself is introducing too much complexity. I'm very
concerned about the idea.
I agree that it would be preferable not to "program the optimizer" when
writing Haskell code. That's another reason in fact why I prefer
`noupdate` over `nofloat`, beacuse actually `noupdate` goes beyond full
laziness. Consider this example from the blog post:
{{{#!hs
retry :: IO a -> IO a
retry io = catch io (\(_ :: SomeException) -> retry io)
main :: IO ()
main = retry $ ni_mapM_ print [1..1000000]
}}}
This program has a memory leak, but it's nothing to do with full laziness
here. Now admittedly we could turn this into a full laziness issue by
giving the argument to `retry` a dummy unit argument or something like
that, so that we write
{{{#!hs
retry :: (() -> IO a) -> IO a
retry io = catch (io ()) (\(_ :: SomeException) -> retry io)
main :: IO ()
main = retry $ \() -> ni_mapM_ print [1..1000000]
}}}
or something like that, but then you would have to do that in every single
function that duplicates IO actions (think `forever`, `replicateM_`, etc.)
Instead, we could mark that list as `noupdate` and the memory leak would
be gone.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12620#comment:11>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list