Skip to content

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

Merged
bors merged 1 commit into
rust-lang:masterfrom
oli-obk:transmuty-pat-tys
Feb 6, 2025
Merged

Pretty print pattern type values with transmute if they don't satisfy their pattern#136235
bors merged 1 commit into
rust-lang:masterfrom
oli-obk:transmuty-pat-tys

Conversation

@oli-obk

Copy link
Copy Markdown
Contributor

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 #136176

cc @compiler-errors@scottmcm

r? @RalfJung because of the interpreter changes

@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 29, 2025
@rustbot

Copy link
Copy Markdown
Collaborator

Some changes occurred to the CTFE machinery

cc @rust-lang/wg-const-eval

cx.validate_operand(
&allocated.into(),
/*recursive*/ false,
/*reset_provenance_and_padding*/ false,

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.

existing, but maybe use enums instead of bool + comments :3

Comment threadcompiler/rustc_const_eval/src/util/validate_scalar_in_layout.rs Outdated
Comment threadcompiler/rustc_const_eval/src/util/validate_scalar_in_layout.rs Outdated
let typing_env = ty::TypingEnv::fully_monomorphized();
let mut cx = InterpCx::new(tcx.tcx, tcx.span, typing_env, machine);

let Ok(layout) = cx.layout_of(ty) else { return false };

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.

Reporting false in case of a layout computation error seems odd? This is almost certainly a bug, right?

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.

I could just unwrap it and we'll do it properly when we can write a test for it

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.

That works for me.
@matthiaskrgr heads-up if you see this ICE, please ping us and thanks in advance for generating a test case. :)

@RalfJung

Copy link
Copy Markdown
Member

r=me with the unwrap.
@rustbot author

@rustbotrustbot 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-review Status: Awaiting review from the assignee but also interested parties. labels Feb 2, 2025
@oli-obk
oli-obkforce-pushed the transmuty-pat-tys branch 2 times, most recently from 9e50c77 to 5465770CompareFebruary 2, 2025 18:45
@oli-obk

Copy link
Copy Markdown
ContributorAuthor

@bors r=RalfJung

@bors

bors commented Feb 2, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit 5465770 has been approved by RalfJung

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 2, 2025
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
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 3, 2025
…iaskrgr
Rollup of 8 pull requests
Successful merges:
- rust-lang#134777 (Enable more tests on Windows)
- rust-lang#134807 (fix(rustdoc): always use a channel when linking to doc.rust-lang.org)
- rust-lang#135621 (Move some std tests to integration tests)
- rust-lang#135695 (Support raw-dylib link kind on ELF)
- rust-lang#135836 (bootstrap: only build `crt{begin,end}.o` when compiling to MUSL)
- rust-lang#136235 (Pretty print pattern type values with transmute if they don't satisfy their pattern)
- rust-lang#136392 (bootstrap: add wrapper macros for `feature = "tracing"`-gated `tracing` macros)
- rust-lang#136462 (mir_build: Simplify `lower_pattern_range_endpoint`)
r? `@ghost`
`@rustbot` modify labels: rollup
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
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 3, 2025
…iaskrgr
Rollup of 7 pull requests
Successful merges:
- rust-lang#134777 (Enable more tests on Windows)
- rust-lang#134807 (fix(rustdoc): always use a channel when linking to doc.rust-lang.org)
- rust-lang#135621 (Move some std tests to integration tests)
- rust-lang#135836 (bootstrap: only build `crt{begin,end}.o` when compiling to MUSL)
- rust-lang#136235 (Pretty print pattern type values with transmute if they don't satisfy their pattern)
- rust-lang#136392 (bootstrap: add wrapper macros for `feature = "tracing"`-gated `tracing` macros)
- rust-lang#136462 (mir_build: Simplify `lower_pattern_range_endpoint`)
r? `@ghost`
`@rustbot` modify labels: rollup
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
@jieyouxujieyouxu mentioned this pull request Feb 3, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 3, 2025
Rollup of 8 pull requests
Successful merges:
- rust-lang#134807 (fix(rustdoc): always use a channel when linking to doc.rust-lang.org)
- rust-lang#134814 (Add `kl` and `widekl` target features, and the feature gate)
- rust-lang#135836 (bootstrap: only build `crt{begin,end}.o` when compiling to MUSL)
- rust-lang#136022 (Port ui/simd tests to use the intrinsic macro)
- rust-lang#136235 (Pretty print pattern type values with transmute if they don't satisfy their pattern)
- rust-lang#136309 (set rustc dylib on manually constructed rustc command)
- rust-lang#136392 (bootstrap: add wrapper macros for `feature = "tracing"`-gated `tracing` macros)
- rust-lang#136462 (mir_build: Simplify `lower_pattern_range_endpoint`)
r? `@ghost`
`@rustbot` modify labels: rollup
@matthiaskrgr

Copy link
Copy Markdown
Member

