summaryrefslogtreecommitdiff
path: root/compiler/GHC/Core/Make.hs
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2021-05-27 12:02:45 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-06-05 19:23:46 -0400
commit52a524f7c8c5701708a007a5946c27914703d045 (patch)
tree63e5417205788aa800e06ef679f96ca29a3586aa /compiler/GHC/Core/Make.hs
parentea9a4ef69a382cf3cee28b78eca390a6a06c6965 (diff)
downloadhaskell-52a524f7c8c5701708a007a5946c27914703d045.tar.gz
Re-do rubbish literals
As #19882 pointed out, we were simply doing rubbish literals wrong. (I'll refrain from explaining the wrong-ness here -- see the ticket.) This patch fixes it by adding a Type (of kind RuntimeRep) as field of LitRubbish, rather than [PrimRep]. The Note [Rubbish literals] in GHC.Types.Literal explains the details.
Diffstat (limited to 'compiler/GHC/Core/Make.hs')
-rw-r--r--compiler/GHC/Core/Make.hs18
1 files changed, 18 insertions, 0 deletions
diff --git a/compiler/GHC/Core/Make.hs b/compiler/GHC/Core/Make.hs
index 129120139b..e0897670fc 100644
--- a/compiler/GHC/Core/Make.hs
+++ b/compiler/GHC/Core/Make.hs
@@ -13,6 +13,7 @@ module GHC.Core.Make (
sortQuantVars, castBottomExpr,
-- * Constructing boxed literals
+ mkLitRubbish,
mkWordExpr,
mkIntExpr, mkIntExprInt, mkUncheckedIntExpr,
mkIntegerExpr, mkNaturalExpr,
@@ -243,6 +244,23 @@ castBottomExpr e res_ty
where
e_ty = exprType e
+mkLitRubbish :: Type -> Maybe CoreExpr
+-- Make a rubbish-literal CoreExpr of the given type.
+-- Fail (returning Nothing) if
+-- * the RuntimeRep of the Type is not monomorphic;
+-- * the type is (a ~# b), the type of coercion
+-- See INVARIANT 1 and 2 of item (2) in Note [Rubbish literals]
+-- in GHC.Types.Literal
+mkLitRubbish ty
+ | not (noFreeVarsOfType rep)
+ = Nothing -- Satisfy INVARIANT 1
+ | isCoVarType ty
+ = Nothing -- Satisfy INVARIANT 2
+ | otherwise
+ = Just (Lit (LitRubbish rep) `mkTyApps` [ty])
+ where
+ rep = getRuntimeRep ty
+
{-
************************************************************************
* *