Skip to content

Commit 108dece

Browse files
committed
Do not clone body for ConstProp.
1 parent 32fe00a commit 108dece

File tree

1 file changed

+8
-25
lines changed

1 file changed

+8
-25
lines changed

compiler/rustc_mir_transform/src/const_prop.rs

+8-25
Original file line numberDiff line numberDiff line change
@@ -94,34 +94,21 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
9494

9595
trace!("ConstProp starting for {:?}", def_id);
9696

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-
11097
// FIXME(oli-obk, eddyb) Optimize locals (or even local paths) to hold
11198
// constants, instead of just checking for const-folding succeeding.
11299
// That would require a uniform one-def no-mutation analysis
113100
// 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);
115102

116103
// Traverse the body in reverse post-order, to ensure that `FullConstProp` locals are
117104
// 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];
121107
optimization_finder.visit_basic_block_data(bb, data);
122108
}
123109

124-
optimization_finder.patch.visit_body_preserves_cfg(body);
110+
let mut patch = optimization_finder.patch;
111+
patch.visit_body_preserves_cfg(body);
125112

126113
trace!("ConstProp done for {:?}", def_id);
127114
}
@@ -339,11 +326,7 @@ impl<'tcx> ty::layout::HasParamEnv<'tcx> for ConstPropagator<'_, 'tcx> {
339326
}
340327

341328
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> {
347330
let def_id = body.source.def_id();
348331
let args = &GenericArgs::identity_for_item(tcx, def_id);
349332
let param_env = tcx.param_env_reveal_all_normalized(def_id);
@@ -374,7 +357,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
374357

375358
ecx.push_stack_frame(
376359
Instance::new(def_id, args),
377-
dummy_body,
360+
body,
378361
&ret,
379362
StackPopCleanup::Root { cleanup: false },
380363
)
@@ -390,7 +373,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
390373
}
391374

392375
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 }
394377
}
395378

396379
fn get_const(&self, place: Place<'tcx>) -> Option<OpTy<'tcx>> {

0 commit comments

Comments
 (0)