Skip to content

Commit ad582fd

Browse files
committed
interpret: the MIR is actually at lifetime 'tcx
1 parent 33a1415 commit ad582fd

File tree

5 files changed

+29
-23
lines changed

5 files changed

+29
-23
lines changed

src/borrow_tracker/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
354354

355355
fn on_stack_pop(
356356
&self,
357-
frame: &Frame<'mir, 'tcx, Provenance, FrameExtra<'tcx>>,
357+
frame: &Frame<'tcx, Provenance, FrameExtra<'tcx>>,
358358
) -> InterpResult<'tcx> {
359359
let this = self.eval_context_ref();
360360
let borrow_tracker = this.machine.borrow_tracker.as_ref().unwrap();

src/concurrency/thread.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::time::{Duration, SystemTime};
99
use either::Either;
1010

1111
use rustc_const_eval::CTRL_C_RECEIVED;
12+
use rustc_data_structures::captures::Captures;
1213
use rustc_data_structures::fx::FxHashMap;
1314
use rustc_hir::def_id::DefId;
1415
use rustc_index::{Idx, IndexVec};
@@ -235,7 +236,7 @@ pub struct Thread<'mir, 'tcx> {
235236
thread_name: Option<Vec<u8>>,
236237

237238
/// The virtual call stack.
238-
stack: Vec<Frame<'mir, 'tcx, Provenance, FrameExtra<'tcx>>>,
239+
stack: Vec<Frame<'tcx, Provenance, FrameExtra<'tcx>>>,
239240

240241
/// The function to call when the stack ran empty, to figure out what to do next.
241242
/// Conceptually, this is the interpreter implementation of the things that happen 'after' the
@@ -376,7 +377,7 @@ impl VisitProvenance for Thread<'_, '_> {
376377
}
377378
}
378379

379-
impl VisitProvenance for Frame<'_, '_, Provenance, FrameExtra<'_>> {
380+
impl VisitProvenance for Frame<'_, Provenance, FrameExtra<'_>> {
380381
fn visit_provenance(&self, visit: &mut VisitWith<'_>) {
381382
let Frame {
382383
return_place,
@@ -505,19 +506,18 @@ impl<'mir, 'tcx: 'mir> ThreadManager<'mir, 'tcx> {
505506
}
506507

507508
/// Borrow the stack of the active thread.
508-
pub fn active_thread_stack(&self) -> &[Frame<'mir, 'tcx, Provenance, FrameExtra<'tcx>>] {
509+
pub fn active_thread_stack(&self) -> &[Frame<'tcx, Provenance, FrameExtra<'tcx>>] {
509510
&self.threads[self.active_thread].stack
510511
}
511512

512513
/// Mutably borrow the stack of the active thread.
513-
fn active_thread_stack_mut(
514-
&mut self,
515-
) -> &mut Vec<Frame<'mir, 'tcx, Provenance, FrameExtra<'tcx>>> {
514+
fn active_thread_stack_mut(&mut self) -> &mut Vec<Frame<'tcx, Provenance, FrameExtra<'tcx>>> {
516515
&mut self.threads[self.active_thread].stack
517516
}
518517
pub fn all_stacks(
519518
&self,
520-
) -> impl Iterator<Item = (ThreadId, &[Frame<'mir, 'tcx, Provenance, FrameExtra<'tcx>>])> {
519+
) -> impl Iterator<Item = (ThreadId, &[Frame<'tcx, Provenance, FrameExtra<'tcx>>])> + Captures<'mir>
520+
{
521521
self.threads.iter_enumerated().map(|(id, t)| (id, &t.stack[..]))
522522
}
523523

@@ -1099,15 +1099,21 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
10991099
}
11001100

11011101
#[inline]
1102-
fn active_thread_stack(&self) -> &[Frame<'mir, 'tcx, Provenance, FrameExtra<'tcx>>] {
1102+
fn active_thread_stack<'a>(&'a self) -> &'a [Frame<'tcx, Provenance, FrameExtra<'tcx>>]
1103+
where
1104+
'mir: 'a,
1105+
{
11031106
let this = self.eval_context_ref();
11041107
this.machine.threads.active_thread_stack()
11051108
}
11061109

11071110
#[inline]
1108-
fn active_thread_stack_mut(
1109-
&mut self,
1110-
) -> &mut Vec<Frame<'mir, 'tcx, Provenance, FrameExtra<'tcx>>> {
1111+
fn active_thread_stack_mut<'a>(
1112+
&'a mut self,
1113+
) -> &'a mut Vec<Frame<'tcx, Provenance, FrameExtra<'tcx>>>
1114+
where
1115+
'mir: 'a,
1116+
{
11111117
let this = self.eval_context_mut();
11121118
this.machine.threads.active_thread_stack_mut()
11131119
}

src/helpers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,7 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
13211321
self.stack()[frame_idx].current_span()
13221322
}
13231323

1324-
fn stack(&self) -> &[Frame<'mir, 'tcx, Provenance, machine::FrameExtra<'tcx>>] {
1324+
fn stack(&self) -> &[Frame<'tcx, Provenance, machine::FrameExtra<'tcx>>] {
13251325
self.threads.active_thread_stack()
13261326
}
13271327

@@ -1330,7 +1330,7 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
13301330
}
13311331

13321332
/// This is the source of truth for the `is_user_relevant` flag in our `FrameExtra`.
1333-
pub fn is_user_relevant(&self, frame: &Frame<'mir, 'tcx, Provenance>) -> bool {
1333+
pub fn is_user_relevant(&self, frame: &Frame<'tcx, Provenance>) -> bool {
13341334
let def_id = frame.instance.def_id();
13351335
(def_id.is_local() || self.local_crates.contains(&def_id.krate))
13361336
&& !frame.instance.def.requires_caller_location(self.tcx)

src/machine.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
949949
dest: &MPlaceTy<'tcx, Provenance>,
950950
ret: Option<mir::BasicBlock>,
951951
unwind: mir::UnwindAction,
952-
) -> InterpResult<'tcx, Option<(&'mir mir::Body<'tcx>, ty::Instance<'tcx>)>> {
952+
) -> InterpResult<'tcx, Option<(&'tcx mir::Body<'tcx>, ty::Instance<'tcx>)>> {
953953
// For foreign items, try to see if we can emulate them.
954954
if ecx.tcx.is_foreign_item(instance.def_id()) {
955955
// An external function call that does not have a MIR body. We either find MIR elsewhere
@@ -1359,8 +1359,8 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
13591359
#[inline(always)]
13601360
fn init_frame_extra(
13611361
ecx: &mut InterpCx<'mir, 'tcx, Self>,
1362-
frame: Frame<'mir, 'tcx, Provenance>,
1363-
) -> InterpResult<'tcx, Frame<'mir, 'tcx, Provenance, FrameExtra<'tcx>>> {
1362+
frame: Frame<'tcx, Provenance>,
1363+
) -> InterpResult<'tcx, Frame<'tcx, Provenance, FrameExtra<'tcx>>> {
13641364
// Start recording our event before doing anything else
13651365
let timing = if let Some(profiler) = ecx.machine.profiler.as_ref() {
13661366
let fn_name = frame.instance.to_string();
@@ -1391,13 +1391,13 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
13911391

13921392
fn stack<'a>(
13931393
ecx: &'a InterpCx<'mir, 'tcx, Self>,
1394-
) -> &'a [Frame<'mir, 'tcx, Self::Provenance, Self::FrameExtra>] {
1394+
) -> &'a [Frame<'tcx, Self::Provenance, Self::FrameExtra>] {
13951395
ecx.active_thread_stack()
13961396
}
13971397

