aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/db.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-10-25 16:04:48 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-10-25 16:04:48 +0100
commit5932bd0bb5fcd066a9d16abcd1597b7097978085 (patch)
tree7b6ea86855fe34c3d45d14262c8cf94e315566e8 /crates/ra_analysis/src/db.rs
parent2cb2074c4b7219b32993abdcc7084637c0123d49 (diff)
parent363adf07b7763cfe7e13fac0ee148361d51834e4 (diff)
Merge #162
162: Db everywhere r=matklad a=matklad This PR continues our switch to salsa. Now *all* state is handled by a single salsa database. Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_analysis/src/db.rs')
-rw-r--r--crates/ra_analysis/src/db.rs58
1 files changed, 10 insertions, 48 deletions
diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs
index b527cde61..3ca14af79 100644
--- a/crates/ra_analysis/src/db.rs
+++ b/crates/ra_analysis/src/db.rs
@@ -1,12 +1,9 @@
1use std::{ 1use std::{
2 fmt,
3 hash::{Hash, Hasher},
4 sync::Arc, 2 sync::Arc,
5}; 3};
6 4
7use ra_editor::LineIndex; 5use ra_editor::LineIndex;
8use ra_syntax::File; 6use ra_syntax::File;
9use rustc_hash::FxHashSet;
10use salsa; 7use salsa;
11 8
12use crate::{ 9use crate::{
@@ -14,20 +11,14 @@ use crate::{
14 Cancelable, Canceled, 11 Cancelable, Canceled,
15 descriptors::module::{SubmodulesQuery, ModuleTreeQuery, ModulesDatabase}, 12 descriptors::module::{SubmodulesQuery, ModuleTreeQuery, ModulesDatabase},
16 symbol_index::SymbolIndex, 13 symbol_index::SymbolIndex,
17 FileId, FileResolverImp, 14 FileId,
18}; 15};
19 16
20#[derive(Default)] 17#[derive(Default, Debug)]
21pub(crate) struct RootDatabase { 18pub(crate) struct RootDatabase {
22 runtime: salsa::Runtime<RootDatabase>, 19 runtime: salsa::Runtime<RootDatabase>,
23} 20}
24 21
25impl fmt::Debug for RootDatabase {
26 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
27 fmt.write_str("RootDatabase { ... }")
28 }
29}
30
31impl salsa::Database for RootDatabase { 22impl salsa::Database for RootDatabase {
32 fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> { 23 fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> {
33 &self.runtime 24 &self.runtime
@@ -58,9 +49,13 @@ impl Clone for RootDatabase {
58 49
59salsa::database_storage! { 50salsa::database_storage! {
60 pub(crate) struct RootDatabaseStorage for RootDatabase { 51 pub(crate) struct RootDatabaseStorage for RootDatabase {
61 impl FilesDatabase { 52 impl crate::input::FilesDatabase {
62 fn file_text() for FileTextQuery; 53 fn file_text() for crate::input::FileTextQuery;
63 fn file_set() for FileSetQuery; 54 fn file_source_root() for crate::input::FileSourceRootQuery;
55 fn source_root() for crate::input::SourceRootQuery;
56 fn libraries() for crate::input::LibrarieseQuery;
57 fn library_symbols() for crate::input::LibrarySymbolsQuery;
58 fn crate_graph() for crate::input::CrateGraphQuery;
64 } 59 }
65 impl SyntaxDatabase { 60 impl SyntaxDatabase {
66 fn file_syntax() for FileSyntaxQuery; 61 fn file_syntax() for FileSyntaxQuery;
@@ -75,40 +70,7 @@ salsa::database_storage! {
75} 70}
76 71
77salsa::query_group! { 72salsa::query_group! {
78 pub(crate) trait FilesDatabase: salsa::Database { 73 pub(crate) trait SyntaxDatabase: crate::input::FilesDatabase {
79 fn file_text(file_id: FileId) -> Arc<String> {
80 type FileTextQuery;
81 storage input;
82 }
83 fn file_set() -> Arc<FileSet> {
84 type FileSetQuery;
85 storage input;
86 }
87 }
88}
89
90#[derive(Default, Debug, Eq)]
91pub(crate) struct FileSet {
92 pub(crate) files: FxHashSet<FileId>,
93 pub(crate) resolver: FileResolverImp,
94}
95
96impl PartialEq for FileSet {
97 fn eq(&self, other: &FileSet) -> bool {
98 self.files == other.files && self.resolver == other.resolver
99 }
100}
101
102impl Hash for FileSet {
103 fn hash<H: Hasher>(&self, hasher: &mut H) {
104 let mut files = self.files.iter().cloned().collect::<Vec<_>>();
105 files.sort();
106 files.hash(hasher);
107 }
108}
109
110salsa::query_group! {
111 pub(crate) trait SyntaxDatabase: FilesDatabase {
112 fn file_syntax(file_id: FileId) -> File { 74 fn file_syntax(file_id: FileId) -> File {
113 type FileSyntaxQuery; 75 type FileSyntaxQuery;
114 } 76 }