Skip to content

Commit aadf935

Browse files
committed
Extend the BorTag GC to AllocIds
1 parent b02a8a9 commit aadf935

File tree

21 files changed

+99
-55
lines changed

21 files changed

+99
-55
lines changed

src/borrow_tracker/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub struct FrameState {
7676
}
7777

7878
impl VisitTags for FrameState {
79-
fn visit_tags(&self, _visit: &mut dyn FnMut(BorTag)) {
79+
fn visit_tags(&self, _visit: &mut TagVisitor<'_>) {
8080
// `protected_tags` are already recorded by `GlobalStateInner`.
8181
}
8282
}
@@ -111,9 +111,9 @@ pub struct GlobalStateInner {
111111
}
112112

113113
impl VisitTags for GlobalStateInner {
114-
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
114+
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
115115
for &tag in self.protected_tags.keys() {
116-
visit(tag);
116+
visit(None, Some(tag));
117117
}
118118
// The only other candidate is base_ptr_tags, and that does not need visiting since we don't ever
119119
// GC the bottommost/root tag.
@@ -472,7 +472,7 @@ impl AllocState {
472472
}
473473

474474
impl VisitTags for AllocState {
475-
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
475+
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
476476
match self {
477477
AllocState::StackedBorrows(sb) => sb.visit_tags(visit),
478478
AllocState::TreeBorrows(tb) => tb.visit_tags(visit),

src/borrow_tracker/stacked_borrows/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,9 @@ impl Stacks {
463463
}
464464

465465
impl VisitTags for Stacks {
466-
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
466+
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
467467
for tag in self.exposed_tags.iter().copied() {
468-
visit(tag);
468+
visit(None, Some(tag));
469469
}
470470
}
471471
}

src/borrow_tracker/tree_borrows/tree.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,10 +745,10 @@ impl Tree {
745745
}
746746

747747
impl VisitTags for Tree {
748-
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
748+
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
749749
// To ensure that the root never gets removed, we visit it
750750
// (the `root` node of `Tree` is not an `Option<_>`)
751-
visit(self.nodes.get(self.root).unwrap().tag)
751+
visit(None, Some(self.nodes.get(self.root).unwrap().tag))
752752
}
753753
}
754754

src/concurrency/data_race.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,8 +694,8 @@ pub struct VClockAlloc {
694694
}
695695

696696
impl VisitTags for VClockAlloc {
697-
fn visit_tags(&self, _visit: &mut dyn FnMut(BorTag)) {
698-
// No tags here.
697+
fn visit_tags(&self, _visit: &mut TagVisitor<'_>) {
698+
// No tags or allocIds here.
699699
}
700700
}
701701

@@ -1275,7 +1275,7 @@ pub struct GlobalState {
12751275
}
12761276

12771277
impl VisitTags for GlobalState {
1278-
fn visit_tags(&self, _visit: &mut dyn FnMut(BorTag)) {
1278+
fn visit_tags(&self, _visit: &mut TagVisitor<'_>) {
12791279
// We don't have any tags.
12801280
}
12811281
}

src/concurrency/init_once.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub(super) struct InitOnce<'mir, 'tcx> {
4646
}
4747

4848
impl<'mir, 'tcx> VisitTags for InitOnce<'mir, 'tcx> {
49-
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
49+
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
5050
for waiter in self.waiters.iter() {
5151
waiter.callback.visit_tags(visit);
5252
}

src/concurrency/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ pub(crate) struct SynchronizationState<'mir, 'tcx> {
182182
}
183183

184184
impl<'mir, 'tcx> VisitTags for SynchronizationState<'mir, 'tcx> {
185-
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
185+
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
186186
for init_once in self.init_onces.iter() {
187187
init_once.visit_tags(visit);
188188
}

src/concurrency/thread.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl<'mir, 'tcx> Thread<'mir, 'tcx> {
220220
}
221221

222222
impl VisitTags for Thread<'_, '_> {
223-
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
223+
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
224224
let Thread {
225225
panic_payloads: panic_payload,
226226
last_error,
@@ -243,7 +243,7 @@ impl VisitTags for Thread<'_, '_> {
243243
}
244244

245245
impl VisitTags for Frame<'_, '_, Provenance, FrameExtra<'_>> {
246-
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
246+
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
247247
let Frame {
248248
return_place,
249249
locals,
@@ -333,7 +333,7 @@ pub struct ThreadManager<'mir, 'tcx> {
333333
}
334334

335335
impl VisitTags for ThreadManager<'_, '_> {
336-
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
336+
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
337337
let ThreadManager {
338338
threads,
339339
thread_local_alloc_ids,

src/concurrency/weak_memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub struct StoreBufferAlloc {
109109
}
110110

111111
impl VisitTags for StoreBufferAlloc {
112-
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
112+
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
113113
let Self { store_buffers } = self;
114114
for val in store_buffers
115115
.borrow()

src/intptrcast.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ pub struct GlobalStateInner {
4545
}
4646

4747
impl VisitTags for GlobalStateInner {
48-
fn visit_tags(&self, _visit: &mut dyn FnMut(BorTag)) {
49-
// Nothing to visit here.
48+
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
49+
for id in &self.exposed {
50+
id.visit_tags(visit)
51+
}
5052
}
5153
}
5254

@@ -63,6 +65,11 @@ impl GlobalStateInner {
6365
}
6466

6567
impl<'mir, 'tcx> GlobalStateInner {
68+
pub fn remove_unreachable_allocs(&mut self, live_allocs: &FxHashSet<AllocId>) {
69+
self.int_to_ptr_map.retain(|(_, id)| live_allocs.contains(id));
70+
self.base_addr.retain(|id, _| live_allocs.contains(id));
71+
}
72+
6673
// Returns the exposed `AllocId` that corresponds to the specified addr,
6774
// or `None` if the addr is out of bounds
6875
fn alloc_id_from_addr(ecx: &MiriInterpCx<'mir, 'tcx>, addr: u64) -> Option<AllocId> {

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ pub use crate::machine::{
125125
pub use crate::mono_hash_map::MonoHashMap;
126126
pub use crate::operator::EvalContextExt as _;
127127
pub use crate::range_map::RangeMap;
128-
pub use crate::tag_gc::{EvalContextExt as _, VisitTags};
128+
pub use crate::tag_gc::{EvalContextExt as _, TagVisitor, VisitTags};
129129

130130
/// Insert rustc arguments at the beginning of the argument list that Miri wants to be
131131
/// set per default, for maximal validation power.

0 commit comments

Comments
 (0)