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 | 50 | ||||
-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/status.rs | 2 |
8 files changed, 71 insertions, 152 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..aa54336b8 100644 --- a/crates/ra_hir/src/mock.rs +++ b/crates/ra_hir/src/mock.rs | |||
@@ -12,6 +12,7 @@ use crate::{db, HirInterner}; | |||
12 | 12 | ||
13 | pub const WORKSPACE: SourceRootId = SourceRootId(0); | 13 | pub const WORKSPACE: SourceRootId = SourceRootId(0); |
14 | 14 | ||
15 | #[salsa::database(ra_db::FilesDatabase, ra_db::SyntaxDatabase, db::HirDatabase)] | ||
15 | #[derive(Debug)] | 16 | #[derive(Debug)] |
16 | pub(crate) struct MockDatabase { | 17 | pub(crate) struct MockDatabase { |
17 | events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>, | 18 | events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>, |
@@ -181,8 +182,7 @@ impl MockDatabase { | |||
181 | pub(crate) fn log(&self, f: impl FnOnce()) -> Vec<salsa::Event<MockDatabase>> { | 182 | pub(crate) fn log(&self, f: impl FnOnce()) -> Vec<salsa::Event<MockDatabase>> { |
182 | *self.events.lock() = Some(Vec::new()); | 183 | *self.events.lock() = Some(Vec::new()); |
183 | f(); | 184 | f(); |
184 | let events = self.events.lock().take().unwrap(); | 185 | self.events.lock().take().unwrap() |
185 | events | ||
186 | } | 186 | } |
187 | 187 | ||
188 | pub(crate) fn log_executed(&self, f: impl FnOnce()) -> Vec<String> { | 188 | pub(crate) fn log_executed(&self, f: impl FnOnce()) -> Vec<String> { |
@@ -192,51 +192,11 @@ impl MockDatabase { | |||
192 | .filter_map(|e| match e.kind { | 192 | .filter_map(|e| match e.kind { |
193 | // This pretty horrible, but `Debug` is the only way to inspect | 193 | // This pretty horrible, but `Debug` is the only way to inspect |
194 | // QueryDescriptor at the moment. | 194 | // QueryDescriptor at the moment. |
195 | salsa::EventKind::WillExecute { descriptor } => Some(format!("{:?}", descriptor)), | 195 | salsa::EventKind::WillExecute { database_key } => { |
196 | Some(format!("{:?}", database_key)) | ||
197 | } | ||
196 | _ => None, | 198 | _ => None, |
197 | }) | 199 | }) |
198 | .collect() | 200 | .collect() |
199 | } | 201 | } |
200 | } | 202 | } |
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_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/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() |