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: Always use the largest tag size that fits. #63902

Open
wants to merge 2 commits into
base: master
from

Conversation

@hvenev
Copy link
Contributor

commented Aug 25, 2019

After pull request #63899.

Try to fit the largest integer in the padding bytes before the fields.

@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 @zackmdavis (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.

@Centril

This comment has been minimized.

Copy link
Member

commented Aug 25, 2019

r? @eddyb

@rust-highfive rust-highfive assigned eddyb and unassigned zackmdavis Aug 25, 2019


// Use the initial field alignment
let mut ity = if def.repr.c() || def.repr.int.is_some() {
let ity = if def.repr.inhibit_enum_layout_opt() {

This comment has been minimized.

Copy link
@eddyb

eddyb Aug 26, 2019

Member

Not a good idea, the old condition here is not about optimizations, it's about whether the discriminant is being forced with #[repr].


for fields in variants.iter() {
let (v_size, v_align) = self.variant_size(fields, &def.repr)
.ok_or(LayoutError::SizeOverflow(ty))?;

This comment has been minimized.

Copy link
@eddyb

eddyb Aug 26, 2019

Member

This looks like it could be expensive.

This comment has been minimized.

Copy link
@eddyb

eddyb Aug 26, 2019

Member

It also doesn't take field sorting and the offset for the tag into account?

This comment has been minimized.

Copy link
@hvenev

hvenev Aug 26, 2019

Author Contributor

It considers field sorting, but it does not compute it. If sorting happens, all padding can be at the start.

This also means it's relatively cheap.

min_ity
} else {
Integer::for_align(dl, start_align).unwrap_or(min_ity)
Integer::approximate_size(gap).unwrap()

This comment has been minimized.

Copy link
@eddyb

eddyb Aug 26, 2019

Member

If you pick something large enough to increase the alignment, you'll easily waste space in types containing this one.
If you think this will never happen, that's still not obvious from the code, and you'd have to either compute both and assert they're the same, and we can land that, crater it, etc. or prove it formally somehow.

This comment has been minimized.

Copy link
@hvenev

hvenev Aug 26, 2019

Author Contributor

Let gap0 be the original value of gap. We either have gap = gap0 < align.abi, or gap = gap0 + (min_ity.size() - gap0).align_to(align.abi) < gap0 + min_ity.size() - gap0 + align.abi = min_ity.size() + align.abi.

ity.size() <= gap. In both cases ity.size() <= gap < min_ity.size() + align.abi, therefore either ity = min_ity or ity.size() < align.abi.

@@ -9,7 +9,7 @@ pub enum Align64 {
A(u32),
B(u32),
}
// CHECK: %Align64 = type { [0 x i32], i32, [15 x i32] }
// CHECK: %Align64 = type { [0 x i64], i64, [7 x i64] }

This comment has been minimized.

Copy link
@eddyb

eddyb Aug 26, 2019

Member

So you're actually moving the field? How do you know that won't cause the field sorting to produce worse results?

@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

@JohnCSimon

This comment has been minimized.

Copy link

commented Sep 14, 2019

ping from triage -
@hvenev I see your pr for #63899 - can you please address the merge conflict in this one and post your status?

Thank you!

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