Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite8379c9

Browse files
committed
interpret: get rid of 'mir lifetime everywhere
1 parent36d36a3 commite8379c9

File tree

87 files changed

+671
-760
lines changed

Some content is hidden

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

87 files changed

+671
-760
lines changed

‎compiler/rustc_const_eval/src/const_eval/dummy_machine.rs‎

Lines changed: 15 additions & 17 deletions
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>forDummyMachine{
48-
interpret::compile_time_machine!(<'mir,'tcx>);
47+
impl<'tcx> interpret::Machine<'tcx>forDummyMachine{
48+
interpret::compile_time_machine!(<'tcx>);
4949
typeMemoryKind = !;
5050
constPANIC_ON_ALLOC_FAIL:bool =true;
5151

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

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

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

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

8585
fnfind_mir_or_eval_fn(
86-
_ecx:&mutInterpCx<'mir,'tcx,Self>,
86+
_ecx:&mutInterpCx<'tcx,Self>,
8787
_instance: ty::Instance<'tcx>,
8888
_abi: rustc_target::spec::abi::Abi,
8989
_args:&[interpret::FnArg<'tcx,Self::Provenance>],
@@ -95,14 +95,14 @@ impl<'mir, 'tcx: 'mir> interpret::Machine<'mir, 'tcx> for DummyMachine {
9595
}
9696

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

104104
fncall_intrinsic(
105-
_ecx:&mutInterpCx<'mir,'tcx,Self>,
105+
_ecx:&mutInterpCx<'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
fnassert_panic(
116-
_ecx:&mutInterpCx<'mir,'tcx,Self>,
116+
_ecx:&mutInterpCx<'tcx,Self>,
117117
_msg:&rustc_middle::mir::AssertMessage<'tcx>,
118118
_unwind:UnwindAction,
119119
) -> interpret::InterpResult<'tcx>{
120120
unimplemented!()
121121
}
122122

123123
fnbinary_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,31 +168,29 @@ impl<'mir, 'tcx: 'mir> interpret::Machine<'mir, 'tcx> for DummyMachine {
168168
}
169169

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

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

187185
fnstack<'a>(
188-
_ecx:&'aInterpCx<'mir,'tcx,Self>,
186+
_ecx:&'aInterpCx<'tcx,Self>,
189187
) ->&'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
fnstack_mut<'a>(
195-
_ecx:&'amutInterpCx<'mir,'tcx,Self>,
193+
_ecx:&'amutInterpCx<'tcx,Self>,
196194
) ->&'amutVec<interpret::Frame<'tcx,Self::Provenance,Self::FrameExtra>>{
197195
unimplemented!()
198196
}

‎compiler/rustc_const_eval/src/const_eval/eval_queries.rs‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ use crate::CTRL_C_RECEIVED;
3131

3232
// Returns a pointer to where the result lives
3333
#[instrument(level ="trace", skip(ecx, body))]
34-
fneval_body_using_ecx<'mir,'tcx,R:InterpretationResult<'tcx>>(
35-
ecx:&mutCompileTimeEvalContext<'mir,'tcx>,
34+
fneval_body_using_ecx<'tcx,R:InterpretationResult<'tcx>>(
35+
ecx:&mutCompileTimeEvalContext<'tcx>,
3636
cid:GlobalId<'tcx>,
3737
body:&'tcx mir::Body<'tcx>,
3838
) ->InterpResult<'tcx,R>{
@@ -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)fnmk_eval_cx_to_read_const_val<'mir,'tcx>(
137+
pub(crate)fnmk_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-
pubfnmk_eval_cx_for_const_val<'mir,'tcx>(
154+
pubfnmk_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)fnop_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-
fnmake_result<'mir>(
329+
fnmake_result(
330330
mplace:MPlaceTy<'tcx>,
331-
ecx:&mutInterpCx<'mir,'tcx,CompileTimeInterpreter<'tcx>>,
331+
ecx:&mutInterpCx<'tcx,CompileTimeInterpreter<'tcx>>,
332332
) ->Self;
333333
}
334334

