Skip to content

Conversation

ogoffart
Copy link
Contributor

@ogoffart ogoffart commented Apr 3, 2020

The field are always re-ordered to minimize padding, regardless of the
alignment of the discriminant

(spinoff from #70477)

The field are always re-ordered to minimize padding, regardless of the
alignment of the discriminant
@rust-highfive
Copy link
Contributor

r? @matthewjasper

(rust_highfive has picked a reviewer for you, use r? to override)

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

Centril commented Apr 3, 2020

r? @eddyb

@rust-highfive rust-highfive assigned eddyb and unassigned matthewjasper Apr 3, 2020
@@ -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);
Copy link
Member

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.

@eddyb
Copy link
Member

eddyb commented Apr 4, 2020

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 enums).

I haven't fully looked into what other implications partially-sorted field orders have.

@bors r+

@bors
Copy link
Collaborator

bors commented Apr 4, 2020

📌 Commit 6b6cb7b has been approved by eddyb

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 4, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Apr 4, 2020
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)
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 5, 2020
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
@bors bors merged commit 630414d into rust-lang:master Apr 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants