Skip to content

Commit

Permalink
Visit the AllocIds and BorTags in borrow state FrameExtra
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Dec 16, 2023
1 parent e615426 commit f82a1c2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/borrow_tracker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub struct FrameState {
/// incremental updates of the global list of protected tags stored in the
/// `stacked_borrows::GlobalState` upon function return, and if we attempt to pop a protected
/// tag, to identify which call is responsible for protecting the tag.
/// See `Stack::item_popped` for more explanation.
/// See `Stack::item_invalidated` for more explanation.
/// Tree Borrows also needs to know which allocation these tags
/// belong to so that it can perform a read through them immediately before
/// the frame gets popped.
Expand All @@ -76,8 +76,10 @@ pub struct FrameState {
}

impl VisitProvenance for FrameState {
fn visit_provenance(&self, _visit: &mut VisitWith<'_>) {
// `protected_tags` are already recorded by `GlobalStateInner`.
fn visit_provenance(&self, visit: &mut VisitWith<'_>) {
for (id, tag) in &self.protected_tags {
visit(Some(*id), Some(*tag));
}
}
}

Expand All @@ -98,7 +100,7 @@ pub struct GlobalStateInner {
/// An item is protected if its tag is in this set, *and* it has the "protected" bit set.
/// We add tags to this when they are created with a protector in `reborrow`, and
/// we remove tags from this when the call which is protecting them returns, in
/// `GlobalStateInner::end_call`. See `Stack::item_popped` for more details.
/// `GlobalStateInner::end_call`. See `Stack::item_invalidated` for more details.
protected_tags: FxHashMap<BorTag, ProtectorKind>,
/// The pointer ids to trace
tracked_pointer_tags: FxHashSet<BorTag>,
Expand All @@ -111,10 +113,8 @@ pub struct GlobalStateInner {
}

impl VisitProvenance for GlobalStateInner {
fn visit_provenance(&self, visit: &mut VisitWith<'_>) {
for &tag in self.protected_tags.keys() {
visit(None, Some(tag));
}
fn visit_provenance(&self, _visit: &mut VisitWith<'_>) {
// All the provenance in protected_tags is also stored in FrameState, and visited there.
// The only other candidate is base_ptr_tags, and that does not need visiting since we don't ever
// GC the bottommost/root tag.
}
Expand Down
17 changes: 17 additions & 0 deletions tests/pass/protector-gc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// When we pop a stack frame with weak protectors, we need to check if the protected pointer's
// allocation is still live. If the provenance GC only knows about the BorTag that is protected,
// we can ICE. This test checks that we don't.
// See https://github.com/rust-lang/miri/issues/3228

#[path = "../utils/mod.rs"]
mod utils;

#[allow(unused)]
fn oof(mut b: Box<u8>) {
b = Box::new(0u8);
utils::run_provenance_gc();
}

fn main() {
oof(Box::new(0u8));
}

0 comments on commit f82a1c2

Please sign in to comment.