Skip to content

Commit c6a63ed

Browse files
committed
Only nuke storage for mapped locals, don't rebuild it
1 parent 54b60b7 commit c6a63ed

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

compiler/rustc_mir_transform/src/move_elimination.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl<'tcx> crate::MirPass<'tcx> for MoveElimination {
5555

5656
apply_mappings(tcx, body, &remapped_locals);
5757

58-
if tcx.sess.emit_lifetime_markers() {
58+
if false && tcx.sess.emit_lifetime_markers() {
5959
reconstruct_storage(body, &points, &liveness_matrix);
6060
}
6161

@@ -388,13 +388,22 @@ fn apply_mappings<'tcx>(
388388
body: &mut Body<'tcx>,
389389
remapped_locals: &IndexVec<Local, Option<Place<'tcx>>>,
390390
) {
391-
let mut rewriter = PlaceUpdater { tcx, remapped_locals };
391+
let mut mapped_locals = DenseBitSet::new_empty(body.local_decls.len());
392+
for (src, dst) in remapped_locals.iter_enumerated() {
393+
if let Some(dst_place) = dst {
394+
mapped_locals.insert(src);
395+
mapped_locals.insert(dst_place.local);
396+
}
397+
}
398+
399+
let mut rewriter = PlaceUpdater { tcx, remapped_locals, mapped_locals };
392400
rewriter.visit_body_preserves_cfg(body);
393401
}
394402

395403
struct PlaceUpdater<'a, 'tcx> {
396404
tcx: TyCtxt<'tcx>,
397405
remapped_locals: &'a IndexVec<Local, Option<Place<'tcx>>>,
406+
mapped_locals: DenseBitSet<Local>,
398407
}
399408

400409
impl<'tcx> MutVisitor<'tcx> for PlaceUpdater<'_, 'tcx> {
@@ -422,11 +431,14 @@ impl<'tcx> MutVisitor<'tcx> for PlaceUpdater<'_, 'tcx> {
422431
}
423432

424433
fn visit_statement(&mut self, statement: &mut Statement<'tcx>, location: Location) {
425-
// Remove all storage statements: we will be reconstructing them
426-
// directly from liveness information.
427-
if let StatementKind::StorageDead(_) | StatementKind::StorageLive(_) = statement.kind {
428-
statement.make_nop(true);
429-
return;
434+
match statement.kind {
435+
StatementKind::StorageDead(local) | StatementKind::StorageLive(local)
436+
if self.mapped_locals.contains(local) =>
437+
{
438+
statement.make_nop(true);
439+
return;
440+
}
441+
_ => {}
430442
}
431443

432444
self.super_statement(statement, location);

0 commit comments

Comments
 (0)