Skip to content

GHC 8.4.1-alpha panics when optimizing function using getTag and tagToEnum#

I originally observed this panic in this Travis build. The panic can be reduced to this file:

{-# LANGUAGE MagicHash #-}
{-# LANGUAGE TypeFamilies #-}
module Bug where

import GHC.Base (getTag)
import GHC.Exts (Int(..), tagToEnum#)

data family TyFamilyEnum
data instance TyFamilyEnum = TyFamilyEnum1 | TyFamilyEnum2 | TyFamilyEnum3

suc :: TyFamilyEnum -> TyFamilyEnum
suc a_aaf8
        = case getTag a_aaf8 of
             a_aaf9
               -> if 2 ==  I# a_aaf9
                  then error "succ{TyFamilyEnum}: tried to take `succ' of last tag in enumeration"
                  else case I# a_aaf9 + 1 of
                         I# i_aafa -> tagToEnum# i_aafa :: TyFamilyEnum

In GHC 8.2.2, compiling this with optimization works fine. But in GHC 8.4.1-alpha, it panics:

$ /opt/ghc/8.4.1/bin/ghc -fforce-recomp -O1 Bug.hs
[1 of 1] Compiling Bug              ( Bug.hs, Bug.o )
ghc: panic! (the 'impossible' happened)
  (GHC version 8.4.0.20171222 for x86_64-unknown-linux):
        Prelude.!!: index too large
Trac metadata
Trac field Value
Version 8.4.1-alpha1
Type Bug
TypeOfFailure OtherFailure
Priority highest
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information