Skip to content

Commit 9b024b6

Browse files
bors[bot]matklad
andcommitted
Merge #1445
1445: Use the new "durability" infrastructure from salsa r=matklad a=matklad Based on https://github.com/nikomatsakis/salsa/tree/durability Durability allows us to skip *validation* work for sysroot and crates.io libraries, which massively speeds up some workloads Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 5ed6a13 + 1700541 commit 9b024b6

File tree

10 files changed

+166
-68
lines changed

10 files changed

+166
-68
lines changed

Cargo.lock

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

crates/ra_cli/src/analysis_bench.rs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
use std::{
22
path::{Path, PathBuf},
3+
sync::Arc,
34
time::Instant,
45
};
56

6-
use ra_db::{salsa::Database, SourceDatabase};
7-
use ra_ide_api::{Analysis, AnalysisHost, FilePosition, LineCol};
7+
use ra_db::{
8+
salsa::{Database, Durability},
9+
FileId, SourceDatabase,
10+
};
11+
use ra_ide_api::{Analysis, AnalysisChange, AnalysisHost, FilePosition, LineCol};
812

913
use crate::Result;
1014

@@ -16,7 +20,7 @@ pub(crate) enum Op {
1620
pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> {
1721
let start = Instant::now();
1822
eprint!("loading: ");
19-
let (host, roots) = ra_batch::load_cargo(path)?;
23+
let (mut host, roots) = ra_batch::load_cargo(path)?;
2024
let db = host.raw_database();
2125
eprintln!("{:?}\n", start.elapsed());
2226

@@ -44,7 +48,7 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> {
4448

4549
match op {
4650
Op::Highlight { .. } => {
47-
let res = do_work(&host, |analysis| {
51+
let res = do_work(&mut host, file_id, |analysis| {
4852
analysis.diagnostics(file_id).unwrap();
4953
analysis.highlight_as_html(file_id, false).unwrap()
5054
});
@@ -59,7 +63,7 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> {
5963
.offset(LineCol { line, col_utf16: column });
6064
let file_postion = FilePosition { file_id, offset };
6165

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));
6367
if verbose {
6468
println!("\n{:#?}", res);
6569
}
@@ -68,7 +72,7 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> {
6872
Ok(())
6973
}
7074

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 {
7276
{
7377
let start = Instant::now();
7478
eprint!("from scratch: ");
@@ -84,7 +88,27 @@ fn do_work<F: Fn(&Analysis) -> T, T>(host: &AnalysisHost, work: F) -> T {
8488
{
8589
let start = Instant::now();
8690
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);
88112
let res = work(&host.analysis());
89113
eprintln!("{:?}", start.elapsed());
90114
res

crates/ra_db/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ version = "0.1.0"
55
authors = ["rust-analyzer developers"]
66

77
[dependencies]
8-
salsa = "0.12.3"
8+
salsa = "0.13.0"
99
relative-path = "0.4.0"
1010
rustc-hash = "1.0"
1111

crates/ra_hir/src/db.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::sync::Arc;
22

3-
use parking_lot::Mutex;
43
use ra_db::{salsa, SourceDatabase};
54
use ra_syntax::{ast, Parse, SmolStr, SyntaxNode};
65

@@ -147,6 +146,7 @@ pub trait DefDatabase: InternDatabase {
147146
}
148147

149148
#[salsa::query_group(HirDatabaseStorage)]
149+
#[salsa::requires(salsa::Database)]
150150
pub trait HirDatabase: DefDatabase + AstDatabase {
151151
#[salsa::invoke(ExprScopes::expr_scopes_query)]
152152
fn expr_scopes(&self, def: DefWithBody) -> Arc<ExprScopes>;
@@ -187,11 +187,10 @@ pub trait HirDatabase: DefDatabase + AstDatabase {
187187
/// This provides the Chalk trait solver instance. Because Chalk always
188188
/// works from a specific crate, this query is keyed on the crate; and
189189
/// because Chalk does its own internal caching, the solver is wrapped in a
190-
/// Mutex and the query is marked volatile, to make sure the cached state is
191-
/// thrown away when input facts change.
190+
/// Mutex and the query does an untracked read internally, to make sure the
191+
/// cached state is thrown away when input facts change.
192192
#[salsa::invoke(crate::ty::traits::trait_solver_query)]
193-
#[salsa::volatile]
194-
fn trait_solver(&self, krate: Crate) -> Arc<Mutex<crate::ty::traits::Solver>>;
193+
fn trait_solver(&self, krate: Crate) -> crate::ty::traits::TraitSolver;
195194

196195
#[salsa::invoke(crate::ty::traits::chalk::associated_ty_data_query)]
197196
fn associated_ty_data(&self, id: chalk_ir::TypeId) -> Arc<chalk_rust_ir::AssociatedTyDatum>;

crates/ra_hir/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![recursion_limit = "512"]
2+
13
//! HIR (previously known as descriptors) provides a high-level object oriented
24
//! access to Rust code.
35
//!

0 commit comments

Comments
 (0)