summaryrefslogtreecommitdiff
path: root/compiler/GHC/StgToCmm
diff options
context:
space:
mode:
authorsheaf <sam.derbyshire@gmail.com>2021-07-12 11:49:48 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-07-23 21:06:56 -0400
commit5d670abd1c2c53a6c0918b1fe52b8ff581b9a394 (patch)
tree9680ed332a62328e5a33c85e793168fd984e35e3 /compiler/GHC/StgToCmm
parentba3028778942f63e888142e5b4d036423049006c (diff)
downloadhaskell-5d670abd1c2c53a6c0918b1fe52b8ff581b9a394.tar.gz
Generalise reallyUnsafePtrEquality# and use it
fixes #9192 and #17126 updates containers submodule 1. Changes the type of the primop `reallyUnsafePtrEquality#` to the most general version possible (heterogeneous as well as levity-polymorphic): > reallyUnsafePtrEquality# > :: forall {l :: Levity} {k :: Levity} > (a :: TYPE (BoxedRep l)) (b :: TYPE (BoxedRep k)) > . a -> b -> Int# 2. Adds a new internal module, `GHC.Ext.PtrEq`, which contains pointer equality operations that are now subsumed by `reallyUnsafePtrEquality#`. These functions are then re-exported by `GHC.Exts` (so that no function goes missing from the export list of `GHC.Exts`, which is user-facing). More specifically, `GHC.Ext.PtrEq` defines: - A new function: * reallyUnsafePtrEquality :: forall (a :: Type). a -> a -> Int# - Library definitions of ex-primops: * `sameMutableArray#` * `sameSmallMutableArray` * `sameMutableByteArray#` * `sameMutableArrayArray#` * `sameMutVar#` * `sameTVar#` * `sameMVar#` * `sameIOPort#` * `eqStableName#` - New functions for comparing non-mutable arrays: * `sameArray#` * `sameSmallArray#` * `sameByteArray#` * `sameArrayArray#` These were requested in #9192. Generally speaking, existing libraries that use `reallyUnsafePtrEquality#` will continue to work with the new, levity-polymorphic version. But not all! Some (`containers`, `unordered-containers`, `dependent-map`) contain the following: > unsafeCoerce# reallyUnsafePtrEquality# a b If we make `reallyUnsafePtrEquality#` levity-polymorphic, this code fails the current GHC representation-polymorphism checks. We agreed that the right solution here is to modify the library; in this case by deleting the call to `unsafeCoerce#`, since `reallyUnsafePtrEquality#` is now type-heterogeneous too.
Diffstat (limited to 'compiler/GHC/StgToCmm')
-rw-r--r--compiler/GHC/StgToCmm/Prim.hs27
1 files changed, 2 insertions, 25 deletions
diff --git a/compiler/GHC/StgToCmm/Prim.hs b/compiler/GHC/StgToCmm/Prim.hs
index 542372105e..d61880a0e2 100644
--- a/compiler/GHC/StgToCmm/Prim.hs
+++ b/compiler/GHC/StgToCmm/Prim.hs
@@ -342,6 +342,8 @@ emitPrimOp dflags primop = case primop of
StableNameToIntOp -> \[arg] -> opIntoRegs $ \[res] ->
emitAssign (CmmLocal res) (cmmLoadIndexW platform arg (fixedHdrSizeW profile) (bWord platform))
+ EqStablePtrOp -> \args -> opTranslate args (mo_wordEq platform)
+
ReallyUnsafePtrEqualityOp -> \[arg1, arg2] -> opIntoRegs $ \[res] ->
emitAssign (CmmLocal res) (CmmMachOp (mo_wordEq platform) [arg1,arg2])
@@ -1462,20 +1464,6 @@ emitPrimOp dflags primop = case primop of
FloatToDoubleOp -> \args -> opTranslate args (MO_FF_Conv W32 W64)
DoubleToFloatOp -> \args -> opTranslate args (MO_FF_Conv W64 W32)
--- Word comparisons masquerading as more exotic things.
-
- SameMutVarOp -> \args -> opTranslate args (mo_wordEq platform)
- SameMVarOp -> \args -> opTranslate args (mo_wordEq platform)
- SameIOPortOp -> \args -> opTranslate args (mo_wordEq platform)
- SameMutableArrayOp -> \args -> opTranslate args (mo_wordEq platform)
- SameMutableByteArrayOp -> \args -> opTranslate args (mo_wordEq platform)
- SameMutableArrayArrayOp -> \args -> opTranslate args (mo_wordEq platform)
- SameSmallMutableArrayOp -> \args -> opTranslate args (mo_wordEq platform)
- SameTVarOp -> \args -> opTranslate args (mo_wordEq platform)
- EqStablePtrOp -> \args -> opTranslate args (mo_wordEq platform)
--- See Note [Comparing stable names]
- EqStableNameOp -> \args -> opTranslate args (mo_wordEq platform)
-
IntQuotRemOp -> \args -> opCallishHandledLater args $
if ncg && (x86ish || ppc) && not (quotRemCanBeOptimized args)
then Left (MO_S_QuotRem (wordWidth platform))
@@ -2092,17 +2080,6 @@ genericFabsOp w [res_r] [aa]
genericFabsOp _ _ _ = panic "genericFabsOp"
--- Note [Comparing stable names]
--- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
--- A StableName# is actually a pointer to a stable name object (SNO)
--- containing an index into the stable name table (SNT). We
--- used to compare StableName#s by following the pointers to the
--- SNOs and checking whether they held the same SNT indices. However,
--- this is not necessary: there is a one-to-one correspondence
--- between SNOs and entries in the SNT, so simple pointer equality
--- does the trick.
-
------------------------------------------------------------------------------
-- Helpers for translating various minor variants of array indexing.