Skip to content

Commit 4d07320

Browse files
committed
Auto merge of #38523 - camlorn:disable_field_reordering, r=nikomatsakis
Disable field reordering This was decided via IRC and needs a backport to beta. Basically, #37429 broke servo, and probably needs an announcement and opt-in flag. I didn't run all tests locally but think I've already reverted all the ones that need to be reverted. r? @nikomatsakis
2 parents 467a7f0 + b6b630a commit 4d07320

File tree

5 files changed

+36
-36
lines changed

5 files changed

+36
-36
lines changed

src/librustc/ty/layout.rs

+4
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,10 @@ impl<'a, 'gcx, 'tcx> Struct {
575575
});
576576
}
577577

578+
// Disable field reordering until we can decide what to do.
579+
// The odd pattern here avoids a warning about the value never being read.
580+
if can_optimize { can_optimize = false }
581+
578582
let (optimize, sort_ascending) = match kind {
579583
StructKind::AlwaysSizedUnivariant => (can_optimize, false),
580584
StructKind::MaybeUnsizedUnivariant => (can_optimize, false),

src/test/run-pass/type-sizes.rs

-7
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ enum e3 {
3131
a([u16; 0], u8), b
3232
}
3333

34-
// Test struct field reordering to make sure it actually reorders.
35-
struct WillOptimize1(u8, u16, u8);
36-
struct WillOptimize2 { a: u8, b: u16, c: u8}
37-
3834
pub fn main() {
3935
assert_eq!(size_of::<u8>(), 1 as usize);
4036
assert_eq!(size_of::<u32>(), 4 as usize);
@@ -58,7 +54,4 @@ pub fn main() {
5854
assert_eq!(size_of::<e1>(), 8 as usize);
5955
assert_eq!(size_of::<e2>(), 8 as usize);
6056
assert_eq!(size_of::<e3>(), 4 as usize);
61-
62-
assert_eq!(size_of::<WillOptimize1>(), 4);
63-
assert_eq!(size_of::<WillOptimize2>(), 4);
6457
}

src/test/ui/print_type_sizes/nullable.stdout

+19-16
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
print-type-size type: `IndirectNonZero<u32>`: 12 bytes, alignment: 4 bytes
2-
print-type-size field `.nested`: 8 bytes
3-
print-type-size field `.post`: 2 bytes
1+
print-type-size type: `IndirectNonZero<u32>`: 20 bytes, alignment: 4 bytes
42
print-type-size field `.pre`: 1 bytes
5-
print-type-size end padding: 1 bytes
6-
print-type-size type: `MyOption<IndirectNonZero<u32>>`: 12 bytes, alignment: 4 bytes
7-
print-type-size variant `Some`: 12 bytes
8-
print-type-size field `.0`: 12 bytes
9-
print-type-size type: `EmbeddedDiscr`: 8 bytes, alignment: 4 bytes
10-
print-type-size variant `Record`: 7 bytes
11-
print-type-size field `.val`: 4 bytes
12-
print-type-size field `.post`: 2 bytes
13-
print-type-size field `.pre`: 1 bytes
14-
print-type-size end padding: 1 bytes
15-
print-type-size type: `NestedNonZero<u32>`: 8 bytes, alignment: 4 bytes
16-
print-type-size field `.val`: 4 bytes
3+
print-type-size padding: 3 bytes
4+
print-type-size field `.nested`: 12 bytes, alignment: 4 bytes
175
print-type-size field `.post`: 2 bytes
6+
print-type-size end padding: 2 bytes
7+
print-type-size type: `MyOption<IndirectNonZero<u32>>`: 20 bytes, alignment: 4 bytes
8+
print-type-size variant `Some`: 20 bytes
9+
print-type-size field `.0`: 20 bytes
10+
print-type-size type: `EmbeddedDiscr`: 12 bytes, alignment: 4 bytes
11+
print-type-size variant `Record`: 10 bytes
12+
print-type-size field `.pre`: 1 bytes
13+
print-type-size padding: 3 bytes
14+
print-type-size field `.val`: 4 bytes, alignment: 4 bytes
15+
print-type-size field `.post`: 2 bytes
16+
print-type-size end padding: 2 bytes
17+
print-type-size type: `NestedNonZero<u32>`: 12 bytes, alignment: 4 bytes
1818
print-type-size field `.pre`: 1 bytes
19-
print-type-size end padding: 1 bytes
19+
print-type-size padding: 3 bytes
20+
print-type-size field `.val`: 4 bytes, alignment: 4 bytes
21+
print-type-size field `.post`: 2 bytes
22+
print-type-size end padding: 2 bytes
2023
print-type-size type: `MyOption<core::nonzero::NonZero<u32>>`: 4 bytes, alignment: 4 bytes
2124
print-type-size variant `Some`: 4 bytes
2225
print-type-size field `.0`: 4 bytes

src/test/ui/print_type_sizes/packed.stdout

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
print-type-size type: `Padded`: 12 bytes, alignment: 4 bytes
2-
print-type-size field `.g`: 4 bytes
3-
print-type-size field `.h`: 2 bytes
1+
print-type-size type: `Padded`: 16 bytes, alignment: 4 bytes
42
print-type-size field `.a`: 1 bytes
53
print-type-size field `.b`: 1 bytes
4+
print-type-size padding: 2 bytes
5+
print-type-size field `.g`: 4 bytes, alignment: 4 bytes
66
print-type-size field `.c`: 1 bytes
7+
print-type-size padding: 1 bytes
8+
print-type-size field `.h`: 2 bytes, alignment: 2 bytes
79
print-type-size field `.d`: 1 bytes
8-
print-type-size end padding: 2 bytes
10+
print-type-size end padding: 3 bytes
911
print-type-size type: `Packed`: 10 bytes, alignment: 1 bytes
1012
print-type-size field `.a`: 1 bytes
1113
print-type-size field `.b`: 1 bytes
+7-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
print-type-size type: `E1`: 12 bytes, alignment: 4 bytes
2-
print-type-size discriminant: 1 bytes
3-
print-type-size variant `A`: 7 bytes
2+
print-type-size discriminant: 4 bytes
3+
print-type-size variant `A`: 5 bytes
4+
print-type-size field `.0`: 4 bytes
45
print-type-size field `.1`: 1 bytes
5-
print-type-size padding: 2 bytes
6-
print-type-size field `.0`: 4 bytes, alignment: 4 bytes
7-
print-type-size variant `B`: 11 bytes
8-
print-type-size padding: 3 bytes
9-
print-type-size field `.0`: 8 bytes, alignment: 4 bytes
6+
print-type-size variant `B`: 8 bytes
7+
print-type-size field `.0`: 8 bytes
108
print-type-size type: `E2`: 12 bytes, alignment: 4 bytes
119
print-type-size discriminant: 1 bytes
1210
print-type-size variant `A`: 7 bytes
@@ -17,7 +15,7 @@ print-type-size variant `B`: 11 bytes
1715
print-type-size padding: 3 bytes
1816
print-type-size field `.0`: 8 bytes, alignment: 4 bytes
1917
print-type-size type: `S`: 8 bytes, alignment: 4 bytes
20-
print-type-size field `.g`: 4 bytes
2118
print-type-size field `.a`: 1 bytes
2219
print-type-size field `.b`: 1 bytes
23-
print-type-size end padding: 2 bytes
20+
print-type-size padding: 2 bytes
21+
print-type-size field `.g`: 4 bytes, alignment: 4 bytes

0 commit comments

Comments
 (0)