Skip to content

Commit 7025605

Browse files
fmeaseJonathanBrouwer
authored andcommitted
Rename #[rustc_dump_layout]'s abi option to backend_repr
Moreover, dereference `ty_layout.align` for `#[rustc_dump_layout(align)]` to render `align: Align($N bytes)` instead of `align: AbiAlign { abi: Align($N bytes) }` which contains the same amount of information but it more concise and legible.
1 parent 357f670 commit 7025605

11 files changed

Lines changed: 44 additions & 36 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/rustc_dump.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,21 @@ impl<S: Stage> CombineAttributeParser<S> for RustcDumpLayoutParser {
8686
return vec![];
8787
};
8888
let kind = match ident.name {
89-
sym::abi => RustcDumpLayoutKind::Abi,
9089
sym::align => RustcDumpLayoutKind::Align,
91-
sym::size => RustcDumpLayoutKind::Size,
92-
sym::homogeneous_aggregate => RustcDumpLayoutKind::HomogenousAggregate,
90+
sym::backend_repr => RustcDumpLayoutKind::BackendRepr,
9391
sym::debug => RustcDumpLayoutKind::Debug,
92+
sym::homogeneous_aggregate => RustcDumpLayoutKind::HomogenousAggregate,
93+
sym::size => RustcDumpLayoutKind::Size,
9494
_ => {
9595
cx.adcx().expected_specific_argument(
9696
ident.span,
97-
&[sym::abi, sym::align, sym::size, sym::homogeneous_aggregate, sym::debug],
97+
&[
98+
sym::align,
99+
sym::backend_repr,
100+
sym::debug,
101+
sym::homogeneous_aggregate,
102+
sym::size,
103+
],
98104
);
99105
continue;
100106
}

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -758,11 +758,11 @@ impl IntoDiagArg for CrateType {
758758

759759
#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)]
760760
pub enum RustcDumpLayoutKind {
761-
Abi,
762761
Align,
763-
Size,
764-
HomogenousAggregate,
762+
BackendRepr,
765763
Debug,
764+
HomogenousAggregate,
765+
Size,
766766
}
767767

768768
#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute, PartialEq, Eq)]

compiler/rustc_passes/src/layout_test.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,21 @@ fn dump_layout_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId, kinds: &[RustcDumpLa
7070
Ok(ty_layout) => {
7171
for kind in kinds {
7272
let message = match kind {
73-
// FIXME: this never was about ABI and now this dump arg is confusing
74-
RustcDumpLayoutKind::Abi => format!("abi: {:?}", ty_layout.backend_repr),
75-
RustcDumpLayoutKind::Align => format!("align: {:?}", ty_layout.align),
76-
RustcDumpLayoutKind::Size => format!("size: {:?}", ty_layout.size),
77-
RustcDumpLayoutKind::HomogenousAggregate => {
78-
let data =
79-
ty_layout.homogeneous_aggregate(&UnwrapLayoutCx { tcx, typing_env });
80-
format!("homogeneous_aggregate: {data:?}")
73+
RustcDumpLayoutKind::Align => format!("align: {:?}", *ty_layout.align),
74+
RustcDumpLayoutKind::BackendRepr => {
75+
format!("backend_repr: {:?}", ty_layout.backend_repr)
8176
}
8277
RustcDumpLayoutKind::Debug => {
8378
let normalized_ty = tcx.normalize_erasing_regions(typing_env, ty);
8479
// FIXME: using the `Debug` impl here isn't ideal.
8580
format!("layout_of({normalized_ty}) = {:#?}", *ty_layout)
8681
}
82+
RustcDumpLayoutKind::HomogenousAggregate => {
83+
let data =
84+
ty_layout.homogeneous_aggregate(&UnwrapLayoutCx { tcx, typing_env });
85+
format!("homogeneous_aggregate: {data:?}")
86+
}
87+
RustcDumpLayoutKind::Size => format!("size: {:?}", ty_layout.size),
8788
};
8889
tcx.dcx().span_err(span, message);
8990
}

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ symbols! {
505505
avx512f,
506506
await_macro,
507507
backchain,
508+
backend_repr,
508509
bang,
509510
begin_panic,
510511
bench,

src/doc/unstable-book/src/language-features/rustc-attrs.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ The `rustc_attrs` feature allows debugging rustc type layouts by using
1313
with `cargo check`) as an alternative to `rustc -Z print-type-sizes`
1414
that is way more verbose.
1515

16-
Options provided by `#[rustc_dump_layout(...)]` are `abi`, `align`, `debug`,
17-
`homogeneous_aggregate` and `size`.
16+
Options provided by `#[rustc_dump_layout(...)]` are `backend_repr`, `align`,
17+
`debug`, `homogeneous_aggregate` and `size`.
1818
Note that it only works on sized types without generics.
1919

2020
## Examples
2121

2222
```rust,compile_fail
2323
#![feature(rustc_attrs)]
2424
25-
#[rustc_dump_layout(abi, size)]
25+
#[rustc_dump_layout(backend_repr, size)]
2626
pub enum X {
2727
Y(u8, u8, u8),
2828
Z(isize),
@@ -32,7 +32,7 @@ pub enum X {
3232
When that is compiled, the compiler will error with something like
3333

3434
```text
35-
error: abi: Aggregate { sized: true }
35+
error: backend_repr: Aggregate { sized: true }
3636
--> src/lib.rs:4:1
3737
|
3838
4 | / pub enum T {

tests/ui/layout/enum-scalar-pair-int-ptr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
#![feature(never_type)]
99
#![crate_type = "lib"]
1010

11-
#[rustc_dump_layout(abi)]
12-
enum ScalarPairPointerWithInt { //~ERROR: abi: ScalarPair
11+
#[rustc_dump_layout(backend_repr)]
12+
enum ScalarPairPointerWithInt { //~ERROR: backend_repr: ScalarPair
1313
A(usize),
1414
B(Box<()>),
1515
}
1616

1717
// Negative test--ensure that pointers are not commoned with integers
1818
// of a different size. (Assumes that no target has 8 bit pointers, which
1919
// feels pretty safe.)
20-
#[rustc_dump_layout(abi)]
21-
enum NotScalarPairPointerWithSmallerInt { //~ERROR: abi: Memory
20+
#[rustc_dump_layout(backend_repr)]
21+
enum NotScalarPairPointerWithSmallerInt { //~ERROR: backend_repr: Memory
2222
A(u8),
2323
B(Box<()>),
2424
}

tests/ui/layout/enum-scalar-pair-int-ptr.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error: abi: ScalarPair(Initialized { value: Int(I?, false), valid_range: $VALID_RANGE }, Initialized { value: Pointer(AddressSpace(0)), valid_range: $VALID_RANGE })
1+
error: backend_repr: ScalarPair(Initialized { value: Int(I?, false), valid_range: $VALID_RANGE }, Initialized { value: Pointer(AddressSpace(0)), valid_range: $VALID_RANGE })
22
--> $DIR/enum-scalar-pair-int-ptr.rs:12:1
33
|
44
LL | enum ScalarPairPointerWithInt {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66

7-
error: abi: Memory { sized: true }
7+
error: backend_repr: Memory { sized: true }
88
--> $DIR/enum-scalar-pair-int-ptr.rs:21:1
99
|
1010
LL | enum NotScalarPairPointerWithSmallerInt {

tests/ui/layout/enum.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#![crate_type = "lib"]
77

88
#[rustc_dump_layout(align)]
9-
enum UninhabitedVariantAlign { //~ERROR: abi: Align(2 bytes)
9+
enum UninhabitedVariantAlign { //~ERROR: align: Align(2 bytes)
1010
A([u8; 32]),
1111
B([u16; 0], !), // make sure alignment in uninhabited fields is respected
1212
}
@@ -17,8 +17,8 @@ enum UninhabitedVariantSpace { //~ERROR: size: Size(16 bytes)
1717
B([u8; 15], !), // make sure there is space being reserved for this field.
1818
}
1919

20-
#[rustc_dump_layout(abi)]
21-
enum ScalarPairDifferingSign { //~ERROR: abi: ScalarPair
20+
#[rustc_dump_layout(backend_repr)]
21+
enum ScalarPairDifferingSign { //~ERROR: backend_repr: ScalarPair
2222
A(u8),
2323
B(i8),
2424
}

tests/ui/layout/enum.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: align: AbiAlign { abi: Align(2 bytes) }
1+
error: align: Align(2 bytes)
22
--> $DIR/enum.rs:9:1
33
|
44
LL | enum UninhabitedVariantAlign {
@@ -10,7 +10,7 @@ error: size: Size(16 bytes)
1010
LL | enum UninhabitedVariantSpace {
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

13-
error: abi: ScalarPair(Initialized { value: Int(I8, false), valid_range: 0..=1 }, Initialized { value: Int(I8, false), valid_range: 0..=255 })
13+
error: backend_repr: ScalarPair(Initialized { value: Int(I8, false), valid_range: 0..=1 }, Initialized { value: Int(I8, false), valid_range: 0..=255 })
1414
--> $DIR/enum.rs:21:1
1515
|
1616
LL | enum ScalarPairDifferingSign {

tests/ui/layout/struct.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#![feature(never_type)]
66
#![crate_type = "lib"]
77

8-
#[rustc_dump_layout(abi)]
9-
struct AlignedZstPreventsScalar(i16, [i32; 0]); //~ERROR: abi: Memory
8+
#[rustc_dump_layout(backend_repr)]
9+
struct AlignedZstPreventsScalar(i16, [i32; 0]); //~ERROR: backend_repr: Memory
1010

11-
#[rustc_dump_layout(abi)]
12-
struct AlignedZstButStillScalar(i32, [i16; 0]); //~ERROR: abi: Scalar
11+
#[rustc_dump_layout(backend_repr)]
12+
struct AlignedZstButStillScalar(i32, [i16; 0]); //~ERROR: backend_repr: Scalar

0 commit comments

Comments
 (0)