Skip to content

"GHC.StgToCmm.Env: variable not found" panic when compiling with -fobject-code (HEAD only)

If you compile the following code:

-- A.hs
module A (C(..)) where

class C a where
  m :: a -> a
  m = identity

identity :: a -> a
identity x = x
-- B.hs
module B where

import A

instance C ()

On GHC HEAD with the -fobject-code flag, it will panic:

$ ~/Software/ghc5/inplace/bin/ghc-stage2 B.hs -fobject-code -fforce-recomp
[1 of 2] Compiling A                ( A.hs, A.o )
[2 of 2] Compiling B                ( B.hs, B.o )
ghc-stage2: panic! (the 'impossible' happened)
  (GHC version 8.11.0.20200222:
        GHC.StgToCmm.Env: variable not found
  identity_rgg
  local binds for:
  eta_B1
  $trModule
  $trModule1_rIF
  $trModule2_rIL
  $trModule3_rIM
  $trModule4_rIN
  Call stack:
      CallStack (from HasCallStack):
        callStackDoc, called at compiler/utils/Outputable.hs:1233:37 in ghc:Outputable
        pprPanic, called at compiler/GHC/StgToCmm/Env.hs:149:9 in ghc:GHC.StgToCmm.Env

The same panic does not occur with GHC 8.8.2 or GHC 8.10.1-rc1:

$ /opt/ghc/8.8.2/bin/ghc B.hs -fobject-code -fforce-recomp
[1 of 2] Compiling A                ( A.hs, A.o )
[2 of 2] Compiling B                ( B.hs, B.o )

$ /opt/ghc/8.10.1/bin/ghc B.hs -fobject-code -fforce-recomp
[1 of 2] Compiling A                ( A.hs, A.o )
[2 of 2] Compiling B                ( B.hs, B.o )

This example was minimized from the basement library, where I actually encountered this panic in practice.

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