@@ -11,9 +11,9 @@ use rustc_index::bit_set::BitSet;
1111use rustc_index:: vec:: IndexVec ;
1212use rustc_middle:: mir:: visit:: { MutatingUseContext , NonMutatingUseContext , PlaceContext , Visitor } ;
1313use rustc_middle:: mir:: {
14- AssertKind , BasicBlock , BinOp , Body , Constant , ConstantKind , Local , LocalDecl , LocalKind ,
15- Location , Operand , Place , Rvalue , SourceInfo , SourceScope , SourceScopeData , Statement ,
16- StatementKind , Terminator , TerminatorKind , UnOp , RETURN_PLACE ,
14+ AssertKind , BasicBlock , BinOp , Body , Constant , ConstantKind , Local , LocalKind , Location ,
15+ Operand , Place , Rvalue , SourceInfo , Statement , StatementKind , Terminator , TerminatorKind , UnOp ,
16+ RETURN_PLACE ,
1717} ;
1818use rustc_middle:: ty:: layout:: { LayoutError , LayoutOf , LayoutOfHelpers , TyAndLayout } ;
1919use rustc_middle:: ty:: subst:: { InternalSubsts , Subst } ;
@@ -308,10 +308,6 @@ struct ConstPropagator<'mir, 'tcx> {
308308 ecx : InterpCx < ' mir , ' tcx , ConstPropMachine < ' mir , ' tcx > > ,
309309 tcx : TyCtxt < ' tcx > ,
310310 param_env : ParamEnv < ' tcx > ,
311- // FIXME(eddyb) avoid cloning these two fields more than once,
312- // by accessing them through `ecx` instead.
313- source_scopes : IndexVec < SourceScope , SourceScopeData < ' tcx > > ,
314- local_decls : IndexVec < Local , LocalDecl < ' tcx > > ,
315311 // Because we have `MutVisitor` we can't obtain the `SourceInfo` from a `Location`. So we store
316312 // the last known `SourceInfo` here and just keep revisiting it.
317313 source_info : Option < SourceInfo > ,
@@ -357,10 +353,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
357353 let substs = & InternalSubsts :: identity_for_item ( tcx, def_id) ;
358354 let param_env = tcx. param_env_reveal_all_normalized ( def_id) ;
359355
360- let span = tcx. def_span ( def_id) ;
361- // FIXME: `CanConstProp::check` computes the layout of all locals, return those layouts
362- // so we can write them to `ecx.frame_mut().locals.layout, reducing the duplication in
363- // `layout_of` query invocations.
364356 let can_const_prop = CanConstProp :: check ( tcx, param_env, body) ;
365357 let mut only_propagate_inside_block_locals = BitSet :: new_empty ( can_const_prop. len ( ) ) ;
366358 for ( l, mode) in can_const_prop. iter_enumerated ( ) {
@@ -370,7 +362,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
370362 }
371363 let mut ecx = InterpCx :: new (
372364 tcx,
373- span ,
365+ tcx . def_span ( def_id ) ,
374366 param_env,
375367 ConstPropMachine :: new ( only_propagate_inside_block_locals, can_const_prop) ,
376368 ) ;
@@ -397,17 +389,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
397389 )
398390 . expect ( "failed to push initial stack frame" ) ;
399391
400- ConstPropagator {
401- ecx,
402- tcx,
403- param_env,
404- // FIXME(eddyb) avoid cloning these two fields more than once,
405- // by accessing them through `ecx` instead.
406- source_scopes : body. source_scopes . clone ( ) ,
407- //FIXME(wesleywiser) we can't steal this because `Visitor::super_visit_body()` needs it
408- local_decls : body. local_decls . clone ( ) ,
409- source_info : None ,
410- }
392+ ConstPropagator { ecx, tcx, param_env, source_info : None }
411393 }
412394
413395 fn get_const ( & self , place : Place < ' tcx > ) -> Option < OpTy < ' tcx > > {
@@ -435,7 +417,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
435417 }
436418
437419 fn lint_root ( & self , source_info : SourceInfo ) -> Option < HirId > {
438- source_info. scope . lint_root ( & self . source_scopes )
420+ source_info. scope . lint_root ( & self . ecx . frame ( ) . body . source_scopes )
439421 }
440422
441423 fn use_ecx < F , T > ( & mut self , f : F ) -> Option < T >
@@ -572,7 +554,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
572554 let r = r?;
573555 // We need the type of the LHS. We cannot use `place_layout` as that is the type
574556 // of the result, which for checked binops is not the same!
575- let left_ty = left. ty ( & self . local_decls , self . tcx ) ;
557+ let left_ty = left. ty ( & self . ecx . frame ( ) . body . local_decls , self . tcx ) ;
576558 let left_size = self . ecx . layout_of ( left_ty) . ok ( ) ?. size ;
577559 let right_size = r. layout . size ;
578560 let r_bits = r. to_scalar ( ) . ok ( ) ;
@@ -1026,7 +1008,7 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
10261008 assert ! (
10271009 self . get_const( local. into( ) ) . is_none( )
10281010 || self
1029- . layout_of( self . local_decls[ local] . ty)
1011+ . layout_of( self . ecx . frame ( ) . body . local_decls[ local] . ty)
10301012 . map_or( true , |layout| layout. is_zst( ) )
10311013 )
10321014 }
0 commit comments