Closed MasonProtter closed 1 year ago
Accessing or mutating the fields of an object is considered to be be non-public API, and does not have a defined semantics, so it does not need to have any defined behavior either
@vtjnash I'm aware that it's not meant to be mutated, that mutation was just for a quick MWE. The reason it's a problem is https://github.com/JuliaLang/julia/pull/52049 where one may want to wrap
a Memory
that's oversized for the array they're making.
Note that very similar things will happen if you change one of the arrays backing a Dict
to have a non-power of 2 size.
Compare
versus
This is problematic because I want to add a
wrap
function which creates anArray
out of aMemory
orMemoryRef
, and ideally we'd want to allow the use of oversizedMemory
to back multidimensional arrays i.e. one could imagine a bump allocator likeSome options going forward are
length(a) = length(a.ref.mem)
length
viaprod(a.dims)
(some benchmarking from @LilithHafner suggests this is fine whenndims < 5
, but would cause performance problems when people assumelength
is free for high dimensional arrays.length
field toArray
. This could be seen as ugly but it has one advantage that it means we don't need to special case theconst
ness of thesize
field anymore to be const forndims > 1
and mutable forndims = 1
.