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

Closed
wants to merge 2 commits into from

Conversation

hvenev
Copy link
Contributor

@hvenev hvenev commented Aug 25, 2019

After pull request #63899.

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

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 25, 2019
@Centril
Copy link
Contributor

Centril 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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it could be expensive.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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] }
Copy link
Member

@eddyb eddyb Aug 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@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
@JohnCSimon
Copy link
Member

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!

@JohnCSimon JohnCSimon added the S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. label Sep 20, 2019
@JohnCSimon
Copy link
Member

Ping from triage.
@hvenev Unfortunately this PR has sat idle for nearly a month and I'm going to have to close it.
cc: @eddyb
Thanks for your contribution, and please reopen this when you have time to address this again.

@JohnCSimon JohnCSimon closed this Sep 20, 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. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants