[GHC] #15696: Derived Ord instance for enumerations with more than 8 elements seems to be incorrect

GHC ghc-devs at haskell.org
Tue Oct 2 17:08:39 UTC 2018


#15696: Derived Ord instance for enumerations with more than 8 elements seems to be
incorrect
-------------------------------------+-------------------------------------
        Reporter:  mrkkrp            |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  highest           |            Milestone:  8.6.2
       Component:  Compiler          |              Version:  8.6.1
      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 RyanGlScott):

 It's also worth noting that you can trim `T` down to just two
 constructors:

 {{{#!hs
 {-# LANGUAGE MagicHash #-}
 module Main where

 import GHC.Base (getTag)
 import GHC.Exts (tagToEnum#, (==#), (<#))

 main :: IO ()
 main = print $ compare a T2
   where
     {-# NOINLINE f #-}
     f = T2
     {-# NOINLINE a #-}
     a = f

 data T = T1 | T2
   deriving (Eq, Show)

 instance Ord Main.T where
   compare a b
     = case getTag a of
         a' -> case getTag b of
                 b' -> if tagToEnum# (a' <# b') :: Bool then
                           LT
                       else
                           if tagToEnum# (a' ==# b') :: Bool then
                               EQ
                           else
                               GT
 }}}

 And the bug will still trigger. (If you define `data T = T2`, then the bug
 will go away.)

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


More information about the ghc-tickets mailing list