remove ItemLikeVisitor impls and add fast paths using DefKind
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
This commit is contained in:
parent
0d01ee9558
commit
3d6f4c85ad
2 changed files with 26 additions and 41 deletions
|
@ -1783,14 +1783,31 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||||
debug!("EncodeContext::encode_traits_and_impls()");
|
debug!("EncodeContext::encode_traits_and_impls()");
|
||||||
empty_proc_macro!(self);
|
empty_proc_macro!(self);
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
let mut visitor = ImplsVisitor { tcx, impls: FxHashMap::default() };
|
let mut fx_hash_map: FxHashMap<DefId, Vec<(DefIndex, Option<SimplifiedType>)>> =
|
||||||
|
FxHashMap::default();
|
||||||
|
|
||||||
for id in tcx.hir().items() {
|
for id in tcx.hir().items() {
|
||||||
let item = tcx.hir().item(id);
|
match tcx.hir().def_kind(id.def_id) {
|
||||||
visitor.visit_item(item);
|
DefKind::Impl => {
|
||||||
|
let item = tcx.hir().item(id);
|
||||||
|
if let Some(trait_ref) = tcx.impl_trait_ref(item.def_id.to_def_id()) {
|
||||||
|
let simplified_self_ty = fast_reject::simplify_type(
|
||||||
|
self.tcx,
|
||||||
|
trait_ref.self_ty(),
|
||||||
|
TreatParams::AsPlaceholders,
|
||||||
|
);
|
||||||
|
|
||||||
|
fx_hash_map
|
||||||
|
.entry(trait_ref.def_id)
|
||||||
|
.or_default()
|
||||||
|
.push((item.def_id.local_def_index, simplified_self_ty));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => continue,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut all_impls: Vec<_> = visitor.impls.into_iter().collect();
|
let mut all_impls: Vec<_> = fx_hash_map.into_iter().collect();
|
||||||
|
|
||||||
// Bring everything into deterministic order for hashing
|
// Bring everything into deterministic order for hashing
|
||||||
all_impls.sort_by_cached_key(|&(trait_def_id, _)| tcx.def_path_hash(trait_def_id));
|
all_impls.sort_by_cached_key(|&(trait_def_id, _)| tcx.def_path_hash(trait_def_id));
|
||||||
|
@ -2053,41 +2070,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ImplsVisitor<'tcx> {
|
|
||||||
tcx: TyCtxt<'tcx>,
|
|
||||||
impls: FxHashMap<DefId, Vec<(DefIndex, Option<SimplifiedType>)>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx, 'v> ItemLikeVisitor<'v> for ImplsVisitor<'tcx> {
|
|
||||||
fn visit_item(&mut self, item: &hir::Item<'_>) {
|
|
||||||
match item.kind {
|
|
||||||
hir::ItemKind::Impl(..) => {
|
|
||||||
if let Some(trait_ref) = self.tcx.impl_trait_ref(item.def_id.to_def_id()) {
|
|
||||||
let simplified_self_ty = fast_reject::simplify_type(
|
|
||||||
self.tcx,
|
|
||||||
trait_ref.self_ty(),
|
|
||||||
TreatParams::AsPlaceholders,
|
|
||||||
);
|
|
||||||
|
|
||||||
self.impls
|
|
||||||
.entry(trait_ref.def_id)
|
|
||||||
.or_default()
|
|
||||||
.push((item.def_id.local_def_index, simplified_self_ty));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn visit_trait_item(&mut self, _trait_item: &'v hir::TraitItem<'v>) {}
|
|
||||||
|
|
||||||
fn visit_impl_item(&mut self, _impl_item: &'v hir::ImplItem<'v>) {
|
|
||||||
// handled in `visit_item` above
|
|
||||||
}
|
|
||||||
|
|
||||||
fn visit_foreign_item(&mut self, _foreign_item: &'v hir::ForeignItem<'v>) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Used to prefetch queries which will be needed later by metadata encoding.
|
/// Used to prefetch queries which will be needed later by metadata encoding.
|
||||||
/// Only a subset of the queries are actually prefetched to keep this code smaller.
|
/// Only a subset of the queries are actually prefetched to keep this code smaller.
|
||||||
fn prefetch_mir(tcx: TyCtxt<'_>) {
|
fn prefetch_mir(tcx: TyCtxt<'_>) {
|
||||||
|
|
|
@ -9,7 +9,6 @@ use rustc_hir as hir;
|
||||||
use rustc_hir::def::{self, CtorKind, DefKind, Namespace};
|
use rustc_hir::def::{self, CtorKind, DefKind, Namespace};
|
||||||
use rustc_hir::def_id::{DefId, DefIdSet, CRATE_DEF_INDEX, LOCAL_CRATE};
|
use rustc_hir::def_id::{DefId, DefIdSet, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||||
use rustc_hir::definitions::{DefPathData, DefPathDataName, DisambiguatedDefPathData};
|
use rustc_hir::definitions::{DefPathData, DefPathDataName, DisambiguatedDefPathData};
|
||||||
use rustc_hir::ItemKind;
|
|
||||||
use rustc_session::config::TrimmedDefPaths;
|
use rustc_session::config::TrimmedDefPaths;
|
||||||
use rustc_session::cstore::{ExternCrate, ExternCrateSource};
|
use rustc_session::cstore::{ExternCrate, ExternCrateSource};
|
||||||
use rustc_span::symbol::{kw, Ident, Symbol};
|
use rustc_span::symbol::{kw, Ident, Symbol};
|
||||||
|
@ -2683,8 +2682,12 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
|
||||||
// Iterate all local crate items no matter where they are defined.
|
// Iterate all local crate items no matter where they are defined.
|
||||||
let hir = tcx.hir();
|
let hir = tcx.hir();
|
||||||
for id in hir.items() {
|
for id in hir.items() {
|
||||||
|
if matches!(hir.def_kind(id.def_id), DefKind::Use) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let item = hir.item(id);
|
let item = hir.item(id);
|
||||||
if item.ident.name.as_str().is_empty() || matches!(item.kind, ItemKind::Use(_, _)) {
|
if item.ident.name.as_str().is_empty() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue