Avoid more invocations of hir_crate query.
This commit is contained in:
parent
11491938f8
commit
db9fea508a
41 changed files with 123 additions and 141 deletions
|
@ -510,15 +510,14 @@ fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt<'_>, id: hir::HirId) -> bool {
|
|||
// or
|
||||
// 2) We are not sure to be live or not
|
||||
// * Implementations of traits and trait methods
|
||||
struct LifeSeeder<'k, 'tcx> {
|
||||
struct LifeSeeder<'tcx> {
|
||||
worklist: Vec<LocalDefId>,
|
||||
krate: &'k hir::Crate<'k>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
// see `MarkSymbolVisitor::struct_constructors`
|
||||
struct_constructors: FxHashMap<LocalDefId, LocalDefId>,
|
||||
}
|
||||
|
||||
impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
|
||||
impl<'v, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'tcx> {
|
||||
fn visit_item(&mut self, item: &hir::Item<'_>) {
|
||||
let allow_dead_code = has_allow_dead_code_or_lang_attr(self.tcx, item.hir_id());
|
||||
if allow_dead_code {
|
||||
|
@ -545,7 +544,7 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
|
|||
self.worklist.push(item.def_id);
|
||||
}
|
||||
for impl_item_ref in items {
|
||||
let impl_item = self.krate.impl_item(impl_item_ref.id);
|
||||
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
|
||||
if of_trait.is_some()
|
||||
|| has_allow_dead_code_or_lang_attr(self.tcx, impl_item.hir_id())
|
||||
{
|
||||
|
@ -589,7 +588,6 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
|
|||
fn create_and_seed_worklist<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
access_levels: &privacy::AccessLevels,
|
||||
krate: &hir::Crate<'_>,
|
||||
) -> (Vec<LocalDefId>, FxHashMap<LocalDefId, LocalDefId>) {
|
||||
let worklist = access_levels
|
||||
.map
|
||||
|
@ -604,9 +602,8 @@ fn create_and_seed_worklist<'tcx>(
|
|||
.collect::<Vec<_>>();
|
||||
|
||||
// Seed implemented trait items
|
||||
let mut life_seeder =
|
||||
LifeSeeder { worklist, krate, tcx, struct_constructors: Default::default() };
|
||||
krate.visit_all_item_likes(&mut life_seeder);
|
||||
let mut life_seeder = LifeSeeder { worklist, tcx, struct_constructors: Default::default() };
|
||||
tcx.hir().visit_all_item_likes(&mut life_seeder);
|
||||
|
||||
(life_seeder.worklist, life_seeder.struct_constructors)
|
||||
}
|
||||
|
@ -614,9 +611,8 @@ fn create_and_seed_worklist<'tcx>(
|
|||
fn find_live<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
access_levels: &privacy::AccessLevels,
|
||||
krate: &hir::Crate<'_>,
|
||||
) -> FxHashSet<LocalDefId> {
|
||||
let (worklist, struct_constructors) = create_and_seed_worklist(tcx, access_levels, krate);
|
||||
let (worklist, struct_constructors) = create_and_seed_worklist(tcx, access_levels);
|
||||
let mut symbol_visitor = MarkSymbolVisitor {
|
||||
worklist,
|
||||
tcx,
|
||||
|
@ -834,8 +830,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
|
|||
|
||||
pub fn check_crate(tcx: TyCtxt<'_>) {
|
||||
let access_levels = &tcx.privacy_access_levels(());
|
||||
let krate = tcx.hir().krate();
|
||||
let live_symbols = find_live(tcx, access_levels, krate);
|
||||
let live_symbols = find_live(tcx, access_levels);
|
||||
let mut visitor = DeadVisitor { tcx, live_symbols };
|
||||
tcx.hir().walk_toplevel_module(&mut visitor);
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ fn diagnostic_items<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> FxHashMap<Symbol
|
|||
let mut collector = DiagnosticItemCollector::new(tcx);
|
||||
|
||||
// Collect diagnostic items in this crate.
|
||||
tcx.hir().krate().visit_all_item_likes(&mut collector);
|
||||
tcx.hir().visit_all_item_likes(&mut collector);
|
||||
|
||||
collector.items
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use rustc_ast::entry::EntryPointType;
|
||||
use rustc_errors::struct_span_err;
|
||||
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc_hir::def_id::{DefId, CRATE_DEF_ID, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
||||
use rustc_hir::{ForeignItem, HirId, ImplItem, Item, ItemKind, Node, TraitItem, CRATE_HIR_ID};
|
||||
use rustc_middle::hir::map::Map;
|
||||
|
@ -68,7 +68,7 @@ fn entry_fn(tcx: TyCtxt<'_>, (): ()) -> Option<(DefId, EntryFnType)> {
|
|||
non_main_fns: Vec::new(),
|
||||
};
|
||||
|
||||
tcx.hir().krate().visit_all_item_likes(&mut ctxt);
|
||||
tcx.hir().visit_all_item_likes(&mut ctxt);
|
||||
|
||||
configure_main(tcx, &ctxt)
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) -> Option<(De
|
|||
}
|
||||
|
||||
fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) {
|
||||
let sp = tcx.hir().krate().module().inner;
|
||||
let sp = tcx.def_span(CRATE_DEF_ID);
|
||||
if *tcx.sess.parse_sess.reached_eof.borrow() {
|
||||
// There's an unclosed brace that made the parser reach `Eof`, we shouldn't complain about
|
||||
// the missing `fn main()` then as it might have been hidden inside an unclosed block.
|
||||
|
|
|
@ -262,7 +262,7 @@ fn get_lang_items(tcx: TyCtxt<'_>, (): ()) -> LanguageItems {
|
|||
}
|
||||
|
||||
// Collect lang items in this crate.
|
||||
tcx.hir().krate().visit_all_item_likes(&mut collector);
|
||||
tcx.hir().visit_all_item_likes(&mut collector);
|
||||
|
||||
// Extract out the found lang items.
|
||||
let LanguageItemCollector { mut items, .. } = collector;
|
||||
|
|
|
@ -12,7 +12,7 @@ use rustc_target::abi::{HasDataLayout, TargetDataLayout};
|
|||
pub fn test_layout(tcx: TyCtxt<'_>) {
|
||||
if tcx.features().rustc_attrs {
|
||||
// if the `rustc_attrs` feature is not enabled, don't bother testing layout
|
||||
tcx.hir().krate().visit_all_item_likes(&mut LayoutTest { tcx });
|
||||
tcx.hir().visit_all_item_likes(&mut LayoutTest { tcx });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -427,7 +427,7 @@ fn reachable_set<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> FxHashSet<LocalDefId> {
|
|||
access_levels,
|
||||
worklist: &mut reachable_context.worklist,
|
||||
};
|
||||
tcx.hir().krate().visit_all_item_likes(&mut collect_private_impl_items);
|
||||
tcx.hir().visit_all_item_likes(&mut collect_private_impl_items);
|
||||
}
|
||||
|
||||
// Step 2: Mark all symbols that the symbols on the worklist touch.
|
||||
|
|
|
@ -906,11 +906,10 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
|
|||
let access_levels = &tcx.privacy_access_levels(());
|
||||
|
||||
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, tcx.hir().span(CRATE_HIR_ID));
|
||||
tcx.hir().walk_toplevel_module(&mut missing);
|
||||
krate.visit_all_item_likes(&mut missing.as_deep_visitor());
|
||||
tcx.hir().visit_all_item_likes(&mut missing.as_deep_visitor());
|
||||
}
|
||||
|
||||
let declared_lang_features = &tcx.features().declared_lang_features;
|
||||
|
|
|
@ -33,7 +33,7 @@ pub fn check_crate<'tcx>(tcx: TyCtxt<'tcx>, items: &mut lang_items::LanguageItem
|
|||
|
||||
{
|
||||
let mut cx = Context { tcx, items };
|
||||
tcx.hir().krate().visit_all_item_likes(&mut cx.as_deep_visitor());
|
||||
tcx.hir().visit_all_item_likes(&mut cx.as_deep_visitor());
|
||||
}
|
||||
verify(tcx, items);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue