@@ -7,6 +7,7 @@ use crate::cycle::{CycleHeadKind, CycleHeads, EMPTY_CYCLE_HEADS};
7
7
use crate :: function:: { Configuration , IngredientImpl } ;
8
8
use crate :: key:: DatabaseKeyIndex ;
9
9
use crate :: loom:: sync:: atomic:: Ordering ;
10
+ use crate :: plumbing:: MemoDropSender ;
10
11
use crate :: revision:: AtomicRevision ;
11
12
use crate :: table:: memo:: MemoTableWithTypesMut ;
12
13
use crate :: zalsa:: { MemoIngredientIndex , Zalsa } ;
@@ -16,27 +17,23 @@ use crate::{Event, EventKind, Id, Revision};
16
17
impl < C : Configuration > IngredientImpl < C > {
17
18
/// Inserts the memo for the given key; (atomically) overwrites and returns any previously existing memo
18
19
pub ( super ) fn insert_memo_into_table_for < ' db > (
19
- & self ,
20
+ & ' db self ,
20
21
zalsa : & ' db Zalsa ,
21
22
id : Id ,
22
23
memo : NonNull < Memo < C :: Output < ' db > > > ,
23
24
memo_ingredient_index : MemoIngredientIndex ,
24
- ) -> Option < NonNull < Memo < C :: Output < ' db > > > > {
25
+ ) {
25
26
// SAFETY: The table stores 'static memos (to support `Any`), the memos are in fact valid
26
27
// for `'db` though as we delay their dropping to the end of a revision.
27
28
let static_memo = unsafe {
28
29
transmute :: < NonNull < Memo < C :: Output < ' db > > > , NonNull < Memo < C :: Output < ' static > > > > ( memo)
29
30
} ;
30
- let old_static_memo = zalsa
31
+ let old_memo = zalsa
31
32
. 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
+ }
40
37
}
41
38
42
39
/// Loads the current memo for `key_index`. This does not hold any sort of
@@ -62,9 +59,11 @@ impl<C: Configuration> IngredientImpl<C> {
62
59
pub ( super ) fn evict_value_from_memo_for (
63
60
table : MemoTableWithTypesMut < ' _ > ,
64
61
memo_ingredient_index : MemoIngredientIndex ,
62
+ delayed : & MemoDropSender ,
65
63
) {
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 } {
68
67
QueryOrigin :: Assigned ( _)
69
68
| QueryOrigin :: DerivedUntracked ( _)
70
69
| QueryOrigin :: FixpointInitial => {
@@ -73,14 +72,9 @@ impl<C: Configuration> IngredientImpl<C> {
73
72
// or those with untracked inputs
74
73
// as their values cannot be reconstructed.
75
74
}
76
- QueryOrigin :: Derived ( _) => {
77
- // Set the memo value to `None`.
78
- memo. value = None ;
79
- }
75
+ QueryOrigin :: Derived ( _) => delayed. clear_value ( memo) ,
80
76
}
81
- } ;
82
-
83
- table. map_memo ( memo_ingredient_index, map)
77
+ }
84
78
}
85
79
}
86
80
@@ -255,4 +249,7 @@ impl<V: Send + Sync + Any> crate::table::memo::Memo for Memo<V> {
255
249
fn origin ( & self ) -> & QueryOrigin {
256
250
& self . revisions . origin
257
251
}
252
+ fn clear_value ( & mut self ) {
253
+ self . value = None ;
254
+ }
258
255
}
0 commit comments