diff options
author | Aleksey Kladov <[email protected]> | 2018-09-15 11:38:31 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-09-15 22:00:05 +0100 |
commit | 47be3a3a24de1eb28e1575db1571d934765f6d53 (patch) | |
tree | 6653f5206a482f013fe0a6d4bb6d6dcc259f16fc /crates | |
parent | 8c737255ff876fc61f8dc8a7d33252476a4b4c8d (diff) |
renames
Diffstat (limited to 'crates')
-rw-r--r-- | crates/libanalysis/src/db/mod.rs | 24 | ||||
-rw-r--r-- | crates/libanalysis/src/module_map_db/descr.rs | 29 | ||||
-rw-r--r-- | crates/libanalysis/src/module_map_db/mod.rs (renamed from crates/libanalysis/src/module_map_db.rs) | 43 |
3 files changed, 49 insertions, 47 deletions
diff --git a/crates/libanalysis/src/db/mod.rs b/crates/libanalysis/src/db/mod.rs index f68aab61c..3198272b7 100644 --- a/crates/libanalysis/src/db/mod.rs +++ b/crates/libanalysis/src/db/mod.rs | |||
@@ -120,38 +120,36 @@ impl<'a> QueryCtx<'a> { | |||
120 | 120 | ||
121 | fn query_config() -> salsa::QueryConfig<State, Data> { | 121 | fn query_config() -> salsa::QueryConfig<State, Data> { |
122 | let mut res = salsa::QueryConfig::new(); | 122 | let mut res = salsa::QueryConfig::new(); |
123 | let queries: Vec<SalsaGroundQuery> = vec![ | 123 | let queries: Vec<BoxedGroundQuery> = vec![ |
124 | queries::FILE_TEXT.into(), | 124 | queries::FILE_TEXT.into(), |
125 | queries::FILE_SET.into(), | 125 | queries::FILE_SET.into(), |
126 | ]; | 126 | ]; |
127 | for q in queries { | 127 | for q in queries { |
128 | res = res.with_ground_query(q.query_type, q.f) | 128 | res = res.with_ground_query(q.query_type, q.f) |
129 | } | 129 | } |
130 | let queries: Vec<SalsaQuery> = vec![ | 130 | let mut queries: Vec<BoxedQuery> = vec![ |
131 | queries::FILE_SYNTAX.into(), | 131 | queries::FILE_SYNTAX.into(), |
132 | ::module_map_db::MODULE_DESCR.into(), | ||
133 | ::module_map_db::RESOLVE_SUBMODULE.into(), | ||
134 | ::module_map_db::PARENT_MODULE.into(), | ||
135 | ]; | 132 | ]; |
133 | ::module_map_db::queries(&mut queries); | ||
136 | for q in queries { | 134 | for q in queries { |
137 | res = res.with_query(q.query_type, q.f); | 135 | res = res.with_query(q.query_type, q.f); |
138 | } | 136 | } |
139 | res | 137 | res |
140 | } | 138 | } |
141 | 139 | ||
142 | struct SalsaGroundQuery { | 140 | struct BoxedGroundQuery { |
143 | query_type: salsa::QueryTypeId, | 141 | query_type: salsa::QueryTypeId, |
144 | f: Box<Fn(&State, &Data) -> (Data, salsa::OutputFingerprint) + Send + Sync + 'static>, | 142 | f: Box<Fn(&State, &Data) -> (Data, salsa::OutputFingerprint) + Send + Sync + 'static>, |
145 | } | 143 | } |
146 | 144 | ||
147 | impl<T, R> From<GroundQuery<T, R>> for SalsaGroundQuery | 145 | impl<T, R> From<GroundQuery<T, R>> for BoxedGroundQuery |
148 | where | 146 | where |
149 | T: Send + Sync + 'static, | 147 | T: Send + Sync + 'static, |
150 | R: Send + Sync + 'static, | 148 | R: Send + Sync + 'static, |
151 | { | 149 | { |
152 | fn from(q: GroundQuery<T, R>) -> SalsaGroundQuery | 150 | fn from(q: GroundQuery<T, R>) -> BoxedGroundQuery |
153 | { | 151 | { |
154 | SalsaGroundQuery { | 152 | BoxedGroundQuery { |
155 | query_type: salsa::QueryTypeId(q.id), | 153 | query_type: salsa::QueryTypeId(q.id), |
156 | f: Box::new(move |state, data| { | 154 | f: Box::new(move |state, data| { |
157 | let data: &T = data.downcast_ref().unwrap(); | 155 | let data: &T = data.downcast_ref().unwrap(); |
@@ -163,19 +161,19 @@ where | |||
163 | } | 161 | } |
164 | } | 162 | } |
165 | 163 | ||
166 | struct SalsaQuery { | 164 | pub(crate) struct BoxedQuery { |
167 | query_type: salsa::QueryTypeId, | 165 | query_type: salsa::QueryTypeId, |
168 | f: Box<Fn(&salsa::QueryCtx<State, Data>, &Data) -> (Data, salsa::OutputFingerprint) + Send + Sync + 'static>, | 166 | f: Box<Fn(&salsa::QueryCtx<State, Data>, &Data) -> (Data, salsa::OutputFingerprint) + Send + Sync + 'static>, |
169 | } | 167 | } |
170 | 168 | ||
171 | impl<T, R> From<Query<T, R>> for SalsaQuery | 169 | impl<T, R> From<Query<T, R>> for BoxedQuery |
172 | where | 170 | where |
173 | T: Hash + Send + Sync + 'static, | 171 | T: Hash + Send + Sync + 'static, |
174 | R: Hash + Send + Sync + 'static, | 172 | R: Hash + Send + Sync + 'static, |
175 | { | 173 | { |
176 | fn from(q: Query<T, R>) -> SalsaQuery | 174 | fn from(q: Query<T, R>) -> BoxedQuery |
177 | { | 175 | { |
178 | SalsaQuery { | 176 | BoxedQuery { |
179 | query_type: salsa::QueryTypeId(q.id), | 177 | query_type: salsa::QueryTypeId(q.id), |
180 | f: Box::new(move |ctx, data| { | 178 | f: Box::new(move |ctx, data| { |
181 | let ctx = QueryCtx { inner: ctx }; | 179 | 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 000000000..fb298a315 --- /dev/null +++ b/crates/libanalysis/src/module_map_db/descr.rs | |||
@@ -0,0 +1,29 @@ | |||
1 | use libsyntax2::{ | ||
2 | SmolStr, | ||
3 | ast::{self, NameOwner}, | ||
4 | }; | ||
5 | |||
6 | #[derive(Debug, Hash)] | ||
7 | pub struct ModuleDescr { | ||
8 | pub submodules: Vec<Submodule> | ||
9 | } | ||
10 | |||
11 | impl ModuleDescr { | ||
12 | pub fn new(root: ast::Root) -> ModuleDescr { | ||
13 | let submodules = root | ||
14 | .modules() | ||
15 | .filter_map(|module| { | ||
16 | let name = module.name()?.text(); | ||
17 | if !module.has_semi() { | ||
18 | return None; | ||
19 | } | ||
20 | Some(Submodule { name }) | ||
21 | }).collect(); | ||
22 | |||
23 | ModuleDescr { submodules } } | ||
24 | } | ||
25 | |||
26 | #[derive(Clone, Hash, PartialEq, Eq, Debug)] | ||
27 | pub struct Submodule { | ||
28 | pub name: SmolStr, | ||
29 | } | ||
diff --git a/crates/libanalysis/src/module_map_db.rs b/crates/libanalysis/src/module_map_db/mod.rs index ff69cc0d2..777f7a38a 100644 --- a/crates/libanalysis/src/module_map_db.rs +++ b/crates/libanalysis/src/module_map_db/mod.rs | |||
@@ -1,12 +1,20 @@ | |||
1 | mod descr; | ||
2 | |||
1 | use std::sync::Arc; | 3 | use std::sync::Arc; |
2 | use { | 4 | use { |
3 | FileId, | 5 | FileId, |
4 | db::{ | 6 | db::{ |
5 | Query, QueryCtx | 7 | BoxedQuery, Query, QueryCtx |
6 | }, | 8 | }, |
7 | module_map::resolve_submodule, | 9 | module_map::resolve_submodule, |
8 | }; | 10 | }; |
9 | 11 | ||
12 | pub(crate) fn queries(acc: &mut Vec<BoxedQuery>) { | ||
13 | acc.push(MODULE_DESCR.into()); | ||
14 | acc.push(RESOLVE_SUBMODULE.into()); | ||
15 | acc.push(PARENT_MODULE.into()); | ||
16 | } | ||
17 | |||
10 | impl<'a> QueryCtx<'a> { | 18 | impl<'a> QueryCtx<'a> { |
11 | fn module_descr(&self, file_id: FileId) -> Arc<descr::ModuleDescr> { | 19 | fn module_descr(&self, file_id: FileId) -> Arc<descr::ModuleDescr> { |
12 | self.get(MODULE_DESCR, file_id) | 20 | self.get(MODULE_DESCR, file_id) |
@@ -52,39 +60,6 @@ pub(crate) const PARENT_MODULE: Query<FileId, Vec<FileId>> = Query { | |||
52 | } | 60 | } |
53 | }; | 61 | }; |
54 | 62 | ||
55 | mod descr { | ||
56 | use libsyntax2::{ | ||
57 | SmolStr, | ||
58 | ast::{self, NameOwner}, | ||
59 | }; | ||
60 | |||
61 | #[derive(Debug, Hash)] | ||
62 | pub struct ModuleDescr { | ||
63 | pub submodules: Vec<Submodule> | ||
64 | } | ||
65 | |||
66 | impl ModuleDescr { | ||
67 | pub fn new(root: ast::Root) -> ModuleDescr { | ||
68 | let submodules = root | ||
69 | .modules() | ||
70 | .filter_map(|module| { | ||
71 | let name = module.name()?.text(); | ||
72 | if !module.has_semi() { | ||
73 | return None; | ||
74 | } | ||
75 | Some(Submodule { name }) | ||
76 | }).collect(); | ||
77 | |||
78 | ModuleDescr { submodules } } | ||
79 | } | ||
80 | |||
81 | #[derive(Clone, Hash, PartialEq, Eq, Debug)] | ||
82 | pub struct Submodule { | ||
83 | pub name: SmolStr, | ||
84 | } | ||
85 | |||
86 | } | ||
87 | |||
88 | #[cfg(test)] | 63 | #[cfg(test)] |
89 | mod tests { | 64 | mod tests { |
90 | use std::collections::HashMap; | 65 | use std::collections::HashMap; |