From 343463c824f4672f19be08f4786d3eeb2e7dea9f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 26 Jun 2019 09:12:46 +0300 Subject: implement durability --- crates/ra_cli/src/analysis_bench.rs | 38 +++++++++++++++++++++----- crates/ra_db/Cargo.toml | 2 +- crates/ra_hir/src/lib.rs | 2 ++ crates/ra_hir/src/ty/traits.rs | 2 +- crates/ra_ide_api/src/change.rs | 53 +++++++++++++++++++++++++++---------- crates/ra_ide_api/src/db.rs | 8 +++--- crates/ra_ide_api/src/lib.rs | 3 +++ crates/ra_lsp_server/src/lib.rs | 1 + 8 files changed, 82 insertions(+), 27 deletions(-) (limited to 'crates') 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 @@ use std::{ path::{Path, PathBuf}, + sync::Arc, time::Instant, }; -use ra_db::{salsa::Database, SourceDatabase}; -use ra_ide_api::{Analysis, AnalysisHost, FilePosition, LineCol}; +use ra_db::{ + salsa::{Database, Durability}, + FileId, SourceDatabase, +}; +use ra_ide_api::{Analysis, AnalysisChange, AnalysisHost, FilePosition, LineCol}; use crate::Result; @@ -16,7 +20,7 @@ pub(crate) enum Op { pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> { let start = Instant::now(); eprint!("loading: "); - let (host, roots) = ra_batch::load_cargo(path)?; + let (mut host, roots) = ra_batch::load_cargo(path)?; let db = host.raw_database(); eprintln!("{:?}\n", start.elapsed()); @@ -44,7 +48,7 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> { match op { Op::Highlight { .. } => { - let res = do_work(&host, |analysis| { + let res = do_work(&mut host, file_id, |analysis| { analysis.diagnostics(file_id).unwrap(); analysis.highlight_as_html(file_id, false).unwrap() }); @@ -59,7 +63,7 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> { .offset(LineCol { line, col_utf16: column }); let file_postion = FilePosition { file_id, offset }; - let res = do_work(&host, |analysis| analysis.completions(file_postion)); + let res = do_work(&mut host, file_id, |analysis| analysis.completions(file_postion)); if verbose { println!("\n{:#?}", res); } @@ -68,7 +72,7 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> { Ok(()) } -fn do_work T, T>(host: &AnalysisHost, work: F) -> T { +fn do_work T, T>(host: &mut AnalysisHost, file_id: FileId, work: F) -> T { { let start = Instant::now(); eprint!("from scratch: "); @@ -84,7 +88,27 @@ fn do_work T, T>(host: &AnalysisHost, work: F) -> T { { let start = Instant::now(); eprint!("trivial change: "); - host.raw_database().salsa_runtime().next_revision(); + host.raw_database().salsa_runtime().synthetic_write(Durability::LOW); + work(&host.analysis()); + eprintln!("{:?}", start.elapsed()); + } + { + let start = Instant::now(); + eprint!("comment change: "); + { + let mut text = host.analysis().file_text(file_id).unwrap().to_string(); + text.push_str("\n/* Hello world */\n"); + let mut change = AnalysisChange::new(); + change.change_file(file_id, Arc::new(text)); + host.apply_change(change); + } + work(&host.analysis()); + eprintln!("{:?}", start.elapsed()); + } + { + let start = Instant::now(); + eprint!("const change: "); + host.raw_database().salsa_runtime().synthetic_write(Durability::HIGH); let res = work(&host.analysis()); eprintln!("{:?}", start.elapsed()); 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" authors = ["rust-analyzer developers"] [dependencies] -salsa = "0.12.3" +salsa = "0.13.0" relative-path = "0.4.0" rustc-hash = "1.0" 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 @@ +#![recursion_limit = "512"] + //! HIR (previously known as descriptors) provides a high-level object oriented //! access to Rust code. //! 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 { ) -> Option { let context = ChalkContext { db, krate: self.krate }; debug!("solve goal: {:?}", goal); - let solution = self.inner.lock().solve_with_fuel(&context, goal, Some(1000)); + let solution = self.inner.lock().solve(&context, goal); debug!("solve({:?}) => {:?}", goal, solution); solution } 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 @@ use std::{fmt, sync::Arc, time}; use ra_db::{ - salsa::{Database, SweepStrategy}, + salsa::{Database, Durability, SweepStrategy}, CrateGraph, FileId, SourceDatabase, SourceRoot, SourceRootId, }; use ra_prof::{memory_usage, profile, Bytes}; @@ -155,54 +155,71 @@ impl RootDatabase { log::info!("apply_change {:?}", change); { let _p = profile("RootDatabase::apply_change/cancellation"); - self.salsa_runtime().next_revision(); + self.salsa_runtime().synthetic_write(Durability::LOW); } if !change.new_roots.is_empty() { let mut local_roots = Vec::clone(&self.local_roots()); for (root_id, is_local) in change.new_roots { let root = if is_local { SourceRoot::new() } else { SourceRoot::new_library() }; - self.set_source_root(root_id, Arc::new(root)); + let durability = durability(&root); + self.set_source_root_with_durability(root_id, Arc::new(root), durability); if is_local { local_roots.push(root_id); } } - self.set_local_roots(Arc::new(local_roots)); + self.set_local_roots_with_durability(Arc::new(local_roots), Durability::HIGH); } for (root_id, root_change) in change.roots_changed { self.apply_root_change(root_id, root_change); } for (file_id, text) in change.files_changed { - self.set_file_text(file_id, text) + let source_root_id = self.file_source_root(file_id); + let source_root = self.source_root(source_root_id); + let durability = durability(&source_root); + self.set_file_text_with_durability(file_id, text, durability) } if !change.libraries_added.is_empty() { let mut libraries = Vec::clone(&self.library_roots()); for library in change.libraries_added { libraries.push(library.root_id); - self.set_source_root(library.root_id, Default::default()); - self.set_constant_library_symbols(library.root_id, Arc::new(library.symbol_index)); + self.set_source_root_with_durability( + library.root_id, + Default::default(), + Durability::HIGH, + ); + self.set_library_symbols_with_durability( + library.root_id, + Arc::new(library.symbol_index), + Durability::HIGH, + ); self.apply_root_change(library.root_id, library.root_change); } - self.set_library_roots(Arc::new(libraries)); + self.set_library_roots_with_durability(Arc::new(libraries), Durability::HIGH); } if let Some(crate_graph) = change.crate_graph { - self.set_crate_graph(Arc::new(crate_graph)) + self.set_crate_graph_with_durability(Arc::new(crate_graph), Durability::HIGH) } } fn apply_root_change(&mut self, root_id: SourceRootId, root_change: RootChange) { let mut source_root = SourceRoot::clone(&self.source_root(root_id)); + let durability = durability(&source_root); for add_file in root_change.added { - self.set_file_text(add_file.file_id, add_file.text); - self.set_file_relative_path(add_file.file_id, add_file.path.clone()); - self.set_file_source_root(add_file.file_id, root_id); + self.set_file_text_with_durability(add_file.file_id, add_file.text, durability); + self.set_file_relative_path_with_durability( + add_file.file_id, + add_file.path.clone(), + durability, + ); + self.set_file_source_root_with_durability(add_file.file_id, root_id, durability); source_root.files.insert(add_file.path, add_file.file_id); } for remove_file in root_change.removed { - self.set_file_text(remove_file.file_id, Default::default()); + self.set_file_text_with_durability(remove_file.file_id, Default::default(), durability); source_root.files.remove(&remove_file.path); } - self.set_source_root(root_id, Arc::new(source_root)); + self.set_source_root_with_durability(root_id, Arc::new(source_root), durability); } pub(crate) fn maybe_collect_garbage(&mut self) { @@ -308,3 +325,11 @@ impl RootDatabase { acc } } + +fn durability(source_root: &SourceRoot) -> Durability { + if source_root.is_library { + Durability::HIGH + } else { + Durability::LOW + } +} 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 @@ use std::{sync::Arc, time}; use ra_db::{ - salsa::{self, Database}, + salsa::{self, Database, Durability}, Canceled, CheckCanceled, FileId, SourceDatabase, }; @@ -57,9 +57,9 @@ impl RootDatabase { last_gc: time::Instant::now(), last_gc_check: time::Instant::now(), }; - db.set_crate_graph(Default::default()); - db.set_local_roots(Default::default()); - db.set_library_roots(Default::default()); + db.set_crate_graph_with_durability(Default::default(), Durability::HIGH); + db.set_local_roots_with_durability(Default::default(), Durability::HIGH); + db.set_library_roots_with_durability(Default::default(), Durability::HIGH); let lru_capacity = lru_capacity.unwrap_or(ra_db::DEFAULT_LRU_CAP); db.query_mut(ra_db::ParseQuery).set_lru_capacity(lru_capacity); 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 { pub fn raw_database(&self) -> &(impl hir::db::HirDatabase + salsa::Database) { &self.db } + pub fn raw_database_mut(&mut self) -> &mut (impl hir::db::HirDatabase + salsa::Database) { + &mut self.db + } } /// 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 @@ +#![recursion_limit = "512"] mod caps; mod cargo_target_spec; mod conv; -- cgit v1.2.3