[GHC] #13370: exprIsBottom inconsistent with strictness analyser

GHC ghc-devs at haskell.org
Mon Mar 6 20:16:26 UTC 2017


#13370: exprIsBottom inconsistent with strictness analyser
-------------------------------------+-------------------------------------
        Reporter:  simonpj           |                Owner:  (none)
            Type:  bug               |               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:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by dfeuer):

 All this looks to me like a piece of a bigger puzzle we need to solve
 relating to strictness in the presence of:

 1. Imprecise exceptions (which we have a whole paper about)

 2. Precise exceptions (which I think we ''don't'' have a good story around
 at all--see #13380)

 3. `catch` and friends.

 I had a (crazy?) thought last night. This may or may not make any sense at
 all, but it's driven by the fundamentally simple idea that ''precise''
 exceptions should be modeled by something that looks vaguely similar to
 `ExceptT SomeException (State (State# RealWorld))`, but that fits into the
 `IO` type we're pretty much stuck with. Right now, `State# RealWorld` is
 terrifically boring for its entire life. But I don't know if it needs to
 be. Imagine if we had instead (very, very approximately)

 {{{#!hs
 data OK = OK
 State# RealWorld = (# OK | SomeException #)
 }}}

 where the "state of the real world" includes what precise exception (if
 any) we have encountered. Now we could talk about ''precise'' exceptions
 in Core in an entirely different fashion:

 {{{#!hs
 instance Monad IO where
   return x = IO $ \s -> (# s, x #)

   -- If the state has become exceptional, then performing additional
   -- actions is useless.
   m >>= f = IO $ \s ->
     case unIO m s of
       (# (# | e #), _ #) -> (# (# | e #), undefined #)
       (# s', r #) -> unIO (f r) s'

 throwIO e = IO $ \s -> (# (# | e #), undefined #)

 -- Function for catching only precise exceptions
 catchIO m f = IO $ \s ->
   case unIO m s of
     (# (# | e #), _ #) -> unIO (f e) realWorld#
 }}}

 Then `seq#` could take on the "magical" job of turning imprecise
 exceptions into precise ones, allowing us to implement `catch`.

 {{{#!hs
 catch# m f s = case seq# (m s) of
   (# (# | e #), _ #) -> f e realWorld# --Imprecise exception executing (m
 s)
   (# _, (# (# | e #), _ #) #) -> f e realWorld# --Precise exception
 executing (m s)
   (# _, res #) -> res
 }}}

 We'd need to perform some sort of magic in code generation to get rid of
 this wacky `State#` and implement exceptions in the usual fashion (I have
 no idea what that would look like myself). But in Core, I think we'd
 greatly confine the weirdness.

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


More information about the ghc-tickets mailing list