13981398
fn stack_mut<'a>(
13991399
ecx: &'a mut InterpCx<'mir, 'tcx, Self>,
1400-
) -> &'a mut Vec<Frame<'mir, 'tcx, Self::Provenance, Self::FrameExtra>> {
1400+
) -> &'a mut Vec<Frame<'tcx, Self::Provenance, Self::FrameExtra>> {
14011401
ecx.active_thread_stack_mut()
14021402
}
14031403

@@ -1444,7 +1444,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
14441444

14451445
fn before_stack_pop(
14461446
ecx: &InterpCx<'mir, 'tcx, Self>,
1447-
frame: &Frame<'mir, 'tcx, Self::Provenance, Self::FrameExtra>,
1447+
frame: &Frame<'tcx, Self::Provenance, Self::FrameExtra>,
14481448
) -> InterpResult<'tcx> {
14491449
// We want this *before* the return value copy, because the return place itself is protected
14501450
// until we do `end_call` here.
@@ -1461,7 +1461,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
14611461
#[inline(always)]
14621462
fn after_stack_pop(
14631463
ecx: &mut InterpCx<'mir, 'tcx, Self>,
1464-
frame: Frame<'mir, 'tcx, Provenance, FrameExtra<'tcx>>,
1464+
frame: Frame<'tcx, Provenance, FrameExtra<'tcx>>,
14651465
unwinding: bool,
14661466
) -> InterpResult<'tcx, StackPopJump> {
14671467
if frame.extra.is_user_relevant {

src/shims/foreign_items.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
4444
dest: &MPlaceTy<'tcx, Provenance>,
4545
ret: Option<mir::BasicBlock>,
4646
unwind: mir::UnwindAction,
47-
) -> InterpResult<'tcx, Option<(&'mir mir::Body<'tcx>, ty::Instance<'tcx>)>> {
47+
) -> InterpResult<'tcx, Option<(&'tcx mir::Body<'tcx>, ty::Instance<'tcx>)>> {
4848
let this = self.eval_context_mut();
4949
let tcx = this.tcx.tcx;
5050

@@ -137,7 +137,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
137137
fn lookup_exported_symbol(
138138
&mut self,
139139
link_name: Symbol,
140-
) -> InterpResult<'tcx, Option<(&'mir mir::Body<'tcx>, ty::Instance<'tcx>)>> {
140+
) -> InterpResult<'tcx, Option<(&'tcx mir::Body<'tcx>, ty::Instance<'tcx>)>> {
141141
let this = self.eval_context_mut();
142142
let tcx = this.tcx.tcx;
143143

0 commit comments

Comments
 (0)