Skip to content

Commit a5288a7

Browse files
authored
Rollup merge of rust-lang#107692 - Swatinem:printsizeyield, r=compiler-errors
Sort Generator `print-type-sizes` according to their yield points Especially when trying to diagnose runaway future sizes, it might be more intuitive to sort the variants according to the control flow (aka their yield points) rather than the size of the variants.
2 parents 64db7fb + dae0015 commit a5288a7

File tree

6 files changed

+25
-12
lines changed

6 files changed

+25
-12
lines changed

compiler/rustc_session/src/code_stats.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ impl CodeStats {
8484
// Sort variants so the largest ones are shown first. A stable sort is
8585
// used here so that source code order is preserved for all variants
8686
// that have the same size.
87-
variants.sort_by(|info1, info2| info2.size.cmp(&info1.size));
87+
// Except for Generators, whose variants are already sorted according to
88+
// their yield points in `variant_info_for_generator`.
89+
if kind != DataTypeKind::Generator {
90+
variants.sort_by(|info1, info2| info2.size.cmp(&info1.size));
91+
}
8892
let info = TypeSizeInfo {
8993
kind,
9094
type_description: type_desc.to_string(),

compiler/rustc_ty_utils/src/layout.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ fn variant_info_for_generator<'tcx>(
970970
})
971971
.collect();
972972

973-
let variant_infos: Vec<_> = generator
973+
let mut variant_infos: Vec<_> = generator
974974
.variant_fields
975975
.iter_enumerated()
976976
.map(|(variant_idx, variant_def)| {
@@ -1033,6 +1033,15 @@ fn variant_info_for_generator<'tcx>(
10331033
}
10341034
})
10351035
.collect();
1036+
1037+
// The first three variants are hardcoded to be `UNRESUMED`, `RETURNED` and `POISONED`.
1038+
// We will move the `RETURNED` and `POISONED` elements to the end so we
1039+
// are left with a sorting order according to the generators yield points:
1040+
// First `Unresumed`, then the `SuspendN` followed by `Returned` and `Panicked` (POISONED).
1041+
let end_states = variant_infos.drain(1..=2);
1042+
let end_states: Vec<_> = end_states.collect();
1043+
variant_infos.extend(end_states);
1044+
10361045
(
10371046
variant_infos,
10381047
match tag_encoding {

tests/ui/async-await/future-sizes/large-arg.stdout

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
print-type-size type: `[async fn body@$DIR/large-arg.rs:6:21: 8:2]`: 3076 bytes, alignment: 1 bytes
22
print-type-size discriminant: 1 bytes
3+
print-type-size variant `Unresumed`: 0 bytes
34
print-type-size variant `Suspend0`: 3075 bytes
45
print-type-size local `.__awaitee`: 3075 bytes, offset: 0 bytes, alignment: 1 bytes
5-
print-type-size variant `Unresumed`: 0 bytes
66
print-type-size variant `Returned`: 0 bytes
77
print-type-size variant `Panicked`: 0 bytes
88
print-type-size type: `[async fn body@$DIR/large-arg.rs:10:30: 12:2]`: 3075 bytes, alignment: 1 bytes
99
print-type-size discriminant: 1 bytes
10+
print-type-size variant `Unresumed`: 1024 bytes
11+
print-type-size upvar `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
1012
print-type-size variant `Suspend0`: 3074 bytes
1113
print-type-size upvar `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
1214
print-type-size local `.__awaitee`: 2050 bytes
13-
print-type-size variant `Unresumed`: 1024 bytes
14-
print-type-size upvar `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
1515
print-type-size variant `Returned`: 1024 bytes
1616
print-type-size upvar `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
1717
print-type-size variant `Panicked`: 1024 bytes
@@ -24,11 +24,11 @@ print-type-size field `.uninit`: 0 bytes
2424
print-type-size field `.value`: 3075 bytes
2525
print-type-size type: `[async fn body@$DIR/large-arg.rs:13:26: 15:2]`: 2050 bytes, alignment: 1 bytes
2626
print-type-size discriminant: 1 bytes
27+
print-type-size variant `Unresumed`: 1024 bytes
28+
print-type-size upvar `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
2729
print-type-size variant `Suspend0`: 2049 bytes
2830
print-type-size upvar `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
2931
print-type-size local `.__awaitee`: 1025 bytes
30-
print-type-size variant `Unresumed`: 1024 bytes
31-
print-type-size upvar `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
3232
print-type-size variant `Returned`: 1024 bytes
3333
print-type-size upvar `.t`: 1024 bytes, offset: 0 bytes, alignment: 1 bytes
3434
print-type-size variant `Panicked`: 1024 bytes

tests/ui/print_type_sizes/async.stdout

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
print-type-size type: `[async fn body@$DIR/async.rs:8:36: 11:2]`: 16386 bytes, alignment: 1 bytes
22
print-type-size discriminant: 1 bytes
3+
print-type-size variant `Unresumed`: 8192 bytes
4+
print-type-size upvar `.arg`: 8192 bytes, offset: 0 bytes, alignment: 1 bytes
35
print-type-size variant `Suspend0`: 16385 bytes
46
print-type-size upvar `.arg`: 8192 bytes, offset: 0 bytes, alignment: 1 bytes
57
print-type-size local `.arg`: 8192 bytes
68
print-type-size local `.__awaitee`: 1 bytes
7-
print-type-size variant `Unresumed`: 8192 bytes
8-
print-type-size upvar `.arg`: 8192 bytes, offset: 0 bytes, alignment: 1 bytes
99
print-type-size variant `Returned`: 8192 bytes
1010
print-type-size upvar `.arg`: 8192 bytes, offset: 0 bytes, alignment: 1 bytes
1111
print-type-size variant `Panicked`: 8192 bytes

tests/ui/print_type_sizes/generator.stdout

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ print-type-size type: `[generator@$DIR/generator.rs:10:5: 10:14]`: 8193 bytes, a
22
print-type-size discriminant: 1 bytes
33
print-type-size variant `Unresumed`: 8192 bytes
44
print-type-size upvar `.array`: 8192 bytes, offset: 0 bytes, alignment: 1 bytes
5+
print-type-size variant `Suspend0`: 8192 bytes
6+
print-type-size upvar `.array`: 8192 bytes, offset: 0 bytes, alignment: 1 bytes
57
print-type-size variant `Returned`: 8192 bytes
68
print-type-size upvar `.array`: 8192 bytes, offset: 0 bytes, alignment: 1 bytes
79
print-type-size variant `Panicked`: 8192 bytes
810
print-type-size upvar `.array`: 8192 bytes, offset: 0 bytes, alignment: 1 bytes
9-
print-type-size variant `Suspend0`: 8192 bytes
10-
print-type-size upvar `.array`: 8192 bytes, offset: 0 bytes, alignment: 1 bytes
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
print-type-size type: `[generator@$DIR/generator_discr_placement.rs:11:13: 11:15]`: 8 bytes, alignment: 4 bytes
22
print-type-size discriminant: 1 bytes
3+
print-type-size variant `Unresumed`: 0 bytes
34
print-type-size variant `Suspend0`: 7 bytes
45
print-type-size padding: 3 bytes
56
print-type-size local `.w`: 4 bytes, alignment: 4 bytes
67
print-type-size variant `Suspend1`: 7 bytes
78
print-type-size padding: 3 bytes
89
print-type-size local `.z`: 4 bytes, alignment: 4 bytes
9-
print-type-size variant `Unresumed`: 0 bytes
1010
print-type-size variant `Returned`: 0 bytes
1111
print-type-size variant `Panicked`: 0 bytes

0 commit comments

Comments
 (0)