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

Open
wants to merge 3 commits into
base: master
from

Conversation

@hvenev
Copy link
Contributor

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

This comment has been minimized.

Copy link
Collaborator

commented Aug 25, 2019

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 {

This comment has been minimized.

Copy link
@eddyb

eddyb Aug 26, 2019

Member

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;

This comment has been minimized.

Copy link
@eddyb

eddyb Aug 26, 2019

Member

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.

This comment has been minimized.

Copy link
@hvenev

hvenev Aug 26, 2019

Author Contributor

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.

This comment has been minimized.

Copy link
@eddyb

eddyb Aug 26, 2019

Member

Nevermind, seems to be #63902.

This comment has been minimized.

Copy link
@eddyb

eddyb Aug 26, 2019

Member

I would very much prefer to fix the bug without landing #63902.

@bors

This comment has been minimized.

Copy link
Contributor

commented Aug 29, 2019

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

@ProgrammaticNajel

This comment has been minimized.

Copy link

commented Sep 6, 2019

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

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

@JohnTitor

This comment has been minimized.

Copy link
Member

commented Sep 15, 2019

Ping from triage: @hvenev any updates on this?

@hvenev

This comment has been minimized.

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.