Skip to content

Commit c92ad33

Browse files
committed
Factor the Stacked Borrows FrameExtra fields
1 parent fc1a539 commit c92ad33

File tree

3 files changed

+33
-20
lines changed

3 files changed

+33
-20
lines changed

src/machine.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub const NUM_CPUS: u64 = 1;
4444
/// Extra data stored with each stack frame
4545
pub struct FrameData<'tcx> {
4646
/// Extra data for Stacked Borrows.
47-
pub call_id: stacked_borrows::CallId,
47+
pub stacked_borrows: stacked_borrows::FrameExtra,
4848

4949
/// If this is Some(), then this is a special "catch unwind" frame (the frame of `try_fn`
5050
/// called by `try`). When this frame is popped during unwinding a panic,
@@ -55,26 +55,15 @@ pub struct FrameData<'tcx> {
5555
/// for the start of this frame. When we finish executing this frame,
5656
/// we use this to register a completed event with `measureme`.
5757
pub timing: Option<measureme::DetachedTiming>,
58-
59-
/// If this frame is protecting any tags, they are listed here. We use this list to do
60-
/// incremental updates of the global list of protected tags stored in the
61-
/// `stacked_borrows::GlobalState` upon function return, and if we attempt to pop a protected
62-
/// tag, to identify which call is responsible for protecting the tag.
63-
/// See `Stack::item_popped` for more explanation.
64-
///
65-
/// This will contain one tag per reference passed to the function, so
66-
/// a size of 2 is enough for the vast majority of functions.
67-
pub protected_tags: SmallVec<[SbTag; 2]>,
6858
}
6959

7060
impl<'tcx> std::fmt::Debug for FrameData<'tcx> {
7161
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
7262
// Omitting `timing`, it does not support `Debug`.
73-
let FrameData { call_id, catch_unwind, timing: _, protected_tags } = self;
63+
let FrameData { stacked_borrows, catch_unwind, timing: _ } = self;
7464
f.debug_struct("FrameData")
75-
.field("call_id", call_id)
65+
.field("stacked_borrows", stacked_borrows)
7666
.field("catch_unwind", catch_unwind)
77-
.field("protected_tags", protected_tags)
7867
.finish()
7968
}
8069
}
@@ -907,8 +896,14 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
907896
stacked_borrows.borrow_mut().new_call()
908897
});
909898

910-
let extra =
911-
FrameData { call_id, catch_unwind: None, timing, protected_tags: SmallVec::new() };
899+
let extra = FrameData {
900+
stacked_borrows: stacked_borrows::FrameExtra {
901+
call_id,
902+
protected_tags: SmallVec::new(),
903+
},
904+
catch_unwind: None,
905+
timing,
906+
};
912907
Ok(frame.with_extra(extra))
913908
}
914909

src/stacked_borrows.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rustc_middle::ty::{
1616
};
1717
use rustc_span::DUMMY_SP;
1818
use rustc_target::abi::Size;
19+
use smallvec::SmallVec;
1920
use std::collections::HashSet;
2021

2122
use crate::*;
@@ -80,6 +81,22 @@ impl SbTagExtra {
8081
}
8182
}
8283

84+
#[derive(Debug)]
85+
pub struct FrameExtra {
86+
/// The ID of the call this frame corresponds to.
87+
pub call_id: CallId,
88+
89+
/// If this frame is protecting any tags, they are listed here. We use this list to do
90+
/// incremental updates of the global list of protected tags stored in the
91+
/// `stacked_borrows::GlobalState` upon function return, and if we attempt to pop a protected
92+
/// tag, to identify which call is responsible for protecting the tag.
93+
/// See `Stack::item_popped` for more explanation.
94+
///
95+
/// This will contain one tag per reference passed to the function, so
96+
/// a size of 2 is enough for the vast majority of functions.
97+
pub protected_tags: SmallVec<[SbTag; 2]>,
98+
}
99+
83100
/// Extra per-allocation state.
84101
#[derive(Clone, Debug)]
85102
pub struct Stacks {
@@ -196,7 +213,7 @@ impl GlobalStateInner {
196213
}
197214

198215
pub fn end_call(&mut self, frame: &machine::FrameData<'_>) {
199-
for tag in &frame.protected_tags {
216+
for tag in &frame.stacked_borrows.protected_tags {
200217
self.protected_tags.remove(tag);
201218
}
202219
}
@@ -325,8 +342,8 @@ impl<'tcx> Stack {
325342
let call_id = threads
326343
.all_stacks()
327344
.flatten()
328-
.find(|t| t.extra.protected_tags.contains(&item.tag()))
329-
.map(|frame| frame.extra.call_id)
345+
.find(|t| t.extra.stacked_borrows.protected_tags.contains(&item.tag()))
346+
.map(|frame| frame.extra.stacked_borrows.call_id)
330347
.unwrap(); // FIXME: Surely we should find something, but a panic seems wrong here?
331348
if let Some((tag, _alloc_range, _offset, _access)) = provoking_access {
332349
Err(err_sb_ub(
@@ -818,7 +835,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
818835
);
819836

820837
if protect {
821-
this.frame_mut().extra.protected_tags.push(new_tag);
838+
this.frame_mut().extra.stacked_borrows.protected_tags.push(new_tag);
822839
this.machine.stacked_borrows.as_mut().unwrap().get_mut().protected_tags.insert(new_tag);
823840
}
824841
// FIXME: can't hold the current span handle across the borrows of self above

src/stacked_borrows/stack.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ impl<'tcx> Stack {
304304
log::trace!("access: disabling item {:?}", item);
305305
visitor(*item)?;
306306
item.set_permission(Permission::Disabled);
307+
// Also update all copies of this item in the cache.
307308
for it in &mut self.cache.items {
308309
if it.tag() == item.tag() {
309310
it.set_permission(Permission::Disabled);

0 commit comments

Comments
 (0)