Skip to content

Commit 7db942b

Browse files
committed
remove the concept of a Call ID
1 parent 10cb5aa commit 7db942b

25 files changed

+40
-98
lines changed

src/tools/miri/README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,6 @@ to Miri failing to detect cases of undefined behavior in a program.
414414
being allocated or freed. This helps in debugging memory leaks and
415415
use after free bugs. Specifying this argument multiple times does not overwrite the previous
416416
values, instead it appends its values to the list. Listing an id multiple times has no effect.
417-
* `-Zmiri-track-call-id=<id1>,<id2>,...` shows a backtrace when the given call ids are
418-
assigned to a stack frame. This helps in debugging UB related to Stacked
419-
Borrows "protectors". Specifying this argument multiple times does not overwrite the previous
420-
values, instead it appends its values to the list. Listing an id multiple times has no effect.
421417
* `-Zmiri-track-pointer-tag=<tag1>,<tag2>,...` shows a backtrace when a given pointer tag
422418
is created and when (if ever) it is popped from a borrow stack (which is where the tag becomes invalid
423419
and any future use of it will error). This helps you in finding out why UB is

src/tools/miri/src/bin/miri.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -581,17 +581,6 @@ fn main() {
581581
show_error!("-Zmiri-track-pointer-tag requires nonzero arguments");
582582
}
583583
}
584-
} else if let Some(param) = arg.strip_prefix("-Zmiri-track-call-id=") {
585-
let ids: Vec<u64> = parse_comma_list(param).unwrap_or_else(|err| {
586-
show_error!("-Zmiri-track-call-id requires a comma separated list of valid `u64` arguments: {err}")
587-
});
588-
for id in ids.into_iter().map(miri::CallId::new) {
589-
if let Some(id) = id {
590-
miri_config.tracked_call_ids.insert(id);
591-
} else {
592-
show_error!("-Zmiri-track-call-id requires a nonzero argument");
593-
}
594-
}
595584
} else if let Some(param) = arg.strip_prefix("-Zmiri-track-alloc-id=") {
596585
let ids = parse_comma_list::<NonZero<u64>>(param).unwrap_or_else(|err| {
597586
show_error!("-Zmiri-track-alloc-id requires a comma separated list of valid non-zero `u64` arguments: {err}")

src/tools/miri/src/borrow_tracker/mod.rs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ use crate::*;
1212
pub mod stacked_borrows;
1313
pub mod tree_borrows;
1414

15-
pub type CallId = NonZero<u64>;
16-
1715
/// Tracking pointer provenance
1816
#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
1917
pub struct BorTag(NonZero<u64>);
@@ -57,9 +55,6 @@ impl fmt::Debug for BorTag {
5755
/// Per-call-stack-frame data for borrow tracking
5856
#[derive(Debug)]
5957
pub struct FrameState {
60-
/// The ID of the call this frame corresponds to.
61-
call_id: CallId,
62-
6358
/// If this frame is protecting any tags, they are listed here. We use this list to do
6459
/// incremental updates of the global list of protected tags stored in the
6560
/// `stacked_borrows::GlobalState` upon function return, and if we attempt to pop a protected
@@ -93,17 +88,13 @@ pub struct GlobalStateInner {
9388
/// The root tag is the one used for the initial pointer.
9489
/// We need this in a separate table to handle cyclic statics.
9590
root_ptr_tags: FxHashMap<AllocId, BorTag>,
96-
/// Next unused call ID (for protectors).
97-
next_call_id: CallId,
9891
/// All currently protected tags.
9992
/// We add tags to this when they are created with a protector in `reborrow`, and
10093
/// we remove tags from this when the call which is protecting them returns, in
10194
/// `GlobalStateInner::end_call`. See `Stack::item_invalidated` for more details.
10295
protected_tags: FxHashMap<BorTag, ProtectorKind>,
10396
/// The pointer ids to trace
10497
tracked_pointer_tags: FxHashSet<BorTag>,
105-
/// The call ids to trace
106-
tracked_call_ids: FxHashSet<CallId>,
10798
/// Whether to recurse into datatypes when searching for pointers to retag.
10899
retag_fields: RetagFields,
109100
/// Whether `core::ptr::Unique` gets special (`Box`-like) handling.
@@ -167,18 +158,15 @@ impl GlobalStateInner {
167158
pub fn new(
168159
borrow_tracker_method: BorrowTrackerMethod,
169160
tracked_pointer_tags: FxHashSet<BorTag>,
170-
tracked_call_ids: FxHashSet<CallId>,
171161
retag_fields: RetagFields,
172162
unique_is_unique: bool,
173163
) -> Self {
174164
GlobalStateInner {
175165
borrow_tracker_method,
176166
next_ptr_tag: BorTag::one(),
177167
root_ptr_tags: FxHashMap::default(),
178-
next_call_id: NonZero::new(1).unwrap(),
179168
protected_tags: FxHashMap::default(),
180169
tracked_pointer_tags,
181-
tracked_call_ids,
182170
retag_fields,
183171
unique_is_unique,
184172
}
@@ -191,14 +179,8 @@ impl GlobalStateInner {
191179
id
192180
}
193181

194-
pub fn new_frame(&mut self, machine: &MiriMachine<'_>) -> FrameState {
195-
let call_id = self.next_call_id;
196-
trace!("new_frame: Assigning call ID {}", call_id);
197-
if self.tracked_call_ids.contains(&call_id) {
198-
machine.emit_diagnostic(NonHaltingDiagnostic::CreatedCallId(call_id));
199-
}
200-
self.next_call_id = NonZero::new(call_id.get() + 1).unwrap();
201-
FrameState { call_id, protected_tags: SmallVec::new() }
182+
pub fn new_frame(&mut self) -> FrameState {
183+
FrameState { protected_tags: SmallVec::new() }
202184
}
203185

204186
fn end_call(&mut self, frame: &machine::FrameExtra<'_>) {
@@ -251,7 +233,6 @@ impl BorrowTrackerMethod {
251233
RefCell::new(GlobalStateInner::new(
252234
self,
253235
config.tracked_pointer_tags.clone(),
254-
config.tracked_call_ids.clone(),
255236
config.retag_fields,
256237
config.unique_is_unique,
257238
))

src/tools/miri/src/borrow_tracker/stacked_borrows/diagnostics.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -429,30 +429,14 @@ impl<'history, 'ecx, 'tcx> DiagnosticCx<'history, 'ecx, 'tcx> {
429429
ProtectorKind::WeakProtector => "weakly protected",
430430
ProtectorKind::StrongProtector => "strongly protected",
431431
};
432-
let item_tag = item.tag();
433-
let call_id = self
434-
.machine
435-
.threads
436-
.all_stacks()
437-
.flat_map(|(_id, stack)| stack)
438-
.map(|frame| {
439-
frame.extra.borrow_tracker.as_ref().expect("we should have borrow tracking data")
440-
})
441-
.find(|frame| frame.protected_tags.iter().any(|(_, tag)| tag == &item_tag))
442-
.map(|frame| frame.call_id)
443-
.unwrap(); // FIXME: Surely we should find something, but a panic seems wrong here?
444432
match self.operation {
445433
Operation::Dealloc(_) =>
446-
err_sb_ub(
447-
format!("deallocating while item {item:?} is {protected} by call {call_id:?}",),
448-
vec![],
449-
None,
450-
),
434+
err_sb_ub(format!("deallocating while item {item:?} is {protected}",), vec![], None),
451435
Operation::Retag(RetagOp { orig_tag: tag, .. })
452436
| Operation::Access(AccessOp { tag, .. }) =>
453437
err_sb_ub(
454438
format!(
455-
"not granting access to tag {tag:?} because that would remove {item:?} which is {protected} because it is an argument of call {call_id:?}",
439+
"not granting access to tag {tag:?} because that would remove {item:?} which is {protected}",
456440
),
457441
vec![],
458442
tag.and_then(|tag| self.get_logs_relevant_to(tag, Some(item.tag()))),

src/tools/miri/src/diagnostics.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ pub enum NonHaltingDiagnostic {
116116
CreatedPointerTag(NonZero<u64>, Option<String>, Option<(AllocId, AllocRange, ProvenanceExtra)>),
117117
/// This `Item` was popped from the borrow stack. The string explains the reason.
118118
PoppedPointerTag(Item, String),
119-
CreatedCallId(CallId),
120119
CreatedAlloc(AllocId, Size, Align, MemoryKind),
121120
FreedAlloc(AllocId),
122121
AccessedAlloc(AllocId, AccessKind),
@@ -607,7 +606,6 @@ impl<'tcx> MiriMachine<'tcx> {
607606
("reborrow of reference to `extern type`".to_string(), DiagLevel::Warning),
608607
CreatedPointerTag(..)
609608
| PoppedPointerTag(..)
610-
| CreatedCallId(..)
611609
| CreatedAlloc(..)
612610
| AccessedAlloc(..)
613611
| FreedAlloc(..)
@@ -625,7 +623,6 @@ impl<'tcx> MiriMachine<'tcx> {
625623
"created tag {tag:?} with {perm} at {alloc_id:?}{range:?} derived from {orig_tag:?}"
626624
),
627625
PoppedPointerTag(item, cause) => format!("popped tracked tag for item {item:?}{cause}"),
628-
CreatedCallId(id) => format!("function call with id {id}"),
629626
CreatedAlloc(AllocId(id), size, align, kind) =>
630627
format!(
631628
"created {kind} allocation of {size} bytes (alignment {align} bytes) with id {id}",

src/tools/miri/src/eval.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ pub struct MiriConfig {
118118
pub seed: Option<u64>,
119119
/// The stacked borrows pointer ids to report about
120120
pub tracked_pointer_tags: FxHashSet<BorTag>,
121-
/// The stacked borrows call IDs to report about
122-
pub tracked_call_ids: FxHashSet<CallId>,
123121
/// The allocation ids to report about.
124122
pub tracked_alloc_ids: FxHashSet<AllocId>,
125123
/// For the tracked alloc ids, also report read/write accesses.
@@ -183,7 +181,6 @@ impl Default for MiriConfig {
183181
args: vec![],
184182
seed: None,
185183
tracked_pointer_tags: FxHashSet::default(),
186-
tracked_call_ids: FxHashSet::default(),
187184
tracked_alloc_ids: FxHashSet::default(),
188185
track_alloc_accesses: false,
189186
data_race_detector: true,

src/tools/miri/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,7 @@ pub use crate::borrow_tracker::stacked_borrows::{
123123
EvalContextExt as _, Item, Permission, Stack, Stacks,
124124
};
125125
pub use crate::borrow_tracker::tree_borrows::{EvalContextExt as _, Tree};
126-
pub use crate::borrow_tracker::{
127-
BorTag, BorrowTrackerMethod, CallId, EvalContextExt as _, RetagFields,
128-
};
126+
pub use crate::borrow_tracker::{BorTag, BorrowTrackerMethod, EvalContextExt as _, RetagFields};
129127
pub use crate::clock::{Clock, Instant};
130128
pub use crate::concurrency::{
131129
cpu_affinity::MAX_CPUS,

src/tools/miri/src/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
13681368
let borrow_tracker = ecx.machine.borrow_tracker.as_ref();
13691369

13701370
let extra = FrameExtra {
1371-
borrow_tracker: borrow_tracker.map(|bt| bt.borrow_mut().new_frame(&ecx.machine)),
1371+
borrow_tracker: borrow_tracker.map(|bt| bt.borrow_mut().new_frame()),
13721372
catch_unwind: None,
13731373
timing,
13741374
is_user_relevant: ecx.machine.is_user_relevant(&frame),

src/tools/miri/tests/fail/both_borrows/aliasing_mut1.stack.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: not granting access to tag <TAG> because that would remove [Unique for <TAG>] which is strongly protected because it is an argument of call ID
1+
error: Undefined Behavior: not granting access to tag <TAG> because that would remove [Unique for <TAG>] which is strongly protected
22
--> $DIR/aliasing_mut1.rs:LL:CC
33
|
44
LL | pub fn safe(x: &mut i32, y: &mut i32) {
5-
| ^ not granting access to tag <TAG> because that would remove [Unique for <TAG>] which is strongly protected because it is an argument of call ID
5+
| ^ not granting access to tag <TAG> because that would remove [Unique for <TAG>] which is strongly protected
66
|
77
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
88
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information

src/tools/miri/tests/fail/both_borrows/aliasing_mut2.stack.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: not granting access to tag <TAG> because that would remove [SharedReadOnly for <TAG>] which is strongly protected because it is an argument of call ID
1+
error: Undefined Behavior: not granting access to tag <TAG> because that would remove [SharedReadOnly for <TAG>] which is strongly protected
22
--> $DIR/aliasing_mut2.rs:LL:CC
33
|
44
LL | pub fn safe(x: &i32, y: &mut i32) {
5-
| ^ not granting access to tag <TAG> because that would remove [SharedReadOnly for <TAG>] which is strongly protected because it is an argument of call ID
5+
| ^ not granting access to tag <TAG> because that would remove [SharedReadOnly for <TAG>] which is strongly protected
66
|
77
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
88
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information

src/tools/miri/tests/fail/both_borrows/aliasing_mut4.stack.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: not granting access to tag <TAG> because that would remove [SharedReadOnly for <TAG>] which is strongly protected because it is an argument of call ID
1+
error: Undefined Behavior: not granting access to tag <TAG> because that would remove [SharedReadOnly for <TAG>] which is strongly protected
22
--> $DIR/aliasing_mut4.rs:LL:CC
33
|
44
LL | pub fn safe(x: &i32, y: &mut Cell<i32>) {
5-
| ^ not granting access to tag <TAG> because that would remove [SharedReadOnly for <TAG>] which is strongly protected because it is an argument of call ID
5+
| ^ not granting access to tag <TAG> because that would remove [SharedReadOnly for <TAG>] which is strongly protected
66
|
77
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
88
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information

src/tools/miri/tests/fail/both_borrows/box_noalias_violation.stack.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: not granting access to tag <TAG> because that would remove [Unique for <TAG>] which is weakly protected because it is an argument of call ID
1+
error: Undefined Behavior: not granting access to tag <TAG> because that would remove [Unique for <TAG>] which is weakly protected
22
--> $DIR/box_noalias_violation.rs:LL:CC
33
|
44
LL | *y
5-
| ^^ not granting access to tag <TAG> because that would remove [Unique for <TAG>] which is weakly protected because it is an argument of call ID
5+
| ^^ not granting access to tag <TAG> because that would remove [Unique for <TAG>] which is weakly protected
66
|
77
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
88
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information

src/tools/miri/tests/fail/both_borrows/illegal_write6.stack.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: not granting access to tag <TAG> because that would remove [Unique for <TAG>] which is strongly protected because it is an argument of call ID
1+
error: Undefined Behavior: not granting access to tag <TAG> because that would remove [Unique for <TAG>] which is strongly protected
22
--> $DIR/illegal_write6.rs:LL:CC
33
|
44
LL | unsafe { *y = 2 };
5-
| ^^^^^^ not granting access to tag <TAG> because that would remove [Unique for <TAG>] which is strongly protected because it is an argument of call ID
5+
| ^^^^^^ not granting access to tag <TAG> because that would remove [Unique for <TAG>] which is strongly protected
66
|
77
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
88
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information

src/tools/miri/tests/fail/both_borrows/invalidate_against_protector2.stack.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: not granting access to tag <TAG> because that would remove [SharedReadOnly for <TAG>] which is strongly protected because it is an argument of call ID
1+
error: Undefined Behavior: not granting access to tag <TAG> because that would remove [SharedReadOnly for <TAG>] which is strongly protected
22
--> $DIR/invalidate_against_protector2.rs:LL:CC
33
|
44
LL | unsafe { *x = 0 };
5-
| ^^^^^^ not granting access to tag <TAG> because that would remove [SharedReadOnly for <TAG>] which is strongly protected because it is an argument of call ID
5+
| ^^^^^^ not granting access to tag <TAG> because that would remove [SharedReadOnly for <TAG>] which is strongly protected
66
|
77
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
88
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information

src/tools/miri/tests/fail/both_borrows/invalidate_against_protector3.stack.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: not granting access to tag <TAG> because that would remove [SharedReadOnly for <TAG>] which is strongly protected because it is an argument of call ID
1+
error: Undefined Behavior: not granting access to tag <TAG> because that would remove [SharedReadOnly for <TAG>] which is strongly protected
22
--> $DIR/invalidate_against_protector3.rs:LL:CC
33
|
44
LL | unsafe { *x = 0 };
5-
| ^^^^^^ not granting access to tag <TAG> because that would remove [SharedReadOnly for <TAG>] which is strongly protected because it is an argument of call ID
5+
| ^^^^^^ not granting access to tag <TAG> because that would remove [SharedReadOnly for <TAG>] which is strongly protected
66
|
77
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
88
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information

src/tools/miri/tests/fail/both_borrows/newtype_pair_retagging.stack.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: not granting access to tag <TAG> because that would remove [Unique for <TAG>] which is strongly protected because it is an argument of call ID
1+
error: Undefined Behavior: not granting access to tag <TAG> because that would remove [Unique for <TAG>] which is strongly protected
22
--> RUSTLIB/alloc/src/boxed.rs:LL:CC
33
|
44
LL | Box(unsafe { Unique::new_unchecked(raw) }, alloc)
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not granting access to tag <TAG> because that would remove [Unique for <TAG>] which is strongly protected because it is an argument of call ID
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not granting access to tag <TAG> because that would remove [Unique for <TAG>] which is strongly protected
66
|
77
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
88
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information

src/tools/miri/tests/fail/both_borrows/newtype_retagging.stack.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: not granting access to tag <TAG> because that would remove [Unique for <TAG>] which is strongly protected because it is an argument of call ID
1+
error: Undefined Behavior: not granting access to tag <TAG> because that would remove [Unique for <TAG>] which is strongly protected
22
--> RUSTLIB/alloc/src/boxed.rs:LL:CC
33
|
44
LL | Box(unsafe { Unique::new_unchecked(raw) }, alloc)
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not granting access to tag <TAG> because that would remove [Unique for <TAG>] which is strongly protected because it is an argument of call ID
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not granting access to tag <TAG> because that would remove [Unique for <TAG>] which is strongly protected
66
|
77
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
88
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information

0 commit comments

Comments
 (0)