diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_db/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_db/src/input.rs | 42 | ||||
-rw-r--r-- | crates/ra_db/src/lib.rs | 68 | ||||
-rw-r--r-- | crates/ra_hir/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/mock.rs | 83 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/tests.rs | 11 | ||||
-rw-r--r-- | crates/ra_ide_api/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_ide_api/src/db.rs | 56 | ||||
-rw-r--r-- | crates/ra_ide_api/src/imp.rs | 39 | ||||
-rw-r--r-- | crates/ra_ide_api/src/status.rs | 2 |
10 files changed, 100 insertions, 206 deletions
diff --git a/crates/ra_db/Cargo.toml b/crates/ra_db/Cargo.toml index bb1b5eae7..3568da905 100644 --- a/crates/ra_db/Cargo.toml +++ b/crates/ra_db/Cargo.toml | |||
@@ -6,7 +6,7 @@ authors = ["Aleksey Kladov <[email protected]>"] | |||
6 | 6 | ||
7 | [dependencies] | 7 | [dependencies] |
8 | relative-path = "0.4.0" | 8 | relative-path = "0.4.0" |
9 | salsa = "0.10.0-alpha1" | 9 | salsa = "0.10.0-alpha3" |
10 | rustc-hash = "1.0" | 10 | rustc-hash = "1.0" |
11 | parking_lot = "0.7.0" | 11 | parking_lot = "0.7.0" |
12 | ra_arena = { path = "../ra_arena" } | 12 | ra_arena = { path = "../ra_arena" } |
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index 9825d52cf..275894252 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs | |||
@@ -5,11 +5,8 @@ | |||
5 | /// Note that neither this module, nor any other part of the analyzer's core do | 5 | /// Note that neither this module, nor any other part of the analyzer's core do |
6 | /// actual IO. See `vfs` and `project_model` in the `ra_lsp_server` crate for how | 6 | /// actual IO. See `vfs` and `project_model` in the `ra_lsp_server` crate for how |
7 | /// actual IO is done and lowered to input. | 7 | /// actual IO is done and lowered to input. |
8 | use std::sync::Arc; | ||
9 | |||
10 | use relative_path::RelativePathBuf; | 8 | use relative_path::RelativePathBuf; |
11 | use rustc_hash::FxHashMap; | 9 | use rustc_hash::FxHashMap; |
12 | use salsa; | ||
13 | 10 | ||
14 | use ra_syntax::SmolStr; | 11 | use ra_syntax::SmolStr; |
15 | use rustc_hash::FxHashSet; | 12 | use rustc_hash::FxHashSet; |
@@ -146,45 +143,6 @@ impl CrateGraph { | |||
146 | } | 143 | } |
147 | } | 144 | } |
148 | 145 | ||
149 | #[salsa::query_group] | ||
150 | pub trait FilesDatabase: salsa::Database { | ||
151 | /// Text of the file. | ||
152 | #[salsa::input] | ||
153 | fn file_text(&self, file_id: FileId) -> Arc<String>; | ||
154 | /// Path to a file, relative to the root of its source root. | ||
155 | #[salsa::input] | ||
156 | fn file_relative_path(&self, file_id: FileId) -> RelativePathBuf; | ||
157 | /// Source root of the file. | ||
158 | #[salsa::input] | ||
159 | fn file_source_root(&self, file_id: FileId) -> SourceRootId; | ||
160 | /// Contents of the source root. | ||
161 | #[salsa::input] | ||
162 | fn source_root(&self, id: SourceRootId) -> Arc<SourceRoot>; | ||
163 | fn source_root_crates(&self, id: SourceRootId) -> Arc<Vec<CrateId>>; | ||
164 | /// The set of "local" (that is, from the current workspace) roots. | ||
165 | /// Files in local roots are assumed to change frequently. | ||
166 | #[salsa::input] | ||
167 | fn local_roots(&self) -> Arc<Vec<SourceRootId>>; | ||
168 | /// The set of roots for crates.io libraries. | ||
169 | /// Files in libraries are assumed to never change. | ||
170 | #[salsa::input] | ||
171 | fn library_roots(&self) -> Arc<Vec<SourceRootId>>; | ||
172 | /// The crate graph. | ||
173 | #[salsa::input] | ||
174 | fn crate_graph(&self) -> Arc<CrateGraph>; | ||
175 | } | ||
176 | |||
177 | fn source_root_crates(db: &impl FilesDatabase, id: SourceRootId) -> Arc<Vec<CrateId>> { | ||
178 | let root = db.source_root(id); | ||
179 | let graph = db.crate_graph(); | ||
180 | let res = root | ||
181 | .files | ||
182 | .values() | ||
183 | .filter_map(|&it| graph.crate_id_for_crate_root(it)) | ||
184 | .collect::<Vec<_>>(); | ||
185 | Arc::new(res) | ||
186 | } | ||
187 | |||
188 | #[cfg(test)] | 146 | #[cfg(test)] |
189 | mod tests { | 147 | mod tests { |
190 | use super::{CrateGraph, FileId, SmolStr}; | 148 | use super::{CrateGraph, FileId, SmolStr}; |
diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index 84759c75a..7e13f70bc 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs | |||
@@ -4,17 +4,18 @@ mod input; | |||
4 | mod loc2id; | 4 | mod loc2id; |
5 | pub mod mock; | 5 | pub mod mock; |
6 | 6 | ||
7 | use std::panic; | 7 | use std::{ |
8 | panic, sync::Arc, | ||
9 | }; | ||
8 | 10 | ||
9 | use ra_syntax::{TextUnit, TextRange, SourceFile, TreeArc}; | 11 | use ra_syntax::{TextUnit, TextRange, SourceFile, TreeArc}; |
12 | use relative_path::RelativePathBuf; | ||
10 | 13 | ||
11 | pub use ::salsa as salsa; | 14 | pub use ::salsa as salsa; |
12 | pub use crate::{ | 15 | pub use crate::{ |
13 | cancellation::Canceled, | 16 | cancellation::Canceled, |
14 | input::{ | 17 | input::{ |
15 | FilesDatabase, FileId, CrateId, SourceRoot, SourceRootId, CrateGraph, Dependency, | 18 | FileId, CrateId, SourceRoot, SourceRootId, CrateGraph, Dependency, |
16 | FileTextQuery, FileSourceRootQuery, SourceRootQuery, SourceRootCratesQuery, LocalRootsQuery, LibraryRootsQuery, CrateGraphQuery, | ||
17 | FileRelativePathQuery | ||
18 | }, | 19 | }, |
19 | loc2id::LocationIntener, | 20 | loc2id::LocationIntener, |
20 | }; | 21 | }; |
@@ -50,16 +51,6 @@ pub trait BaseDatabase: salsa::Database + panic::RefUnwindSafe { | |||
50 | } | 51 | } |
51 | } | 52 | } |
52 | 53 | ||
53 | #[salsa::query_group] | ||
54 | pub trait SyntaxDatabase: crate::input::FilesDatabase + BaseDatabase { | ||
55 | fn source_file(&self, file_id: FileId) -> TreeArc<SourceFile>; | ||
56 | } | ||
57 | |||
58 | fn source_file(db: &impl SyntaxDatabase, file_id: FileId) -> TreeArc<SourceFile> { | ||
59 | let text = db.file_text(file_id); | ||
60 | SourceFile::parse(&*text) | ||
61 | } | ||
62 | |||
63 | #[derive(Clone, Copy, Debug)] | 54 | #[derive(Clone, Copy, Debug)] |
64 | pub struct FilePosition { | 55 | pub struct FilePosition { |
65 | pub file_id: FileId, | 56 | pub file_id: FileId, |
@@ -71,3 +62,52 @@ pub struct FileRange { | |||
71 | pub file_id: FileId, | 62 | pub file_id: FileId, |
72 | pub range: TextRange, | 63 | pub range: TextRange, |
73 | } | 64 | } |
65 | |||
66 | #[salsa::query_group] | ||
67 | pub trait FilesDatabase: salsa::Database { | ||
68 | /// Text of the file. | ||
69 | #[salsa::input] | ||
70 | fn file_text(&self, file_id: FileId) -> Arc<String>; | ||
71 | /// Path to a file, relative to the root of its source root. | ||
72 | #[salsa::input] | ||
73 | fn file_relative_path(&self, file_id: FileId) -> RelativePathBuf; | ||
74 | /// Source root of the file. | ||
75 | #[salsa::input] | ||
76 | fn file_source_root(&self, file_id: FileId) -> SourceRootId; | ||
77 | /// Contents of the source root. | ||
78 | #[salsa::input] | ||
79 | fn source_root(&self, id: SourceRootId) -> Arc<SourceRoot>; | ||
80 | fn source_root_crates(&self, id: SourceRootId) -> Arc<Vec<CrateId>>; | ||
81 | /// The set of "local" (that is, from the current workspace) roots. | ||
82 | /// Files in local roots are assumed to change frequently. | ||
83 | #[salsa::input] | ||
84 | fn local_roots(&self) -> Arc<Vec<SourceRootId>>; | ||
85 | /// The set of roots for crates.io libraries. | ||
86 | /// Files in libraries are assumed to never change. | ||
87 | #[salsa::input] | ||
88 | fn library_roots(&self) -> Arc<Vec<SourceRootId>>; | ||
89 | /// The crate graph. | ||
90 | #[salsa::input] | ||
91 | fn crate_graph(&self) -> Arc<CrateGraph>; | ||
92 | } | ||
93 | |||
94 | fn source_root_crates(db: &impl FilesDatabase, id: SourceRootId) -> Arc<Vec<CrateId>> { | ||
95 | let root = db.source_root(id); | ||
96 | let graph = db.crate_graph(); | ||
97 | let res = root | ||
98 | .files | ||
99 | .values() | ||
100 | .filter_map(|&it| graph.crate_id_for_crate_root(it)) | ||
101 | .collect::<Vec<_>>(); | ||
102 | Arc::new(res) | ||
103 | } | ||
104 | |||
105 | #[salsa::query_group] | ||
106 | pub trait SyntaxDatabase: FilesDatabase + BaseDatabase { | ||
107 | fn source_file(&self, file_id: FileId) -> TreeArc<SourceFile>; | ||
108 | } | ||
109 | |||
110 | fn source_file(db: &impl SyntaxDatabase, file_id: FileId) -> TreeArc<SourceFile> { | ||
111 | let text = db.file_text(file_id); | ||
112 | SourceFile::parse(&*text) | ||
113 | } | ||
diff --git a/crates/ra_hir/Cargo.toml b/crates/ra_hir/Cargo.toml index 86937ccd8..3d802ade4 100644 --- a/crates/ra_hir/Cargo.toml +++ b/crates/ra_hir/Cargo.toml | |||
@@ -12,6 +12,8 @@ rustc-hash = "1.0" | |||
12 | parking_lot = "0.7.0" | 12 | parking_lot = "0.7.0" |
13 | ena = "0.11" | 13 | ena = "0.11" |
14 | join_to_string = "0.1.3" | 14 | join_to_string = "0.1.3" |
15 | salsa = "0.10.0-alpha3" | ||
16 | |||
15 | ra_syntax = { path = "../ra_syntax" } | 17 | ra_syntax = { path = "../ra_syntax" } |
16 | ra_arena = { path = "../ra_arena" } | 18 | ra_arena = { path = "../ra_arena" } |
17 | ra_db = { path = "../ra_db" } | 19 | ra_db = { path = "../ra_db" } |
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs index 1a83a5c87..36b174cd6 100644 --- a/crates/ra_hir/src/mock.rs +++ b/crates/ra_hir/src/mock.rs | |||
@@ -2,8 +2,7 @@ use std::{sync::Arc, panic}; | |||
2 | 2 | ||
3 | use parking_lot::Mutex; | 3 | use parking_lot::Mutex; |
4 | use ra_db::{ | 4 | use ra_db::{ |
5 | BaseDatabase, FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId, | 5 | BaseDatabase, FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId, FilesDatabase, |
6 | salsa::{self, Database}, | ||
7 | }; | 6 | }; |
8 | use relative_path::RelativePathBuf; | 7 | use relative_path::RelativePathBuf; |
9 | use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset}; | 8 | use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset}; |
@@ -12,6 +11,7 @@ use crate::{db, HirInterner}; | |||
12 | 11 | ||
13 | pub const WORKSPACE: SourceRootId = SourceRootId(0); | 12 | pub const WORKSPACE: SourceRootId = SourceRootId(0); |
14 | 13 | ||
14 | #[salsa::database(ra_db::FilesDatabase, ra_db::SyntaxDatabase, db::HirDatabase)] | ||
15 | #[derive(Debug)] | 15 | #[derive(Debug)] |
16 | pub(crate) struct MockDatabase { | 16 | pub(crate) struct MockDatabase { |
17 | events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>, | 17 | events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>, |
@@ -33,8 +33,7 @@ impl MockDatabase { | |||
33 | let mut db = MockDatabase::default(); | 33 | let mut db = MockDatabase::default(); |
34 | let mut source_root = SourceRoot::default(); | 34 | let mut source_root = SourceRoot::default(); |
35 | let file_id = db.add_file(WORKSPACE, &mut source_root, "/main.rs", text); | 35 | let file_id = db.add_file(WORKSPACE, &mut source_root, "/main.rs", text); |
36 | db.query_mut(ra_db::SourceRootQuery) | 36 | db.set_source_root(WORKSPACE, Arc::new(source_root.clone())); |
37 | .set(WORKSPACE, Arc::new(source_root.clone())); | ||
38 | (db, source_root, file_id) | 37 | (db, source_root, file_id) |
39 | } | 38 | } |
40 | 39 | ||
@@ -44,11 +43,6 @@ impl MockDatabase { | |||
44 | (db, position) | 43 | (db, position) |
45 | } | 44 | } |
46 | 45 | ||
47 | pub(crate) fn set_crate_graph(&mut self, crate_graph: CrateGraph) { | ||
48 | self.query_mut(ra_db::CrateGraphQuery) | ||
49 | .set((), Arc::new(crate_graph)); | ||
50 | } | ||
51 | |||
52 | fn from_fixture(fixture: &str) -> (MockDatabase, SourceRoot, Option<FilePosition>) { | 46 | fn from_fixture(fixture: &str) -> (MockDatabase, SourceRoot, Option<FilePosition>) { |
53 | let mut db = MockDatabase::default(); | 47 | let mut db = MockDatabase::default(); |
54 | 48 | ||
@@ -80,8 +74,7 @@ impl MockDatabase { | |||
80 | self.add_file(source_root_id, &mut source_root, &entry.meta, &entry.text); | 74 | self.add_file(source_root_id, &mut source_root, &entry.meta, &entry.text); |
81 | } | 75 | } |
82 | } | 76 | } |
83 | self.query_mut(ra_db::SourceRootQuery) | 77 | self.set_source_root(source_root_id, Arc::new(source_root.clone())); |
84 | .set(source_root_id, Arc::new(source_root.clone())); | ||
85 | (source_root, position) | 78 | (source_root, position) |
86 | } | 79 | } |
87 | 80 | ||
@@ -99,17 +92,15 @@ impl MockDatabase { | |||
99 | let file_id = FileId(self.file_counter); | 92 | let file_id = FileId(self.file_counter); |
100 | self.file_counter += 1; | 93 | self.file_counter += 1; |
101 | let text = Arc::new(text.to_string()); | 94 | let text = Arc::new(text.to_string()); |
102 | self.query_mut(ra_db::FileTextQuery).set(file_id, text); | 95 | self.set_file_text(file_id, text); |
103 | self.query_mut(ra_db::FileRelativePathQuery) | 96 | self.set_file_relative_path(file_id, path.clone()); |
104 | .set(file_id, path.clone()); | 97 | self.set_file_source_root(file_id, source_root_id); |
105 | self.query_mut(ra_db::FileSourceRootQuery) | ||
106 | .set(file_id, source_root_id); | ||
107 | source_root.files.insert(path, file_id); | 98 | source_root.files.insert(path, file_id); |
108 | 99 | ||
109 | if is_crate_root { | 100 | if is_crate_root { |
110 | let mut crate_graph = CrateGraph::default(); | 101 | let mut crate_graph = CrateGraph::default(); |
111 | crate_graph.add_crate_root(file_id); | 102 | crate_graph.add_crate_root(file_id); |
112 | self.set_crate_graph(crate_graph); | 103 | self.set_crate_graph(Arc::new(crate_graph)); |
113 | } | 104 | } |
114 | file_id | 105 | file_id |
115 | } | 106 | } |
@@ -148,12 +139,9 @@ impl Default for MockDatabase { | |||
148 | interner: Default::default(), | 139 | interner: Default::default(), |
149 | file_counter: 0, | 140 | file_counter: 0, |
150 | }; | 141 | }; |
151 | db.query_mut(ra_db::CrateGraphQuery) | 142 | db.set_crate_graph(Default::default()); |
152 | .set((), Default::default()); | 143 | db.set_local_roots(Default::default()); |
153 | db.query_mut(ra_db::LocalRootsQuery) | 144 | db.set_library_roots(Default::default()); |
154 | .set((), Default::default()); | ||
155 | db.query_mut(ra_db::LibraryRootsQuery) | ||
156 | .set((), Default::default()); | ||
157 | db | 145 | db |
158 | } | 146 | } |
159 | } | 147 | } |
@@ -181,8 +169,7 @@ impl MockDatabase { | |||
181 | pub(crate) fn log(&self, f: impl FnOnce()) -> Vec<salsa::Event<MockDatabase>> { | 169 | pub(crate) fn log(&self, f: impl FnOnce()) -> Vec<salsa::Event<MockDatabase>> { |
182 | *self.events.lock() = Some(Vec::new()); | 170 | *self.events.lock() = Some(Vec::new()); |
183 | f(); | 171 | f(); |
184 | let events = self.events.lock().take().unwrap(); | 172 | self.events.lock().take().unwrap() |
185 | events | ||
186 | } | 173 | } |
187 | 174 | ||
188 | pub(crate) fn log_executed(&self, f: impl FnOnce()) -> Vec<String> { | 175 | pub(crate) fn log_executed(&self, f: impl FnOnce()) -> Vec<String> { |
@@ -192,51 +179,11 @@ impl MockDatabase { | |||
192 | .filter_map(|e| match e.kind { | 179 | .filter_map(|e| match e.kind { |
193 | // This pretty horrible, but `Debug` is the only way to inspect | 180 | // This pretty horrible, but `Debug` is the only way to inspect |
194 | // QueryDescriptor at the moment. | 181 | // QueryDescriptor at the moment. |
195 | salsa::EventKind::WillExecute { descriptor } => Some(format!("{:?}", descriptor)), | 182 | salsa::EventKind::WillExecute { database_key } => { |
183 | Some(format!("{:?}", database_key)) | ||
184 | } | ||
196 | _ => None, | 185 | _ => None, |
197 | }) | 186 | }) |
198 | .collect() | 187 | .collect() |
199 | } | 188 | } |
200 | } | 189 | } |
201 | |||
202 | salsa::database_storage! { | ||
203 | pub(crate) struct MockDatabaseStorage for MockDatabase { | ||
204 | impl ra_db::FilesDatabase { | ||
205 | fn file_text() for ra_db::FileTextQuery; | ||
206 | fn file_relative_path() for ra_db::FileRelativePathQuery; | ||
207 | fn file_source_root() for ra_db::FileSourceRootQuery; | ||
208 | fn source_root() for ra_db::SourceRootQuery; | ||
209 | fn source_root_crates() for ra_db::SourceRootCratesQuery; | ||
210 | fn local_roots() for ra_db::LocalRootsQuery; | ||
211 | fn library_roots() for ra_db::LibraryRootsQuery; | ||
212 | fn crate_graph() for ra_db::CrateGraphQuery; | ||
213 | } | ||
214 | impl ra_db::SyntaxDatabase { | ||
215 | fn source_file() for ra_db::SourceFileQuery; | ||
216 | } | ||
217 | impl db::HirDatabase { | ||
218 | fn hir_source_file() for db::HirSourceFileQuery; | ||
219 | fn expand_macro_invocation() for db::ExpandMacroInvocationQuery; | ||
220 | fn module_tree() for db::ModuleTreeQuery; | ||
221 | fn fn_scopes() for db::FnScopesQuery; | ||
222 | fn file_items() for db::FileItemsQuery; | ||
223 | fn file_item() for db::FileItemQuery; | ||
224 | fn lower_module() for db::LowerModuleQuery; | ||
225 | fn lower_module_module() for db::LowerModuleModuleQuery; | ||
226 | fn lower_module_source_map() for db::LowerModuleSourceMapQuery; | ||
227 | fn item_map() for db::ItemMapQuery; | ||
228 | fn submodules() for db::SubmodulesQuery; | ||
229 | fn infer() for db::InferQuery; | ||
230 | fn type_for_def() for db::TypeForDefQuery; | ||
231 | fn type_for_field() for db::TypeForFieldQuery; | ||
232 | fn struct_data() for db::StructDataQuery; | ||
233 | fn enum_data() for db::EnumDataQuery; | ||
234 | fn impls_in_module() for db::ImplsInModuleQuery; | ||
235 | fn impls_in_crate() for db::ImplsInCrateQuery; | ||
236 | fn body_hir() for db::BodyHirQuery; | ||
237 | fn body_syntax_mapping() for db::BodySyntaxMappingQuery; | ||
238 | fn fn_signature() for db::FnSignatureQuery; | ||
239 | fn generic_params() for db::GenericParamsQuery; | ||
240 | } | ||
241 | } | ||
242 | } | ||
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index c033bebe8..24936976c 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use std::sync::Arc; | 1 | use std::sync::Arc; |
2 | 2 | ||
3 | use ra_db::{CrateGraph, SourceRootId, salsa::Database}; | 3 | use ra_db::{CrateGraph, SourceRootId, FilesDatabase}; |
4 | use relative_path::RelativePath; | 4 | use relative_path::RelativePath; |
5 | use test_utils::{assert_eq_text, covers}; | 5 | use test_utils::{assert_eq_text, covers}; |
6 | 6 | ||
@@ -257,7 +257,7 @@ fn item_map_across_crates() { | |||
257 | .add_dep(main_crate, "test_crate".into(), lib_crate) | 257 | .add_dep(main_crate, "test_crate".into(), lib_crate) |
258 | .unwrap(); | 258 | .unwrap(); |
259 | 259 | ||
260 | db.set_crate_graph(crate_graph); | 260 | db.set_crate_graph(Arc::new(crate_graph)); |
261 | 261 | ||
262 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); | 262 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); |
263 | let krate = module.krate(&db).unwrap(); | 263 | let krate = module.krate(&db).unwrap(); |
@@ -309,7 +309,7 @@ fn import_across_source_roots() { | |||
309 | .add_dep(main_crate, "test_crate".into(), lib_crate) | 309 | .add_dep(main_crate, "test_crate".into(), lib_crate) |
310 | .unwrap(); | 310 | .unwrap(); |
311 | 311 | ||
312 | db.set_crate_graph(crate_graph); | 312 | db.set_crate_graph(Arc::new(crate_graph)); |
313 | 313 | ||
314 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); | 314 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); |
315 | let krate = module.krate(&db).unwrap(); | 315 | let krate = module.krate(&db).unwrap(); |
@@ -351,7 +351,7 @@ fn reexport_across_crates() { | |||
351 | .add_dep(main_crate, "test_crate".into(), lib_crate) | 351 | .add_dep(main_crate, "test_crate".into(), lib_crate) |
352 | .unwrap(); | 352 | .unwrap(); |
353 | 353 | ||
354 | db.set_crate_graph(crate_graph); | 354 | db.set_crate_graph(Arc::new(crate_graph)); |
355 | 355 | ||
356 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); | 356 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); |
357 | let krate = module.krate(&db).unwrap(); | 357 | let krate = module.krate(&db).unwrap(); |
@@ -377,8 +377,7 @@ fn check_item_map_is_not_recomputed(initial: &str, file_change: &str) { | |||
377 | }); | 377 | }); |
378 | assert!(format!("{:?}", events).contains("item_map")) | 378 | assert!(format!("{:?}", events).contains("item_map")) |
379 | } | 379 | } |
380 | db.query_mut(ra_db::FileTextQuery) | 380 | db.set_file_text(pos.file_id, Arc::new(file_change.to_string())); |
381 | .set(pos.file_id, Arc::new(file_change.to_string())); | ||
382 | 381 | ||
383 | { | 382 | { |
384 | let events = db.log_executed(|| { | 383 | let events = db.log_executed(|| { |
diff --git a/crates/ra_ide_api/Cargo.toml b/crates/ra_ide_api/Cargo.toml index 20c911f8f..61942bbbb 100644 --- a/crates/ra_ide_api/Cargo.toml +++ b/crates/ra_ide_api/Cargo.toml | |||
@@ -13,6 +13,7 @@ fst = "0.3.1" | |||
13 | rustc-hash = "1.0" | 13 | rustc-hash = "1.0" |
14 | parking_lot = "0.7.0" | 14 | parking_lot = "0.7.0" |
15 | unicase = "2.2.0" | 15 | unicase = "2.2.0" |
16 | salsa = "0.10.0-alpha3" | ||
16 | 17 | ||
17 | ra_syntax = { path = "../ra_syntax" } | 18 | ra_syntax = { path = "../ra_syntax" } |
18 | ra_ide_api_light = { path = "../ra_ide_api_light" } | 19 | ra_ide_api_light = { path = "../ra_ide_api_light" } |
diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs index 11305613c..f0190ae51 100644 --- a/crates/ra_ide_api/src/db.rs +++ b/crates/ra_ide_api/src/db.rs | |||
@@ -7,6 +7,13 @@ use ra_db::{ | |||
7 | 7 | ||
8 | use crate::{symbol_index, LineIndex}; | 8 | use crate::{symbol_index, LineIndex}; |
9 | 9 | ||
10 | #[salsa::database( | ||
11 | ra_db::FilesDatabase, | ||
12 | ra_db::SyntaxDatabase, | ||
13 | LineIndexDatabase, | ||
14 | symbol_index::SymbolsDatabase, | ||
15 | hir::db::HirDatabase | ||
16 | )] | ||
10 | #[derive(Debug)] | 17 | #[derive(Debug)] |
11 | pub(crate) struct RootDatabase { | 18 | pub(crate) struct RootDatabase { |
12 | runtime: salsa::Runtime<RootDatabase>, | 19 | runtime: salsa::Runtime<RootDatabase>, |
@@ -64,52 +71,3 @@ fn line_index(db: &impl ra_db::FilesDatabase, file_id: FileId) -> Arc<LineIndex> | |||
64 | let text = db.file_text(file_id); | 71 | let text = db.file_text(file_id); |
65 | Arc::new(LineIndex::new(&*text)) | 72 | Arc::new(LineIndex::new(&*text)) |
66 | } | 73 | } |
67 | |||
68 | salsa::database_storage! { | ||
69 | pub(crate) struct RootDatabaseStorage for RootDatabase { | ||
70 | impl ra_db::FilesDatabase { | ||
71 | fn file_text() for ra_db::FileTextQuery; | ||
72 | fn file_relative_path() for ra_db::FileRelativePathQuery; | ||
73 | fn file_source_root() for ra_db::FileSourceRootQuery; | ||
74 | fn source_root() for ra_db::SourceRootQuery; | ||
75 | fn source_root_crates() for ra_db::SourceRootCratesQuery; | ||
76 | fn local_roots() for ra_db::LocalRootsQuery; | ||
77 | fn library_roots() for ra_db::LibraryRootsQuery; | ||
78 | fn crate_graph() for ra_db::CrateGraphQuery; | ||
79 | } | ||
80 | impl ra_db::SyntaxDatabase { | ||
81 | fn source_file() for ra_db::SourceFileQuery; | ||
82 | } | ||
83 | impl LineIndexDatabase { | ||
84 | fn line_index() for LineIndexQuery; | ||
85 | } | ||
86 | impl symbol_index::SymbolsDatabase { | ||
87 | fn file_symbols() for symbol_index::FileSymbolsQuery; | ||
88 | fn library_symbols() for symbol_index::LibrarySymbolsQuery; | ||
89 | } | ||
90 | impl hir::db::HirDatabase { | ||
91 | fn hir_source_file() for hir::db::HirSourceFileQuery; | ||
92 | fn expand_macro_invocation() for hir::db::ExpandMacroInvocationQuery; | ||
93 | fn module_tree() for hir::db::ModuleTreeQuery; | ||
94 | fn fn_scopes() for hir::db::FnScopesQuery; | ||
95 | fn file_items() for hir::db::FileItemsQuery; | ||
96 | fn file_item() for hir::db::FileItemQuery; | ||
97 | fn lower_module() for hir::db::LowerModuleQuery; | ||
98 | fn lower_module_module() for hir::db::LowerModuleModuleQuery; | ||
99 | fn lower_module_source_map() for hir::db::LowerModuleSourceMapQuery; | ||
100 | fn item_map() for hir::db::ItemMapQuery; | ||
101 | fn submodules() for hir::db::SubmodulesQuery; | ||
102 | fn infer() for hir::db::InferQuery; | ||
103 | fn type_for_def() for hir::db::TypeForDefQuery; | ||
104 | fn type_for_field() for hir::db::TypeForFieldQuery; | ||
105 | fn struct_data() for hir::db::StructDataQuery; | ||
106 | fn enum_data() for hir::db::EnumDataQuery; | ||
107 | fn impls_in_module() for hir::db::ImplsInModuleQuery; | ||
108 | fn impls_in_crate() for hir::db::ImplsInCrateQuery; | ||
109 | fn body_hir() for hir::db::BodyHirQuery; | ||
110 | fn body_syntax_mapping() for hir::db::BodySyntaxMappingQuery; | ||
111 | fn fn_signature() for hir::db::FnSignatureQuery; | ||
112 | fn generic_params() for hir::db::GenericParamsQuery; | ||
113 | } | ||
114 | } | ||
115 | } | ||
diff --git a/crates/ra_ide_api/src/imp.rs b/crates/ra_ide_api/src/imp.rs index ddd9354ec..8ecb8b17c 100644 --- a/crates/ra_ide_api/src/imp.rs +++ b/crates/ra_ide_api/src/imp.rs | |||
@@ -5,7 +5,7 @@ use hir::{ | |||
5 | }; | 5 | }; |
6 | use ra_db::{ | 6 | use ra_db::{ |
7 | FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase, | 7 | FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase, |
8 | salsa::{self, Database}, | 8 | salsa::Database, |
9 | }; | 9 | }; |
10 | use ra_ide_api_light::{self, assists, LocalEdit, Severity}; | 10 | use ra_ide_api_light::{self, assists, LocalEdit, Severity}; |
11 | use ra_syntax::{ | 11 | use ra_syntax::{ |
@@ -18,7 +18,7 @@ use crate::{ | |||
18 | AnalysisChange, | 18 | AnalysisChange, |
19 | CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit, | 19 | CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit, |
20 | Query, RootChange, SourceChange, SourceFileEdit, | 20 | Query, RootChange, SourceChange, SourceFileEdit, |
21 | symbol_index::{FileSymbol, LibrarySymbolsQuery}, | 21 | symbol_index::{FileSymbol, SymbolsDatabase}, |
22 | }; | 22 | }; |
23 | 23 | ||
24 | impl db::RootDatabase { | 24 | impl db::RootDatabase { |
@@ -28,59 +28,48 @@ impl db::RootDatabase { | |||
28 | if !change.new_roots.is_empty() { | 28 | if !change.new_roots.is_empty() { |
29 | let mut local_roots = Vec::clone(&self.local_roots()); | 29 | let mut local_roots = Vec::clone(&self.local_roots()); |
30 | for (root_id, is_local) in change.new_roots { | 30 | for (root_id, is_local) in change.new_roots { |
31 | self.query_mut(ra_db::SourceRootQuery) | 31 | self.set_source_root(root_id, Default::default()); |
32 | .set(root_id, Default::default()); | ||
33 | if is_local { | 32 | if is_local { |
34 | local_roots.push(root_id); | 33 | local_roots.push(root_id); |
35 | } | 34 | } |
36 | } | 35 | } |
37 | self.query_mut(ra_db::LocalRootsQuery) | 36 | self.set_local_roots(Arc::new(local_roots)); |
38 | .set((), Arc::new(local_roots)); | ||
39 | } | 37 | } |
40 | 38 | ||
41 | for (root_id, root_change) in change.roots_changed { | 39 | for (root_id, root_change) in change.roots_changed { |
42 | self.apply_root_change(root_id, root_change); | 40 | self.apply_root_change(root_id, root_change); |
43 | } | 41 | } |
44 | for (file_id, text) in change.files_changed { | 42 | for (file_id, text) in change.files_changed { |
45 | self.query_mut(ra_db::FileTextQuery).set(file_id, text) | 43 | self.set_file_text(file_id, text) |
46 | } | 44 | } |
47 | if !change.libraries_added.is_empty() { | 45 | if !change.libraries_added.is_empty() { |
48 | let mut libraries = Vec::clone(&self.library_roots()); | 46 | let mut libraries = Vec::clone(&self.library_roots()); |
49 | for library in change.libraries_added { | 47 | for library in change.libraries_added { |
50 | libraries.push(library.root_id); | 48 | libraries.push(library.root_id); |
51 | self.query_mut(ra_db::SourceRootQuery) | 49 | self.set_source_root(library.root_id, Default::default()); |
52 | .set(library.root_id, Default::default()); | 50 | self.set_constant_library_symbols(library.root_id, Arc::new(library.symbol_index)); |
53 | self.query_mut(LibrarySymbolsQuery) | ||
54 | .set_constant(library.root_id, Arc::new(library.symbol_index)); | ||
55 | self.apply_root_change(library.root_id, library.root_change); | 51 | self.apply_root_change(library.root_id, library.root_change); |
56 | } | 52 | } |
57 | self.query_mut(ra_db::LibraryRootsQuery) | 53 | self.set_library_roots(Arc::new(libraries)); |
58 | .set((), Arc::new(libraries)); | ||
59 | } | 54 | } |
60 | if let Some(crate_graph) = change.crate_graph { | 55 | if let Some(crate_graph) = change.crate_graph { |
61 | self.query_mut(ra_db::CrateGraphQuery) | 56 | self.set_crate_graph(Arc::new(crate_graph)) |
62 | .set((), Arc::new(crate_graph)) | ||
63 | } | 57 | } |
64 | } | 58 | } |
65 | 59 | ||
66 | fn apply_root_change(&mut self, root_id: SourceRootId, root_change: RootChange) { | 60 | fn apply_root_change(&mut self, root_id: SourceRootId, root_change: RootChange) { |
67 | let mut source_root = SourceRoot::clone(&self.source_root(root_id)); | 61 | let mut source_root = SourceRoot::clone(&self.source_root(root_id)); |
68 | for add_file in root_change.added { | 62 | for add_file in root_change.added { |
69 | self.query_mut(ra_db::FileTextQuery) | 63 | self.set_file_text(add_file.file_id, add_file.text); |
70 | .set(add_file.file_id, add_file.text); | 64 | self.set_file_relative_path(add_file.file_id, add_file.path.clone()); |
71 | self.query_mut(ra_db::FileRelativePathQuery) | 65 | self.set_file_source_root(add_file.file_id, root_id); |
72 | .set(add_file.file_id, add_file.path.clone()); | ||
73 | self.query_mut(ra_db::FileSourceRootQuery) | ||
74 | .set(add_file.file_id, root_id); | ||
75 | source_root.files.insert(add_file.path, add_file.file_id); | 66 | source_root.files.insert(add_file.path, add_file.file_id); |
76 | } | 67 | } |
77 | for remove_file in root_change.removed { | 68 | for remove_file in root_change.removed { |
78 | self.query_mut(ra_db::FileTextQuery) | 69 | self.set_file_text(remove_file.file_id, Default::default()); |
79 | .set(remove_file.file_id, Default::default()); | ||
80 | source_root.files.remove(&remove_file.path); | 70 | source_root.files.remove(&remove_file.path); |
81 | } | 71 | } |
82 | self.query_mut(ra_db::SourceRootQuery) | 72 | self.set_source_root(root_id, Arc::new(source_root)); |
83 | .set(root_id, Arc::new(source_root)); | ||
84 | } | 73 | } |
85 | 74 | ||
86 | #[allow(unused)] | 75 | #[allow(unused)] |
diff --git a/crates/ra_ide_api/src/status.rs b/crates/ra_ide_api/src/status.rs index 5c14cbdeb..d499dd878 100644 --- a/crates/ra_ide_api/src/status.rs +++ b/crates/ra_ide_api/src/status.rs | |||
@@ -6,7 +6,7 @@ use ra_db::{ | |||
6 | use crate::db::RootDatabase; | 6 | use crate::db::RootDatabase; |
7 | 7 | ||
8 | pub(crate) fn status(db: &RootDatabase) -> String { | 8 | pub(crate) fn status(db: &RootDatabase) -> String { |
9 | let n_parsed_files = db.query(SourceFileQuery).keys::<Vec<_>>().len(); | 9 | let n_parsed_files = db.query(SourceFileQuery).entries::<Vec<_>>().len(); |
10 | let n_defs = { | 10 | let n_defs = { |
11 | let interner: &hir::HirInterner = db.as_ref(); | 11 | let interner: &hir::HirInterner = db.as_ref(); |
12 | interner.len() | 12 | interner.len() |