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

GHC ghc-devs at haskell.org
Thu Oct 25 11:43:55 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 simonpj):

 This is all caused by `-fsolve-constant-dicts`: see
 [http://downloads.haskell.org/~ghc/master/users-guide/using-
 optimisation.html#ghc-flag--fsolve-constant-dicts the manual], and Trac
 #12791 and #5835.

 The reason that behaviour differs with -O is because `-fsolve-constant-
 dicts` is implied by `-O`.

 The problem comes in
 {{{
 instance Project a b => Project a (B b) where
   project (B a) = project a
 }}}
 From the RHS we get
 {{{
 [W] Project a b
 }}}
 Shall we solve it from the dict passed into the instance?  Or
 from the top-level instance declaration?
 {{{
 instance {-# OVERLAPPING #-} Project a b where
   project _ = Nothing
 }}}
 With `-fsolve-constant-dicts`, GHC chooses the latter, wrongly.

 When you declare that instance as OVERLAPPABLE, thus
 {{{
 instance {-# OVERLAPPABLE #-} Project a b where
   project _ = Nothing
 }}}
 GHC carefully refrains from using it, precisely because it might be
 overlapped
 (Trac #14434).

 Sadly, ''any'' instance declaration can be overlapped; GHC gives no way to
 say "this instance declaration cannot and must not be overlapped".
 Instead, in the presence of overlapping instances, the soundness of
 `-fsolve-constant-dicts` relies on the user specifying that an instance
 can be overlapped, by saying OVERLAPPABLE.  This is terribly
 unsatisfactory, but at least we now understand what is going on.

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


More information about the ghc-tickets mailing list