Skip to content

Commit 513a567

Browse files
committed
Store tracked struct ids as Vec on Revisions
1 parent 80fb79e commit 513a567

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

src/function/diff_outputs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ where
5454
// Remove the outputs that are no longer present in the current revision
5555
// to prevent that the next revision is seeded with an id mapping that no longer exists.
5656
tracked_struct_ids
57-
.retain(|k, value| !old_outputs.contains(&(k.ingredient_index(), value.index())));
57+
.retain(|(k, value)| !old_outputs.contains(&(k.ingredient_index(), value.index())));
5858
}
5959

6060
for (ingredient_index, key_index) in old_outputs {

src/tracked_struct.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,17 @@ impl Clone for IdentityMap {
220220
table: self.table.clone(),
221221
}
222222
}
223-
fn clone_from(&mut self, source: &Self) {
224-
self.table.clone_from(&source.table);
225-
}
226223
}
227224

228225
impl IdentityMap {
226+
pub(crate) fn from_slice(&mut self, source: &[(Identity, Id)]) {
227+
self.table.clear();
228+
229+
for (key, id) in source {
230+
self.insert(*key, *id);
231+
}
232+
}
233+
229234
pub(crate) fn insert(&mut self, key: Identity, id: Id) -> Option<Id> {
230235
let entry = self.table.find_mut(key.hash, |&(k, _)| k == key);
231236
match entry {
@@ -248,16 +253,12 @@ impl IdentityMap {
248253
self.table.is_empty()
249254
}
250255

251-
pub(crate) fn retain(&mut self, mut f: impl FnMut(&Identity, &mut Id) -> bool) {
252-
self.table.retain(|(k, v)| f(k, v));
253-
}
254-
255256
pub(crate) fn clear(&mut self) {
256257
self.table.clear()
257258
}
258259

259-
pub(crate) fn shrink_to_fit(&mut self) {
260-
self.table.shrink_to_fit(|(k, _)| k.hash);
260+
pub(crate) fn into_vec(self) -> Vec<(Identity, Id)> {
261+
self.table.into_iter().collect()
261262
}
262263
}
263264

src/zalsa_local.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ impl QueryRevisionsExtra {
367367
Some(Box::new(QueryRevisionsExtraInner {
368368
accumulated,
369369
cycle_heads,
370-
tracked_struct_ids,
370+
tracked_struct_ids: tracked_struct_ids.into_vec(),
371371
}))
372372
};
373373

@@ -396,7 +396,7 @@ struct QueryRevisionsExtraInner {
396396
/// previous revision. To handle this, `diff_outputs` compares
397397
/// the structs from the old/new revision and retains
398398
/// only entries that appeared in the new revision.
399-
tracked_struct_ids: IdentityMap,
399+
tracked_struct_ids: Vec<(Identity, Id)>,
400400

401401
/// This result was computed based on provisional values from
402402
/// these cycle heads. The "cycle head" is the query responsible
@@ -416,7 +416,7 @@ const _: [(); std::mem::size_of::<QueryRevisions>()] = [(); std::mem::size_of::<
416416
#[cfg(not(feature = "shuttle"))]
417417
#[cfg(target_pointer_width = "64")]
418418
const _: [(); std::mem::size_of::<QueryRevisionsExtraInner>()] =
419-
[(); std::mem::size_of::<[usize; 9]>()];
419+
[(); std::mem::size_of::<[usize; 8]>()];
420420

421421
impl QueryRevisions {
422422
pub(crate) fn fixpoint_initial(query: DatabaseKeyIndex) -> Self {
@@ -475,16 +475,16 @@ impl QueryRevisions {
475475
}
476476

477477
/// Returns a reference to the `IdentityMap` for this query, or `None` if the map is empty.
478-
pub fn tracked_struct_ids(&self) -> Option<&IdentityMap> {
478+
pub fn tracked_struct_ids(&self) -> Option<&[(Identity, Id)]> {
479479
self.extra
480480
.0
481481
.as_ref()
482-
.map(|extra| &extra.tracked_struct_ids)
482+
.map(|extra| &*extra.tracked_struct_ids)
483483
.filter(|tracked_struct_ids| !tracked_struct_ids.is_empty())
484484
}
485485

486486
/// Returns a mutable reference to the `IdentityMap` for this query, or `None` if the map is empty.
487-
pub fn tracked_struct_ids_mut(&mut self) -> Option<&mut IdentityMap> {
487+
pub fn tracked_struct_ids_mut(&mut self) -> Option<&mut Vec<(Identity, Id)>> {
488488
self.extra
489489
.0
490490
.as_mut()
@@ -836,15 +836,15 @@ pub(crate) struct ActiveQueryGuard<'me> {
836836

837837
impl ActiveQueryGuard<'_> {
838838
/// Initialize the tracked struct ids with the values from the prior execution.
839-
pub(crate) fn seed_tracked_struct_ids(&self, tracked_struct_ids: &IdentityMap) {
839+
pub(crate) fn seed_tracked_struct_ids(&self, tracked_struct_ids: &[(Identity, Id)]) {
840840
self.local_state.with_query_stack_mut(|stack| {
841841
#[cfg(debug_assertions)]
842842
assert_eq!(stack.len(), self.push_len);
843843
let frame = stack.last_mut().unwrap();
844844
assert!(frame.tracked_struct_ids().is_empty());
845845
frame
846846
.tracked_struct_ids_mut()
847-
.clone_from(tracked_struct_ids);
847+
.from_slice(tracked_struct_ids);
848848
})
849849
}
850850

0 commit comments

Comments
 (0)