From 5b2524eb03d0fc88d045ffee3043b66abbbbf6d2 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 16 Aug 2023 18:19:48 +0000 Subject: [PATCH] Do not pre-compute reachable blocks. --- .../src/elaborate_drops.rs | 20 ------------------- .../basic_assignment.main.ElaborateDrops.diff | 6 ++++-- ...41110.test.ElaborateDrops.panic-abort.diff | 3 ++- ...1110.test.ElaborateDrops.panic-unwind.diff | 3 ++- ...41888.main.ElaborateDrops.panic-abort.diff | 6 +++++- ...1888.main.ElaborateDrops.panic-unwind.diff | 6 +++++- 6 files changed, 18 insertions(+), 26 deletions(-) diff --git a/compiler/rustc_mir_transform/src/elaborate_drops.rs b/compiler/rustc_mir_transform/src/elaborate_drops.rs index 78c0c6b6b86..b6b1ae6d3c3 100644 --- a/compiler/rustc_mir_transform/src/elaborate_drops.rs +++ b/compiler/rustc_mir_transform/src/elaborate_drops.rs @@ -74,12 +74,6 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { .iterate_to_fixpoint() .into_results_cursor(body); let dead_unwinds = compute_dead_unwinds(&body, &mut inits); - let mut reachable = BitSet::new_empty(body.basic_blocks.len()); - for bb in body.basic_blocks.indices() { - if inits.results().entry_set_for_block(bb).is_reachable() { - reachable.insert(bb); - } - } let uninits = MaybeUninitializedPlaces::new(tcx, body, &env) .mark_inactive_variants_as_uninit() @@ -97,7 +91,6 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { init_data: InitializationData { inits, uninits }, drop_flags, patch: MirPatch::new(body), - reachable, } .elaborate() }; @@ -262,7 +255,6 @@ struct ElaborateDropsCtxt<'a, 'tcx> { init_data: InitializationData<'a, 'tcx>, drop_flags: IndexVec>, patch: MirPatch<'tcx>, - reachable: BitSet, } impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> { @@ -302,9 +294,6 @@ fn elaborate(mut self) -> MirPatch<'tcx> { fn collect_drop_flags(&mut self) { for (bb, data) in self.body.basic_blocks.iter_enumerated() { - if !self.reachable.contains(bb) { - continue; - } let terminator = data.terminator(); let place = match terminator.kind { TerminatorKind::Drop { ref place, .. } => place, @@ -356,9 +345,6 @@ fn collect_drop_flags(&mut self) { fn elaborate_drops(&mut self) { for (bb, data) in self.body.basic_blocks.iter_enumerated() { - if !self.reachable.contains(bb) { - continue; - } let loc = Location { block: bb, statement_index: data.statements.len() }; let terminator = data.terminator(); @@ -437,9 +423,6 @@ fn drop_flags_on_init(&mut self) { fn drop_flags_for_fn_rets(&mut self) { for (bb, data) in self.body.basic_blocks.iter_enumerated() { - if !self.reachable.contains(bb) { - continue; - } if let TerminatorKind::Call { destination, target: Some(tgt), @@ -478,9 +461,6 @@ fn drop_flags_for_locs(&mut self) { // clobbered before they are read. for (bb, data) in self.body.basic_blocks.iter_enumerated() { - if !self.reachable.contains(bb) { - continue; - } debug!("drop_flags_for_locs({:?})", data); for i in 0..(data.statements.len() + 1) { debug!("drop_flag_for_locs: stmt {}", i); diff --git a/tests/mir-opt/basic_assignment.main.ElaborateDrops.diff b/tests/mir-opt/basic_assignment.main.ElaborateDrops.diff index 34a1b5f2ff3..15269fb8f6c 100644 --- a/tests/mir-opt/basic_assignment.main.ElaborateDrops.diff +++ b/tests/mir-opt/basic_assignment.main.ElaborateDrops.diff @@ -47,7 +47,8 @@ bb2 (cleanup): { _5 = move _6; - drop(_6) -> [return: bb6, unwind terminate]; +- drop(_6) -> [return: bb6, unwind terminate]; ++ goto -> bb6; } bb3: { @@ -70,7 +71,8 @@ } bb6 (cleanup): { - drop(_5) -> [return: bb7, unwind terminate]; +- drop(_5) -> [return: bb7, unwind terminate]; ++ goto -> bb7; } bb7 (cleanup): { diff --git a/tests/mir-opt/issue_41110.test.ElaborateDrops.panic-abort.diff b/tests/mir-opt/issue_41110.test.ElaborateDrops.panic-abort.diff index 00e6ae5a21c..65f4806aaf7 100644 --- a/tests/mir-opt/issue_41110.test.ElaborateDrops.panic-abort.diff +++ b/tests/mir-opt/issue_41110.test.ElaborateDrops.panic-abort.diff @@ -47,7 +47,8 @@ bb3 (cleanup): { _2 = move _5; - drop(_5) -> [return: bb8, unwind terminate]; +- drop(_5) -> [return: bb8, unwind terminate]; ++ goto -> bb8; } bb4: { diff --git a/tests/mir-opt/issue_41110.test.ElaborateDrops.panic-unwind.diff b/tests/mir-opt/issue_41110.test.ElaborateDrops.panic-unwind.diff index 924207ffc3d..4845fc732aa 100644 --- a/tests/mir-opt/issue_41110.test.ElaborateDrops.panic-unwind.diff +++ b/tests/mir-opt/issue_41110.test.ElaborateDrops.panic-unwind.diff @@ -47,7 +47,8 @@ bb3 (cleanup): { _2 = move _5; - drop(_5) -> [return: bb8, unwind terminate]; +- drop(_5) -> [return: bb8, unwind terminate]; ++ goto -> bb8; } bb4: { diff --git a/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-abort.diff b/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-abort.diff index 02803285e8e..aca7fe95c18 100644 --- a/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-abort.diff +++ b/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-abort.diff @@ -54,8 +54,12 @@ } bb4 (cleanup): { ++ _7 = const true; ++ _8 = const true; ++ _9 = const true; _1 = move _3; - drop(_3) -> [return: bb11, unwind terminate]; +- drop(_3) -> [return: bb11, unwind terminate]; ++ goto -> bb11; } bb5: { diff --git a/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-unwind.diff b/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-unwind.diff index 9d6a3958769..60ce9cd8ad9 100644 --- a/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-unwind.diff +++ b/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-unwind.diff @@ -54,8 +54,12 @@ } bb4 (cleanup): { ++ _7 = const true; ++ _8 = const true; ++ _9 = const true; _1 = move _3; - drop(_3) -> [return: bb11, unwind terminate]; +- drop(_3) -> [return: bb11, unwind terminate]; ++ goto -> bb11; } bb5: {