Skip to content

Commit 6cdfd1c

Browse files
Make find_path_inner a query
This eliminates any remaining performance problems in the "Implement default members" assist (at least that I've found).
1 parent 4677cea commit 6cdfd1c

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

crates/ra_hir_def/src/db.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::{
1717
item_scope::ItemInNs,
1818
lang_item::{LangItemTarget, LangItems},
1919
nameres::{raw::RawItems, CrateDefMap},
20+
path::ModPath,
2021
visibility::Visibility,
2122
AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc,
2223
GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId,
@@ -118,6 +119,9 @@ pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
118119
item: ItemInNs,
119120
krate: CrateId,
120121
) -> 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>;
121125
}
122126

123127
fn crate_def_map_wait(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> {

crates/ra_hir_def/src/find_path.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::{
2020
/// *from where* you're referring to the item, hence the `from` parameter.
2121
pub fn find_path(db: &dyn DefDatabase, item: ItemInNs, from: ModuleId) -> Option<ModPath> {
2222
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)
2424
}
2525

2626
const MAX_PATH_LEN: usize = 15;
@@ -49,7 +49,7 @@ impl ModPath {
4949
}
5050
}
5151

52-
fn find_path_inner(
52+
pub(crate) fn find_path_inner_query(
5353
db: &dyn DefDatabase,
5454
item: ItemInNs,
5555
from: ModuleId,
@@ -140,8 +140,7 @@ fn find_path_inner(
140140
let mut best_path = None;
141141
let mut best_path_len = max_len;
142142
for (module_id, name) in importable_locations {
143-
let mut path = match find_path_inner(
144-
db,
143+
let mut path = match db.find_path_inner(
145144
ItemInNs::Types(ModuleDefId::ModuleId(module_id)),
146145
from,
147146
best_path_len - 1,

0 commit comments

Comments
 (0)