StablePtr# array operations should be lev-polymorphic
StablePtr#
is levity polymorphic: TYPE (BoxedRep lev) -> Type
. Most primitive operations on StablePtr#
are levity polymorphic, but array operations such as indexStablePtrArray#
, readWord8ArrayAsStablePtr#
etc. are not. As far as I understand, there is no reason for this limitation. The change should be
--- a/utils/genprimopcode/AccessOps.hs
+++ b/utils/genprimopcode/AccessOps.hs
@@ -24,7 +24,7 @@ elementTypes =
, MkElementType "Addr" (strToTy "Addr#" ) "a machine address" machWord
, MkElementType "Float" (strToTy "Float#" ) "a single-precision floating-point value" (Just 4)
, MkElementType "Double" (strToTy "Double#") "a double-precision floating-point value" (Just 8)
- , MkElementType "StablePtr" (TyApp (TyCon "StablePtr#") [TyVar "a"])
+ , MkElementType "StablePtr" (TyApp (TyCon "StablePtr#") [TyVar "a_levpoly"])
"a 'StablePtr#' value" machWord
] ++ do
n <- [8, 16, 32, 64]
but it needs a test and CLC approval.
I have audited other operations in GHC.Prim
. The only other case where we have a levity-monomorphic operation on a levity-polymorphic primitive are atomicModifyMutVar*
operations. Since they rely on using a thunk, they can't be generalized.