Skip to content

Conversation

@royAmmerschuber
Copy link
Contributor

Currently, if we do a protector release access we assume that any other subtree (including the main subtree) could be a child of the accessed node, meaning we conservatively don't update them based on the access.

This PR determines as accurately as possible (under the current model), which other subtrees could be children of the accessed tag.
This means we now accurately reflect:

  • the main subtree is never a child of the accessed tag
  • if the accessed tag doesn't have exposed children, then no other subtree is a child of it
  • a subtree can only be a child of the accessed tag, if there exists an exposed child of the accessed tag with a tag less than the root of the subtree

@rustbot
Copy link
Collaborator

rustbot commented Dec 16, 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 Dec 16, 2025
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.

Mostly comments about comments, as usual. :)

View changes since this review

global,
ChildrenVisitMode::VisitChildrenOfAccessed,
&diagnostics,
None, // min_exposed_child only matters for protector end access,
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
None, // min_exposed_child only matters for protector end access,
/* min_exposed_child */ None, // only matters for protector end access,

let min_exposed_child = if self.roots.len() > 1 {
LocationTree::get_min_exposed_child(source_idx, &self.nodes)
} else {
None
Copy link
Member

Choose a reason for hiding this comment

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

Is this correct?

Suggested change
None
// There's no point in computing this when there is just one tree.
None

while let Some(idx) = stack.pop() {
let node = nodes.get(idx).unwrap();
if min_tag.is_some_and(|min| min < node.tag) {
continue;
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
continue;
// The minimum we found before is bigger than this tag, and therefore
// also bigger than all its children, so we can skip this subtree.
continue;

Comment on lines +954 to +955
if let Some(min_exposed_child) = min_exposed_child
&& tag > min_exposed_child
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this condition check visit_children?

Comment on lines +946 to +947
// On a protector release access we skip the children of the accessed tag so that
// we can correctly return references from functions. However, if the tag has
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
// On a protector release access we skip the children of the accessed tag so that
// we can correctly return references from functions. However, if the tag has
// On a protector release access we have to skip the children of the accessed tag.
// However, if the tag has


/// This is a variant of the test in `../protector-write-lazy.rs`, but with
/// wildcard references.
/// Checks that a protector release transitions a foreign reference on a reference,
Copy link
Member

Choose a reason for hiding this comment

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

What does "transitions a foreign reference on a reference" mean?

/// wildcard references.
/// Checks that a protector release transitions a foreign reference on a reference,
/// if we can determine that it's not a child of the released tag.
/// For this version we know the tag is not a child, because its wildcard root has
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
/// For this version we know the tag is not a child, because its wildcard root has
/// For this version we know the tag is not a child because its wildcard root has

// │ │
// ▼ ▼
// ┌───────────┐ ┌───────────┐
// │ arg4 │ │ ref6│
Copy link
Member

Choose a reason for hiding this comment

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

Does the horizontal alignment of ref6 mean anything?

Copy link
Member

Choose a reason for hiding this comment

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

This test seems very similar to the previous one, why did you add it as a separate test? Is there some plausible bug in the code that could make a difference between these tests?

Comment on lines +912 to +915
/// * `min_exposed_child`: any subtree that could be a child of `access_source` must
/// have a root with a larger tag than this. If None then no other subtree can be
/// a child of `access_source`.
/// This only gets read if `visit_children==SkipChildrenOfAccessed`.
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 doesn't match the name. What about something like this?

Suggested change
/// * `min_exposed_child`: any subtree that could be a child of `access_source` must
/// have a root with a larger tag than this. If None then no other subtree can be
/// a child of `access_source`.
/// This only gets read if `visit_children==SkipChildrenOfAccessed`.
/// * `min_exposed_child`: The tag of the smallest exposed (transitive) child of the accessed node.
/// This is useful with `visit_children == SkipChildrenOfAccessed`, where we need to skip children
/// of the accessed.

@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 Dec 18, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 18, 2025

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

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