summaryrefslogtreecommitdiff
path: root/compiler/GHC/Stg/Unarise.hs
diff options
context:
space:
mode:
authorSebastian Graf <sebastian.graf@kit.edu>2021-03-01 21:40:22 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-03-26 23:02:15 -0400
commit57d21e6a522f5522ba238675e74f510ab8e5d300 (patch)
tree4132fca9afc4c2ee8ca0d23266919c77fec27201 /compiler/GHC/Stg/Unarise.hs
parent5741caeb0454c1bee9ca865ce6c3dfdd980ecf3e (diff)
downloadhaskell-57d21e6a522f5522ba238675e74f510ab8e5d300.tar.gz
Rubbish literals for all representations (#18983)
This patch cleans up the complexity around WW's `mk_absent_let` by broadening the scope of `LitRubbish`. Rubbish literals now store the `PrimRep` they represent and are ultimately lowered in Cmm. This in turn allows absent literals of `VecRep` or `VoidRep`. The latter allows absent literals for unlifted coercions, as requested in #18983. I took the liberty to rewrite and clean up `Note [Absent fillers]` and `Note [Rubbish values]` to account for the new implementation and to make them more orthogonal in their description. I didn't add a new regression test, as `T18982` already contains the test in the ticket and its test output changes as expected. Fixes #18983.
Diffstat (limited to 'compiler/GHC/Stg/Unarise.hs')
-rw-r--r--compiler/GHC/Stg/Unarise.hs32
1 files changed, 30 insertions, 2 deletions
diff --git a/compiler/GHC/Stg/Unarise.hs b/compiler/GHC/Stg/Unarise.hs
index c9160ff72a..03c2deb03e 100644
--- a/compiler/GHC/Stg/Unarise.hs
+++ b/compiler/GHC/Stg/Unarise.hs
@@ -193,6 +193,9 @@ STG programs after unarisation have these invariants:
This means that it's safe to wrap `StgArg`s of DataCon applications with
`GHC.StgToCmm.Env.NonVoid`, for example.
+ * Similar to unboxed tuples, Note [Rubbish values] of TupleRep may only
+ appear in return position.
+
* Alt binders (binders in patterns) are always non-void.
* Binders always have zero (for void arguments) or one PrimRep.
@@ -207,6 +210,7 @@ import GHC.Prelude
import GHC.Types.Basic
import GHC.Core
import GHC.Core.DataCon
+import GHC.Core.TyCon ( isVoidRep )
import GHC.Data.FastString (FastString, mkFastString)
import GHC.Types.Id
import GHC.Types.Literal
@@ -349,6 +353,11 @@ unariseExpr rho (StgCase scrut bndr alt_ty alts)
, Just args' <- unariseMulti_maybe rho dc args ty_args
= elimCase rho args' bndr alt_ty alts
+ -- See (3) of Note [Rubbish values] in GHC.Types.Literal
+ | StgLit lit <- scrut
+ , Just args' <- unariseRubbish_maybe lit
+ = elimCase rho args' bndr alt_ty alts
+
-- general case
| otherwise
= do scrut' <- unariseExpr rho scrut
@@ -379,6 +388,22 @@ unariseMulti_maybe rho dc args ty_args
| otherwise
= Nothing
+-- Doesn't return void args.
+unariseRubbish_maybe :: Literal -> Maybe [OutStgArg]
+unariseRubbish_maybe lit
+ | LitRubbish preps <- lit
+ , [prep] <- preps
+ , not (isVoidRep prep)
+ -- Single, non-void PrimRep. Nothing to do!
+ = Nothing
+
+ | LitRubbish preps <- lit
+ -- Multiple reps, possibly with VoidRep. Eliminate!
+ = Just [ StgLitArg (LitRubbish [prep]) | prep <- preps, not (isVoidRep prep) ]
+
+ | otherwise
+ = Nothing
+
--------------------------------------------------------------------------------
elimCase :: UnariseEnv
@@ -719,8 +744,11 @@ unariseConArg rho (StgVarArg x) =
-- Here realWorld# is not in the envt, but
-- is a void, and so should be eliminated
| otherwise -> [StgVarArg x]
-unariseConArg _ arg@(StgLitArg lit) =
- ASSERT(not (isVoidTy (literalType lit))) -- We have no void literals
+unariseConArg _ arg@(StgLitArg lit)
+ | Just as <- unariseRubbish_maybe lit
+ = as
+ | otherwise
+ = ASSERT(not (isVoidTy (literalType lit))) -- We have no non-rubbish void literals
[arg]
unariseConArgs :: UnariseEnv -> [InStgArg] -> [OutStgArg]