@@ -341,7 +341,7 @@ where
341341 . unwrap_or ( ( Durability :: MAX , Revision :: max ( ) ) ) ;
342342
343343 let value = value. shared . get_mut ( ) . with ( |value_shared| {
344- // SAFETY: We hold the lock and the value has not been read in this revision .
344+ // SAFETY: We hold the lock.
345345 let value_shared = unsafe { & mut * value_shared } ;
346346
347347 // Mark the slot as reused.
@@ -354,13 +354,31 @@ where
354354 unsafe { & * UnsafeRef :: into_raw ( cursor. remove ( ) . unwrap ( ) ) }
355355 } ) ;
356356
357- // SAFETY: We hold the lock.
358- let id = value. shared . with_mut ( |value_shared| unsafe {
357+ let id = value. shared . with_mut ( |value_shared| {
358+ // SAFETY: We hold the lock.
359+ let value_shared = unsafe { & mut * value_shared } ;
360+
359361 // Note we need to retain the previous durability here to ensure queries trying
360362 // to read the old value are revalidated.
361- ( * value_shared) . durability =
362- std:: cmp:: max ( ( * value_shared) . durability , durability) ;
363- ( * value_shared) . id
363+ value_shared. durability = std:: cmp:: max ( value_shared. durability , durability) ;
364+
365+ let index = self . database_key_index ( value_shared. id ) ;
366+
367+ // Record a dependency on the value.
368+ zalsa_local. report_tracked_read_simple (
369+ index,
370+ value_shared. durability ,
371+ value_shared. first_interned_at ,
372+ ) ;
373+
374+ zalsa. event ( & || {
375+ Event :: new ( EventKind :: DidReuseInternedValue {
376+ key : index,
377+ revision : current_revision,
378+ } )
379+ } ) ;
380+
381+ value_shared. id
364382 } ) ;
365383
366384 // Reuse the value slot with the new data.
@@ -371,20 +389,15 @@ where
371389 * fields = self . to_internal_data ( assemble ( id, key) ) ;
372390 } ) ;
373391
392+ // TODO: Need to free the memory safely here.
393+ value. memos . clear ( ) ;
394+
374395 // Move the value to the front of the LRU list.
375396 //
376397 // SAFETY: The value pointer is valid for the lifetime of the database
377398 // and only accessed mutably while holding the lock.
378399 shared. lru . push_front ( unsafe { UnsafeRef :: from_raw ( value) } ) ;
379400
380- let index = self . database_key_index ( id) ;
381- zalsa. event ( & || {
382- Event :: new ( EventKind :: DidReuseInternedValue {
383- key : index,
384- revision : current_revision,
385- } )
386- } ) ;
387-
388401 return id;
389402 }
390403 }
0 commit comments