Skip to content

Commit 92c10bf

Browse files
bors[bot]matklad
andcommitted
Merge #183
183: update salsa r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 962a491 + a17b410 commit 92c10bf

File tree

4 files changed

+55
-45
lines changed

4 files changed

+55
-45
lines changed

Cargo.lock

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ra_analysis/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ log = "0.4.5"
99
relative-path = "0.4.0"
1010
rayon = "1.0.2"
1111
fst = "0.3.1"
12-
salsa = "0.7.0"
12+
salsa = "0.8.0"
1313
rustc-hash = "1.0"
1414
ra_syntax = { path = "../ra_syntax" }
1515
ra_editor = { path = "../ra_editor" }

crates/ra_analysis/src/db.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,10 @@ pub(crate) fn check_canceled(db: &impl salsa::Database) -> Cancelable<()> {
3535
}
3636

3737
impl salsa::ParallelDatabase for RootDatabase {
38-
fn fork(&self) -> Self {
39-
RootDatabase {
40-
runtime: self.runtime.fork(),
41-
}
42-
}
43-
}
44-
45-
impl Clone for RootDatabase {
46-
fn clone(&self) -> RootDatabase {
47-
salsa::ParallelDatabase::fork(self)
38+
fn snapshot(&self) -> salsa::Snapshot<RootDatabase> {
39+
salsa::Snapshot::new(RootDatabase {
40+
runtime: self.runtime.snapshot(self),
41+
})
4842
}
4943
}
5044

crates/ra_analysis/src/imp.rs

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::{
2+
fmt,
23
hash::{Hash, Hasher},
34
sync::Arc,
45
};
@@ -92,26 +93,26 @@ pub(crate) struct AnalysisHostImpl {
9293

9394
impl AnalysisHostImpl {
9495
pub fn new() -> AnalysisHostImpl {
95-
let db = db::RootDatabase::default();
96-
db.query(crate::input::SourceRootQuery)
96+
let mut db = db::RootDatabase::default();
97+
db.query_mut(crate::input::SourceRootQuery)
9798
.set(WORKSPACE, Default::default());
98-
db.query(crate::input::CrateGraphQuery)
99+
db.query_mut(crate::input::CrateGraphQuery)
99100
.set((), Default::default());
100-
db.query(crate::input::LibrariesQuery)
101+
db.query_mut(crate::input::LibrariesQuery)
101102
.set((), Default::default());
102103
AnalysisHostImpl { db }
103104
}
104105
pub fn analysis(&self) -> AnalysisImpl {
105106
AnalysisImpl {
106-
db: self.db.fork(), // freeze revision here
107+
db: self.db.snapshot(),
107108
}
108109
}
109110
pub fn apply_change(&mut self, change: AnalysisChange) {
110111
log::info!("apply_change {:?}", change);
111112

112113
for (file_id, text) in change.files_changed {
113114
self.db
114-
.query(crate::input::FileTextQuery)
115+
.query_mut(crate::input::FileTextQuery)
115116
.set(file_id, Arc::new(text))
116117
}
117118
if !(change.files_added.is_empty() && change.files_removed.is_empty()) {
@@ -121,22 +122,22 @@ impl AnalysisHostImpl {
121122
let mut source_root = SourceRoot::clone(&self.db.source_root(WORKSPACE));
122123
for (file_id, text) in change.files_added {
123124
self.db
124-
.query(crate::input::FileTextQuery)
125+
.query_mut(crate::input::FileTextQuery)
125126
.set(file_id, Arc::new(text));
126127
self.db
127-
.query(crate::input::FileSourceRootQuery)
128+
.query_mut(crate::input::FileSourceRootQuery)
128129
.set(file_id, crate::input::WORKSPACE);
129130
source_root.files.insert(file_id);
130131
}
131132
for file_id in change.files_removed {
132133
self.db
133-
.query(crate::input::FileTextQuery)
134+
.query_mut(crate::input::FileTextQuery)
134135
.set(file_id, Arc::new(String::new()));
135136
source_root.files.remove(&file_id);
136137
}
137138
source_root.file_resolver = file_resolver;
138139
self.db
139-
.query(crate::input::SourceRootQuery)
140+
.query_mut(crate::input::SourceRootQuery)
140141
.set(WORKSPACE, Arc::new(source_root))
141142
}
142143
if !change.libraries_added.is_empty() {
@@ -148,38 +149,44 @@ impl AnalysisHostImpl {
148149
for (file_id, text) in library.files {
149150
files.insert(file_id);
150151
self.db
151-
.query(crate::input::FileSourceRootQuery)
152+
.query_mut(crate::input::FileSourceRootQuery)
152153
.set_constant(file_id, source_root_id);
153154
self.db
154-
.query(crate::input::FileTextQuery)
155+
.query_mut(crate::input::FileTextQuery)
155156
.set_constant(file_id, Arc::new(text));
156157
}
157158
let source_root = SourceRoot {
158159
files,
159160
file_resolver: library.file_resolver,
160161
};
161162
self.db
162-
.query(crate::input::SourceRootQuery)
163+
.query_mut(crate::input::SourceRootQuery)
163164
.set(source_root_id, Arc::new(source_root));
164165
self.db
165-
.query(crate::input::LibrarySymbolsQuery)
166+
.query_mut(crate::input::LibrarySymbolsQuery)
166167
.set(source_root_id, Arc::new(library.symbol_index));
167168
}
168169
self.db
169-
.query(crate::input::LibrariesQuery)
170+
.query_mut(crate::input::LibrariesQuery)
170171
.set((), Arc::new(libraries));
171172
}
172173
if let Some(crate_graph) = change.crate_graph {
173174
self.db
174-
.query(crate::input::CrateGraphQuery)
175+
.query_mut(crate::input::CrateGraphQuery)
175176
.set((), Arc::new(crate_graph))
176177
}
177178
}
178179
}
179180

180-
#[derive(Debug)]
181181
pub(crate) struct AnalysisImpl {
182-
pub(crate) db: db::RootDatabase,
182+
pub(crate) db: salsa::Snapshot<db::RootDatabase>,
183+
}
184+
185+
impl 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+
}
183190
}
184191

185192
impl AnalysisImpl {
@@ -198,10 +205,19 @@ impl AnalysisImpl {
198205
.collect()
199206
} else {
200207
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());
202218
files
203219
.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))
205221
.filter_map(|it| it.ok())
206222
.collect()
207223
};
@@ -229,7 +245,7 @@ impl AnalysisImpl {
229245
return None;
230246
}
231247
};
232-
let decl = link.bind_source(&module_tree, &self.db);
248+
let decl = link.bind_source(&module_tree, &*self.db);
233249
let decl = decl.ast();
234250

235251
let sym = FileSymbol {
@@ -371,7 +387,7 @@ impl AnalysisImpl {
371387
})
372388
.collect::<Vec<_>>();
373389
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) {
375391
let diag = match problem {
376392
Problem::UnresolvedModule { candidate } => {
377393
let create_file = FileSystemEdit::CreateFile {

0 commit comments

Comments
 (0)