diff options
author | Aleksey Kladov <[email protected]> | 2019-01-09 19:51:05 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-09 19:51:05 +0000 |
commit | cf20ecae9f9572d598c3655f1c5dae35a9f4c548 (patch) | |
tree | 505577efa309efb6307b12e06b4bc8aa5c543e58 /crates/ra_db | |
parent | c2b8aa1ce5e5398d981387079e86ff67a5b7e8c0 (diff) |
unwind on cancel
Diffstat (limited to 'crates/ra_db')
-rw-r--r-- | crates/ra_db/src/lib.rs | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index fb8ea2496..abe6430fb 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs | |||
@@ -5,6 +5,8 @@ mod input; | |||
5 | mod loc2id; | 5 | mod loc2id; |
6 | pub mod mock; | 6 | pub mod mock; |
7 | 7 | ||
8 | use std::panic; | ||
9 | |||
8 | use ra_syntax::{TextUnit, TextRange, SourceFile, TreePtr}; | 10 | use ra_syntax::{TextUnit, TextRange, SourceFile, TreePtr}; |
9 | 11 | ||
10 | pub use crate::{ | 12 | pub use crate::{ |
@@ -18,13 +20,21 @@ pub use crate::{ | |||
18 | loc2id::LocationIntener, | 20 | loc2id::LocationIntener, |
19 | }; | 21 | }; |
20 | 22 | ||
21 | pub trait BaseDatabase: salsa::Database { | 23 | pub trait BaseDatabase: salsa::Database + panic::RefUnwindSafe { |
22 | fn check_canceled(&self) -> Cancelable<()> { | 24 | fn check_canceled(&self) -> Cancelable<()> { |
23 | if self.salsa_runtime().is_current_revision_canceled() { | 25 | self.salsa_runtime() |
24 | Err(Canceled::new()) | 26 | .unwind_if_current_revision_is_canceled(); |
25 | } else { | 27 | Ok(()) |
26 | Ok(()) | 28 | } |
27 | } | 29 | |
30 | fn catch_canceled<F: FnOnce(&Self) -> T + panic::UnwindSafe, T>( | ||
31 | &self, | ||
32 | f: F, | ||
33 | ) -> Result<T, Canceled> { | ||
34 | panic::catch_unwind(|| f(self)).map_err(|err| match err.downcast::<salsa::Canceled>() { | ||
35 | Ok(_) => Canceled::new(), | ||
36 | Err(payload) => panic::resume_unwind(payload), | ||
37 | }) | ||
28 | } | 38 | } |
29 | } | 39 | } |
30 | 40 | ||