HEAD-only panic (coVarKindsTypesRole, non coercion variable) with -O2 and -dcore-lint
This was originally spotted on head.hackage
's CI, as this bug prevents the JuicyPixels-3.3.4
library from compiling. Here is a minimized reproducer:
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE TypeOperators #-}
module Codec.Picture.Metadata where
import Control.DeepSeq( NFData( .. ) )
import Data.Typeable( (:~:)( Refl ) )
import Data.Word( Word16 )
data ExifTag
= TagPhotometricInterpretation
| TagUnknown !Word16
deriving Eq
data ExifData = ExifNone
data Keys a where
Exif :: !ExifTag -> Keys ExifData
Unknown :: !String -> Keys Value
data Value
data Elem k =
forall a. (Show a, NFData a) => !(k a) :=> a
keyEq :: Keys a -> Keys b -> Maybe (a :~: b)
keyEq a b = case (a, b) of
(Unknown v1, Unknown v2) | v1 == v2 -> Just Refl
(Exif t1, Exif t2) | t1 == t2 -> Just Refl
_ -> Nothing
newtype Metadatas = Metadatas { getMetadatas :: [Elem Keys] }
lookup :: Keys a -> Metadatas -> Maybe a
lookup k = go . getMetadatas where
go [] = Nothing
go ((k2 :=> v) : rest) = case keyEq k k2 of
Nothing -> go rest
Just Refl -> Just v
With GHC 8.10.1 or earlier, this compiles successfully with -O2
and -dcore-lint
. On GHC HEAD, however, it panics:
$ ~/Software/ghc5/inplace/bin/ghc-stage2 -O2 -fforce-recomp Bug2.hs -dcore-lint
[1 of 1] Compiling Codec.Picture.Metadata ( Bug2.hs, Bug2.o )
ghc-stage2: panic! (the 'impossible' happened)
(GHC version 8.11.0.20191217:
coVarKindsTypesRole, non coercion variable
wild_X6
ExifTag
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1173:37 in ghc:Outputable
pprPanic, called at compiler/types/Coercion.hs:490:4 in ghc:Coercion