11use crate :: debug:: TableEntry ;
22use crate :: durability:: Durability ;
33use crate :: hash:: FxIndexMap ;
4- use crate :: lru:: Lru ;
54use crate :: plumbing:: DerivedQueryStorageOps ;
6- use crate :: plumbing:: LruQueryStorageOps ;
75use crate :: plumbing:: QueryFunction ;
86use crate :: plumbing:: QueryStorageMassOps ;
97use crate :: plumbing:: QueryStorageOps ;
@@ -13,7 +11,6 @@ use crate::{Database, DatabaseKeyIndex, QueryDb, Revision};
1311use parking_lot:: RwLock ;
1412use std:: borrow:: Borrow ;
1513use std:: hash:: Hash ;
16- use std:: marker:: PhantomData ;
1714use triomphe:: Arc ;
1815
1916mod slot;
@@ -22,79 +19,32 @@ use slot::Slot;
2219/// Memoized queries store the result plus a list of the other queries
2320/// that they invoked. This means we can avoid recomputing them when
2421/// none of those inputs have changed.
25- pub type MemoizedStorage < Q > = DerivedStorage < Q , AlwaysMemoizeValue > ;
26-
27- /// "Dependency" queries just track their dependencies and not the
28- /// actual value (which they produce on demand). This lessens the
29- /// storage requirements.
30- pub type DependencyStorage < Q > = DerivedStorage < Q , NeverMemoizeValue > ;
22+ pub type MemoizedStorage < Q > = DerivedStorage < Q > ;
3123
3224/// Handles storage where the value is 'derived' by executing a
3325/// function (in contrast to "inputs").
34- pub struct DerivedStorage < Q , MP >
26+ pub struct DerivedStorage < Q >
3527where
3628 Q : QueryFunction ,
37- MP : MemoizationPolicy < Q > ,
3829{
3930 group_index : u16 ,
40- lru_list : Lru < Slot < Q , MP > > ,
41- slot_map : RwLock < FxIndexMap < Q :: Key , Arc < Slot < Q , MP > > > > ,
42- policy : PhantomData < MP > ,
31+ slot_map : RwLock < FxIndexMap < Q :: Key , Arc < Slot < Q > > > > ,
4332}
4433
45- impl < Q , MP > std:: panic:: RefUnwindSafe for DerivedStorage < Q , MP >
34+ impl < Q > std:: panic:: RefUnwindSafe for DerivedStorage < Q >
4635where
4736 Q : QueryFunction ,
48- MP : MemoizationPolicy < Q > ,
37+
4938 Q :: Key : std:: panic:: RefUnwindSafe ,
5039 Q :: Value : std:: panic:: RefUnwindSafe ,
5140{
5241}
5342
54- pub trait MemoizationPolicy < Q > : Send + Sync
43+ impl < Q > DerivedStorage < Q >
5544where
5645 Q : QueryFunction ,
5746{
58- fn should_memoize_value ( key : & Q :: Key ) -> bool ;
59-
60- fn memoized_value_eq ( old_value : & Q :: Value , new_value : & Q :: Value ) -> bool ;
61- }
62-
63- pub enum AlwaysMemoizeValue { }
64- impl < Q > MemoizationPolicy < Q > for AlwaysMemoizeValue
65- where
66- Q : QueryFunction ,
67- Q :: Value : Eq ,
68- {
69- fn should_memoize_value ( _key : & Q :: Key ) -> bool {
70- true
71- }
72-
73- fn memoized_value_eq ( old_value : & Q :: Value , new_value : & Q :: Value ) -> bool {
74- old_value == new_value
75- }
76- }
77-
78- pub enum NeverMemoizeValue { }
79- impl < Q > MemoizationPolicy < Q > for NeverMemoizeValue
80- where
81- Q : QueryFunction ,
82- {
83- fn should_memoize_value ( _key : & Q :: Key ) -> bool {
84- false
85- }
86-
87- fn memoized_value_eq ( _old_value : & Q :: Value , _new_value : & Q :: Value ) -> bool {
88- panic ! ( "cannot reach since we never memoize" )
89- }
90- }
91-
92- impl < Q , MP > DerivedStorage < Q , MP >
93- where
94- Q : QueryFunction ,
95- MP : MemoizationPolicy < Q > ,
96- {
97- fn slot ( & self , key : & Q :: Key ) -> Arc < Slot < Q , MP > > {
47+ fn slot ( & self , key : & Q :: Key ) -> Arc < Slot < Q > > {
9848 if let Some ( v) = self . slot_map . read ( ) . get ( key) {
9949 return v. clone ( ) ;
10050 }
@@ -111,20 +61,14 @@ where
11161 }
11262}
11363
114- impl < Q , MP > QueryStorageOps < Q > for DerivedStorage < Q , MP >
64+ impl < Q > QueryStorageOps < Q > for DerivedStorage < Q >
11565where
11666 Q : QueryFunction ,
117- MP : MemoizationPolicy < Q > ,
11867{
11968 const CYCLE_STRATEGY : crate :: plumbing:: CycleRecoveryStrategy = Q :: CYCLE_STRATEGY ;
12069
12170 fn new ( group_index : u16 ) -> Self {
122- DerivedStorage {
123- group_index,
124- slot_map : RwLock :: new ( FxIndexMap :: default ( ) ) ,
125- lru_list : Default :: default ( ) ,
126- policy : PhantomData ,
127- }
71+ DerivedStorage { group_index, slot_map : RwLock :: new ( FxIndexMap :: default ( ) ) }
12872 }
12973
13074 fn fmt_index (
@@ -161,10 +105,6 @@ where
161105 let slot = self . slot ( key) ;
162106 let StampedValue { value, durability, changed_at } = slot. read ( db, key) ;
163107
164- if let Some ( evicted) = self . lru_list . record_use ( & slot) {
165- evicted. evict ( ) ;
166- }
167-
168108 db. salsa_runtime ( ) . report_query_read_and_unwind_if_cycle_resulted (
169109 slot. database_key_index ( ) ,
170110 durability,
@@ -187,31 +127,18 @@ where
187127 }
188128}
189129
190- impl < Q , MP > QueryStorageMassOps for DerivedStorage < Q , MP >
130+ impl < Q > QueryStorageMassOps for DerivedStorage < Q >
191131where
192132 Q : QueryFunction ,
193- MP : MemoizationPolicy < Q > ,
194133{
195134 fn purge ( & self ) {
196- self . lru_list . purge ( ) ;
197135 * self . slot_map . write ( ) = Default :: default ( ) ;
198136 }
199137}
200138
201- impl < Q , MP > LruQueryStorageOps for DerivedStorage < Q , MP >
202- where
203- Q : QueryFunction ,
204- MP : MemoizationPolicy < Q > ,
205- {
206- fn set_lru_capacity ( & self , new_capacity : u16 ) {
207- self . lru_list . set_lru_capacity ( new_capacity) ;
208- }
209- }
210-
211- impl < Q , MP > DerivedQueryStorageOps < Q > for DerivedStorage < Q , MP >
139+ impl < Q > DerivedQueryStorageOps < Q > for DerivedStorage < Q >
212140where
213141 Q : QueryFunction ,
214- MP : MemoizationPolicy < Q > ,
215142{
216143 fn invalidate < S > ( & self , runtime : & mut Runtime , key : & S )
217144 where
0 commit comments