Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
367 changes: 258 additions & 109 deletions compiler/rustc_abi/src/layout.rs

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ bitflags! {
/// See [`TyAndLayout::pass_indirectly_in_non_rustic_abis`] for details.
const PASS_INDIRECTLY_IN_NON_RUSTIC_ABIS = 1 << 5;
const IS_SCALABLE = 1 << 6;
// Any of these flags being set prevent field reordering optimisation.
const FIELD_ORDER_UNOPTIMIZABLE = ReprFlags::IS_C.bits()
| ReprFlags::IS_SIMD.bits()
| ReprFlags::IS_SCALABLE.bits()
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4468,7 +4468,13 @@ mod size_asserts {
static_assert_size!(GenericParam, 80);
static_assert_size!(Generics, 40);
static_assert_size!(Impl, 80);
#[cfg(not(bootstrap))]
static_assert_size!(Item, 136);
#[cfg(bootstrap)]
static_assert_size!(Item, 144);
#[cfg(not(bootstrap))]
static_assert_size!(ItemKind, 80);
#[cfg(bootstrap)]
static_assert_size!(ItemKind, 88);
static_assert_size!(Lifetime, 16);
static_assert_size!(LitKind, 24);
Expand Down
26 changes: 10 additions & 16 deletions tests/ui/print_type_sizes/padding.stdout
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
print-type-size type: `E1`: 12 bytes, alignment: 4 bytes
print-type-size discriminant: 1 bytes
print-type-size variant `B`: 11 bytes
print-type-size padding: 3 bytes
print-type-size field `.0`: 8 bytes, alignment: 4 bytes
print-type-size variant `A`: 7 bytes
print-type-size type: `E1`: 8 bytes, alignment: 4 bytes
print-type-size variant `B`: 8 bytes
print-type-size field `.0`: 8 bytes
print-type-size variant `A`: 5 bytes
print-type-size field `.0`: 4 bytes
print-type-size field `.1`: 1 bytes
print-type-size padding: 2 bytes
print-type-size field `.0`: 4 bytes, alignment: 4 bytes
print-type-size type: `E2`: 12 bytes, alignment: 4 bytes
print-type-size discriminant: 1 bytes
print-type-size variant `B`: 11 bytes
print-type-size padding: 3 bytes
print-type-size field `.0`: 8 bytes, alignment: 4 bytes
print-type-size variant `A`: 7 bytes
print-type-size type: `E2`: 8 bytes, alignment: 4 bytes
print-type-size variant `B`: 8 bytes
print-type-size field `.0`: 8 bytes
print-type-size variant `A`: 5 bytes
print-type-size field `.1`: 4 bytes
print-type-size field `.0`: 1 bytes
print-type-size padding: 2 bytes
print-type-size field `.1`: 4 bytes, alignment: 4 bytes
print-type-size type: `S`: 8 bytes, alignment: 4 bytes
print-type-size field `.g`: 4 bytes
print-type-size field `.a`: 1 bytes
Expand Down
1 change: 1 addition & 0 deletions tests/ui/stats/input-stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// stage1 and stage2 will give different outputs for this test.
// Add an `ignore-stage1` comment marker to work around that problem during
// that time.
//@ ignore-stage1


// The aim here is to include at least one of every different type of top-level
Expand Down
18 changes: 9 additions & 9 deletions tests/ui/stats/input-stats.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ ast-stats ================================================================
ast-stats POST EXPANSION AST STATS: input_stats
ast-stats Name Accumulated Size Count Item Size
ast-stats ----------------------------------------------------------------
ast-stats Item 1_584 (NN.N%) 11 144
ast-stats - Enum 144 (NN.N%) 1
ast-stats - ExternCrate 144 (NN.N%) 1
ast-stats - ForeignMod 144 (NN.N%) 1
ast-stats - Impl 144 (NN.N%) 1
ast-stats - Trait 144 (NN.N%) 1
ast-stats - Fn 288 (NN.N%) 2
ast-stats - Use 576 (NN.N%) 4
ast-stats Item 1_496 (NN.N%) 11 136
ast-stats - Enum 136 (NN.N%) 1
ast-stats - ExternCrate 136 (NN.N%) 1
ast-stats - ForeignMod 136 (NN.N%) 1
ast-stats - Impl 136 (NN.N%) 1
ast-stats - Trait 136 (NN.N%) 1
ast-stats - Fn 272 (NN.N%) 2
ast-stats - Use 544 (NN.N%) 4
ast-stats PathSegment 840 (NN.N%) 35 24
ast-stats Ty 784 (NN.N%) 14 56
ast-stats - Ptr 56 (NN.N%) 1
Expand Down Expand Up @@ -58,7 +58,7 @@ ast-stats GenericArgs 40 (NN.N%) 1 40
ast-stats - AngleBracketed 40 (NN.N%) 1
ast-stats Crate 40 (NN.N%) 1 40
ast-stats ----------------------------------------------------------------
ast-stats Total 6_872 126
ast-stats Total 6_784 126
ast-stats ================================================================
hir-stats ================================================================
hir-stats HIR STATS: input_stats
Expand Down
126 changes: 126 additions & 0 deletions tests/ui/structs-enums/enum-niche-fill-around-tag.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
//@ run-pass

#![allow(dead_code)]
#![feature(offset_of_enum)]

use std::mem::{align_of, offset_of};
use std::mem::size_of;
use std::num::NonZero;

enum Inner {
A(u8, u32),
B(u32),
}

enum Outer {
A(Inner),
B(u32, u8),
}

struct WithPadding {
a: bool,
b: bool,
c: u32,
}

enum RepackPadding {
A(u32, u8),
B(WithPadding),
}

struct RepackedBase {
int32: u32,
boolean: bool,
}

enum RepackedAroundNiche {
A(RepackedBase),
B(u16, u32, u8),
}

enum NestedRepackedAroundNiche {
A(RepackedAroundNiche),
B(u16, u32, u8),
}

struct RepackedPair {
field2: u16,
field3: u8,
}

enum RepackedNestedAggregate {
A(u16, RepackedPair),
B(NestedRepackedAroundNiche),
}

struct FittingNichePayload {
word: u32,
flag: bool,
}

// The first and last max-sized niche candidates cannot encode all variants.
// The middle candidate can, so the enum layout has to keep looking.
enum ChooseFittingNiche {
SmallNicheFront(u16, u32, NonZero<u8>),
WideNiche(FittingNichePayload),
SmallNicheBack(u16, u32, NonZero<u8>),
V0,
V1,
V2,
}

fn main() {
assert_eq!(size_of::<Inner>(), 8);

assert_eq!(size_of::<Outer>(), 8);
assert_eq!(size_of::<RepackPadding>(), 8);

assert_eq!(size_of::<RepackedBase>(), 8);
assert_eq!(align_of::<RepackedBase>(), 4);
assert_eq!(offset_of!(RepackedBase, int32), 0);
assert_eq!(offset_of!(RepackedBase, boolean), 4);

assert_eq!(size_of::<RepackedAroundNiche>(), 8);
assert_eq!(align_of::<RepackedAroundNiche>(), 4);
assert_eq!(size_of::<Option<RepackedAroundNiche>>(), 8);
assert_eq!(offset_of!(RepackedAroundNiche, A.0), 0);
assert_eq!(offset_of!(RepackedAroundNiche, B.1), 0);
assert_eq!(offset_of!(RepackedAroundNiche, B.2), 5);
assert_eq!(offset_of!(RepackedAroundNiche, B.0), 6);

assert_eq!(size_of::<NestedRepackedAroundNiche>(), 8);
assert_eq!(align_of::<NestedRepackedAroundNiche>(), 4);
assert_eq!(size_of::<Option<NestedRepackedAroundNiche>>(), 8);
assert_eq!(offset_of!(NestedRepackedAroundNiche, A.0), 0);
assert_eq!(offset_of!(NestedRepackedAroundNiche, B.1), 0);
assert_eq!(offset_of!(NestedRepackedAroundNiche, B.2), 5);
assert_eq!(offset_of!(NestedRepackedAroundNiche, B.0), 6);

assert_eq!(size_of::<RepackedPair>(), 4);
assert_eq!(align_of::<RepackedPair>(), 2);
assert_eq!(offset_of!(RepackedPair, field2), 0);
assert_eq!(offset_of!(RepackedPair, field3), 2);

assert_eq!(size_of::<RepackedNestedAggregate>(), 8);
assert_eq!(align_of::<RepackedNestedAggregate>(), 4);
assert_eq!(size_of::<Option<RepackedNestedAggregate>>(), 8);
assert_eq!(offset_of!(RepackedNestedAggregate, B.0), 0);
assert_eq!(offset_of!(RepackedNestedAggregate, A.1), 0);
assert_eq!(offset_of!(RepackedNestedAggregate, A.0), 6);

assert_eq!(size_of::<FittingNichePayload>(), 8);
assert_eq!(align_of::<FittingNichePayload>(), 4);
assert_eq!(offset_of!(FittingNichePayload, word), 0);
assert_eq!(offset_of!(FittingNichePayload, flag), 4);

assert_eq!(size_of::<ChooseFittingNiche>(), 8);
assert_eq!(align_of::<ChooseFittingNiche>(), 4);
assert_eq!(size_of::<Option<ChooseFittingNiche>>(), 8);
assert_eq!(offset_of!(ChooseFittingNiche, WideNiche.0), 0);
assert_eq!(offset_of!(ChooseFittingNiche, SmallNicheFront.1), 0);
assert_eq!(offset_of!(ChooseFittingNiche, SmallNicheFront.2), 5);
assert_eq!(offset_of!(ChooseFittingNiche, SmallNicheFront.0), 6);
assert_eq!(offset_of!(ChooseFittingNiche, SmallNicheBack.1), 0);
assert_eq!(offset_of!(ChooseFittingNiche, SmallNicheBack.2), 5);
assert_eq!(offset_of!(ChooseFittingNiche, SmallNicheBack.0), 6);
}
Loading