Some Addr#, (Mutable)ByteArray# primops do not note mutability expectations
One group of primops exported by GHC.Exts are the index<primty>OffAddr# :: Addr# -> Int# -> <primty>
functions.
Their type signatures were somewhat surprising to me-- how are we to read from an address without some sort of state tracking?
The Haddock docstrings state "Read a (pretty type description); offset in (type size in bytes) words."
This docstring is shared with the associated read<primty>OffAddr# :: Addr# -> Int# -> State# d -> (# State# d, <primty> #)
function.
These primops are for reading from immutable non-GC-managed addresses. I eventually gathered so from some documentation in GHC.Prim,
which explains what the index, read and write primops do in the context of ByteArray#
s. On a closer look, there are notes on whether a given primop works with immutable or mutable memory, but these are inconsistently applied, and no Addr#
primops make any reference.
I think primops that access the contents of some pointer (Addr#
, MutableByteArray#
or ByteArray#
) should note the mutability of the memory they're accessing. This is potentially "obvious" for the latter two, but easily confusing for Addr#
access primops which aren't explained purely by their type signatures.
This is fairly easily accomplished by editing some desc
fields in utils/genprimopcode/AccessOps.hs
.