[GHC] #12860: GeneralizedNewtypeDeriving + MultiParamTypeClasses sends typechecker into an infinite loop

GHC ghc-devs at haskell.org
Tue Apr 17 13:55:20 UTC 2018


#12860: GeneralizedNewtypeDeriving + MultiParamTypeClasses sends typechecker into
an infinite loop
-------------------------------------+-------------------------------------
        Reporter:  RyanGlScott       |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler (Type    |              Version:  8.0.1
  checker)                           |             Keywords:  FunDeps,
      Resolution:                    |  deriving
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Compile-time      |  Unknown/Multiple
  performance bug                    |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by RyanGlScott):

 I've hit another snag, related to comment:15. I tried putting the call to
 `checkValidInstance` after `simplifyDeriv` has finished iterating, but
 that doesn't work for the original program in this ticket. Why? Because
 during the second iteration of `simplifyDeriv`, we pass the context `C b
 a` (the result of the first iteration of `simplifyDeriv`) to
 `solveWantedsAndDrop`. But that leads to the infinite loop described in
 comment:2, so it's already too late by that point.

 Naturally, I thought to instead try calling `checkValidInstance` after
 //every// iteration of `simplifyDeriv`. This does fix the original
 program, but it causes `T4809.hs` to fail instead. The reason is because
 of this derived instance:

 {{{#!hs
 newtype XMLGenT m a = XMLGenT (m a)
   deriving (MonadRWS r w s)
 }}}

 After the first iteration of `simplifyDeriv`, it produces the context
 `Monoid w`. We then pass the following instance to `checkValidInstance`:

 {{{#!hs
 instance Monoid w => MonadRWS r w s (XMLGenT m)
 }}}

 But this doesn't satisfy the coverage condition for `MonadRWS`'s fundeps!
 (We need `m -> r`, `m -> w`, and `m -> s`.) The final context for this
 instance, `(MonadReader r m, MonadWriter w m, MonadState s m)`, //does//
 satisfy the coverage condition, but we don't get this until after a later
 iteration of `simplifyDeriv`.

 To sum it up: I can't call `checkValidInstance` at the end, since an
 intermediate context might throw the simplifier into a loop, but I can't
 call `checkValidInstance` in the middle either, since an intermediate
 context might not satisfy the coverage condition. I don't know how to
 proceed from here.

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


More information about the ghc-tickets mailing list