From e82d32d6654ef708d580e3ed6f0cc1130daa6cb9 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Mon, 15 Mar 2021 16:03:21 -0400 Subject: compiler: Introduce mutableByteArrayContents# primop As noted in #19540, a number of users within and outside of GHC rely on unsafeCoerceUnlifted to work around the fact that this was missing --- compiler/GHC/Builtin/primops.txt.pp | 4 ++++ compiler/GHC/StgToCmm/Prim.hs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/compiler/GHC/Builtin/primops.txt.pp b/compiler/GHC/Builtin/primops.txt.pp index 27b7f55132..c11cc05a40 100644 --- a/compiler/GHC/Builtin/primops.txt.pp +++ b/compiler/GHC/Builtin/primops.txt.pp @@ -1655,6 +1655,10 @@ primop ByteArrayContents_Char "byteArrayContents#" GenPrimOp ByteArray# -> Addr# {Intended for use with pinned arrays; otherwise very unsafe!} +primop MutableByteArrayContents_Char "mutableByteArrayContents#" GenPrimOp + MutableByteArray# s -> Addr# + {Intended for use with pinned arrays; otherwise very unsafe!} + primop SameMutableByteArrayOp "sameMutableByteArray#" GenPrimOp MutableByteArray# s -> MutableByteArray# s -> Int# diff --git a/compiler/GHC/StgToCmm/Prim.hs b/compiler/GHC/StgToCmm/Prim.hs index b10462a10b..484863d37a 100644 --- a/compiler/GHC/StgToCmm/Prim.hs +++ b/compiler/GHC/StgToCmm/Prim.hs @@ -335,6 +335,10 @@ emitPrimOp dflags primop = case primop of ByteArrayContents_Char -> \[arg] -> opIntoRegs $ \[res] -> emitAssign (CmmLocal res) (cmmOffsetB platform arg (arrWordsHdrSize profile)) +-- #define mutableByteArrayContentszh(r,a) r = BYTE_ARR_CTS(a) + MutableByteArrayContents_Char -> \[arg] -> opIntoRegs $ \[res] -> + emitAssign (CmmLocal res) (cmmOffsetB platform arg (arrWordsHdrSize profile)) + -- #define stableNameToIntzh(r,s) (r = ((StgStableName *)s)->sn) StableNameToIntOp -> \[arg] -> opIntoRegs $ \[res] -> emitAssign (CmmLocal res) (cmmLoadIndexW platform arg (fixedHdrSizeW profile) (bWord platform)) -- cgit v1.2.1