1
Fork 0

Auto merge of #88435 - cjgillot:no-walk-crate, r=Aaron1011

Avoid invoking the hir_crate query to traverse the HIR

Walking the HIR tree is done using the `hir_crate` query. However, this is unnecessary, since `hir_owner(CRATE_DEF_ID)` provides the same information. Since depending on `hir_crate` forces dependents to always be executed, this leads to unnecessary work.

By splitting HIR and attributes visits, we can avoid an edge to `hir_crate` when trying to visit the HIR tree.
This commit is contained in:
bors 2021-09-05 21:40:34 +00:00
commit 7849e3e9dd
25 changed files with 117 additions and 132 deletions

View file

@ -451,9 +451,8 @@ fn late_lint_pass_crate<'tcx, T: LateLintPass<'tcx>>(tcx: TyCtxt<'tcx>, pass: T)
// since the root module isn't visited as an item (because it isn't an
// item), warn for it here.
lint_callback!(cx, check_crate, krate);
hir_visit::walk_crate(cx, krate);
tcx.hir().walk_toplevel_module(cx);
tcx.hir().walk_attributes(cx);
lint_callback!(cx, check_crate_post, krate);
})
}

View file

@ -37,7 +37,7 @@ fn lint_levels(tcx: TyCtxt<'_>, (): ()) -> LintLevelMap {
let push = builder.levels.push(tcx.hir().attrs(hir::CRATE_HIR_ID), &store, true);
builder.levels.register_id(hir::CRATE_HIR_ID);
intravisit::walk_crate(&mut builder, krate);
tcx.hir().walk_toplevel_module(&mut builder);
builder.levels.pop(push);
builder.levels.build_map()