Skip to content

getIdFromTrivialExpr panic with interpreter + optimizations

The following file causes a panic in getIdFromTrivialExpr in a compiler that is modified to support ghci -O (see #23267 (closed))

module I where

class C a where
  unused :: forall b. Eq b => b -> a

instance C () where
  unused = unused

gmapM :: forall m. (() -> m, m -> m -> m) -> (forall a. C a => a -> a) -> m
gmapM kla g = f ()
  where
    f :: forall a. C a => a -> m
    f x = seq (g x) (snd kla (fst kla ()) (fst kla ()))
$ ./stage1/bin/ghc -dlint -O --interactive I 
GHCi, version 9.7.20230416: https://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling I                ( I.hs, interpreted ) [Source file changed]
<glooming warnings>
<no location info>: error:
    panic! (the 'impossible' happened)
  GHC version 9.7.20230416:
	getIdFromTrivialExpr
  poly_f_sZt @m_aVZ $sf_sZa
  Call stack:
      CallStack (from HasCallStack):
        callStackDoc, called at compiler/GHC/Utils/Panic.hs:189:37 in ghc:GHC.Utils.Panic
        pprPanic, called at compiler/GHC/Core/Utils.hs:1083:18 in ghc:GHC.Core.Utils
        getIdFromTrivialExpr, called at compiler/GHC/Core/Subst.hs:597:14 in ghc:GHC.Core.Subst
  CallStack (from HasCallStack):
    panic, called at compiler/GHC/Utils/Error.hs:479:29 in ghc:GHC.Utils.Error

Instead of -O it's possible to pass -ffull-laziness -fstrictness -fcall-arity -fspecialize, all 4 are needed.

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