-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Support pretty printing of invalid constants #94020
Merged
Merged
Changes from all commits
Commits
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 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 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 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 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 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
55 changes: 55 additions & 0 deletions
55
src/test/mir-opt/const_prop/invalid_constant.main.ConstProp.diff
This file contains 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,55 @@ | ||
- // MIR for `main` before ConstProp | ||
+ // MIR for `main` after ConstProp | ||
|
||
fn main() -> () { | ||
let mut _0: (); // return place in scope 0 at $DIR/invalid_constant.rs:15:11: 15:11 | ||
let _1: std::option::Option<()>; // in scope 0 at $DIR/invalid_constant.rs:16:5: 16:12 | ||
let mut _2: std::option::Option<std::option::Option<()>>; // in scope 0 at $DIR/invalid_constant.rs:16:7: 16:11 | ||
scope 1 (inlined f) { // at $DIR/invalid_constant.rs:16:5: 16:12 | ||
debug x => _2; // in scope 1 at $DIR/invalid_constant.rs:16:5: 16:12 | ||
let mut _3: isize; // in scope 1 at $DIR/invalid_constant.rs:16:5: 16:12 | ||
let _4: std::option::Option<()>; // in scope 1 at $DIR/invalid_constant.rs:16:5: 16:12 | ||
scope 2 { | ||
debug y => _4; // in scope 2 at $DIR/invalid_constant.rs:16:5: 16:12 | ||
} | ||
} | ||
|
||
bb0: { | ||
discriminant(_2) = 0; // scope 0 at $DIR/invalid_constant.rs:16:7: 16:11 | ||
- _3 = discriminant(_2); // scope 1 at $DIR/invalid_constant.rs:16:5: 16:12 | ||
- switchInt(move _3) -> [0_isize: bb3, otherwise: bb2]; // scope 1 at $DIR/invalid_constant.rs:16:5: 16:12 | ||
+ _3 = const 0_isize; // scope 1 at $DIR/invalid_constant.rs:16:5: 16:12 | ||
+ switchInt(const 0_isize) -> [0_isize: bb3, otherwise: bb2]; // scope 1 at $DIR/invalid_constant.rs:16:5: 16:12 | ||
} | ||
|
||
bb1: { | ||
nop; // scope 0 at $DIR/invalid_constant.rs:15:11: 17:2 | ||
return; // scope 0 at $DIR/invalid_constant.rs:17:2: 17:2 | ||
} | ||
|
||
bb2: { | ||
- _4 = ((_2 as Some).0: std::option::Option<()>); // scope 1 at $DIR/invalid_constant.rs:16:5: 16:12 | ||
- _1 = _4; // scope 2 at $DIR/invalid_constant.rs:16:5: 16:12 | ||
+ _4 = const Scalar(0x02): Option::<()>; // scope 1 at $DIR/invalid_constant.rs:16:5: 16:12 | ||
+ // ty::Const | ||
+ // + ty: std::option::Option<()> | ||
+ // + val: Value(Scalar(0x02)) | ||
+ // mir::Constant | ||
+ // + span: $DIR/invalid_constant.rs:16:5: 16:12 | ||
+ // + literal: Const { ty: std::option::Option<()>, val: Value(Scalar(0x02)) } | ||
+ _1 = const Scalar(0x02): Option::<()>; // scope 2 at $DIR/invalid_constant.rs:16:5: 16:12 | ||
+ // ty::Const | ||
+ // + ty: std::option::Option<()> | ||
+ // + val: Value(Scalar(0x02)) | ||
+ // mir::Constant | ||
+ // + span: $DIR/invalid_constant.rs:16:5: 16:12 | ||
+ // + literal: Const { ty: std::option::Option<()>, val: Value(Scalar(0x02)) } | ||
goto -> bb1; // scope 0 at $DIR/invalid_constant.rs:10:20: 10:21 | ||
} | ||
|
||
bb3: { | ||
discriminant(_1) = 0; // scope 1 at $DIR/invalid_constant.rs:16:5: 16:12 | ||
goto -> bb1; // scope 0 at $DIR/invalid_constant.rs:9:17: 9:21 | ||
} | ||
} | ||
|
This file contains 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,17 @@ | ||
// Verify that we can pretty print invalid constant introduced | ||
// by constant propagation. Regression test for issue #93688. | ||
// | ||
// compile-flags: -Copt-level=0 -Zinline-mir | ||
|
||
#[inline(always)] | ||
pub fn f(x: Option<Option<()>>) -> Option<()> { | ||
match x { | ||
None => None, | ||
Some(y) => y, | ||
} | ||
} | ||
|
||
// EMIT_MIR invalid_constant.main.ConstProp.diff | ||
fn main() { | ||
f(None); | ||
} |
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.
Why does this change?
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.
That's just the optimization changing the mir. This is a diff of a diff