From 64455ad701c8bce6e35793042f5e2ec177e12f7e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 10 Jan 2019 12:20:32 +0300 Subject: use unwinding for cancelation --- crates/ra_db/src/cancellation.rs | 4 ++++ crates/ra_db/src/lib.rs | 9 +++++---- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'crates/ra_db') diff --git a/crates/ra_db/src/cancellation.rs b/crates/ra_db/src/cancellation.rs index 8d38eebfb..f7077b992 100644 --- a/crates/ra_db/src/cancellation.rs +++ b/crates/ra_db/src/cancellation.rs @@ -27,6 +27,10 @@ impl Canceled { pub(crate) fn new() -> Canceled { Canceled { _private: () } } + + pub fn throw() -> ! { + std::panic::resume_unwind(Box::new(Canceled::new())) + } } impl std::fmt::Display for Canceled { diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index abe6430fb..00d2d5ae9 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs @@ -20,10 +20,10 @@ pub use crate::{ loc2id::LocationIntener, }; -pub trait BaseDatabase: salsa::Database + panic::RefUnwindSafe { +pub trait BaseDatabase: salsa::Database { fn check_canceled(&self) -> Cancelable<()> { self.salsa_runtime() - .unwind_if_current_revision_is_canceled(); + .if_current_revision_is_canceled(Canceled::throw); Ok(()) } @@ -31,8 +31,9 @@ pub trait BaseDatabase: salsa::Database + panic::RefUnwindSafe { &self, f: F, ) -> Result { - panic::catch_unwind(|| f(self)).map_err(|err| match err.downcast::() { - Ok(_) => Canceled::new(), + let me = panic::AssertUnwindSafe(self); + panic::catch_unwind(|| f(me.0)).map_err(|err| match err.downcast::() { + Ok(canceled) => *canceled, Err(payload) => panic::resume_unwind(payload), }) } -- cgit v1.2.3