GHC: Ticket #10562: GHC 7.10.2 RC cannot build boolsimplifier-0.1.8
http://trac.haskell.org/trac/ghc/ticket/10562
<p>
In running a Stackage Nightly build with GHC 7.10.2 (via Herbert's PPA), I discovered the following regression:
</p>
<p>
<a class="ext-link" href="http://lpaste.net/135057"><span class="icon"></span>http://lpaste.net/135057</a>
</p>
<p>
Note that boolsimplifier-0.1.8 compiles just fine with GHC 7.10.1, but not with 7.10.2. I am still running the rest of the Stackage build.
</p>
<p>
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.10.1.20150619
</p>
en-usGHChttp://trac.haskell.org/trac/ghc/chrome/site/ghc_logo.png
http://trac.haskell.org/trac/ghc/ticket/10562
Trac 1.2.2snoybergTue, 23 Jun 2015 16:40:22 GMTmilestone set
http://trac.haskell.org/trac/ghc/ticket/10562#comment:1
http://trac.haskell.org/trac/ghc/ticket/10562#comment:1
<ul>
<li><strong>milestone</strong>
set to <em>7.10.2</em>
</li>
</ul>
TicketgershombTue, 23 Jun 2015 17:08:53 GMT
http://trac.haskell.org/trac/ghc/ticket/10562#comment:2
http://trac.haskell.org/trac/ghc/ticket/10562#comment:2
<p>
So the relevant lines seem to be:
</p>
<pre class="wiki">data QueryRep qtyp a where
QAtom :: (Ord a) => a -> QueryRep QAtomTyp a
QOp :: (Show qtyp, Ord a) => Set (QueryRep QAtomTyp a) -> Set (QueryRep (QFlipTyp qtyp) a) -> QueryRep qtyp a
instance (Eq a) => Eq (QueryRep qtyp a) where
(QAtom x) == (QAtom y) = x == y
(QOp as cs) == (QOp as' cs') = as == as' && cs == cs'
_ == _ = False -- can't happen
instance (Ord a) => Ord (QueryRep qtyp a) where
compare (QAtom x) (QAtom y) = compare x y
compare (QOp as cs) (QOp as' cs') = compare as as' `mappend` compare cs cs'
compare (QAtom _) _ = GT -- can't happen
compare _ _ = LT -- can't happen
</pre><p>
And the relevant error seems to be
</p>
<pre class="wiki"> Overlapping instances for Eq (QueryRep (QFlipTyp qtyp) a)
arising from a use of ‘compare’
</pre><p>
With the additional info:
</p>
<pre class="wiki"> There exists a (perhaps superclass) match:
from the context (Eq (QueryRep qtyp a), Ord a)
bound by the instance declaration
at Data/BoolSimplifier.hs:116:10-41
or from (Show qtyp, Ord a)
bound by a pattern with constructor
QOp :: forall qtyp a.
(Show qtyp, Ord a) =>
Set (QueryRep QAtomTyp a)
-> Set (QueryRep (QFlipTyp qtyp) a) -> QueryRep qtyp a,
in an equation for ‘compare’
at Data/BoolSimplifier.hs:118:14-22
or from (Show qtyp, Ord a)
bound by a pattern with constructor
QOp :: forall qtyp a.
(Show qtyp, Ord a) =>
Set (QueryRep QAtomTyp a)
-> Set (QueryRep (QFlipTyp qtyp) a) -> QueryRep qtyp a,
in an equation for ‘compare’
at Data/BoolSimplifier.hs:118:26-36
(The choice depends on the instantiation of ‘qtyp, a’
To pick the first instance above, use IncoherentInstances
when compiling the other instance declarations)
In the second argument of ‘mappend’, namely ‘compare cs cs'’
In the expression: compare as as' `mappend` compare cs cs'
In an equation for ‘compare’:
compare (QOp as cs) (QOp as' cs')
= compare as as' `mappend` compare cs cs'
</pre><p>
So what's happening is we've asserted there's an <code>Ord a</code> dictionary three different ways -- first and second from packing it in each of the two GADTs, and third from the constrain in the instance head. Interestingly, it doesn't seem to balk at duplicate <code>Ord</code> instances themselves, but from the fact that they lead to duplicate <code>Eq</code> instances.
</p>
<p>
To be honest, I don't remember why the <code>Ord</code> constraint is ever packed with the GADT at all. But, regardless, this seems like something the compiler should be able to handle properly, and it seems like a regression if it can't?
</p>
TicketgershombTue, 23 Jun 2015 17:09:23 GMTcc set
http://trac.haskell.org/trac/ghc/ticket/10562#comment:3
http://trac.haskell.org/trac/ghc/ticket/10562#comment:3
<ul>
<li><strong>cc</strong>
<em>gershomb</em> added
</li>
</ul>
TicketSimon Peyton Jones <simonpj@…>Thu, 25 Jun 2015 14:51:17 GMT
http://trac.haskell.org/trac/ghc/ticket/10562#comment:4
http://trac.haskell.org/trac/ghc/ticket/10562#comment:4
<p>
In <a class="changeset" href="http://trac.haskell.org/trac/ghc/changeset/c7b6fb59eca478650dcb391a6f424e3c42a155dc/ghc" title="Test Trac #10562">c7b6fb59eca478650dcb391a6f424e3c42a155dc/ghc</a>:
</p>
<pre class="message">Test Trac #10562</pre>
TicketsimonpjThu, 25 Jun 2015 15:50:30 GMT
http://trac.haskell.org/trac/ghc/ticket/10562#comment:5
http://trac.haskell.org/trac/ghc/ticket/10562#comment:5
<p>
Here is a smaller test case
</p>
<pre class="wiki">{-# LANGUAGE GADTs, TypeFamilies #-}
module T10562 where
type family Flip a
data QueryRep qtyp a where
QAtom :: a -> QueryRep () a
QOp :: QueryRep (Flip qtyp) a -> QueryRep qtyp a
instance (Eq a) => Eq (QueryRep qtyp a)
instance (Ord a) => Ord (QueryRep qtyp a) where
compare (QOp a) (QOp b) = a `compare` b
</pre><p>
With 7.10 we get
</p>
<pre class="wiki">T10562.hs:13:31:
Overlapping instances for Eq (QueryRep (Flip qtyp) a)
arising from a use of ‘compare’
</pre><p>
The problem arises because of the "silent superclass" trick (which is happily gone from HEAD). The instance declaration that is actually checked is
</p>
<pre class="wiki">instance (Eq (QueryRep qtyp a), Ord a) => Ord (QueryRep qtyp a)
</pre><p>
with an extra <code>Eq (QueryRep qtyp a)</code> constraint. That gets GHC confused when it tries to solve <code>Eq (QueryRep (Flip qtyp) a)</code> from a method.
</p>
<p>
A workaround is to use <code>-XIncoherentInstances</code> for this module.
</p>
<p>
Exactly the same failure happens with GHC 7.8.3 doesn't it? Though apparently not with 7.8.2, mysteriously.
</p>
<p>
I'm sorry but it's not feasible to get HEAD's solution into 7.10 now. It works fine in HEAD, and I'll add the example as a test case, to check it stays working.
</p>
<p>
Simon
</p>
TicketthoughtpoliceTue, 30 Jun 2015 14:07:01 GMTstatus, milestone changed; testcase, resolution set
http://trac.haskell.org/trac/ghc/ticket/10562#comment:6
http://trac.haskell.org/trac/ghc/ticket/10562#comment:6
<ul>
<li><strong>testcase</strong>
set to <em>tests/typecheck/should_compile/T10562</em>
</li>
<li><strong>status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
<li><strong>milestone</strong>
changed from <em>7.10.2</em> to <em>7.12.1</em>
</li>
</ul>
<p>
After a quick discussion with Simon, due to the infeasibility of fixing this (and there being a workaround), we're going to punt this to 7.12.1.
</p>
TicketthoughtpoliceFri, 11 Sep 2015 08:38:26 GMTmilestone changed
http://trac.haskell.org/trac/ghc/ticket/10562#comment:7
http://trac.haskell.org/trac/ghc/ticket/10562#comment:7
<ul>
<li><strong>milestone</strong>
changed from <em>7.12.1</em> to <em>8.0.1</em>
</li>
</ul>
<p>
Milestone renamed
</p>
Ticket