Skip to content

GHC panic: "StgCmmEnv: variable not found" - Something with MonoLocalBinds, type inference and -fdefer-type-errors

Summary

GHC panics on some modules with GADTs enabled, top level declarations without type annotations and -fdefer-type-errors enabled.

Steps to reproduce

The smallest module I could find to trigger the bug:

{-# LANGUAGE GADTs #-}

breaks = pure "anything polymorphic"

main = do
  putStrLn "could be anything"
  breaks
  putStrLn "also could be anything"

Command and output:

▶ ghc -fdefer-type-errors Panic.hs
[1 of 1] Compiling Main             ( Panic.hs, Panic.o )
ghc: panic! (the 'impossible' happened)
  (GHC version 8.6.5 for x86_64-unknown-linux):
        StgCmmEnv: variable not found
  $dMonad_a1ce
  local binds for:
  $trModule
  whatever_rq4
  $trModule1_r1p6
  $trModule2_r1pj
  $trModule3_r1pk
  $trModule4_r1pl
  sat_s1rx
  Call stack:
      CallStack (from HasCallStack):
        callStackDoc, called at compiler/utils/Outputable.hs:1160:37 in ghc:Outputable
        pprPanic, called at compiler/codeGen/StgCmmEnv.hs:149:9 in ghc:StgCmmEnv

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

This compiles fine without -fdefer-type-errors, or with type signatures for either breaks or main, or without GADTs enabled. GHCi loads the module without problem, but panics whenever it needs to use any symbol from the module, including unrelated symbols.

Expected behavior

I expect GHC not to panic.

Environment

  • GHC version used: 8.6.5

Optional:

  • Operating System: Arch linux
  • System Architecture: x86_64
Edited by Ryan Scott
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information