diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-15 12:46:18 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-15 12:46:18 +0000 |
commit | 443ff27724855ffbfccad3513bb82d59e1a4f8ae (patch) | |
tree | 684cec39e4dd7856c4738a4635ac5bce814efcd0 /crates/ra_db | |
parent | c7f072372edc7a94544c993d03928aab2ac92dab (diff) | |
parent | fedd320cf284ec5d489e62bf809277cedd9f60ac (diff) |
Merge #548
548: check_canceled does not return Result r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_db')
-rw-r--r-- | crates/ra_db/src/lib.rs | 16 |
1 files changed, 14 insertions, 2 deletions
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::{ | |||
21 | }; | 21 | }; |
22 | 22 | ||
23 | pub trait BaseDatabase: salsa::Database + panic::RefUnwindSafe { | 23 | pub trait BaseDatabase: salsa::Database + panic::RefUnwindSafe { |
24 | fn check_canceled(&self) -> Cancelable<()> { | 24 | /// Aborts current query if there are pending changes. |
25 | /// | ||
26 | /// rust-analyzer needs to be able to answer semantic questions about the | ||
27 | /// code while the code is being modified. A common problem is that a | ||
28 | /// long-running query is being calculated when a new change arrives. | ||
29 | /// | ||
30 | /// We can't just apply the change immediately: this will cause the pending | ||
31 | /// query to see inconsistent state (it will observe an absence of | ||
32 | /// repeatable read). So what we do is we **cancel** all pending queries | ||
33 | /// before applying the change. | ||
34 | /// | ||
35 | /// We implement cancellation by panicking with a special value and catching | ||
36 | /// it on the API boundary. Salsa explicitly supports this use-case. | ||
37 | fn check_canceled(&self) { | ||
25 | if self.salsa_runtime().is_current_revision_canceled() { | 38 | if self.salsa_runtime().is_current_revision_canceled() { |
26 | Canceled::throw() | 39 | Canceled::throw() |
27 | } | 40 | } |
28 | Ok(()) | ||
29 | } | 41 | } |
30 | 42 | ||
31 | fn catch_canceled<F: FnOnce(&Self) -> T + panic::UnwindSafe, T>( | 43 | fn catch_canceled<F: FnOnce(&Self) -> T + panic::UnwindSafe, T>( |