Skip to content

Commit 570f5d6

Browse files
committed
cleanup
1 parent 1192d2c commit 570f5d6

File tree

5 files changed

+17
-21
lines changed

5 files changed

+17
-21
lines changed

src/borrow_tracker/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,20 +274,20 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
274274
&mut self,
275275
kind: RetagKind,
276276
place: &PlaceTy<'tcx, Provenance>,
277-
borrow_tracker_method: BorrowTrackerMethod,
278277
) -> InterpResult<'tcx> {
279278
let this = self.eval_context_mut();
280-
match borrow_tracker_method {
279+
let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().method();
280+
match method {
281281
BorrowTrackerMethod::StackedBorrows => this.sb_retag(kind, place),
282282
}
283283
}
284284

285285
fn retag_return_place(
286286
&mut self,
287-
borrow_tracker_method: BorrowTrackerMethod,
288287
) -> InterpResult<'tcx> {
289288
let this = self.eval_context_mut();
290-
match borrow_tracker_method {
289+
let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().method();
290+
match method {
291291
BorrowTrackerMethod::StackedBorrows => this.sb_retag_return_place(),
292292
}
293293
}
@@ -296,10 +296,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
296296
&mut self,
297297
alloc_id: AllocId,
298298
tag: BorTag,
299-
borrow_tracker_method: BorrowTrackerMethod,
300299
) -> InterpResult<'tcx> {
301300
let this = self.eval_context_mut();
302-
match borrow_tracker_method {
301+
let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().method();
302+
match method {
303303
BorrowTrackerMethod::StackedBorrows => this.sb_expose_tag(alloc_id, tag),
304304
}
305305
}

src/borrow_tracker/stacked_borrows/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,11 +566,12 @@ trait EvalContextPrivExt<'mir: 'ecx, 'tcx: 'mir, 'ecx>: crate::MiriInterpCxExt<'
566566
// if converting this alloc_id from a global to a local one
567567
// uncovers a non-supported `extern static`.
568568
let extra = this.get_alloc_extra(alloc_id)?;
569-
let sb = extra
569+
let mut stacked_borrows = extra
570570
.borrow_tracker
571571
.as_ref()
572572
.expect("We should have borrow tracking data")
573-
.assert_sb();
573+
.assert_sb()
574+
.borrow_mut();
574575
// Note that we create a *second* `DiagnosticCxBuilder` below for the actual retag.
575576
// FIXME: can this be done cleaner?
576577
let dcx = DiagnosticCxBuilder::retag(
@@ -580,7 +581,6 @@ trait EvalContextPrivExt<'mir: 'ecx, 'tcx: 'mir, 'ecx>: crate::MiriInterpCxExt<'
580581
orig_tag,
581582
alloc_range(base_offset, size),
582583
);
583-
let mut stacked_borrows = sb.borrow_mut();
584584
let mut dcx = dcx.build(&mut stacked_borrows.history, base_offset);
585585
dcx.log_creation();
586586
if protect.is_some() {

src/intptrcast.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,8 @@ impl<'mir, 'tcx> GlobalStateInner {
112112
if global_state.provenance_mode != ProvenanceMode::Strict {
113113
trace!("Exposing allocation id {alloc_id:?}");
114114
global_state.exposed.insert(alloc_id);
115-
if let Some(borrow_tracker) = &ecx.machine.borrow_tracker {
116-
let method = borrow_tracker.borrow().method();
117-
ecx.expose_tag(alloc_id, tag, method)?;
115+
if ecx.machine.borrow_tracker.is_some() {
116+
ecx.expose_tag(alloc_id, tag)?;
118117
}
119118
}
120119
Ok(())

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub use crate::shims::tls::TlsData;
8585
pub use crate::shims::EvalContextExt as _;
8686

8787
pub use crate::borrow_tracker::stacked_borrows::{
88-
EvalContextExt as StackedBorEvalContextExt, Item, Permission, Stack, Stacks,
88+
EvalContextExt as _, Item, Permission, Stack, Stacks,
8989
};
9090
pub use crate::borrow_tracker::{
9191
BorTag, BorrowTrackerMethod, CallId, EvalContextExt as _, RetagFields,

src/machine.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,7 @@ impl ProvenanceExtra {
254254
/// Extra per-allocation data
255255
#[derive(Debug, Clone)]
256256
pub struct AllocExtra {
257-
/// Stacked Borrows state. Although it is always added,
258-
/// one of the implementations does nothing
257+
/// Global state of the borrow tracker, if enabled.
259258
pub borrow_tracker: Option<borrow_tracker::AllocExtra>,
260259
/// Data race detection via the use of a vector-clock,
261260
/// this is only added if it is enabled.
@@ -1061,9 +1060,8 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
10611060
kind: mir::RetagKind,
10621061
place: &PlaceTy<'tcx, Provenance>,
10631062
) -> InterpResult<'tcx> {
1064-
if let Some(borrow_tracker) = &ecx.machine.borrow_tracker {
1065-
let method = borrow_tracker.borrow().method();
1066-
ecx.retag(kind, place, method)?;
1063+
if ecx.machine.borrow_tracker.is_some() {
1064+
ecx.retag(kind, place)?;
10671065
}
10681066
Ok(())
10691067
}
@@ -1150,9 +1148,8 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
11501148
let stack_len = ecx.active_thread_stack().len();
11511149
ecx.active_thread_mut().set_top_user_relevant_frame(stack_len - 1);
11521150
}
1153-
if let Some(borrow_tracker) = &ecx.machine.borrow_tracker {
1154-
let method = borrow_tracker.borrow().method();
1155-
ecx.retag_return_place(method)?;
1151+
if ecx.machine.borrow_tracker.is_some() {
1152+
ecx.retag_return_place()?;
11561153
}
11571154
Ok(())
11581155
}

0 commit comments

Comments
 (0)