Skip to content

Commit 36d36a3

Browse files
committed
interpret: the MIR is actually at lifetime 'tcx
1 parent cdc509f commit 36d36a3

File tree

13 files changed

+75
-74
lines changed

13 files changed

+75
-74
lines changed

compiler/rustc_const_eval/src/const_eval/dummy_machine.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl<'mir, 'tcx: 'mir> interpret::Machine<'mir, 'tcx> for DummyMachine {
9090
_destination: &interpret::MPlaceTy<'tcx, Self::Provenance>,
9191
_target: Option<BasicBlock>,
9292
_unwind: UnwindAction,
93-
) -> interpret::InterpResult<'tcx, Option<(&'mir Body<'tcx>, ty::Instance<'tcx>)>> {
93+
) -> interpret::InterpResult<'tcx, Option<(&'tcx Body<'tcx>, ty::Instance<'tcx>)>> {
9494
unimplemented!()
9595
}
9696

@@ -176,24 +176,24 @@ impl<'mir, 'tcx: 'mir> interpret::Machine<'mir, 'tcx> for DummyMachine {
176176

177177
fn init_frame_extra(
178178
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
179-
_frame: interpret::Frame<'mir, 'tcx, Self::Provenance>,
179+
_frame: interpret::Frame<'tcx, Self::Provenance>,
180180
) -> interpret::InterpResult<
181181
'tcx,
182-
interpret::Frame<'mir, 'tcx, Self::Provenance, Self::FrameExtra>,
182+
interpret::Frame<'tcx, Self::Provenance, Self::FrameExtra>,
183183
> {
184184
unimplemented!()
185185
}
186186

187187
fn stack<'a>(
188188
_ecx: &'a InterpCx<'mir, 'tcx, Self>,
189-
) -> &'a [interpret::Frame<'mir, 'tcx, Self::Provenance, Self::FrameExtra>] {
189+
) -> &'a [interpret::Frame<'tcx, Self::Provenance, Self::FrameExtra>] {
190190
// Return an empty stack instead of panicking, as `cur_span` uses it to evaluate constants.
191191
&[]
192192
}
193193

194194
fn stack_mut<'a>(
195195
_ecx: &'a mut InterpCx<'mir, 'tcx, Self>,
196-
) -> &'a mut Vec<interpret::Frame<'mir, 'tcx, Self::Provenance, Self::FrameExtra>> {
196+
) -> &'a mut Vec<interpret::Frame<'tcx, Self::Provenance, Self::FrameExtra>> {
197197
unimplemented!()
198198
}
199199
}

compiler/rustc_const_eval/src/const_eval/error.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,10 @@ impl<'tcx> Into<InterpErrorInfo<'tcx>> for ConstEvalErrKind {
5858
}
5959
}
6060

61-
pub fn get_span_and_frames<'tcx, 'mir>(
61+
pub fn get_span_and_frames<'tcx>(
6262
tcx: TyCtxtAt<'tcx>,
63-
stack: &[Frame<'mir, 'tcx, impl Provenance, impl Sized>],
64-
) -> (Span, Vec<errors::FrameNote>)
65-
where
66-
'tcx: 'mir,
67-
{
63+
stack: &[Frame<'tcx, impl Provenance, impl Sized>],
64+
) -> (Span, Vec<errors::FrameNote>) {
6865
let mut stacktrace = Frame::generate_stacktrace_from_stack(stack);
6966
// Filter out `requires_caller_location` frames.
7067
stacktrace.retain(|frame| !frame.instance.def.requires_caller_location(*tcx));
@@ -161,9 +158,9 @@ where
161158

162159
/// Emit a lint from a const-eval situation.
163160
// Even if this is unused, please don't remove it -- chances are we will need to emit a lint during const-eval again in the future!
164-
pub(super) fn lint<'tcx, 'mir, L>(
161+
pub(super) fn lint<'tcx, L>(
165162
tcx: TyCtxtAt<'tcx>,
166-
machine: &CompileTimeInterpreter<'mir, 'tcx>,
163+
machine: &CompileTimeInterpreter<'tcx>,
167164
lint: &'static rustc_session::lint::Lint,
168165
decorator: impl FnOnce(Vec<errors::FrameNote>) -> L,
169166
) where

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::CTRL_C_RECEIVED;
3434
fn eval_body_using_ecx<'mir, 'tcx, R: InterpretationResult<'tcx>>(
3535
ecx: &mut CompileTimeEvalContext<'mir, 'tcx>,
3636
cid: GlobalId<'tcx>,
37-
body: &'mir mir::Body<'tcx>,
37+
body: &'tcx mir::Body<'tcx>,
3838
) -> InterpResult<'tcx, R> {
3939
trace!(?ecx.param_env);
4040
let tcx = *ecx.tcx;
@@ -328,14 +328,14 @@ pub trait InterpretationResult<'tcx> {
328328
/// evaluation query.
329329
fn make_result<'mir>(
330330
mplace: MPlaceTy<'tcx>,
331-
ecx: &mut InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
331+
ecx: &mut InterpCx<'mir, 'tcx, CompileTimeInterpreter<'tcx>>,
332332
) -> Self;
333333
}
334334

