summaryrefslogtreecommitdiff
path: root/utils/genprimopcode
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 /utils/genprimopcode
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 'utils/genprimopcode')
-rw-r--r--utils/genprimopcode/Main.hs10
1 files changed, 8 insertions, 2 deletions
diff --git a/utils/genprimopcode/Main.hs b/utils/genprimopcode/Main.hs
index f5eaf757e2..06a4922aa3 100644
--- a/utils/genprimopcode/Main.hs
+++ b/utils/genprimopcode/Main.hs
@@ -854,8 +854,11 @@ ppTyVar "c" = "gammaTyVarSpec"
ppTyVar "s" = "deltaTyVarSpec"
ppTyVar "o" = "runtimeRep1TyVarInf, openAlphaTyVarSpec"
ppTyVar "p" = "runtimeRep2TyVarInf, openBetaTyVarSpec"
-ppTyVar "v" = "levity1TyVarInf, levPolyTyVar1Spec"
+ppTyVar "v" = "levity1TyVarInf, levPolyAlphaTyVarSpec"
+ppTyVar "w" = "levity2TyVarInf, levPolyBetaTyVarSpec"
ppTyVar _ = error "Unknown type var"
+-- o, p, v and w have a special meaning. See primops.txt.pp
+-- Note [Levity and representation polymorphic primops]
ppType :: Ty -> String
ppType (TyApp (TyCon "Any") []) = "anyTy"
@@ -889,7 +892,10 @@ ppType (TyVar "c") = "gammaTy"
ppType (TyVar "s") = "deltaTy"
ppType (TyVar "o") = "openAlphaTy"
ppType (TyVar "p") = "openBetaTy"
-ppType (TyVar "v") = "levPolyTy1"
+ppType (TyVar "v") = "levPolyAlphaTy"
+ppType (TyVar "w") = "levPolyBetaTy"
+-- o, p, v and w have a special meaning. See primops.txt.pp
+-- Note [Levity and representation polymorphic primops]
ppType (TyApp (TyCon "State#") [x]) = "mkStatePrimTy " ++ ppType x
ppType (TyApp (TyCon "MutVar#") [x,y]) = "mkMutVarPrimTy " ++ ppType x