Skip to content

Render pattern types nicely in mir dumps - #136176

Merged
bors merged 2 commits into
rust-lang:masterfrom
oli-obk:pattern-type-mir-opts
Jan 29, 2025
Merged

Render pattern types nicely in mir dumps#136176
bors merged 2 commits into
rust-lang:masterfrom
oli-obk:pattern-type-mir-opts

Conversation

@oli-obk

Copy link
Copy Markdown
Contributor

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

r? @scottmcm

best reviewed commit by commit

@rustbotrustbot 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
scope 1 {
debug x => const 2_u32 is 1..=;
scope 2 {
debug y => const 0_u32 is 1..=;

@oli-obkoli-obkJan 28, 2025

Copy link
Copy Markdown
ContributorAuthor

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-errorscompiler-errors left a comment

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

r? compiler-errors @bors r+ rollup

@bors

bors commented Jan 28, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit fd6713f has been approved by compiler-errors

It is now in the queue for this repository.

@borsbors 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
Comment threadtests/mir-opt/pattern_types.rs Outdated
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..=}

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
ContributorAuthor

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
…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
@ZalatharZalathar mentioned this pull request Jan 29, 2025
@fmeasefmease mentioned this pull request Jan 29, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 29, 2025
Rollup of 9 pull requests
Successful merges:
- rust-lang#136121 (Deduplicate operand creation between scalars, non-scalars and string patterns)
- rust-lang#136134 (Fix SIMD codegen tests on LLVM 20)
- rust-lang#136153 (Locate asan-odr-win with other sanitizer tests)
- rust-lang#136161 (rustdoc: add nobuild typescript checking to our JS)
- rust-lang#136166 (interpret: is_alloc_live: check global allocs last)
- rust-lang#136168 (GCI: Don't try to eval / collect mono items inside overly generic free const items)
- rust-lang#136170 (Reject unsound toggling of Arm atomics-32 target feature)
- rust-lang#136176 (Render pattern types nicely in mir dumps)
- rust-lang#136186 (uefi: process: Fix args)
r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 29, 2025
Rollup of 9 pull requests
Successful merges:
- rust-lang#136121 (Deduplicate operand creation between scalars, non-scalars and string patterns)
- rust-lang#136134 (Fix SIMD codegen tests on LLVM 20)
- rust-lang#136153 (Locate asan-odr-win with other sanitizer tests)
- rust-lang#136161 (rustdoc: add nobuild typescript checking to our JS)
- rust-lang#136166 (interpret: is_alloc_live: check global allocs last)
- rust-lang#136168 (GCI: Don't try to eval / collect mono items inside overly generic free const items)
- rust-lang#136170 (Reject unsound toggling of Arm atomics-32 target feature)
- rust-lang#136176 (Render pattern types nicely in mir dumps)
- rust-lang#136186 (uefi: process: Fix args)
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit f49ad60 into rust-lang:masterJan 29, 2025
@rustbotrustbot added this to the 1.86.0 milestone Jan 29, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 29, 2025
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
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
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
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
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
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
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-actionsBot pushed a commit to rust-lang/miri that referenced this pull request Feb 7, 2025
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-actionsBot pushed a commit to tautschnig/verify-rust-std that referenced this pull request Mar 11, 2025
Rollup of 9 pull requests
Successful merges:
- rust-lang#136121 (Deduplicate operand creation between scalars, non-scalars and string patterns)
- rust-lang#136134 (Fix SIMD codegen tests on LLVM 20)
- rust-lang#136153 (Locate asan-odr-win with other sanitizer tests)
- rust-lang#136161 (rustdoc: add nobuild typescript checking to our JS)
- rust-lang#136166 (interpret: is_alloc_live: check global allocs last)
- rust-lang#136168 (GCI: Don't try to eval / collect mono items inside overly generic free const items)
- rust-lang#136170 (Reject unsound toggling of Arm atomics-32 target feature)
- rust-lang#136176 (Render pattern types nicely in mir dumps)
- rust-lang#136186 (uefi: process: Fix args)
r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant 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.

5 participants

@oli-obk@compiler-errors@bors@scottmcm@rustbot