Skip to content
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 1 commit into from
Feb 16, 2022
Merged

Conversation

tmiasko
Copy link
Contributor

@tmiasko tmiasko commented Feb 15, 2022

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.

Closes #93688.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Feb 15, 2022
@rust-highfive
Copy link
Collaborator

Some changes occured to the CTFE / Miri engine

cc @rust-lang/miri

@rust-highfive
Copy link
Collaborator

r? @oli-obk

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 15, 2022
@oli-obk
Copy link
Contributor

oli-obk commented Feb 15, 2022

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Feb 15, 2022

📌 Commit a8bc3b3c353b479f8063f41bb620e3611a3e2fa3 has been approved by oli-obk

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 15, 2022
@tmiasko
Copy link
Contributor Author

tmiasko commented Feb 15, 2022

Rebased to resolve conflicts with #93148.

@bors r=oli-obk

@bors
Copy link
Contributor

bors commented Feb 15, 2022

📌 Commit ae5c039c11ca544f331202d847fc55ab4a587a02 has been approved by oli-obk

bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 15, 2022
…askrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#93899 (Describe VecDeque with more consistent names)
 - rust-lang#93949 (Add basic platform support to library/{panic_}unwind for m68k)
 - rust-lang#93999 (suggest using raw strings when invalid escapes appear in literals)
 - rust-lang#94001 (llvm: migrate to new parameter-bearing uwtable attr)
 - rust-lang#94014 (Move transmute_undefined_repr back to nursery)

Failed merges:

 - rust-lang#94020 (Support pretty printing of invalid constants)

r? `@ghost`
`@rustbot` modify labels: rollup
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this change?

Copy link
Contributor

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

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 ConstValue(Scalar(0x02): Option::<()>); // scope 1 at $DIR/invalid_constant.rs:16:5: 16:12
Copy link
Member

@RalfJung RalfJung Feb 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const ConstValue seems somewhat redundant, if we always have that const prefix maybe we should make this just const Scalar(0x02): Option::<()>? Or maybe also somehow indicate that this value is invalid and a "fallback" printing was used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped ConstValue part, matching the following fall back format instead of the preceding verbose one.

@oli-obk
Copy link
Contributor

oli-obk commented Feb 15, 2022

@bors r- the output could be adjusted a bit

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 15, 2022
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.
@oli-obk
Copy link
Contributor

oli-obk commented Feb 16, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Feb 16, 2022

📌 Commit 92d20c4 has been approved by oli-obk

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 16, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 16, 2022
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.

Closes rust-lang#93688.
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 16, 2022
…askrgr

Rollup of 10 pull requests

Successful merges:

 - rust-lang#92366 (Resolve concern of `derive_default_enum`)
 - rust-lang#93382 (Add a bit more padding in search box)
 - rust-lang#93962 (Make [u8]::cmp implementation branchless)
 - rust-lang#94015 (rustdoc --check option documentation)
 - rust-lang#94017 (Clarify confusing UB statement in MIR)
 - rust-lang#94020 (Support pretty printing of invalid constants)
 - rust-lang#94027 (Update browser UI test version)
 - rust-lang#94037 (Fix inconsistent symbol mangling with -Zverbose)
 - rust-lang#94045 (Update books)
 - rust-lang#94054 (:arrow_up: rust-analyzer)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE: enum value has invalid tag, no-core-2.rs -Zmir-opt-level=3 --emit=mir -Zdump-mir=all
6 participants