@@ -33,11 +33,9 @@ pub struct InterpCx<'mir, 'tcx, M: Machine<'mir, 'tcx>> {
3333 pub machine : M ,
3434
3535 /// 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
3937 /// we are evaluating (if this is CTFE).
40- pub ( super ) root_span : Span ,
38+ pub tcx : TyCtxtAt < ' tcx > ,
4139
4240 /// Bounds in scope for polymorphic evaluations.
4341 pub ( crate ) param_env : ty:: ParamEnv < ' tcx > ,
@@ -200,7 +198,7 @@ where
200198{
201199 #[ inline]
202200 fn tcx ( & self ) -> TyCtxt < ' tcx > {
203- self . tcx
201+ * self . tcx
204202 }
205203}
206204
@@ -219,7 +217,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> LayoutOf for InterpCx<'mir, 'tcx,
219217
220218 #[ inline]
221219 fn layout_of ( & self , ty : Ty < ' tcx > ) -> Self :: TyAndLayout {
222- self . tcx_at ( )
220+ self . tcx
223221 . layout_of ( self . param_env . and ( ty) )
224222 . map_err ( |layout| err_inval ! ( Layout ( layout) ) . into ( ) )
225223 }
@@ -304,8 +302,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
304302 ) -> Self {
305303 InterpCx {
306304 machine,
307- tcx,
308- root_span,
305+ tcx : tcx. at ( root_span) ,
309306 param_env,
310307 memory : Memory :: new ( tcx, memory_extra) ,
311308 vtables : FxHashMap :: default ( ) ,
@@ -318,14 +315,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
318315 . last ( )
319316 . and_then ( |f| f. current_source_info ( ) )
320317 . 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 )
329319 }
330320
331321 #[ inline( always) ]
@@ -403,12 +393,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
403393
404394 #[ inline]
405395 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 )
407397 }
408398
409399 #[ inline]
410400 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 )
412402 }
413403
414404 pub fn load_mir (
@@ -419,21 +409,20 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
419409 // do not continue if typeck errors occurred (can only occur in local crate)
420410 let did = instance. def_id ( ) ;
421411 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 {
425414 throw_inval ! ( TypeckError ( error_reported) )
426415 }
427416 }
428417 }
429418 trace ! ( "load mir(instance={:?}, promoted={:?})" , instance, promoted) ;
430419 if let Some ( promoted) = promoted {
431- return Ok ( & self . tcx_at ( ) . promoted_mir ( did) [ promoted] ) ;
420+ return Ok ( & self . tcx . promoted_mir ( did) [ promoted] ) ;
432421 }
433422 match instance {
434423 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) )
437426 } else {
438427 throw_unsup ! ( NoMirFor ( def_id) )
439428 }
@@ -474,7 +463,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
474463 trace ! ( "resolve: {:?}, {:#?}" , def_id, substs) ;
475464 trace ! ( "param_env: {:#?}" , self . param_env) ;
476465 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) {
478467 Ok ( Some ( instance) ) => Ok ( instance) ,
479468 Ok ( None ) => throw_inval ! ( TooGeneric ) ,
480469
@@ -493,7 +482,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
493482 // have to support that case (mostly by skipping all caching).
494483 match frame. locals . get ( local) . and_then ( |state| state. layout . get ( ) ) {
495484 None => {
496- let layout = from_known_layout ( self . tcx_at ( ) , layout, || {
485+ let layout = from_known_layout ( self . tcx , layout, || {
497486 let local_ty = frame. body . local_decls [ local] . ty ;
498487 let local_ty =
499488 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> {
645634 let mut locals = IndexVec :: from_elem ( dummy, & body. local_decls ) ;
646635
647636 // 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 ( ) ) {
649638 // statics and constants don't have `Storage*` statements, no need to look for them
650639 //
651640 // FIXME: The above is likely untrue. See
@@ -860,7 +849,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
860849 } else {
861850 self . param_env
862851 } ;
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 ) ) ?;
864853
865854 // Even though `ecx.const_eval` is called from `eval_const_to_op` we can never have a
866855 // 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> {
891880 // FIXME: We can hit delay_span_bug if this is an invalid const, interning finds
892881 // that problem, but we never run validation to show an error. Can we ensure
893882 // 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) ) ?;
895884 self . raw_const_to_mplace ( val)
896885 }
897886
0 commit comments