Skip to content

GHC HEAD regression: Prelude.!!: index too large

git-annex-6.20170321 from Hackage currently fails to build with GHC 8.2.1 and HEAD because it triggers this panic. Here's a simplified example that exhibits the issue:

module Command.Vicfg where

import qualified Data.Map as M

class Default a where
  def :: a

instance Default Int where
  def = 0

data Cfg = Cfg
    { cfgTrustMap :: M.Map Int Int
    , cfgGroupMap :: M.Map Int Int
    }

defCfg :: Cfg -> Cfg
defCfg curcfg = Cfg
    { cfgTrustMap = mapdef $ cfgTrustMap curcfg
    , cfgGroupMap = mapdef $ cfgGroupMap curcfg
    }
  where
    mapdef :: Default v => M.Map k v -> M.Map k v
    mapdef = M.map (const def)
$ /opt/ghc/8.2.1/bin/ghc Bug.hs -O1
[1 of 1] Compiling Command.Vicfg    ( Bug.hs, Bug.o )
ghc: panic! (the 'impossible' happened)
  (GHC version 8.2.0.20170321 for x86_64-unknown-linux):
        Prelude.!!: index too large

Note:

  • You need optimization (-O1 or -O2) enabled.
  • You need to import Map/map for this panic to trigger, it seems, as redefining Map/map locally makes it work again.
Edited by Ryan Scott
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information