Skip to content

Commit

Permalink
Don't try to save an extra block
Browse files Browse the repository at this point in the history
This is preparation for the next commit.
  • Loading branch information
Nadrieril committed Jul 9, 2024
1 parent c5062f7 commit 8a222ff
Show file tree
Hide file tree
Showing 15 changed files with 284 additions and 268 deletions.
22 changes: 9 additions & 13 deletions compiler/rustc_mir_build/src/build/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2021,19 +2021,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {

// The block that we should branch to if none of the
// `target_candidates` match.
let remainder_start = if !remaining_candidates.is_empty() {
let remainder_start = self.cfg.start_new_block();
self.match_candidates(
span,
scrutinee_span,
remainder_start,
otherwise_block,
remaining_candidates,
);
remainder_start
} else {
otherwise_block
};
let remainder_start = self.cfg.start_new_block();

// For each outcome of test, process the candidates that still apply.
let target_blocks: FxIndexMap<_, _> = target_candidates
Expand Down Expand Up @@ -2061,6 +2049,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
&test,
target_blocks,
);

self.match_candidates(
span,
scrutinee_span,
remainder_start,
otherwise_block,
remaining_candidates,
);
}
}

Expand Down
18 changes: 11 additions & 7 deletions tests/mir-opt/building/issue_101867.main.built.after.mir
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ fn main() -> () {
StorageLive(_5);
PlaceMention(_1);
_6 = discriminant(_1);
switchInt(move _6) -> [1: bb4, otherwise: bb3];
switchInt(move _6) -> [1: bb5, otherwise: bb4];
}

bb1: {
StorageLive(_3);
StorageLive(_4);
_4 = begin_panic::<&str>(const "explicit panic") -> bb8;
_4 = begin_panic::<&str>(const "explicit panic") -> bb9;
}

bb2: {
Expand All @@ -43,31 +43,35 @@ fn main() -> () {
}

bb3: {
goto -> bb7;
goto -> bb8;
}

bb4: {
falseEdge -> [real: bb6, imaginary: bb3];
goto -> bb3;
}

bb5: {
goto -> bb3;
falseEdge -> [real: bb7, imaginary: bb3];
}

bb6: {
goto -> bb4;
}

bb7: {
_5 = ((_1 as Some).0: u8);
_0 = const ();
StorageDead(_5);
StorageDead(_1);
return;
}

bb7: {
bb8: {
StorageDead(_5);
goto -> bb1;
}

bb8 (cleanup): {
bb9 (cleanup): {
resume;
}
}
34 changes: 19 additions & 15 deletions tests/mir-opt/building/issue_49232.main.built.after.mir
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ fn main() -> () {
}

bb1: {
falseUnwind -> [real: bb2, unwind: bb14];
falseUnwind -> [real: bb2, unwind: bb15];
}

bb2: {
StorageLive(_2);
StorageLive(_3);
_3 = const true;
PlaceMention(_3);
switchInt(_3) -> [0: bb4, otherwise: bb6];
switchInt(_3) -> [0: bb5, otherwise: bb7];
}

bb3: {
Expand All @@ -34,59 +34,63 @@ fn main() -> () {
}

bb4: {
falseEdge -> [real: bb8, imaginary: bb6];
goto -> bb3;
}

bb5: {
goto -> bb3;
falseEdge -> [real: bb9, imaginary: bb7];
}

bb6: {
_0 = const ();
goto -> bb13;
goto -> bb4;
}

bb7: {
goto -> bb3;
_0 = const ();
goto -> bb14;
}

bb8: {
_2 = const 4_i32;
goto -> bb11;
goto -> bb4;
}

bb9: {
unreachable;
_2 = const 4_i32;
goto -> bb12;
}

bb10: {
goto -> bb11;
unreachable;
}

bb11: {
goto -> bb12;
}

bb12: {
FakeRead(ForLet(None), _2);
StorageDead(_3);
StorageLive(_5);
StorageLive(_6);
_6 = &_2;
_5 = std::mem::drop::<&i32>(move _6) -> [return: bb12, unwind: bb14];
_5 = std::mem::drop::<&i32>(move _6) -> [return: bb13, unwind: bb15];
}

bb12: {
bb13: {
StorageDead(_6);
StorageDead(_5);
_1 = const ();
StorageDead(_2);
goto -> bb1;
}

bb13: {
bb14: {
StorageDead(_3);
StorageDead(_2);
return;
}

bb14 (cleanup): {
bb15 (cleanup): {
resume;
}
}
Loading

0 comments on commit 8a222ff

Please sign in to comment.