[GHC] #15125: Typeclass instance selection depends on the optimisation level

GHC ghc-devs at haskell.org
Wed May 9 13:04:01 UTC 2018


#15125: Typeclass instance selection depends on the optimisation level
-------------------------------------+-------------------------------------
        Reporter:  nicuveo           |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  8.2.2
      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 RyanGlScott):

 I'm quite confused, as I can't seem to trigger this bug in GHC 8.4.2 (or
 HEAD).

 First, it's worth noting that the tarball you provided has a slightly
 different program than the one you gave in the original description. The
 modules in the tarball are:

 {{{#!hs
 {-# LANGUAGE FlexibleInstances #-}
 {-# OPTIONS_GHC -fno-warn-simplifiable-class-constraints #-}

 module A where

 import           Data.Maybe

 class A a where
   someValue :: a -> Maybe Int

 instance {-# INCOHERENT #-} A a where
   someValue = const Nothing

 getInt :: A a => a -> Int
 getInt x = fromMaybe 0 $ someValue x
 }}}
 {{{#!hs
 module B where

 import           A

 data B = B Int
 data C = C Int

 instance A B where
   someValue (B x) = Just x

 getBInt :: Int
 getBInt = getInt $ B 42

 getCInt :: Int
 getCInt = getInt $ C 42
 }}}
 {{{#!hs
 -- Main.hs
 import           B

 main :: IO ()
 main = do
   putStrLn "=========================================="
   putStrLn $ "B: " ++ show getBInt
   putStrLn $ "C: " ++ show getCInt
 }}}

 I'll use these, since the programs in the original description do not
 compile.

 Second, when I compile and run these with GHC 8.4.2, I get the same
 answer, regardless of optimization level:

 {{{
 $ /opt/ghc/8.4.2/bin/ghc -O0 -fforce-recomp Main.hs
 [1 of 3] Compiling A                ( A.hs, A.o )
 [2 of 3] Compiling B                ( B.hs, B.o )
 [3 of 3] Compiling Main             ( Main.hs, Main.o )
 Linking Main ...

 $ ./Main
 ==========================================
 B: 42
 C: 0

 $ /opt/ghc/8.4.2/bin/ghc -O2 -fforce-recomp Main.hs
 [1 of 3] Compiling A                ( A.hs, A.o )
 [2 of 3] Compiling B                ( B.hs, B.o )
 [3 of 3] Compiling Main             ( Main.hs, Main.o )
 Linking Main ...

 $ ./Main
 ==========================================
 B: 42
 C: 0
 }}}

 So unless you're using a yet more different version of this program, I'm
 inclined to agree that there is no bug here.

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


More information about the ghc-tickets mailing list