@@ -2,12 +2,13 @@ use std::sync::atomic::Ordering;
2
2
3
3
use crate :: accumulator:: accumulated_map:: InputAccumulatedValues ;
4
4
use crate :: cycle:: { CycleHeads , CycleRecoveryStrategy } ;
5
+ use crate :: function:: fetch:: LazyActiveQueryGuard ;
5
6
use crate :: function:: memo:: Memo ;
6
7
use crate :: function:: { Configuration , IngredientImpl } ;
7
8
use crate :: key:: DatabaseKeyIndex ;
8
9
use crate :: table:: sync:: ClaimResult ;
9
10
use crate :: zalsa:: { MemoIngredientIndex , Zalsa , ZalsaDatabase } ;
10
- use crate :: zalsa_local:: { ActiveQueryGuard , QueryEdge , QueryOrigin } ;
11
+ use crate :: zalsa_local:: { QueryEdge , QueryOrigin } ;
11
12
use crate :: { AsDynDatabase as _, Id , Revision } ;
12
13
13
14
/// Result of memo validation.
@@ -135,9 +136,9 @@ where
135
136
) ;
136
137
137
138
// Check if the inputs are still valid. We can just compare `changed_at`.
138
- let active_query = db . zalsa_local ( ) . push_query ( database_key_index, 0 ) ;
139
+ let mut active_query = LazyActiveQueryGuard :: new ( database_key_index) ;
139
140
if let VerifyResult :: Unchanged ( _, cycle_heads) =
140
- self . deep_verify_memo ( db, zalsa, old_memo, & active_query)
141
+ self . deep_verify_memo ( db, zalsa, old_memo, & mut active_query)
141
142
{
142
143
return Some ( if old_memo. revisions . changed_at > revision {
143
144
VerifyResult :: Changed
@@ -151,7 +152,11 @@ where
151
152
// backdated. In that case, although we will have computed a new memo,
152
153
// the value has not logically changed.
153
154
if old_memo. value . is_some ( ) {
154
- let memo = self . execute ( db, active_query, Some ( old_memo) ) ;
155
+ let memo = self . execute (
156
+ db,
157
+ active_query. into_inner ( db. zalsa_local ( ) ) ,
158
+ Some ( old_memo) ,
159
+ ) ;
155
160
let changed_at = memo. revisions . changed_at ;
156
161
157
162
return Some ( if changed_at > revision {
@@ -317,14 +322,14 @@ where
317
322
/// Takes an [`ActiveQueryGuard`] argument because this function recursively
318
323
/// walks dependencies of `old_memo` and may even execute them to see if their
319
324
/// outputs have changed.
320
- pub ( super ) fn deep_verify_memo (
325
+ pub ( super ) fn deep_verify_memo < ' db > (
321
326
& self ,
322
- db : & C :: DbView ,
327
+ db : & ' db C :: DbView ,
323
328
zalsa : & Zalsa ,
324
329
old_memo : & Memo < C :: Output < ' _ > > ,
325
- active_query : & ActiveQueryGuard < ' _ > ,
330
+ active_query : & mut LazyActiveQueryGuard < ' db > ,
326
331
) -> VerifyResult {
327
- let database_key_index = active_query. database_key_index ;
332
+ let database_key_index = active_query. database_key_index ( ) ;
328
333
329
334
tracing:: debug!(
330
335
"{database_key_index:?}: deep_verify_memo(old_memo = {old_memo:#?})" ,
@@ -333,9 +338,10 @@ where
333
338
334
339
let shallow_update = self . shallow_verify_memo ( zalsa, database_key_index, old_memo) ;
335
340
let shallow_update_possible = shallow_update. is_some ( ) ;
336
-
337
341
if let Some ( shallow_update) = shallow_update {
338
- if self . validate_may_be_provisional ( db, zalsa, database_key_index, old_memo) {
342
+ if self . validate_may_be_provisional ( db, zalsa, database_key_index, old_memo)
343
+ || self . validate_same_iteration ( db, database_key_index, old_memo)
344
+ {
339
345
self . update_shallow ( db, zalsa, database_key_index, old_memo, shallow_update) ;
340
346
341
347
return VerifyResult :: unchanged ( ) ;
@@ -365,11 +371,14 @@ where
365
371
}
366
372
QueryOrigin :: Derived ( edges) => {
367
373
let is_provisional = old_memo. may_be_provisional ( ) ;
374
+
368
375
// If the value is from the same revision but is still provisional, consider it changed
369
376
if shallow_update_possible && is_provisional {
370
377
return VerifyResult :: Changed ;
371
378
}
372
379
380
+ let _guard = active_query. guard ( db. zalsa_local ( ) ) ;
381
+
373
382
let mut cycle_heads = CycleHeads :: default ( ) ;
374
383
' cycle: loop {
375
384
// Fully tracked inputs? Iterate over the inputs and check them, one by one.
0 commit comments