335335
impl<'tcx>InterpretationResult<'tcx>forConstAlloc<'tcx>{
336-
fnmake_result<'mir>(
336+
fnmake_result(
337337
mplace:MPlaceTy<'tcx>,
338-
_ecx:&mutInterpCx<'mir,'tcx,CompileTimeInterpreter<'tcx>>,
338+
_ecx:&mutInterpCx<'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-
fnconst_validate_mplace<'mir,'tcx>(
420-
ecx:&InterpCx<'mir,'tcx,CompileTimeInterpreter<'tcx>>,
419+
fnconst_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-
fnreport_validation_error<'mir,'tcx>(
450-
ecx:&InterpCx<'mir,'tcx,CompileTimeInterpreter<'tcx>>,
449+
fnreport_validation_error<'tcx>(
450+
ecx:&InterpCx<'tcx,CompileTimeInterpreter<'tcx>>,
451451
error:InterpErrorInfo<'tcx>,
452452
alloc_id:AllocId,
453453
) ->ErrorHandled{

‎compiler/rustc_const_eval/src/const_eval/machine.rs‎

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ impl<K: Hash + Eq, V> interpret::AllocMap<K, V> for FxIndexMap<K, V> {
164164
}
165165
}
166166

167-
pub(crate)typeCompileTimeEvalContext<'mir,'tcx> =
168-
InterpCx<'mir,'tcx,CompileTimeInterpreter<'tcx>>;
167+
pub(crate)typeCompileTimeEvalContext<'tcx> =InterpCx<'tcx,CompileTimeInterpreter<'tcx>>;
169168

170169
#[derive(Debug,PartialEq,Eq,Copy,Clone)]
171170
pubenumMemoryKind{
@@ -197,7 +196,7 @@ impl interpret::MayLeak for ! {
197196
}
198197
}
199198

200-
impl<'mir,'tcx:'mir>CompileTimeEvalContext<'mir,'tcx>{
199+
impl<'tcx>CompileTimeEvalContext<'tcx>{
201200
fnlocation_triple_for_span(&self,span:Span) ->(Symbol,u32,u32){
202201
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
203202
let caller =self.tcx.sess.source_map().lookup_char_pos(topmost.lo());
@@ -371,25 +370,25 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> {
371370
}
372371
}
373372

374-
impl<'mir,'tcx:'mir> interpret::Machine<'mir,'tcx>forCompileTimeInterpreter<'tcx>{
375-
compile_time_machine!(<'mir,'tcx>);
373+
impl<'tcx> interpret::Machine<'tcx>forCompileTimeInterpreter<'tcx>{
374+
compile_time_machine!(<'tcx>);
376375

377376
typeMemoryKind =MemoryKind;
378377

379378
constPANIC_ON_ALLOC_FAIL:bool =false;// will be raised as a proper error
380379

381380
#[inline(always)]
382-
fnenforce_alignment(ecx:&InterpCx<'mir,'tcx,Self>) ->bool{
381+
fnenforce_alignment(ecx:&InterpCx<'tcx,Self>) ->bool{
383382
matches!(ecx.machine.check_alignment,CheckAlignment::Error)
384383
}
385384

386385
#[inline(always)]
387-
fnenforce_validity(ecx:&InterpCx<'mir,'tcx,Self>,layout:TyAndLayout<'tcx>) ->bool{
386+
fnenforce_validity(ecx:&InterpCx<'tcx,Self>,layout:TyAndLayout<'tcx>) ->bool{
388387
ecx.tcx.sess.opts.unstable_opts.extra_const_ub_checks || layout.abi.is_uninhabited()
389388
}
390389

391390
fnload_mir(
392-
ecx:&InterpCx<'mir,'tcx,Self>,
391+
ecx:&InterpCx<'tcx,Self>,
393392
instance: ty::InstanceDef<'tcx>,
394393
) ->InterpResult<'tcx,&'tcx mir::Body<'tcx>>{
395394
match instance{
@@ -410,7 +409,7 @@ impl<'mir, 'tcx: 'mir> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter
410409
}
411410

412411
fnfind_mir_or_eval_fn(
413-
ecx:&mutInterpCx<'mir,'tcx,Self>,
412+
ecx:&mutInterpCx<'tcx,Self>,
414413
orig_instance: ty::Instance<'tcx>,
415414
_abi:CallAbi,
416415
args:&[FnArg<'tcx>],
@@ -448,15 +447,15 @@ impl<'mir, 'tcx: 'mir> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter
448447
Ok(Some((ecx.load_mir(instance.def,None)?, orig_instance)))
449448
}
450449

451-
fnpanic_nounwind(ecx:&mutInterpCx<'mir,'tcx,Self>,msg:&str) ->InterpResult<'tcx>{
450+
fnpanic_nounwind(ecx:&mutInterpCx<'tcx,Self>,msg:&str) ->InterpResult<'tcx>{
452451
let msg =Symbol::intern(msg);
453452
let span = ecx.find_closest_untracked_caller_location();
454453
let(file, line, col) = ecx.location_triple_for_span(span);
455454
Err(ConstEvalErrKind::Panic{ msg, file, line, col}.into())
456455
}
457456

458457
fncall_intrinsic(
459-
ecx:&mutInterpCx<'mir,'tcx,Self>,
458+
ecx:&mutInterpCx<'tcx,Self>,
460459
instance: ty::Instance<'tcx>,
461460
args:&[OpTy<'tcx>],
462461
dest:&MPlaceTy<'tcx,Self::Provenance>,
@@ -555,7 +554,7 @@ impl<'mir, 'tcx: 'mir> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter
555554
}
556555

557556
fnassert_panic(
558-
ecx:&mutInterpCx<'mir,'tcx,Self>,
557+
ecx:&mutInterpCx<'tcx,Self>,
559558
msg:&AssertMessage<'tcx>,
560559
_unwind: mir::UnwindAction,
561560
) ->InterpResult<'tcx>{
@@ -586,15 +585,15 @@ impl<'mir, 'tcx: 'mir> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter
586585
}
587586

588587
fnbinary_ptr_op(
589-
_ecx:&InterpCx<'mir,'tcx,Self>,
588+
_ecx:&InterpCx<'tcx,Self>,
590589
_bin_op: mir::BinOp,
591590
_left:&ImmTy<'tcx>,
592591
_right:&ImmTy<'tcx>,
593592
) ->InterpResult<'tcx,ImmTy<'tcx>>{
594593
throw_unsup_format!("pointer arithmetic or comparison is not supported at compile-time");
595594
}
596595

597-
fnincrement_const_eval_counter(ecx:&mutInterpCx<'mir,'tcx,Self>) ->InterpResult<'tcx>{
596+
fnincrement_const_eval_counter(ecx:&mutInterpCx<'tcx,Self>) ->InterpResult<'tcx>{
598597
// The step limit has already been hit in a previous call to `increment_const_eval_counter`.
599598

600599
ifletSome(new_steps) = ecx.machine.num_evaluated_steps.checked_add(1){
@@ -650,14 +649,14 @@ impl<'mir, 'tcx: 'mir> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter
650649
}
651650

652651
#[inline(always)]
653-
fnexpose_ptr(_ecx:&mutInterpCx<'mir,'tcx,Self>,_ptr:Pointer) ->InterpResult<'tcx>{
652+
fnexpose_ptr(_ecx:&mutInterpCx<'tcx,Self>,_ptr:Pointer) ->InterpResult<'tcx>{
654653
// This is only reachable with -Zunleash-the-miri-inside-of-you.
655654
throw_unsup_format!("exposing pointers is not possible at compile-time")
656655
}
657656

658657
#[inline(always)]
659658
fninit_frame_extra(
660-
ecx:&mutInterpCx<'mir,'tcx,Self>,
659+
ecx:&mutInterpCx<'tcx,Self>,
661660
frame:Frame<'tcx>,
662661
) ->InterpResult<'tcx,Frame<'tcx>>{
663662
// Enforce stack size limit. Add 1 because this is run before the new frame is pushed.
@@ -670,14 +669,14 @@ impl<'mir, 'tcx: 'mir> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter
670669

671670
#[inline(always)]
672671
fnstack<'a>(
673-
ecx:&'aInterpCx<'mir,'tcx,Self>,
672+
ecx:&'aInterpCx<'tcx,Self>,
674673
) ->&'a[Frame<'tcx,Self::Provenance,Self::FrameExtra>]{
675674
&ecx.machine.stack
676675
}
677676

678677
#[inline(always)]
679678
fnstack_mut<'a>(
680-
ecx:&'amutInterpCx<'mir,'tcx,Self>,
679+
ecx:&'amutInterpCx<'tcx,Self>,
681680
) ->&'amutVec<Frame<'tcx,Self::Provenance,Self::FrameExtra>>{
682681
&mut ecx.machine.stack
683682
}
@@ -715,7 +714,7 @@ impl<'mir, 'tcx: 'mir> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter
715714
}
716715

717716
fnretag_ptr_value(
718-
ecx:&mutInterpCx<'mir,'tcx,Self>,
717+
ecx:&mutInterpCx<'tcx,Self>,
719718
_kind: mir::RetagKind,
720719
val:&ImmTy<'tcx,CtfeProvenance>,
721720
) ->InterpResult<'tcx,ImmTy<'tcx,CtfeProvenance>>{
@@ -756,10 +755,7 @@ impl<'mir, 'tcx: 'mir> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter
756755
Ok(())
757756
}
758757

759-
fnbefore_alloc_read(
760-
ecx:&InterpCx<'mir,'tcx,Self>,
761-
alloc_id:AllocId,
762-
) ->InterpResult<'tcx>{
758+
fnbefore_alloc_read(ecx:&InterpCx<'tcx,Self>,alloc_id:AllocId) ->InterpResult<'tcx>{
763759
// Check if this is the currently evaluated static.
764760
ifSome(alloc_id) == ecx.machine.static_root_ids.map(|(id, _)| id){
765761
returnErr(ConstEvalErrKind::RecursiveStatic.into());

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp