RubbishLit can trip up CoreToStg
In a branch of mine I tried only generating RubbishLit's and no absentErrors as a temporary workaround.
Sadly this didn't work, but I got a compiler panic from CoreToStg instead.
*** Deleting temp dirs:
ghc.exe: panic! (the 'impossible' happened)
(GHC version 9.3.20210510:
CoreToStg.myCollectArgs
RUBBISH[LiftedRep] @(Int -> ReadS a_smsc) n_sz7o s_sz7q
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\\CoreToStg.hs:971:33 in ghc:GHC.CoreToStg
myCollectArgs, called at compiler\\GHC\\CoreToStg.hs:402:24 in ghc:GHC.CoreToStg
coreToStgExpr, called at compiler\\GHC\\CoreToStg.hs:449:20 in ghc:GHC.CoreToStg
coreToStgExpr, called at compiler\\GHC\\CoreToStg.hs:705:20 in ghc:GHC.CoreToStg
The offending piece of code before and after core prep:
-- Before core prep:
(Text.ParserCombinators.ReadP.Look
@a_smsc
(\ (s_aiNA :: String) ->
case Data.Sequence.Internal.$fRead1Seq5
@a_smsc (RUBBISH[LiftedRep] @(Int -> ReadS a_smsc) n_aiNj s_aiNA)
of {
[] -> Text.ParserCombinators.ReadP.Fail @a_smsc;
: r_aiNC rs_aiND ->
Text.ParserCombinators.ReadP.Final
@a_smsc (GHC.Base.:| @(a_smsc, String) r_aiNC rs_aiND)
}))
-- After core prep
let {
sat_sz7w [Occ=Once1]
:: GHC.Base.String -> Text.ParserCombinators.ReadP.P a_smsc
[LclId]
sat_sz7w
= \ (s_sz7q [Occ=Once1] :: GHC.Base.String) ->
case RUBBISH[LiftedRep]
@(GHC.Types.Int -> Text.ParserCombinators.ReadP.ReadS a_smsc)
n_sz7o
s_sz7q
of sat_sz7r [Occ=Once1]
{ __DEFAULT ->
case Data.Sequence.Internal.$fRead1Seq5 @a_smsc sat_sz7r of
At first I thought the problem is that we case-bind the rubbishLit.
But I think the issue is simply that we apply the rubbish lit to values.
We start out by calling coreToStgExpr body
inside the case for the lambda.
Then coreToStgExpr scrut
for the case expression.
This leaves us with the expression RUBBISH[LiftedRep] @(<type>) n_sz7o s_sz7q
.
We already have a case that one might think would catch this:
coreToStgExpr (App l@(Lit LitRubbish{}) Type{}) = coreToStgExpr l
Alas, we have an expression of the form:
((App rubbish type) `App` foo) `App` bar
So we hit this case instead:
coreToStgExpr expr@(App _ _)
= coreToStgApp f args ticks
where
(f, args, ticks) = myCollectArgs expr
Which calls myCollectArgs expr. But it has the precondition that argument expression is an 'App', and there is a 'Var' at the head of the 'App' chain.
Which isn't the case here. Our head of the chain is a rubbishLit! So myCollectArgs blows up.
I think we need to fix this in two steps:
- Check for rubbishLit in myCollectArgs
- Check for f == rubbishLit after we return from
myCollectArgs
and handle the case specially. Because coreToStgApp is no better equipped to handle rubbishLit than myCollectArgs currently is.