Render pattern types nicely in mir dumps by oli-obk · Pull Request #136176 · rust-lang/rust (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation6 Commits2 Checks6 Files changed

Conversation

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

[ Show hidden characters]({{ revealButtonHref }})

oli-obk

avoid falling through to the fallback rendering that just does a hex dump

r? @scottmcm

best reviewed commit by commit

@oli-obk

@oli-obk

@rustbot rustbot added S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

T-compiler

Relevant to the compiler team, which will review and decide on the PR/issue.

labels

Jan 28, 2025

oli-obk

scope 1 {
debug x => const 2_u32 is 1..=;
scope 2 {
debug y => const 0_u32 is 1..=;

Choose a reason for hiding this comment

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

This one is fun. We do render as transmute for other things that are invalid (e.g. chars that aren't valid chars, or bools that aren't 0 or 1), but it's harder to do this here without running validation on it... and I'm not sure all the extra logic for doing so would be worth it.

compiler-errors

Choose a reason for hiding this comment

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

Would be nice if we had some way of statically validating that a ScalarInt is valid in a Layout for this exact check (and it may be useful elsewhere in the compiler).

But looks fine for now.

@compiler-errors

r? compiler-errors @bors r+ rollup

@bors

📌 Commit fd6713f has been approved by compiler-errors

It is now in the queue for this repository.

@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

Jan 28, 2025

scottmcm

fn main() {
// CHECK: debug x => const {transmute(0x00000002): (u32) is 1..=}
let x: pattern_type!(u32 is 1..) = unsafe { std::mem::transmute(2) };
// CHECK: debug y => const {transmute(0x00000000): (u32) is 1..=}

Choose a reason for hiding this comment

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

Hmm, definitely interesting. I guess this is falling under the "compilation doesn't have to detect UB" rule?

Choose a reason for hiding this comment

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

Well... we kinda do because there could be no UB, just const prop crossing a check that prevents UB. So this could happen in dead code. So there is an argument for showing that in pretty printing. I'll see if I can pull out the logic we use in const validation in a way that makes it reusable here

Zalathar added a commit to Zalathar/rust that referenced this pull request

Jan 29, 2025

@Zalathar

…ompiler-errors

Render pattern types nicely in mir dumps

avoid falling through to the fallback rendering that just does a hex dump

r? @scottmcm

best reviewed commit by commit

bors added a commit to rust-lang-ci/rust that referenced this pull request

Jan 29, 2025

@bors

Rollup of 9 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

bors added a commit to rust-lang-ci/rust that referenced this pull request

Jan 29, 2025

@bors

Rollup of 9 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request

Jan 29, 2025

@rust-timer

Rollup merge of rust-lang#136176 - oli-obk:pattern-type-mir-opts, r=compiler-errors

Render pattern types nicely in mir dumps

avoid falling through to the fallback rendering that just does a hex dump

r? @scottmcm

best reviewed commit by commit

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Feb 3, 2025

@matthiaskrgr

Pretty print pattern type values with transmute if they don't satisfy their pattern

Instead of printing 0_u32 is 1.., we now print the default fallback rendering that we also use for invalid bools, chars, ...: {transmute(0x00000000): (u32) is 1..=}.

These cases can occur in mir dumps when const prop propagates a constant across a safety check that would prevent the actually UB value from existing. That's fine though, as it's dead code and we always need to allow UB in dead code.

follow-up to rust-lang#136176

cc @compiler-errors @scottmcm

r? @RalfJung because of the interpreter changes

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Feb 3, 2025

@matthiaskrgr

Pretty print pattern type values with transmute if they don't satisfy their pattern

Instead of printing 0_u32 is 1.., we now print the default fallback rendering that we also use for invalid bools, chars, ...: {transmute(0x00000000): (u32) is 1..=}.

These cases can occur in mir dumps when const prop propagates a constant across a safety check that would prevent the actually UB value from existing. That's fine though, as it's dead code and we always need to allow UB in dead code.

follow-up to rust-lang#136176

cc @compiler-errors @scottmcm

r? @RalfJung because of the interpreter changes

jieyouxu added a commit to jieyouxu/rust that referenced this pull request

Feb 3, 2025

@jieyouxu

Pretty print pattern type values with transmute if they don't satisfy their pattern

Instead of printing 0_u32 is 1.., we now print the default fallback rendering that we also use for invalid bools, chars, ...: {transmute(0x00000000): (u32) is 1..=}.

These cases can occur in mir dumps when const prop propagates a constant across a safety check that would prevent the actually UB value from existing. That's fine though, as it's dead code and we always need to allow UB in dead code.

follow-up to rust-lang#136176

cc @compiler-errors @scottmcm

r? @RalfJung because of the interpreter changes

workingjubilee added a commit to workingjubilee/rustc that referenced this pull request

Feb 6, 2025

@workingjubilee

Pretty print pattern type values with transmute if they don't satisfy their pattern

Instead of printing 0_u32 is 1.., we now print the default fallback rendering that we also use for invalid bools, chars, ...: {transmute(0x00000000): (u32) is 1..=}.

These cases can occur in mir dumps when const prop propagates a constant across a safety check that would prevent the actually UB value from existing. That's fine though, as it's dead code and we always need to allow UB in dead code.

follow-up to rust-lang#136176

cc @compiler-errors @scottmcm

r? @RalfJung because of the interpreter changes

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Feb 6, 2025

@matthiaskrgr

Pretty print pattern type values with transmute if they don't satisfy their pattern

Instead of printing 0_u32 is 1.., we now print the default fallback rendering that we also use for invalid bools, chars, ...: {transmute(0x00000000): (u32) is 1..=}.

These cases can occur in mir dumps when const prop propagates a constant across a safety check that would prevent the actually UB value from existing. That's fine though, as it's dead code and we always need to allow UB in dead code.

follow-up to rust-lang#136176

cc @compiler-errors @scottmcm

r? @RalfJung because of the interpreter changes

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request

Feb 6, 2025

@rust-timer

Rollup merge of rust-lang#136235 - oli-obk:transmuty-pat-tys, r=RalfJung

Pretty print pattern type values with transmute if they don't satisfy their pattern

Instead of printing 0_u32 is 1.., we now print the default fallback rendering that we also use for invalid bools, chars, ...: {transmute(0x00000000): (u32) is 1..=}.

These cases can occur in mir dumps when const prop propagates a constant across a safety check that would prevent the actually UB value from existing. That's fine though, as it's dead code and we always need to allow UB in dead code.

follow-up to rust-lang#136176

cc @compiler-errors @scottmcm

r? @RalfJung because of the interpreter changes

github-actions bot pushed a commit to rust-lang/miri that referenced this pull request

Feb 7, 2025

@matthiaskrgr

Pretty print pattern type values with transmute if they don't satisfy their pattern

Instead of printing 0_u32 is 1.., we now print the default fallback rendering that we also use for invalid bools, chars, ...: {transmute(0x00000000): (u32) is 1..=}.

These cases can occur in mir dumps when const prop propagates a constant across a safety check that would prevent the actually UB value from existing. That's fine though, as it's dead code and we always need to allow UB in dead code.

follow-up to rust-lang/rust#136176

cc @compiler-errors @scottmcm

r? @RalfJung because of the interpreter changes

github-actions bot pushed a commit to tautschnig/verify-rust-std that referenced this pull request

Mar 11, 2025

@bors

Rollup of 9 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

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.