@@ -100,22 +100,11 @@ where
100
100
}
101
101
102
102
pub fn validate ( & self , current_revision : Revision , id : Id ) {
103
- Self :: validate_in_map ( & self . map , current_revision, id)
104
- }
105
-
106
- pub fn validate_in_map (
107
- map : & FxDashMap < Id , Alloc < Value < C > > > ,
108
- current_revision : Revision ,
109
- id : Id ,
110
- ) {
111
- let mut data = map. get_mut ( & id) . unwrap ( ) ;
103
+ let mut data = self . map . get_mut ( & id) . unwrap ( ) ;
112
104
113
105
// UNSAFE: We never permit `&`-access in the current revision until data.created_at
114
106
// has been updated to the current revision (which we check below).
115
107
let data = unsafe { data. as_mut ( ) } ;
116
-
117
- // Never update a struct twice in the same revision.
118
- assert ! ( data. created_at <= current_revision) ;
119
108
data. created_at = current_revision;
120
109
}
121
110
@@ -126,7 +115,7 @@ where
126
115
///
127
116
/// * If the value is not present in the map.
128
117
/// * If the value is already updated in this revision.
129
- pub fn update ( & self , current_revision : Revision , id : Id ) -> Update < ' _ , C > {
118
+ pub fn update ( & self , zalsa : & Zalsa , id : Id ) -> Update < ' _ , C > {
130
119
let mut data = self . map . get_mut ( & id) . unwrap ( ) ;
131
120
132
121
// UNSAFE: We never permit `&`-access in the current revision until data.created_at
@@ -156,9 +145,10 @@ where
156
145
//
157
146
// For this reason, we just return `None` in this case, ensuring that the calling
158
147
// code cannot violate that `&`-reference.
148
+ let current_revision = zalsa. current_revision ( ) ;
159
149
if data_ref. created_at == current_revision {
160
150
drop ( data) ;
161
- return Update :: Current ( Self :: get_from_map ( & self . map , current_revision , id) ) ;
151
+ return Update :: Current ( Self :: get_from_map ( & self . map , zalsa , id) ) ;
162
152
}
163
153
164
154
data_ref. created_at = current_revision;
@@ -171,64 +161,25 @@ where
171
161
///
172
162
/// * If the value is not present in the map.
173
163
/// * If the value has not been updated in this revision.
174
- pub fn get ( & self , current_revision : Revision , id : Id ) -> C :: Struct < ' _ > {
175
- Self :: get_from_map ( & self . map , current_revision , id)
164
+ pub fn get ( & self , zalsa : & Zalsa , id : Id ) -> C :: Struct < ' _ > {
165
+ Self :: get_from_map ( & self . map , zalsa , id)
176
166
}
177
167
178
168
/// Helper function, provides shared functionality for [`StructMapView`][]
179
169
///
180
170
/// # Panics
181
171
///
182
172
/// * If the value is not present in the map.
183
- /// * If the value has not been updated in this revision.
184
- fn get_from_map (
185
- map : & FxDashMap < Id , Alloc < Value < C > > > ,
186
- current_revision : Revision ,
187
- id : Id ,
188
- ) -> C :: Struct < ' _ > {
189
- let data = map. get ( & id) . unwrap ( ) ;
190
-
191
- // UNSAFE: We permit `&`-access in the current revision once data.created_at
192
- // has been updated to the current revision (which we check below).
193
- let data_ref: & Value < C > = unsafe { data. as_ref ( ) } ;
194
-
195
- // Before we drop the lock, check that the value has
196
- // been updated in this revision. This is what allows us to return a Struct
197
- let created_at = data_ref. created_at ;
198
- assert ! (
199
- created_at == current_revision,
200
- "access to tracked struct from previous revision"
201
- ) ;
202
-
203
- // Unsafety clause:
204
- //
205
- // * Value will not be updated again in this revision,
206
- // and revision will not change so long as runtime is shared
207
- // * We only remove values from the map when we have `&mut self`
208
- unsafe { C :: struct_from_raw ( data. as_raw ( ) ) }
209
- }
210
-
211
- /// Lookup an existing tracked struct from the map, maybe validating it to current revision.
212
- ///
213
- /// Validates to current revision if the struct was last created/validated in a revision that
214
- /// is still current for the struct's durability. That is, if the struct is HIGH durability
215
- /// (created by a HIGH durability query) and was created in R2, and we are now at R3 but no
216
- /// HIGH durability input has changed since R2, the struct is still valid and we can validate
217
- /// it to R3.
218
- ///
219
- /// # Panics
220
- ///
221
- /// * If the value is not present in the map.
222
- /// * If the value has not been updated in the last-changed revision for its durability.
223
- fn get_and_validate_last_changed < ' db > (
224
- map : & ' db FxDashMap < Id , Alloc < Value < C > > > ,
173
+ /// * If the value has not been updated since last-modified revision for its durability.
174
+ fn get_from_map < ' a > (
175
+ map : & ' a FxDashMap < Id , Alloc < Value < C > > > ,
225
176
zalsa : & Zalsa ,
226
177
id : Id ,
227
- ) -> C :: Struct < ' db > {
228
- let data = map. get ( & id) . unwrap ( ) ;
178
+ ) -> C :: Struct < ' a > {
179
+ let mut data = map. get_mut ( & id) . unwrap ( ) ;
229
180
230
181
// UNSAFE: We permit `&`-access in the current revision once data.created_at
231
- // has been updated to the current revision (which we ensure below).
182
+ // has been updated to the current revision (which we check below).
232
183
let data_ref: & Value < C > = unsafe { data. as_ref ( ) } ;
233
184
234
185
// Before we drop the lock, check that the value has been updated in the most recent
@@ -237,25 +188,24 @@ where
237
188
let last_changed = zalsa. last_changed_revision ( data_ref. durability ) ;
238
189
assert ! (
239
190
created_at >= last_changed,
240
- "access to tracked struct from obsolete revision"
191
+ "access to tracked struct from previous revision"
241
192
) ;
242
193
194
+ // Validate in current revision, if needed.
195
+ let current_revision = zalsa. current_revision ( ) ;
196
+ if created_at < current_revision {
197
+ // UNSAFE: We never permit `&`-access in the current revision until data.created_at
198
+ // has been updated to the current revision (which we check below).
199
+ let data = unsafe { data. as_mut ( ) } ;
200
+ data. created_at = current_revision;
201
+ }
202
+
243
203
// Unsafety clause:
244
204
//
245
205
// * Value will not be updated again in this revision,
246
206
// and revision will not change so long as runtime is shared
247
207
// * We only remove values from the map when we have `&mut self`
248
- let ret = unsafe { C :: struct_from_raw ( data. as_raw ( ) ) } ;
249
-
250
- drop ( data) ;
251
-
252
- // Validate in current revision, if necessary.
253
- let current_revision = zalsa. current_revision ( ) ;
254
- if last_changed < current_revision {
255
- Self :: validate_in_map ( map, current_revision, id) ;
256
- }
257
-
258
- ret
208
+ unsafe { C :: struct_from_raw ( data. as_raw ( ) ) }
259
209
}
260
210
261
211
/// Remove the entry for `id` from the map.
@@ -288,12 +238,8 @@ where
288
238
///
289
239
/// * If the value is not present in the map.
290
240
/// * If the value has not been updated in this revision.
291
- pub fn get ( & self , current_revision : Revision , id : Id ) -> C :: Struct < ' _ > {
292
- StructMap :: get_from_map ( & self . map , current_revision, id)
293
- }
294
-
295
- pub fn get_and_validate_last_changed < ' db > ( & ' db self , zalsa : & Zalsa , id : Id ) -> C :: Struct < ' db > {
296
- StructMap :: get_and_validate_last_changed ( & self . map , zalsa, id)
241
+ pub fn get ( & self , zalsa : & Zalsa , id : Id ) -> C :: Struct < ' _ > {
242
+ StructMap :: get_from_map ( & self . map , zalsa, id)
297
243
}
298
244
}
299
245
0 commit comments