A minimal package to expose an interface for reasoning about and controlling the mutability of indexable containers, via:
issettable(x)
returns aBool
indicating whethersetindex!
works onx
.freeze(x)
returns a container with the values contained withinx
that cannot be mutated viasetindex!
.thaw(x)
is the reverse offreeze
, returning a container with the values contained withx
that can be mutated viasetindex!
.
In the general case, the above might require copying the contents of x
, but in practice we
expect the Julia compiler to become good at reasoning about the lifetime of objects via escape
analysis (as it can already do for structs).
NOTE: The current implementation here for AbstractArray
might be unsound because it does not perform defensive copying! This package provides interface guarantees around setindex!
only - actual values may mutate if the underlying data structures are accessed directly. It may be useful for experimentation or preventing some varieties of bugs.
See also Base.Experimental.Const
in Julia 1.3 onwards, and the ArrayInterface.jl package.