Skip to content

Commit e9a7977

Browse files
Merge #8866
8866: Update salsa r=matklad a=jonas-schievink This updates salsa to include salsa-rs/salsa#265, and removes all cancellation-related code from rust-analyzer Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2 parents b8d2699 + acb5c22 commit e9a7977

File tree

16 files changed

+98
-189
lines changed

16 files changed

+98
-189
lines changed

Cargo.lock

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

crates/base_db/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ edition = "2018"
1010
doctest = false
1111

1212
[dependencies]
13-
salsa = "0.16.0"
13+
salsa = "0.17.0-pre.1"
1414
rustc-hash = "1.1.0"
1515

1616
syntax = { path = "../syntax", version = "0.0.0" }

crates/base_db/src/cancellation.rs

Lines changed: 0 additions & 48 deletions
This file was deleted.

crates/base_db/src/lib.rs

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//! base_db defines basic database traits. The concrete DB is defined by ide.
2-
mod cancellation;
32
mod input;
43
mod change;
54
pub mod fixture;
@@ -10,14 +9,13 @@ use rustc_hash::FxHashSet;
109
use syntax::{ast, Parse, SourceFile, TextRange, TextSize};
1110

1211
pub use crate::{
13-
cancellation::Canceled,
1412
change::Change,
1513
input::{
1614
CrateData, CrateDisplayName, CrateGraph, CrateId, CrateName, Dependency, Edition, Env,
1715
ProcMacro, ProcMacroExpander, ProcMacroId, ProcMacroKind, SourceRoot, SourceRootId,
1816
},
1917
};
20-
pub use salsa;
18+
pub use salsa::{self, Cancelled};
2119
pub use vfs::{file_set::FileSet, AnchoredPath, AnchoredPathBuf, FileId, VfsPath};
2220

2321
#[macro_export]
@@ -38,45 +36,6 @@ pub trait Upcast<T: ?Sized> {
3836
fn upcast(&self) -> &T;
3937
}
4038

41-
pub trait CheckCanceled {
42-
/// Aborts current query if there are pending changes.
43-
///
44-
/// rust-analyzer needs to be able to answer semantic questions about the
45-
/// code while the code is being modified. A common problem is that a
46-
/// long-running query is being calculated when a new change arrives.
47-
///
48-
/// We can't just apply the change immediately: this will cause the pending
49-
/// query to see inconsistent state (it will observe an absence of
50-
/// repeatable read). So what we do is we **cancel** all pending queries
51-
/// before applying the change.
52-
///
53-
/// We implement cancellation by panicking with a special value and catching
54-
/// it on the API boundary. Salsa explicitly supports this use-case.
55-
fn check_canceled(&self);
56-
57-
fn catch_canceled<F, T>(&self, f: F) -> Result<T, Canceled>
58-
where
59-
Self: Sized + panic::RefUnwindSafe,
60-
F: FnOnce(&Self) -> T + panic::UnwindSafe,
61-
{
62-
// Uncomment to debug missing cancellations.
63-
// let _span = profile::heartbeat_span();
64-
panic::catch_unwind(|| f(self)).map_err(|err| match err.downcast::<Canceled>() {
65-
Ok(canceled) => *canceled,
66-
Err(payload) => panic::resume_unwind(payload),
67-
})
68-
}
69-
}
70-
71-
impl<T: salsa::Database> CheckCanceled for T {
72-
fn check_canceled(&self) {
73-
// profile::heartbeat();
74-
if self.salsa_runtime().is_current_revision_canceled() {
75-
Canceled::throw()
76-
}
77-
}
78-
}
79-
8039
#[derive(Clone, Copy, Debug)]
8140
pub struct FilePosition {
8241
pub file_id: FileId,
@@ -101,7 +60,7 @@ pub trait FileLoader {
10160
/// Database which stores all significant input facts: source code and project
10261
/// model. Everything else in rust-analyzer is derived from these queries.
10362
#[salsa::query_group(SourceDatabaseStorage)]
104-
pub trait SourceDatabase: CheckCanceled + FileLoader + std::fmt::Debug {
63+
pub trait SourceDatabase: FileLoader + std::fmt::Debug {
10564
// Parses the file into the syntax tree.
10665
#[salsa::invoke(parse_query)]
10766
fn parse(&self, file_id: FileId) -> Parse<ast::SourceFile>;

crates/hir/src/semantics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ impl<'db> SemanticsImpl<'db> {
361361
let sa = self.analyze(&parent);
362362

363363
let token = successors(Some(InFile::new(sa.file_id, token)), |token| {
364-
self.db.check_canceled();
364+
self.db.unwind_if_cancelled();
365365
let macro_call = token.value.ancestors().find_map(ast::MacroCall::cast)?;
366366
let tt = macro_call.token_tree()?;
367367
if !tt.syntax().text_range().contains_range(token.value.text_range()) {

crates/hir_def/src/nameres/collector.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ impl DefCollector<'_> {
351351
let mut i = 0;
352352
'outer: loop {
353353
loop {
354-
self.db.check_canceled();
354+
self.db.unwind_if_cancelled();
355355
loop {
356356
if self.resolve_imports() == ReachedFixedPoint::Yes {
357357
break;
@@ -836,7 +836,7 @@ impl DefCollector<'_> {
836836
vis: Visibility,
837837
import_type: ImportType,
838838
) {
839-
self.db.check_canceled();
839+
self.db.unwind_if_cancelled();
840840
self.update_recursive(module_id, resolutions, vis, import_type, 0)
841841
}
842842

crates/hir_ty/src/infer/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl<'a> InferenceContext<'a> {
119119
}
120120

121121
fn infer_expr_inner(&mut self, tgt_expr: ExprId, expected: &Expectation) -> Ty {
122-
self.db.check_canceled();
122+
self.db.unwind_if_cancelled();
123123

124124
let body = Arc::clone(&self.body); // avoid borrow checker problem
125125
let ty = match &body[tgt_expr] {

crates/hir_ty/src/traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ fn solve(
112112
let fuel = std::cell::Cell::new(CHALK_SOLVER_FUEL);
113113

114114
let should_continue = || {
115-
context.db.check_canceled();
115+
db.unwind_if_cancelled();
116116
let remaining = fuel.get();
117117
fuel.set(remaining - 1);
118118
if remaining == 0 {

0 commit comments

Comments
 (0)