-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Rename UninhabitedEnumBranching
to UnreachableEnumBranching
#122225
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
6 commits
Select commit
Hold shift + click to select a range
8ddd966
Rename `UninhabitedEnumBranching` to `UnreachableEnumBranching`
dianqk df33e02
Add comments for `UnreachableEnumBranching`
dianqk a10d157
Addition of parentheses to clarify precedence
dianqk f8656ef
Update `unreachable_enum_default_branch.rs`
dianqk 102bda4
Remove restrictions on small enum statements such as `Order`, `Option…
dianqk ec313d1
Update the test case for `SimplifyCfg-after-unreachable-enum-branching`
dianqk 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
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
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
This file was deleted.
Oops, something went wrong.
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,43 @@ | ||
//@ compile-flags: -O | ||
|
||
#![crate_type = "lib"] | ||
|
||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] | ||
pub struct Int(u32); | ||
|
||
const A: Int = Int(201); | ||
const B: Int = Int(270); | ||
const C: Int = Int(153); | ||
|
||
// The code is from https://github.com/rust-lang/rust/issues/119520. | ||
// This code will basically turn into `matches!(x.partial_cmp(&A), Some(Greater | Equal))`. | ||
// The otherwise branch must be `Less`. | ||
// CHECK-LABEL: @implicit_match( | ||
// CHECK-SAME: [[TMP0:%.*]]) | ||
// CHECK-NEXT: start: | ||
// CHECK-NEXT: [[TMP1:%.*]] = add i32 [[TMP0]], -201 | ||
// CHECK-NEXT: icmp ult i32 [[TMP1]], 70 | ||
// CHECK-NEXT: icmp eq i32 [[TMP0]], 153 | ||
// CHECK-NEXT: [[SPEC_SELECT:%.*]] = or i1 | ||
// CHECK-NEXT: ret i1 [[SPEC_SELECT]] | ||
#[no_mangle] | ||
pub fn implicit_match(x: Int) -> bool { | ||
(x >= A && x <= B) | ||
|| x == C | ||
} | ||
|
||
// The code is from https://github.com/rust-lang/rust/issues/110097. | ||
// We expect it to generate the same optimized code as a full match. | ||
// CHECK-LABEL: @if_let( | ||
// CHECK-NEXT: start: | ||
// CHECK-NEXT: insertvalue | ||
// CHECK-NEXT: insertvalue | ||
// CHECK-NEXT: ret | ||
#[no_mangle] | ||
pub fn if_let(val: Result<i32, ()>) -> Result<i32, ()> { | ||
if let Ok(x) = val { | ||
Ok(x) | ||
} else { | ||
Err(()) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...plify_dead_blocks.assert_nonzero_nonmax.SimplifyCfg-after-unreachable-enum-branching.diff
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,33 @@ | ||
- // MIR for `assert_nonzero_nonmax` before SimplifyCfg-after-unreachable-enum-branching | ||
+ // MIR for `assert_nonzero_nonmax` after SimplifyCfg-after-unreachable-enum-branching | ||
|
||
fn assert_nonzero_nonmax(_1: u8) -> u8 { | ||
let mut _0: u8; | ||
|
||
bb0: { | ||
- switchInt(_1) -> [0: bb3, 1: bb2, 255: bb3, otherwise: bb4]; | ||
+ switchInt(_1) -> [0: bb2, 1: bb1, 255: bb2, otherwise: bb3]; | ||
} | ||
|
||
bb1: { | ||
- _0 = const 1_u8; | ||
- return; | ||
- } | ||
- | ||
- bb2: { | ||
_0 = const 2_u8; | ||
return; | ||
} | ||
|
||
- bb3: { | ||
+ bb2: { | ||
unreachable; | ||
} | ||
|
||
- bb4: { | ||
+ bb3: { | ||
_0 = _1; | ||
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,52 @@ | ||
//@ unit-test: SimplifyCfg-after-unreachable-enum-branching | ||
#![feature(custom_mir, core_intrinsics)] | ||
#![crate_type = "lib"] | ||
|
||
use std::intrinsics::mir::*; | ||
|
||
// Check that we correctly cleaned up the dead BB. | ||
// EMIT_MIR simplify_dead_blocks.assert_nonzero_nonmax.SimplifyCfg-after-unreachable-enum-branching.diff | ||
#[custom_mir(dialect = "runtime", phase = "post-cleanup")] | ||
pub unsafe fn assert_nonzero_nonmax(x: u8) -> u8 { | ||
// CHECK-LABEL: fn assert_nonzero_nonmax( | ||
// CHECK: bb0: { | ||
// CHECK-NEXT: switchInt({{.*}}) -> [0: [[unreachable:bb.*]], 1: [[retblock2:bb.*]], 255: [[unreachable:bb.*]], otherwise: [[retblock:bb.*]]]; | ||
// CHECK-NEXT: } | ||
// CHECK-NOT: _0 = const 1_u8; | ||
// CHECK: [[retblock2]]: { | ||
// CHECK-NEXT: _0 = const 2_u8; | ||
// CHECK-NEXT: return; | ||
// CHECK-NEXT: } | ||
// CHECK: [[unreachable]]: { | ||
// CHECK-NEXT: unreachable; | ||
// CHECK-NEXT: } | ||
// CHECK: [[retblock]]: { | ||
// CHECK-NEXT: _0 = _1; | ||
// CHECK-NEXT: return; | ||
// CHECK-NEXT: } | ||
mir!( | ||
{ | ||
match x { | ||
0 => unreachable, | ||
1 => retblock2, | ||
u8::MAX => unreachable, | ||
_ => retblock, | ||
} | ||
} | ||
deadRetblock1 = { | ||
RET = 1; | ||
Return() | ||
} | ||
retblock2 = { | ||
RET = 2; | ||
Return() | ||
} | ||
unreachable = { | ||
Unreachable() | ||
} | ||
retblock = { | ||
RET = x; | ||
Return() | ||
} | ||
) | ||
} |
25 changes: 0 additions & 25 deletions
25
...nreachable_blocks.assert_nonzero_nonmax.SimplifyCfg-after-uninhabited-enum-branching.diff
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
...fallthrough.UninhabitedEnumBranching.diff → ...fallthrough.UnreachableEnumBranching.diff
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
4 changes: 2 additions & 2 deletions
4
...fallthrough.UninhabitedEnumBranching.diff → ...fallthrough.UnreachableEnumBranching.diff
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
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.
The
allow(rustc::potential_query_instability)
should include a comment that the length of the list is known to be 1. Or use one of the exactly_one iterator adapaters.