Skip to content

Commit ac33068

Browse files
committed
Avoid over-counting of UsePath in the HIR stats.
1 parent 7fff114 commit ac33068

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
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.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ hir-stats - Impl 88 (NN.N%) 1
171171
hir-stats - Trait 88 (NN.N%) 1
172172
hir-stats - Fn 176 (NN.N%) 2
173173
hir-stats - Use 352 (NN.N%) 4
174-
hir-stats Path 1_240 (NN.N%) 31 40
175-
hir-stats PathSegment 1_920 (NN.N%) 40 48
174+
hir-stats Path 1_040 (NN.N%) 26 40
175+
hir-stats PathSegment 1_776 (NN.N%) 37 48
176176
hir-stats ----------------------------------------------------------------
177-
hir-stats Total 8_988 180
177+
hir-stats Total 8_644 172
178178
hir-stats

0 commit comments

Comments
 (0)