@@ -11,9 +11,9 @@ use rustc_index::bit_set::BitSet;
11
11
use rustc_index:: vec:: IndexVec ;
12
12
use rustc_middle:: mir:: visit:: { MutatingUseContext , NonMutatingUseContext , PlaceContext , Visitor } ;
13
13
use 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 ,
17
17
} ;
18
18
use rustc_middle:: ty:: layout:: { LayoutError , LayoutOf , LayoutOfHelpers , TyAndLayout } ;
19
19
use rustc_middle:: ty:: subst:: { InternalSubsts , Subst } ;
@@ -308,10 +308,6 @@ struct ConstPropagator<'mir, 'tcx> {
308
308
ecx : InterpCx < ' mir , ' tcx , ConstPropMachine < ' mir , ' tcx > > ,
309
309
tcx : TyCtxt < ' tcx > ,
310
310
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 > > ,
315
311
// Because we have `MutVisitor` we can't obtain the `SourceInfo` from a `Location`. So we store
316
312
// the last known `SourceInfo` here and just keep revisiting it.
317
313
source_info : Option < SourceInfo > ,
@@ -357,10 +353,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
357
353
let substs = & InternalSubsts :: identity_for_item ( tcx, def_id) ;
358
354
let param_env = tcx. param_env_reveal_all_normalized ( def_id) ;
359
355
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.
364
356
let can_const_prop = CanConstProp :: check ( tcx, param_env, body) ;
365
357
let mut only_propagate_inside_block_locals = BitSet :: new_empty ( can_const_prop. len ( ) ) ;
366
358
for ( l, mode) in can_const_prop. iter_enumerated ( ) {
@@ -370,7 +362,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
370
362
}
371
363
let mut ecx = InterpCx :: new (
372
364
tcx,
373
- span ,
365
+ tcx . def_span ( def_id ) ,
374
366
param_env,
375
367
ConstPropMachine :: new ( only_propagate_inside_block_locals, can_const_prop) ,
376
368
) ;
@@ -397,17 +389,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
397
389
)
398
390
. expect ( "failed to push initial stack frame" ) ;
399
391
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 }
411
393
}
412
394
413
395
fn get_const ( & self , place : Place < ' tcx > ) -> Option < OpTy < ' tcx > > {
@@ -435,7 +417,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
435
417
}
436
418
437
419
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 )
439
421
}
440
422
441
423
fn use_ecx < F , T > ( & mut self , f : F ) -> Option < T >
@@ -572,7 +554,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
572
554
let r = r?;
573
555
// We need the type of the LHS. We cannot use `place_layout` as that is the type
574
556
// 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 ) ;
576
558
let left_size = self . ecx . layout_of ( left_ty) . ok ( ) ?. size ;
577
559
let right_size = r. layout . size ;
578
560
let r_bits = r. to_scalar ( ) . ok ( ) ;
@@ -1026,7 +1008,7 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
1026
1008
assert ! (
1027
1009
self . get_const( local. into( ) ) . is_none( )
1028
1010
|| self
1029
- . layout_of( self . local_decls[ local] . ty)
1011
+ . layout_of( self . ecx . frame ( ) . body . local_decls[ local] . ty)
1030
1012
. map_or( true , |layout| layout. is_zst( ) )
1031
1013
)
1032
1014
}
0 commit comments