remove some uses of visit_all_item_likes in incremental, metadata and interface crates

Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
This commit is contained in:
Miguel Guarniz 2022-04-06 19:04:15 -04:00
parent b73b4de982
commit 0baf85e8b6
6 changed files with 64 additions and 7 deletions

View File

@ -147,7 +147,28 @@ pub fn check_dirty_clean_annotations(tcx: TyCtxt<'_>) {
tcx.dep_graph.with_ignore(|| {
let mut dirty_clean_visitor = DirtyCleanVisitor { tcx, checked_attrs: Default::default() };
tcx.hir().visit_all_item_likes(&mut dirty_clean_visitor);
let crate_items = tcx.hir_crate_items(());
for id in crate_items.items() {
let item = tcx.hir().item(id);
dirty_clean_visitor.check_item(item.def_id, item.span);
}
for id in crate_items.trait_items() {
let item = tcx.hir().trait_item(id);
dirty_clean_visitor.check_item(item.def_id, item.span);
}
for id in crate_items.impl_items() {
let item = tcx.hir().impl_item(id);
dirty_clean_visitor.check_item(item.def_id, item.span);
}
for id in crate_items.foreign_items() {
let item = tcx.hir().foreign_item(id);
dirty_clean_visitor.check_item(item.def_id, item.span);
}
let mut all_attrs = FindAllAttrs { tcx, found_attrs: vec![] };
tcx.hir().walk_attributes(&mut all_attrs);

View File

@ -7,7 +7,14 @@ use rustc_span::symbol::sym;
fn proc_macro_decls_static(tcx: TyCtxt<'_>, (): ()) -> Option<LocalDefId> {
let mut finder = Finder { tcx, decls: None };
tcx.hir().visit_all_item_likes(&mut finder);
for id in tcx.hir().items() {
let item = tcx.hir().item(id);
let attrs = finder.tcx.hir().attrs(item.hir_id());
if finder.tcx.sess.contains_name(attrs, sym::rustc_proc_macro_decls) {
finder.decls = Some(item.hir_id());
}
}
finder.decls.map(|id| tcx.hir().local_def_id(id))
}

View File

@ -4,9 +4,16 @@ use rustc_middle::ty::TyCtxt;
use rustc_session::cstore::ForeignModule;
crate fn collect(tcx: TyCtxt<'_>) -> Vec<ForeignModule> {
let mut collector = Collector { modules: Vec::new() };
tcx.hir().visit_all_item_likes(&mut collector);
collector.modules
let mut modules = Vec::new();
for id in tcx.hir().items() {
let item = tcx.hir().item(id);
let hir::ItemKind::ForeignMod { items, .. } = item.kind else {
continue;
};
let foreign_items = items.iter().map(|it| it.id.def_id.to_def_id()).collect();
modules.push(ForeignModule { foreign_items, def_id: id.def_id.to_def_id() });
}
modules
}
struct Collector {

View File

@ -15,7 +15,10 @@ use rustc_target::spec::abi::Abi;
crate fn collect(tcx: TyCtxt<'_>) -> Vec<NativeLib> {
let mut collector = Collector { tcx, libs: Vec::new() };
tcx.hir().visit_all_item_likes(&mut collector);
for id in tcx.hir().items() {
let item = tcx.hir().item(id);
collector.visit_item(item);
}
collector.process_command_line();
collector.libs
}

View File

@ -1784,7 +1784,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
empty_proc_macro!(self);
let tcx = self.tcx;
let mut visitor = ImplsVisitor { tcx, impls: FxHashMap::default() };
tcx.hir().visit_all_item_likes(&mut visitor);
for id in tcx.hir().items() {
let item = tcx.hir().item(id);
visitor.visit_item(item);
}
let mut all_impls: Vec<_> = visitor.impls.into_iter().collect();

View File

@ -45,6 +45,21 @@ pub struct ModuleItems {
foreign_items: Box<[ForeignItemId]>,
}
impl ModuleItems {
pub fn items(&self) -> impl Iterator<Item = ItemId> {
self.items.to_vec().into_iter()
}
pub fn trait_items(&self) -> impl Iterator<Item = TraitItemId> {
self.trait_items.to_vec().into_iter()
}
pub fn impl_items(&self) -> impl Iterator<Item = ImplItemId> {
self.impl_items.to_vec().into_iter()
}
pub fn foreign_items(&self) -> impl Iterator<Item = ForeignItemId> {
self.foreign_items.to_vec().into_iter()
}
}
impl<'tcx> TyCtxt<'tcx> {
#[inline(always)]
pub fn hir(self) -> map::Map<'tcx> {