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, CycleHeadKeys , CycleHeads , CycleRecoveryAction , CycleRecoveryStrategy ,
1112 ProvisionalStatus ,
1213} ;
1314use crate :: database:: RawDatabase ;
14- use crate :: function:: delete:: DeletedEntries ;
1515use crate :: function:: sync:: { ClaimResult , SyncTable } ;
1616use crate :: ingredient:: { Ingredient , WaitForResult } ;
1717use crate :: key:: DatabaseKeyIndex ;
1818use crate :: plumbing:: MemoIngredientMap ;
1919use crate :: salsa_struct:: SalsaStructInDb ;
2020use crate :: sync:: Arc ;
21- use crate :: table:: memo:: MemoTableTypes ;
21+ use crate :: table:: memo:: { DeletedEntries , MemoTableTypes } ;
2222use crate :: table:: Table ;
2323use crate :: views:: DatabaseDownCaster ;
2424use crate :: zalsa:: { IngredientIndex , MemoIngredientIndex , Zalsa } ;
@@ -28,7 +28,6 @@ use crate::{Id, Revision};
2828#[ cfg( feature = "accumulator" ) ]
2929mod accumulated;
3030mod backdate;
31- mod delete;
3231mod diff_outputs;
3332mod execute;
3433mod fetch;
@@ -147,7 +146,8 @@ pub struct IngredientImpl<C: Configuration> {
147146 /// current revision: you would be right, but we are being defensive, because
148147 /// we don't know that we can trust the database to give us the same runtime
149148 /// everytime and so forth.
150- deleted_entries : DeletedEntries < C > ,
149+ delete : DeletedEntries ,
150+ config : PhantomData < fn ( C ) -> C > ,
151151}
152152
153153impl < C > IngredientImpl < C >
@@ -162,10 +162,11 @@ where
162162 Self {
163163 index,
164164 memo_ingredient_indices,
165- lru : lru:: Lru :: new ( lru) ,
166- deleted_entries : Default :: default ( ) ,
167165 view_caster : OnceLock :: new ( ) ,
166+ lru : lru:: Lru :: new ( lru) ,
167+ delete : DeletedEntries :: default ( ) ,
168168 sync_table : SyncTable :: new ( index) ,
169+ config : PhantomData ,
169170 }
170171 }
171172
@@ -222,16 +223,7 @@ where
222223 // FIXME: Use `Box::into_non_null` once stable
223224 let memo = NonNull :: from ( Box :: leak ( Box :: new ( memo) ) ) ;
224225
225- if let Some ( old_value) =
226- self . insert_memo_into_table_for ( zalsa, id, memo, memo_ingredient_index)
227- {
228- // In case there is a reference to the old memo out there, we have to store it
229- // in the deleted entries. This will get cleared when a new revision starts.
230- //
231- // SAFETY: Once the revision starts, there will be no outstanding borrows to the
232- // memo contents, and so it will be safe to free.
233- unsafe { self . deleted_entries . push ( old_value) } ;
234- }
226+ self . insert_memo_into_table_for ( zalsa, id, memo, memo_ingredient_index) ;
235227 // SAFETY: memo has been inserted into the table
236228 unsafe { self . extend_memo_lifetime ( memo. as_ref ( ) ) }
237229 }
@@ -344,16 +336,19 @@ where
344336 true
345337 }
346338
347- fn reset_for_new_revision ( & mut self , table : & mut Table ) {
339+ fn reset_for_new_revision (
340+ & mut self ,
341+ table : & mut Table ,
342+ new_buffer : DeletedEntries ,
343+ ) -> DeletedEntries {
348344 self . lru . for_each_evicted ( |evict| {
349345 let ingredient_index = table. ingredient_index ( evict) ;
350346 Self :: evict_value_from_memo_for (
351347 table. memos_mut ( evict) ,
352348 self . memo_ingredient_indices . get ( ingredient_index) ,
353349 )
354350 } ) ;
355-
356- self . deleted_entries . clear ( ) ;
351+ mem:: replace ( & mut self . delete , new_buffer)
357352 }
358353
359354 fn debug_name ( & self ) -> & ' static str {
0 commit comments