From 33debc40654be9e9061c53784f6c762b2fd21eba Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 17 May 2021 19:07:10 +0200 Subject: Update salsa --- crates/base_db/src/cancellation.rs | 48 -------------------------------------- crates/base_db/src/lib.rs | 45 ++--------------------------------- 2 files changed, 2 insertions(+), 91 deletions(-) delete mode 100644 crates/base_db/src/cancellation.rs (limited to 'crates/base_db') diff --git a/crates/base_db/src/cancellation.rs b/crates/base_db/src/cancellation.rs deleted file mode 100644 index 7420a1976..000000000 --- a/crates/base_db/src/cancellation.rs +++ /dev/null @@ -1,48 +0,0 @@ -//! Utility types to support cancellation. -//! -//! In a typical IDE use-case, requests and modification happen concurrently, as -//! in the following scenario: -//! -//! * user types a character, -//! * a syntax highlighting process is started -//! * user types next character, while syntax highlighting *is still in -//! progress*. -//! -//! In this situation, we want to react to modification as quickly as possible. -//! At the same time, in-progress results are not very interesting, because they -//! are invalidated by the edit anyway. So, we first cancel all in-flight -//! requests, and then apply modification knowing that it won't interfere with -//! any background processing (this bit is handled by salsa, see the -//! `BaseDatabase::check_canceled` method). - -/// An "error" signifying that the operation was canceled. -#[derive(Clone, PartialEq, Eq, Hash)] -pub struct Canceled { - _private: (), -} - -impl Canceled { - pub(crate) fn new() -> Canceled { - Canceled { _private: () } - } - - pub fn throw() -> ! { - // We use resume and not panic here to avoid running the panic - // hook (that is, to avoid collecting and printing backtrace). - std::panic::resume_unwind(Box::new(Canceled::new())) - } -} - -impl std::fmt::Display for Canceled { - fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - fmt.write_str("canceled") - } -} - -impl std::fmt::Debug for Canceled { - fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(fmt, "Canceled") - } -} - -impl std::error::Error for Canceled {} diff --git a/crates/base_db/src/lib.rs b/crates/base_db/src/lib.rs index 980a0ed98..62bf2a4b2 100644 --- a/crates/base_db/src/lib.rs +++ b/crates/base_db/src/lib.rs @@ -1,5 +1,4 @@ //! base_db defines basic database traits. The concrete DB is defined by ide. -mod cancellation; mod input; mod change; pub mod fixture; @@ -10,14 +9,13 @@ use rustc_hash::FxHashSet; use syntax::{ast, Parse, SourceFile, TextRange, TextSize}; pub use crate::{ - cancellation::Canceled, change::Change, input::{ CrateData, CrateDisplayName, CrateGraph, CrateId, CrateName, Dependency, Edition, Env, ProcMacro, ProcMacroExpander, ProcMacroId, ProcMacroKind, SourceRoot, SourceRootId, }, }; -pub use salsa; +pub use salsa::{self, Cancelled}; pub use vfs::{file_set::FileSet, AnchoredPath, AnchoredPathBuf, FileId, VfsPath}; #[macro_export] @@ -38,45 +36,6 @@ pub trait Upcast { fn upcast(&self) -> &T; } -pub trait CheckCanceled { - /// Aborts current query if there are pending changes. - /// - /// rust-analyzer needs to be able to answer semantic questions about the - /// code while the code is being modified. A common problem is that a - /// long-running query is being calculated when a new change arrives. - /// - /// We can't just apply the change immediately: this will cause the pending - /// query to see inconsistent state (it will observe an absence of - /// repeatable read). So what we do is we **cancel** all pending queries - /// before applying the change. - /// - /// We implement cancellation by panicking with a special value and catching - /// it on the API boundary. Salsa explicitly supports this use-case. - fn check_canceled(&self); - - fn catch_canceled(&self, f: F) -> Result - where - Self: Sized + panic::RefUnwindSafe, - F: FnOnce(&Self) -> T + panic::UnwindSafe, - { - // Uncomment to debug missing cancellations. - // let _span = profile::heartbeat_span(); - panic::catch_unwind(|| f(self)).map_err(|err| match err.downcast::() { - Ok(canceled) => *canceled, - Err(payload) => panic::resume_unwind(payload), - }) - } -} - -impl CheckCanceled for T { - fn check_canceled(&self) { - // profile::heartbeat(); - if self.salsa_runtime().is_current_revision_canceled() { - Canceled::throw() - } - } -} - #[derive(Clone, Copy, Debug)] pub struct FilePosition { pub file_id: FileId, @@ -101,7 +60,7 @@ pub trait FileLoader { /// Database which stores all significant input facts: source code and project /// model. Everything else in rust-analyzer is derived from these queries. #[salsa::query_group(SourceDatabaseStorage)] -pub trait SourceDatabase: CheckCanceled + FileLoader + std::fmt::Debug { +pub trait SourceDatabase: FileLoader + std::fmt::Debug { // Parses the file into the syntax tree. #[salsa::invoke(parse_query)] fn parse(&self, file_id: FileId) -> Parse; -- cgit v1.2.3 From acb5c227ed2d2d52d67ab56a61e6944cd4d5de88 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Sat, 29 May 2021 21:10:00 +0200 Subject: Update to prerelease --- crates/base_db/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/base_db') diff --git a/crates/base_db/Cargo.toml b/crates/base_db/Cargo.toml index 1724d2f85..69173ad1f 100644 --- a/crates/base_db/Cargo.toml +++ b/crates/base_db/Cargo.toml @@ -10,7 +10,7 @@ edition = "2018" doctest = false [dependencies] -salsa = "0.16.0" +salsa = "0.17.0-pre.1" rustc-hash = "1.1.0" syntax = { path = "../syntax", version = "0.0.0" } -- cgit v1.2.3