Skip to content

Commit

Permalink
Sort Eq candidates in the failure case too
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Mar 13, 2024
1 parent b9d4447 commit 9f16356
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 51 deletions.
14 changes: 8 additions & 6 deletions compiler/rustc_mir_build/src/build/matches/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,12 +649,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
}

// FIXME(#29623): return `Some(1)` when the values are different.
(TestKind::Eq { value: test_val, .. }, TestCase::Constant { value: case_val })
if test_val == case_val =>
{
fully_matched = true;
Some(TestBranch::Success)
(TestKind::Eq { value: test_val, .. }, TestCase::Constant { value: case_val }) => {
if test_val == case_val {
fully_matched = true;
Some(TestBranch::Success)
} else {
fully_matched = false;
Some(TestBranch::Failure)
}
}

(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ fn constant_eq(_1: &str, _2: bool) -> u32 {
let mut _5: bool;
let mut _6: bool;
let mut _7: bool;
let mut _8: bool;
let mut _9: &&str;
let mut _10: &bool;
let mut _11: bool;
let mut _8: &&str;
let mut _9: &bool;
let mut _10: bool;

bb0: {
StorageLive(_3);
Expand All @@ -24,104 +23,96 @@ fn constant_eq(_1: &str, _2: bool) -> u32 {
StorageDead(_5);
StorageDead(_4);
PlaceMention(_3);
_8 = <str as PartialEq>::eq((_3.0: &str), const "a") -> [return: bb13, unwind: bb21];
_7 = <str as PartialEq>::eq((_3.0: &str), const "a") -> [return: bb11, unwind: bb19];
}

bb1: {
_7 = <str as PartialEq>::eq((_3.0: &str), const "b") -> [return: bb11, unwind: bb21];
switchInt((_3.1: bool)) -> [0: bb2, otherwise: bb3];
}

bb2: {
_6 = <str as PartialEq>::eq((_3.0: &str), const "a") -> [return: bb8, unwind: bb21];
_0 = const 5_u32;
goto -> bb18;
}

bb3: {
switchInt((_3.1: bool)) -> [0: bb4, otherwise: bb5];
falseEdge -> [real: bb17, imaginary: bb2];
}

bb4: {
_0 = const 5_u32;
goto -> bb20;
falseEdge -> [real: bb12, imaginary: bb9];
}

bb5: {
falseEdge -> [real: bb19, imaginary: bb4];
switchInt((_3.1: bool)) -> [0: bb1, otherwise: bb6];
}

bb6: {
switchInt((_3.1: bool)) -> [0: bb3, otherwise: bb7];
falseEdge -> [real: bb16, imaginary: bb3];
}

bb7: {
falseEdge -> [real: bb18, imaginary: bb5];
_6 = <str as PartialEq>::eq((_3.0: &str), const "b") -> [return: bb10, unwind: bb19];
}

bb8: {
switchInt(move _6) -> [0: bb3, otherwise: bb6];
switchInt((_3.1: bool)) -> [0: bb1, otherwise: bb9];
}

bb9: {
switchInt((_3.1: bool)) -> [0: bb2, otherwise: bb10];
falseEdge -> [real: bb15, imaginary: bb6];
}

bb10: {
falseEdge -> [real: bb17, imaginary: bb7];
switchInt(move _6) -> [0: bb1, otherwise: bb8];
}

bb11: {
switchInt(move _7) -> [0: bb2, otherwise: bb9];
switchInt(move _7) -> [0: bb7, otherwise: bb4];
}

bb12: {
falseEdge -> [real: bb14, imaginary: bb10];
_8 = &fake (_3.0: &str);
_9 = &fake (_3.1: bool);
StorageLive(_10);
_10 = const true;
switchInt(move _10) -> [0: bb14, otherwise: bb13];
}

bb13: {
switchInt(move _8) -> [0: bb1, otherwise: bb12];
}

bb14: {
_9 = &fake (_3.0: &str);
_10 = &fake (_3.1: bool);
StorageLive(_11);
_11 = const true;
switchInt(move _11) -> [0: bb16, otherwise: bb15];
}

bb15: {
StorageDead(_11);
StorageDead(_10);
FakeRead(ForMatchGuard, _8);
FakeRead(ForMatchGuard, _9);
FakeRead(ForMatchGuard, _10);
_0 = const 1_u32;
goto -> bb20;
goto -> bb18;
}

bb16: {
StorageDead(_11);
falseEdge -> [real: bb1, imaginary: bb10];
bb14: {
StorageDead(_10);
falseEdge -> [real: bb5, imaginary: bb9];
}

bb17: {
bb15: {
_0 = const 2_u32;
goto -> bb20;
goto -> bb18;
}

bb18: {
bb16: {
_0 = const 3_u32;
goto -> bb20;
goto -> bb18;
}

bb19: {
bb17: {
_0 = const 4_u32;
goto -> bb20;
goto -> bb18;
}

bb20: {
bb18: {
StorageDead(_3);
return;
}

bb21 (cleanup): {
bb19 (cleanup): {
resume;
}
}
2 changes: 1 addition & 1 deletion tests/mir-opt/building/match/sort_candidates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// EMIT_MIR sort_candidates.constant_eq.SimplifyCfg-initial.after.mir
fn constant_eq(s: &str, b: bool) -> u32 {
// For now we test "a" twice.
// Check that we only test "a" once
match (s, b) {
("a", _) if true => 1,
("b", true) => 2,
Expand Down

0 comments on commit 9f16356

Please sign in to comment.