335335
impl<'tcx> InterpretationResult<'tcx> for ConstAlloc<'tcx> {
336336
fn make_result<'mir>(
337337
mplace: MPlaceTy<'tcx>,
338-
_ecx: &mut InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
338+
_ecx: &mut InterpCx<'mir, 'tcx, CompileTimeInterpreter<'tcx>>,
339339
) -> Self {
340340
ConstAlloc { alloc_id: mplace.ptr().provenance.unwrap().alloc_id(), ty: mplace.layout.ty }
341341
}
@@ -417,7 +417,7 @@ fn eval_in_interpreter<'tcx, R: InterpretationResult<'tcx>>(
417417

418418
#[inline(always)]
419419
fn const_validate_mplace<'mir, 'tcx>(
420-
ecx: &InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
420+
ecx: &InterpCx<'mir, 'tcx, CompileTimeInterpreter<'tcx>>,
421421
mplace: &MPlaceTy<'tcx>,
422422
cid: GlobalId<'tcx>,
423423
) -> Result<(), ErrorHandled> {
@@ -447,7 +447,7 @@ fn const_validate_mplace<'mir, 'tcx>(
447447

448448
#[inline(always)]
449449
fn report_validation_error<'mir, 'tcx>(
450-
ecx: &InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
450+
ecx: &InterpCx<'mir, 'tcx, CompileTimeInterpreter<'tcx>>,
451451
error: InterpErrorInfo<'tcx>,
452452
alloc_id: AllocId,
453453
) -> ErrorHandled {

compiler/rustc_const_eval/src/const_eval/machine.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ const TINY_LINT_TERMINATOR_LIMIT: usize = 20;
4545
const PROGRESS_INDICATOR_START: usize = 4_000_000;
4646

4747
/// Extra machine state for CTFE, and the Machine instance
48-
pub struct CompileTimeInterpreter<'mir, 'tcx> {
48+
pub struct CompileTimeInterpreter<'tcx> {
4949
/// The number of terminators that have been evaluated.
5050
///
5151
/// This is used to produce lints informing the user that the compiler is not stuck.
5252
/// Set to `usize::MAX` to never report anything.
5353
pub(super) num_evaluated_steps: usize,
5454

5555
/// The virtual call stack.
56-
pub(super) stack: Vec<Frame<'mir, 'tcx>>,
56+
pub(super) stack: Vec<Frame<'tcx>>,
5757

5858
/// Pattern matching on consts with references would be unsound if those references
5959
/// could point to anything mutable. Therefore, when evaluating consts and when constructing valtrees,
@@ -90,7 +90,7 @@ impl From<bool> for CanAccessMutGlobal {
9090
}
9191
}
9292

93-
impl<'mir, 'tcx> CompileTimeInterpreter<'mir, 'tcx> {
93+
impl<'tcx> CompileTimeInterpreter<'tcx> {
9494
pub(crate) fn new(
9595
can_access_mut_global: CanAccessMutGlobal,
9696
check_alignment: CheckAlignment,
@@ -165,7 +165,7 @@ impl<K: Hash + Eq, V> interpret::AllocMap<K, V> for FxIndexMap<K, V> {
165165
}
166166

167167
pub(crate) type CompileTimeEvalContext<'mir, 'tcx> =
168-
InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>;
168+
InterpCx<'mir, 'tcx, CompileTimeInterpreter<'tcx>>;
169169

170170
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
171171
pub enum MemoryKind {
@@ -371,7 +371,7 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> {
371371
}
372372
}
373373

374-
impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, 'tcx> {
374+
impl<'mir, 'tcx: 'mir> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'tcx> {
375375
compile_time_machine!(<'mir, 'tcx>);
376376

377377
type MemoryKind = MemoryKind;
@@ -417,7 +417,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
417417
dest: &MPlaceTy<'tcx>,
418418
ret: Option<mir::BasicBlock>,
419419
_unwind: mir::UnwindAction, // unwinding is not supported in consts
420-
) -> InterpResult<'tcx, Option<(&'mir mir::Body<'tcx>, ty::Instance<'tcx>)>> {
420+
) -> InterpResult<'tcx, Option<(&'tcx mir::Body<'tcx>, ty::Instance<'tcx>)>> {
421421
debug!("find_mir_or_eval_fn: {:?}", orig_instance);
422422

423423
// Replace some functions.
@@ -658,8 +658,8 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
658658
#[inline(always)]
659659
fn init_frame_extra(
660660
ecx: &mut InterpCx<'mir, 'tcx, Self>,
661-
frame: Frame<'mir, 'tcx>,
662-
) -> InterpResult<'tcx, Frame<'mir, 'tcx>> {
661+
frame: Frame<'tcx>,
662+
) -> InterpResult<'tcx, Frame<'tcx>> {
663663
// Enforce stack size limit. Add 1 because this is run before the new frame is pushed.
664664
if !ecx.recursion_limit.value_within_limit(ecx.stack().len() + 1) {
665665
throw_exhaust!(StackFrameLimitReached)
@@ -671,14 +671,14 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
671671
#[inline(always)]
672672
fn stack<'a>(
673673
ecx: &'a InterpCx<'mir, 'tcx, Self>,
674-
) -> &'a [Frame<'mir, 'tcx, Self::Provenance, Self::FrameExtra>] {
674+
) -> &'a [Frame<'tcx, Self::Provenance, Self::FrameExtra>] {
675675
&ecx.machine.stack
676676
}
677677

678678
#[inline(always)]
679679
fn stack_mut<'a>(
680680
ecx: &'a mut InterpCx<'mir, 'tcx, Self>,
681-
) -> &'a mut Vec<Frame<'mir, 'tcx, Self::Provenance, Self::FrameExtra>> {
681+
) -> &'a mut Vec<Frame<'tcx, Self::Provenance, Self::FrameExtra>> {
682682
&mut ecx.machine.stack
683683
}
684684

compiler/rustc_const_eval/src/interpret/eval_context.rs

+12-14
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ impl Drop for SpanGuard {
9090
}
9191

9292
/// A stack frame.
93-
pub struct Frame<'mir, 'tcx, Prov: Provenance = CtfeProvenance, Extra = ()> {
93+
pub struct Frame<'tcx, Prov: Provenance = CtfeProvenance, Extra = ()> {
9494
////////////////////////////////////////////////////////////////////////////////
9595
// Function and callsite information
9696
////////////////////////////////////////////////////////////////////////////////
9797
/// The MIR for the function called on this frame.
98-
pub body: &'mir mir::Body<'tcx>,
98+
pub body: &'tcx mir::Body<'tcx>,
9999

100100
/// The def_id and args of the current function.
101101
pub instance: ty::Instance<'tcx>,
@@ -232,8 +232,8 @@ impl<'tcx, Prov: Provenance> LocalState<'tcx, Prov> {
232232
}
233233
}
234234

235-
impl<'mir, 'tcx, Prov: Provenance> Frame<'mir, 'tcx, Prov> {
236-
pub fn with_extra<Extra>(self, extra: Extra) -> Frame<'mir, 'tcx, Prov, Extra> {
235+
impl<'tcx, Prov: Provenance> Frame<'tcx, Prov> {
236+
pub fn with_extra<Extra>(self, extra: Extra) -> Frame<'tcx, Prov, Extra> {
237237
Frame {
238238
body: self.body,
239239
instance: self.instance,
@@ -247,7 +247,7 @@ impl<'mir, 'tcx, Prov: Provenance> Frame<'mir, 'tcx, Prov> {
247247
}
248248
}
249249

250-
impl<'mir, 'tcx, Prov: Provenance, Extra> Frame<'mir, 'tcx, Prov, Extra> {
250+
impl<'tcx, Prov: Provenance, Extra> Frame<'tcx, Prov, Extra> {
251251
/// Get the current location within the Frame.
252252
///
253253
/// If this is `Left`, we are not currently executing any particular statement in
@@ -517,14 +517,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
517517
}
518518

519519
#[inline(always)]
520-
pub(crate) fn stack(&self) -> &[Frame<'mir, 'tcx, M::Provenance, M::FrameExtra>] {
520+
pub(crate) fn stack(&self) -> &[Frame<'tcx, M::Provenance, M::FrameExtra>] {
521521
M::stack(self)
522522
}
523523

524524
#[inline(always)]
525-
pub(crate) fn stack_mut(
526-
&mut self,
527-
) -> &mut Vec<Frame<'mir, 'tcx, M::Provenance, M::FrameExtra>> {
525+
pub(crate) fn stack_mut(&mut self) -> &mut Vec<Frame<'tcx, M::Provenance, M::FrameExtra>> {
528526
M::stack_mut(self)
529527
}
530528

@@ -536,12 +534,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
536534
}
537535

538536
#[inline(always)]
539-
pub fn frame(&self) -> &Frame<'mir, 'tcx, M::Provenance, M::FrameExtra> {
537+
pub fn frame(&self) -> &Frame<'tcx, M::Provenance, M::FrameExtra> {
540538
self.stack().last().expect("no call frames exist")
541539
}
542540

543541
#[inline(always)]
544-
pub fn frame_mut(&mut self) -> &mut Frame<'mir, 'tcx, M::Provenance, M::FrameExtra> {
542+
pub fn frame_mut(&mut self) -> &mut Frame<'tcx, M::Provenance, M::FrameExtra> {
545543
self.stack_mut().last_mut().expect("no call frames exist")
546544
}
547545

@@ -602,7 +600,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
602600
T: TypeFoldable<TyCtxt<'tcx>>,
603601
>(
604602
&self,
605-
frame: &Frame<'mir, 'tcx, M::Provenance, M::FrameExtra>,
603+
frame: &Frame<'tcx, M::Provenance, M::FrameExtra>,
606604
value: T,
607605
) -> Result<T, ErrorHandled> {
608606
frame
@@ -680,7 +678,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
680678
#[inline(always)]
681679
pub(super) fn layout_of_local(
682680
&self,
683-
frame: &Frame<'mir, 'tcx, M::Provenance, M::FrameExtra>,
681+
frame: &Frame<'tcx, M::Provenance, M::FrameExtra>,
684682
local: mir::Local,
685683
layout: Option<TyAndLayout<'tcx>>,
686684
) -> InterpResult<'tcx, TyAndLayout<'tcx>> {
@@ -803,7 +801,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
803801
pub fn push_stack_frame(
804802
&mut self,
805803
instance: ty::Instance<'tcx>,
806-
body: &'mir mir::Body<'tcx>,
804+
body: &'tcx mir::Body<'tcx>,
807805
return_place: &MPlaceTy<'tcx, M::Provenance>,
808806
return_to_block: StackPopCleanup,
809807
) -> InterpResult<'tcx> {

compiler/rustc_const_eval/src/interpret/intern.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub trait HasStaticRootDefId {
4646
fn static_def_id(&self) -> Option<LocalDefId>;
4747
}
4848

49-
impl HasStaticRootDefId for const_eval::CompileTimeInterpreter<'_, '_> {
49+
impl HasStaticRootDefId for const_eval::CompileTimeInterpreter<'_> {
5050
fn static_def_id(&self) -> Option<LocalDefId> {
5151
Some(self.static_root_ids?.1)
5252
}

compiler/rustc_const_eval/src/interpret/machine.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ pub trait Machine<'mir, 'tcx: 'mir>: Sized {
200200
destination: &MPlaceTy<'tcx, Self::Provenance>,
201201
target: Option<mir::BasicBlock>,
202202
unwind: mir::UnwindAction,
203-
) -> InterpResult<'tcx, Option<(&'mir mir::Body<'tcx>, ty::Instance<'tcx>)>>;
203+
) -> InterpResult<'tcx, Option<(&'tcx mir::Body<'tcx>, ty::Instance<'tcx>)>>;
204204

205205
/// Execute `fn_val`. It is the hook's responsibility to advance the instruction
206206
/// pointer as appropriate.
@@ -478,18 +478,18 @@ pub trait Machine<'mir, 'tcx: 'mir>: Sized {
478478
/// Called immediately before a new stack frame gets pushed.
479479
fn init_frame_extra(
480480
ecx: &mut InterpCx<'mir, 'tcx, Self>,
481-
frame: Frame<'mir, 'tcx, Self::Provenance>,
482-
) -> InterpResult<'tcx, Frame<'mir, 'tcx, Self::Provenance, Self::FrameExtra>>;
481+
frame: Frame<'tcx, Self::Provenance>,
482+
) -> InterpResult<'tcx, Frame<'tcx, Self::Provenance, Self::FrameExtra>>;
483483

484484
/// Borrow the current thread's stack.
485485
fn stack<'a>(
486486
ecx: &'a InterpCx<'mir, 'tcx, Self>,
487-
) -> &'a [Frame<'mir, 'tcx, Self::Provenance, Self::FrameExtra>];
487+
) -> &'a [Frame<'tcx, Self::Provenance, Self::FrameExtra>];
488488

489489
/// Mutably borrow the current thread's stack.
490490
fn stack_mut<'a>(
491491
ecx: &'a mut InterpCx<'mir, 'tcx, Self>,
492-
) -> &'a mut Vec<Frame<'mir, 'tcx, Self::Provenance, Self::FrameExtra>>;
492+
) -> &'a mut Vec<Frame<'tcx, Self::Provenance, Self::FrameExtra>>;
493493

