Skip to content

Tree Borrows: How would more precise UnsafeCell tracking work? #403

Open
@RalfJung

Description

@RalfJung

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-aliasing-modelTopic: Related to the aliasing model (e.g. Stacked/Tree Borrows)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions