[GHC] #12620: Allow the user to prevent floating and CSE

GHC ghc-devs at haskell.org
Wed Oct 5 22:03:05 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 simonpj):

 > Any thunk of type `Sink` never gets updated.

 That's extremely dodgy isn't it?   What about
 {{{
 let s1 :: Sink = ...
     s2 :: Sink = ...
     x  :: Sink = if <expensive> then s1 else s2
 }}}
 If `x` is not updated, but is evaluated more than once, we'll evaluate
 `<expensive>` more than once.

 Perhaps you mean something more like this:
 {{{
 data Sink = Await (Maybe Char -o Sink) | Done Int
 }}}
 Notice the "`-o`", meaning a "one-shot function".  The idea is that one-
 shot functions are called at most once.  (Maybe exactly once, but I think
 at-most once is better.)

 So in your `countFrom` example, the continuation `k` would not be floated
 outside the lambda; and if it was written outside it'd be floated inside
 the lambda.

 GHC already has the notion of a one-shot lambda; it's just not dignified
 as part of the type system.

 Would that serve?  I think that you do intend that the argujment of
 `Await` is called at most once, don't you?

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12620#comment:25>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list