summaryrefslogtreecommitdiff
path: root/compiler/GHC/Utils
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/Utils
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/Utils')
-rw-r--r--compiler/GHC/Utils/Misc.hs14
1 files changed, 13 insertions, 1 deletions
diff --git a/compiler/GHC/Utils/Misc.hs b/compiler/GHC/Utils/Misc.hs
index f7168190e4..abd85b6b66 100644
--- a/compiler/GHC/Utils/Misc.hs
+++ b/compiler/GHC/Utils/Misc.hs
@@ -43,7 +43,7 @@ module GHC.Utils.Misc (
listLengthCmp, atLength,
equalLength, compareLength, leLength, ltLength,
- isSingleton, only, GHC.Utils.Misc.singleton,
+ isSingleton, only, expectOnly, GHC.Utils.Misc.singleton,
notNull, snocView,
isIn, isn'tIn,
@@ -563,6 +563,18 @@ only (a:_) = a
#endif
only _ = panic "Util: only"
+-- | Extract the single element of a list and panic with the given message if
+-- there are more elements or the list was empty.
+-- Like 'expectJust', but for lists.
+expectOnly :: HasCallStack => String -> [a] -> a
+{-# INLINE expectOnly #-}
+#if defined(DEBUG)
+expectOnly _ [a] = a
+#else
+expectOnly _ (a:_) = a
+#endif
+expectOnly msg _ = panic ("expectOnly: " ++ msg)
+
-- Debugging/specialising versions of \tr{elem} and \tr{notElem}
# if !defined(DEBUG)