@@ -33,11 +33,9 @@ pub struct InterpCx<'mir, 'tcx, M: Machine<'mir, 'tcx>> {
33
33
pub machine : M ,
34
34
35
35
/// The results of the type checker, from rustc.
36
- pub tcx : TyCtxt < ' tcx > ,
37
-
38
- /// The span of the "root" of the evaluation, i.e., the const
36
+ /// The span in this is the "root" of the evaluation, i.e., the const
39
37
/// we are evaluating (if this is CTFE).
40
- pub ( super ) root_span : Span ,
38
+ pub tcx : TyCtxtAt < ' tcx > ,
41
39
42
40
/// Bounds in scope for polymorphic evaluations.
43
41
pub ( crate ) param_env : ty:: ParamEnv < ' tcx > ,
@@ -200,7 +198,7 @@ where
200
198
{
201
199
#[ inline]
202
200
fn tcx ( & self ) -> TyCtxt < ' tcx > {
203
- self . tcx
201
+ * self . tcx
204
202
}
205
203
}
206
204
@@ -219,7 +217,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> LayoutOf for InterpCx<'mir, 'tcx,
219
217
220
218
#[ inline]
221
219
fn layout_of ( & self , ty : Ty < ' tcx > ) -> Self :: TyAndLayout {
222
- self . tcx_at ( )
220
+ self . tcx
223
221
. layout_of ( self . param_env . and ( ty) )
224
222
. map_err ( |layout| err_inval ! ( Layout ( layout) ) . into ( ) )
225
223
}
@@ -304,8 +302,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
304
302
) -> Self {
305
303
InterpCx {
306
304
machine,
307
- tcx,
308
- root_span,
305
+ tcx : tcx. at ( root_span) ,
309
306
param_env,
310
307
memory : Memory :: new ( tcx, memory_extra) ,
311
308
vtables : FxHashMap :: default ( ) ,
@@ -318,14 +315,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
318
315
. last ( )
319
316
. and_then ( |f| f. current_source_info ( ) )
320
317
. map ( |si| si. span )
321
- . unwrap_or ( self . root_span )
322
- }
323
-
324
- #[ inline( always) ]
325
- pub fn tcx_at ( & self ) -> TyCtxtAt < ' tcx > {
326
- // Computing the current span has a non-trivial cost, and for cycle errors
327
- // the "root span" is good enough.
328
- self . tcx . at ( self . root_span )
318
+ . unwrap_or ( self . tcx . span )
329
319
}
330
320
331
321
#[ inline( always) ]
@@ -403,12 +393,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
403
393
404
394
#[ inline]
405
395
pub fn type_is_sized ( & self , ty : Ty < ' tcx > ) -> bool {
406
- ty. is_sized ( self . tcx_at ( ) , self . param_env )
396
+ ty. is_sized ( self . tcx , self . param_env )
407
397
}
408
398
409
399
#[ inline]
410
400
pub fn type_is_freeze ( & self , ty : Ty < ' tcx > ) -> bool {
411
- ty. is_freeze ( self . tcx , self . param_env , self . root_span )
401
+ ty. is_freeze ( * self . tcx , self . param_env , self . tcx . span )
412
402
}
413
403
414
404
pub fn load_mir (
@@ -419,21 +409,20 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
419
409
// do not continue if typeck errors occurred (can only occur in local crate)
420
410
let did = instance. def_id ( ) ;
421
411
if let Some ( did) = did. as_local ( ) {
422
- if self . tcx_at ( ) . has_typeck_tables ( did) {
423
- if let Some ( error_reported) = self . tcx_at ( ) . typeck_tables_of ( did) . tainted_by_errors
424
- {
412
+ if self . tcx . has_typeck_tables ( did) {
413
+ if let Some ( error_reported) = self . tcx . typeck_tables_of ( did) . tainted_by_errors {
425
414
throw_inval ! ( TypeckError ( error_reported) )
426
415
}
427
416
}
428
417
}
429
418
trace ! ( "load mir(instance={:?}, promoted={:?})" , instance, promoted) ;
430
419
if let Some ( promoted) = promoted {
431
- return Ok ( & self . tcx_at ( ) . promoted_mir ( did) [ promoted] ) ;
420
+ return Ok ( & self . tcx . promoted_mir ( did) [ promoted] ) ;
432
421
}
433
422
match instance {
434
423
ty:: InstanceDef :: Item ( def_id) => {
435
- if self . tcx_at ( ) . is_mir_available ( did) {
436
- Ok ( self . tcx_at ( ) . optimized_mir ( did) )
424
+ if self . tcx . is_mir_available ( did) {
425
+ Ok ( self . tcx . optimized_mir ( did) )
437
426
} else {
438
427
throw_unsup ! ( NoMirFor ( def_id) )
439
428
}
@@ -474,7 +463,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
474
463
trace ! ( "resolve: {:?}, {:#?}" , def_id, substs) ;
475
464
trace ! ( "param_env: {:#?}" , self . param_env) ;
476
465
trace ! ( "substs: {:#?}" , substs) ;
477
- match ty:: Instance :: resolve ( self . tcx , self . param_env , def_id, substs) {
466
+ match ty:: Instance :: resolve ( * self . tcx , self . param_env , def_id, substs) {
478
467
Ok ( Some ( instance) ) => Ok ( instance) ,
479
468
Ok ( None ) => throw_inval ! ( TooGeneric ) ,
480
469
@@ -493,7 +482,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
493
482
// have to support that case (mostly by skipping all caching).
494
483
match frame. locals . get ( local) . and_then ( |state| state. layout . get ( ) ) {
495
484
None => {
496
- let layout = from_known_layout ( self . tcx_at ( ) , layout, || {
485
+ let layout = from_known_layout ( self . tcx , layout, || {
497
486
let local_ty = frame. body . local_decls [ local] . ty ;
498
487
let local_ty =
499
488
self . subst_from_frame_and_normalize_erasing_regions ( frame, local_ty) ;
@@ -645,7 +634,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
645
634
let mut locals = IndexVec :: from_elem ( dummy, & body. local_decls ) ;
646
635
647
636
// Now mark those locals as dead that we do not want to initialize
648
- match self . tcx_at ( ) . def_kind ( instance. def_id ( ) ) {
637
+ match self . tcx . def_kind ( instance. def_id ( ) ) {
649
638
// statics and constants don't have `Storage*` statements, no need to look for them
650
639
//
651
640
// FIXME: The above is likely untrue. See
@@ -860,7 +849,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
860
849
} else {
861
850
self . param_env
862
851
} ;
863
- let val = self . tcx . const_eval_global_id ( param_env, gid, Some ( self . root_span ) ) ?;
852
+ let val = self . tcx . const_eval_global_id ( param_env, gid, Some ( self . tcx . span ) ) ?;
864
853
865
854
// Even though `ecx.const_eval` is called from `eval_const_to_op` we can never have a
866
855
// recursion deeper than one level, because the `tcx.const_eval` above is guaranteed to not
@@ -891,7 +880,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
891
880
// FIXME: We can hit delay_span_bug if this is an invalid const, interning finds
892
881
// that problem, but we never run validation to show an error. Can we ensure
893
882
// this does not happen?
894
- let val = self . tcx_at ( ) . const_eval_raw ( param_env. and ( gid) ) ?;
883
+ let val = self . tcx . const_eval_raw ( param_env. and ( gid) ) ?;
895
884
self . raw_const_to_mplace ( val)
896
885
}
897
886
0 commit comments