@@ -14,7 +14,7 @@ use crate::runtime::Running;
1414use crate :: sync:: atomic:: Ordering ;
1515use crate :: table:: memo:: MemoTableWithTypesMut ;
1616use crate :: zalsa:: { MemoIngredientIndex , Zalsa } ;
17- use crate :: zalsa_local:: { QueryOriginRef , QueryRevisions , ZalsaLocal } ;
17+ use crate :: zalsa_local:: { QueryOriginRef , QueryRevisions } ;
1818use crate :: { Event , EventKind , Id , Revision } ;
1919
2020impl < C : Configuration > IngredientImpl < C > {
@@ -132,50 +132,12 @@ impl<'db, C: Configuration> Memo<'db, C> {
132132 !self . revisions . verified_final . load ( Ordering :: Relaxed )
133133 }
134134
135- /// Invoked when `refresh_memo` is about to return a memo to the caller; if that memo is
136- /// provisional, and its cycle head is claimed by another thread, we need to wait for that
137- /// other thread to complete the fixpoint iteration, and then retry fetching our own memo.
138- ///
139- /// Return `true` if the caller should retry, `false` if the caller should go ahead and return
140- /// this memo to the caller.
141- #[ inline( always) ]
142- pub ( super ) fn provisional_retry (
143- & self ,
144- zalsa : & Zalsa ,
145- zalsa_local : & ZalsaLocal ,
146- database_key_index : DatabaseKeyIndex ,
147- retry_count : & mut u32 ,
148- ) -> bool {
149- if self . block_on_heads ( zalsa, zalsa_local) {
150- // If we get here, we are a provisional value of
151- // the cycle head (either initial value, or from a later iteration) and should be
152- // returned to caller to allow fixpoint iteration to proceed.
153- false
154- } else {
155- assert ! (
156- * retry_count <= 20000 ,
157- "Provisional memo retry limit exceeded for {database_key_index:?}; \
158- this usually indicates a bug in salsa's cycle caching/locking. \
159- (retried {retry_count} times)",
160- ) ;
161-
162- * retry_count += 1 ;
163-
164- // all our cycle heads are complete; re-fetch
165- // and we should get a non-provisional memo.
166- crate :: tracing:: debug!(
167- "Retrying provisional memo {database_key_index:?} after awaiting cycle heads."
168- ) ;
169- true
170- }
171- }
172-
173135 /// Blocks on all cycle heads (recursively) that this memo depends on.
174136 ///
175137 /// Returns `true` if awaiting all cycle heads results in a cycle. This means, they're all waiting
176138 /// for us to make progress.
177139 #[ inline( always) ]
178- pub ( super ) fn block_on_heads ( & self , zalsa : & Zalsa , zalsa_local : & ZalsaLocal ) -> bool {
140+ pub ( super ) fn block_on_heads ( & self , zalsa : & Zalsa ) -> bool {
179141 // IMPORTANT: If you make changes to this function, make sure to run `cycle_nested_deep` with
180142 // shuttle with at least 10k iterations.
181143
@@ -184,16 +146,12 @@ impl<'db, C: Configuration> Memo<'db, C> {
184146 return true ;
185147 }
186148
187- return block_on_heads_cold ( zalsa, zalsa_local , cycle_heads) ;
149+ return block_on_heads_cold ( zalsa, cycle_heads) ;
188150
189151 #[ inline( never) ]
190- fn block_on_heads_cold (
191- zalsa : & Zalsa ,
192- zalsa_local : & ZalsaLocal ,
193- heads : & CycleHeads ,
194- ) -> bool {
152+ fn block_on_heads_cold ( zalsa : & Zalsa , heads : & CycleHeads ) -> bool {
195153 let _entered = crate :: tracing:: debug_span!( "block_on_heads" ) . entered ( ) ;
196- let cycle_heads = TryClaimCycleHeadsIter :: new ( zalsa, zalsa_local , heads) ;
154+ let cycle_heads = TryClaimCycleHeadsIter :: new ( zalsa, heads) ;
197155 let mut all_cycles = true ;
198156
199157 for claim_result in cycle_heads {
@@ -447,6 +405,7 @@ mod persistence {
447405 }
448406}
449407
408+ #[ derive( Debug ) ]
450409pub ( super ) enum TryClaimHeadsResult < ' me > {
451410 /// Claiming the cycle head results in a cycle.
452411 Cycle {
@@ -465,19 +424,15 @@ pub(super) enum TryClaimHeadsResult<'me> {
465424/// Iterator to try claiming the transitive cycle heads of a memo.
466425pub ( super ) struct TryClaimCycleHeadsIter < ' a > {
467426 zalsa : & ' a Zalsa ,
468- zalsa_local : & ' a ZalsaLocal ,
427+
469428 cycle_heads : CycleHeadsIterator < ' a > ,
470429}
471430
472431impl < ' a > TryClaimCycleHeadsIter < ' a > {
473- pub ( super ) fn new (
474- zalsa : & ' a Zalsa ,
475- zalsa_local : & ' a ZalsaLocal ,
476- cycle_heads : & ' a CycleHeads ,
477- ) -> Self {
432+ pub ( super ) fn new ( zalsa : & ' a Zalsa , cycle_heads : & ' a CycleHeads ) -> Self {
478433 Self {
479434 zalsa,
480- zalsa_local ,
435+
481436 cycle_heads : cycle_heads. iter ( ) ,
482437 }
483438 }
@@ -488,31 +443,7 @@ impl<'me> Iterator for TryClaimCycleHeadsIter<'me> {
488443
489444 fn next ( & mut self ) -> Option < Self :: Item > {
490445 let head = self . cycle_heads . next ( ) ?;
491-
492446 let head_database_key = head. database_key_index ;
493- let head_iteration_count = head. iteration_count . load ( ) ;
494-
495- // The most common case is that the head is already in the query stack. So let's check that first.
496- // SAFETY: We do not access the query stack reentrantly.
497- if let Some ( current_iteration_count) = unsafe {
498- self . zalsa_local . with_query_stack_unchecked ( |stack| {
499- stack
500- . iter ( )
501- . rev ( )
502- . find ( |query| query. database_key_index == head_database_key)
503- . map ( |query| query. iteration_count ( ) )
504- } )
505- } {
506- crate :: tracing:: trace!(
507- "Waiting for {head_database_key:?} results in a cycle (because it is already in the query stack)"
508- ) ;
509- return Some ( TryClaimHeadsResult :: Cycle {
510- head_iteration_count,
511- memo_iteration_count : current_iteration_count,
512- verified_at : self . zalsa . current_revision ( ) ,
513- } ) ;
514- }
515-
516447 let head_key_index = head_database_key. key_index ( ) ;
517448 let ingredient = self
518449 . zalsa
@@ -543,7 +474,7 @@ impl<'me> Iterator for TryClaimCycleHeadsIter<'me> {
543474
544475 Some ( TryClaimHeadsResult :: Cycle {
545476 memo_iteration_count : current_iteration_count,
546- head_iteration_count,
477+ head_iteration_count : head . iteration_count . load ( ) ,
547478 verified_at,
548479 } )
549480 }
0 commit comments