Skip to content

Commit 13a4540

Browse files
committed
Auto merge of #141725 - nnethercote:avoid-UsePath-overcounting, r=BoxyUwU
Avoid over-counting of `UsePath` in the HIR stats. Currently we over-count. Details in the individual commits. r? `@BoxyUwU`
2 parents 337c11e + ac33068 commit 13a4540

File tree

3 files changed

+173
-163
lines changed

3 files changed

+173
-163
lines changed

compiler/rustc_passes/src/input_stats.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,16 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
426426
hir_visit::walk_fn(self, fk, fd, b, id)
427427
}
428428

429-
fn visit_use(&mut self, p: &'v hir::UsePath<'v>, hir_id: HirId) {
429+
fn visit_use(&mut self, p: &'v hir::UsePath<'v>, _hir_id: HirId) {
430430
// This is `visit_use`, but the type is `Path` so record it that way.
431431
self.record("Path", None, p);
432-
hir_visit::walk_use(self, p, hir_id)
432+
// Don't call `hir_visit::walk_use(self, p, hir_id)`: it calls
433+
// `visit_path` up to three times, once for each namespace result in
434+
// `p.res`, by building temporary `Path`s that are not part of the real
435+
// HIR, which causes `p` to be double- or triple-counted. Instead just
436+
// walk the path internals (i.e. the segments) directly.
437+
let hir::Path { span: _, res: _, segments } = *p;
438+
ast_visit::walk_list!(self, visit_path_segment, segments);
433439
}
434440

435441
fn visit_trait_item(&mut self, ti: &'v hir::TraitItem<'v>) {

tests/ui/stats/input-stats.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
//@ only-64bit
44
// layout randomization affects the hir stat output
55
//@ needs-deterministic-layouts
6+
//
7+
// Filter out the percentages because a change to a single count can affect
8+
// many or all percentages, which makes the diffs hard to read.
9+
//@ normalize-stderr: "\([0-9 ][0-9]\.[0-9]%\)" -> "(NN.N%)"
610

711
// Type layouts sometimes change. When that happens, until the next bootstrap
812
// bump occurs, stage1 and stage2 will give different outputs for this test.

0 commit comments

Comments
 (0)