Skip to content

Commit 84134c6

Browse files
address nits
1 parent e34f35e commit 84134c6

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

src/tools/miri/src/borrow_tracker/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ pub struct FrameState {
7171

7272
impl VisitProvenance for FrameState {
7373
fn visit_provenance(&self, visit: &mut VisitWith<'_>) {
74+
// Visit all protected tags. At least in Tree Borrows,
75+
// protected tags can not be GC'd because they still have
76+
// an access coming when the protector ends. Additionally,
77+
// the tree compacting mechanism of TB's GC relies on the fact
78+
// that all protected tags are marked as live for correctness,
79+
// so we _have_ to visit them here.
7480
for (id, tag) in &self.protected_tags {
7581
visit(Some(*id), Some(*tag));
7682
}

src/tools/miri/src/borrow_tracker/tree_borrows/perms.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -288,18 +288,19 @@ impl Permission {
288288
(ReservedFrz { .. }, ReservedIM) => false,
289289
(ReservedFrz { .. }, _) => true,
290290
// Active can not be replaced by something surviving
291-
// foreign reads and then remaining writable
291+
// foreign reads and then remaining writable.
292292
(Active, ReservedIM) => false,
293293
(Active, ReservedFrz { .. }) => false,
294+
// Replacing a state by itself is always okay, even if the child state is protected.
294295
(Active, Active) => true,
295-
// Active can be replaced by Frozen, since it is not protected
296+
// Active can be replaced by Frozen, since it is not protected.
296297
(Active, Frozen) => true,
297298
(Active, Disabled) => true,
298-
// Frozen can only be replaced by Disabled
299+
// Frozen can only be replaced by Disabled (and itself).
299300
(Frozen, Frozen) => true,
300301
(Frozen, Disabled) => true,
301302
(Frozen, _) => false,
302-
// Disabled can not be replaced by anything else
303+
// Disabled can not be replaced by anything else.
303304
(Disabled, Disabled) => true,
304305
(Disabled, _) => false,
305306
}

src/tools/miri/src/borrow_tracker/tree_borrows/tree.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ impl LocationState {
128128
Ok(transition)
129129
}
130130

131-
/// Like `perform_access`, but ignores the diagnostics, and also is pure.
132-
/// As such, it returns `Some(x)` if the transition succeeded, or `None`
133-
/// if there was an error.
134-
#[allow(unused)]
131+
/// Like `perform_access`, but ignores the concrete error cause and also uses state-passing
132+
/// rather than a mutable reference. As such, it returns `Some(x)` if the transition succeeded,
133+
/// or `None` if there was an error.
134+
#[cfg(test)]
135135
fn perform_access_no_fluff(
136136
mut self,
137137
access_kind: AccessKind,
@@ -865,14 +865,18 @@ impl Tree {
865865
live: &FxHashSet<BorTag>,
866866
) -> Option<UniIndex> {
867867
let node = self.nodes.get(idx).unwrap();
868+
869+
// We never want to replace the root node, as it is also kept in `root_ptr_tags`.
868870
if node.children.len() != 1 || live.contains(&node.tag) || node.parent.is_none() {
869871
return None;
870872
}
871-
// Since protected nodes are never GC'd (see `borrow_tracker::GlobalStateInner::visit_provenance`),
873+
// Since protected nodes are never GC'd (see `borrow_tracker::FrameExtra::visit_provenance`),
872874
// we know that `node` is not protected because otherwise `live` would
873875
// have contained `node.tag`.
874876
let child_idx = node.children[0];
875877
let child = self.nodes.get(child_idx).unwrap();
878+
// Check that for that one child, `can_be_replaced_by_child` holds for the permission
879+
// on all locations.
876880
for (_, data) in self.rperms.iter_all() {
877881
let parent_perm =
878882
data.get(idx).map(|x| x.permission).unwrap_or_else(|| node.default_initial_perm);
@@ -893,7 +897,6 @@ impl Tree {
893897
/// should have no children, but this is not checked, so that nodes
894898
/// whose children were rotated somewhere else can be deleted without
895899
/// having to first modify them to clear that array.
896-
/// otherwise (i.e. the GC should have marked it as removable).
897900
fn remove_useless_node(&mut self, this: UniIndex) {
898901
// Due to the API of UniMap we must make sure to call
899902
// `UniValMap::remove` for the key of this node on *all* maps that used it
@@ -950,17 +953,18 @@ impl Tree {
950953
// Remove all useless children.
951954
children_of_node.retain_mut(|idx| {
952955
if self.is_useless(*idx, live) {
953-
// delete it everywhere else
956+
// Delete `idx` node everywhere else.
954957
self.remove_useless_node(*idx);
955-
// and delete it from children_of_node
958+
// And delete it from children_of_node.
956959
false
957960
} else {
958961
if let Some(nextchild) = self.can_be_replaced_by_single_child(*idx, live) {
959-
// delete the in-between child
962+
// `nextchild` is our grandchild, and will become our direct child.
963+
// Delete the in-between node, `idx`.
960964
self.remove_useless_node(*idx);
961-
// set the new child's parent
965+
// Set the new child's parent.
962966
self.nodes.get_mut(nextchild).unwrap().parent = Some(*tag);
963-
// save the new child in children_of_node
967+
// Save the new child in children_of_node.
964968
*idx = nextchild;
965969
}
966970
// retain it

0 commit comments

Comments
 (0)