Skip to content

RebindableSyntax with RankNTypes and type class method call yields panic.

The following program in a file ghc-panic.hs

{-# LANGUAGE
    GADTSyntax
  , RankNTypes
  , RebindableSyntax
#-}

import Prelude hiding ((>>=))

data InfDo where
    InfDo :: String -> (forall a. a -> InfDo) -> InfDo

prog :: InfDo
prog = do
    _ <- show (42 :: Int)
    prog
  where
    (>>=) = InfDo

main :: IO ()
main = let x = prog in x `seq` return ()

when loaded into GHCi yields

λ> main
ghc: panic! (the 'impossible' happened)
  (GHC version 8.4.3 for x86_64-unknown-linux):
	nameModule
  system $dShow_abfY
  Call stack:
      CallStack (from HasCallStack):
        callStackDoc, called at compiler/utils/Outputable.hs:1150:37 in ghc:Outputable
        pprPanic, called at compiler/basicTypes/Name.hs:241:3 in ghc:Name

and separate compilation yields

$ ghc ghc-panic.hs 
[1 of 1] Compiling Main             ( ghc-panic.hs, ghc-panic.o )
ghc: panic! (the 'impossible' happened)
  (GHC version 8.4.3 for x86_64-unknown-linux):
	StgCmmEnv: variable not found
  $dShow_a1qI
  local binds for:
  $tcInfDo
  $trModule
  $tcInfDo1_r1th
  $tcInfDo2_r1tH
  $trModule1_r1tI
  $trModule2_r1tJ
  $trModule3_r1tK
  $trModule4_r1tL
  sat_s1E4
  Call stack:
      CallStack (from HasCallStack):
        callStackDoc, called at compiler/utils/Outputable.hs:1150:37 in ghc:Outputable
        pprPanic, called at compiler/codeGen/StgCmmEnv.hs:149:9 in ghc:StgCmmEnv

The problem disappears when either the rank-2 type is removed from InfDo or when the call to show is replaced by a static string.

Besides 8.4.3, also reproduced with 8.6.0.20180714.

I believe it is somewhat related to https://ghc.haskell.org/trac/ghc/ticket/14963

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