@@ -16,131 +16,6 @@ pub fn views<Db: ?Sized + Database>(db: &Db) -> &Views {
16
16
db. zalsa ( ) . views ( )
17
17
}
18
18
19
- /// The "plumbing interface" to the Salsa database.
20
- ///
21
- /// **NOT SEMVER STABLE.**
22
- pub trait Zalsa {
23
- /// Returns a reference to the underlying.
24
- fn views ( & self ) -> & Views ;
25
-
26
- /// Returns the nonce for the underyling storage.
27
- ///
28
- /// # Safety
29
- ///
30
- /// This nonce is guaranteed to be unique for the database and never to be reused.
31
- fn nonce ( & self ) -> Nonce < StorageNonce > ;
32
-
33
- /// Lookup the index assigned to the given jar (if any). This lookup is based purely on the jar's type.
34
- fn lookup_jar_by_type ( & self , jar : & dyn Jar ) -> Option < IngredientIndex > ;
35
-
36
- /// Adds a jar to the database, returning the index of the first ingredient.
37
- /// If a jar of this type is already present, returns the existing index.
38
- fn add_or_lookup_jar_by_type ( & self , jar : & dyn Jar ) -> IngredientIndex ;
39
-
40
- /// Gets an `&`-ref to an ingredient by index
41
- fn lookup_ingredient ( & self , index : IngredientIndex ) -> & dyn Ingredient ;
42
-
43
- /// Gets an `&mut`-ref to an ingredient by index.
44
- fn lookup_ingredient_mut ( & mut self , index : IngredientIndex ) -> & mut dyn Ingredient ;
45
-
46
- fn runtimex ( & self ) -> & Runtime ;
47
-
48
- /// Return the current revision
49
- fn current_revision ( & self ) -> Revision ;
50
-
51
- /// Return the time when an input of durability `durability` last changed
52
- fn last_changed_revision ( & self , durability : Durability ) -> Revision ;
53
-
54
- /// True if any threads have signalled for cancellation
55
- fn load_cancellation_flag ( & self ) -> bool ;
56
-
57
- /// Signal for cancellation, indicating current thread is trying to get unique access.
58
- fn set_cancellation_flag ( & self ) ;
59
-
60
- /// Reports a (synthetic) tracked write to "some input of the given durability".
61
- fn report_tracked_write ( & mut self , durability : Durability ) ;
62
- }
63
-
64
- impl Zalsa for ZalsaImpl {
65
- fn views ( & self ) -> & Views {
66
- & self . views_of
67
- }
68
-
69
- fn nonce ( & self ) -> Nonce < StorageNonce > {
70
- self . nonce
71
- }
72
-
73
- fn lookup_jar_by_type ( & self , jar : & dyn Jar ) -> Option < IngredientIndex > {
74
- self . jar_map . lock ( ) . get ( & jar. type_id ( ) ) . copied ( )
75
- }
76
-
77
- fn add_or_lookup_jar_by_type ( & self , jar : & dyn Jar ) -> IngredientIndex {
78
- {
79
- let jar_type_id = jar. type_id ( ) ;
80
- let mut jar_map = self . jar_map . lock ( ) ;
81
- * jar_map
82
- . entry ( jar_type_id)
83
- . or_insert_with ( || {
84
- let index = IngredientIndex :: from ( self . ingredients_vec . len ( ) ) ;
85
- let ingredients = jar. create_ingredients ( index) ;
86
- for ingredient in ingredients {
87
- let expected_index = ingredient. ingredient_index ( ) ;
88
-
89
- if ingredient. requires_reset_for_new_revision ( ) {
90
- self . ingredients_requiring_reset . push ( expected_index) ;
91
- }
92
-
93
- let actual_index = self
94
- . ingredients_vec
95
- . push ( ingredient) ;
96
- assert_eq ! (
97
- expected_index. as_usize( ) ,
98
- actual_index,
99
- "ingredient `{:?}` was predicted to have index `{:?}` but actually has index `{:?}`" ,
100
- self . ingredients_vec. get( actual_index) . unwrap( ) ,
101
- expected_index,
102
- actual_index,
103
- ) ;
104
-
105
- }
106
- index
107
- } )
108
- }
109
- }
110
-
111
- fn lookup_ingredient ( & self , index : IngredientIndex ) -> & dyn Ingredient {
112
- & * * self . ingredients_vec . get ( index. as_usize ( ) ) . unwrap ( )
113
- }
114
-
115
- fn lookup_ingredient_mut ( & mut self , index : IngredientIndex ) -> & mut dyn Ingredient {
116
- & mut * * self . ingredients_vec . get_mut ( index. as_usize ( ) ) . unwrap ( )
117
- }
118
-
119
- fn current_revision ( & self ) -> Revision {
120
- self . runtime . current_revision ( )
121
- }
122
-
123
- fn load_cancellation_flag ( & self ) -> bool {
124
- self . runtime . load_cancellation_flag ( )
125
- }
126
-
127
- fn report_tracked_write ( & mut self , durability : Durability ) {
128
- self . runtime . report_tracked_write ( durability)
129
- }
130
-
131
- fn runtimex ( & self ) -> & Runtime {
132
- & self . runtime
133
- }
134
-
135
- fn last_changed_revision ( & self , durability : Durability ) -> Revision {
136
- self . runtime . last_changed_revision ( durability)
137
- }
138
-
139
- fn set_cancellation_flag ( & self ) {
140
- self . runtime . set_cancellation_flag ( )
141
- }
142
- }
143
-
144
19
/// Nonce type representing the underlying database storage.
145
20
#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord ) ]
146
21
pub struct StorageNonce ;
@@ -180,9 +55,10 @@ impl IngredientIndex {
180
55
}
181
56
}
182
57
183
- /// The "storage" struct stores all the data for the jars.
184
- /// It is shared between the main database and any active snapshots.
185
- pub ( crate ) struct ZalsaImpl {
58
+ /// The "plumbing interface" to the Salsa database. Stores all the ingredients and other data.
59
+ ///
60
+ /// **NOT SEMVER STABLE.**
61
+ pub struct Zalsa {
186
62
user_data : Box < dyn Any + Send + Sync > ,
187
63
188
64
views_of : Views ,
@@ -210,7 +86,7 @@ pub(crate) struct ZalsaImpl {
210
86
runtime : Runtime ,
211
87
}
212
88
213
- impl ZalsaImpl {
89
+ impl Zalsa {
214
90
pub ( crate ) fn with < U : UserData > ( user_data : U ) -> Self {
215
91
Self {
216
92
views_of : Views :: new :: < DatabaseImpl < U > > ( ) ,
@@ -223,6 +99,84 @@ impl ZalsaImpl {
223
99
}
224
100
}
225
101
102
+ pub ( crate ) fn views ( & self ) -> & Views {
103
+ & self . views_of
104
+ }
105
+
106
+ pub ( crate ) fn nonce ( & self ) -> Nonce < StorageNonce > {
107
+ self . nonce
108
+ }
109
+
110
+ /// **NOT SEMVER STABLE**
111
+ pub fn add_or_lookup_jar_by_type ( & self , jar : & dyn Jar ) -> IngredientIndex {
112
+ {
113
+ let jar_type_id = jar. type_id ( ) ;
114
+ let mut jar_map = self . jar_map . lock ( ) ;
115
+ * jar_map
116
+ . entry ( jar_type_id)
117
+ . or_insert_with ( || {
118
+ let index = IngredientIndex :: from ( self . ingredients_vec . len ( ) ) ;
119
+ let ingredients = jar. create_ingredients ( index) ;
120
+ for ingredient in ingredients {
121
+ let expected_index = ingredient. ingredient_index ( ) ;
122
+
123
+ if ingredient. requires_reset_for_new_revision ( ) {
124
+ self . ingredients_requiring_reset . push ( expected_index) ;
125
+ }
126
+
127
+ let actual_index = self
128
+ . ingredients_vec
129
+ . push ( ingredient) ;
130
+ assert_eq ! (
131
+ expected_index. as_usize( ) ,
132
+ actual_index,
133
+ "ingredient `{:?}` was predicted to have index `{:?}` but actually has index `{:?}`" ,
134
+ self . ingredients_vec. get( actual_index) . unwrap( ) ,
135
+ expected_index,
136
+ actual_index,
137
+ ) ;
138
+
139
+ }
140
+ index
141
+ } )
142
+ }
143
+ }
144
+
145
+ pub ( crate ) fn lookup_ingredient ( & self , index : IngredientIndex ) -> & dyn Ingredient {
146
+ & * * self . ingredients_vec . get ( index. as_usize ( ) ) . unwrap ( )
147
+ }
148
+
149
+ /// **NOT SEMVER STABLE**
150
+ pub fn lookup_ingredient_mut ( & mut self , index : IngredientIndex ) -> & mut dyn Ingredient {
151
+ & mut * * self . ingredients_vec . get_mut ( index. as_usize ( ) ) . unwrap ( )
152
+ }
153
+
154
+ /// **NOT SEMVER STABLE**
155
+ pub fn current_revision ( & self ) -> Revision {
156
+ self . runtime . current_revision ( )
157
+ }
158
+
159
+ pub ( crate ) fn load_cancellation_flag ( & self ) -> bool {
160
+ self . runtime . load_cancellation_flag ( )
161
+ }
162
+
163
+ pub ( crate ) fn report_tracked_write ( & mut self , durability : Durability ) {
164
+ self . runtime . report_tracked_write ( durability)
165
+ }
166
+
167
+ pub ( crate ) fn runtimex ( & self ) -> & Runtime {
168
+ & self . runtime
169
+ }
170
+
171
+ /// **NOT SEMVER STABLE**
172
+ pub fn last_changed_revision ( & self , durability : Durability ) -> Revision {
173
+ self . runtime . last_changed_revision ( durability)
174
+ }
175
+
176
+ pub ( crate ) fn set_cancellation_flag ( & self ) {
177
+ self . runtime . set_cancellation_flag ( )
178
+ }
179
+
226
180
pub ( crate ) fn user_data ( & self ) -> & ( dyn Any + Send + Sync ) {
227
181
& * self . user_data
228
182
}
0 commit comments