@@ -7,6 +7,7 @@ use crate::cycle::{CycleHeadKind, CycleHeads, EMPTY_CYCLE_HEADS};
77use crate :: function:: { Configuration , IngredientImpl } ;
88use crate :: key:: DatabaseKeyIndex ;
99use crate :: loom:: sync:: atomic:: Ordering ;
10+ use crate :: plumbing:: MemoDropSender ;
1011use crate :: revision:: AtomicRevision ;
1112use crate :: table:: memo:: MemoTableWithTypesMut ;
1213use crate :: zalsa:: { MemoIngredientIndex , Zalsa } ;
@@ -16,27 +17,23 @@ use crate::{Event, EventKind, Id, Revision};
1617impl < C : Configuration > IngredientImpl < C > {
1718 /// Inserts the memo for the given key; (atomically) overwrites and returns any previously existing memo
1819 pub ( super ) fn insert_memo_into_table_for < ' db > (
19- & self ,
20+ & ' db self ,
2021 zalsa : & ' db Zalsa ,
2122 id : Id ,
2223 memo : NonNull < Memo < C :: Output < ' db > > > ,
2324 memo_ingredient_index : MemoIngredientIndex ,
24- ) -> Option < NonNull < Memo < C :: Output < ' db > > > > {
25+ ) {
2526 // SAFETY: The table stores 'static memos (to support `Any`), the memos are in fact valid
2627 // for `'db` though as we delay their dropping to the end of a revision.
2728 let static_memo = unsafe {
2829 transmute :: < NonNull < Memo < C :: Output < ' db > > > , NonNull < Memo < C :: Output < ' static > > > > ( memo)
2930 } ;
30- let old_static_memo = zalsa
31+ let old_memo = zalsa
3132 . memo_table_for ( id)
32- . insert ( memo_ingredient_index, static_memo) ?;
33- // SAFETY: The table stores 'static memos (to support `Any`), the memos are in fact valid
34- // for `'db` though as we delay their dropping to the end of a revision.
35- Some ( unsafe {
36- transmute :: < NonNull < Memo < C :: Output < ' static > > > , NonNull < Memo < C :: Output < ' db > > > > (
37- old_static_memo,
38- )
39- } )
33+ . insert ( memo_ingredient_index, static_memo) ;
34+ if let Some ( old_memo) = old_memo {
35+ self . delete . delay ( old_memo) ;
36+ }
4037 }
4138
4239 /// Loads the current memo for `key_index`. This does not hold any sort of
@@ -62,9 +59,11 @@ impl<C: Configuration> IngredientImpl<C> {
6259 pub ( super ) fn evict_value_from_memo_for (
6360 table : MemoTableWithTypesMut < ' _ > ,
6461 memo_ingredient_index : MemoIngredientIndex ,
62+ delayed : & MemoDropSender ,
6563 ) {
66- let map = |memo : & mut Memo < C :: Output < ' static > > | {
67- match & memo. revisions . origin {
64+ if let Some ( memo) = table. fetch_raw :: < Memo < C :: Output < ' static > > > ( memo_ingredient_index) {
65+ // SAFETY: The memo is live
66+ match unsafe { & memo. as_ref ( ) . revisions . origin } {
6867 QueryOrigin :: Assigned ( _)
6968 | QueryOrigin :: DerivedUntracked ( _)
7069 | QueryOrigin :: FixpointInitial => {
@@ -73,14 +72,9 @@ impl<C: Configuration> IngredientImpl<C> {
7372 // or those with untracked inputs
7473 // as their values cannot be reconstructed.
7574 }
76- QueryOrigin :: Derived ( _) => {
77- // Set the memo value to `None`.
78- memo. value = None ;
79- }
75+ QueryOrigin :: Derived ( _) => delayed. clear_value ( memo) ,
8076 }
81- } ;
82-
83- table. map_memo ( memo_ingredient_index, map)
77+ }
8478 }
8579}
8680
@@ -255,4 +249,7 @@ impl<V: Send + Sync + Any> crate::table::memo::Memo for Memo<V> {
255249 fn origin ( & self ) -> & QueryOrigin {
256250 & self . revisions . origin
257251 }
252+ fn clear_value ( & mut self ) {
253+ self . value = None ;
254+ }
258255}
0 commit comments