Skip to content

Commit e8258d6

Browse files
committed
Review feedback
1 parent 1f6b1b2 commit e8258d6

File tree

2 files changed

+36
-29
lines changed

2 files changed

+36
-29
lines changed

src/function/fetch.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ where
171171
ClaimResult::Claimed(guard) => guard,
172172
};
173173

174-
let mut active_query = LazyActiveQuery::new(database_key_index, db.zalsa_local());
174+
let mut active_query = LazyActiveQueryGuard::new(database_key_index);
175175

176176
// Now that we've claimed the item, check again to see if there's a "hot" value.
177177
let opt_old_memo = self.get_memo_from_table_for(zalsa, id, memo_ingredient_index);
@@ -189,23 +189,21 @@ where
189189
}
190190
}
191191

192-
let memo = self.execute(db, active_query.into_inner(), opt_old_memo);
192+
let memo = self.execute(db, active_query.into_inner(db.zalsa_local()), opt_old_memo);
193193

194194
Some(memo)
195195
}
196196
}
197197

198-
pub(super) struct LazyActiveQuery<'me> {
198+
pub(super) struct LazyActiveQueryGuard<'me> {
199199
guard: Option<ActiveQueryGuard<'me>>,
200-
zalsa_local: &'me ZalsaLocal,
201200
database_key_index: DatabaseKeyIndex,
202201
}
203202

204-
impl<'me> LazyActiveQuery<'me> {
205-
pub(super) fn new(database_key_index: DatabaseKeyIndex, zalsa_local: &'me ZalsaLocal) -> Self {
203+
impl<'me> LazyActiveQueryGuard<'me> {
204+
pub(super) fn new(database_key_index: DatabaseKeyIndex) -> Self {
206205
Self {
207206
guard: None,
208-
zalsa_local,
209207
database_key_index,
210208
}
211209
}
@@ -214,13 +212,13 @@ impl<'me> LazyActiveQuery<'me> {
214212
self.database_key_index
215213
}
216214

217-
pub(super) fn get(&mut self) -> &ActiveQueryGuard<'me> {
215+
pub(super) fn guard(&mut self, zalsa_local: &'me ZalsaLocal) -> &ActiveQueryGuard<'me> {
218216
self.guard
219-
.get_or_insert_with(|| self.zalsa_local.push_query(self.database_key_index, 0))
217+
.get_or_insert_with(|| zalsa_local.push_query(self.database_key_index, 0))
220218
}
221219

222-
pub(super) fn into_inner(self) -> ActiveQueryGuard<'me> {
220+
pub(super) fn into_inner(self, zalsa_local: &'me ZalsaLocal) -> ActiveQueryGuard<'me> {
223221
self.guard
224-
.unwrap_or_else(|| self.zalsa_local.push_query(self.database_key_index, 0))
222+
.unwrap_or_else(|| zalsa_local.push_query(self.database_key_index, 0))
225223
}
226224
}

src/function/maybe_changed_after.rs

+27-18
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::sync::atomic::Ordering;
22

33
use crate::accumulator::accumulated_map::InputAccumulatedValues;
44
use crate::cycle::{CycleHeads, CycleRecoveryStrategy};
5-
use crate::function::fetch::LazyActiveQuery;
5+
use crate::function::fetch::LazyActiveQueryGuard;
66
use crate::function::memo::Memo;
77
use crate::function::{Configuration, IngredientImpl};
88
use crate::key::DatabaseKeyIndex;
@@ -136,7 +136,7 @@ where
136136
);
137137

138138
// Check if the inputs are still valid. We can just compare `changed_at`.
139-
let mut active_query = LazyActiveQuery::new(database_key_index, db.zalsa_local());
139+
let mut active_query = LazyActiveQueryGuard::new(database_key_index);
140140
if let VerifyResult::Unchanged(_, cycle_heads) =
141141
self.deep_verify_memo(db, zalsa, old_memo, &mut active_query)
142142
{
@@ -152,7 +152,11 @@ where
152152
// backdated. In that case, although we will have computed a new memo,
153153
// the value has not logically changed.
154154
if old_memo.value.is_some() {
155-
let memo = self.execute(db, active_query.into_inner(), Some(old_memo));
155+
let memo = self.execute(
156+
db,
157+
active_query.into_inner(db.zalsa_local()),
158+
Some(old_memo),
159+
);
156160
let changed_at = memo.revisions.changed_at;
157161

158162
return Some(if changed_at > revision {
@@ -315,12 +319,12 @@ where
315319
/// Takes an [`ActiveQueryGuard`] argument because this function recursively
316320
/// walks dependencies of `old_memo` and may even execute them to see if their
317321
/// outputs have changed.
318-
pub(super) fn deep_verify_memo(
322+
pub(super) fn deep_verify_memo<'db>(
319323
&self,
320-
db: &C::DbView,
324+
db: &'db C::DbView,
321325
zalsa: &Zalsa,
322326
old_memo: &Memo<C::Output<'_>>,
323-
active_query: &mut LazyActiveQuery<'_>,
327+
active_query: &mut LazyActiveQueryGuard<'db>,
324328
) -> VerifyResult {
325329
let database_key_index = active_query.database_key_index();
326330

@@ -329,22 +333,18 @@ where
329333
old_memo = old_memo.tracing_debug()
330334
);
331335

336+
let mut is_shallow_update_possible = false;
332337
if let Some(shallow_update) = self.shallow_verify_memo(zalsa, database_key_index, old_memo)
333338
{
339+
is_shallow_update_possible = true;
340+
334341
if self.validate_may_be_provisional(db, zalsa, database_key_index, old_memo)
335342
|| self.validate_same_iteration(db, database_key_index, old_memo)
336343
{
337344
self.update_shallow(db, zalsa, database_key_index, old_memo, shallow_update);
338345

339346
return VerifyResult::unchanged();
340347
}
341-
342-
if let QueryOrigin::Derived(_) = &old_memo.revisions.origin {
343-
// If the value is from the same revision but is still provisional, consider it changed
344-
if old_memo.may_be_provisional() {
345-
return VerifyResult::Changed;
346-
}
347-
}
348348
}
349349

350350
match &old_memo.revisions.origin {
@@ -369,7 +369,14 @@ where
369369
VerifyResult::Changed
370370
}
371371
QueryOrigin::Derived(edges) => {
372-
let _guard = active_query.get();
372+
let is_provisional = old_memo.may_be_provisional();
373+
374+
// If the value is from the same revision but is still provisional, consider it changed
375+
if is_shallow_update_possible && old_memo.may_be_provisional() {
376+
return VerifyResult::Changed;
377+
}
378+
379+
let _guard = active_query.guard(db.zalsa_local());
373380

374381
let mut cycle_heads = CycleHeads::default();
375382
'cycle: loop {
@@ -456,10 +463,12 @@ where
456463
inputs,
457464
);
458465

459-
old_memo
460-
.revisions
461-
.verified_final
462-
.store(true, Ordering::Relaxed);
466+
if is_provisional {
467+
old_memo
468+
.revisions
469+
.verified_final
470+
.store(true, Ordering::Relaxed);
471+
}
463472

464473
if in_heads {
465474
continue 'cycle;

0 commit comments

Comments
 (0)