@bors r-
it no werky :( #136482 (comment)

@borsbors removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Feb 3, 2025
@borsbors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Feb 3, 2025
@rust-log-analyzer

This comment has been minimized.

@oli-obk

Copy link
Copy Markdown
ContributorAuthor

@bors r=RalfJung

@bors

bors commented Feb 5, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit ab31159 has been approved by RalfJung

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 5, 2025
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
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 6, 2025
…kingjubilee
Rollup of 9 pull requests
Successful merges:
- rust-lang#135439 (Make `-O` mean `OptLevel::Aggressive`)
- rust-lang#136193 (Implement pattern type ffi checks)
- rust-lang#136235 (Pretty print pattern type values with transmute if they don't satisfy their pattern)
- rust-lang#136311 (Ensure that we never try to monomorphize the upcasting or vtable calls of impossible dyn types)
- rust-lang#136315 (Use short ty string for binop and unop errors)
- rust-lang#136393 (Fix accidentally not emitting overflowing literals lints anymore in patterns)
- rust-lang#136530 (Implement `x perf` directly in bootstrap)
- rust-lang#136580 (Couple of changes to run rustc in miri)
- rust-lang#136589 (Enable "jump to def" feature on rustc docs)
r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 6, 2025
…iaskrgr
Rollup of 7 pull requests
Successful merges:
- rust-lang#136073 (Always compute coroutine layout for eagerly emitting recursive layout errors)
- rust-lang#136235 (Pretty print pattern type values with transmute if they don't satisfy their pattern)
- rust-lang#136311 (Ensure that we never try to monomorphize the upcasting or vtable calls of impossible dyn types)
- rust-lang#136315 (Use short ty string for binop and unop errors)
- rust-lang#136393 (Fix accidentally not emitting overflowing literals lints anymore in patterns)
- rust-lang#136435 (Simplify some code for lowering THIR patterns)
- rust-lang#136630 (Change two std process tests to not output to std{out,err}, and fix test suite stat reset in bootstrap CI test rendering)
r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 6, 2025
Rollup of 7 pull requests
Successful merges:
- rust-lang#136073 (Always compute coroutine layout for eagerly emitting recursive layout errors)
- rust-lang#136235 (Pretty print pattern type values with transmute if they don't satisfy their pattern)
- rust-lang#136311 (Ensure that we never try to monomorphize the upcasting or vtable calls of impossible dyn types)
- rust-lang#136315 (Use short ty string for binop and unop errors)
- rust-lang#136393 (Fix accidentally not emitting overflowing literals lints anymore in patterns)
- rust-lang#136435 (Simplify some code for lowering THIR patterns)
- rust-lang#136630 (Change two std process tests to not output to std{out,err}, and fix test suite stat reset in bootstrap CI test rendering)
r? `@ghost`
`@rustbot` modify labels: rollup
try-job: aarch64-gnu-debug
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 6, 2025
…iaskrgr
Rollup of 7 pull requests
Successful merges:
- rust-lang#136073 (Always compute coroutine layout for eagerly emitting recursive layout errors)
- rust-lang#136235 (Pretty print pattern type values with transmute if they don't satisfy their pattern)
- rust-lang#136311 (Ensure that we never try to monomorphize the upcasting or vtable calls of impossible dyn types)
- rust-lang#136315 (Use short ty string for binop and unop errors)
- rust-lang#136393 (Fix accidentally not emitting overflowing literals lints anymore in patterns)
- rust-lang#136435 (Simplify some code for lowering THIR patterns)
- rust-lang#136630 (Change two std process tests to not output to std{out,err}, and fix test suite stat reset in bootstrap CI test rendering)
r? `@ghost`
`@rustbot` modify labels: rollup
try-job: aarch64-gnu-debug
@bors
bors merged commit 62cad97 into rust-lang:masterFeb 6, 2025
@rustbotrustbot added this to the 1.86.0 milestone Feb 6, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 6, 2025
…kingjubilee
Rollup of 9 pull requests
Successful merges:
- rust-lang#135439 (Make `-O` mean `OptLevel::Aggressive`)
- rust-lang#136193 (Implement pattern type ffi checks)
- rust-lang#136235 (Pretty print pattern type values with transmute if they don't satisfy their pattern)
- rust-lang#136311 (Ensure that we never try to monomorphize the upcasting or vtable calls of impossible dyn types)
- rust-lang#136315 (Use short ty string for binop and unop errors)
- rust-lang#136393 (Fix accidentally not emitting overflowing literals lints anymore in patterns)
- rust-lang#136530 (Implement `x perf` directly in bootstrap)
- rust-lang#136580 (Couple of changes to run rustc in miri)
- rust-lang#136589 (Enable "jump to def" feature on rustc docs)
r? `@ghost`
`@rustbot` modify labels: rollup
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
flip1995 pushed a commit to flip1995/rust that referenced this pull request Feb 20, 2025
…iaskrgr
Rollup of 7 pull requests
Successful merges:
- rust-lang#136073 (Always compute coroutine layout for eagerly emitting recursive layout errors)
- rust-lang#136235 (Pretty print pattern type values with transmute if they don't satisfy their pattern)
- rust-lang#136311 (Ensure that we never try to monomorphize the upcasting or vtable calls of impossible dyn types)
- rust-lang#136315 (Use short ty string for binop and unop errors)
- rust-lang#136393 (Fix accidentally not emitting overflowing literals lints anymore in patterns)
- rust-lang#136435 (Simplify some code for lowering THIR patterns)
- rust-lang#136630 (Change two std process tests to not output to std{out,err}, and fix test suite stat reset in bootstrap CI test rendering)
r? `@ghost`
`@rustbot` modify labels: rollup
try-job: aarch64-gnu-debug
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.

7 participants

@oli-obk@rustbot@RalfJung@bors@matthiaskrgr@rust-log-analyzer@lcnr