Skip to content

"opt_univ fell into a hole" panic from rewrite rule

Roboguy reports (via IRC) that the following causes a GHC panic:

{-# LANGUAGE RankNTypes #-}

module Crash where

data Exp a = Exp

fromExp :: Exp a -> a
fromExp _ = error "Impossible"

toExp :: a -> Exp a
toExp _ = Exp



newtype Iter a b = Iter { getIter :: forall r. (a -> r) -> (b -> r) -> r }

iterLoop :: (a -> Iter a b) -> a -> b
iterLoop f x = getIter (f x) (iterLoop f) id


  -- This rewrite rule results in a GHC panic: "opt_univ fell into a hole" on GHC 8.0.1, 8.0.2, and 8.1.
{-# RULES "fromExp-into-iterLoop" [~]
    forall (f :: Int -> Iter (Exp Int) (Exp Char))
           (init :: Int).
    fromExp (iterLoop f init)
      =
    fromExp (iterLoop (f . fromExp) (toExp init))
  #-}

I have confirmed this, and see the following error:

ghc-stage2: panic! (the 'impossible' happened)
  (GHC version 8.1.20170305 for x86_64-unknown-linux):
        opt_univ fell into a hole
  {a1WD}
  Call stack:
      CallStack (from HasCallStack):
        prettyCurrentCallStack, called at compiler/utils/Outputable.hs:1191:58 in ghc:Outputable
        callStackDoc, called at compiler/utils/Outputable.hs:1195:37 in ghc:Outputable
        pprPanic, called at compiler/types/OptCoercion.hs:398:29 in ghc:OptCoercion
Trac metadata
Trac field Value
Version 8.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC roboguy
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information