implement RefUnwindSafe

This commit is contained in:
Aleksey Kladov 2019-01-10 13:04:04 +03:00
parent 64455ad701
commit f72c031eb9
4 changed files with 16 additions and 6 deletions

2
Cargo.lock generated
View file

@ -1024,7 +1024,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "salsa"
version = "0.9.1"
source = "git+https://github.com/matklad/salsa?branch=panic-hooks#add15d83eaa865571cd33e60b2eb611a366ca3ff"
source = "git+https://github.com/matklad/salsa?branch=panic-hooks#a17757bbaaadeed4839366745b848d66ac991cd0"
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)",

View file

@ -20,7 +20,7 @@ pub use crate::{
loc2id::LocationIntener,
};
pub trait BaseDatabase: salsa::Database {
pub trait BaseDatabase: salsa::Database + panic::RefUnwindSafe {
fn check_canceled(&self) -> Cancelable<()> {
self.salsa_runtime()
.if_current_revision_is_canceled(Canceled::throw);
@ -31,8 +31,7 @@ pub trait BaseDatabase: salsa::Database {
&self,
f: F,
) -> Result<T, Canceled> {
let me = panic::AssertUnwindSafe(self);
panic::catch_unwind(|| f(me.0)).map_err(|err| match err.downcast::<Canceled>() {
panic::catch_unwind(|| f(self)).map_err(|err| match err.downcast::<Canceled>() {
Ok(canceled) => *canceled,
Err(payload) => panic::resume_unwind(payload),
})

View file

@ -1,4 +1,4 @@
use std::hash::Hash;
use std::{panic, hash::Hash};
use parking_lot::Mutex;
use rustc_hash::FxHashMap;
@ -70,6 +70,15 @@ where
map: Mutex<Loc2IdMap<LOC, ID>>,
}
impl<LOC, ID> panic::RefUnwindSafe for LocationIntener<LOC, ID>
where
ID: ArenaId + Clone,
LOC: Clone + Eq + Hash,
ID: panic::RefUnwindSafe,
LOC: panic::RefUnwindSafe,
{
}
impl<LOC, ID> Default for LocationIntener<LOC, ID>
where
ID: ArenaId + Clone,

View file

@ -1,4 +1,4 @@
use std::sync::Arc;
use std::{sync::Arc, panic};
use parking_lot::Mutex;
use salsa::{self, Database};
@ -18,6 +18,8 @@ pub(crate) struct MockDatabase {
file_counter: u32,
}
impl panic::RefUnwindSafe for MockDatabase {}
impl MockDatabase {
pub(crate) fn with_files(fixture: &str) -> (MockDatabase, SourceRoot) {
let (db, source_root, position) = MockDatabase::from_fixture(fixture);