Skip to content

Commit

Permalink
Move the exit block of the match to the end
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjasper committed Feb 21, 2019
1 parent 90f40cd commit 5ffc919
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 126 deletions.
14 changes: 9 additions & 5 deletions src/librustc_mir/build/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {

// Step 5. Create everything else: the guards and the arms.

// all the arm blocks will rejoin here
let end_block = self.cfg.start_new_block();

let outer_source_info = self.source_info(span);

for (arm, candidates) in arm_candidates {
let arm_end_blocks: Vec<_> = arm_candidates.into_iter().map(|(arm, candidates)| {
let mut arm_block = self.cfg.start_new_block();

let body = self.hir.mirror(arm.body.clone());
Expand Down Expand Up @@ -283,6 +279,14 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
}

unpack!(arm_block = self.into(destination, arm_block, body));

arm_block
}).collect();

// all the arm blocks will rejoin here
let end_block = self.cfg.start_new_block();

for arm_block in arm_end_blocks {
self.cfg.terminate(
arm_block,
outer_source_info,
Expand Down
38 changes: 19 additions & 19 deletions src/test/mir-opt/issue-49232.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ fn main() {
// resume;
// }
// bb5: {
// falseEdges -> [real: bb12, imaginary: bb6];
// falseEdges -> [real: bb11, imaginary: bb6];
// }
// bb6: {
// falseEdges -> [real: bb14, imaginary: bb7];
// falseEdges -> [real: bb13, imaginary: bb7];
// }
// bb7: {
// unreachable;
Expand All @@ -62,41 +62,41 @@ fn main() {
// goto -> bb5;
// }
// bb10: {
// FakeRead(ForLet, _2);
// StorageDead(_3);
// StorageLive(_6);
// _6 = &_2;
// _5 = const std::mem::drop(move _6) -> [return: bb19, unwind: bb4];
// _2 = const 4i32;
// goto -> bb18;
// }
// bb11: {
// _2 = const 4i32;
// goto -> bb10;
// }
// bb12: {
// goto -> bb11;
// _0 = ();
// goto -> bb14;
// }
// bb13: {
// _0 = ();
// goto -> bb15;
// goto -> bb12;
// }
// bb14: {
// goto -> bb13;
// }
// bb15: {
// StorageDead(_3);
// goto -> bb16;
// goto -> bb15;
// }
// bb16: {
// bb15: {
// StorageDead(_2);
// goto -> bb2;
// }
// bb17: {
// bb16: {
// _4 = ();
// unreachable;
// }
// bb18: {
// bb17: {
// StorageDead(_4);
// goto -> bb10;
// goto -> bb18;
// }
// bb18: {
// FakeRead(ForLet, _2);
// StorageDead(_3);
// StorageLive(_6);
// _6 = &_2;
// _5 = const std::mem::drop(move _6) -> [return: bb19, unwind: bb4];
// }
// bb19: {
// StorageDead(_6);
Expand Down
120 changes: 60 additions & 60 deletions src/test/mir-opt/match_false_edges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ fn main() {
// resume;
// }
// bb2: {
// falseEdges -> [real: bb9, imaginary: bb3]; //pre_binding1
// falseEdges -> [real: bb8, imaginary: bb3]; //pre_binding1
// }
// bb3: {
// falseEdges -> [real: bb12, imaginary: bb4]; //pre_binding2
// falseEdges -> [real: bb11, imaginary: bb4]; //pre_binding2
// }
// bb4: {
// falseEdges -> [real: bb13, imaginary: bb5]; //pre_binding3
// falseEdges -> [real: bb12, imaginary: bb5]; //pre_binding3
// }
// bb5: {
// unreachable;
Expand All @@ -68,43 +68,43 @@ fn main() {
// bb7: {
// unreachable;
// }
// bb8: {
// ...
// return;
// }
// bb9: { // binding1 and guard
// bb8: { // binding1 and guard
// StorageLive(_6);
// _6 = &(((promoted[1]: std::option::Option<i32>) as Some).0: i32);
// _4 = &shallow (promoted[0]: std::option::Option<i32>);
// StorageLive(_7);
// _7 = const guard() -> [return: bb10, unwind: bb1];
// _7 = const guard() -> [return: bb9, unwind: bb1];
// }
// bb10: {
// bb9: {
// FakeRead(ForMatchGuard, _4);
// FakeRead(ForGuardBinding, _6);
// switchInt(move _7) -> [false: bb6, otherwise: bb11];
// switchInt(move _7) -> [false: bb6, otherwise: bb10];
// }
// bb11: {
// bb10: {
// StorageLive(_5);
// _5 = ((_2 as Some).0: i32);
// StorageLive(_8);
// _8 = _5;
// _1 = (const 1i32, move _8);
// StorageDead(_8);
// goto -> bb8;
// goto -> bb13;
// }
// bb12: {
// bb11: {
// StorageLive(_9);
// _9 = ((_2 as Some).0: i32);
// StorageLive(_10);
// _10 = _9;
// _1 = (const 2i32, move _10);
// StorageDead(_10);
// goto -> bb8;
// goto -> bb13;
// }
// bb13: {
// bb12: {
// _1 = (const 3i32, const 3i32);
// goto -> bb8;
// goto -> bb13;
// }
// bb13: {
// ...
// return;
// }
// END rustc.full_tested_match.QualifyAndPromoteConstants.after.mir
//
Expand All @@ -120,13 +120,13 @@ fn main() {
// resume;
// }
// bb2: {
// falseEdges -> [real: bb9, imaginary: bb3];
// falseEdges -> [real: bb8, imaginary: bb3];
// }
// bb3: {
// falseEdges -> [real: bb12, imaginary: bb4];
// falseEdges -> [real: bb11, imaginary: bb4];
// }
// bb4: {
// falseEdges -> [real: bb13, imaginary: bb5];
// falseEdges -> [real: bb12, imaginary: bb5];
// }
// bb5: {
// unreachable;
Expand All @@ -137,43 +137,43 @@ fn main() {
// bb7: {
// unreachable;
// }
// bb8: {
// ...
// return;
// }
// bb9: { // binding1 and guard
// bb8: { // binding1 and guard
// StorageLive(_6);
// _6 = &((_2 as Some).0: i32);
// _4 = &shallow _2;
// StorageLive(_7);
// _7 = const guard() -> [return: bb10, unwind: bb1];
// _7 = const guard() -> [return: bb9, unwind: bb1];
// }
// bb10: { // end of guard
// bb9: { // end of guard
// FakeRead(ForMatchGuard, _4);
// FakeRead(ForGuardBinding, _6);
// switchInt(move _7) -> [false: bb6, otherwise: bb11];
// switchInt(move _7) -> [false: bb6, otherwise: bb10];
// }
// bb11: { // arm1
// bb10: { // arm1
// StorageLive(_5);
// _5 = ((_2 as Some).0: i32);
// StorageLive(_8);
// _8 = _5;
// _1 = (const 1i32, move _8);
// StorageDead(_8);
// goto -> bb8;
// goto -> bb13;
// }
// bb12: { // arm2
// bb11: { // arm2
// _1 = (const 3i32, const 3i32);
// goto -> bb8;
// goto -> bb13;
// }
// bb13: { // binding3 and arm3
// bb12: { // binding3 and arm3
// StorageLive(_9);
// _9 = ((_2 as Some).0: i32);
// StorageLive(_10);
// _10 = _9;
// _1 = (const 2i32, move _10);
// StorageDead(_10);
// goto -> bb8;
// goto -> bb13;
// }
// bb13: {
// ...
// return;
// }
// END rustc.full_tested_match2.QualifyAndPromoteConstants.before.mir
//
Expand All @@ -189,79 +189,79 @@ fn main() {
// resume;
// }
// bb2: {
// falseEdges -> [real: bb10, imaginary: bb3]; //pre_binding1
// falseEdges -> [real: bb9, imaginary: bb3];
// }
// bb3: {
// falseEdges -> [real: bb13, imaginary: bb4]; //pre_binding2
// falseEdges -> [real: bb12, imaginary: bb4];
// }
// bb4: {
// falseEdges -> [real: bb14, imaginary: bb5]; //pre_binding3
// falseEdges -> [real: bb13, imaginary: bb5];
// }
// bb5: {
// falseEdges -> [real: bb17, imaginary: bb6]; //pre_binding4
// falseEdges -> [real: bb16, imaginary: bb6];
// }
// bb6: {
// unreachable;
// }
// bb7: { // to pre_binding2
// bb7: {
// falseEdges -> [real: bb3, imaginary: bb3];
// }
// bb8: { // to pre_binding4
// bb8: {
// falseEdges -> [real: bb5, imaginary: bb5];
// }
// bb9: {
// ...
// return;
// }
// bb10: { // binding1: Some(w) if guard()
// bb9: { // binding1: Some(w) if guard()
// StorageLive(_7);
// _7 = &((_2 as Some).0: i32);
// _5 = &shallow _2;
// StorageLive(_8);
// _8 = const guard() -> [return: bb11, unwind: bb1];
// _8 = const guard() -> [return: bb10, unwind: bb1];
// }
// bb11: { //end of guard
// bb10: { //end of guard
// FakeRead(ForMatchGuard, _5);
// FakeRead(ForGuardBinding, _7);
// switchInt(move _8) -> [false: bb7, otherwise: bb12];
// switchInt(move _8) -> [false: bb7, otherwise: bb11];
// }
// bb12: { // set up bindings for arm1
// bb11: { // set up bindings for arm1
// StorageLive(_6);
// _6 = ((_2 as Some).0: i32);
// _1 = const 1i32;
// goto -> bb9;
// goto -> bb17;
// }
// bb13: { // binding2 & arm2
// bb12: { // binding2 & arm2
// StorageLive(_9);
// _9 = _2;
// _1 = const 2i32;
// goto -> bb9;
// goto -> bb17;
// }
// bb14: { // binding3: Some(y) if guard2(y)
// bb13: { // binding3: Some(y) if guard2(y)
// StorageLive(_11);
// _11 = &((_2 as Some).0: i32);
// _5 = &shallow _2;
// StorageLive(_12);
// StorageLive(_13);
// _13 = (*_11);
// _12 = const guard2(move _13) -> [return: bb15, unwind: bb1];
// _12 = const guard2(move _13) -> [return: bb14, unwind: bb1];
// }
// bb15: { // end of guard2
// bb14: { // end of guard2
// StorageDead(_13);
// FakeRead(ForMatchGuard, _5);
// FakeRead(ForGuardBinding, _11);
// switchInt(move _12) -> [false: bb8, otherwise: bb16];
// switchInt(move _12) -> [false: bb8, otherwise: bb15];
// }
// bb16: { // binding4 & arm4
// bb15: { // binding4 & arm4
// StorageLive(_10);
// _10 = ((_2 as Some).0: i32);
// _1 = const 3i32;
// goto -> bb9;
// goto -> bb17;
// }
// bb17: {
// bb16: {
// StorageLive(_14);
// _14 = _2;
// _1 = const 4i32;
// goto -> bb9;
// goto -> bb17;
// }
// bb17: {
// ...
// return;
// }
// END rustc.main.QualifyAndPromoteConstants.before.mir
Loading

0 comments on commit 5ffc919

Please sign in to comment.