GHC: Ticket #8066: Compiler Panic When Using Instance Derivation With Singletons
http://ghc.haskell.org/trac/ghc/ticket/8066
<p>
The following code causes a compiler panic:
</p>
<pre class="wiki">{-# LANGUAGE MultiParamTypeClasses, TypeSynonymInstances, FlexibleInstances, TemplateHaskell, GADTs, TypeFamilies, DataKinds, KindSignatures #-}
module Example
( UnqualifiedTVar(..)
, QualifiedTVar(..)
, TVar(..)
, QVar
, UVar
, TQual(..)
) where
import GHC.TypeLits
import qualified Data.Set as Set
type Identifier = String
type Span = (Int,Int)
data QualForm
= UnqualifiedTVar
| QualifiedTVar
deriving (Eq, Ord, Read, Show)
data instance Sing (f :: QualForm) where
UnqualifiedTVarS :: Sing UnqualifiedTVar
QualifiedTVarS :: Sing QualifiedTVar
instance Eq (Sing (a::QualForm)) where
(==) = undefined
instance Ord (Sing (a::QualForm)) where
compare = undefined
instance SingI UnqualifiedTVar where
sing = UnqualifiedTVarS
instance SingI QualifiedTVar where
sing = QualifiedTVarS
data TVar (a :: QualForm)
= TVar (Sing a) Int [Span]
deriving (Eq, Ord, Show)
type QVar = TVar QualifiedTVar
type UVar = TVar UnqualifiedTVar
data AnyVar
= SomeQVar QVar
| SomeUVar UVar
anyVar :: TVar (a :: QualForm) -> AnyVar
anyVar a =
let (TVar s _ _) = a in
case fromSing s of
UnqualifiedTVarS -> SomeUVar a
QualifiedTVarS -> SomeQVar a
</pre><p>
This has been tested on GHC 7.6.1 and GHC 7.6.3; both give an error message such as
</p>
<pre class="wiki">ghc: panic! (the 'impossible' happened)
(GHC version 7.6.1.20121207 for i386-unknown-linux):
find_thing APromotionErr FamDataConPE
</pre><p>
This problem seems to have something to do with instance derivation; removing the instances for Eq and Ord causes the problem to go away.
</p>
en-usGHChttp://ghc.haskell.org/trac/ghc/chrome/site/ghc_logo.png
http://ghc.haskell.org/trac/ghc/ticket/8066
Trac 1.2.2.dev0tvynrTue, 16 Jul 2013 20:03:27 GMTfailure changed
http://ghc.haskell.org/trac/ghc/ticket/8066#comment:1
http://ghc.haskell.org/trac/ghc/ticket/8066#comment:1
<ul>
<li><strong>failure</strong>
changed from <em>None/Unknown</em> to <em>Compile-time crash</em>
</li>
</ul>
TicketsimonpjThu, 25 Jul 2013 07:15:04 GMT
http://ghc.haskell.org/trac/ghc/ticket/8066#comment:2
http://ghc.haskell.org/trac/ghc/ticket/8066#comment:2
<p>
The HEAD gives
</p>
<pre class="wiki">T8066.hs:42:22:
No instance for (SingE QualForm (KindOf QualForm a))
arising from the 'deriving' clause of a data type declaration
Possible fix:
use a standalone 'deriving instance' declaration,
so you can specify the instance context yourself
When deriving the instance for (Show (TVar a))
</pre><p>
Does that seem more reasonable? We've fixed lots of kind-related bugs in 7.6.
</p>
<p>
If the error looks ok, can we close the ticket?
</p>
<p>
Simon
</p>
TickettvynrThu, 25 Jul 2013 11:04:40 GMT
http://ghc.haskell.org/trac/ghc/ticket/8066#comment:3
http://ghc.haskell.org/trac/ghc/ticket/8066#comment:3
<p>
That looks great, thanks. Everything I was worried about is fine; I'd call the ticket closed. :) And for anyone else who encounters this problem or is perhaps about as confused by the TypeLits stuff as I am, adding the following fixes the panic in GHC 7.6.1 (and leads to revealing mistakes in the anyVar function):
</p>
<pre class="wiki">instance SingE (Kind :: QualForm) QualForm where
fromSing x = case x of
UnqualifiedTVarS -> UnqualifiedTVar
QualifiedTVarS -> QualifiedTVar
</pre>
TicketsimonpjFri, 26 Jul 2013 23:22:36 GMTstatus changed; resolution set
http://ghc.haskell.org/trac/ghc/ticket/8066#comment:4
http://ghc.haskell.org/trac/ghc/ticket/8066#comment:4
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
</ul>
Ticket