Skip to content

Avoid over-counting of UsePath in the HIR stats. #141725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions compiler/rustc_passes/src/input_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,16 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
hir_visit::walk_fn(self, fk, fd, b, id)
}

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

fn visit_trait_item(&mut self, ti: &'v hir::TraitItem<'v>) {
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/stats/input-stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
//@ only-64bit
// layout randomization affects the hir stat output
//@ needs-deterministic-layouts
//
// Filter out the percentages because a change to a single count can affect
// many or all percentages, which makes the diffs hard to read.
//@ normalize-stderr: "\([0-9 ][0-9]\.[0-9]%\)" -> "(NN.N%)"

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