Skip to content

Commit e212af2

Browse files
committed
re-architect the tag visitor traits
1 parent 841d1b2 commit e212af2

File tree

15 files changed

+306
-222
lines changed

15 files changed

+306
-222
lines changed

src/tools/miri/src/concurrency/data_race.rs

+12
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,12 @@ pub struct VClockAlloc {
696696
alloc_ranges: RefCell<RangeMap<MemoryCellClocks>>,
697697
}
698698

699+
impl VisitTags for VClockAlloc {
700+
fn visit_tags(&self, _visit: &mut dyn FnMut(SbTag)) {
701+
// No tags here.
702+
}
703+
}
704+
699705
impl VClockAlloc {
700706
/// Create a new data-race detector for newly allocated memory.
701707
pub fn new_allocation(
@@ -1239,6 +1245,12 @@ pub struct GlobalState {
12391245
pub track_outdated_loads: bool,
12401246
}
12411247

1248+
impl VisitTags for GlobalState {
1249+
fn visit_tags(&self, _visit: &mut dyn FnMut(SbTag)) {
1250+
// We don't have any tags.
1251+
}
1252+
}
1253+
12421254
impl GlobalState {
12431255
/// Create a new global state, setup with just thread-id=0
12441256
/// advanced to timestamp = 1.

src/tools/miri/src/concurrency/thread.rs

+18-23
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub enum SchedulingAction {
3232

3333
/// Timeout callbacks can be created by synchronization primitives to tell the
3434
/// scheduler that they should be called once some period of time passes.
35-
pub trait MachineCallback<'mir, 'tcx>: VisitMachineValues {
35+
pub trait MachineCallback<'mir, 'tcx>: VisitTags {
3636
fn call(&self, ecx: &mut InterpCx<'mir, 'tcx, MiriMachine<'mir, 'tcx>>) -> InterpResult<'tcx>;
3737
}
3838

@@ -183,25 +183,21 @@ impl<'mir, 'tcx> Thread<'mir, 'tcx> {
183183
}
184184
}
185185

186-
impl VisitMachineValues for Thread<'_, '_> {
187-
fn visit_machine_values(&self, visit: &mut ProvenanceVisitor) {
186+
impl VisitTags for Thread<'_, '_> {
187+
fn visit_tags(&self, visit: &mut dyn FnMut(SbTag)) {
188188
let Thread { panic_payload, last_error, stack, state: _, thread_name: _, join_status: _ } =
189189
self;
190190

191-
if let Some(payload) = panic_payload {
192-
visit.visit(*payload);
193-
}
194-
if let Some(error) = last_error {
195-
visit.visit(**error);
196-
}
191+
panic_payload.visit_tags(visit);
192+
last_error.visit_tags(visit);
197193
for frame in stack {
198-
frame.visit_machine_values(visit)
194+
frame.visit_tags(visit)
199195
}
200196
}
201197
}
202198

203-
impl VisitMachineValues for Frame<'_, '_, Provenance, FrameData<'_>> {
204-
fn visit_machine_values(&self, visit: &mut ProvenanceVisitor) {
199+
impl VisitTags for Frame<'_, '_, Provenance, FrameData<'_>> {
200+
fn visit_tags(&self, visit: &mut dyn FnMut(SbTag)) {
205201
let Frame {
206202
return_place,
207203
locals,
@@ -210,21 +206,20 @@ impl VisitMachineValues for Frame<'_, '_, Provenance, FrameData<'_>> {
210206
instance: _,
211207
return_to_block: _,
212208
loc: _,
209+
// There are some private fields we cannot access; they contain no tags.
213210
..
214211
} = self;
215212

216213
// Return place.
217-
if let Place::Ptr(mplace) = **return_place {
218-
visit.visit(mplace);
219-
}
214+
return_place.visit_tags(visit);
220215
// Locals.
221216
for local in locals.iter() {
222217
if let LocalValue::Live(value) = &local.value {
223-
visit.visit(value);
218+
value.visit_tags(visit);
224219
}
225220
}
226221

227-
extra.visit_machine_values(visit);
222+
extra.visit_tags(visit);
228223
}
229224
}
230225

@@ -300,8 +295,8 @@ impl<'mir, 'tcx> Default for ThreadManager<'mir, 'tcx> {
300295
}
301296
}
302297

303-
impl VisitMachineValues for ThreadManager<'_, '_> {
304-
fn visit_machine_values(&self, visit: &mut ProvenanceVisitor) {
298+
impl VisitTags for ThreadManager<'_, '_> {
299+
fn visit_tags(&self, visit: &mut dyn FnMut(SbTag)) {
305300
let ThreadManager {
306301
threads,
307302
thread_local_alloc_ids,
@@ -312,13 +307,13 @@ impl VisitMachineValues for ThreadManager<'_, '_> {
312307
} = self;
313308

314309
for thread in threads {
315-
thread.visit_machine_values(visit);
310+
thread.visit_tags(visit);
316311
}
317-
for ptr in thread_local_alloc_ids.borrow().values().copied() {
318-
visit.visit(ptr);
312+
for ptr in thread_local_alloc_ids.borrow().values() {
313+
ptr.visit_tags(visit);
319314
}
320315
for callback in timeout_callbacks.values() {
321-
callback.callback.visit_machine_values(visit);
316+
callback.callback.visit_tags(visit);
322317
}
323318
}
324319
}

src/tools/miri/src/concurrency/weak_memory.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,15 @@ pub struct StoreBufferAlloc {
108108
store_buffers: RefCell<RangeObjectMap<StoreBuffer>>,
109109
}
110110

111-
impl VisitMachineValues for StoreBufferAlloc {
112-
fn visit_machine_values(&self, visit: &mut ProvenanceVisitor) {
113-
for val in self
114-
.store_buffers
111+
impl VisitTags for StoreBufferAlloc {
112+
fn visit_tags(&self, visit: &mut dyn FnMut(SbTag)) {
113+
let Self { store_buffers } = self;
114+
for val in store_buffers
115115
.borrow()
116116
.iter()
117117
.flat_map(|buf| buf.buffer.iter().map(|element| &element.val))
118118
{
119-
visit.visit(val);
119+
val.visit_tags(visit);
120120
}
121121
}
122122
}

src/tools/miri/src/intptrcast.rs

+6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ pub struct GlobalStateInner {
4444
provenance_mode: ProvenanceMode,
4545
}
4646

47+
impl VisitTags for GlobalStateInner {
48+
fn visit_tags(&self, _visit: &mut dyn FnMut(SbTag)) {
49+
// Nothing to visit here.
50+
}
51+
}
52+
4753
impl GlobalStateInner {
4854
pub fn new(config: &MiriConfig) -> Self {
4955
GlobalStateInner {

src/tools/miri/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub use crate::range_map::RangeMap;
112112
pub use crate::stacked_borrows::{
113113
CallId, EvalContextExt as StackedBorEvalContextExt, Item, Permission, SbTag, Stack, Stacks,
114114
};
115-
pub use crate::tag_gc::{EvalContextExt as _, ProvenanceVisitor, VisitMachineValues};
115+
pub use crate::tag_gc::{EvalContextExt as _, VisitTags};
116116

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

src/tools/miri/src/machine.rs

+58-35
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,12 @@ impl<'tcx> std::fmt::Debug for FrameData<'tcx> {
6363
}
6464
}
6565

66-
impl VisitMachineValues for FrameData<'_> {
67-
fn visit_machine_values(&self, visit: &mut ProvenanceVisitor) {
68-
let FrameData { catch_unwind, stacked_borrows: _, timing: _ } = self;
66+
impl VisitTags for FrameData<'_> {
67+
fn visit_tags(&self, visit: &mut dyn FnMut(SbTag)) {
68+
let FrameData { catch_unwind, stacked_borrows, timing: _ } = self;
6969

70-
if let Some(catch_unwind) = catch_unwind {
71-
catch_unwind.visit_machine_values(visit);
72-
}
70+
catch_unwind.visit_tags(visit);
71+
stacked_borrows.visit_tags(visit);
7372
}
7473
}
7574

@@ -261,17 +260,13 @@ pub struct AllocExtra {
261260
pub weak_memory: Option<weak_memory::AllocExtra>,
262261
}
263262

264-
impl VisitMachineValues for AllocExtra {
265-
fn visit_machine_values(&self, visit: &mut ProvenanceVisitor) {
266-
let AllocExtra { stacked_borrows, data_race: _, weak_memory } = self;
267-
268-
if let Some(stacked_borrows) = stacked_borrows {
269-
stacked_borrows.borrow().visit_machine_values(visit);
270-
}
263+
impl VisitTags for AllocExtra {
264+
fn visit_tags(&self, visit: &mut dyn FnMut(SbTag)) {
265+
let AllocExtra { stacked_borrows, data_race, weak_memory } = self;
271266

272-
if let Some(weak_memory) = weak_memory {
273-
weak_memory.visit_machine_values(visit);
274-
}
267+
stacked_borrows.visit_tags(visit);
268+
data_race.visit_tags(visit);
269+
weak_memory.visit_tags(visit);
275270
}
276271
}
277272

@@ -615,8 +610,9 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
615610
}
616611
}
617612

618-
impl VisitMachineValues for MiriMachine<'_, '_> {
619-
fn visit_machine_values(&self, visit: &mut ProvenanceVisitor) {
613+
impl VisitTags for MiriMachine<'_, '_> {
614+
fn visit_tags(&self, visit: &mut dyn FnMut(SbTag)) {
615+
#[rustfmt::skip]
620616
let MiriMachine {
621617
threads,
622618
tls,
@@ -626,25 +622,52 @@ impl VisitMachineValues for MiriMachine<'_, '_> {
626622
cmd_line,
627623
extern_statics,
628624
dir_handler,
629-
..
625+
stacked_borrows,
626+
data_race,
627+
intptrcast,
628+
file_handler,
629+
tcx: _,
630+
isolated_op: _,
631+
validate: _,
632+
enforce_abi: _,
633+
clock: _,
634+
layouts: _,
635+
static_roots: _,
636+
profiler: _,
637+
string_cache: _,
638+
exported_symbols_cache: _,
639+
panic_on_unsupported: _,
640+
backtrace_style: _,
641+
local_crates: _,
642+
rng: _,
643+
tracked_alloc_ids: _,
644+
check_alignment: _,
645+
cmpxchg_weak_failure_rate: _,
646+
mute_stdout_stderr: _,
647+
weak_memory: _,
648+
preemption_rate: _,
649+
report_progress: _,
650+
basic_block_count: _,
651+
#[cfg(unix)]
652+
external_so_lib: _,
653+
gc_interval: _,
654+
since_gc: _,
655+
num_cpus: _,
630656
} = self;
631657

632-
threads.visit_machine_values(visit);
633-
tls.visit_machine_values(visit);
634-
env_vars.visit_machine_values(visit);
635-
dir_handler.visit_machine_values(visit);
636-
637-
if let Some(argc) = argc {
638-
visit.visit(argc);
639-
}
640-
if let Some(argv) = argv {
641-
visit.visit(argv);
642-
}
643-
if let Some(cmd_line) = cmd_line {
644-
visit.visit(cmd_line);
645-
}
646-
for ptr in extern_statics.values().copied() {
647-
visit.visit(ptr);
658+
threads.visit_tags(visit);
659+
tls.visit_tags(visit);
660+
env_vars.visit_tags(visit);
661+
dir_handler.visit_tags(visit);
662+
file_handler.visit_tags(visit);
663+
data_race.visit_tags(visit);
664+
stacked_borrows.visit_tags(visit);
665+
intptrcast.visit_tags(visit);
666+
argc.visit_tags(visit);
667+
argv.visit_tags(visit);
668+
cmd_line.visit_tags(visit);
669+
for ptr in extern_statics.values() {
670+
ptr.visit_tags(visit);
648671
}
649672
}
650673
}

src/tools/miri/src/shims/env.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,13 @@ pub struct EnvVars<'tcx> {
3636
pub(crate) environ: Option<MPlaceTy<'tcx, Provenance>>,
3737
}
3838

39-
impl VisitMachineValues for EnvVars<'_> {
40-
fn visit_machine_values(&self, visit: &mut ProvenanceVisitor) {
39+
impl VisitTags for EnvVars<'_> {
40+
fn visit_tags(&self, visit: &mut dyn FnMut(SbTag)) {
4141
let EnvVars { map, environ } = self;
4242

43+
environ.visit_tags(visit);
4344
for ptr in map.values() {
44-
visit.visit(*ptr);
45-
}
46-
if let Some(env) = environ {
47-
visit.visit(**env);
45+
ptr.visit_tags(visit);
4846
}
4947
}
5048
}

src/tools/miri/src/shims/panic.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ pub struct CatchUnwindData<'tcx> {
3535
ret: mir::BasicBlock,
3636
}
3737

38-
impl VisitMachineValues for CatchUnwindData<'_> {
39-
fn visit_machine_values(&self, visit: &mut ProvenanceVisitor) {
40-
let CatchUnwindData { catch_fn, data, dest: _, ret: _ } = self;
41-
visit.visit(catch_fn);
42-
visit.visit(data);
38+
impl VisitTags for CatchUnwindData<'_> {
39+
fn visit_tags(&self, visit: &mut dyn FnMut(SbTag)) {
40+
let CatchUnwindData { catch_fn, data, dest, ret: _ } = self;
41+
catch_fn.visit_tags(visit);
42+
data.visit_tags(visit);
43+
dest.visit_tags(visit);
4344
}
4445
}
4546

src/tools/miri/src/shims/time.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
219219
this.register_timeout_callback(
220220
active_thread,
221221
Time::Monotonic(timeout_time),
222-
Box::new(Callback { active_thread }),
222+
Box::new(UnblockCallback { thread_to_unblock: active_thread }),
223223
);
224224

225225
Ok(0)
@@ -242,24 +242,24 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
242242
this.register_timeout_callback(
243243
active_thread,
244244
Time::Monotonic(timeout_time),
245-
Box::new(Callback { active_thread }),
245+
Box::new(UnblockCallback { thread_to_unblock: active_thread }),
246246
);
247247

248248
Ok(())
249249
}
250250
}
251251

252-
struct Callback {
253-
active_thread: ThreadId,
252+
struct UnblockCallback {
253+
thread_to_unblock: ThreadId,
254254
}
255255

256-
impl VisitMachineValues for Callback {
257-
fn visit_machine_values(&self, _visit: &mut ProvenanceVisitor) {}
256+
impl VisitTags for UnblockCallback {
257+
fn visit_tags(&self, _visit: &mut dyn FnMut(SbTag)) {}
258258
}
259259

260-
impl<'mir, 'tcx: 'mir> MachineCallback<'mir, 'tcx> for Callback {
260+
impl<'mir, 'tcx: 'mir> MachineCallback<'mir, 'tcx> for UnblockCallback {
261261
fn call(&self, ecx: &mut MiriInterpCx<'mir, 'tcx>) -> InterpResult<'tcx> {
262-
ecx.unblock_thread(self.active_thread);
262+
ecx.unblock_thread(self.thread_to_unblock);
263263
Ok(())
264264
}
265265
}

src/tools/miri/src/shims/tls.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,15 @@ impl<'tcx> TlsData<'tcx> {
235235
}
236236
}
237237

238-
impl VisitMachineValues for TlsData<'_> {
239-
fn visit_machine_values(&self, visit: &mut ProvenanceVisitor) {
238+
impl VisitTags for TlsData<'_> {
239+
fn visit_tags(&self, visit: &mut dyn FnMut(SbTag)) {
240240
let TlsData { keys, macos_thread_dtors, next_key: _, dtors_running: _ } = self;
241241

242242
for scalar in keys.values().flat_map(|v| v.data.values()) {
243-
visit.visit(scalar);
243+
scalar.visit_tags(visit);
244244
}
245245
for (_, scalar) in macos_thread_dtors.values() {
246-
visit.visit(scalar);
246+
scalar.visit_tags(visit);
247247
}
248248
}
249249
}

0 commit comments

Comments
 (0)