Skip to content

Commit ca1ab3e

Browse files
committed
In -Zprint-type-size output, sort enum variants by size.
It's useful to see the biggest variants first.
1 parent 96d700f commit ca1ab3e

File tree

6 files changed

+32
-26
lines changed

6 files changed

+32
-26
lines changed

src/librustc/session/code_stats.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ impl CodeStats {
5757
overall_size: Size,
5858
packed: bool,
5959
opt_discr_size: Option<Size>,
60-
variants: Vec<VariantInfo>) {
60+
mut variants: Vec<VariantInfo>) {
61+
// Sort variants so the largest ones are shown first. A stable sort is
62+
// used here so that source code order is preserved for all variants
63+
// that have the same size.
64+
variants.sort_by(|info1, info2| {
65+
info2.size.cmp(&info1.size)
66+
});
6167
let info = TypeSizeInfo {
6268
kind,
6369
type_description: type_desc.to_string(),

src/test/ui/print_type_sizes/multiple_types.stdout

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
print-type-size type: `Enum`: 51 bytes, alignment: 1 bytes
22
print-type-size discriminant: 1 bytes
3-
print-type-size variant `Small`: 7 bytes
4-
print-type-size field `.0`: 7 bytes
53
print-type-size variant `Large`: 50 bytes
64
print-type-size field `.0`: 50 bytes
5+
print-type-size variant `Small`: 7 bytes
6+
print-type-size field `.0`: 7 bytes
77
print-type-size type: `FiftyBytes`: 50 bytes, alignment: 1 bytes
88
print-type-size field `.0`: 50 bytes
99
print-type-size type: `SevenBytes`: 7 bytes, alignment: 1 bytes

src/test/ui/print_type_sizes/niche-filling.stdout

+14-14
Original file line numberDiff line numberDiff line change
@@ -4,75 +4,75 @@ print-type-size field `.post`: 2 bytes
44
print-type-size field `.pre`: 1 bytes
55
print-type-size end padding: 1 bytes
66
print-type-size type: `MyOption<IndirectNonZero>`: 12 bytes, alignment: 4 bytes
7-
print-type-size variant `None`: 0 bytes
87
print-type-size variant `Some`: 12 bytes
98
print-type-size field `.0`: 12 bytes
10-
print-type-size type: `EmbeddedDiscr`: 8 bytes, alignment: 4 bytes
119
print-type-size variant `None`: 0 bytes
10+
print-type-size type: `EmbeddedDiscr`: 8 bytes, alignment: 4 bytes
1211
print-type-size variant `Record`: 7 bytes
1312
print-type-size field `.val`: 4 bytes
1413
print-type-size field `.post`: 2 bytes
1514
print-type-size field `.pre`: 1 bytes
15+
print-type-size variant `None`: 0 bytes
1616
print-type-size end padding: 1 bytes
1717
print-type-size type: `NestedNonZero`: 8 bytes, alignment: 4 bytes
1818
print-type-size field `.val`: 4 bytes
1919
print-type-size field `.post`: 2 bytes
2020
print-type-size field `.pre`: 1 bytes
2121
print-type-size end padding: 1 bytes
2222
print-type-size type: `Enum4<(), char, (), ()>`: 4 bytes, alignment: 4 bytes
23-
print-type-size variant `One`: 0 bytes
24-
print-type-size field `.0`: 0 bytes
2523
print-type-size variant `Two`: 4 bytes
2624
print-type-size field `.0`: 4 bytes
25+
print-type-size variant `One`: 0 bytes
26+
print-type-size field `.0`: 0 bytes
2727
print-type-size variant `Three`: 0 bytes
2828
print-type-size field `.0`: 0 bytes
2929
print-type-size variant `Four`: 0 bytes
3030
print-type-size field `.0`: 0 bytes
3131
print-type-size type: `MyOption<char>`: 4 bytes, alignment: 4 bytes
32-
print-type-size variant `None`: 0 bytes
3332
print-type-size variant `Some`: 4 bytes
3433
print-type-size field `.0`: 4 bytes
35-
print-type-size type: `MyOption<std::num::NonZeroU32>`: 4 bytes, alignment: 4 bytes
3634
print-type-size variant `None`: 0 bytes
35+
print-type-size type: `MyOption<std::num::NonZeroU32>`: 4 bytes, alignment: 4 bytes
3736
print-type-size variant `Some`: 4 bytes
3837
print-type-size field `.0`: 4 bytes
38+
print-type-size variant `None`: 0 bytes
3939
print-type-size type: `std::num::NonZeroU32`: 4 bytes, alignment: 4 bytes
4040
print-type-size field `.0`: 4 bytes
4141
print-type-size type: `Enum4<(), (), (), MyOption<u8>>`: 2 bytes, alignment: 1 bytes
42+
print-type-size variant `Four`: 2 bytes
43+
print-type-size field `.0`: 2 bytes
4244
print-type-size variant `One`: 0 bytes
4345
print-type-size field `.0`: 0 bytes
4446
print-type-size variant `Two`: 0 bytes
4547
print-type-size field `.0`: 0 bytes
4648
print-type-size variant `Three`: 0 bytes
4749
print-type-size field `.0`: 0 bytes
48-
print-type-size variant `Four`: 2 bytes
49-
print-type-size field `.0`: 2 bytes
5050
print-type-size type: `MyOption<MyOption<u8>>`: 2 bytes, alignment: 1 bytes
51-
print-type-size variant `None`: 0 bytes
5251
print-type-size variant `Some`: 2 bytes
5352
print-type-size field `.0`: 2 bytes
53+
print-type-size variant `None`: 0 bytes
5454
print-type-size type: `MyOption<u8>`: 2 bytes, alignment: 1 bytes
5555
print-type-size discriminant: 1 bytes
56-
print-type-size variant `None`: 0 bytes
5756
print-type-size variant `Some`: 1 bytes
5857
print-type-size field `.0`: 1 bytes
58+
print-type-size variant `None`: 0 bytes
5959
print-type-size type: `Enum4<(), (), bool, ()>`: 1 bytes, alignment: 1 bytes
60+
print-type-size variant `Three`: 1 bytes
61+
print-type-size field `.0`: 1 bytes
6062
print-type-size variant `One`: 0 bytes
6163
print-type-size field `.0`: 0 bytes
6264
print-type-size variant `Two`: 0 bytes
6365
print-type-size field `.0`: 0 bytes
64-
print-type-size variant `Three`: 1 bytes
65-
print-type-size field `.0`: 1 bytes
6666
print-type-size variant `Four`: 0 bytes
6767
print-type-size field `.0`: 0 bytes
6868
print-type-size type: `MyOption<bool>`: 1 bytes, alignment: 1 bytes
69-
print-type-size variant `None`: 0 bytes
7069
print-type-size variant `Some`: 1 bytes
7170
print-type-size field `.0`: 1 bytes
72-
print-type-size type: `MyOption<std::cmp::Ordering>`: 1 bytes, alignment: 1 bytes
7371
print-type-size variant `None`: 0 bytes
72+
print-type-size type: `MyOption<std::cmp::Ordering>`: 1 bytes, alignment: 1 bytes
7473
print-type-size variant `Some`: 1 bytes
7574
print-type-size field `.0`: 1 bytes
75+
print-type-size variant `None`: 0 bytes
7676
print-type-size type: `std::cmp::Ordering`: 1 bytes, alignment: 1 bytes
7777
print-type-size discriminant: 1 bytes
7878
print-type-size variant `Less`: 0 bytes

src/test/ui/print_type_sizes/padding.stdout

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
print-type-size type: `E1`: 12 bytes, alignment: 4 bytes
22
print-type-size discriminant: 1 bytes
3+
print-type-size variant `B`: 11 bytes
4+
print-type-size padding: 3 bytes
5+
print-type-size field `.0`: 8 bytes, alignment: 4 bytes
36
print-type-size variant `A`: 7 bytes
47
print-type-size field `.1`: 1 bytes
58
print-type-size padding: 2 bytes
69
print-type-size field `.0`: 4 bytes, alignment: 4 bytes
10+
print-type-size type: `E2`: 12 bytes, alignment: 4 bytes
11+
print-type-size discriminant: 1 bytes
712
print-type-size variant `B`: 11 bytes
813
print-type-size padding: 3 bytes
914
print-type-size field `.0`: 8 bytes, alignment: 4 bytes
10-
print-type-size type: `E2`: 12 bytes, alignment: 4 bytes
11-
print-type-size discriminant: 1 bytes
1215
print-type-size variant `A`: 7 bytes
1316
print-type-size field `.0`: 1 bytes
1417
print-type-size padding: 2 bytes
1518
print-type-size field `.1`: 4 bytes, alignment: 4 bytes
16-
print-type-size variant `B`: 11 bytes
17-
print-type-size padding: 3 bytes
18-
print-type-size field `.0`: 8 bytes, alignment: 4 bytes
1919
print-type-size type: `S`: 8 bytes, alignment: 4 bytes
2020
print-type-size field `.g`: 4 bytes
2121
print-type-size field `.a`: 1 bytes

src/test/ui/print_type_sizes/repr-align.stdout

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
print-type-size type: `E`: 32 bytes, alignment: 16 bytes
22
print-type-size discriminant: 4 bytes
3-
print-type-size variant `A`: 4 bytes
4-
print-type-size field `.0`: 4 bytes
53
print-type-size variant `B`: 28 bytes
64
print-type-size padding: 12 bytes
75
print-type-size field `.0`: 16 bytes, alignment: 16 bytes
6+
print-type-size variant `A`: 4 bytes
7+
print-type-size field `.0`: 4 bytes
88
print-type-size type: `S`: 32 bytes, alignment: 16 bytes
99
print-type-size field `.c`: 16 bytes
1010
print-type-size field `.a`: 4 bytes

src/test/ui/print_type_sizes/variants.stdout

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
print-type-size type: `Enum`: 51 bytes, alignment: 1 bytes
22
print-type-size discriminant: 1 bytes
3-
print-type-size variant `Small`: 7 bytes
4-
print-type-size field `.0`: 7 bytes
53
print-type-size variant `Large`: 50 bytes
64
print-type-size field `.0`: 50 bytes
5+
print-type-size variant `Small`: 7 bytes
6+
print-type-size field `.0`: 7 bytes
77
print-type-size type: `FiftyBytes`: 50 bytes, alignment: 1 bytes
88
print-type-size field `.0`: 50 bytes
99
print-type-size type: `SevenBytes`: 7 bytes, alignment: 1 bytes

0 commit comments

Comments
 (0)