Skip to content

Commit 5b2524e

Browse files
committed
Do not pre-compute reachable blocks.
1 parent f5e4eb9 commit 5b2524e

6 files changed

+18
-26
lines changed

compiler/rustc_mir_transform/src/elaborate_drops.rs

-20
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,6 @@ impl<'tcx> MirPass<'tcx> for ElaborateDrops {
7474
.iterate_to_fixpoint()
7575
.into_results_cursor(body);
7676
let dead_unwinds = compute_dead_unwinds(&body, &mut inits);
77-
let mut reachable = BitSet::new_empty(body.basic_blocks.len());
78-
for bb in body.basic_blocks.indices() {
79-
if inits.results().entry_set_for_block(bb).is_reachable() {
80-
reachable.insert(bb);
81-
}
82-
}
8377

8478
let uninits = MaybeUninitializedPlaces::new(tcx, body, &env)
8579
.mark_inactive_variants_as_uninit()
@@ -97,7 +91,6 @@ impl<'tcx> MirPass<'tcx> for ElaborateDrops {
9791
init_data: InitializationData { inits, uninits },
9892
drop_flags,
9993
patch: MirPatch::new(body),
100-
reachable,
10194
}
10295
.elaborate()
10396
};
@@ -262,7 +255,6 @@ struct ElaborateDropsCtxt<'a, 'tcx> {
262255
init_data: InitializationData<'a, 'tcx>,
263256
drop_flags: IndexVec<MovePathIndex, Option<Local>>,
264257
patch: MirPatch<'tcx>,
265-
reachable: BitSet<BasicBlock>,
266258
}
267259

268260
impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
@@ -302,9 +294,6 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
302294

303295
fn collect_drop_flags(&mut self) {
304296
for (bb, data) in self.body.basic_blocks.iter_enumerated() {
305-
if !self.reachable.contains(bb) {
306-
continue;
307-
}
308297
let terminator = data.terminator();
309298
let place = match terminator.kind {
310299
TerminatorKind::Drop { ref place, .. } => place,
@@ -356,9 +345,6 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
356345

357346
fn elaborate_drops(&mut self) {
358347
for (bb, data) in self.body.basic_blocks.iter_enumerated() {
359-
if !self.reachable.contains(bb) {
360-
continue;
361-
}
362348
let loc = Location { block: bb, statement_index: data.statements.len() };
363349
let terminator = data.terminator();
364350

@@ -437,9 +423,6 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
437423

438424
fn drop_flags_for_fn_rets(&mut self) {
439425
for (bb, data) in self.body.basic_blocks.iter_enumerated() {
440-
if !self.reachable.contains(bb) {
441-
continue;
442-
}
443426
if let TerminatorKind::Call {
444427
destination,
445428
target: Some(tgt),
@@ -478,9 +461,6 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
478461
// clobbered before they are read.
479462

480463
for (bb, data) in self.body.basic_blocks.iter_enumerated() {
481-
if !self.reachable.contains(bb) {
482-
continue;
483-
}
484464
debug!("drop_flags_for_locs({:?})", data);
485465
for i in 0..(data.statements.len() + 1) {
486466
debug!("drop_flag_for_locs: stmt {}", i);

tests/mir-opt/basic_assignment.main.ElaborateDrops.diff

+4-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747

4848
bb2 (cleanup): {
4949
_5 = move _6;
50-
drop(_6) -> [return: bb6, unwind terminate];
50+
- drop(_6) -> [return: bb6, unwind terminate];
51+
+ goto -> bb6;
5152
}
5253

5354
bb3: {
@@ -70,7 +71,8 @@
7071
}
7172

7273
bb6 (cleanup): {
73-
drop(_5) -> [return: bb7, unwind terminate];
74+
- drop(_5) -> [return: bb7, unwind terminate];
75+
+ goto -> bb7;
7476
}
7577

7678
bb7 (cleanup): {

tests/mir-opt/issue_41110.test.ElaborateDrops.panic-abort.diff

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747

4848
bb3 (cleanup): {
4949
_2 = move _5;
50-
drop(_5) -> [return: bb8, unwind terminate];
50+
- drop(_5) -> [return: bb8, unwind terminate];
51+
+ goto -> bb8;
5152
}
5253

5354
bb4: {

tests/mir-opt/issue_41110.test.ElaborateDrops.panic-unwind.diff

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747

4848
bb3 (cleanup): {
4949
_2 = move _5;
50-
drop(_5) -> [return: bb8, unwind terminate];
50+
- drop(_5) -> [return: bb8, unwind terminate];
51+
+ goto -> bb8;
5152
}
5253

5354
bb4: {

tests/mir-opt/issue_41888.main.ElaborateDrops.panic-abort.diff

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@
5454
}
5555

5656
bb4 (cleanup): {
57+
+ _7 = const true;
58+
+ _8 = const true;
59+
+ _9 = const true;
5760
_1 = move _3;
58-
drop(_3) -> [return: bb11, unwind terminate];
61+
- drop(_3) -> [return: bb11, unwind terminate];
62+
+ goto -> bb11;
5963
}
6064

6165
bb5: {

tests/mir-opt/issue_41888.main.ElaborateDrops.panic-unwind.diff

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@
5454
}
5555

5656
bb4 (cleanup): {
57+
+ _7 = const true;
58+
+ _8 = const true;
59+
+ _9 = const true;
5760
_1 = move _3;
58-
drop(_3) -> [return: bb11, unwind terminate];
61+
- drop(_3) -> [return: bb11, unwind terminate];
62+
+ goto -> bb11;
5963
}
6064

6165
bb5: {

0 commit comments

Comments
 (0)