GHCI panics: isUnliftedType
GHC panics when the following program is loaded in ghci:
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
module PatternPanic
(
Outer(..),
Inner(..),
pattern TestPat
) where
data Outer = Outer Inner Inner
data Inner = Inner Int Int
pattern TestPat :: String -> String -> Outer
pattern TestPat ref1 ref2 <-
Outer (Inner (extractRef -> Just ref1)
(extractRef -> Just ref2)
)
(Inner (isSameRef ref1 -> True)
(isSameRef ref2 -> True)
)
------------ Helper functions ------------
extractRef :: Int -> Maybe String
extractRef 0 = Nothing
extractRef v = Just $ show v
isSameRef :: String -> Int -> Bool
isSameRef refName e
| Just refName2 <- extractRef e
= refName == refName2
isSameRef _ _ = False
-- Note that the GHC panic does not happen if 'isSameRef' is replaced with the following version.
-- isSameRef :: String -> Int -> Bool
-- isSameRef refName e =
-- extractRef e == Just refName
Returns
GHCi, version 8.6.3: http://www.haskell.org/ghc/ :? for help
Prelude> :l PatternPanic.hs
[1 of 1] Compiling PatternPanic ( PatternPanic.hs, interpreted )
ghc: panic! (the 'impossible' happened)
(GHC version 8.6.3 for x86_64-apple-darwin):
isUnliftedType
r_a2Qa :: TYPE rep_a2Q9
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1160:37 in ghc:Outputable
pprPanic, called at compiler/types/Type.hs:2021:10 in ghc:Type
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
This simplified code snippet was extracted from a relatively large codebase (~180k LOC). Note, that we would get the same error when we try to compile this application with -O2
with ghc > 8.4. Unfortunately, I am not able to reproduce compilation failure with this minimal example, though.
I tried it with GHC 8.9.20190323 x86_64-apple-darwin
- same error.
#14828 (closed) looks quite similar.