diff --git a/crates/libanalysis/src/db/mod.rs b/crates/libanalysis/src/db/mod.rs index f68aab61c0..3198272b7d 100644 --- a/crates/libanalysis/src/db/mod.rs +++ b/crates/libanalysis/src/db/mod.rs @@ -120,38 +120,36 @@ impl<'a> QueryCtx<'a> { fn query_config() -> salsa::QueryConfig { let mut res = salsa::QueryConfig::new(); - let queries: Vec = vec![ + let queries: Vec = vec![ queries::FILE_TEXT.into(), queries::FILE_SET.into(), ]; for q in queries { res = res.with_ground_query(q.query_type, q.f) } - let queries: Vec = vec![ + let mut queries: Vec = vec![ queries::FILE_SYNTAX.into(), - ::module_map_db::MODULE_DESCR.into(), - ::module_map_db::RESOLVE_SUBMODULE.into(), - ::module_map_db::PARENT_MODULE.into(), ]; + ::module_map_db::queries(&mut queries); for q in queries { res = res.with_query(q.query_type, q.f); } res } -struct SalsaGroundQuery { +struct BoxedGroundQuery { query_type: salsa::QueryTypeId, f: Box (Data, salsa::OutputFingerprint) + Send + Sync + 'static>, } -impl From> for SalsaGroundQuery +impl From> for BoxedGroundQuery where T: Send + Sync + 'static, R: Send + Sync + 'static, { - fn from(q: GroundQuery) -> SalsaGroundQuery + fn from(q: GroundQuery) -> BoxedGroundQuery { - SalsaGroundQuery { + BoxedGroundQuery { query_type: salsa::QueryTypeId(q.id), f: Box::new(move |state, data| { let data: &T = data.downcast_ref().unwrap(); @@ -163,19 +161,19 @@ where } } -struct SalsaQuery { +pub(crate) struct BoxedQuery { query_type: salsa::QueryTypeId, f: Box, &Data) -> (Data, salsa::OutputFingerprint) + Send + Sync + 'static>, } -impl From> for SalsaQuery +impl From> for BoxedQuery where T: Hash + Send + Sync + 'static, R: Hash + Send + Sync + 'static, { - fn from(q: Query) -> SalsaQuery + fn from(q: Query) -> BoxedQuery { - SalsaQuery { + BoxedQuery { query_type: salsa::QueryTypeId(q.id), f: Box::new(move |ctx, data| { let ctx = QueryCtx { inner: ctx }; diff --git a/crates/libanalysis/src/module_map_db/descr.rs b/crates/libanalysis/src/module_map_db/descr.rs new file mode 100644 index 0000000000..fb298a315d --- /dev/null +++ b/crates/libanalysis/src/module_map_db/descr.rs @@ -0,0 +1,29 @@ +use libsyntax2::{ + SmolStr, + ast::{self, NameOwner}, +}; + +#[derive(Debug, Hash)] +pub struct ModuleDescr { + pub submodules: Vec +} + +impl ModuleDescr { + pub fn new(root: ast::Root) -> ModuleDescr { + let submodules = root + .modules() + .filter_map(|module| { + let name = module.name()?.text(); + if !module.has_semi() { + return None; + } + Some(Submodule { name }) + }).collect(); + + ModuleDescr { submodules } } +} + +#[derive(Clone, Hash, PartialEq, Eq, Debug)] +pub struct Submodule { + pub name: SmolStr, +} diff --git a/crates/libanalysis/src/module_map_db.rs b/crates/libanalysis/src/module_map_db/mod.rs similarity index 87% rename from crates/libanalysis/src/module_map_db.rs rename to crates/libanalysis/src/module_map_db/mod.rs index ff69cc0d20..777f7a38ad 100644 --- a/crates/libanalysis/src/module_map_db.rs +++ b/crates/libanalysis/src/module_map_db/mod.rs @@ -1,12 +1,20 @@ +mod descr; + use std::sync::Arc; use { FileId, db::{ - Query, QueryCtx + BoxedQuery, Query, QueryCtx }, module_map::resolve_submodule, }; +pub(crate) fn queries(acc: &mut Vec) { + acc.push(MODULE_DESCR.into()); + acc.push(RESOLVE_SUBMODULE.into()); + acc.push(PARENT_MODULE.into()); +} + impl<'a> QueryCtx<'a> { fn module_descr(&self, file_id: FileId) -> Arc { self.get(MODULE_DESCR, file_id) @@ -52,39 +60,6 @@ pub(crate) const PARENT_MODULE: Query> = Query { } }; -mod descr { - use libsyntax2::{ - SmolStr, - ast::{self, NameOwner}, - }; - - #[derive(Debug, Hash)] - pub struct ModuleDescr { - pub submodules: Vec - } - - impl ModuleDescr { - pub fn new(root: ast::Root) -> ModuleDescr { - let submodules = root - .modules() - .filter_map(|module| { - let name = module.name()?.text(); - if !module.has_semi() { - return None; - } - Some(Submodule { name }) - }).collect(); - - ModuleDescr { submodules } } - } - - #[derive(Clone, Hash, PartialEq, Eq, Debug)] - pub struct Submodule { - pub name: SmolStr, - } - -} - #[cfg(test)] mod tests { use std::collections::HashMap;