Skip to content

ASSERT failed in_scope InScope

Summary

GHC 9.4.3 compiles a program successfully, while GHC HEAD 9.5.20221111 (obtained from https://gitlab.haskell.org/ghc/ghc/-/jobs/artifacts/master/raw/ghc-x86_64-darwin-validate.tar.xz?job=x86_64-darwin-validate) fails with a panic.

Steps to reproduce

Save this as Bug.hs:

{-# LANGUAGE UndecidableInstances #-}

{-# OPTIONS_GHC -O #-}

module Lib (foo) where

import qualified Data.Map as M

newtype Fix f = Fix (f (Fix f))

instance Eq (f (Fix f)) => Eq (Fix f) where
  Fix a == Fix b = a == b

instance Ord (f (Fix f)) => Ord (Fix f) where
  Fix a `compare` Fix b = a `compare` b

data Foo i r = Foo i r
  deriving (Eq, Ord)

newtype Bar a = Bar (M.Map Char (M.Map (Fix (Foo ())) Word))

foo :: Bar a -> Bar a -> Bar a
foo (Bar a) (Bar b) = Bar (M.unionWith M.union a b)

Now run:

$ ghc-9.4.3 Bug.hs
[1 of 1] Compiling Lib              ( Bug.hs, Bug.o )
$ ghc-head Bug.hs
[1 of 1] Compiling Lib              ( Bug.hs, Bug.o )
WARNING:
  Glomming in
  Lib:
    [s1oC :->, s1ri :->, s1rw :-> OnceL1!, s1sq :->, s1t1 :-> OnceL1!,
     s1tC :-> OnceL1!]
  Call stack:
      CallStack (from HasCallStack):
        warnPprTrace, called at compiler/GHC/Core/Opt/OccurAnal.hs:91:5 in ghc:GHC.Core.Opt.OccurAnal

<no location info>: error:
    panic! (the 'impossible' happened)
  GHC version 9.5.20221111:
	ASSERT failed!
  in_scope InScope {wild_00 wild_X1 wild_X2 a1_a11M a2_a11N b1_a11O
                    b2_a11P $c==_a12P $c/=_a131 $cp1Ord_a13h $ccompare_a13j $c<_a13G
                    $c<=_a140 $c>=_a14e $cmax_a14m $cmin_a14u $cp1Ord_a14I $c<_a14U
                    $c<=_a152 $c>_a15a $cmax_a15p $cmin_a15w $c/=_a15R $krep_a1ig
                    $krep_a1ih $krep_a1ii $krep_a1ij $krep_a1ik $krep_a1il $krep_a1im
                    $krep_a1in $krep_a1io $krep_a1ip $krep_a1iq $krep_a1ir $krep_a1is
                    $krep_a1it $krep_a1iu $krep_a1iv $krep_a1iw $krep_a1ix $krep_a1iy
                    $krep_a1iz $krep_a1iA wild_a1pe bx_a1pf kx_a1pg x_a1ph l_a1pi
                    r_a1pj wild_a1ux wild1_a1uz foo $tc'Fix $tcFix $fOrdFix $fEqFix
                    $tc'Foo $tcFoo $tc'Bar $tcBar $fEqFoo $fOrdFoo $trModule $dOrd_s1nX
                    $dOrd_s1nY foo_s1nZ $trModule_s1o0 $trModule_s1o1 $trModule_s1o2
                    $trModule_s1o3 $tcFix_s1o8 $tcFix_s1o9 $krep_s1oa $tc'Fix_s1ob
                    $tc'Fix_s1oc $tcFoo_s1od $tcFoo_s1oe $krep_s1of $krep_s1og
                    $krep_s1oh $krep_s1oi $krep_s1oj $krep_s1ok $krep_s1ol $krep_s1om
                    $tc'Foo_s1on $tc'Foo_s1oo $tcBar_s1op $tcBar_s1oq $krep_s1or
                    $krep_s1os $tc'Bar_s1ot $tc'Bar_s1ou $sunion_s1oC $ssplit_s1oP
                    $s$wsplit_s1pH $sinsert_s1qy $sinsertR_s1rc $sunionWith_s1ri
                    $ssplitLookup_s1rw $s$wsplitLookup_s1sq poly_go15_s1tE lvl_s1tF
                    $sgo15_s1tH $sgo15_s1tM $sgo15_s1tR lvl_s1tT $sgo15_s1tW
                    $sgo15_s1u1 $w$cmax_s1vW $w$cmin_s1we $w$c<=_s1wv $w$c>=_s1wM
                    a_s1xC k2_s1xD t_s1xE $wpoly_go15_s1xH $w$sgo15_s1xZ $w$sgo15_s1yh
                    $w$sgo15_s1yI $j_s1zD}
  tenv [a1oR :-> a_s1xC]
  cenv []
  tys [a_a12r]
  cos []
  needInScope {a_a12r}
  Call stack:
      CallStack (from HasCallStack):
        assertPpr, called at compiler/GHC/Core/TyCo/Subst.hs:696:5 in ghc:GHC.Core.TyCo.Subst
        checkValidSubst, called at compiler/GHC/Core/TyCo/Subst.hs:720:29 in ghc:GHC.Core.TyCo.Subst
        substTy, called at compiler/GHC/Core/Opt/Simplify/Env.hs:1233:18 in ghc:GHC.Core.Opt.Simplify.Env
        substTy, called at compiler/GHC/Core/Opt/Simplify/Iteration.hs:1306:14 in ghc:GHC.Core.Opt.Simplify.Iteration

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

Expected behavior

I'd expect both versions of GHC to compile successfully.

Environment

  • GHC version used: GHC HEAD 9.5.20221111
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information