-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
layout: Avoid niches that make things worse. #63903
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @eddyb (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
@@ -951,19 +1024,20 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { | |||
Some(niche) => niche, | |||
_ => continue, | |||
}; | |||
// Do not use a niche smaller than the tag unless it reduces the size. | |||
if !must_grow && niche.available(dl) >> ity.size().bits() == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The size of the discriminant shouldn't be used (since it ignores the actual available range). Instead, you want to compare with .available(dl)
on the tag niche (computed further down):
let largest_niche = Niche::from_scalar(dl, Size::ZERO, tag.clone());
prefix_align = prefix_align.max(field.align.abi); | ||
} | ||
} | ||
prefix_align = align.abi; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fact that some of this code was moved up but not all of it makes me uneasy. I can't easily tell if it will always produce the same result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The niche filling code needs to use the alignment without ity.align(dl)
. I suppose I could use a different name for that, maybe body_align
, and only set align
after we know that we'll use a tag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, seems to be #63902.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would very much prefer to fix the bug without landing #63902.
☔ The latest upstream changes (presumably #63998) made this pull request unmergeable. Please resolve the merge conflicts. |
Ping from triage: @hvenev any updates on this? |
I've been busy over the last few weeks. I should be able to work on this in a few days. |
Ping from Triage: @hvenev we are closing this due to inactivity. However, when you have updates, please re-open. Thanks for the PR. |
After pull request #63902. Fixes issue #63866.
In cases where adding a tag does not increase the size of the enum, don't use a niche that has fewer values than the tag.