From fedd320cf284ec5d489e62bf809277cedd9f60ac Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 15 Jan 2019 15:45:48 +0300 Subject: check_canceled does not return Result --- crates/ra_db/src/lib.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'crates/ra_db/src/lib.rs') diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index 0e7f32e66..8473fc050 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs @@ -21,11 +21,23 @@ pub use crate::{ }; pub trait BaseDatabase: salsa::Database + panic::RefUnwindSafe { - fn check_canceled(&self) -> Cancelable<()> { + /// 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) { if self.salsa_runtime().is_current_revision_canceled() { Canceled::throw() } - Ok(()) } fn catch_canceled T + panic::UnwindSafe, T>( -- cgit v1.2.3