aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-11-01 12:29:23 +0000
committerAleksey Kladov <[email protected]>2018-11-01 12:30:07 +0000
commita17b41033ac5406ca93f46a0562f0792701586df (patch)
tree38828c9efec9d9d2ca6f925551389e891756427e /crates/ra_analysis/src
parent962a491829c2a803f5dc8c8c5e173baa89079e8b (diff)
update salsa
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r--crates/ra_analysis/src/db.rs14
-rw-r--r--crates/ra_analysis/src/imp.rs60
2 files changed, 42 insertions, 32 deletions
diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs
index 94fdd36a4..9548ec602 100644
--- a/crates/ra_analysis/src/db.rs
+++ b/crates/ra_analysis/src/db.rs
@@ -35,16 +35,10 @@ pub(crate) fn check_canceled(db: &impl salsa::Database) -> Cancelable<()> {
35} 35}
36 36
37impl salsa::ParallelDatabase for RootDatabase { 37impl salsa::ParallelDatabase for RootDatabase {
38 fn fork(&self) -> Self { 38 fn snapshot(&self) -> salsa::Snapshot<RootDatabase> {
39 RootDatabase { 39 salsa::Snapshot::new(RootDatabase {
40 runtime: self.runtime.fork(), 40 runtime: self.runtime.snapshot(self),
41 } 41 })
42 }
43}
44
45impl Clone for RootDatabase {
46 fn clone(&self) -> RootDatabase {
47 salsa::ParallelDatabase::fork(self)
48 } 42 }
49} 43}
50 44
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index 060e2b606..77dd71dcf 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -1,4 +1,5 @@
1use std::{ 1use std::{
2 fmt,
2 hash::{Hash, Hasher}, 3 hash::{Hash, Hasher},
3 sync::Arc, 4 sync::Arc,
4}; 5};
@@ -92,18 +93,18 @@ pub(crate) struct AnalysisHostImpl {
92 93
93impl AnalysisHostImpl { 94impl AnalysisHostImpl {
94 pub fn new() -> AnalysisHostImpl { 95 pub fn new() -> AnalysisHostImpl {
95 let db = db::RootDatabase::default(); 96 let mut db = db::RootDatabase::default();
96 db.query(crate::input::SourceRootQuery) 97 db.query_mut(crate::input::SourceRootQuery)
97 .set(WORKSPACE, Default::default()); 98 .set(WORKSPACE, Default::default());
98 db.query(crate::input::CrateGraphQuery) 99 db.query_mut(crate::input::CrateGraphQuery)
99 .set((), Default::default()); 100 .set((), Default::default());
100 db.query(crate::input::LibrariesQuery) 101 db.query_mut(crate::input::LibrariesQuery)
101 .set((), Default::default()); 102 .set((), Default::default());
102 AnalysisHostImpl { db } 103 AnalysisHostImpl { db }
103 } 104 }
104 pub fn analysis(&self) -> AnalysisImpl { 105 pub fn analysis(&self) -> AnalysisImpl {
105 AnalysisImpl { 106 AnalysisImpl {
106 db: self.db.fork(), // freeze revision here 107 db: self.db.snapshot(),
107 } 108 }
108 } 109 }
109 pub fn apply_change(&mut self, change: AnalysisChange) { 110 pub fn apply_change(&mut self, change: AnalysisChange) {
@@ -111,7 +112,7 @@ impl AnalysisHostImpl {
111 112
112 for (file_id, text) in change.files_changed { 113 for (file_id, text) in change.files_changed {
113 self.db 114 self.db
114 .query(crate::input::FileTextQuery) 115 .query_mut(crate::input::FileTextQuery)
115 .set(file_id, Arc::new(text)) 116 .set(file_id, Arc::new(text))
116 } 117 }
117 if !(change.files_added.is_empty() && change.files_removed.is_empty()) { 118 if !(change.files_added.is_empty() && change.files_removed.is_empty()) {
@@ -121,22 +122,22 @@ impl AnalysisHostImpl {
121 let mut source_root = SourceRoot::clone(&self.db.source_root(WORKSPACE)); 122 let mut source_root = SourceRoot::clone(&self.db.source_root(WORKSPACE));
122 for (file_id, text) in change.files_added { 123 for (file_id, text) in change.files_added {
123 self.db 124 self.db
124 .query(crate::input::FileTextQuery) 125 .query_mut(crate::input::FileTextQuery)
125 .set(file_id, Arc::new(text)); 126 .set(file_id, Arc::new(text));
126 self.db 127 self.db
127 .query(crate::input::FileSourceRootQuery) 128 .query_mut(crate::input::FileSourceRootQuery)
128 .set(file_id, crate::input::WORKSPACE); 129 .set(file_id, crate::input::WORKSPACE);
129 source_root.files.insert(file_id); 130 source_root.files.insert(file_id);
130 } 131 }
131 for file_id in change.files_removed { 132 for file_id in change.files_removed {
132 self.db 133 self.db
133 .query(crate::input::FileTextQuery) 134 .query_mut(crate::input::FileTextQuery)
134 .set(file_id, Arc::new(String::new())); 135 .set(file_id, Arc::new(String::new()));
135 source_root.files.remove(&file_id); 136 source_root.files.remove(&file_id);
136 } 137 }
137 source_root.file_resolver = file_resolver; 138 source_root.file_resolver = file_resolver;
138 self.db 139 self.db
139 .query(crate::input::SourceRootQuery) 140 .query_mut(crate::input::SourceRootQuery)
140 .set(WORKSPACE, Arc::new(source_root)) 141 .set(WORKSPACE, Arc::new(source_root))
141 } 142 }
142 if !change.libraries_added.is_empty() { 143 if !change.libraries_added.is_empty() {
@@ -148,10 +149,10 @@ impl AnalysisHostImpl {
148 for (file_id, text) in library.files { 149 for (file_id, text) in library.files {
149 files.insert(file_id); 150 files.insert(file_id);
150 self.db 151 self.db
151 .query(crate::input::FileSourceRootQuery) 152 .query_mut(crate::input::FileSourceRootQuery)
152 .set_constant(file_id, source_root_id); 153 .set_constant(file_id, source_root_id);
153 self.db 154 self.db
154 .query(crate::input::FileTextQuery) 155 .query_mut(crate::input::FileTextQuery)
155 .set_constant(file_id, Arc::new(text)); 156 .set_constant(file_id, Arc::new(text));
156 } 157 }
157 let source_root = SourceRoot { 158 let source_root = SourceRoot {
@@ -159,27 +160,33 @@ impl AnalysisHostImpl {
159 file_resolver: library.file_resolver, 160 file_resolver: library.file_resolver,
160 }; 161 };
161 self.db 162 self.db
162 .query(crate::input::SourceRootQuery) 163 .query_mut(crate::input::SourceRootQuery)
163 .set(source_root_id, Arc::new(source_root)); 164 .set(source_root_id, Arc::new(source_root));
164 self.db 165 self.db
165 .query(crate::input::LibrarySymbolsQuery) 166 .query_mut(crate::input::LibrarySymbolsQuery)
166 .set(source_root_id, Arc::new(library.symbol_index)); 167 .set(source_root_id, Arc::new(library.symbol_index));
167 } 168 }
168 self.db 169 self.db
169 .query(crate::input::LibrariesQuery) 170 .query_mut(crate::input::LibrariesQuery)
170 .set((), Arc::new(libraries)); 171 .set((), Arc::new(libraries));
171 } 172 }
172 if let Some(crate_graph) = change.crate_graph { 173 if let Some(crate_graph) = change.crate_graph {
173 self.db 174 self.db
174 .query(crate::input::CrateGraphQuery) 175 .query_mut(crate::input::CrateGraphQuery)
175 .set((), Arc::new(crate_graph)) 176 .set((), Arc::new(crate_graph))
176 } 177 }
177 } 178 }
178} 179}
179 180
180#[derive(Debug)]
181pub(crate) struct AnalysisImpl { 181pub(crate) struct AnalysisImpl {
182 pub(crate) db: db::RootDatabase, 182 pub(crate) db: salsa::Snapshot<db::RootDatabase>,
183}
184
185impl fmt::Debug for AnalysisImpl {
186 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
187 let db: &db::RootDatabase = &self.db;
188 fmt.debug_struct("AnalysisImpl").field("db", db).finish()
189 }
183} 190}
184 191
185impl AnalysisImpl { 192impl AnalysisImpl {
@@ -198,10 +205,19 @@ impl AnalysisImpl {
198 .collect() 205 .collect()
199 } else { 206 } else {
200 let files = &self.db.source_root(WORKSPACE).files; 207 let files = &self.db.source_root(WORKSPACE).files;
201 let db = self.db.clone(); 208
209 /// Need to wrap Snapshot to provide `Clon` impl for `map_with`
210 struct Snap(salsa::Snapshot<db::RootDatabase>);
211 impl Clone for Snap {
212 fn clone(&self) -> Snap {
213 Snap(self.0.snapshot())
214 }
215 }
216
217 let snap = Snap(self.db.snapshot());
202 files 218 files
203 .par_iter() 219 .par_iter()
204 .map_with(db, |db, &file_id| db.file_symbols(file_id)) 220 .map_with(snap, |db, &file_id| db.0.file_symbols(file_id))
205 .filter_map(|it| it.ok()) 221 .filter_map(|it| it.ok())
206 .collect() 222 .collect()
207 }; 223 };
@@ -229,7 +245,7 @@ impl AnalysisImpl {
229 return None; 245 return None;
230 } 246 }
231 }; 247 };
232 let decl = link.bind_source(&module_tree, &self.db); 248 let decl = link.bind_source(&module_tree, &*self.db);
233 let decl = decl.ast(); 249 let decl = decl.ast();
234 250
235 let sym = FileSymbol { 251 let sym = FileSymbol {
@@ -371,7 +387,7 @@ impl AnalysisImpl {
371 }) 387 })
372 .collect::<Vec<_>>(); 388 .collect::<Vec<_>>();
373 if let Some(m) = module_tree.any_module_for_file(file_id) { 389 if let Some(m) = module_tree.any_module_for_file(file_id) {
374 for (name_node, problem) in m.problems(&module_tree, &self.db) { 390 for (name_node, problem) in m.problems(&module_tree, &*self.db) {
375 let diag = match problem { 391 let diag = match problem {
376 Problem::UnresolvedModule { candidate } => { 392 Problem::UnresolvedModule { candidate } => {
377 let create_file = FileSystemEdit::CreateFile { 393 let create_file = FileSystemEdit::CreateFile {