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:
commit
7849e3e9dd
25 changed files with 117 additions and 132 deletions
|
@ -775,5 +775,5 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
|
|||
let krate = tcx.hir().krate();
|
||||
let live_symbols = find_live(tcx, access_levels, krate);
|
||||
let mut visitor = DeadVisitor { tcx, live_symbols };
|
||||
intravisit::walk_crate(&mut visitor, krate);
|
||||
tcx.hir().walk_toplevel_module(&mut visitor);
|
||||
}
|
||||
|
|
|
@ -11,6 +11,10 @@ use rustc_middle::ty::TyCtxt;
|
|||
pub fn check_crate(tcx: TyCtxt<'_>) {
|
||||
tcx.dep_graph.assert_ignored();
|
||||
|
||||
if tcx.sess.opts.debugging_opts.hir_stats {
|
||||
crate::hir_stats::print_hir_stats(tcx);
|
||||
}
|
||||
|
||||
let errors = Lock::new(Vec::new());
|
||||
let hir_map = tcx.hir();
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ use rustc_hir as hir;
|
|||
use rustc_hir::intravisit as hir_visit;
|
||||
use rustc_hir::HirId;
|
||||
use rustc_middle::hir::map::Map;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_middle::util::common::to_readable_str;
|
||||
use rustc_span::Span;
|
||||
|
||||
|
@ -25,18 +26,19 @@ struct NodeData {
|
|||
}
|
||||
|
||||
struct StatCollector<'k> {
|
||||
krate: Option<&'k hir::Crate<'k>>,
|
||||
krate: Option<Map<'k>>,
|
||||
data: FxHashMap<&'static str, NodeData>,
|
||||
seen: FxHashSet<Id>,
|
||||
}
|
||||
|
||||
pub fn print_hir_stats(krate: &hir::Crate<'_>) {
|
||||
pub fn print_hir_stats(tcx: TyCtxt<'_>) {
|
||||
let mut collector = StatCollector {
|
||||
krate: Some(krate),
|
||||
krate: Some(tcx.hir()),
|
||||
data: FxHashMap::default(),
|
||||
seen: FxHashSet::default(),
|
||||
};
|
||||
hir_visit::walk_crate(&mut collector, krate);
|
||||
tcx.hir().walk_toplevel_module(&mut collector);
|
||||
tcx.hir().walk_attributes(&mut collector);
|
||||
collector.print("HIR STATS");
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
use rustc_ast::{Attribute, MetaItem, MetaItemKind};
|
||||
use rustc_errors::struct_span_err;
|
||||
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
|
||||
use rustc_hir::intravisit::{NestedVisitorMap, Visitor};
|
||||
use rustc_middle::hir::map::Map;
|
||||
use rustc_middle::middle::lib_features::LibFeatures;
|
||||
use rustc_middle::ty::query::Providers;
|
||||
|
@ -126,9 +126,7 @@ impl Visitor<'tcx> for LibFeatureCollector<'tcx> {
|
|||
|
||||
fn get_lib_features(tcx: TyCtxt<'_>, (): ()) -> LibFeatures {
|
||||
let mut collector = LibFeatureCollector::new(tcx);
|
||||
let krate = tcx.hir().krate();
|
||||
|
||||
intravisit::walk_crate(&mut collector, krate);
|
||||
tcx.hir().walk_attributes(&mut collector);
|
||||
collector.lib_features
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ use rustc_errors::struct_span_err;
|
|||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc_hir::hir_id::CRATE_HIR_ID;
|
||||
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
|
||||
use rustc_hir::{FieldDef, Generics, HirId, Item, TraitRef, Ty, TyKind, Variant};
|
||||
use rustc_middle::hir::map::Map;
|
||||
|
@ -678,7 +679,6 @@ fn stability_index(tcx: TyCtxt<'tcx>, (): ()) -> Index<'tcx> {
|
|||
.collect();
|
||||
|
||||
{
|
||||
let krate = tcx.hir().krate();
|
||||
let mut annotator = Annotator {
|
||||
tcx,
|
||||
index: &mut index,
|
||||
|
@ -711,13 +711,13 @@ fn stability_index(tcx: TyCtxt<'tcx>, (): ()) -> Index<'tcx> {
|
|||
|
||||
annotator.annotate(
|
||||
CRATE_DEF_ID,
|
||||
krate.module().inner,
|
||||
tcx.hir().span(CRATE_HIR_ID),
|
||||
None,
|
||||
AnnotationKind::Required,
|
||||
InheritDeprecation::Yes,
|
||||
InheritConstStability::No,
|
||||
InheritStability::No,
|
||||
|v| intravisit::walk_crate(v, krate),
|
||||
|v| tcx.hir().walk_toplevel_module(v),
|
||||
);
|
||||
}
|
||||
index
|
||||
|
@ -908,8 +908,8 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
|
|||
if tcx.stability().staged_api[&LOCAL_CRATE] {
|
||||
let krate = tcx.hir().krate();
|
||||
let mut missing = MissingStabilityAnnotations { tcx, access_levels };
|
||||
missing.check_missing_stability(CRATE_DEF_ID, krate.module().inner);
|
||||
intravisit::walk_crate(&mut missing, krate);
|
||||
missing.check_missing_stability(CRATE_DEF_ID, tcx.hir().span(CRATE_HIR_ID));
|
||||
tcx.hir().walk_toplevel_module(&mut missing);
|
||||
krate.visit_all_item_likes(&mut missing.as_deep_visitor());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue