[GHC] #15135: Overlapping typeclass instance selection depends on the optimisation level

GHC ghc-devs at haskell.org
Wed Oct 24 10:45:37 UTC 2018


#15135: Overlapping typeclass instance selection depends on the optimisation level
-------------------------------------+-------------------------------------
        Reporter:  nicuveo           |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.8.1
       Component:  Compiler          |              Version:  8.4.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 AntC):

 Replying to [comment:3 baramoglo]:
 > Here is an example that exhibits the same bug (I think) in a single
 file:
 >
 > ...
 > Prints `Just A` when compiled with `-O0` and `Nothing` when compiled
 with `-O1`.
 >

 I agree the optimisation level shouldn't change the behaviour when
 everything's in a single module.

 > Note that the first instance should really say `{-# OVERLAPPABLE #-}`
 (AFAIU). If I change to that, the bug goes away.
 >

 Ugh! Strictly speaking, the second and third instances are `INCOHERENT`
 because in no substitution ordering. But your `project (B A) :: Maybe A`,
 by giving a type annotation means it's apart from the second instance. (It
 should resolve to the third, which is marked `OVERLAPPING` so that's OK
 against the other eligible instance, i.e. the first one.)

 > Let me know if you think this should be filed as a different bug.

 The O.P. is a classic 'Orphan Instances' problem, so expected behaviour.
 And as Simon's comment:2 says, use `OVERLAPPABLE` to avoid premature
 instance resolution in the imported module. I'm surprised that also seems
 to be required when in a single module. That seems too subtle for my
 liking.

 BTW what happens if you change all the pragmas to `OVERLAPS`? (That's
 supposed to give the effect of both `OVERLAPPING` and `OVERLAPPABLE`.)

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


More information about the ghc-tickets mailing list