Stacked Borrows: don't read from memory during retagging #931
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, retagging of a shared reference tries real hard to find the
UnsafeCell
and mark everything else as frozen. We even read enum discriminants to figure out the variant and determine if there is anUnsafeCell
in there or not.Unfortunately, that leads to some very hard to analyze behavior: during retagging, we do read accesses, which are subject to the rules of Stacked Borrows and the existing tags! My head hurts when I try to think about this. It's just too recursive.
This PR simplifies the semantics by treating enums like unions: if any variant has an
UnsafeCell
, the entire thing behaves like anUnsafeCell
. This means retagging no longer has to read from memory, the way it affects the stack is entirely determined by the type.