Skip to content

ghc panic: Template variable unbound in rewrite rule when compiling with -O2

I've seen a few related tickets, but they are market as closed.

% ghc -O2 binlist.hs


[1 of 1] Compiling Main             ( binlist.hs, binlist.o )
ghc: panic! (the 'impossible' happened)
  (GHC version 7.10.1.20150630 for x86_64-unknown-linux):
        Template variable unbound in rewrite rule
  sg_s5zh
  [sc_s5zf, sc_s5zg, sg_s5zh, sg_s5zi]
  [sc_s5zf, sc_s5zg, sg_s5zh, sg_s5zi]
  [: @ a_a3fo sc_s5zf sc_s5zg]
  [: @ a_a3fo sc_s5zb sc_s5zc]

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

% cat binlist.hs

import Control.Monad
import Data.Binary
import Data.List


newtype A a = A [a]


instance Binary a => Binary (A a) where
    put (A xs) = case splitAt 254 xs of
        (_, []) -> mapM_ put xs
        (a, b)  -> put (A b)
 
    get = do xs <- replicateM 254 get
             A ys <- get
             return $ A $ xs ++ ys

main :: IO ()
main = undefined
Edited by Richard Eisenberg
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information