@@ -94,34 +94,21 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
94
94
95
95
trace ! ( "ConstProp starting for {:?}" , def_id) ;
96
96
97
- let dummy_body = & Body :: new (
98
- body. source ,
99
- ( * body. basic_blocks ) . to_owned ( ) ,
100
- body. source_scopes . clone ( ) ,
101
- body. local_decls . clone ( ) ,
102
- Default :: default ( ) ,
103
- body. arg_count ,
104
- Default :: default ( ) ,
105
- body. span ,
106
- body. generator_kind ( ) ,
107
- body. tainted_by_errors ,
108
- ) ;
109
-
110
97
// FIXME(oli-obk, eddyb) Optimize locals (or even local paths) to hold
111
98
// constants, instead of just checking for const-folding succeeding.
112
99
// That would require a uniform one-def no-mutation analysis
113
100
// and RPO (or recursing when needing the value of a local).
114
- let mut optimization_finder = ConstPropagator :: new ( body, dummy_body , tcx) ;
101
+ let mut optimization_finder = ConstPropagator :: new ( body, tcx) ;
115
102
116
103
// Traverse the body in reverse post-order, to ensure that `FullConstProp` locals are
117
104
// assigned before being read.
118
- let rpo = body. basic_blocks . reverse_postorder ( ) . to_vec ( ) ;
119
- for bb in rpo {
120
- let data = & mut body. basic_blocks . as_mut_preserves_cfg ( ) [ bb] ;
105
+ for & bb in body. basic_blocks . reverse_postorder ( ) {
106
+ let data = & body. basic_blocks [ bb] ;
121
107
optimization_finder. visit_basic_block_data ( bb, data) ;
122
108
}
123
109
124
- optimization_finder. patch . visit_body_preserves_cfg ( body) ;
110
+ let mut patch = optimization_finder. patch ;
111
+ patch. visit_body_preserves_cfg ( body) ;
125
112
126
113
trace ! ( "ConstProp done for {:?}" , def_id) ;
127
114
}
@@ -339,11 +326,7 @@ impl<'tcx> ty::layout::HasParamEnv<'tcx> for ConstPropagator<'_, 'tcx> {
339
326
}
340
327
341
328
impl < ' mir , ' tcx > ConstPropagator < ' mir , ' tcx > {
342
- fn new (
343
- body : & Body < ' tcx > ,
344
- dummy_body : & ' mir Body < ' tcx > ,
345
- tcx : TyCtxt < ' tcx > ,
346
- ) -> ConstPropagator < ' mir , ' tcx > {
329
+ fn new ( body : & ' mir Body < ' tcx > , tcx : TyCtxt < ' tcx > ) -> ConstPropagator < ' mir , ' tcx > {
347
330
let def_id = body. source . def_id ( ) ;
348
331
let args = & GenericArgs :: identity_for_item ( tcx, def_id) ;
349
332
let param_env = tcx. param_env_reveal_all_normalized ( def_id) ;
@@ -374,7 +357,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
374
357
375
358
ecx. push_stack_frame (
376
359
Instance :: new ( def_id, args) ,
377
- dummy_body ,
360
+ body ,
378
361
& ret,
379
362
StackPopCleanup :: Root { cleanup : false } ,
380
363
)
@@ -390,7 +373,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
390
373
}
391
374
392
375
let patch = Patch :: new ( tcx) ;
393
- ConstPropagator { ecx, tcx, param_env, local_decls : & dummy_body . local_decls , patch }
376
+ ConstPropagator { ecx, tcx, param_env, local_decls : & body . local_decls , patch }
394
377
}
395
378
396
379
fn get_const ( & self , place : Place < ' tcx > ) -> Option < OpTy < ' tcx > > {
0 commit comments