From cf20ecae9f9572d598c3655f1c5dae35a9f4c548 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 9 Jan 2019 22:51:05 +0300 Subject: [PATCH] unwind on cancel --- Cargo.lock | 8 +++----- Cargo.toml | 1 + crates/ra_db/src/lib.rs | 22 ++++++++++++++++------ 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b3172dc2837..d2d37f0c7a6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -661,7 +661,7 @@ dependencies = [ "ra_syntax 0.1.0", "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "salsa 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "salsa 0.9.1", "test_utils 0.1.0", ] @@ -680,7 +680,7 @@ dependencies = [ "ra_syntax 0.1.0", "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "salsa 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "salsa 0.9.1", "test_utils 0.1.0", ] @@ -700,7 +700,7 @@ dependencies = [ "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "salsa 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "salsa 0.9.1", "test_utils 0.1.0", "unicase 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1030,7 +1030,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "salsa" version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1587,7 +1586,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rusty-fork 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9591f190d2852720b679c21f66ad929f9f1d7bb09d1193c26167586029d8489c" "checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7" "checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9" -"checksum salsa 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "442ef4acdb48c0e24ddaf4f3b62555af2d1da7047f2f26acd54ae73010aa0c02" "checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" diff --git a/Cargo.toml b/Cargo.toml index 1cf83dfa896..57896078e3a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,4 @@ debug = true [patch.'crates-io'] cargo_metadata = { git = "https://github.com/oli-obk/cargo_metadata.git", rev="f73e27b24e" } +salsa = { path = "/home/matklad/projects/salsa" } diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index fb8ea249654..abe6430fb04 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs @@ -5,6 +5,8 @@ mod input; mod loc2id; pub mod mock; +use std::panic; + use ra_syntax::{TextUnit, TextRange, SourceFile, TreePtr}; pub use crate::{ @@ -18,13 +20,21 @@ pub use crate::{ loc2id::LocationIntener, }; -pub trait BaseDatabase: salsa::Database { +pub trait BaseDatabase: salsa::Database + panic::RefUnwindSafe { fn check_canceled(&self) -> Cancelable<()> { - if self.salsa_runtime().is_current_revision_canceled() { - Err(Canceled::new()) - } else { - Ok(()) - } + self.salsa_runtime() + .unwind_if_current_revision_is_canceled(); + Ok(()) + } + + fn catch_canceled T + panic::UnwindSafe, T>( + &self, + f: F, + ) -> Result { + panic::catch_unwind(|| f(self)).map_err(|err| match err.downcast::() { + Ok(_) => Canceled::new(), + Err(payload) => panic::resume_unwind(payload), + }) } }