Skip to content

Conversation

@royAmmerschuber
Copy link
Contributor

Adds proper suport for reborrowing wildcard pointers to tree borrows.

@rustbot
Copy link
Collaborator

rustbot commented Nov 17, 2025

Thank you for contributing to Miri! A reviewer will take a look at your PR, typically within a week or two.
Please remember to not force-push to the PR branch except when you need to rebase due to a conflict or when the reviewer asks you for it.

@rustbot rustbot added the S-waiting-on-review Status: Waiting for a review to complete label Nov 17, 2025
Comment on lines 1175 to 1176
// then check if we can skip the entire subtree because the access might not
// change any permissions here anyway.
Copy link
Member

Choose a reason for hiding this comment

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

I'm confused by the "might not" here. (Isn't that something you already had before and we removed it in the previous PR?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, your right. This got lost in a rebase.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

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.

Overall approach looks good. Here's a bunch of comments. :)

Please also add the 3 SB tests in this area: illegal_read/write_despite_exposed*.

View changes since this review


let state = perm.or_insert(node.default_location_state());
#[cfg(feature = "expensive-consistency-checks")]
self.verify_wildcard_consistency(global);
Copy link
Member

Choose a reason for hiding this comment

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

We should only need this if a wildcard is involved in the access, right? I.e. if the tag is wildcard, or if there are multiple roots.

pub(super) root: UniIndex,
/// Contains both the root of the main tree as well as the roots of the wildcard subtrees.
/// Sorted according to `BorTag` from low to high. This also means the main root is `root[0]`.
pub(super) roots: SmallVec<[UniIndex; 2]>,
Copy link
Member

Choose a reason for hiding this comment

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

This seems like a good place to describe what these multiple trees even mean.

parent_node.children.push(idx);
} else {
// If the parent had wildcard provenance, then register the idx
// as a new wildcard root.
Copy link
Member

Choose a reason for hiding this comment

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

Please explain why this preserves sortedness.

}

// We need to ensure the consistency of the wildcard access tracking data structure.
// For this, we insert the correct entry for this tag based on its parent, if it exists.
Copy link
Member

Choose a reason for hiding this comment

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

The comment does not cover the else branch.

// Foreign accesses are always possible on wildcard subtrees, as they have
// `max_foreign_access==Write` on their root. However on the main tree this can fail
// resulting in an access error.
let accessed_root_tag = accessed_root.map(|idx| nodes.get(idx).unwrap().tag);
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem to directly relate to the comment. You can just move it up.


/// Print extra text if the tag is exposed.
fn print_exposed(&self, exposed: bool) -> S {
if exposed { " Exposed" } else { "" }
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
if exposed { " Exposed" } else { "" }
if exposed { " (exposed)" } else { "" }

Comment on lines +45 to +46
// We can still access both ref1, ref2.
assert_eq!(*ref2, 13);
Copy link
Member

Choose a reason for hiding this comment

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

Comment and code don't quite match... we can access both, after all.
You can just explain that this is technically UB we don't catch.

Comment on lines +96 to +97
// We should be able to access any of the references.
assert_eq!(*ref2, 13);
Copy link
Member

Choose a reason for hiding this comment

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

Again this doesn't quite test what the comment says.

// │ │
// └────────────┘

// This is the only valid ordering these accesses can happen in.
Copy link
Member

Choose a reason for hiding this comment

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

This should refer back to the comment for the test: accessing reb2 doesn't invalidate reb1 because ref1 exists. (Also, please pick more distinguishable names.)

Copy link
Member

Choose a reason for hiding this comment

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

Please explain in the comment that this tests the max_local_tag logic.

@rustbot rustbot added S-waiting-on-author Status: Waiting for the PR author to address review comments and removed S-waiting-on-review Status: Waiting for a review to complete labels Nov 24, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 24, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

};
// Afterwards we check all tags in arbitrary order, so that we also catch
// protectors on different subtrees.
// (This unnecessarily checks the tags of `start_idx`s subtree again)
Copy link
Member

Choose a reason for hiding this comment

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

This comment seems outdated now.

Comment on lines 873 to 878
TreeVisitor { nodes: &mut self.nodes, loc }.traverse_this_parents_children_other(
*root,
// Visit all children, skipping none.
|_| ContinueTraversal::Recurse,
check_strong_protector,
)?;
Copy link
Member

Choose a reason for hiding this comment

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

This part is still duplicated between the two branches... maybe it makes more sense to share the entire visitor invocation, not just the check_strong_protector closure?

@rustbot

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Nov 25, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: Waiting for the PR author to address review comments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants