[GHC] #7411: Exceptions are optimized away in certain situations

GHC ghc-devs at haskell.org
Mon May 7 13:39:46 UTC 2018


#7411: Exceptions are optimized away in certain situations
-------------------------------------+-------------------------------------
        Reporter:  SimonHengel       |                Owner:  tdammers
            Type:  bug               |               Status:  new
        Priority:  high              |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  7.6.1
      Resolution:                    |             Keywords:  seq, deepseq,
                                     |  evaluate, exceptions
Operating System:  Linux             |         Architecture:  x86_64
                                     |  (amd64)
 Type of failure:  Incorrect result  |            Test Case:
  at runtime                         |  simplCore/should_fail/T7411
      Blocked By:                    |             Blocking:
 Related Tickets:  #5129             |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by tdammers):

 Another data point: this only happens with lists, not with tuples - e.g.,
 the following works as expected:

 {{{
 import Control.Exception
 import Control.DeepSeq
 main = evaluate (('a', undefined :: [Char]) `deepseq` return () :: IO ())
 }}}

 Which is baffling in that the `NFData` instances for tuples and lists are
 strikingly similar and *should* do the same thing.

 It gets even more baffling when I implement a custom (but isomorphic)
 drop-in replacement for `[]`, like so:

 {{{
 import Control.Exception
 import Control.DeepSeq

 data List a = Nil | Cons a (List a)

 instance NFData a => NFData (List a) where
   rnf v = case v of
     Nil -> ()
     (Cons x (Cons y xs)) -> rnf x `seq` rnf y `seq` rnf xs

 main = evaluate ((Cons 'a' $ Cons undefined $ Nil) `deepseq` return () ::
 IO ())
 }}}

 This example reproduces the problem; however, changing the instance like
 this behaves:

 {{{
 instance NFData a => NFData (List a) where
   rnf v = case v of
     Nil -> ()
     (Cons x (Cons y xs)) -> rnf x `seq` rnf y
 }}}

 In other words, if the `NFData` instance says *not* to look beyond the
 second list element, then the failure occurs, but if does look beyond,
 then it gets optimized away.

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


More information about the ghc-tickets mailing list