summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2023-01-17 16:08:46 -0500
committerBen Gamari <ben@smart-cactus.org>2023-01-17 16:12:09 -0500
commit36fe85b90f5cdb36f2323d6ba6f4e6f59596fbc8 (patch)
tree8b622f73a4fb16b6a9f8721e5ceb7b08bb9bdf18
parentc79b2b65fff93b4f4e38e5d124f0cb8c6ef704c0 (diff)
downloadhaskell-wip/T22710.tar.gz
primops: Introduce unsafeThawByteArray#wip/T22710
This addresses an odd asymmetry in the ByteArray# primops, which previously provided unsafeFreezeByteArray# but no corresponding thaw operation. Closes #22710
-rw-r--r--compiler/GHC/Builtin/primops.txt.pp10
-rw-r--r--compiler/GHC/StgToCmm/Prim.hs4
-rw-r--r--compiler/GHC/StgToJS/Prim.hs1
-rw-r--r--libraries/ghc-prim/changelog.md7
4 files changed, 21 insertions, 1 deletions
diff --git a/compiler/GHC/Builtin/primops.txt.pp b/compiler/GHC/Builtin/primops.txt.pp
index d51f3616f2..1777ce4255 100644
--- a/compiler/GHC/Builtin/primops.txt.pp
+++ b/compiler/GHC/Builtin/primops.txt.pp
@@ -1780,7 +1780,15 @@ primop ResizeMutableByteArrayOp_Char "resizeMutableByteArray#" GenPrimOp
primop UnsafeFreezeByteArrayOp "unsafeFreezeByteArray#" GenPrimOp
MutableByteArray# s -> State# s -> (# State# s, ByteArray# #)
- {Make a mutable byte array immutable, without copying.}
+ {Make a mutable byte array immutable, without copying.
+
+ @since 0.11.0}
+ with
+ has_side_effects = True
+
+primop UnsafeThawByteArrayOp "unsafeThawByteArray#" GenPrimOp
+ MutableByteArray# s -> State# s -> (# State# s, ByteArray# #)
+ {Make an immutable byte array mutable, without copying.}
with
has_side_effects = True
diff --git a/compiler/GHC/StgToCmm/Prim.hs b/compiler/GHC/StgToCmm/Prim.hs
index e17a937a9e..948e76af87 100644
--- a/compiler/GHC/StgToCmm/Prim.hs
+++ b/compiler/GHC/StgToCmm/Prim.hs
@@ -375,6 +375,10 @@ emitPrimOp cfg primop =
UnsafeFreezeByteArrayOp -> \[arg] -> opIntoRegs $ \[res] ->
emitAssign (CmmLocal res) arg
+-- #define unsafeThawByteArrayzh(r,a) r=(a)
+ UnsafeThawByteArrayOp -> \[arg] -> opIntoRegs $ \[res] ->
+ emitAssign (CmmLocal res) arg
+
-- Reading/writing pointer arrays
ReadArrayOp -> \[obj, ix] -> opIntoRegs $ \[res] ->
diff --git a/compiler/GHC/StgToJS/Prim.hs b/compiler/GHC/StgToJS/Prim.hs
index 6085b110cf..939b7152fa 100644
--- a/compiler/GHC/StgToJS/Prim.hs
+++ b/compiler/GHC/StgToJS/Prim.hs
@@ -606,6 +606,7 @@ genPrim prof bound ty op = case op of
ShrinkMutableByteArrayOp_Char -> \[] [a,n] -> PrimInline $ appS "h$shrinkMutableByteArray" [a,n]
ResizeMutableByteArrayOp_Char -> \[r] [a,n] -> PrimInline $ r |= app "h$resizeMutableByteArray" [a,n]
UnsafeFreezeByteArrayOp -> \[a] [b] -> PrimInline $ a |= b
+ UnsafeThawByteArrayOp -> \[a] [b] -> PrimInline $ a |= b
SizeofByteArrayOp -> \[r] [a] -> PrimInline $ r |= a .^ "len"
SizeofMutableByteArrayOp -> \[r] [a] -> PrimInline $ r |= a .^ "len"
GetSizeofMutableByteArrayOp -> \[r] [a] -> PrimInline $ r |= a .^ "len"
diff --git a/libraries/ghc-prim/changelog.md b/libraries/ghc-prim/changelog.md
index 0e909da691..72e69531e8 100644
--- a/libraries/ghc-prim/changelog.md
+++ b/libraries/ghc-prim/changelog.md
@@ -1,3 +1,10 @@
+## 0.11.0
+
+- Shipped with GHC 9.8.1
+
+- The `unsafeThawByteArray#` primop was added, serving as a inverse to the existing
+ `unsafeFreezeByteArray#` primop (see #22710).
+
## 0.10.0
- Shipped with GHC 9.6.1