Skip to content

Commit f86ba13

Browse files
committed
adapt signatures to take &self and use interior mutability, expose provenances
1 parent 5c27b83 commit f86ba13

File tree

9 files changed

+14
-15
lines changed

9 files changed

+14
-15
lines changed

compiler/rustc_const_eval/src/const_eval/dummy_machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl<'tcx> interpret::Machine<'tcx> for DummyMachine {
169169
}
170170

171171
fn expose_provenance(
172-
_ecx: &mut InterpCx<'tcx, Self>,
172+
_ecx: &InterpCx<'tcx, Self>,
173173
_provenance: Self::Provenance,
174174
) -> interpret::InterpResult<'tcx> {
175175
unimplemented!()

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
586586

587587
#[inline(always)]
588588
fn expose_provenance(
589-
_ecx: &mut InterpCx<'tcx, Self>,
589+
_ecx: &InterpCx<'tcx, Self>,
590590
_provenance: Self::Provenance,
591591
) -> InterpResult<'tcx> {
592592
// This is only reachable with -Zunleash-the-miri-inside-of-you.

compiler/rustc_const_eval/src/interpret/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ pub trait Machine<'tcx>: Sized {
330330
/// Marks a pointer as exposed, allowing it's provenance
331331
/// to be recovered. "Pointer-to-int cast"
332332
fn expose_provenance(
333-
ecx: &mut InterpCx<'tcx, Self>,
333+
ecx: &InterpCx<'tcx, Self>,
334334
provenance: Self::Provenance,
335335
) -> InterpResult<'tcx>;
336336

compiler/rustc_const_eval/src/interpret/memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
968968

969969
let alloc = self.get_alloc_raw(id)?;
970970
for prov in alloc.provenance().provenances() {
971-
//M::expose_provenance(self, prov)?; // TODO: mutable borrow here gives issues due to provenances iterator lifetime...
971+
M::expose_provenance(self, prov)?;
972972
if let Some(id) = prov.get_alloc_id() {
973973
todo.push(id);
974974
}

src/tools/miri/src/alloc_addresses/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,9 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
286286

287287
impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {}
288288
pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
289-
fn expose_ptr(&mut self, alloc_id: AllocId, tag: BorTag) -> InterpResult<'tcx> {
290-
let this = self.eval_context_mut();
291-
let global_state = this.machine.alloc_addresses.get_mut();
289+
fn expose_ptr(&self, alloc_id: AllocId, tag: BorTag) -> InterpResult<'tcx> {
290+
let this = self.eval_context_ref();
291+
let mut global_state = this.machine.alloc_addresses.borrow_mut();
292292
// In strict mode, we don't need this, so we can save some cycles by not tracking it.
293293
if global_state.provenance_mode == ProvenanceMode::Strict {
294294
return interp_ok(());
@@ -299,7 +299,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
299299
return interp_ok(());
300300
}
301301
trace!("Exposing allocation id {alloc_id:?}");
302-
let global_state = this.machine.alloc_addresses.get_mut();
303302
global_state.exposed.insert(alloc_id);
304303
if this.machine.borrow_tracker.is_some() {
305304
this.expose_tag(alloc_id, tag)?;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
302302
}
303303
}
304304

305-
fn expose_tag(&mut self, alloc_id: AllocId, tag: BorTag) -> InterpResult<'tcx> {
306-
let this = self.eval_context_mut();
305+
fn expose_tag(&self, alloc_id: AllocId, tag: BorTag) -> InterpResult<'tcx> {
306+
let this = self.eval_context_ref();
307307
let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().borrow_tracker_method;
308308
match method {
309309
BorrowTrackerMethod::StackedBorrows => this.sb_expose_tag(alloc_id, tag),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,8 +1011,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
10111011
}
10121012

10131013
/// Mark the given tag as exposed. It was found on a pointer with the given AllocId.
1014-
fn sb_expose_tag(&mut self, alloc_id: AllocId, tag: BorTag) -> InterpResult<'tcx> {
1015-
let this = self.eval_context_mut();
1014+
fn sb_expose_tag(&self, alloc_id: AllocId, tag: BorTag) -> InterpResult<'tcx> {
1015+
let this = self.eval_context_ref();
10161016

10171017
// Function pointers and dead objects don't have an alloc_extra so we ignore them.
10181018
// This is okay because accessing them is UB anyway, no need for any Stacked Borrows checks.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
532532
}
533533

534534
/// Mark the given tag as exposed. It was found on a pointer with the given AllocId.
535-
fn tb_expose_tag(&mut self, alloc_id: AllocId, tag: BorTag) -> InterpResult<'tcx> {
536-
let this = self.eval_context_mut();
535+
fn tb_expose_tag(&self, alloc_id: AllocId, tag: BorTag) -> InterpResult<'tcx> {
536+
let this = self.eval_context_ref();
537537

538538
// Function pointers and dead objects don't have an alloc_extra so we ignore them.
539539
// This is okay because accessing them is UB anyway, no need for any Tree Borrows checks.

src/tools/miri/src/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
12441244
/// Called on `ptr as usize` casts.
12451245
/// (Actually computing the resulting `usize` doesn't need machine help,
12461246
/// that's just `Scalar::try_to_int`.)
1247-
fn expose_provenance(ecx: &mut InterpCx<'tcx, Self>, provenance: Self::Provenance) -> InterpResult<'tcx> {
1247+
fn expose_provenance(ecx: &InterpCx<'tcx, Self>, provenance: Self::Provenance) -> InterpResult<'tcx> {
12481248
match provenance {
12491249
Provenance::Concrete { alloc_id, tag } => ecx.expose_ptr(alloc_id, tag),
12501250
Provenance::Wildcard => {

0 commit comments

Comments
 (0)