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

Temporary fix for the layout of aligned enums #92932

Merged
merged 1 commit into from
Feb 3, 2022
Merged

Temporary fix for the layout of aligned enums #92932

merged 1 commit into from
Feb 3, 2022

Conversation

ouz-a
Copy link
Contributor

@ouz-a ouz-a commented Jan 15, 2022

Fix for the issue #92464

I was after this issue for quite some time now, I have a temporary fix for it.
I think the current problem is here created tag value might be wrong, because when I checked min and max values it's always between 0..1, which results in wrong size comparison in a few lines down below.
I think min and max values don't take #[repr(aligned(8))] into consideration and just act from base values assigned inside the enum. If what I am saying is true, aligned enums were created with the wrong layout for some time.

As stated in the title this is only a temporary fix and I think this needs further investigation, if someone wants to mentor it I would like to work on that too. 😸

Edit: Weird some tests fail now going to close this for now...

Edit2: I made it work again.

I think I figured out the main problem of the issue, layout types of aligned enums with custom discriminant types were not handled, which resulted in confusing(such as this issue) behavior down the line, this is a kinda hacky fix for the issue.

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

r? @jackh726

(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 Jan 15, 2022
@ouz-a ouz-a changed the title Temporary fix for the issue #92464 Temporary fix for the layout of aligned enums Jan 15, 2022
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@ouz-a ouz-a closed this Jan 15, 2022
@ouz-a ouz-a reopened this Jan 16, 2022
@ouz-a
Copy link
Contributor Author

ouz-a commented Jan 16, 2022

updated the tittle and main comment, to explain why changes were made

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@ouz-a
Copy link
Contributor Author

ouz-a commented Jan 17, 2022

r? @jackh726

@rust-log-analyzer

This comment has been minimized.

@jackh726
Copy link
Member

There's probably a better reviewer than me for this.

r? rust-lang/compiler

@rust-highfive rust-highfive assigned davidtwco and unassigned jackh726 Jan 30, 2022
@davidtwco
Copy link
Member

I'm not familiar with this code so I'll reassign. You'll need remove the merge commits though - we don't land pull requests with merge commits, you should rebase instead.

r? @oli-obk

@rust-highfive rust-highfive assigned oli-obk and unassigned davidtwco Jan 31, 2022
@oli-obk
Copy link
Contributor

oli-obk commented Feb 1, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Feb 1, 2022

📌 Commit fd5be23 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 1, 2022
@matthiaskrgr
Copy link
Member

@bors rolllup=never (in case of perf impact)

@matthiaskrgr
Copy link
Member

@bors rollup=never

@bors
Copy link
Contributor

bors commented Feb 3, 2022

⌛ Testing commit fd5be23 with merge 85305239569a792a47cc31c47fa937f807f5d5ea...

@bors
Copy link
Contributor

bors commented Feb 3, 2022

💥 Test timed out

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

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@matthiaskrgr
Copy link
Member

@bors retry #93329

@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 3, 2022
@bors
Copy link
Contributor

bors commented Feb 3, 2022

⌛ Testing commit fd5be23 with merge 8b7853f...

@bors
Copy link
Contributor

bors commented Feb 3, 2022

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing 8b7853f to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Feb 3, 2022
@bors bors merged commit 8b7853f into rust-lang:master Feb 3, 2022
@rustbot rustbot added this to the 1.60.0 milestone Feb 3, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (8b7853f): comparison url.

Summary: This benchmark run did not return any relevant results. 5 results were found to be statistically significant but too small to be relevant.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

@RalfJung
Copy link
Member

RalfJung commented May 7, 2022

FWIW this fix was wrong and introduced another bug elsewhere, see #96185.

@ouz-a
Copy link
Contributor Author

ouz-a commented May 7, 2022

I knew this one was going to bite me later, IIRC the original issue this PR tried to fix was convoluted one and this was the best I could do back then 😅

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jul 5, 2022
Fix repr(align) enum handling

`enum`, for better or worse, supports `repr(align)`. That has already caused a bug in rust-lang#92464, which was "fixed" in rust-lang#92932, but it turns out that that fix is wrong and caused rust-lang#96185.

So this reverts rust-lang#92932 (which fixes rust-lang#96185), and attempts another strategy for fixing rust-lang#92464: special-case enums when doing a cast, re-using the code to load the discriminant rather than assuming that the enum has scalar layout. This works fine for the interpreter.

However, rust-lang#92464 contained another testcase that was previously not in the test suite -- and after adding it, it ICEs again. This is not surprising; codegen needs the same patch that I did in the interpreter. Probably this has to happen [around here](https://github.com/rust-lang/rust/blob/d32ce37a171663048a4c4a536803434e40f52bd6/compiler/rustc_codegen_ssa/src/mir/rvalue.rs#L276). Unfortunately I don't know how to do that -- the interpreter can load a discriminant from an operand, but codegen can only do that from a place. `@oli-obk` `@eddyb` `@bjorn3` any idea?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.

None yet