Skip to content

Patch: new primops for byte range copies ByteArray# <-> Addr#

Currently we have:

  • copyByteArray# for ByteArray# to MutableByteArray#
  • copyMutableByteArray# for MutableByteArray# to MutableByteArray#

This patch adds primops for similar cases involving Addr#s, that is pointers to pinned or foreign memory.

  • copyByteArrayToAddr# for ByteArray# to Addr#
  • copyMutableByteArrayToAddr# for MutableByteArray# to Addr#
  • copyAddrToByteArray# for Addr# to MutableByteArray#

These are not covered by the existing primops of course, and are useful because ByteArray#s are a bit special, sometimes being unpinned, and being aligned, and being so primitve/built-in. It's true we could use FFI import of memcpy using the GHC's FFI extension to turn ByteArray# into a pointer on the C side. However we don't do that for the existing primops and we're following the same pattern here. (Good reasons for them all to be primops: abstracts the backend/platform better, can take advantage of known allignment and size info).

In particular, these primops would be useful in the impl of low level libs like bytestring, text, array, binary etc.

Trac metadata
Trac field Value
Version 7.6.3
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information