Skip to content

Panic from refineFromInScope when simplifying Lam body

I encountered this problem when writing a Core plugin.

Suppose I have a Lam, say \ (eta_B0 :: Word8) -> v_B1 eta_B0 v_B3, and if I call simplExpr on its body, v_B1 eta_B0 v_B3, with the default SimplEnv (obtained via mkSimplEnv), GHC would panic:

ghc: panic! (the 'impossible' happened)
  (GHC version 9.2.1:
	refineFromInScope
  InScope {wild_00}
  eta_B0
  Call stack:
      CallStack (from HasCallStack):
        callStackDoc, called at compiler/GHC/Utils/Panic.hs:181:37 in ghc:GHC.Utils.Panic
        pprPanic, called at compiler/GHC/Core/Opt/Simplify/Env.hs:706:30 in ghc:GHC.Core.Opt.Simplify.Env

To work around this, I had to explicitly add eta_B0 to SimplEnv. This isn't needed in GHC 9.0 or before, but is needed in GHC 9.2. Is this the right behavior? It doesn't seem so - can't refineFromInScope simply return the Var as it is if it can't be refined?

I see that there are two related issues, #19360 (closed) and #20639 (closed), but their fixes don't resolve this.

GHC version used: 9.2.1 + 43cab5f7 (which fixes #20639 (closed))

Edit: this problem also exists in GHC 9.2.2.

cc @simonpj who fixed both of the above issues.

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