[GHC] #15349: fixST is a bit wrong

GHC ghc-devs at haskell.org
Sat Jul 21 20:11:12 UTC 2018


#15349: fixST is a bit wrong
-------------------------------------+-------------------------------------
        Reporter:  dfeuer            |                Owner:  dfeuer
            Type:  bug               |               Status:  merge
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Core Libraries    |              Version:  8.5
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Incorrect result  |  Unknown/Multiple
  at runtime                         |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):  Phab:D4948
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by dfeuer):

 Let's try to think this lazy thing through a little bit. In the general
 case, we have something like

 {{{#!hs
 runST $ (m >>= \x -> fixST (f x)) >>= g
 }}}

 There are lots of possible ways the dependencies could go. `g` may demand
 a value and/or a state token. Depending on that, `f x` may demand a value
 and/or a state token.

 If `f x` does ''not'' end up demanding a state token, then that means it
 doesn't mutate anything, so it's safe to duplicate its evaluation (but
 also perfectly fine to ensure that doesn't happen, of course). On the flip
 side, the `MVar` solution can easily fall apart here; if we read a value
 from an `MVar`, we have to make sure to run an action to fill it.
 Furthermore, we can't just stick `MVar` creation into the state thread,
 because that will demand a state token that we're not allowed to demand.

 If `f x` demands a state token, then it ''might'' perform mutation, and
 therefore mustn't be duplicated.

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


More information about the ghc-tickets mailing list