Auto merge of #45225 - eddyb:trans-abi, r=arielb1

Refactor type memory layouts and ABIs, to be more general and easier to optimize.

To combat combinatorial explosion, type layouts are now described through 3 orthogonal properties:
* `Variants` describes the plurality of sum types (where applicable)
  * `Single` is for one inhabited/active variant, including all C `struct`s and `union`s
  * `Tagged` has its variants discriminated by an integer tag, including C `enum`s
  * `NicheFilling` uses otherwise-invalid values ("niches") for all but one of its inhabited variants
* `FieldPlacement` describes the number and memory offsets of fields (if any)
  * `Union` has all its fields at offset `0`
  * `Array` has offsets that are a multiple of its `stride`; guarantees all fields have one type
  * `Arbitrary` records all the field offsets, which can be out-of-order
* `Abi` describes how values of the type should be passed around, including for FFI
  * `Uninhabited` corresponds to no values, associated with unreachable control-flow
  * `Scalar` is ABI-identical to its only integer/floating-point/pointer "scalar component"
  * `ScalarPair` has two "scalar components", but only applies to the Rust ABI
  * `Vector` is for SIMD vectors, typically `#[repr(simd)]` `struct`s in Rust
  * `Aggregate` has arbitrary contents, including all non-transparent C `struct`s and `union`s

Size optimizations implemented so far:
* ignoring uninhabited variants (i.e. containing uninhabited fields), e.g.:
  * `Option<!>` is 0 bytes
  * `Result<T, !>` has the same size as `T`
* using arbitrary niches, not just `0`, to represent a data-less variant, e.g.:
  * `Option<bool>`, `Option<Option<bool>>`, `Option<Ordering>` are all 1 byte
  * `Option<char>` is 4 bytes
* using a range of niches to represent *multiple* data-less variants, e.g.:
  * `enum E { A(bool), B, C, D }` is 1 byte

Code generation now takes advantage of `Scalar` and `ScalarPair` to, in more cases, pass around scalar components as immediates instead of indirectly, through pointers into temporary memory, while avoiding LLVM's "first-class aggregates", and there's more untapped potential here.

Closes #44426, fixes #5977, fixes #14540, fixes #43278.
This commit is contained in:
bors 2017-11-19 22:12:22 +00:00
commit f50fd075c2
93 changed files with 5064 additions and 5702 deletions

View file

