Skip to content

Commit e0a056b

Browse files
committed
Address reviews
1 parent a5e1704 commit e0a056b

File tree

8 files changed

+37
-42
lines changed

8 files changed

+37
-42
lines changed

src/cancelled.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::panic::{self, UnwindSafe};
1111
#[non_exhaustive]
1212
pub enum Cancelled {
1313
/// The query was operating but the local database execution has been cancelled.
14-
Cancelled,
14+
Local,
1515

1616
/// The query was operating on revision R, but there is a pending write to move to revision R+1.
1717
PendingWrite,
@@ -46,7 +46,7 @@ impl Cancelled {
4646
impl std::fmt::Display for Cancelled {
4747
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4848
let why = match self {
49-
Cancelled::Cancelled => "canellation request",
49+
Cancelled::Local => "local canellation request",
5050
Cancelled::PendingWrite => "pending write",
5151
Cancelled::PropagatedPanic => "propagated panic",
5252
};

src/database.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub trait Database: Send + ZalsaDatabase + AsDynDatabase {
6868
let _ = self.zalsa_mut();
6969
}
7070

71-
/// Retrives a [`CancellationToken`] for the current database.
71+
/// Retrieves a [`CancellationToken`] for the current database handle.
7272
fn cancellation_token(&self) -> CancellationToken {
7373
self.zalsa_local().cancellation_token()
7474
}

src/function/fetch.rs

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -105,39 +105,37 @@ where
105105
) -> Option<&'db Memo<'db, C>> {
106106
let database_key_index = self.database_key_index(id);
107107
// Try to claim this query: if someone else has claimed it already, go back and start again.
108-
let claim_guard = loop {
109-
match self
110-
.sync_table
111-
.try_claim(zalsa, zalsa_local, id, Reentrancy::Allow)
112-
{
113-
ClaimResult::Claimed(guard) => break guard,
114-
ClaimResult::Running(blocked_on) => {
115-
if !blocked_on.block_on(zalsa) {
116-
continue;
117-
}
108+
let claim_guard = match self
109+
.sync_table
110+
.try_claim(zalsa, zalsa_local, id, Reentrancy::Allow)
111+
{
112+
ClaimResult::Claimed(guard) => guard,
113+
ClaimResult::Running(blocked_on) => {
114+
if !blocked_on.block_on(zalsa) {
115+
return None;
116+
}
118117

119-
if C::CYCLE_STRATEGY == CycleRecoveryStrategy::FallbackImmediate {
120-
let memo = self.get_memo_from_table_for(zalsa, id, memo_ingredient_index);
118+
if C::CYCLE_STRATEGY == CycleRecoveryStrategy::FallbackImmediate {
119+
let memo = self.get_memo_from_table_for(zalsa, id, memo_ingredient_index);
121120

122-
if let Some(memo) = memo {
123-
if memo.value.is_some() {
124-
memo.block_on_heads(zalsa);
125-
}
121+
if let Some(memo) = memo {
122+
if memo.value.is_some() {
123+
memo.block_on_heads(zalsa);
126124
}
127125
}
128-
129-
return None;
130-
}
131-
ClaimResult::Cycle { .. } => {
132-
return Some(self.fetch_cold_cycle(
133-
zalsa,
134-
zalsa_local,
135-
db,
136-
id,
137-
database_key_index,
138-
memo_ingredient_index,
139-
));
140126
}
127+
128+
return None;
129+
}
130+
ClaimResult::Cycle { .. } => {
131+
return Some(self.fetch_cold_cycle(
132+
zalsa,
133+
zalsa_local,
134+
db,
135+
id,
136+
database_key_index,
137+
memo_ingredient_index,
138+
));
141139
}
142140
};
143141

src/function/maybe_changed_after.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,15 @@ where
141141
) -> Option<VerifyResult> {
142142
let database_key_index = self.database_key_index(key_index);
143143

144-
let claim_guard = loop {
144+
let claim_guard =
145145
match self
146146
.sync_table
147147
.try_claim(zalsa, zalsa_local, key_index, Reentrancy::Deny)
148148
{
149-
ClaimResult::Claimed(guard) => break guard,
149+
ClaimResult::Claimed(guard) => guard,
150150
ClaimResult::Running(blocked_on) => {
151-
if blocked_on.block_on(zalsa) {
152-
return None;
153-
}
151+
_ = blocked_on.block_on(zalsa);
152+
return None;
154153
}
155154
ClaimResult::Cycle { .. } => {
156155
return Some(self.maybe_changed_after_cold_cycle(
@@ -159,8 +158,7 @@ where
159158
cycle_heads,
160159
))
161160
}
162-
}
163-
};
161+
};
164162
// Load the current memo, if any.
165163
let Some(old_memo) = self.get_memo_from_table_for(zalsa, key_index, memo_ingredient_index)
166164
else {

src/runtime.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ impl Running<'_> {
125125
///
126126
/// Returns `true` if the computation was successful, and `false` if the other thread was cancelled.
127127
#[must_use]
128-
#[cold]
129128
pub(crate) fn block_on(self, zalsa: &Zalsa) -> bool {
130129
let BlockedOnInner {
131130
dg,

src/zalsa_local.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ impl ZalsaLocal {
448448

449449
#[cold]
450450
pub(crate) fn unwind_cancelled(&self) {
451-
Cancelled::Cancelled.throw();
451+
Cancelled::Local.throw();
452452
}
453453
}
454454

tests/cancellation_token.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn cancellation_token() {
4444
a(&db, input)
4545
})
4646
});
47-
assert!(matches!(res, Err(Cancelled::Cancelled)), "{res:?}");
47+
assert!(matches!(res, Err(Cancelled::Local)), "{res:?}");
4848
drop(res);
4949
db.assert_logs(expect![[r#"
5050
[

tests/parallel/cancellation_token_recomputes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ fn execute() {
3838
db_signaler.signal(3);
3939
let (r1, r2) = (t1.join(), t2.join());
4040
let r1 = *r1.unwrap_err().downcast::<salsa::Cancelled>().unwrap();
41-
assert!(matches!(r1, Cancelled::Cancelled), "{r1:?}");
41+
assert!(matches!(r1, Cancelled::Local), "{r1:?}");
4242
assert_eq!(r2.unwrap(), 1);
4343
}

0 commit comments

Comments
 (0)