Description
One of the key differences between Stacked Borrows and Tree Borrows is that &(i32, Cell<i32>)
in SB enforces that the first component of the pair is read-only, while TB does not (UnsafeCell
is "maximally infectious" in TB). This seems to be one of the most controversial parts of TB.
Leaving aside the question of which of these behaviors is preferable -- what would TB with more precise UnsafeCell
even look like? In TB, creating a &!Freeze
from a mutable reference is simply a NOP -- the original tag is also used for the new reference, allowing arbitrary aliasing between parent and child. Clearly that does not work any more if some bytes of an &!Freeze
can have immutability guarantees: the child pointer needs a new tag which, on the readonly locations, is in Frozen
state to ensure that writes to foreign pointers (parents/uncles/...) invalidate the tag. But on readwrite locations, we need a state that allows foreign writes, which does not currently exist.
So, we need a new possible state for tags in TB, Aliased
or so, which presumably allows arbitrary foreign (and child) accesses. It should be the case that it never makes a difference whether an access is performed with a tag in Aliased
state, or its parent tag.
Is that it? Or are there more challenges?
@Vanille-N would having such a state violate any of the assumptions that various parts of Tree Borrows are making?