aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-10-15 20:29:24 +0100
committerAleksey Kladov <[email protected]>2018-10-15 20:29:24 +0100
commitbbcd998433075aba66ef0677bcdd821ca5fc926e (patch)
tree58130242a9a726bb552d01f5c72d1c4d13ead701 /crates/ra_analysis
parent76c51fae77d5dc2d7791132ecc78e444118e48de (diff)
make analysis sync
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r--crates/ra_analysis/src/db.rs14
-rw-r--r--crates/ra_analysis/src/imp.rs12
-rw-r--r--crates/ra_analysis/src/lib.rs6
-rw-r--r--crates/ra_analysis/src/roots.rs24
4 files changed, 37 insertions, 19 deletions
diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs
index 0773edcc1..c69577233 100644
--- a/crates/ra_analysis/src/db.rs
+++ b/crates/ra_analysis/src/db.rs
@@ -30,6 +30,20 @@ impl salsa::Database for RootDatabase {
30 } 30 }
31} 31}
32 32
33impl salsa::ParallelDatabase for RootDatabase {
34 fn fork(&self) -> Self {
35 RootDatabase {
36 runtime: self.runtime.fork(),
37 }
38 }
39}
40
41impl Clone for RootDatabase {
42 fn clone(&self) -> RootDatabase {
43 salsa::ParallelDatabase::fork(self)
44 }
45}
46
33salsa::database_storage! { 47salsa::database_storage! {
34 pub(crate) struct RootDatabaseStorage for RootDatabase { 48 pub(crate) struct RootDatabaseStorage for RootDatabase {
35 impl FilesDatabase { 49 impl FilesDatabase {
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index 0cf6db40d..d07d797d5 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -78,13 +78,13 @@ impl Default for FileResolverImp {
78 78
79#[derive(Debug)] 79#[derive(Debug)]
80pub(crate) struct AnalysisHostImpl { 80pub(crate) struct AnalysisHostImpl {
81 data: Arc<WorldData> 81 data: WorldData
82} 82}
83 83
84impl AnalysisHostImpl { 84impl AnalysisHostImpl {
85 pub fn new() -> AnalysisHostImpl { 85 pub fn new() -> AnalysisHostImpl {
86 AnalysisHostImpl { 86 AnalysisHostImpl {
87 data: Arc::new(WorldData::default()), 87 data: WorldData::default(),
88 } 88 }
89 } 89 }
90 pub fn analysis(&self) -> AnalysisImpl { 90 pub fn analysis(&self) -> AnalysisImpl {
@@ -114,18 +114,18 @@ impl AnalysisHostImpl {
114 self.data_mut().libs.push(Arc::new(root)); 114 self.data_mut().libs.push(Arc::new(root));
115 } 115 }
116 fn data_mut(&mut self) -> &mut WorldData { 116 fn data_mut(&mut self) -> &mut WorldData {
117 Arc::make_mut(&mut self.data) 117 &mut self.data
118 } 118 }
119} 119}
120 120
121pub(crate) struct AnalysisImpl { 121pub(crate) struct AnalysisImpl {
122 needs_reindex: AtomicBool, 122 needs_reindex: AtomicBool,
123 data: Arc<WorldData>, 123 data: WorldData,
124} 124}
125 125
126impl fmt::Debug for AnalysisImpl { 126impl fmt::Debug for AnalysisImpl {
127 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 127 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
128 (&*self.data).fmt(f) 128 self.data.fmt(f)
129 } 129 }
130} 130}
131 131
@@ -133,7 +133,7 @@ impl Clone for AnalysisImpl {
133 fn clone(&self) -> AnalysisImpl { 133 fn clone(&self) -> AnalysisImpl {
134 AnalysisImpl { 134 AnalysisImpl {
135 needs_reindex: AtomicBool::new(self.needs_reindex.load(SeqCst)), 135 needs_reindex: AtomicBool::new(self.needs_reindex.load(SeqCst)),
136 data: Arc::clone(&self.data), 136 data: self.data.clone(),
137 } 137 }
138 } 138 }
139} 139}
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs
index d49132513..c76e4f4fe 100644
--- a/crates/ra_analysis/src/lib.rs
+++ b/crates/ra_analysis/src/lib.rs
@@ -258,3 +258,9 @@ impl LibraryData {
258 LibraryData { root } 258 LibraryData { root }
259 } 259 }
260} 260}
261
262#[test]
263fn analysis_is_send() {
264 fn is_send<T: Send>() {}
265 is_send::<Analysis>();
266}
diff --git a/crates/ra_analysis/src/roots.rs b/crates/ra_analysis/src/roots.rs
index 42833af36..76bcecd38 100644
--- a/crates/ra_analysis/src/roots.rs
+++ b/crates/ra_analysis/src/roots.rs
@@ -2,7 +2,6 @@ use std::{
2 sync::Arc, 2 sync::Arc,
3 panic, 3 panic,
4}; 4};
5use parking_lot::RwLock;
6 5
7use once_cell::sync::OnceCell; 6use once_cell::sync::OnceCell;
8use rayon::prelude::*; 7use rayon::prelude::*;
@@ -30,7 +29,7 @@ pub(crate) trait SourceRoot {
30 29
31#[derive(Default, Debug, Clone)] 30#[derive(Default, Debug, Clone)]
32pub(crate) struct WritableSourceRoot { 31pub(crate) struct WritableSourceRoot {
33 db: Arc<RwLock<db::RootDatabase>>, 32 db: db::RootDatabase,
34} 33}
35 34
36impl WritableSourceRoot { 35impl WritableSourceRoot {
@@ -39,7 +38,6 @@ impl WritableSourceRoot {
39 changes: &mut dyn Iterator<Item=(FileId, Option<String>)>, 38 changes: &mut dyn Iterator<Item=(FileId, Option<String>)>,
40 file_resolver: Option<FileResolverImp>, 39 file_resolver: Option<FileResolverImp>,
41 ) { 40 ) {
42 let db = self.db.write();
43 let mut changed = FxHashSet::default(); 41 let mut changed = FxHashSet::default();
44 let mut removed = FxHashSet::default(); 42 let mut removed = FxHashSet::default();
45 for (file_id, text) in changes { 43 for (file_id, text) in changes {
@@ -48,13 +46,13 @@ impl WritableSourceRoot {
48 removed.insert(file_id); 46 removed.insert(file_id);
49 } 47 }
50 Some(text) => { 48 Some(text) => {
51 db.query(db::FileTextQuery) 49 self.db.query(db::FileTextQuery)
52 .set(file_id, Arc::new(text)); 50 .set(file_id, Arc::new(text));
53 changed.insert(file_id); 51 changed.insert(file_id);
54 } 52 }
55 } 53 }
56 } 54 }
57 let file_set = db.file_set(()); 55 let file_set = self.db.file_set(());
58 let mut files: FxHashSet<FileId> = file_set 56 let mut files: FxHashSet<FileId> = file_set
59 .files 57 .files
60 .clone(); 58 .clone();
@@ -63,28 +61,28 @@ impl WritableSourceRoot {
63 } 61 }
64 files.extend(changed); 62 files.extend(changed);
65 let resolver = file_resolver.unwrap_or_else(|| file_set.resolver.clone()); 63 let resolver = file_resolver.unwrap_or_else(|| file_set.resolver.clone());
66 db.query(db::FileSetQuery) 64 self.db.query(db::FileSetQuery)
67 .set((), Arc::new(db::FileSet { files, resolver })); 65 .set((), Arc::new(db::FileSet { files, resolver }));
68 } 66 }
69} 67}
70 68
71impl SourceRoot for WritableSourceRoot { 69impl SourceRoot for WritableSourceRoot {
72 fn module_tree(&self) -> Arc<ModuleTreeDescriptor> { 70 fn module_tree(&self) -> Arc<ModuleTreeDescriptor> {
73 self.db.read().module_tree(()) 71 self.db.module_tree(())
74 } 72 }
75 fn contains(&self, file_id: FileId) -> bool { 73 fn contains(&self, file_id: FileId) -> bool {
76 let db = self.db.read(); 74 self.db.file_set(())
77 let files = &db.file_set(()).files; 75 .files
78 files.contains(&file_id) 76 .contains(&file_id)
79 } 77 }
80 fn lines(&self, file_id: FileId) -> Arc<LineIndex> { 78 fn lines(&self, file_id: FileId) -> Arc<LineIndex> {
81 self.db.read().file_lines(file_id) 79 self.db.file_lines(file_id)
82 } 80 }
83 fn syntax(&self, file_id: FileId) -> File { 81 fn syntax(&self, file_id: FileId) -> File {
84 self.db.read().file_syntax(file_id) 82 self.db.file_syntax(file_id)
85 } 83 }
86 fn symbols<'a>(&'a self, acc: &mut Vec<Arc<SymbolIndex>>) { 84 fn symbols<'a>(&'a self, acc: &mut Vec<Arc<SymbolIndex>>) {
87 let db = self.db.read(); 85 let db = &self.db;
88 let symbols = db.file_set(()); 86 let symbols = db.file_set(());
89 let symbols = symbols 87 let symbols = symbols
90 .files 88 .files