-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Handle discriminant in DataflowConstProp #107411
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 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0d59b8c
Remove redundant test.
cjgillot cd3649b
Only exclude locals if the place is not indirect.
cjgillot 9a6c04f
Handle discriminants in dataflow-const-prop.
cjgillot c48756c
Limit creation of tracked place directly.
cjgillot 9af191f
Improve value_analysis API.
cjgillot 67a8c16
Complete for_each_aliasing_place.
cjgillot df889c9
Rename assign_idx methods.
cjgillot 09797a4
Typo.
cjgillot 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
Large diffs are not rendered by default.
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
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
26 changes: 26 additions & 0 deletions
26
tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.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,26 @@ | ||
- // MIR for `mutate_discriminant` before DataflowConstProp | ||
+ // MIR for `mutate_discriminant` after DataflowConstProp | ||
|
||
fn mutate_discriminant() -> u8 { | ||
let mut _0: u8; // return place in scope 0 at $DIR/enum.rs:+0:29: +0:31 | ||
let mut _1: std::option::Option<NonZeroUsize>; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL | ||
let mut _2: isize; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL | ||
|
||
bb0: { | ||
discriminant(_1) = 1; // scope 0 at $DIR/enum.rs:+4:13: +4:34 | ||
(((_1 as variant#1).0: NonZeroUsize).0: usize) = const 0_usize; // scope 0 at $DIR/enum.rs:+6:13: +6:64 | ||
_2 = discriminant(_1); // scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL | ||
switchInt(_2) -> [0: bb1, otherwise: bb2]; // scope 0 at $DIR/enum.rs:+9:13: +12:14 | ||
} | ||
|
||
bb1: { | ||
_0 = const 1_u8; // scope 0 at $DIR/enum.rs:+15:13: +15:20 | ||
return; // scope 0 at $DIR/enum.rs:+16:13: +16:21 | ||
} | ||
|
||
bb2: { | ||
_0 = const 2_u8; // scope 0 at $DIR/enum.rs:+19:13: +19:20 | ||
unreachable; // scope 0 at $DIR/enum.rs:+20:13: +20:26 | ||
} | ||
} | ||
|
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 |
---|---|---|
@@ -1,13 +1,52 @@ | ||
// unit-test: DataflowConstProp | ||
|
||
// Not trackable, because variants could be aliased. | ||
#![feature(custom_mir, core_intrinsics, rustc_attrs)] | ||
|
||
use std::intrinsics::mir::*; | ||
|
||
enum E { | ||
V1(i32), | ||
V2(i32) | ||
} | ||
|
||
// EMIT_MIR enum.main.DataflowConstProp.diff | ||
fn main() { | ||
// EMIT_MIR enum.simple.DataflowConstProp.diff | ||
fn simple() { | ||
let e = E::V1(0); | ||
let x = match e { E::V1(x) => x, E::V2(x) => x }; | ||
} | ||
|
||
#[rustc_layout_scalar_valid_range_start(1)] | ||
#[rustc_nonnull_optimization_guaranteed] | ||
struct NonZeroUsize(usize); | ||
|
||
// EMIT_MIR enum.mutate_discriminant.DataflowConstProp.diff | ||
#[custom_mir(dialect = "runtime", phase = "post-cleanup")] | ||
fn mutate_discriminant() -> u8 { | ||
mir!( | ||
let x: Option<NonZeroUsize>; | ||
{ | ||
SetDiscriminant(x, 1); | ||
// This assignment overwrites the niche in which the discriminant is stored. | ||
place!(Field(Field(Variant(x, 1), 0), 0)) = 0_usize; | ||
// So we cannot know the value of this discriminant. | ||
let a = Discriminant(x); | ||
match a { | ||
0 => bb1, | ||
_ => bad, | ||
} | ||
} | ||
bb1 = { | ||
RET = 1; | ||
Return() | ||
} | ||
bad = { | ||
RET = 2; | ||
Unreachable() | ||
} | ||
) | ||
} | ||
|
||
fn main() { | ||
simple(); | ||
mutate_discriminant(); | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.