Skip to content

Commit d758691

Browse files
authored
Resolve unwind safety fixme (#761)
1 parent a86db59 commit d758691

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/runtime.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::{
22
mem,
3+
panic::AssertUnwindSafe,
34
sync::atomic::{AtomicBool, Ordering},
45
thread::ThreadId,
56
};
@@ -189,14 +190,19 @@ impl Runtime {
189190
})
190191
});
191192

193+
// `DependencyGraph::block_on` does not panic, so we cannot enter an inconsistent state.
194+
let dg = AssertUnwindSafe(dg);
195+
// `DependencyGraph::block_on` does not panic, nor does it read from query_mutex_guard, so
196+
// we cannot enter an inconsistent state for this parameter.
197+
let query_mutex_guard = AssertUnwindSafe(query_mutex_guard);
192198
let result = local_state.with_query_stack(|stack| {
193199
let (new_stack, result) = DependencyGraph::block_on(
194-
dg,
200+
{ dg }.0,
195201
thread_id,
196202
database_key,
197203
other_id,
198204
mem::take(stack),
199-
query_mutex_guard,
205+
{ query_mutex_guard }.0,
200206
);
201207
*stack = new_stack;
202208
result

src/zalsa_local.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::Cancelled;
1919
use crate::Id;
2020
use crate::Revision;
2121
use std::cell::RefCell;
22+
use std::panic::UnwindSafe;
2223

2324
/// State that is specific to a single execution thread.
2425
///
@@ -102,8 +103,7 @@ impl ZalsaLocal {
102103
/// Executes a closure within the context of the current active query stacks.
103104
pub(crate) fn with_query_stack<R>(
104105
&self,
105-
// FIXME: We ought to require `UnwindSafe` here to prove that `ZalsaLocal: RefUnwindSafe`
106-
c: impl FnOnce(&mut Vec<ActiveQuery>) -> R, /*+ UnwindSafe */
106+
c: impl UnwindSafe + FnOnce(&mut Vec<ActiveQuery>) -> R,
107107
) -> R {
108108
c(self.query_stack.borrow_mut().as_mut())
109109
}
@@ -285,9 +285,10 @@ impl ZalsaLocal {
285285
}
286286
}
287287

288-
// Okay to implement as `ZalsaLocal`` is !Sync and FIXME: See `Self::with_query_stack`
288+
// Okay to implement as `ZalsaLocal`` is !Sync
289289
// - `most_recent_pages` can't observe broken states as we cannot panic such that we enter an
290290
// inconsistent state
291+
// - neither can `query_stack` as we require the closures accessing it to be `UnwindSafe`
291292
impl std::panic::RefUnwindSafe for ZalsaLocal {}
292293

293294
/// Summarizes "all the inputs that a query used"

0 commit comments

Comments
 (0)