Skip to content

HEAD-only panic when compiling primitive-0.7.1 without optimization (cpe_app(runRW#))

The following code, reduced from the primitive-0.7.1 library, will panic when build with HEAD + O0:

{-# LANGUAGE MagicHash #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE UnboxedTuples #-}
module Bug where

import GHC.Exts
import GHC.ST

data MutableArray s a = MutableArray (MutableArray# s a)

runArray#
  :: (forall s. ST s (MutableArray s a))
  -> Array# a
runArray# m = case runRW# $ \s ->
  case unST m s of { (# s', MutableArray mary# #) ->
  unsafeFreezeArray# mary# s'} of (# _, ary# #) -> ary#

unST :: ST s a -> State# s -> (# State# s, a #)
unST (ST f) = f
$ ~/Software/ghc5/inplace/bin/ghc-stage2 Bug.hs -fforce-recomp -O0
[1 of 1] Compiling Bug              ( Bug.hs, Bug.o )
ghc-stage2: panic! (the 'impossible' happened)
  (GHC version 8.11.0.20200619:
        cpe_app(runRW#)
  [app TYPE: 'TupleRep '[ 'TupleRep '[], 'UnliftedRep],
   app TYPE: (# State# RealWorld, Array# a_axd #)]
  0
  Call stack:
      CallStack (from HasCallStack):
        callStackDoc, called at compiler/GHC/Utils/Outputable.hs:1229:37 in ghc:GHC.Utils.Outputable
        pprPanic, called at compiler/GHC/CoreToStg/Prep.hs:803:11 in ghc:GHC.CoreToStg.Prep

This does not happen with GHC 8.10.1.

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