Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-db/src/symbol_index.rs')
-rw-r--r--crates/ide-db/src/symbol_index.rs55
1 files changed, 18 insertions, 37 deletions
diff --git a/crates/ide-db/src/symbol_index.rs b/crates/ide-db/src/symbol_index.rs
index 2737436993..d1ba79e8c7 100644
--- a/crates/ide-db/src/symbol_index.rs
+++ b/crates/ide-db/src/symbol_index.rs
@@ -27,16 +27,13 @@ use std::{
ops::ControlFlow,
};
-use base_db::{
- ra_salsa::{self, ParallelDatabase},
- SourceRootDatabase, SourceRootId, Upcast,
-};
-use fst::{raw::IndexedValue, Automaton, Streamer};
+use base_db::{RootQueryDb, SourceDatabase, SourceRootId};
+use fst::{Automaton, Streamer, raw::IndexedValue};
use hir::{
+ Crate, Module,
db::HirDatabase,
import_map::{AssocSearchMode, SearchMode},
symbols::{FileSymbol, SymbolCollector},
- Crate, Module,
};
use rayon::prelude::*;
use rustc_hash::FxHashSet;
@@ -99,38 +96,42 @@ impl Query {
}
}
-#[ra_salsa::query_group(SymbolsDatabaseStorage)]
-pub trait SymbolsDatabase: HirDatabase + SourceRootDatabase + Upcast<dyn HirDatabase> {
+#[query_group::query_group]
+pub trait SymbolsDatabase: HirDatabase + SourceDatabase {
/// The symbol index for a given module. These modules should only be in source roots that
/// are inside local_roots.
+ // FIXME: Is it worth breaking the encapsulation boundary of `hir`, and make this take a `ModuleId`,
+ // in order for it to be a non-interned query?
+ #[salsa::invoke_interned(module_symbols)]
fn module_symbols(&self, module: Module) -> Arc<SymbolIndex>;
/// The symbol index for a given source root within library_roots.
+ #[salsa::invoke_interned(library_symbols)]
fn library_symbols(&self, source_root_id: SourceRootId) -> Arc<SymbolIndex>;
- #[ra_salsa::transparent]
+ #[salsa::transparent]
/// The symbol indices of modules that make up a given crate.
fn crate_symbols(&self, krate: Crate) -> Box<[Arc<SymbolIndex>]>;
/// The set of "local" (that is, from the current workspace) roots.
/// Files in local roots are assumed to change frequently.
- #[ra_salsa::input]
+ #[salsa::input]
fn local_roots(&self) -> Arc<FxHashSet<SourceRootId>>;
/// The set of roots for crates.io libraries.
/// Files in libraries are assumed to never change.
- #[ra_salsa::input]
+ #[salsa::input]
fn library_roots(&self) -> Arc<FxHashSet<SourceRootId>>;
}
fn library_symbols(db: &dyn SymbolsDatabase, source_root_id: SourceRootId) -> Arc<SymbolIndex> {
let _p = tracing::info_span!("library_symbols").entered();
- let mut symbol_collector = SymbolCollector::new(db.upcast());
+ let mut symbol_collector = SymbolCollector::new(db);
db.source_root_crates(source_root_id)
.iter()
- .flat_map(|&krate| Crate::from(krate).modules(db.upcast()))
+ .flat_map(|&krate| Crate::from(krate).modules(db))
// we specifically avoid calling other SymbolsDatabase queries here, even though they do the same thing,
// as the index for a library is not going to really ever change, and we do not want to store each
// the module or crate indices for those in salsa unless we need to.
@@ -142,32 +143,12 @@ fn library_symbols(db: &dyn SymbolsDatabase, source_root_id: SourceRootId) -> Ar
fn module_symbols(db: &dyn SymbolsDatabase, module: Module) -> Arc<SymbolIndex> {
let _p = tracing::info_span!("module_symbols").entered();
- Arc::new(SymbolIndex::new(SymbolCollector::new_module(db.upcast(), module)))
+ Arc::new(SymbolIndex::new(SymbolCollector::new_module(db, module)))
}
pub fn crate_symbols(db: &dyn SymbolsDatabase, krate: Crate) -> Box<[Arc<SymbolIndex>]> {
let _p = tracing::info_span!("crate_symbols").entered();
- krate.modules(db.upcast()).into_iter().map(|module| db.module_symbols(module)).collect()
-}
-
-/// Need to wrap Snapshot to provide `Clone` impl for `map_with`
-struct Snap<DB>(DB);
-impl<DB: ParallelDatabase> Snap<ra_salsa::Snapshot<DB>> {
- fn new(db: &DB) -> Self {
- Self(db.snapshot())
- }
-}
-impl<DB: ParallelDatabase> Clone for Snap<ra_salsa::Snapshot<DB>> {
- fn clone(&self) -> Snap<ra_salsa::Snapshot<DB>> {
- Snap(self.0.snapshot())
- }
-}
-impl<DB> std::ops::Deref for Snap<DB> {
- type Target = DB;
-
- fn deref(&self) -> &Self::Target {
- &self.0
- }
+ krate.modules(db).into_iter().map(|module| db.module_symbols(module)).collect()
}
// Feature: Workspace Symbol
@@ -201,7 +182,7 @@ pub fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol> {
let indices: Vec<_> = if query.libs {
db.library_roots()
.par_iter()
- .map_with(Snap::new(db), |snap, &root| snap.library_symbols(root))
+ .map_with(db.clone(), |snap, &root| snap.library_symbols(root))
.collect()
} else {
let mut crates = Vec::new();
@@ -211,7 +192,7 @@ pub fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol> {
}
let indices: Vec<_> = crates
.into_par_iter()
- .map_with(Snap::new(db), |snap, krate| snap.crate_symbols(krate.into()))
+ .map_with(db.clone(), |snap, krate| snap.crate_symbols(krate.into()))
.collect();
indices.iter().flat_map(|indices| indices.iter().cloned()).collect()
};