@ -9,6 +9,7 @@
// except according to those terms.
// compile-flags: -C no-prepopulate-passes
// ignore-tidy-linelength
#![crate_type = "lib"]
@ -23,9 +24,9 @@ pub fn helper(_: usize) {
pub fn no_op_slice_adjustment(x: &[u8]) -> &[u8] {
// We used to generate an extra alloca and memcpy for the block's trailing expression value, so
// check that we copy directly to the return value slot
// CHECK: %0 = insertvalue { i8*, [[USIZE]] } undef, i8* %x.ptr, 0
// CHECK: %1 = insertvalue { i8*, [[USIZE]] } %0, [[USIZE]] %x.meta, 1
// CHECK: ret { i8*, [[USIZE]] } %1
// CHECK: %0 = insertvalue { [0 x i8]*, [[USIZE]] } undef, [0 x i8]* %x.0, 0
// CHECK: %1 = insertvalue { [0 x i8]*, [[USIZE]] } %0, [[USIZE]] %x.1, 1
// CHECK: ret { [0 x i8]*, [[USIZE]] } %1
{ x }
}

View file

@ -54,7 +54,7 @@ pub fn inline_enum_const() -> E<i8, i16> {
#[no_mangle]
pub fn low_align_const() -> E<i16, [i16; 3]> {
// Check that low_align_const and high_align_const use the same constant
// CHECK: load {{.*}} bitcast ({ i16, i16, [4 x i8] }** [[LOW_HIGH_REF]]
// CHECK: load {{.*}} bitcast ({ i16, [0 x i8], i16, [4 x i8] }** [[LOW_HIGH_REF]]
*&E::A(0)
}
@ -62,6 +62,6 @@ pub fn low_align_const() -> E<i16, [i16; 3]> {
#[no_mangle]
pub fn high_align_const() -> E<i16, i32> {
// Check that low_align_const and high_align_const use the same constant
// CHECK: load {{.*}} bitcast ({ i16, i16, [4 x i8] }** [[LOW_HIGH_REF]]
// CHECK: load {{.*}} bitcast ({ i16, [0 x i8], i16, [4 x i8] }** [[LOW_HIGH_REF]]
*&E::A(0)
}

View file

@ -9,12 +9,13 @@
// except according to those terms.
// compile-flags: -C no-prepopulate-passes
// ignore-tidy-linelength
#![crate_type = "lib"]
#![feature(custom_attribute)]
pub struct S {
_field: [i64; 4],
_field: [i32; 8],
}
pub struct UnsafeInner {
@ -45,13 +46,13 @@ pub fn static_borrow(_: &'static i32) {
pub fn named_borrow<'r>(_: &'r i32) {
}
// CHECK: @unsafe_borrow(%UnsafeInner* dereferenceable(2) %arg0)
// CHECK: @unsafe_borrow(i16* dereferenceable(2) %arg0)
// unsafe interior means this isn't actually readonly and there may be aliases ...
#[no_mangle]
pub fn unsafe_borrow(_: &UnsafeInner) {
}
// CHECK: @mutable_unsafe_borrow(%UnsafeInner* dereferenceable(2) %arg0)
// CHECK: @mutable_unsafe_borrow(i16* dereferenceable(2) %arg0)
// ... unless this is a mutable borrow, those never alias
// ... except that there's this LLVM bug that forces us to not use noalias, see #29485
#[no_mangle]
@ -76,7 +77,7 @@ pub fn indirect_struct(_: S) {
pub fn borrowed_struct(_: &S) {
}
// CHECK: noalias dereferenceable(4) i32* @_box(i32* noalias dereferenceable(4) %x)
// CHECK: noalias align 4 dereferenceable(4) i32* @_box(i32* noalias dereferenceable(4) %x)
#[no_mangle]
pub fn _box(x: Box<i32>) -> Box<i32> {
x
@ -86,7 +87,7 @@ pub fn _box(x: Box<i32>) -> Box<i32> {
#[no_mangle]
pub fn struct_return() -> S {
S {
_field: [0, 0, 0, 0]
_field: [0, 0, 0, 0, 0, 0, 0, 0]
}
}
@ -96,43 +97,43 @@ pub fn struct_return() -> S {
pub fn helper(_: usize) {
}
// CHECK: @slice(i8* noalias nonnull readonly %arg0.ptr, [[USIZE]] %arg0.meta)
// CHECK: @slice([0 x i8]* noalias nonnull readonly %arg0.0, [[USIZE]] %arg0.1)
// FIXME #25759 This should also have `nocapture`
#[no_mangle]
pub fn slice(_: &[u8]) {
}
// CHECK: @mutable_slice(i8* nonnull %arg0.ptr, [[USIZE]] %arg0.meta)
// CHECK: @mutable_slice([0 x i8]* nonnull %arg0.0, [[USIZE]] %arg0.1)
// FIXME #25759 This should also have `nocapture`
// ... there's this LLVM bug that forces us to not use noalias, see #29485
#[no_mangle]
pub fn mutable_slice(_: &mut [u8]) {
}
// CHECK: @unsafe_slice(%UnsafeInner* nonnull %arg0.ptr, [[USIZE]] %arg0.meta)
// CHECK: @unsafe_slice([0 x i16]* nonnull %arg0.0, [[USIZE]] %arg0.1)
// unsafe interior means this isn't actually readonly and there may be aliases ...
#[no_mangle]
pub fn unsafe_slice(_: &[UnsafeInner]) {
}
// CHECK: @str(i8* noalias nonnull readonly %arg0.ptr, [[USIZE]] %arg0.meta)
// CHECK: @str([0 x i8]* noalias nonnull readonly %arg0.0, [[USIZE]] %arg0.1)
// FIXME #25759 This should also have `nocapture`
#[no_mangle]
pub fn str(_: &[u8]) {
}
// CHECK: @trait_borrow({}* nonnull, {}* noalias nonnull readonly)
// CHECK: @trait_borrow(%"core::ops::drop::Drop"* nonnull %arg0.0, {}* noalias nonnull readonly %arg0.1)
// FIXME #25759 This should also have `nocapture`
#[no_mangle]
pub fn trait_borrow(_: &Drop) {
}
// CHECK: @trait_box({}* noalias nonnull, {}* noalias nonnull readonly)
// CHECK: @trait_box(%"core::ops::drop::Drop"* noalias nonnull, {}* noalias nonnull readonly)
#[no_mangle]
pub fn trait_box(_: Box<Drop>) {
}
// CHECK: { i16*, [[USIZE]] } @return_slice(i16* noalias nonnull readonly %x.ptr, [[USIZE]] %x.meta)
// CHECK: { [0 x i16]*, [[USIZE]] } @return_slice([0 x i16]* noalias nonnull readonly %x.0, [[USIZE]] %x.1)
#[no_mangle]
pub fn return_slice(x: &[u16]) -> &[u16] {
x

View file

@ -15,7 +15,7 @@
#[no_mangle]
pub struct F32(f32);
// CHECK: define float @add_newtype_f32(float, float)
// CHECK: define float @add_newtype_f32(float %a, float %b)
#[inline(never)]
#[no_mangle]
pub fn add_newtype_f32(a: F32, b: F32) -> F32 {
@ -25,7 +25,7 @@ pub fn add_newtype_f32(a: F32, b: F32) -> F32 {
#[no_mangle]
pub struct F64(f64);
// CHECK: define double @add_newtype_f64(double, double)
// CHECK: define double @add_newtype_f64(double %a, double %b)
#[inline(never)]
#[no_mangle]
pub fn add_newtype_f64(a: F64, b: F64) -> F64 {

View file

@ -22,12 +22,12 @@ pub enum E {
B(f32)
}
// CHECK: @VAR2 = constant {{.*}} { i32 0, i32 666 }, section ".test_two"
// CHECK: @VAR2 = constant {{.*}}, section ".test_two"
#[no_mangle]
#[link_section = ".test_two"]
pub static VAR2: E = E::A(666);
// CHECK: @VAR3 = constant {{.*}} { i32 1, float 1.000000e+00 }, section ".test_three"
// CHECK: @VAR3 = constant {{.*}}, section ".test_three"
#[no_mangle]
#[link_section = ".test_three"]
pub static VAR3: E = E::B(1.);

View file

@ -12,11 +12,9 @@
// compile-flags: -O
#![crate_type="lib"]
pub enum Three { First, Second, Third }
use Three::*;
pub enum Three { A, B, C }
pub enum Four { First, Second, Third, Fourth }
use Four::*;
pub enum Four { A, B, C, D }
#[no_mangle]
pub fn three_valued(x: Three) -> Three {
@ -24,9 +22,9 @@ pub fn three_valued(x: Three) -> Three {
// CHECK-NEXT: {{^.*:$}}
// CHECK-NEXT: ret i8 %0
match x {
First => First,
Second => Second,
Third => Third,
Three::A => Three::A,
Three::B => Three::B,
Three::C => Three::C,
}
}
@ -36,9 +34,9 @@ pub fn four_valued(x: Four) -> Four {
// CHECK-NEXT: {{^.*:$}}
// CHECK-NEXT: ret i8 %0
match x {
First => First,
Second => Second,
Third => Third,
Fourth => Fourth,
Four::A => Four::A,
Four::B => Four::B,
Four::C => Four::C,
Four::D => Four::D,
}
}

View file

@ -54,9 +54,6 @@ pub struct PackedPair(u8, u32);
// CHECK-LABEL: @pkd_pair
#[no_mangle]
pub fn pkd_pair(pair1: &mut PackedPair, pair2: &mut PackedPair) {
// CHECK: [[V1:%[a-z0-9]+]] = load i8, i8* %{{.*}}, align 1
// CHECK: [[V2:%[a-z0-9]+]] = load i32, i32* %{{.*}}, align 1
// CHECK: store i8 [[V1]], i8* {{.*}}, align 1
// CHECK: store i32 [[V2]], i32* {{.*}}, align 1
// CHECK: call void @llvm.memcpy.{{.*}}(i8* %{{.*}}, i8* %{{.*}}, i{{[0-9]+}} 5, i32 1, i1 false)
*pair2 = *pair1;
}

View file

@ -9,6 +9,7 @@
// except according to those terms.
// compile-flags: -C no-prepopulate-passes
// ignore-tidy-linelength
#![crate_type = "lib"]
@ -23,10 +24,10 @@ pub fn helper(_: usize) {
pub fn ref_dst(s: &[u8]) {
// We used to generate an extra alloca and memcpy to ref the dst, so check that we copy
// directly to the alloca for "x"
// CHECK: [[X0:%[0-9]+]] = getelementptr {{.*}} { i8*, [[USIZE]] }* %x, i32 0, i32 0
// CHECK: store i8* %s.ptr, i8** [[X0]]
// CHECK: [[X1:%[0-9]+]] = getelementptr {{.*}} { i8*, [[USIZE]] }* %x, i32 0, i32 1
// CHECK: store [[USIZE]] %s.meta, [[USIZE]]* [[X1]]
// CHECK: [[X0:%[0-9]+]] = getelementptr {{.*}} { [0 x i8]*, [[USIZE]] }* %x, i32 0, i32 0
// CHECK: store [0 x i8]* %s.0, [0 x i8]** [[X0]]
// CHECK: [[X1:%[0-9]+]] = getelementptr {{.*}} { [0 x i8]*, [[USIZE]] }* %x, i32 0, i32 1
// CHECK: store [[USIZE]] %s.1, [[USIZE]]* [[X1]]
let x = &*s;
&x; // keep variable in an alloca

View file

@ -15,7 +15,7 @@
// CHECK-LABEL: @zero_sized_elem
#[no_mangle]
pub fn zero_sized_elem() {
// CHECK-NOT: br label %slice_loop_header{{.*}}
// CHECK-NOT: br label %repeat_loop_header{{.*}}
// CHECK-NOT: call void @llvm.memset.p0i8
let x = [(); 4];
drop(&x);
@ -24,7 +24,7 @@ pub fn zero_sized_elem() {
// CHECK-LABEL: @zero_len_array
#[no_mangle]
pub fn zero_len_array() {
// CHECK-NOT: br label %slice_loop_header{{.*}}
// CHECK-NOT: br label %repeat_loop_header{{.*}}
// CHECK-NOT: call void @llvm.memset.p0i8
let x = [4; 0];
drop(&x);
@ -34,7 +34,7 @@ pub fn zero_len_array() {
#[no_mangle]
pub fn byte_array() {
// CHECK: call void @llvm.memset.p0i8.i[[WIDTH:[0-9]+]](i8* {{.*}}, i8 7, i[[WIDTH]] 4
// CHECK-NOT: br label %slice_loop_header{{.*}}
// CHECK-NOT: br label %repeat_loop_header{{.*}}
let x = [7u8; 4];
drop(&x);
}
@ -50,7 +50,7 @@ enum Init {
#[no_mangle]
pub fn byte_enum_array() {
// CHECK: call void @llvm.memset.p0i8.i[[WIDTH:[0-9]+]](i8* {{.*}}, i8 {{.*}}, i[[WIDTH]] 4
// CHECK-NOT: br label %slice_loop_header{{.*}}
// CHECK-NOT: br label %repeat_loop_header{{.*}}
let x = [Init::Memset; 4];
drop(&x);
}
@ -59,7 +59,7 @@ pub fn byte_enum_array() {
#[no_mangle]
pub fn zeroed_integer_array() {
// CHECK: call void @llvm.memset.p0i8.i[[WIDTH:[0-9]+]](i8* {{.*}}, i8 0, i[[WIDTH]] 16
// CHECK-NOT: br label %slice_loop_header{{.*}}
// CHECK-NOT: br label %repeat_loop_header{{.*}}
let x = [0u32; 4];
drop(&x);
}
@ -67,7 +67,7 @@ pub fn zeroed_integer_array() {
// CHECK-LABEL: @nonzero_integer_array
#[no_mangle]
pub fn nonzero_integer_array() {
// CHECK: br label %slice_loop_header{{.*}}
// CHECK: br label %repeat_loop_header{{.*}}
// CHECK-NOT: call void @llvm.memset.p0i8
let x = [0x1a_2b_3c_4d_u32; 4];
drop(&x);

View file

@ -8,7 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern: overflow representing the type
// error-pattern: unsupported cyclic reference between types/traits detected
// note-pattern: the cycle begins when computing layout of
// note-pattern: ...which then requires computing layout of
// note-pattern: ...which then again requires computing layout of
trait Mirror { type It: ?Sized; }

View file

@ -2,10 +2,15 @@
#include <stddef.h>
#include <stdint.h>
size_t slice_len(uint8_t *data, size_t len) {
return len;
struct ByteSlice {
uint8_t *data;
size_t len;
};
size_t slice_len(struct ByteSlice bs) {
return bs.len;
}
uint8_t slice_elem(uint8_t *data, size_t len, size_t idx) {
return data[idx];
uint8_t slice_elem(struct ByteSlice bs, size_t idx) {
return bs.data[idx];
}

View file

@ -108,6 +108,9 @@ pub fn main() {
let array_expected_size = round_up(28, align_of::<Eu64NonCLike<[u32; 5]>>());
assert_eq!(size_of::<Eu64NonCLike<[u32; 5]>>(), array_expected_size);
assert_eq!(size_of::<Eu64NonCLike<[u32; 6]>>(), 32);
assert_eq!(align_of::<Eu32>(), align_of::<u32>());
assert_eq!(align_of::<Eu64NonCLike<u8>>(), align_of::<u64>());
}
// Rounds x up to the next multiple of a

View file

@ -22,6 +22,11 @@ enum UnivariantWithoutDescr {
Y
}
#[repr(u8)]
enum UnivariantWithData {
Z(u8),
}
pub fn main() {
{
assert_eq!(4, mem::size_of::<Univariant>());
@ -44,4 +49,12 @@ pub fn main() {
// check it has the same memory layout as u16
assert_eq!(&[descr, descr, descr], ints);
}
{
assert_eq!(2, mem::size_of::<UnivariantWithData>());
match UnivariantWithData::Z(4) {
UnivariantWithData::Z(x) => assert_eq!(x, 4),
}
}
}

View file

@ -0,0 +1,25 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[repr(packed)]
#[derive(Copy, Clone)]
struct Packed<T>(T);
fn main() {
let one = (Some(Packed((&(), 0))), true);
let two = [one, one];
let stride = (&two[1] as *const _ as usize) - (&two[0] as *const _ as usize);
// This can fail if rustc and LLVM disagree on the size of a type.
// In this case, `Option<Packed<(&(), u32)>>` was erronously not
// marked as packed despite needing alignment `1` and containing
// its `&()` discriminant, which has alignment larger than `1`.
assert_eq!(stride, std::mem::size_of_val(&one));
}

View file

@ -1,9 +0,0 @@
error[E0391]: unsupported cyclic reference between types/traits detected
|
note: the cycle begins when computing layout of `S`...
note: ...which then requires computing layout of `std::option::Option<<S as Mirror>::It>`...
note: ...which then requires computing layout of `<S as Mirror>::It`...
= note: ...which then again requires computing layout of `S`, completing the cycle.
error: aborting due to previous error

View file

@ -10,8 +10,8 @@
// compile-flags: -Z print-type-sizes
// This file illustrates how enums with a non-null field are handled,
// modelled after cases like `Option<&u32>` and such.
// This file illustrates how niche-filling enums are handled,
// modelled after cases like `Option<&u32>`, `Option<bool>` and such.
//
// It uses NonZero directly, rather than `&_` or `Unique<_>`, because
// the test is not set up to deal with target-dependent pointer width.
@ -68,8 +68,22 @@ impl One for u32 {
fn one() -> Self { 1 }
}
pub enum Enum4<A, B, C, D> {
One(A),
Two(B),
Three(C),
Four(D)
}
pub fn main() {
let _x: MyOption<NonZero<u32>> = Default::default();
let _y: EmbeddedDiscr = Default::default();
let _z: MyOption<IndirectNonZero<u32>> = Default::default();
let _a: MyOption<bool> = Default::default();
let _b: MyOption<char> = Default::default();
let _c: MyOption<std::cmp::Ordering> = Default::default();
let _b: MyOption<MyOption<u8>> = Default::default();
let _e: Enum4<(), char, (), ()> = Enum4::One(());
let _f: Enum4<(), (), bool, ()> = Enum4::One(());
let _g: Enum4<(), (), (), MyOption<u8>> = Enum4::One(());
}

View file

@ -0,0 +1,80 @@
print-type-size type: `IndirectNonZero<u32>`: 12 bytes, alignment: 4 bytes
print-type-size field `.nested`: 8 bytes
print-type-size field `.post`: 2 bytes
print-type-size field `.pre`: 1 bytes
print-type-size end padding: 1 bytes
print-type-size type: `MyOption<IndirectNonZero<u32>>`: 12 bytes, alignment: 4 bytes
print-type-size variant `None`: 0 bytes
print-type-size variant `Some`: 12 bytes
print-type-size field `.0`: 12 bytes
print-type-size type: `EmbeddedDiscr`: 8 bytes, alignment: 4 bytes
print-type-size variant `None`: 0 bytes
print-type-size variant `Record`: 7 bytes
print-type-size field `.val`: 4 bytes
print-type-size field `.post`: 2 bytes
print-type-size field `.pre`: 1 bytes
print-type-size end padding: 1 bytes
print-type-size type: `NestedNonZero<u32>`: 8 bytes, alignment: 4 bytes
print-type-size field `.val`: 4 bytes
print-type-size field `.post`: 2 bytes
print-type-size field `.pre`: 1 bytes
print-type-size end padding: 1 bytes
print-type-size type: `Enum4<(), char, (), ()>`: 4 bytes, alignment: 4 bytes
print-type-size variant `One`: 0 bytes
print-type-size field `.0`: 0 bytes
print-type-size variant `Two`: 4 bytes
print-type-size field `.0`: 4 bytes
print-type-size variant `Three`: 0 bytes
print-type-size field `.0`: 0 bytes
print-type-size variant `Four`: 0 bytes
print-type-size field `.0`: 0 bytes
print-type-size type: `MyOption<char>`: 4 bytes, alignment: 4 bytes
print-type-size variant `None`: 0 bytes
print-type-size variant `Some`: 4 bytes
print-type-size field `.0`: 4 bytes
print-type-size type: `MyOption<core::nonzero::NonZero<u32>>`: 4 bytes, alignment: 4 bytes
print-type-size variant `None`: 0 bytes
print-type-size variant `Some`: 4 bytes
print-type-size field `.0`: 4 bytes
print-type-size type: `core::nonzero::NonZero<u32>`: 4 bytes, alignment: 4 bytes
print-type-size field `.0`: 4 bytes
print-type-size type: `Enum4<(), (), (), MyOption<u8>>`: 2 bytes, alignment: 1 bytes
print-type-size variant `One`: 0 bytes
print-type-size field `.0`: 0 bytes
print-type-size variant `Two`: 0 bytes
print-type-size field `.0`: 0 bytes
print-type-size variant `Three`: 0 bytes
print-type-size field `.0`: 0 bytes
print-type-size variant `Four`: 2 bytes
print-type-size field `.0`: 2 bytes
print-type-size type: `MyOption<MyOption<u8>>`: 2 bytes, alignment: 1 bytes
print-type-size variant `None`: 0 bytes
print-type-size variant `Some`: 2 bytes
print-type-size field `.0`: 2 bytes
print-type-size type: `MyOption<u8>`: 2 bytes, alignment: 1 bytes
print-type-size discriminant: 1 bytes
print-type-size variant `None`: 0 bytes
print-type-size variant `Some`: 1 bytes
print-type-size field `.0`: 1 bytes
print-type-size type: `Enum4<(), (), bool, ()>`: 1 bytes, alignment: 1 bytes
print-type-size variant `One`: 0 bytes
print-type-size field `.0`: 0 bytes
print-type-size variant `Two`: 0 bytes
print-type-size field `.0`: 0 bytes
print-type-size variant `Three`: 1 bytes
print-type-size field `.0`: 1 bytes
print-type-size variant `Four`: 0 bytes
print-type-size field `.0`: 0 bytes
print-type-size type: `MyOption<bool>`: 1 bytes, alignment: 1 bytes
print-type-size variant `None`: 0 bytes
print-type-size variant `Some`: 1 bytes
print-type-size field `.0`: 1 bytes
print-type-size type: `MyOption<core::cmp::Ordering>`: 1 bytes, alignment: 1 bytes
print-type-size variant `None`: 0 bytes
print-type-size variant `Some`: 1 bytes
print-type-size field `.0`: 1 bytes
print-type-size type: `core::cmp::Ordering`: 1 bytes, alignment: 1 bytes
print-type-size discriminant: 1 bytes
print-type-size variant `Less`: 0 bytes
print-type-size variant `Equal`: 0 bytes
print-type-size variant `Greater`: 0 bytes

View file

@ -1,24 +0,0 @@
print-type-size type: `IndirectNonZero<u32>`: 12 bytes, alignment: 4 bytes
print-type-size field `.nested`: 8 bytes
print-type-size field `.post`: 2 bytes
print-type-size field `.pre`: 1 bytes
print-type-size end padding: 1 bytes
print-type-size type: `MyOption<IndirectNonZero<u32>>`: 12 bytes, alignment: 4 bytes
print-type-size variant `Some`: 12 bytes
print-type-size field `.0`: 12 bytes
print-type-size type: `EmbeddedDiscr`: 8 bytes, alignment: 4 bytes
print-type-size variant `Record`: 7 bytes
print-type-size field `.val`: 4 bytes
print-type-size field `.post`: 2 bytes
print-type-size field `.pre`: 1 bytes
print-type-size end padding: 1 bytes
print-type-size type: `NestedNonZero<u32>`: 8 bytes, alignment: 4 bytes
print-type-size field `.val`: 4 bytes
print-type-size field `.post`: 2 bytes
print-type-size field `.pre`: 1 bytes
print-type-size end padding: 1 bytes
print-type-size type: `MyOption<core::nonzero::NonZero<u32>>`: 4 bytes, alignment: 4 bytes
print-type-size variant `Some`: 4 bytes
print-type-size field `.0`: 4 bytes
print-type-size type: `core::nonzero::NonZero<u32>`: 4 bytes, alignment: 4 bytes
print-type-size field `.0`: 4 bytes

View file

@ -1,4 +1,4 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
@ -8,7 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Test([i32]);
fn main() {
let _x: fn(_) -> Test = Test;
// compile-flags: -Z print-type-sizes
#![feature(never_type)]
pub fn main() {
let _x: Option<!> = None;
let _y: Result<u32, !> = Ok(42);
}

View file

@ -0,0 +1,5 @@
print-type-size type: `std::result::Result<u32, !>`: 4 bytes, alignment: 4 bytes
print-type-size variant `Ok`: 4 bytes
print-type-size field `.0`: 4 bytes
print-type-size type: `std::option::Option<!>`: 0 bytes, alignment: 1 bytes
print-type-size variant `None`: 0 bytes