[GHC] #15114: ghc 8.4.1 optimizes True to False

GHC ghc-devs at haskell.org
Wed May 2 21:28:46 UTC 2018


#15114: ghc 8.4.1 optimizes True to False
-------------------------------------+-------------------------------------
        Reporter:  elaforge          |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  8.4.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 hvr):

 The title is misleading IMO: it's not that the `else` branch is taken
 instead of the `then` branch, but rather that the `evaluate` effect
 floats/leaks out of the inactive control flow path. I.e. the `a` branch is
 still taken; it's just that the `error` exception is triggered before we
 can reach it.

 Here's a modified example which better shows what I mean:

 {{{#!hs
 import qualified Control.Exception as Exception
 import Debug.Trace

 main :: IO ()
 main = do
     c <- unserialize
     putStrLn "all is well"
     print c

 unserialize :: IO Char
 unserialize =
     if definitelyTrue
         then do
             putStrLn "HEY"
             return 'a'
         else do
             Exception.evaluate (traceShow "wrong place" 'b')

 {-# NOINLINE definitelyTrue #-}
 definitelyTrue :: Bool
 definitelyTrue = True
 }}}

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


More information about the ghc-tickets mailing list