aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-05-21 00:48:02 +0100
committerGitHub <[email protected]>2020-05-21 00:48:02 +0100
commit42dd0ce51ffee1dbfc58be7ebb0861aa2331b9cc (patch)
tree6e436f2bb3f7d1088db31ce8d9aad0146ef9eec4 /crates
parente632d07015e3aad6f81a87c5abf178ae60c86d1a (diff)
parent6cdfd1c3cf3d58eee90b5034d4e2d702fdc0f8f5 (diff)
Merge #4506
4506: Make `find_path_inner` a query r=matklad a=jonas-schievink This eliminates the remaining performance problems in the "Implement default members" assist (at least those that I've found). Closes https://github.com/rust-analyzer/rust-analyzer/issues/4498 Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir_def/src/db.rs4
-rw-r--r--crates/ra_hir_def/src/find_path.rs7
2 files changed, 7 insertions, 4 deletions
diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs
index 2f71511ba..945a0025e 100644
--- a/crates/ra_hir_def/src/db.rs
+++ b/crates/ra_hir_def/src/db.rs
@@ -17,6 +17,7 @@ use crate::{
17 item_scope::ItemInNs, 17 item_scope::ItemInNs,
18 lang_item::{LangItemTarget, LangItems}, 18 lang_item::{LangItemTarget, LangItems},
19 nameres::{raw::RawItems, CrateDefMap}, 19 nameres::{raw::RawItems, CrateDefMap},
20 path::ModPath,
20 visibility::Visibility, 21 visibility::Visibility,
21 AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc, 22 AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc,
22 GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId, 23 GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId,
@@ -118,6 +119,9 @@ pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
118 item: ItemInNs, 119 item: ItemInNs,
119 krate: CrateId, 120 krate: CrateId,
120 ) -> Arc<[(ModuleId, Name, Visibility)]>; 121 ) -> Arc<[(ModuleId, Name, Visibility)]>;
122
123 #[salsa::invoke(find_path::find_path_inner_query)]
124 fn find_path_inner(&self, item: ItemInNs, from: ModuleId, max_len: usize) -> Option<ModPath>;
121} 125}
122 126
123fn crate_def_map_wait(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> { 127fn crate_def_map_wait(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> {
diff --git a/crates/ra_hir_def/src/find_path.rs b/crates/ra_hir_def/src/find_path.rs
index 68d3cde08..4db798473 100644
--- a/crates/ra_hir_def/src/find_path.rs
+++ b/crates/ra_hir_def/src/find_path.rs
@@ -20,7 +20,7 @@ use crate::{
20/// *from where* you're referring to the item, hence the `from` parameter. 20/// *from where* you're referring to the item, hence the `from` parameter.
21pub fn find_path(db: &dyn DefDatabase, item: ItemInNs, from: ModuleId) -> Option<ModPath> { 21pub fn find_path(db: &dyn DefDatabase, item: ItemInNs, from: ModuleId) -> Option<ModPath> {
22 let _p = profile("find_path"); 22 let _p = profile("find_path");
23 find_path_inner(db, item, from, MAX_PATH_LEN) 23 db.find_path_inner(item, from, MAX_PATH_LEN)
24} 24}
25 25
26const MAX_PATH_LEN: usize = 15; 26const MAX_PATH_LEN: usize = 15;
@@ -49,7 +49,7 @@ impl ModPath {
49 } 49 }
50} 50}
51 51
52fn find_path_inner( 52pub(crate) fn find_path_inner_query(
53 db: &dyn DefDatabase, 53 db: &dyn DefDatabase,
54 item: ItemInNs, 54 item: ItemInNs,
55 from: ModuleId, 55 from: ModuleId,
@@ -140,8 +140,7 @@ fn find_path_inner(
140 let mut best_path = None; 140 let mut best_path = None;
141 let mut best_path_len = max_len; 141 let mut best_path_len = max_len;
142 for (module_id, name) in importable_locations { 142 for (module_id, name) in importable_locations {
143 let mut path = match find_path_inner( 143 let mut path = match db.find_path_inner(
144 db,
145 ItemInNs::Types(ModuleDefId::ModuleId(module_id)), 144 ItemInNs::Types(ModuleDefId::ModuleId(module_id)),
146 from, 145 from,
147 best_path_len - 1, 146 best_path_len - 1,