Skip to content

Commit a59072e

Browse files
committed
Auto merge of #125602 - RalfJung:interpret-mir-lifetime, r=oli-obk
interpret: get rid of 'mir lifetime I realized our MIR bodies are actually at lifetime `'tcx`, so we don't need to carry around this other lifetime everywhere. r? `@oli-obk`
2 parents b582f80 + e8379c9 commit a59072e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+727
-815
lines changed

compiler/rustc_const_eval/src/const_eval/dummy_machine.rs

+19-21
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@ impl HasStaticRootDefId for DummyMachine {
4444
}
4545
}
4646

47-
impl<'mir, 'tcx: 'mir> interpret::Machine<'mir, 'tcx> for DummyMachine {
48-
interpret::compile_time_machine!(<'mir, 'tcx>);
47+
impl<'tcx> interpret::Machine<'tcx> for DummyMachine {
48+
interpret::compile_time_machine!(<'tcx>);
4949
type MemoryKind = !;
5050
const PANIC_ON_ALLOC_FAIL: bool = true;
5151

5252
// We want to just eval random consts in the program, so `eval_mir_const` can fail.
5353
const ALL_CONSTS_ARE_PRECHECKED: bool = false;
5454

5555
#[inline(always)]
56-
fn enforce_alignment(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
56+
fn enforce_alignment(_ecx: &InterpCx<'tcx, Self>) -> bool {
5757
false // no reason to enforce alignment
5858
}
5959

60-
fn enforce_validity(_ecx: &InterpCx<'mir, 'tcx, Self>, _layout: TyAndLayout<'tcx>) -> bool {
60+
fn enforce_validity(_ecx: &InterpCx<'tcx, Self>, _layout: TyAndLayout<'tcx>) -> bool {
6161
false
6262
}
6363

@@ -83,26 +83,26 @@ impl<'mir, 'tcx: 'mir> interpret::Machine<'mir, 'tcx> for DummyMachine {
8383
}
8484

8585
fn find_mir_or_eval_fn(
86-
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
86+
_ecx: &mut InterpCx<'tcx, Self>,
8787
_instance: ty::Instance<'tcx>,
8888
_abi: rustc_target::spec::abi::Abi,
8989
_args: &[interpret::FnArg<'tcx, Self::Provenance>],
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

9797
fn panic_nounwind(
98-
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
98+
_ecx: &mut InterpCx<'tcx, Self>,
9999
_msg: &str,
100100
) -> interpret::InterpResult<'tcx> {
101101
unimplemented!()
102102
}
103103

104104
fn call_intrinsic(
105-
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
105+
_ecx: &mut InterpCx<'tcx, Self>,
106106
_instance: ty::Instance<'tcx>,
107107
_args: &[interpret::OpTy<'tcx, Self::Provenance>],
108108
_destination: &interpret::MPlaceTy<'tcx, Self::Provenance>,
@@ -113,15 +113,15 @@ impl<'mir, 'tcx: 'mir> interpret::Machine<'mir, 'tcx> for DummyMachine {
113113
}
114114

115115
fn assert_panic(
116-
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
116+
_ecx: &mut InterpCx<'tcx, Self>,
117117
_msg: &rustc_middle::mir::AssertMessage<'tcx>,
118118
_unwind: UnwindAction,
119119
) -> interpret::InterpResult<'tcx> {
120120
unimplemented!()
121121
}
122122

123123
fn binary_ptr_op(
124-
ecx: &InterpCx<'mir, 'tcx, Self>,
124+
ecx: &InterpCx<'tcx, Self>,
125125
bin_op: BinOp,
126126
left: &interpret::ImmTy<'tcx, Self::Provenance>,
127127
right: &interpret::ImmTy<'tcx, Self::Provenance>,
@@ -168,32 +168,30 @@ impl<'mir, 'tcx: 'mir> interpret::Machine<'mir, 'tcx> for DummyMachine {
168168
}
169169

170170
fn expose_ptr(
171-
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
171+
_ecx: &mut InterpCx<'tcx, Self>,
172172
_ptr: interpret::Pointer<Self::Provenance>,
173173
) -> interpret::InterpResult<'tcx> {
174174
unimplemented!()
175175
}
176176

177177
fn init_frame_extra(
178-
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
179-
_frame: interpret::Frame<'mir, 'tcx, Self::Provenance>,
180-
) -> interpret::InterpResult<
181-
'tcx,
182-
interpret::Frame<'mir, 'tcx, Self::Provenance, Self::FrameExtra>,
183-
> {
178+
_ecx: &mut InterpCx<'tcx, Self>,
179+
_frame: interpret::Frame<'tcx, Self::Provenance>,
180+
) -> interpret::InterpResult<'tcx, interpret::Frame<'tcx, Self::Provenance, Self::FrameExtra>>
181+
{
184182
unimplemented!()
185183
}
186184

187185
fn stack<'a>(
188-
_ecx: &'a InterpCx<'mir, 'tcx, Self>,
189-
) -> &'a [interpret::Frame<'mir, 'tcx, Self::Provenance, Self::FrameExtra>] {
186+
_ecx: &'a InterpCx<'tcx, Self>,
187+
) -> &'a [interpret::Frame<'tcx, Self::Provenance, Self::FrameExtra>] {
190188
// Return an empty stack instead of panicking, as `cur_span` uses it to evaluate constants.
191189
&[]
192190
}
193191

194192
fn stack_mut<'a>(
195-
_ecx: &'a mut InterpCx<'mir, 'tcx, Self>,
196-
) -> &'a mut Vec<interpret::Frame<'mir, 'tcx, Self::Provenance, Self::FrameExtra>> {
193+
_ecx: &'a mut InterpCx<'tcx, Self>,
194+
) -> &'a mut Vec<interpret::Frame<'tcx, Self::Provenance, Self::FrameExtra>> {
197195
unimplemented!()
198196
}
199197
}

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

+16-16
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ use crate::CTRL_C_RECEIVED;
3131

3232
// Returns a pointer to where the result lives
3333
#[instrument(level = "trace", skip(ecx, body))]
34-
fn eval_body_using_ecx<'mir, 'tcx, R: InterpretationResult<'tcx>>(
35-
ecx: &mut CompileTimeEvalContext<'mir, 'tcx>,
34+
fn eval_body_using_ecx<'tcx, R: InterpretationResult<'tcx>>(
35+
ecx: &mut CompileTimeEvalContext<'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;
@@ -134,12 +134,12 @@ fn eval_body_using_ecx<'mir, 'tcx, R: InterpretationResult<'tcx>>(
134134
/// that inform us about the generic bounds of the constant. E.g., using an associated constant
135135
/// of a function's generic parameter will require knowledge about the bounds on the generic
136136
/// parameter. These bounds are passed to `mk_eval_cx` via the `ParamEnv` argument.
137-
pub(crate) fn mk_eval_cx_to_read_const_val<'mir, 'tcx>(
137+
pub(crate) fn mk_eval_cx_to_read_const_val<'tcx>(
138138
tcx: TyCtxt<'tcx>,
139139
root_span: Span,
140140
param_env: ty::ParamEnv<'tcx>,
141141
can_access_mut_global: CanAccessMutGlobal,
142-
) -> CompileTimeEvalContext<'mir, 'tcx> {
142+
) -> CompileTimeEvalContext<'tcx> {
143143
debug!("mk_eval_cx: {:?}", param_env);
144144
InterpCx::new(
145145
tcx,
@@ -151,12 +151,12 @@ pub(crate) fn mk_eval_cx_to_read_const_val<'mir, 'tcx>(
151151

152152
/// Create an interpreter context to inspect the given `ConstValue`.
153153
/// Returns both the context and an `OpTy` that represents the constant.
154-
pub fn mk_eval_cx_for_const_val<'mir, 'tcx>(
154+
pub fn mk_eval_cx_for_const_val<'tcx>(
155155
tcx: TyCtxtAt<'tcx>,
156156
param_env: ty::ParamEnv<'tcx>,
157157
val: mir::ConstValue<'tcx>,
158158
ty: Ty<'tcx>,
159-
) -> Option<(CompileTimeEvalContext<'mir, 'tcx>, OpTy<'tcx>)> {
159+
) -> Option<(CompileTimeEvalContext<'tcx>, OpTy<'tcx>)> {
160160
let ecx = mk_eval_cx_to_read_const_val(tcx.tcx, tcx.span, param_env, CanAccessMutGlobal::No);
161161
let op = ecx.const_val_to_op(val, ty, None).ok()?;
162162
Some((ecx, op))
@@ -170,7 +170,7 @@ pub fn mk_eval_cx_for_const_val<'mir, 'tcx>(
170170
/// encounter an `Indirect` they cannot handle.
171171
#[instrument(skip(ecx), level = "debug")]
172172
pub(super) fn op_to_const<'tcx>(
173-
ecx: &CompileTimeEvalContext<'_, 'tcx>,
173+
ecx: &CompileTimeEvalContext<'tcx>,
174174
op: &OpTy<'tcx>,
175175
for_diagnostics: bool,
176176
) -> ConstValue<'tcx> {
@@ -326,16 +326,16 @@ pub trait InterpretationResult<'tcx> {
326326
/// This function takes the place where the result of the evaluation is stored
327327
/// and prepares it for returning it in the appropriate format needed by the specific
328328
/// evaluation query.
329-
fn make_result<'mir>(
329+
fn make_result(
330330
mplace: MPlaceTy<'tcx>,
331-
ecx: &mut InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>,
331+
ecx: &mut InterpCx<'tcx, CompileTimeInterpreter<'tcx>>,
332332
) -> Self;
333333
}
334334

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

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

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

0 commit comments

Comments
 (0)