streamly
streamly copied to clipboard
Expose `Streamly.Data.Unboxed`
- Rename the Unboxed APIs properly.
- Rename
ArrayContentsproperly
readByteArray -> peekWith writeByteArray -> pokeWith ArrayContents -> Memory or Storage or OAM (Offset Adressable Memory)
To be able to support different memory types, we can split the Unboxed type class in two classes:
- Unboxed: Specifying size and alignment for the type, this will be the same for all memory types. That way we can ensure that the size and alignment remain the same whichever method we use to read or write the type.
- Unbox: Specifying the read and write operations, this will be different for different memory types
We can then possibly have multiple Unbox type classes for different memory types:
- Array.Unbox operating on MutableByteArray#
- Foreign.Unbox operating on Ptr akin to Foreign.Storable
- ForeignPtr.Unbox operating on ForeignPtr (requires touching during read and write). This can be implemented in terms of the previous two.
We can then use the same common array code and pass the relevant type class dictionary to use a particular memory type. We could use a type class with two parameters one for memory type and one for the storable type, but that would make constraint types unnecessarily complex. And we would mostly need only the byte-array type class, others would not be used often. We only need a provision for those, just in case.
Alternatively, instead of creating a new type class for size and alignment, we can just reuse Storable and put a Storable constraint on Unbox. And make sure all instances are compatible with Storable. This will make the use of Storable and Unbox consistent. The downside is that to make an instance of Unbox you will also have to make an instance of Storable. However, if you are never going to use peek/poke you can leave those undefined and just specify size/alignment.
Common API naming:
newAlignedgetInternalcastreallocAlignedasPtrUnsafeputSliceUnsafecmp
We should not expose internal details. Any common internal manipulating APIs should be given a place in the Unbox type class.
The module should be renamed to Streamly.Internal.Data.MutableByteArray
Closed in https://github.com/composewell/streamly/pull/1772
We can keep this open as there is more discussion on this. Pushing this to 0.10.0
See #1910