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

GHC ghc-devs at haskell.org
Thu Oct 11 10:15:06 UTC 2018


#15696: Derived Ord instance for enumerations with more than 8 elements seems to be
incorrect
-------------------------------------+-------------------------------------
        Reporter:  mrkkrp            |                Owner:  osa1
            Type:  bug               |               Status:  patch
        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:  #14677, #15155    |  Differential Rev(s):  Phab:D5196,
       Wiki Page:                    |  Phab:D5201
-------------------------------------+-------------------------------------

Comment (by osa1):

 OK, that makes sense, thanks. Moving on, I'm now trying to understand an
 assertion in `FloatIn` which is triggered when I make the `can_fail`
 change and
 update `ok_app` so that `dataToTag#` is never OK for speculation.

 The assertion that fails is this: (in FloatIn.hs)

 {{{
 fiExpr _ to_drop (_, AnnLit lit)     = ASSERT( null to_drop ) Lit lit
 }}}

 The definition that triggers it:

 {{{
 $wclosureTypeHeaderSize_s75y [InlPrag=NOUSERINLINE[2]]
   :: ClosureType -> Int#
 [LclId, Arity=1, Str=<S,U>]
 $wclosureTypeHeaderSize_s75y
   = \ (w_s75u :: ClosureType) ->
       case dataToTag# @ ClosureType w_s75u of a#_a4k2 [Dmd=<S,U>]
       { __DEFAULT ->
       join {
         $j_s6vr [Dmd=<L,U(U)>] :: Int#
         [LclId[JoinId(0)], Str=m]
         $j_s6vr
           = case w_s75u of lwild_s6yB {
               __DEFAULT ->
                 case a#_a4k2 of a#_a4jU [Dmd=<L,A>] { __DEFAULT ->
                 case w_s75u of lwild_s6yA {
                   __DEFAULT ->
                     case a#_a4k2 of a#_X4Ml [Dmd=<L,A>] { __DEFAULT ->
                     case w_s75u of lwild_s6vm {
                       __DEFAULT ->
                         case a#_a4k2 of a#_X4Mq [Dmd=<L,A>] { __DEFAULT ->
 1# };
                       AP_STACK -> 2#
                     }
                     };
                   AP -> 2#
                 }
                 };
               THUNK_SELECTOR -> 2#
             } } in
       case <# a#_a4k2 15# of lwild_s6vx {
         __DEFAULT ->
           case a#_a4k2 of b#_a4k3 [Dmd=<S,U>] { __DEFAULT ->
           case <# 20# a#_a4k2 of lwild_s6vu {
             __DEFAULT -> 2#;
             1# -> jump $j_s6vr
           }
           };
         1# -> jump $j_s6vr
       }
       }
 }}}

 At one point `fiExpr` comes across this expression:

 {{{
 case a#_a4k2 :: Int# of a#_X4Mq [Dmd=<L,A>] { __DEFAULT -> 1# }
 }}}

 with an empty "to drop" list. At this point we try to float the case
 inside the
 alternative (happens in first `AnnCase` alternative of `fiExpr`), but body
 of
 the alternative is a literal so the assertion is triggered.

 Questions:

 - What's wrong with seeing a literal when floating stuff inwards? Why not
 just
   introduce case/let around it?

 - There should be some code somewhere that's supposed to ensure that this
   assertion is not triggered, but I can't find it.

 - Why did simplifier not remove this case expression? It does no work (the
   scrutinee is unlifted and binder is not used) but it's somehow not
 eliminated
   by the simplifier pass right before FloatIn.

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


More information about the ghc-tickets mailing list