Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tree Borrows: Make tree root always be initialized #3415

Merged
merged 1 commit into from Mar 26, 2024

Conversation

JoJoDeveloping
Copy link
Contributor

This PR fixes a slight annoyance we discovered while formally proving that certain optimizations are sound with Tree Borrows. In particular... (copied from the commit message):

There should never be an Active but not initialized node in the borrow tree. If such a node exists, and if it has a protector, then on a foreign read, it could become disabled. This leads to some problems when formally proving that read moving optimizations are sound.

The root node is the only node for which this can happen, since all other nodes can only become Active when actually used. But special-casing the root node here is annoying to reason about, everything becomes much nicer if we can simply say that all Active nodes must be initialized. This requires making the root node default-initialized.

This is also more intuitive, since the root arguably becomes initialized during the allocation, which can be considered a write.

Copy link
Member

@RalfJung RalfJung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome to Miri. :)

I have some questions about the PR, though.

src/borrow_tracker/tree_borrows/tree.rs Outdated Show resolved Hide resolved
src/borrow_tracker/tree_borrows/tree.rs Outdated Show resolved Hide resolved
src/borrow_tracker/tree_borrows/tree.rs Outdated Show resolved Hide resolved
src/borrow_tracker/tree_borrows/tree.rs Outdated Show resolved Hide resolved
src/borrow_tracker/tree_borrows/tree/tests.rs Outdated Show resolved Hide resolved
@JoJoDeveloping
Copy link
Contributor Author

After some further thought, we decided to make the root note default Disabled and to manually set it to Active initialized on all in-bounds positions. This way, out-of-bounds accesses are also UB in TB.

@JoJoDeveloping JoJoDeveloping force-pushed the tree-borrows-initialized-root branch 2 times, most recently from 8ab3543 to 63107f8 Compare March 26, 2024 00:30
Comment on lines 475 to 477
// we manually set it to `Active` on all in-bounds positions.
// we also ensure that it is initalized, so that no `Active` but
// not yet initialized nodes exist.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// we manually set it to `Active` on all in-bounds positions.
// we also ensure that it is initalized, so that no `Active` but
// not yet initialized nodes exist.
// We manually set it to `Active` on all in-bounds positions.
// We also ensure that it is initalized, so that no `Active` but
// not yet initialized nodes exist. Essentially, we pretend there
// was a write that initialized these to `Active`.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

@RalfJung RalfJung Mar 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You dropped part of my diff, I had also fixed capitalization in the first two lines.

That's why using the github button is a good idea. ;) (You can than still pull, squash, force-push if you want to avoid the extra commit.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, alternatively I could simply look more closely 🙈
I've also fixed capitalization in other places.

@RalfJung
Copy link
Member

LGTM, just one comment nit. :)

There should never be an `Active` but not initialized node in the
borrow tree. If such a node exists, and if it has a protector, then
on a foreign read, it could become disabled. This leads to some
problems when formally proving that read-reordering optimizations are
sound.

The root node is the only node for which this can happen, since all
other nodes can only become `Active` when actually used. But special-
casing the root node here is annoying to reason about, everything
becomes much nicer if we can simply say that *all* `Active` nodes
must be initialized. This requires making the root node default-
initialized.

This is also more intuitive, since the root arguably becomes ini-
tialized during the allocation, which can be considered a write.
@RalfJung
Copy link
Member

Thanks!
@bors r+

@bors
Copy link
Collaborator

bors commented Mar 26, 2024

📌 Commit 5b208c4 has been approved by RalfJung

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Mar 26, 2024

⌛ Testing commit 5b208c4 with merge 7cf91ad...

@bors
Copy link
Collaborator

bors commented Mar 26, 2024

☀️ Test successful - checks-actions
Approved by: RalfJung
Pushing 7cf91ad to master...

@bors bors merged commit 7cf91ad into rust-lang:master Mar 26, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants