diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_cli/src/analysis_bench.rs | 38 | ||||
-rw-r--r-- | crates/ra_db/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/traits.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/change.rs | 53 | ||||
-rw-r--r-- | crates/ra_ide_api/src/db.rs | 8 | ||||
-rw-r--r-- | crates/ra_ide_api/src/lib.rs | 3 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/lib.rs | 1 |
8 files changed, 82 insertions, 27 deletions
diff --git a/crates/ra_cli/src/analysis_bench.rs b/crates/ra_cli/src/analysis_bench.rs index 5e9d0c16d..9e76bcebf 100644 --- a/crates/ra_cli/src/analysis_bench.rs +++ b/crates/ra_cli/src/analysis_bench.rs | |||
@@ -1,10 +1,14 @@ | |||
1 | use std::{ | 1 | use std::{ |
2 | path::{Path, PathBuf}, | 2 | path::{Path, PathBuf}, |
3 | sync::Arc, | ||
3 | time::Instant, | 4 | time::Instant, |
4 | }; | 5 | }; |
5 | 6 | ||
6 | use ra_db::{salsa::Database, SourceDatabase}; | 7 | use ra_db::{ |
7 | use ra_ide_api::{Analysis, AnalysisHost, FilePosition, LineCol}; | 8 | salsa::{Database, Durability}, |
9 | FileId, SourceDatabase, | ||
10 | }; | ||
11 | use ra_ide_api::{Analysis, AnalysisChange, AnalysisHost, FilePosition, LineCol}; | ||
8 | 12 | ||
9 | use crate::Result; | 13 | use crate::Result; |
10 | 14 | ||
@@ -16,7 +20,7 @@ pub(crate) enum Op { | |||
16 | pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> { | 20 | pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> { |
17 | let start = Instant::now(); | 21 | let start = Instant::now(); |
18 | eprint!("loading: "); | 22 | eprint!("loading: "); |
19 | let (host, roots) = ra_batch::load_cargo(path)?; | 23 | let (mut host, roots) = ra_batch::load_cargo(path)?; |
20 | let db = host.raw_database(); | 24 | let db = host.raw_database(); |
21 | eprintln!("{:?}\n", start.elapsed()); | 25 | eprintln!("{:?}\n", start.elapsed()); |
22 | 26 | ||
@@ -44,7 +48,7 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> { | |||
44 | 48 | ||
45 | match op { | 49 | match op { |
46 | Op::Highlight { .. } => { | 50 | Op::Highlight { .. } => { |
47 | let res = do_work(&host, |analysis| { | 51 | let res = do_work(&mut host, file_id, |analysis| { |
48 | analysis.diagnostics(file_id).unwrap(); | 52 | analysis.diagnostics(file_id).unwrap(); |
49 | analysis.highlight_as_html(file_id, false).unwrap() | 53 | analysis.highlight_as_html(file_id, false).unwrap() |
50 | }); | 54 | }); |
@@ -59,7 +63,7 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> { | |||
59 | .offset(LineCol { line, col_utf16: column }); | 63 | .offset(LineCol { line, col_utf16: column }); |
60 | let file_postion = FilePosition { file_id, offset }; | 64 | let file_postion = FilePosition { file_id, offset }; |
61 | 65 | ||
62 | let res = do_work(&host, |analysis| analysis.completions(file_postion)); | 66 | let res = do_work(&mut host, file_id, |analysis| analysis.completions(file_postion)); |
63 | if verbose { | 67 | if verbose { |
64 | println!("\n{:#?}", res); | 68 | println!("\n{:#?}", res); |
65 | } | 69 | } |
@@ -68,7 +72,7 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> { | |||
68 | Ok(()) | 72 | Ok(()) |
69 | } | 73 | } |
70 | 74 | ||
71 | fn do_work<F: Fn(&Analysis) -> T, T>(host: &AnalysisHost, work: F) -> T { | 75 | fn do_work<F: Fn(&Analysis) -> T, T>(host: &mut AnalysisHost, file_id: FileId, work: F) -> T { |
72 | { | 76 | { |
73 | let start = Instant::now(); | 77 | let start = Instant::now(); |
74 | eprint!("from scratch: "); | 78 | eprint!("from scratch: "); |
@@ -84,7 +88,27 @@ fn do_work<F: Fn(&Analysis) -> T, T>(host: &AnalysisHost, work: F) -> T { | |||
84 | { | 88 | { |
85 | let start = Instant::now(); | 89 | let start = Instant::now(); |
86 | eprint!("trivial change: "); | 90 | eprint!("trivial change: "); |
87 | host.raw_database().salsa_runtime().next_revision(); | 91 | host.raw_database().salsa_runtime().synthetic_write(Durability::LOW); |
92 | work(&host.analysis()); | ||
93 | eprintln!("{:?}", start.elapsed()); | ||
94 | } | ||
95 | { | ||
96 | let start = Instant::now(); | ||
97 | eprint!("comment change: "); | ||
98 | { | ||
99 | let mut text = host.analysis().file_text(file_id).unwrap().to_string(); | ||
100 | text.push_str("\n/* Hello world */\n"); | ||
101 | let mut change = AnalysisChange::new(); | ||
102 | change.change_file(file_id, Arc::new(text)); | ||
103 | host.apply_change(change); | ||
104 | } | ||
105 | work(&host.analysis()); | ||
106 | eprintln!("{:?}", start.elapsed()); | ||
107 | } | ||
108 | { | ||
109 | let start = Instant::now(); | ||
110 | eprint!("const change: "); | ||
111 | host.raw_database().salsa_runtime().synthetic_write(Durability::HIGH); | ||
88 | let res = work(&host.analysis()); | 112 | let res = work(&host.analysis()); |
89 | eprintln!("{:?}", start.elapsed()); | 113 | eprintln!("{:?}", start.elapsed()); |
90 | res | 114 | res |
diff --git a/crates/ra_db/Cargo.toml b/crates/ra_db/Cargo.toml index 7a13c247b..2fac07bc5 100644 --- a/crates/ra_db/Cargo.toml +++ b/crates/ra_db/Cargo.toml | |||
@@ -5,7 +5,7 @@ version = "0.1.0" | |||
5 | authors = ["rust-analyzer developers"] | 5 | authors = ["rust-analyzer developers"] |
6 | 6 | ||
7 | [dependencies] | 7 | [dependencies] |
8 | salsa = "0.12.3" | 8 | salsa = "0.13.0" |
9 | relative-path = "0.4.0" | 9 | relative-path = "0.4.0" |
10 | rustc-hash = "1.0" | 10 | rustc-hash = "1.0" |
11 | 11 | ||
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 081974e2b..018fcd096 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -1,3 +1,5 @@ | |||
1 | #![recursion_limit = "512"] | ||
2 | |||
1 | //! HIR (previously known as descriptors) provides a high-level object oriented | 3 | //! HIR (previously known as descriptors) provides a high-level object oriented |
2 | //! access to Rust code. | 4 | //! access to Rust code. |
3 | //! | 5 | //! |
diff --git a/crates/ra_hir/src/ty/traits.rs b/crates/ra_hir/src/ty/traits.rs index 5406fb4a6..b634f0b79 100644 --- a/crates/ra_hir/src/ty/traits.rs +++ b/crates/ra_hir/src/ty/traits.rs | |||
@@ -38,7 +38,7 @@ impl TraitSolver { | |||
38 | ) -> Option<chalk_solve::Solution> { | 38 | ) -> Option<chalk_solve::Solution> { |
39 | let context = ChalkContext { db, krate: self.krate }; | 39 | let context = ChalkContext { db, krate: self.krate }; |
40 | debug!("solve goal: {:?}", goal); | 40 | debug!("solve goal: {:?}", goal); |
41 | let solution = self.inner.lock().solve_with_fuel(&context, goal, Some(1000)); | 41 | let solution = self.inner.lock().solve(&context, goal); |
42 | debug!("solve({:?}) => {:?}", goal, solution); | 42 | debug!("solve({:?}) => {:?}", goal, solution); |
43 | solution | 43 | solution |
44 | } | 44 | } |
diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs index 147d2b21d..0234c572d 100644 --- a/crates/ra_ide_api/src/change.rs +++ b/crates/ra_ide_api/src/change.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use std::{fmt, sync::Arc, time}; | 1 | use std::{fmt, sync::Arc, time}; |
2 | 2 | ||
3 | use ra_db::{ | 3 | use ra_db::{ |
4 | salsa::{Database, SweepStrategy}, | 4 | salsa::{Database, Durability, SweepStrategy}, |
5 | CrateGraph, FileId, SourceDatabase, SourceRoot, SourceRootId, | 5 | CrateGraph, FileId, SourceDatabase, SourceRoot, SourceRootId, |
6 | }; | 6 | }; |
7 | use ra_prof::{memory_usage, profile, Bytes}; | 7 | use ra_prof::{memory_usage, profile, Bytes}; |
@@ -155,54 +155,71 @@ impl RootDatabase { | |||
155 | log::info!("apply_change {:?}", change); | 155 | log::info!("apply_change {:?}", change); |
156 | { | 156 | { |
157 | let _p = profile("RootDatabase::apply_change/cancellation"); | 157 | let _p = profile("RootDatabase::apply_change/cancellation"); |
158 | self.salsa_runtime().next_revision(); | 158 | self.salsa_runtime().synthetic_write(Durability::LOW); |
159 | } | 159 | } |
160 | if !change.new_roots.is_empty() { | 160 | if !change.new_roots.is_empty() { |
161 | let mut local_roots = Vec::clone(&self.local_roots()); | 161 | let mut local_roots = Vec::clone(&self.local_roots()); |
162 | for (root_id, is_local) in change.new_roots { | 162 | for (root_id, is_local) in change.new_roots { |
163 | let root = if is_local { SourceRoot::new() } else { SourceRoot::new_library() }; | 163 | let root = if is_local { SourceRoot::new() } else { SourceRoot::new_library() }; |
164 | self.set_source_root(root_id, Arc::new(root)); | 164 | let durability = durability(&root); |
165 | self.set_source_root_with_durability(root_id, Arc::new(root), durability); | ||
165 | if is_local { | 166 | if is_local { |
166 | local_roots.push(root_id); | 167 | local_roots.push(root_id); |
167 | } | 168 | } |
168 | } | 169 | } |
169 | self.set_local_roots(Arc::new(local_roots)); | 170 | self.set_local_roots_with_durability(Arc::new(local_roots), Durability::HIGH); |
170 | } | 171 | } |
171 | 172 | ||
172 | for (root_id, root_change) in change.roots_changed { | 173 | for (root_id, root_change) in change.roots_changed { |
173 | self.apply_root_change(root_id, root_change); | 174 | self.apply_root_change(root_id, root_change); |
174 | } | 175 | } |
175 | for (file_id, text) in change.files_changed { | 176 | for (file_id, text) in change.files_changed { |
176 | self.set_file_text(file_id, text) | 177 | let source_root_id = self.file_source_root(file_id); |
178 | let source_root = self.source_root(source_root_id); | ||
179 | let durability = durability(&source_root); | ||
180 | self.set_file_text_with_durability(file_id, text, durability) | ||
177 | } | 181 | } |
178 | if !change.libraries_added.is_empty() { | 182 | if !change.libraries_added.is_empty() { |
179 | let mut libraries = Vec::clone(&self.library_roots()); | 183 | let mut libraries = Vec::clone(&self.library_roots()); |
180 | for library in change.libraries_added { | 184 | for library in change.libraries_added { |
181 | libraries.push(library.root_id); | 185 | libraries.push(library.root_id); |
182 | self.set_source_root(library.root_id, Default::default()); | 186 | self.set_source_root_with_durability( |
183 | self.set_constant_library_symbols(library.root_id, Arc::new(library.symbol_index)); | 187 | library.root_id, |
188 | Default::default(), | ||
189 | Durability::HIGH, | ||
190 | ); | ||
191 | self.set_library_symbols_with_durability( | ||
192 | library.root_id, | ||
193 | Arc::new(library.symbol_index), | ||
194 | Durability::HIGH, | ||
195 | ); | ||
184 | self.apply_root_change(library.root_id, library.root_change); | 196 | self.apply_root_change(library.root_id, library.root_change); |
185 | } | 197 | } |
186 | self.set_library_roots(Arc::new(libraries)); | 198 | self.set_library_roots_with_durability(Arc::new(libraries), Durability::HIGH); |
187 | } | 199 | } |
188 | if let Some(crate_graph) = change.crate_graph { | 200 | if let Some(crate_graph) = change.crate_graph { |
189 | self.set_crate_graph(Arc::new(crate_graph)) | 201 | self.set_crate_graph_with_durability(Arc::new(crate_graph), Durability::HIGH) |
190 | } | 202 | } |
191 | } | 203 | } |
192 | 204 | ||
193 | fn apply_root_change(&mut self, root_id: SourceRootId, root_change: RootChange) { | 205 | fn apply_root_change(&mut self, root_id: SourceRootId, root_change: RootChange) { |
194 | let mut source_root = SourceRoot::clone(&self.source_root(root_id)); | 206 | let mut source_root = SourceRoot::clone(&self.source_root(root_id)); |
207 | let durability = durability(&source_root); | ||
195 | for add_file in root_change.added { | 208 | for add_file in root_change.added { |
196 | self.set_file_text(add_file.file_id, add_file.text); | 209 | self.set_file_text_with_durability(add_file.file_id, add_file.text, durability); |
197 | self.set_file_relative_path(add_file.file_id, add_file.path.clone()); | 210 | self.set_file_relative_path_with_durability( |
198 | self.set_file_source_root(add_file.file_id, root_id); | 211 | add_file.file_id, |
212 | add_file.path.clone(), | ||
213 | durability, | ||
214 | ); | ||
215 | self.set_file_source_root_with_durability(add_file.file_id, root_id, durability); | ||
199 | source_root.files.insert(add_file.path, add_file.file_id); | 216 | source_root.files.insert(add_file.path, add_file.file_id); |
200 | } | 217 | } |
201 | for remove_file in root_change.removed { | 218 | for remove_file in root_change.removed { |
202 | self.set_file_text(remove_file.file_id, Default::default()); | 219 | self.set_file_text_with_durability(remove_file.file_id, Default::default(), durability); |
203 | source_root.files.remove(&remove_file.path); | 220 | source_root.files.remove(&remove_file.path); |
204 | } | 221 | } |
205 | self.set_source_root(root_id, Arc::new(source_root)); | 222 | self.set_source_root_with_durability(root_id, Arc::new(source_root), durability); |
206 | } | 223 | } |
207 | 224 | ||
208 | pub(crate) fn maybe_collect_garbage(&mut self) { | 225 | pub(crate) fn maybe_collect_garbage(&mut self) { |
@@ -308,3 +325,11 @@ impl RootDatabase { | |||
308 | acc | 325 | acc |
309 | } | 326 | } |
310 | } | 327 | } |
328 | |||
329 | fn durability(source_root: &SourceRoot) -> Durability { | ||
330 | if source_root.is_library { | ||
331 | Durability::HIGH | ||
332 | } else { | ||
333 | Durability::LOW | ||
334 | } | ||
335 | } | ||
diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs index 44216b045..fc8252e4b 100644 --- a/crates/ra_ide_api/src/db.rs +++ b/crates/ra_ide_api/src/db.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use std::{sync::Arc, time}; | 1 | use std::{sync::Arc, time}; |
2 | 2 | ||
3 | use ra_db::{ | 3 | use ra_db::{ |
4 | salsa::{self, Database}, | 4 | salsa::{self, Database, Durability}, |
5 | Canceled, CheckCanceled, FileId, SourceDatabase, | 5 | Canceled, CheckCanceled, FileId, SourceDatabase, |
6 | }; | 6 | }; |
7 | 7 | ||
@@ -57,9 +57,9 @@ impl RootDatabase { | |||
57 | last_gc: time::Instant::now(), | 57 | last_gc: time::Instant::now(), |
58 | last_gc_check: time::Instant::now(), | 58 | last_gc_check: time::Instant::now(), |
59 | }; | 59 | }; |
60 | db.set_crate_graph(Default::default()); | 60 | db.set_crate_graph_with_durability(Default::default(), Durability::HIGH); |
61 | db.set_local_roots(Default::default()); | 61 | db.set_local_roots_with_durability(Default::default(), Durability::HIGH); |
62 | db.set_library_roots(Default::default()); | 62 | db.set_library_roots_with_durability(Default::default(), Durability::HIGH); |
63 | let lru_capacity = lru_capacity.unwrap_or(ra_db::DEFAULT_LRU_CAP); | 63 | let lru_capacity = lru_capacity.unwrap_or(ra_db::DEFAULT_LRU_CAP); |
64 | db.query_mut(ra_db::ParseQuery).set_lru_capacity(lru_capacity); | 64 | db.query_mut(ra_db::ParseQuery).set_lru_capacity(lru_capacity); |
65 | db.query_mut(hir::db::ParseMacroQuery).set_lru_capacity(lru_capacity); | 65 | db.query_mut(hir::db::ParseMacroQuery).set_lru_capacity(lru_capacity); |
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index edb646c11..fa4ae4379 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs | |||
@@ -281,6 +281,9 @@ impl AnalysisHost { | |||
281 | pub fn raw_database(&self) -> &(impl hir::db::HirDatabase + salsa::Database) { | 281 | pub fn raw_database(&self) -> &(impl hir::db::HirDatabase + salsa::Database) { |
282 | &self.db | 282 | &self.db |
283 | } | 283 | } |
284 | pub fn raw_database_mut(&mut self) -> &mut (impl hir::db::HirDatabase + salsa::Database) { | ||
285 | &mut self.db | ||
286 | } | ||
284 | } | 287 | } |
285 | 288 | ||
286 | /// Analysis is a snapshot of a world state at a moment in time. It is the main | 289 | /// Analysis is a snapshot of a world state at a moment in time. It is the main |
diff --git a/crates/ra_lsp_server/src/lib.rs b/crates/ra_lsp_server/src/lib.rs index 795f86383..ca388e472 100644 --- a/crates/ra_lsp_server/src/lib.rs +++ b/crates/ra_lsp_server/src/lib.rs | |||
@@ -1,3 +1,4 @@ | |||
1 | #![recursion_limit = "512"] | ||
1 | mod caps; | 2 | mod caps; |
2 | mod cargo_target_spec; | 3 | mod cargo_target_spec; |
3 | mod conv; | 4 | mod conv; |