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

layout: Avoid niches that make things worse. #63903

Closed
wants to merge 3 commits into from

Conversation

hvenev
Copy link
Contributor

@hvenev hvenev commented Aug 25, 2019

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.

@rust-highfive
Copy link
Collaborator

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.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 25, 2019
@@ -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 {
Copy link
Member

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;
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

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.

@bors
Copy link
Contributor

bors commented Aug 29, 2019

☔ The latest upstream changes (presumably #63998) made this pull request unmergeable. Please resolve the merge conflicts.

@wirelessringo
Copy link

Ping from triage. @hvenev any updates on this? Thanks.

@rustbot modify labels to +S-waiting-on-author, -S-waiting-on-review

@rustbot rustbot 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 Sep 6, 2019
@JohnTitor
Copy link
Member

Ping from triage: @hvenev any updates on this?

@hvenev
Copy link
Contributor Author

hvenev commented Sep 15, 2019

I've been busy over the last few weeks. I should be able to work on this in a few days.

@joelpalmer joelpalmer added S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 23, 2019
@joelpalmer
Copy link

Ping from Triage: @hvenev we are closing this due to inactivity. However, when you have updates, please re-open. Thanks for the PR.

@joelpalmer joelpalmer closed this Sep 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants