Skip to content

Commit d727f86

Browse files
committed
Fix -Z inputs-stats ordering.
In #129533 the main hash function changed and the order of `-Z input-stats` output changed, which showed that it is dependent on the hash function, even though it is sorted. That's because entries with the same cumulative size are ordered in a way that depends on the hash function. This commit fixes that by using the entry label as the secondary ordering key.
1 parent d185062 commit d727f86

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

compiler/rustc_passes/src/input_stats.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ impl<'k> StatCollector<'k> {
152152
// We will soon sort, so the initial order does not matter.
153153
#[allow(rustc::potential_query_instability)]
154154
let mut subnodes: Vec<_> = node.subnodes.iter().collect();
155-
subnodes.sort_by_key(|(_, subnode)| subnode.count * subnode.size);
155+
subnodes.sort_by(|(label1, subnode1), (label2, subnode2)| {
156+
(subnode1.count * subnode1.size, label1)
157+
.cmp(&(subnode2.count * subnode2.size, label2))
158+
});
156159

157160
for (label, subnode) in subnodes {
158161
let size = subnode.count * subnode.size;

tests/ui/stats/input-stats.stderr

+17-17
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ ast-stats-1 Block 192 ( 2.9%) 6 32
2424
ast-stats-1 FieldDef 208 ( 3.1%) 2 104
2525
ast-stats-1 Variant 208 ( 3.1%) 2 104
2626
ast-stats-1 AssocItem 352 ( 5.3%) 4 88
27-
ast-stats-1 - Type 176 ( 2.6%) 2
2827
ast-stats-1 - Fn 176 ( 2.6%) 2
28+
ast-stats-1 - Type 176 ( 2.6%) 2
2929
ast-stats-1 GenericBound 352 ( 5.3%) 4 88
3030
ast-stats-1 - Trait 352 ( 5.3%) 4
3131
ast-stats-1 GenericParam 480 ( 7.2%) 5 96
@@ -34,22 +34,22 @@ ast-stats-1 - Struct 72 ( 1.1%) 1
3434
ast-stats-1 - Wild 72 ( 1.1%) 1
3535
ast-stats-1 - Ident 360 ( 5.4%) 5
3636
ast-stats-1 Expr 576 ( 8.6%) 8 72
37-
ast-stats-1 - Path 72 ( 1.1%) 1
3837
ast-stats-1 - Match 72 ( 1.1%) 1
38+
ast-stats-1 - Path 72 ( 1.1%) 1
3939
ast-stats-1 - Struct 72 ( 1.1%) 1
4040
ast-stats-1 - Lit 144 ( 2.2%) 2
4141
ast-stats-1 - Block 216 ( 3.2%) 3
4242
ast-stats-1 PathSegment 744 (11.1%) 31 24
4343
ast-stats-1 Ty 896 (13.4%) 14 64
44-
ast-stats-1 - Ref 64 ( 1.0%) 1
4544
ast-stats-1 - Ptr 64 ( 1.0%) 1
45+
ast-stats-1 - Ref 64 ( 1.0%) 1
4646
ast-stats-1 - ImplicitSelf 128 ( 1.9%) 2
4747
ast-stats-1 - Path 640 ( 9.6%) 10
4848
ast-stats-1 Item 1_224 (18.3%) 9 136
49+
ast-stats-1 - Enum 136 ( 2.0%) 1
4950
ast-stats-1 - ForeignMod 136 ( 2.0%) 1
50-
ast-stats-1 - Trait 136 ( 2.0%) 1
5151
ast-stats-1 - Impl 136 ( 2.0%) 1
52-
ast-stats-1 - Enum 136 ( 2.0%) 1
52+
ast-stats-1 - Trait 136 ( 2.0%) 1
5353
ast-stats-1 - Fn 272 ( 4.1%) 2
5454
ast-stats-1 - Use 408 ( 6.1%) 3
5555
ast-stats-1 ----------------------------------------------------------------
@@ -82,8 +82,8 @@ ast-stats-2 Block 192 ( 2.6%) 6 32
8282
ast-stats-2 FieldDef 208 ( 2.8%) 2 104
8383
ast-stats-2 Variant 208 ( 2.8%) 2 104
8484
ast-stats-2 AssocItem 352 ( 4.8%) 4 88
85-
ast-stats-2 - Type 176 ( 2.4%) 2
8685
ast-stats-2 - Fn 176 ( 2.4%) 2
86+
ast-stats-2 - Type 176 ( 2.4%) 2
8787
ast-stats-2 GenericBound 352 ( 4.8%) 4 88
8888
ast-stats-2 - Trait 352 ( 4.8%) 4
8989
ast-stats-2 GenericParam 480 ( 6.5%) 5 96
@@ -92,24 +92,24 @@ ast-stats-2 - Struct 72 ( 1.0%) 1
9292
ast-stats-2 - Wild 72 ( 1.0%) 1
9393
ast-stats-2 - Ident 360 ( 4.9%) 5
9494
ast-stats-2 Expr 648 ( 8.8%) 9 72
95-
ast-stats-2 - Path 72 ( 1.0%) 1
95+
ast-stats-2 - InlineAsm 72 ( 1.0%) 1
9696
ast-stats-2 - Match 72 ( 1.0%) 1
97+
ast-stats-2 - Path 72 ( 1.0%) 1
9798
ast-stats-2 - Struct 72 ( 1.0%) 1
98-
ast-stats-2 - InlineAsm 72 ( 1.0%) 1
9999
ast-stats-2 - Lit 144 ( 2.0%) 2
100100
ast-stats-2 - Block 216 ( 2.9%) 3
101101
ast-stats-2 PathSegment 864 (11.8%) 36 24
102102
ast-stats-2 Ty 896 (12.2%) 14 64
103-
ast-stats-2 - Ref 64 ( 0.9%) 1
104103
ast-stats-2 - Ptr 64 ( 0.9%) 1
104+
ast-stats-2 - Ref 64 ( 0.9%) 1
105105
ast-stats-2 - ImplicitSelf 128 ( 1.7%) 2
106106
ast-stats-2 - Path 640 ( 8.7%) 10
107107
ast-stats-2 Item 1_496 (20.4%) 11 136
108108
ast-stats-2 - Enum 136 ( 1.9%) 1
109-
ast-stats-2 - Trait 136 ( 1.9%) 1
110-
ast-stats-2 - Impl 136 ( 1.9%) 1
111109
ast-stats-2 - ExternCrate 136 ( 1.9%) 1
112110
ast-stats-2 - ForeignMod 136 ( 1.9%) 1
111+
ast-stats-2 - Impl 136 ( 1.9%) 1
112+
ast-stats-2 - Trait 136 ( 1.9%) 1
113113
ast-stats-2 - Fn 272 ( 3.7%) 2
114114
ast-stats-2 - Use 544 ( 7.4%) 4
115115
ast-stats-2 ----------------------------------------------------------------
@@ -135,9 +135,9 @@ hir-stats WherePredicate 72 ( 0.8%) 3 24
135135
hir-stats - BoundPredicate 72 ( 0.8%) 3
136136
hir-stats Arm 80 ( 0.9%) 2 40
137137
hir-stats Stmt 96 ( 1.1%) 3 32
138+
hir-stats - Expr 32 ( 0.4%) 1
138139
hir-stats - Let 32 ( 0.4%) 1
139140
hir-stats - Semi 32 ( 0.4%) 1
140-
hir-stats - Expr 32 ( 0.4%) 1
141141
hir-stats FnDecl 120 ( 1.3%) 3 40
142142
hir-stats Attribute 128 ( 1.4%) 4 32
143143
hir-stats FieldDef 128 ( 1.4%) 2 64
@@ -153,22 +153,22 @@ hir-stats - Wild 72 ( 0.8%) 1
153153
hir-stats - Binding 216 ( 2.4%) 3
154154
hir-stats Generics 560 ( 6.3%) 10 56
155155
hir-stats Ty 720 ( 8.1%) 15 48
156-
hir-stats - Ref 48 ( 0.5%) 1
157156
hir-stats - Ptr 48 ( 0.5%) 1
157+
hir-stats - Ref 48 ( 0.5%) 1
158158
hir-stats - Path 624 ( 7.0%) 13
159159
hir-stats Expr 768 ( 8.6%) 12 64
160-
hir-stats - Path 64 ( 0.7%) 1
160+
hir-stats - InlineAsm 64 ( 0.7%) 1
161161
hir-stats - Match 64 ( 0.7%) 1
162+
hir-stats - Path 64 ( 0.7%) 1
162163
hir-stats - Struct 64 ( 0.7%) 1
163-
hir-stats - InlineAsm 64 ( 0.7%) 1
164164
hir-stats - Lit 128 ( 1.4%) 2
165165
hir-stats - Block 384 ( 4.3%) 6
166166
hir-stats Item 968 (10.8%) 11 88
167167
hir-stats - Enum 88 ( 1.0%) 1
168-
hir-stats - Trait 88 ( 1.0%) 1
169-
hir-stats - Impl 88 ( 1.0%) 1
170168
hir-stats - ExternCrate 88 ( 1.0%) 1
171169
hir-stats - ForeignMod 88 ( 1.0%) 1
170+
hir-stats - Impl 88 ( 1.0%) 1
171+
hir-stats - Trait 88 ( 1.0%) 1
172172
hir-stats - Fn 176 ( 2.0%) 2
173173
hir-stats - Use 352 ( 3.9%) 4
174174
hir-stats Path 1_240 (13.9%) 31 40

0 commit comments

Comments
 (0)