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

Mark unions non-const-propagatable in KnownPanicsLint without calling layout #124504

Merged
merged 1 commit into from Apr 29, 2024

Conversation

gurry
Copy link
Contributor

@gurry gurry commented Apr 29, 2024

Fixes #123710

The ICE occurs during the layout calculation of the union InvalidTag in #123710 because the following assert fails:

assert_eq!(
common_align, field.align.abi,
"non-Aggregate field with matching ABI but differing alignment"
);

The layout calculation is invoked by KnownPanicsLint when it is trying to figure out which locals it can const prop. Since KnownPanicsLint is never actually going to const props unions thanks to PR #121628 there's no point calling layout to check if it can. So in this fix I skip the call to layout and just mark the local non-const propagatable if it is a union.

as they have a potential to ICE during layout calculation
@rustbot
Copy link
Collaborator

rustbot commented Apr 29, 2024

r? @pnkfelix

rustbot has assigned @pnkfelix.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Apr 29, 2024
@rustbot
Copy link
Collaborator

rustbot commented Apr 29, 2024

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@gurry gurry changed the title Prohibit const prop of unions in KnownPanicsLint Mark unions non-const-propagatable in KnownPanicsLint without calling layout Apr 29, 2024
@oli-obk
Copy link
Contributor

oli-obk commented Apr 29, 2024

Though the reason it ICEs is that unions are incompatible with const propagation, as Rust has no concept of "active variant" of unions. So either we permit using unions for transmutes in const prop, or we can't support them at all. The reason we don't allow unions transmutes in const prop is that the current design of const prop just isn't compatible with it

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Apr 29, 2024

📌 Commit 254a9fb has been approved by oli-obk

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 Apr 29, 2024
@gurry
Copy link
Contributor Author

gurry commented Apr 29, 2024

Though the reason it ICEs is that unions are incompatible with const propagation, as Rust has no concept of "active variant" of unions. So either we permit using unions for transmutes in const prop, or we can't support them at all. The reason we don't allow unions transmutes in const prop is that the current design of const prop just isn't compatible with it

@bors r+ rollup

Oh I see. Thanks for the context.

I'll try to add it in the comments in a subsequent PR.

bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 29, 2024
Rollup of 7 pull requests

Successful merges:

 - rust-lang#124269 (Pretty-print parenthesis around binary in postfix match)
 - rust-lang#124415 (Use probes more aggressively in new solver)
 - rust-lang#124475 (Remove direct dependencies on lazy_static, once_cell and byteorder)
 - rust-lang#124484 (Fix rust-lang#124478 - offset_of! returns a temporary)
 - rust-lang#124504 (Mark unions non-const-propagatable in `KnownPanicsLint` without calling layout)
 - rust-lang#124508 (coverage: Avoid hard-coded values when visiting logical ops)
 - rust-lang#124522 ([Refactor] Rename `Lint` and `LintGroup`'s `is_loaded` to `is_externally_loaded` )

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 43265f5 into rust-lang:master Apr 29, 2024
10 checks passed
@rustbot rustbot added this to the 1.80.0 milestone Apr 29, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 29, 2024
Rollup merge of rust-lang#124504 - gurry:123710-union-ICE, r=oli-obk

Mark unions non-const-propagatable in `KnownPanicsLint` without calling layout

Fixes rust-lang#123710

The ICE occurs during the layout calculation of the union `InvalidTag` in rust-lang#123710 because the following assert fails:https://github.com/rust-lang/rust/blob/5fe8b697e729b6eb64841a3905e57da1b47f4ca3/compiler/rustc_abi/src/layout.rs#L289-L292

The layout calculation is invoked by `KnownPanicsLint` when it is trying to figure out which locals it can const prop. Since `KnownPanicsLint` is never actually going to const props unions thanks to PR rust-lang#121628 there's no point calling layout to check if it can. So in this fix I skip the call to layout and just mark the local non-const propagatable if it is a union.
@gurry gurry deleted the 123710-union-ICE branch April 30, 2024 01:22
@gurry
Copy link
Contributor Author

gurry commented Apr 30, 2024

I'll try to add it in the comments in a subsequent PR.

Updated the comment in #124550

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 30, 2024
…-obk

Remove redundant union check in `KnownPanicsLint` const prop

Removes the below check which prevents unions from being const propagated:https://github.com/rust-lang/rust/blob/f9dca46218d4b8efa062aec4fd0820cbb4942aa2/compiler/rustc_mir_transform/src/known_panics_lint.rs#L587-L594

It is not needed because after PR rust-lang#124504 we mark unions as `NoPropagation` over here: https://github.com/rust-lang/rust/blob/f9dca46218d4b8efa062aec4fd0820cbb4942aa2/compiler/rustc_mir_transform/src/known_panics_lint.rs#L899-L902 which is enough to prevent them from being const propagated.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 30, 2024
Rollup merge of rust-lang#124550 - gurry:remove-redundant-code, r=oli-obk

Remove redundant union check in `KnownPanicsLint` const prop

Removes the below check which prevents unions from being const propagated:https://github.com/rust-lang/rust/blob/f9dca46218d4b8efa062aec4fd0820cbb4942aa2/compiler/rustc_mir_transform/src/known_panics_lint.rs#L587-L594

It is not needed because after PR rust-lang#124504 we mark unions as `NoPropagation` over here: https://github.com/rust-lang/rust/blob/f9dca46218d4b8efa062aec4fd0820cbb4942aa2/compiler/rustc_mir_transform/src/known_panics_lint.rs#L899-L902 which is enough to prevent them from being const propagated.
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: assertion left == right failed: non-Aggregate field with matching ABI but differing alignment
5 participants