Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal: Reduce the number of traits passed through chalk during applicable trait lookup #9017

Merged
merged 1 commit into from
May 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions crates/ide_db/src/helpers/import_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@ fn trait_applicable_items(

let db = sema.db;

let related_dyn_traits =
trait_candidate.receiver_ty.applicable_inherent_traits(db).collect::<FxHashSet<_>>();
let mut required_assoc_items = FxHashSet::default();
let trait_candidates = items_locator::items_with_name(
sema,
Expand All @@ -431,13 +433,15 @@ fn trait_applicable_items(
.filter_map(|input| item_as_assoc(db, input))
.filter_map(|assoc| {
let assoc_item_trait = assoc.containing_trait(db)?;
required_assoc_items.insert(assoc);
Some(assoc_item_trait.into())
if related_dyn_traits.contains(&assoc_item_trait) {
None
} else {
required_assoc_items.insert(assoc);
Some(assoc_item_trait.into())
}
})
.collect();

let related_dyn_traits =
trait_candidate.receiver_ty.applicable_inherent_traits(db).collect::<FxHashSet<_>>();
let mut located_imports = FxHashSet::default();

if trait_assoc_item {
Expand All @@ -454,10 +458,6 @@ fn trait_applicable_items(
}
}
let located_trait = assoc.containing_trait(db)?;
if related_dyn_traits.contains(&located_trait) {
return None;
}

let trait_item = ItemInNs::from(ModuleDef::from(located_trait));
let original_item = assoc_to_item(assoc);
located_imports.insert(LocatedImport::new(
Expand All @@ -480,9 +480,6 @@ fn trait_applicable_items(
let assoc = function.as_assoc_item(db)?;
if required_assoc_items.contains(&assoc) {
let located_trait = assoc.containing_trait(db)?;
if related_dyn_traits.contains(&located_trait) {
return None;
}
let trait_item = ItemInNs::from(ModuleDef::from(located_trait));
let original_item = assoc_to_item(assoc);
located_imports.insert(LocatedImport::new(
Expand Down