Skip to content

Commit 1776178

Browse files
committed
re-architect the tag visitor traits
1 parent 1ad66d9 commit 1776178

File tree

15 files changed

+303
-222
lines changed

15 files changed

+303
-222
lines changed

src/concurrency/data_race.rs

Lines changed: 12 additions & 0 deletions
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/concurrency/thread.rs

Lines changed: 18 additions & 23 deletions
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/concurrency/weak_memory.rs

Lines changed: 5 additions & 5 deletions
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/intptrcast.rs

Lines changed: 6 additions & 0 deletions
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/lib.rs

Lines changed: 1 addition & 1 deletion
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/machine.rs

Lines changed: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,12 @@ impl<'tcx> std::fmt::Debug for FrameData<'tcx> {
6464
}
6565
}
6666

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

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

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

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

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

@@ -613,8 +608,8 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
613608
}
614609
}
615610

616-
impl VisitMachineValues for MiriMachine<'_, '_> {
617-
fn visit_machine_values(&self, visit: &mut ProvenanceVisitor) {
611+
impl VisitTags for MiriMachine<'_, '_> {
612+
fn visit_tags(&self, visit: &mut dyn FnMut(SbTag)) {
618613
let MiriMachine {
619614
threads,
620615
tls,
@@ -624,25 +619,50 @@ impl VisitMachineValues for MiriMachine<'_, '_> {
624619
cmd_line,
625620
extern_statics,
626621
dir_handler,
627-
..
622+
stacked_borrows,
623+
data_race,
624+
intptrcast,
625+
file_handler,
626+
tcx: _,
627+
isolated_op: _,
628+
validate: _,
629+
enforce_abi: _,
630+
clock: _,
631+
layouts: _,
632+
static_roots: _,
633+
profiler: _,
634+
string_cache: _,
635+
exported_symbols_cache: _,
636+
panic_on_unsupported: _,
637+
backtrace_style: _,
638+
local_crates: _,
639+
rng: _,
640+
tracked_alloc_ids: _,
641+
check_alignment: _,
642+
cmpxchg_weak_failure_rate: _,
643+
mute_stdout_stderr: _,
644+
weak_memory: _,
645+
preemption_rate: _,
646+
report_progress: _,
647+
basic_block_count: _,
648+
external_so_lib: _,
649+
gc_interval: _,
650+
since_gc: _,
628651
} = self;
629652

630-
threads.visit_machine_values(visit);
631-
tls.visit_machine_values(visit);
632-
env_vars.visit_machine_values(visit);
633-
dir_handler.visit_machine_values(visit);
634-
635-
if let Some(argc) = argc {
636-
visit.visit(argc);
637-
}
638-
if let Some(argv) = argv {
639-
visit.visit(argv);
640-
}
641-
if let Some(cmd_line) = cmd_line {
642-
visit.visit(cmd_line);
643-
}
644-
for ptr in extern_statics.values().copied() {
645-
visit.visit(ptr);
653+
threads.visit_tags(visit);
654+
tls.visit_tags(visit);
655+
env_vars.visit_tags(visit);
656+
dir_handler.visit_tags(visit);
657+
file_handler.visit_tags(visit);
658+
data_race.visit_tags(visit);
659+
stacked_borrows.visit_tags(visit);
660+
intptrcast.visit_tags(visit);
661+
argc.visit_tags(visit);
662+
argv.visit_tags(visit);
663+
cmd_line.visit_tags(visit);
664+
for ptr in extern_statics.values() {
665+
ptr.visit_tags(visit);
646666
}
647667
}
648668
}

src/shims/env.rs

Lines changed: 4 additions & 6 deletions
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/shims/panic.rs

Lines changed: 6 additions & 5 deletions
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/shims/time.rs

Lines changed: 8 additions & 8 deletions
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/shims/tls.rs

Lines changed: 4 additions & 4 deletions
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)