update salsa

This commit is contained in:
Aleksey Kladov 2018-11-01 15:29:23 +03:00
parent 962a491829
commit a17b41033a
4 changed files with 55 additions and 45 deletions

24
Cargo.lock generated
View file

@ -268,7 +268,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.16 (registry+https://github.com/rust-lang/crates.io-index)", "syn 0.15.17 (registry+https://github.com/rust-lang/crates.io-index)",
"synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -484,7 +484,7 @@ dependencies = [
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.16 (registry+https://github.com/rust-lang/crates.io-index)", "syn 0.15.17 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -608,7 +608,7 @@ dependencies = [
"rayon 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"salsa 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "salsa 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"test_utils 0.1.0", "test_utils 0.1.0",
] ]
@ -836,7 +836,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "salsa" name = "salsa"
version = "0.7.0" version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"derive-new 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "derive-new 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -890,7 +890,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.16 (registry+https://github.com/rust-lang/crates.io-index)", "syn 0.15.17 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -965,7 +965,7 @@ dependencies = [
[[package]] [[package]]
name = "syn" name = "syn"
version = "0.15.16" version = "0.15.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
@ -980,7 +980,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.16 (registry+https://github.com/rust-lang/crates.io-index)", "syn 0.15.17 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -995,7 +995,7 @@ dependencies = [
[[package]] [[package]]
name = "tera" name = "tera"
version = "0.11.18" version = "0.11.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1021,7 +1021,7 @@ dependencies = [
"failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ron 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "ron 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tera 0.11.18 (registry+https://github.com/rust-lang/crates.io-index)", "tera 0.11.19 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -1352,7 +1352,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
"checksum ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7153dd96dade874ab973e098cb62fcdbb89a03682e46b144fd09550998d4a4a7" "checksum ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7153dd96dade874ab973e098cb62fcdbb89a03682e46b144fd09550998d4a4a7"
"checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9" "checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9"
"checksum salsa 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef0f1fb2a01d4579b6658343b1b5431a72c62c186ebb9b40bd6cd3078c7afecf" "checksum salsa 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e56b13ce9b2bfaa1c89863d76880838c0734de85beeaef437fd70d4fa7e253d3"
"checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267" "checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267"
"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
@ -1368,10 +1368,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
"checksum superslice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b50b13d42370e0f5fc62eafdd5c2d20065eaf5458dab215ff3e20e63eea96b30" "checksum superslice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b50b13d42370e0f5fc62eafdd5c2d20065eaf5458dab215ff3e20e63eea96b30"
"checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741" "checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741"
"checksum syn 0.15.16 (registry+https://github.com/rust-lang/crates.io-index)" = "0b78d53b5e1b6e63129140b1336877c3bddbae398c7956150396bdad0e28676c" "checksum syn 0.15.17 (registry+https://github.com/rust-lang/crates.io-index)" = "3391038ebc3e4ab24eb028cb0ef2f2dc4ba0cbf72ee895ed6a6fad730640b5bc"
"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" "checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015"
"checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" "checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
"checksum tera 0.11.18 (registry+https://github.com/rust-lang/crates.io-index)" = "6c87cae42cc4fc480278c7583792cc5da2d51a25be916b7921cbb45c43063b8d" "checksum tera 0.11.19 (registry+https://github.com/rust-lang/crates.io-index)" = "6ac6d8ad623a7efcfb4367ce2a36f84ef849d5aa3c7bcf2e0324c4cbcc57ebaf"
"checksum teraron 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0d89ad4617d1dec55331067fadaa041e813479e1779616f3d3ce9308bf46184e" "checksum teraron 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0d89ad4617d1dec55331067fadaa041e813479e1779616f3d3ce9308bf46184e"
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
"checksum text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8009d7bdbd896a7e09b595f8f9325a19047fc708653e60d0895202b82135048f" "checksum text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8009d7bdbd896a7e09b595f8f9325a19047fc708653e60d0895202b82135048f"

View file

@ -9,7 +9,7 @@ log = "0.4.5"
relative-path = "0.4.0" relative-path = "0.4.0"
rayon = "1.0.2" rayon = "1.0.2"
fst = "0.3.1" fst = "0.3.1"
salsa = "0.7.0" salsa = "0.8.0"
rustc-hash = "1.0" rustc-hash = "1.0"
ra_syntax = { path = "../ra_syntax" } ra_syntax = { path = "../ra_syntax" }
ra_editor = { path = "../ra_editor" } ra_editor = { path = "../ra_editor" }

View file

@ -35,16 +35,10 @@ pub(crate) fn check_canceled(db: &impl salsa::Database) -> Cancelable<()> {
} }
impl salsa::ParallelDatabase for RootDatabase { impl salsa::ParallelDatabase for RootDatabase {
fn fork(&self) -> Self { fn snapshot(&self) -> salsa::Snapshot<RootDatabase> {
RootDatabase { salsa::Snapshot::new(RootDatabase {
runtime: self.runtime.fork(), runtime: self.runtime.snapshot(self),
} })
}
}
impl Clone for RootDatabase {
fn clone(&self) -> RootDatabase {
salsa::ParallelDatabase::fork(self)
} }
} }

View file

@ -1,4 +1,5 @@
use std::{ use std::{
fmt,
hash::{Hash, Hasher}, hash::{Hash, Hasher},
sync::Arc, sync::Arc,
}; };
@ -92,18 +93,18 @@ pub(crate) struct AnalysisHostImpl {
impl AnalysisHostImpl { impl AnalysisHostImpl {
pub fn new() -> AnalysisHostImpl { pub fn new() -> AnalysisHostImpl {
let db = db::RootDatabase::default(); let mut db = db::RootDatabase::default();
db.query(crate::input::SourceRootQuery) db.query_mut(crate::input::SourceRootQuery)
.set(WORKSPACE, Default::default()); .set(WORKSPACE, Default::default());
db.query(crate::input::CrateGraphQuery) db.query_mut(crate::input::CrateGraphQuery)
.set((), Default::default()); .set((), Default::default());
db.query(crate::input::LibrariesQuery) db.query_mut(crate::input::LibrariesQuery)
.set((), Default::default()); .set((), Default::default());
AnalysisHostImpl { db } AnalysisHostImpl { db }
} }
pub fn analysis(&self) -> AnalysisImpl { pub fn analysis(&self) -> AnalysisImpl {
AnalysisImpl { AnalysisImpl {
db: self.db.fork(), // freeze revision here db: self.db.snapshot(),
} }
} }
pub fn apply_change(&mut self, change: AnalysisChange) { pub fn apply_change(&mut self, change: AnalysisChange) {
@ -111,7 +112,7 @@ impl AnalysisHostImpl {
for (file_id, text) in change.files_changed { for (file_id, text) in change.files_changed {
self.db self.db
.query(crate::input::FileTextQuery) .query_mut(crate::input::FileTextQuery)
.set(file_id, Arc::new(text)) .set(file_id, Arc::new(text))
} }
if !(change.files_added.is_empty() && change.files_removed.is_empty()) { if !(change.files_added.is_empty() && change.files_removed.is_empty()) {
@ -121,22 +122,22 @@ impl AnalysisHostImpl {
let mut source_root = SourceRoot::clone(&self.db.source_root(WORKSPACE)); let mut source_root = SourceRoot::clone(&self.db.source_root(WORKSPACE));
for (file_id, text) in change.files_added { for (file_id, text) in change.files_added {
self.db self.db
.query(crate::input::FileTextQuery) .query_mut(crate::input::FileTextQuery)
.set(file_id, Arc::new(text)); .set(file_id, Arc::new(text));
self.db self.db
.query(crate::input::FileSourceRootQuery) .query_mut(crate::input::FileSourceRootQuery)
.set(file_id, crate::input::WORKSPACE); .set(file_id, crate::input::WORKSPACE);
source_root.files.insert(file_id); source_root.files.insert(file_id);
} }
for file_id in change.files_removed { for file_id in change.files_removed {
self.db self.db
.query(crate::input::FileTextQuery) .query_mut(crate::input::FileTextQuery)
.set(file_id, Arc::new(String::new())); .set(file_id, Arc::new(String::new()));
source_root.files.remove(&file_id); source_root.files.remove(&file_id);
} }
source_root.file_resolver = file_resolver; source_root.file_resolver = file_resolver;
self.db self.db
.query(crate::input::SourceRootQuery) .query_mut(crate::input::SourceRootQuery)
.set(WORKSPACE, Arc::new(source_root)) .set(WORKSPACE, Arc::new(source_root))
} }
if !change.libraries_added.is_empty() { if !change.libraries_added.is_empty() {
@ -148,10 +149,10 @@ impl AnalysisHostImpl {
for (file_id, text) in library.files { for (file_id, text) in library.files {
files.insert(file_id); files.insert(file_id);
self.db self.db
.query(crate::input::FileSourceRootQuery) .query_mut(crate::input::FileSourceRootQuery)
.set_constant(file_id, source_root_id); .set_constant(file_id, source_root_id);
self.db self.db
.query(crate::input::FileTextQuery) .query_mut(crate::input::FileTextQuery)
.set_constant(file_id, Arc::new(text)); .set_constant(file_id, Arc::new(text));
} }
let source_root = SourceRoot { let source_root = SourceRoot {
@ -159,27 +160,33 @@ impl AnalysisHostImpl {
file_resolver: library.file_resolver, file_resolver: library.file_resolver,
}; };
self.db self.db
.query(crate::input::SourceRootQuery) .query_mut(crate::input::SourceRootQuery)
.set(source_root_id, Arc::new(source_root)); .set(source_root_id, Arc::new(source_root));
self.db self.db
.query(crate::input::LibrarySymbolsQuery) .query_mut(crate::input::LibrarySymbolsQuery)
.set(source_root_id, Arc::new(library.symbol_index)); .set(source_root_id, Arc::new(library.symbol_index));
} }
self.db self.db
.query(crate::input::LibrariesQuery) .query_mut(crate::input::LibrariesQuery)
.set((), Arc::new(libraries)); .set((), Arc::new(libraries));
} }
if let Some(crate_graph) = change.crate_graph { if let Some(crate_graph) = change.crate_graph {
self.db self.db
.query(crate::input::CrateGraphQuery) .query_mut(crate::input::CrateGraphQuery)
.set((), Arc::new(crate_graph)) .set((), Arc::new(crate_graph))
} }
} }
} }
#[derive(Debug)]
pub(crate) struct AnalysisImpl { pub(crate) struct AnalysisImpl {
pub(crate) db: db::RootDatabase, pub(crate) db: salsa::Snapshot<db::RootDatabase>,
}
impl fmt::Debug for AnalysisImpl {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let db: &db::RootDatabase = &self.db;
fmt.debug_struct("AnalysisImpl").field("db", db).finish()
}
} }
impl AnalysisImpl { impl AnalysisImpl {
@ -198,10 +205,19 @@ impl AnalysisImpl {
.collect() .collect()
} else { } else {
let files = &self.db.source_root(WORKSPACE).files; let files = &self.db.source_root(WORKSPACE).files;
let db = self.db.clone();
/// Need to wrap Snapshot to provide `Clon` impl for `map_with`
struct Snap(salsa::Snapshot<db::RootDatabase>);
impl Clone for Snap {
fn clone(&self) -> Snap {
Snap(self.0.snapshot())
}
}
let snap = Snap(self.db.snapshot());
files files
.par_iter() .par_iter()
.map_with(db, |db, &file_id| db.file_symbols(file_id)) .map_with(snap, |db, &file_id| db.0.file_symbols(file_id))
.filter_map(|it| it.ok()) .filter_map(|it| it.ok())
.collect() .collect()
}; };
@ -229,7 +245,7 @@ impl AnalysisImpl {
return None; return None;
} }
}; };
let decl = link.bind_source(&module_tree, &self.db); let decl = link.bind_source(&module_tree, &*self.db);
let decl = decl.ast(); let decl = decl.ast();
let sym = FileSymbol { let sym = FileSymbol {
@ -371,7 +387,7 @@ impl AnalysisImpl {
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
if let Some(m) = module_tree.any_module_for_file(file_id) { if let Some(m) = module_tree.any_module_for_file(file_id) {
for (name_node, problem) in m.problems(&module_tree, &self.db) { for (name_node, problem) in m.problems(&module_tree, &*self.db) {
let diag = match problem { let diag = match problem {
Problem::UnresolvedModule { candidate } => { Problem::UnresolvedModule { candidate } => {
let create_file = FileSystemEdit::CreateFile { let create_file = FileSystemEdit::CreateFile {