@@ -2,7 +2,7 @@ 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:: LazyActiveQuery ;
5
+ use crate :: function:: fetch:: LazyActiveQueryGuard ;
6
6
use crate :: function:: memo:: Memo ;
7
7
use crate :: function:: { Configuration , IngredientImpl } ;
8
8
use crate :: key:: DatabaseKeyIndex ;
@@ -136,7 +136,7 @@ where
136
136
) ;
137
137
138
138
// 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) ;
140
140
if let VerifyResult :: Unchanged ( _, cycle_heads) =
141
141
self . deep_verify_memo ( db, zalsa, old_memo, & mut active_query)
142
142
{
@@ -152,7 +152,11 @@ where
152
152
// backdated. In that case, although we will have computed a new memo,
153
153
// the value has not logically changed.
154
154
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
+ ) ;
156
160
let changed_at = memo. revisions . changed_at ;
157
161
158
162
return Some ( if changed_at > revision {
@@ -315,12 +319,12 @@ where
315
319
/// Takes an [`ActiveQueryGuard`] argument because this function recursively
316
320
/// walks dependencies of `old_memo` and may even execute them to see if their
317
321
/// outputs have changed.
318
- pub ( super ) fn deep_verify_memo (
322
+ pub ( super ) fn deep_verify_memo < ' db > (
319
323
& self ,
320
- db : & C :: DbView ,
324
+ db : & ' db C :: DbView ,
321
325
zalsa : & Zalsa ,
322
326
old_memo : & Memo < C :: Output < ' _ > > ,
323
- active_query : & mut LazyActiveQuery < ' _ > ,
327
+ active_query : & mut LazyActiveQueryGuard < ' db > ,
324
328
) -> VerifyResult {
325
329
let database_key_index = active_query. database_key_index ( ) ;
326
330
@@ -329,22 +333,18 @@ where
329
333
old_memo = old_memo. tracing_debug( )
330
334
) ;
331
335
336
+ let mut is_shallow_update_possible = false ;
332
337
if let Some ( shallow_update) = self . shallow_verify_memo ( zalsa, database_key_index, old_memo)
333
338
{
339
+ is_shallow_update_possible = true ;
340
+
334
341
if self . validate_may_be_provisional ( db, zalsa, database_key_index, old_memo)
335
342
|| self . validate_same_iteration ( db, database_key_index, old_memo)
336
343
{
337
344
self . update_shallow ( db, zalsa, database_key_index, old_memo, shallow_update) ;
338
345
339
346
return VerifyResult :: unchanged ( ) ;
340
347
}
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
- }
348
348
}
349
349
350
350
match & old_memo. revisions . origin {
@@ -369,7 +369,14 @@ where
369
369
VerifyResult :: Changed
370
370
}
371
371
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 ( ) ) ;
373
380
374
381
let mut cycle_heads = CycleHeads :: default ( ) ;
375
382
' cycle: loop {
@@ -456,10 +463,12 @@ where
456
463
inputs,
457
464
) ;
458
465
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
+ }
463
472
464
473
if in_heads {
465
474
continue ' cycle;
0 commit comments