-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Do not disable field reordering on enums with big discriminant #70748
Conversation
The field are always re-ordered to minimize padding, regardless of the alignment of the discriminant
(rust_highfive has picked a reviewer for you, use r? to override) |
r? @eddyb |
@@ -104,6 +127,8 @@ pub fn main() { | |||
assert_eq!(size_of::<e3>(), 4 as usize); | |||
assert_eq!(size_of::<ReorderedStruct>(), 4); | |||
assert_eq!(size_of::<ReorderedEnum>(), 6); | |||
assert_eq!(size_of::<ReorderedEnum2>(), 8); |
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.
For the record, before this PR it was 12
.
FWIW, this has some more details #70477 (comment). My reasoning is that the discriminant "commutes" with the group of fields right next to it, which have lower alignment, without changes in padding. I believe this doesn't hold for descending sorting (by alignment), but only ascending sorting, of variant fields (it's the latter we do for I haven't fully looked into what other implications partially-sorted field orders have. @bors r+ |
📌 Commit 6b6cb7b has been approved by |
Do not disable field reordering on enums with big discriminant The field are always re-ordered to minimize padding, regardless of the alignment of the discriminant (spinoff from rust-lang#70477)
Rollup of 6 pull requests Successful merges: - rust-lang#70635 (rustc_target: Some cleanup to `no_default_libraries`) - rust-lang#70748 (Do not disable field reordering on enums with big discriminant) - rust-lang#70752 (Add slice::fill) - rust-lang#70766 (use ManuallyDrop instead of forget inside collections) - rust-lang#70768 (macro_rules: `NtLifetime` cannot start with an identifier) - rust-lang#70783 (comment refers to removed type) Failed merges: r? @ghost
The field are always re-ordered to minimize padding, regardless of the
alignment of the discriminant
(spinoff from #70477)