SE-0519: Borrow and Inout types for safe, first-class references

This is a known limitation. The fundamental requirement is not that you be able to reassign the reference value, but that you have exclusive ownership of the reference while mutating through it. Unfortunately, inout/mutating is the only tool the language currently provides to assert exclusive ownership. We have been exploring features to allow exclusivity to be asserted without requiring mutability, and Inout (or whatever we decide to name it) would benefit from that as much as MutableSpan would.

UnsafeMutablePointer and class-based reference types do not have this problem, since they defer exclusivity to either programmer responsibility (in the case of UnsafeMutablePointer) or dynamic exclusivity checks (in the case of classes). By contrast, Inout and MutableSpan are intended to be zero-overhead and fully statically checked.

4 Likes