First, it does not matter how you set the values. In your example, whether you write node[2] = Node(2) or node.children[2] = Node(2), the behavior is the same. All that matters is what you pass to isKnownUniquelyReferenced. In both cases we have:
Next, it is indeed the subscript setter which results in the behavior difference. Replacing the set block with a _modify block makes both calls to isKnownUniquelyReferenced return true. The get block may be left as-is, or replaced with a _read block. I’m not certain what difference it makes:
Of course, both _read and _modify are undocumented and not officially part of the language. They are, however, used extensively in the standard library.
i have been using _read and _modify (_modify more than _read) in production for years and i know many other swift developers who do the same. to me, they are part of the language already, as it’s very difficult to write performant Swift libraries without _modify.
i don’t know why they haven’t been naturalized yet, they are so widely used that changing the semantics would break a ton of libraries. the situation is a lot like @_inlinable before it lost the underscore.