mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 15:14:32 +00:00
unwind on cancel
This commit is contained in:
parent
c2b8aa1ce5
commit
cf20ecae9f
3 changed files with 20 additions and 11 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -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"
|
||||
|
|
|
@ -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" }
|
||||
|
|
|
@ -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<F: FnOnce(&Self) -> T + panic::UnwindSafe, T>(
|
||||
&self,
|
||||
f: F,
|
||||
) -> Result<T, Canceled> {
|
||||
panic::catch_unwind(|| f(self)).map_err(|err| match err.downcast::<salsa::Canceled>() {
|
||||
Ok(_) => Canceled::new(),
|
||||
Err(payload) => panic::resume_unwind(payload),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue