Skip to content

Commit aaf674e

Browse files
committed
Extend the BorTag GC to AllocIds
1 parent e9e1b3d commit aaf674e

File tree

24 files changed

+294
-236
lines changed

24 files changed

+294
-236
lines changed

src/borrow_tracker/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ pub struct FrameState {
7575
pub protected_tags: SmallVec<[(AllocId, BorTag); 2]>,
7676
}
7777

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

113-
impl VisitTags for GlobalStateInner {
114-
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
113+
impl VisitProvenance for GlobalStateInner {
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.
@@ -471,8 +471,8 @@ impl AllocState {
471471
}
472472
}
473473

474-
impl VisitTags for AllocState {
475-
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
474+
impl VisitProvenance for AllocState {
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,10 @@ impl Stacks {
462462
}
463463
}
464464

465-
impl VisitTags for Stacks {
466-
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
465+
impl VisitProvenance for Stacks {
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -744,11 +744,11 @@ impl Tree {
744744
}
745745
}
746746

747-
impl VisitTags for Tree {
748-
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
747+
impl VisitProvenance for Tree {
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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -693,9 +693,9 @@ pub struct VClockAlloc {
693693
alloc_ranges: RefCell<RangeMap<MemoryCellClocks>>,
694694
}
695695

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

@@ -1269,8 +1269,8 @@ pub struct GlobalState {
12691269
pub track_outdated_loads: bool,
12701270
}
12711271

1272-
impl VisitTags for GlobalState {
1273-
fn visit_tags(&self, _visit: &mut dyn FnMut(BorTag)) {
1272+
impl VisitProvenance for GlobalState {
1273+
fn visit_tags(&self, _visit: &mut TagVisitor<'_>) {
12741274
// We don't have any tags.
12751275
}
12761276
}

src/concurrency/init_once.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ pub(super) struct InitOnce<'mir, 'tcx> {
4545
data_race: VClock,
4646
}
4747

48-
impl<'mir, 'tcx> VisitTags for InitOnce<'mir, 'tcx> {
49-
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
48+
impl<'mir, 'tcx> VisitProvenance for InitOnce<'mir, 'tcx> {
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ pub(crate) struct SynchronizationState<'mir, 'tcx> {
181181
pub(super) init_onces: IndexVec<InitOnceId, InitOnce<'mir, 'tcx>>,
182182
}
183183

184-
impl<'mir, 'tcx> VisitTags for SynchronizationState<'mir, 'tcx> {
185-
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
184+
impl<'mir, 'tcx> VisitProvenance for SynchronizationState<'mir, 'tcx> {
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: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ enum SchedulingAction {
3434
}
3535

3636
/// Trait for callbacks that can be executed when some event happens, such as after a timeout.
37-
pub trait MachineCallback<'mir, 'tcx>: VisitTags {
37+
pub trait MachineCallback<'mir, 'tcx>: VisitProvenance {
3838
fn call(&self, ecx: &mut InterpCx<'mir, 'tcx, MiriMachine<'mir, 'tcx>>) -> InterpResult<'tcx>;
3939
}
4040

@@ -219,8 +219,8 @@ impl<'mir, 'tcx> Thread<'mir, 'tcx> {
219219
}
220220
}
221221

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

245-
impl VisitTags for Frame<'_, '_, Provenance, FrameExtra<'_>> {
246-
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
245+
impl VisitProvenance for Frame<'_, '_, Provenance, FrameExtra<'_>> {
246+
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
247247
let Frame {
248248
return_place,
249249
locals,
@@ -332,8 +332,8 @@ pub struct ThreadManager<'mir, 'tcx> {
332332
timeout_callbacks: FxHashMap<ThreadId, TimeoutCallbackInfo<'mir, 'tcx>>,
333333
}
334334

335-
impl VisitTags for ThreadManager<'_, '_> {
336-
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
335+
impl VisitProvenance for ThreadManager<'_, '_> {
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ pub struct StoreBufferAlloc {
108108
store_buffers: RefCell<RangeObjectMap<StoreBuffer>>,
109109
}
110110

111-
impl VisitTags for StoreBufferAlloc {
112-
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
111+
impl VisitProvenance for StoreBufferAlloc {
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: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,21 @@ pub struct GlobalStateInner {
4646
provenance_mode: ProvenanceMode,
4747
}
4848

49-
impl VisitTags for GlobalStateInner {
50-
fn visit_tags(&self, _visit: &mut dyn FnMut(BorTag)) {
51-
// Nothing to visit here.
49+
impl VisitProvenance for GlobalStateInner {
50+
fn visit_tags(&self, visit: &mut TagVisitor<'_>) {
51+
let GlobalStateInner {
52+
int_to_ptr_map: _,
53+
base_addr: _,
54+
exposed,
55+
next_base_addr: _,
56+
provenance_mode: _,
57+
} = self;
58+
// Though int_to_ptr_map and base_addr contain AllocIds, we do not want to visit them
59+
// because they are the state accumulation that our GC is supposed to clean out. Every
60+
// allocation produces an entry in int_to_ptr_map and base_addr indefinitely.
61+
for id in exposed {
62+
id.visit_tags(visit)
63+
}
5264
}
5365
}
5466

@@ -62,6 +74,10 @@ impl GlobalStateInner {
6274
provenance_mode: config.provenance_mode,
6375
}
6476
}
77+
78+
pub fn remove_unreachable_allocs(&mut self, reachable_allocs: &FxHashSet<AllocId>) {
79+
self.base_addr.retain(|id, _| reachable_allocs.contains(id));
80+
}
6581
}
6682

6783
/// Shifts `addr` to make it aligned with `align` by rounding `addr` to the smallest multiple

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ mod intptrcast;
7676
mod machine;
7777
mod mono_hash_map;
7878
mod operator;
79+
mod provenance_gc;
7980
mod range_map;
8081
mod shims;
81-
mod tag_gc;
8282

8383
// Establish a "crate-wide prelude": we often import `crate::*`.
8484

@@ -124,8 +124,8 @@ pub use crate::machine::{
124124
};
125125
pub use crate::mono_hash_map::MonoHashMap;
126126
pub use crate::operator::EvalContextExt as _;
127+
pub use crate::provenance_gc::{EvalContextExt as _, TagVisitor, VisitProvenance};
127128
pub use crate::range_map::RangeMap;
128-
pub use crate::tag_gc::{EvalContextExt as _, 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)