This post is ispired by the following discussions about mutability and stack-allocated arrays: Initializing an array of mutable objects is surprisingly slow
Fortran vs Julia stack allocated arrays
Why mutable structs are allocated on the heap?
Mutate NTuple at position
Way to have a function "mutate an immutable" without much performance loss
And the actual issue is: WIP: Make mutating immutables easier
It seems to me that many people get confused with mutability, fixed-sized types and stack-allocation, but the point is, we can overwrite whole immutable objects, but not change their parts.
If so, maybe this issue can be resolved by adding another
atomic type qualifier, along with
atomic struct Foo x::Int y::Int end
atomic treats every field change to be equivalent to the entire structure overwrite. But, knowing that the only one field is changed, it is optimized to only one field overwrite?
This has more consistent syntax with the other functions, since we do not need to have special write syntax, such as Setfield.jl or
MArray at StaticArrays.jl, so the same functions can be used for immutables, mutables and atomic types, and we can explicitly define, for which types we want to be able to overwrite individual fields.