HEAD regression: lookupIdSubst panic with GHCi
(Originally observed in a head.hackage
issue: head.hackage#88 (comment 513332))
GHC HEAD (at commit eb1a6ab1) panics when loading the following code into GHCi:
-- A.hs
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module A where
import Data.Kind
type Sing :: k -> Type
#if __GLASGOW_HASKELL__ >= 909
type family Sing @k
#else
type family Sing
#endif
type SBool :: Bool -> Type
data SBool b where
SFalse :: SBool False
STrue :: SBool True
type instance Sing @Bool = SBool
type DefaultEq :: k -> k -> Bool
type family DefaultEq a b where
DefaultEq a a = 'True
DefaultEq a b = 'False
type Not :: Bool -> Bool
type family Not b where
Not False = True
Not True = False
sNot :: forall (b :: Bool). Sing b -> Sing (Not b)
sNot SFalse = STrue
sNot STrue = SFalse
class PEq a where
type (x :: a) == (y :: a) :: Bool
type (x :: a) /= (y :: a) :: Bool
type x /= y = Not (x == y)
class SEq a where
(%==) :: forall (x :: a) (y :: a).
Sing x -> Sing y -> Sing (x == y)
(%/=) :: forall (x :: a) (y :: a).
Sing x -> Sing y -> Sing (x /= y)
default (%/=) :: forall (x :: a) (y :: a).
((x /= y) ~ Not (x == y)) =>
Sing x -> Sing y -> Sing (x /= y)
(%/=) sx sy = sNot (sx %== sy)
-- B.hs
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module B where
import GHC.Exts (TYPE)
import Type.Reflection
import A
type instance Sing @(TYPE rep) = TypeRep
instance PEq (TYPE rep) where
type x == y = DefaultEq x y
instance SEq (TYPE rep) where
tra %== trb =
case eqTypeRep tra trb of
Just HRefl -> STrue
Nothing -> undefined
$ ghc-9.9.20230716 --interactive B.hs
GHCi, version 9.9.20230716: https://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rscott/.ghci
[1 of 2] Compiling A ( A.hs, interpreted )
[2 of 2] Compiling B ( B.hs, interpreted )
<no location info>: error:
panic! (the 'impossible' happened)
GHC version 9.9.20230716:
lookupIdSubst
eta_i1Ia
InScope {rep_a1uz $c%==_a1uB $c%/=_a1GR x_a1GW y_a1GX a_i1HX
$dSEq_i1HY x_i1HZ y_i1I0 $d~_i1I1 eta_i1I2 eta1_i1I3 co_i1I4
$fSEqTYPE $fPEqTYPE}
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/GHC/Utils/Panic.hs:191:37 in ghc-9.9-inplace:GHC.Utils.Panic
pprPanic, called at compiler/GHC/Core/Subst.hs:197:17 in ghc-9.9-inplace:GHC.Core.Subst
CallStack (from HasCallStack):
panic, called at compiler/GHC/Utils/Error.hs:503:29 in ghc-9.9-inplace:GHC.Utils.Error
Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug
Failed, one module loaded.
GHC 9.6 and earlier do not panic, on the other hand. I was only able to trigger the panic with GHCi, and not with an ordinary invocation of GHC.