[GHC] #15918: GHC panic from QuantifiedConstraints(?)

GHC ghc-devs at haskell.org
Mon Nov 26 13:18:01 UTC 2018


#15918: GHC panic from QuantifiedConstraints(?)
-------------------------------------+-------------------------------------
        Reporter:  Iceland_jack      |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.3
       Component:  Compiler          |              Version:  8.6.2
      Resolution:                    |             Keywords:
                                     |  QuantifiedConstraints
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 another symptom of the bug identified in #15799.

 In the example of this ticket we have
 {{{
 Elaborated types
   Rev :: forall k. (k->*) -> Constraint
   Build :: forall k. ((k->*) -> Constraint) -> k -> *

   rev :: forall k (f :: k->*) (a :: k). Rev @k f => f a

   instance forall k (cls :: (k->*) -> Constraint).
               (forall (xx :: k->*). cls xx => Rev @k xx)
               => Rev @k (Build @k cls)

 From the RHS of uu:

   [W] Rev @k (Build ([] |> co))
   [W] co :: (* -> *)  ~  ((k->*) -> Constraint)
 }}}
 Decompose co, we get
 {{{
   [W] Rev @k (Build ([] |> (co1 -> co2)))
   [W] co1 :: *  ~  (k->*)
   [W] co2 :: *  ~  Constraint
 }}}
 Now the first constraint matches the instance, so we get a substitution:
 {{{
    cls :-> ([] |> (co1 -> co2)
 }}}
 Now
 * we apply `substTheta` (this is in `Inst.instDFunType`) to `(cls xx)`
 * `substTheta` calls `mkAppTy ([] |> (co1 -> co2)) xx`
 * `mkAppTy` uses `decomposePiCos` (which works) and then calls `mkCastTy`
 (twice)
 * Alas, `mkCastTy` considers that `Constraint ~ *`, and we lose `co2`
 And that's how the assert fails.

 The underlying cause is the same: `mkCastTy` is using `isReflexiveCo`, and
 we
 really want `mkTcCastTy` here.  But we don't really want to have a `Tc`
 variant
 of `substTy`!

 Sigh. So much pain from the varying treatment of `Constraint` and `Type`.

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


More information about the ghc-tickets mailing list