CorePrep: unlifted but not ok-for-speculation assert failure
The program below triggers the following assertion (GHC built with DEBUG) on HEAD:
-- GHC.CoreToStg.Prep.mkFloat
| is_unlifted = ASSERT2( ok_for_spec, ppr rhs )
FloatCase rhs bndr DEFAULT [] True
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE UnboxedSums #-}
{-# LANGUAGE UnboxedTuples #-}
{-# OPTIONS_GHC -ddump-simpl -ddump-stg-final -ddump-to-file -dno-typeable-binds -O #-}
module Bug where
build f (# ma #) = case ma of
(# a | #) -> (# | f a #)
(# | a #) -> (# | f a #)
rebuild def f (# ma #) = case ma of
(# _ | #) -> (# def | #)
(# | a #) -> (# | f a #)
rebuild2 def f (# ma, b #) = case ma of
(# a | #) -> rebuild def (f a) (# b #)
(# | a #) -> build (f a) (# b #)
go :: (env -> a -> (# env, (# a | a #) #)) -> env -> [a] -> (# env, (# [a] | [a] #) #)
go _ env [] = (# env, (# [] | #) #)
go f env t@(a:as) = (# env'', t' #)
where
!t' = rebuild2 t (:) (# a', as' #)
!(# env', !as' #) = go f env as
!(# env'', !a' #) = f env' a
❯ ~/projects/ghc/master/_build/ghc-stage1 Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
ghc: panic! (the 'impossible' happened)
(GHC version 9.1.20210301:
ASSERT failed!
case ipv3_sD3 of {
(#_|#) a2_sD5 ->
case ipv1_sD0 of {
(#_|#) ds4_sD7 ->
(#_|#) @'LiftedRep @'LiftedRep @[a_aza] @[a_aza] wild_sCU;
(#|_#) a3_sD8 ->
let {
sat_sD9 :: [a_aza]
[LclId]
sat_sD9 = : @a_aza a2_sD5 a3_sD8 } in
(#|_#) @'LiftedRep @'LiftedRep @[a_aza] @[a_aza] sat_sD9
};
(#|_#) a2_sDa ->
case ipv1_sD0 of {
(#_|#) a3_sDc ->
let {
sat_sDd :: [a_aza]
[LclId]
sat_sDd = : @a_aza a2_sDa a3_sDc } in
(#|_#) @'LiftedRep @'LiftedRep @[a_aza] @[a_aza] sat_sDd;
(#|_#) a3_sDe ->
let {
sat_sDf :: [a_aza]
[LclId]
sat_sDf = : @a_aza a2_sDa a3_sDe } in
(#|_#) @'LiftedRep @'LiftedRep @[a_aza] @[a_aza] sat_sDf
}
}
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/GHC/Utils/Panic.hs:181:37 in ghc:GHC.Utils.Panic
pprPanic, called at compiler/GHC/Utils/Panic.hs:300:5 in ghc:GHC.Utils.Panic
assertPprPanic, called at compiler/GHC/CoreToStg/Prep.hs:1410:60 in ghc:GHC.CoreToStg.Prep