11pub ( crate ) use maybe_changed_after:: VerifyResult ;
22use std:: any:: Any ;
3- use std:: fmt ;
3+ use std:: marker :: PhantomData ;
44use std:: ptr:: NonNull ;
55use std:: sync:: atomic:: Ordering ;
66use std:: sync:: OnceLock ;
7+ use std:: { fmt, mem} ;
78pub ( crate ) use sync:: SyncGuard ;
89
910use crate :: cycle:: {
1011 empty_cycle_heads, CycleHeads , CycleRecoveryAction , CycleRecoveryStrategy , ProvisionalStatus ,
1112} ;
1213use crate :: database:: RawDatabase ;
13- use crate :: function:: delete:: DeletedEntries ;
1414use crate :: function:: sync:: { ClaimResult , SyncTable } ;
1515use crate :: ingredient:: { Ingredient , WaitForResult } ;
1616use crate :: key:: DatabaseKeyIndex ;
1717use crate :: plumbing:: MemoIngredientMap ;
1818use crate :: salsa_struct:: SalsaStructInDb ;
1919use crate :: sync:: Arc ;
20- use crate :: table:: memo:: MemoTableTypes ;
20+ use crate :: table:: memo:: { DeletedEntries , MemoTableTypes } ;
2121use crate :: table:: Table ;
2222use crate :: views:: DatabaseDownCaster ;
2323use crate :: zalsa:: { IngredientIndex , MemoIngredientIndex , Zalsa } ;
@@ -27,7 +27,6 @@ use crate::{Id, Revision};
2727#[ cfg( feature = "accumulator" ) ]
2828mod accumulated;
2929mod backdate;
30- mod delete;
3130mod diff_outputs;
3231mod execute;
3332mod fetch;
@@ -146,7 +145,8 @@ pub struct IngredientImpl<C: Configuration> {
146145 /// current revision: you would be right, but we are being defensive, because
147146 /// we don't know that we can trust the database to give us the same runtime
148147 /// everytime and so forth.
149- deleted_entries : DeletedEntries < C > ,
148+ delete : DeletedEntries ,
149+ config : PhantomData < fn ( C ) -> C > ,
150150}
151151
152152impl < C > IngredientImpl < C >
@@ -161,10 +161,11 @@ where
161161 Self {
162162 index,
163163 memo_ingredient_indices,
164- lru : lru:: Lru :: new ( lru) ,
165- deleted_entries : Default :: default ( ) ,
166164 view_caster : OnceLock :: new ( ) ,
165+ lru : lru:: Lru :: new ( lru) ,
166+ delete : DeletedEntries :: default ( ) ,
167167 sync_table : SyncTable :: new ( index) ,
168+ config : PhantomData ,
168169 }
169170 }
170171
@@ -221,16 +222,7 @@ where
221222 // FIXME: Use `Box::into_non_null` once stable
222223 let memo = NonNull :: from ( Box :: leak ( Box :: new ( memo) ) ) ;
223224
224- if let Some ( old_value) =
225- self . insert_memo_into_table_for ( zalsa, id, memo, memo_ingredient_index)
226- {
227- // In case there is a reference to the old memo out there, we have to store it
228- // in the deleted entries. This will get cleared when a new revision starts.
229- //
230- // SAFETY: Once the revision starts, there will be no outstanding borrows to the
231- // memo contents, and so it will be safe to free.
232- unsafe { self . deleted_entries . push ( old_value) } ;
233- }
225+ self . insert_memo_into_table_for ( zalsa, id, memo, memo_ingredient_index) ;
234226 // SAFETY: memo has been inserted into the table
235227 unsafe { self . extend_memo_lifetime ( memo. as_ref ( ) ) }
236228 }
@@ -343,16 +335,19 @@ where
343335 true
344336 }
345337
346- fn reset_for_new_revision ( & mut self , table : & mut Table ) {
338+ fn reset_for_new_revision (
339+ & mut self ,
340+ table : & mut Table ,
341+ new_buffer : DeletedEntries ,
342+ ) -> DeletedEntries {
347343 self . lru . for_each_evicted ( |evict| {
348344 let ingredient_index = table. ingredient_index ( evict) ;
349345 Self :: evict_value_from_memo_for (
350346 table. memos_mut ( evict) ,
351347 self . memo_ingredient_indices . get ( ingredient_index) ,
352348 )
353349 } ) ;
354-
355- self . deleted_entries . clear ( ) ;
350+ mem:: replace ( & mut self . delete , new_buffer)
356351 }
357352
358353 fn debug_name ( & self ) -> & ' static str {
0 commit comments