494494
/// Called immediately after a stack frame got pushed and its locals got initialized.
495495
fn after_stack_push(_ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> {
@@ -499,7 +499,7 @@ pub trait Machine<'mir, 'tcx: 'mir>: Sized {
499499
/// Called just before the return value is copied to the caller-provided return place.
500500
fn before_stack_pop(
501501
_ecx: &InterpCx<'mir, 'tcx, Self>,
502-
_frame: &Frame<'mir, 'tcx, Self::Provenance, Self::FrameExtra>,
502+
_frame: &Frame<'tcx, Self::Provenance, Self::FrameExtra>,
503503
) -> InterpResult<'tcx> {
504504
Ok(())
505505
}
@@ -509,7 +509,7 @@ pub trait Machine<'mir, 'tcx: 'mir>: Sized {
509509
#[inline(always)]
510510
fn after_stack_pop(
511511
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
512-
_frame: Frame<'mir, 'tcx, Self::Provenance, Self::FrameExtra>,
512+
_frame: Frame<'tcx, Self::Provenance, Self::FrameExtra>,
513513
unwinding: bool,
514514
) -> InterpResult<'tcx, StackPopJump> {
515515
// By default, we do not support unwinding from panics

compiler/rustc_const_eval/src/interpret/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ where
8484
impl<'tcx> InterpretationResult<'tcx> for mir::interpret::ConstAllocation<'tcx> {
8585
fn make_result<'mir>(
8686
mplace: MPlaceTy<'tcx>,
87-
ecx: &mut InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
87+
ecx: &mut InterpCx<'mir, 'tcx, CompileTimeInterpreter<'tcx>>,
8888
) -> Self {
8989
let alloc_id = mplace.ptr().provenance.unwrap().alloc_id();
9090
let alloc = ecx.memory.alloc_map.swap_remove(&alloc_id).unwrap().1;

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

+1-1
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();

0 commit comments

Comments
 (0)