[GHC] #11555: catch _|_ breaks at -O1

GHC ghc-devs at haskell.org
Mon Feb 8 18:10:37 UTC 2016


#11555: catch _|_ breaks at -O1
-------------------------------------+-------------------------------------
        Reporter:  slyfox            |                Owner:
            Type:  bug               |               Status:  new
        Priority:  highest           |            Milestone:  8.0.1
       Component:  Compiler          |              Version:  8.0.1-rc2
      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):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by NeilMitchell):

 Note that the second example involves no {{{unsafePerformIO}}}, so it's
 surprisingly semantics just with imprecise exceptions alone. My personal
 expectation is that yes, you would have to create a thunk for {{{g}}} -
 but my expectations rarely match the lazy exception semantics. If
 alternatively you argue that one valid interpretation is {{{catch _|_ x =
 _|_}}}, then why not define:

 {{{#!hs
 catch !a b = ...
 }}}

 I suspect having a lazy first argument never improves performance, and now
 it's always picking the same semantics at all optimisation levels.

 Note that in the above examples {{{evaluate}}} is a sufficient trick, but
 for Shake only because I reduced the example. In the real code it takes an
 argument of type {{{IO a}}}. I think a correct general workaround is:

 {{{#!hs
 safeCatch a b = catch (join $ evaluate a) b
 }}}

 But it would be good to get someone who fully understands the semantics to
 declare this a "safe" trick.

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


More information about the ghc-tickets mailing list