-
Notifications
You must be signed in to change notification settings - Fork 13.3k
match lowering: sort Eq
candidates in the failure case too
#122459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
118 changes: 118 additions & 0 deletions
118
tests/mir-opt/building/match/sort_candidates.constant_eq.SimplifyCfg-initial.after.mir
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// MIR for `constant_eq` after SimplifyCfg-initial | ||
|
||
fn constant_eq(_1: &str, _2: bool) -> u32 { | ||
debug s => _1; | ||
debug b => _2; | ||
let mut _0: u32; | ||
let mut _3: (&str, bool); | ||
let mut _4: &str; | ||
let mut _5: bool; | ||
let mut _6: bool; | ||
let mut _7: bool; | ||
let mut _8: &&str; | ||
let mut _9: &bool; | ||
let mut _10: bool; | ||
|
||
bb0: { | ||
StorageLive(_3); | ||
StorageLive(_4); | ||
_4 = _1; | ||
StorageLive(_5); | ||
_5 = _2; | ||
_3 = (move _4, move _5); | ||
StorageDead(_5); | ||
StorageDead(_4); | ||
PlaceMention(_3); | ||
_7 = <str as PartialEq>::eq((_3.0: &str), const "a") -> [return: bb11, unwind: bb19]; | ||
} | ||
|
||
bb1: { | ||
switchInt((_3.1: bool)) -> [0: bb2, otherwise: bb3]; | ||
} | ||
|
||
bb2: { | ||
_0 = const 5_u32; | ||
goto -> bb18; | ||
} | ||
|
||
bb3: { | ||
falseEdge -> [real: bb17, imaginary: bb2]; | ||
} | ||
|
||
bb4: { | ||
falseEdge -> [real: bb12, imaginary: bb9]; | ||
} | ||
|
||
bb5: { | ||
switchInt((_3.1: bool)) -> [0: bb1, otherwise: bb6]; | ||
} | ||
|
||
bb6: { | ||
falseEdge -> [real: bb16, imaginary: bb3]; | ||
} | ||
|
||
bb7: { | ||
_6 = <str as PartialEq>::eq((_3.0: &str), const "b") -> [return: bb10, unwind: bb19]; | ||
} | ||
|
||
bb8: { | ||
switchInt((_3.1: bool)) -> [0: bb1, otherwise: bb9]; | ||
} | ||
|
||
bb9: { | ||
falseEdge -> [real: bb15, imaginary: bb6]; | ||
} | ||
|
||
bb10: { | ||
switchInt(move _6) -> [0: bb1, otherwise: bb8]; | ||
} | ||
|
||
bb11: { | ||
switchInt(move _7) -> [0: bb7, otherwise: bb4]; | ||
} | ||
|
||
bb12: { | ||
_8 = &fake (_3.0: &str); | ||
_9 = &fake (_3.1: bool); | ||
StorageLive(_10); | ||
_10 = const true; | ||
switchInt(move _10) -> [0: bb14, otherwise: bb13]; | ||
} | ||
|
||
bb13: { | ||
StorageDead(_10); | ||
FakeRead(ForMatchGuard, _8); | ||
FakeRead(ForMatchGuard, _9); | ||
_0 = const 1_u32; | ||
goto -> bb18; | ||
} | ||
|
||
bb14: { | ||
StorageDead(_10); | ||
falseEdge -> [real: bb5, imaginary: bb9]; | ||
} | ||
|
||
bb15: { | ||
_0 = const 2_u32; | ||
goto -> bb18; | ||
} | ||
|
||
bb16: { | ||
_0 = const 3_u32; | ||
goto -> bb18; | ||
} | ||
|
||
bb17: { | ||
_0 = const 4_u32; | ||
goto -> bb18; | ||
} | ||
|
||
bb18: { | ||
StorageDead(_3); | ||
return; | ||
} | ||
|
||
bb19 (cleanup): { | ||
resume; | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
tests/mir-opt/building/match/sort_candidates.disjoint_ranges.SimplifyCfg-initial.after.mir
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// MIR for `disjoint_ranges` after SimplifyCfg-initial | ||
|
||
fn disjoint_ranges(_1: i32, _2: bool) -> u32 { | ||
debug x => _1; | ||
debug b => _2; | ||
let mut _0: u32; | ||
let mut _3: bool; | ||
let mut _4: bool; | ||
let mut _5: bool; | ||
let mut _6: bool; | ||
let mut _7: &i32; | ||
let mut _8: bool; | ||
|
||
bb0: { | ||
PlaceMention(_1); | ||
_5 = Le(const 0_i32, _1); | ||
switchInt(move _5) -> [0: bb3, otherwise: bb8]; | ||
} | ||
|
||
bb1: { | ||
_0 = const 3_u32; | ||
goto -> bb14; | ||
} | ||
|
||
bb2: { | ||
falseEdge -> [real: bb9, imaginary: bb4]; | ||
} | ||
|
||
bb3: { | ||
_3 = Le(const 10_i32, _1); | ||
switchInt(move _3) -> [0: bb5, otherwise: bb7]; | ||
} | ||
|
||
bb4: { | ||
falseEdge -> [real: bb12, imaginary: bb6]; | ||
} | ||
|
||
bb5: { | ||
switchInt(_1) -> [4294967295: bb6, otherwise: bb1]; | ||
} | ||
|
||
bb6: { | ||
falseEdge -> [real: bb13, imaginary: bb1]; | ||
} | ||
|
||
bb7: { | ||
_4 = Le(_1, const 20_i32); | ||
switchInt(move _4) -> [0: bb5, otherwise: bb4]; | ||
} | ||
|
||
bb8: { | ||
_6 = Lt(_1, const 10_i32); | ||
switchInt(move _6) -> [0: bb3, otherwise: bb2]; | ||
} | ||
|
||
bb9: { | ||
_7 = &fake _1; | ||
StorageLive(_8); | ||
_8 = _2; | ||
switchInt(move _8) -> [0: bb11, otherwise: bb10]; | ||
} | ||
|
||
bb10: { | ||
StorageDead(_8); | ||
FakeRead(ForMatchGuard, _7); | ||
_0 = const 0_u32; | ||
goto -> bb14; | ||
} | ||
|
||
bb11: { | ||
StorageDead(_8); | ||
falseEdge -> [real: bb1, imaginary: bb4]; | ||
} | ||
|
||
bb12: { | ||
_0 = const 1_u32; | ||
goto -> bb14; | ||
} | ||
|
||
bb13: { | ||
_0 = const 2_u32; | ||
goto -> bb14; | ||
} | ||
|
||
bb14: { | ||
return; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Check specific cases of sorting candidates in match lowering. | ||
#![feature(exclusive_range_pattern)] | ||
|
||
// EMIT_MIR sort_candidates.constant_eq.SimplifyCfg-initial.after.mir | ||
fn constant_eq(s: &str, b: bool) -> u32 { | ||
// Check that we only test "a" once | ||
|
||
// CHECK-LABEL: fn constant_eq( | ||
// CHECK: bb0: { | ||
// CHECK: [[a:_.*]] = const "a"; | ||
// CHECK-NOT: {{_.*}} = const "a"; | ||
match (s, b) { | ||
("a", _) if true => 1, | ||
("b", true) => 2, | ||
("a", true) => 3, | ||
(_, true) => 4, | ||
_ => 5, | ||
} | ||
} | ||
|
||
// EMIT_MIR sort_candidates.disjoint_ranges.SimplifyCfg-initial.after.mir | ||
fn disjoint_ranges(x: i32, b: bool) -> u32 { | ||
// When `(0..=10).contains(x) && !b`, we should jump to the last arm without testing the two | ||
// other candidates. | ||
|
||
// CHECK-LABEL: fn disjoint_ranges( | ||
// CHECK: debug b => _2; | ||
// CHECK: bb0: { | ||
// CHECK: switchInt(_2) -> [0: [[jump:bb.*]], otherwise: {{bb.*}}]; | ||
// CHECK: [[jump]]: { | ||
// CHECK-NEXT: _0 = const 3_u32; | ||
// CHECK-NEXT: return; | ||
match x { | ||
0..10 if b => 0, | ||
10..=20 => 1, | ||
-1 => 2, | ||
_ => 3, | ||
} | ||
} | ||
|
||
fn main() {} |
106 changes: 0 additions & 106 deletions
106
tests/mir-opt/match_test.main.SimplifyCfg-initial.after.mir
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer keeping them separate because the fully_matched logic is already not easy to follow across the function