Skip to content

Panic with unsafeCoerce and -dcore-lint

{-# LANGUAGE MagicHash, TypeInType, ScopedTypeVariables #-}
module UIOST where
import GHC.Exts
import Data.Kind
import Unsafe.Coerce

unsafeCoerce' :: forall (r :: RuntimeRep)
                       (a :: TYPE r) (b :: TYPE r).
                a -> b
unsafeCoerce' = unsafeCoerce id

Compiling this with optimization and -dcore-lint produces a panic:

ghc-stage2: panic! (the 'impossible' happened)
  (GHC version 8.1.20170308 for x86_64-unknown-linux):
        runtimeRepPrimRep
  typePrimRep (a_aW7 :: TYPE r_aW6)
  r_aW6
  Call stack:
      CallStack (from HasCallStack):
        prettyCurrentCallStack, called at compiler/utils/Outputable.hs:1191:58 in ghc:Outputable
        callStackDoc, called at compiler/utils/Outputable.hs:1195:37 in ghc:Outputable
        pprPanic, called at compiler/simplStg/RepType.hs:360:5 in ghc:RepType

Using unsafeCoerce# id produces the panic without optimization. I have not been able to reproduce the problem without -dcore-lint.

Edited by David Feuer
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information