forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support pretty printing of invalid constants
Make it possible to pretty print invalid constants by introducing a fallible variant of `destructure_const` and falling back to debug formatting when it fails.
- Loading branch information
Showing
7 changed files
with
117 additions
and
29 deletions.
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); | ||
} |