mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Speedup trait impl search for goto_implementation
This commit is contained in:
parent
6c782a5314
commit
6241567948
2 changed files with 19 additions and 3 deletions
|
@ -51,7 +51,8 @@ use hir_expand::{diagnostics::DiagnosticSink, name::name, MacroDefKind};
|
||||||
use hir_ty::{
|
use hir_ty::{
|
||||||
autoderef,
|
autoderef,
|
||||||
display::{write_bounds_like_dyn_trait_with_prefix, HirDisplayError, HirFormatter},
|
display::{write_bounds_like_dyn_trait_with_prefix, HirDisplayError, HirFormatter},
|
||||||
method_resolution, to_assoc_type_id,
|
method_resolution::{self, TyFingerprint},
|
||||||
|
to_assoc_type_id,
|
||||||
traits::{FnTrait, Solution, SolutionVariables},
|
traits::{FnTrait, Solution, SolutionVariables},
|
||||||
AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, DebruijnIndex, GenericPredicate,
|
AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, DebruijnIndex, GenericPredicate,
|
||||||
InEnvironment, Interner, Obligation, ProjectionPredicate, ProjectionTy, Scalar, Substs, Ty,
|
InEnvironment, Interner, Obligation, ProjectionPredicate, ProjectionTy, Scalar, Substs, Ty,
|
||||||
|
@ -1500,13 +1501,20 @@ impl Impl {
|
||||||
def_crates.iter().for_each(|&id| {
|
def_crates.iter().for_each(|&id| {
|
||||||
all.extend(db.inherent_impls_in_crate(id).all_impls().map(Self::from).filter(filter))
|
all.extend(db.inherent_impls_in_crate(id).all_impls().map(Self::from).filter(filter))
|
||||||
});
|
});
|
||||||
|
let fp = TyFingerprint::for_impl(&ty.value);
|
||||||
for id in def_crates
|
for id in def_crates
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|&id| Crate { id }.reverse_dependencies(db))
|
.flat_map(|&id| Crate { id }.reverse_dependencies(db))
|
||||||
.map(|Crate { id }| id)
|
.map(|Crate { id }| id)
|
||||||
.chain(def_crates.iter().copied())
|
.chain(def_crates.iter().copied())
|
||||||
{
|
{
|
||||||
all.extend(db.trait_impls_in_crate(id).all_impls().map(Self::from).filter(filter));
|
match fp {
|
||||||
|
Some(fp) => all.extend(
|
||||||
|
db.trait_impls_in_crate(id).for_self_ty(fp).map(Self::from).filter(filter),
|
||||||
|
),
|
||||||
|
None => all
|
||||||
|
.extend(db.trait_impls_in_crate(id).all_impls().map(Self::from).filter(filter)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
all
|
all
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ impl TyFingerprint {
|
||||||
/// Creates a TyFingerprint for looking up an impl. Only certain types can
|
/// Creates a TyFingerprint for looking up an impl. Only certain types can
|
||||||
/// have impls: if we have some `struct S`, we can have an `impl S`, but not
|
/// have impls: if we have some `struct S`, we can have an `impl S`, but not
|
||||||
/// `impl &S`. Hence, this will return `None` for reference types and such.
|
/// `impl &S`. Hence, this will return `None` for reference types and such.
|
||||||
pub(crate) fn for_impl(ty: &Ty) -> Option<TyFingerprint> {
|
pub fn for_impl(ty: &Ty) -> Option<TyFingerprint> {
|
||||||
let fp = match *ty.interned(&Interner) {
|
let fp = match *ty.interned(&Interner) {
|
||||||
TyKind::Str => TyFingerprint::Str,
|
TyKind::Str => TyFingerprint::Str,
|
||||||
TyKind::Never => TyFingerprint::Never,
|
TyKind::Never => TyFingerprint::Never,
|
||||||
|
@ -141,6 +141,14 @@ impl TraitImpls {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Queries all trait impls for the given type.
|
||||||
|
pub fn for_self_ty(&self, fp: TyFingerprint) -> impl Iterator<Item = ImplId> + '_ {
|
||||||
|
self.map
|
||||||
|
.values()
|
||||||
|
.flat_map(move |impls| impls.get(&None).into_iter().chain(impls.get(&Some(fp))))
|
||||||
|
.flat_map(|it| it.iter().copied())
|
||||||
|
}
|
||||||
|
|
||||||
/// Queries all impls of the given trait.
|
/// Queries all impls of the given trait.
|
||||||
pub fn for_trait(&self, trait_: TraitId) -> impl Iterator<Item = ImplId> + '_ {
|
pub fn for_trait(&self, trait_: TraitId) -> impl Iterator<Item = ImplId> + '_ {
|
||||||
self.map
|
self.map
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue