Skip to content

Commit

Permalink
Remove IngredientIndex from tracked_struct_ids, use KeyStruct field i…
Browse files Browse the repository at this point in the history
…nstead
  • Loading branch information
puuuuh committed Oct 12, 2024
1 parent b71fd36 commit c6ebf22
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
12 changes: 2 additions & 10 deletions src/active_query.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
use rustc_hash::FxHashMap;

use crate::{
accumulator::accumulated_map::AccumulatedMap,
durability::Durability,
hash::FxIndexSet,
key::{DatabaseKeyIndex, DependencyIndex},
tracked_struct::{Disambiguator, KeyStruct},
zalsa_local::EMPTY_DEPENDENCIES,
Cycle, IngredientIndex, Revision,
};
use crate::{accumulator::accumulated_map::AccumulatedMap, durability::Durability, hash::FxIndexSet, key::{DatabaseKeyIndex, DependencyIndex}, tracked_struct::{Disambiguator, KeyStruct}, zalsa_local::EMPTY_DEPENDENCIES, Cycle, Id, IngredientIndex, Revision};

use super::zalsa_local::{EdgeKind, QueryEdges, QueryOrigin, QueryRevisions};

Expand Down Expand Up @@ -49,7 +41,7 @@ pub(crate) struct ActiveQuery {

/// Map from tracked struct keys (which include the hash + disambiguator) to their
/// final id.
pub(crate) tracked_struct_ids: FxHashMap<KeyStruct, DatabaseKeyIndex>,
pub(crate) tracked_struct_ids: FxHashMap<KeyStruct, Id>,

/// Stores the values accumulated to the given ingredient.
/// The type of accumulated value is erased but known to the ingredient.
Expand Down
6 changes: 3 additions & 3 deletions src/function/diff_outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ where
if !old_outputs.is_empty() {
// Remove the outputs that are no longer present in the current revision
// to prevent that the next revision is seeded with a id mapping that no longer exists.
revisions.tracked_struct_ids.retain(|_k, value| {
revisions.tracked_struct_ids.retain(|k, value| {
!old_outputs.contains(&DependencyIndex {
ingredient_index: value.ingredient_index,
key_index: Some(value.key_index),
ingredient_index: k.ingredient_index,
key_index: Some(*value),
})
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/tracked_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ where
#[derive(Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Copy, Clone)]
pub(crate) struct KeyStruct {
/// IngredientIndex of the tracked struct
ingredient_index: IngredientIndex,
pub(crate) ingredient_index: IngredientIndex,

/// The hash of the `#[id]` fields of this struct.
/// Note that multiple structs may share the same hash.
Expand Down Expand Up @@ -283,7 +283,7 @@ where
let id = self.allocate(zalsa, zalsa_local, current_revision, &current_deps, fields);
let key = self.database_key_index(id);
zalsa_local.add_output(key.into());
zalsa_local.store_tracked_struct_id(key_struct, key);
zalsa_local.store_tracked_struct_id(key_struct, id);
C::struct_from_id(id)
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/zalsa_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,17 +292,18 @@ impl ZalsaLocal {
self.query_in_progress(),
"cannot create a tracked struct disambiguator outside of a tracked function"
);

self.with_query_stack(|stack| {
let top_query = stack.last().unwrap();
top_query
.tracked_struct_ids
.get(key_struct)
.map(|index| index.key_index())
.map(|index| *index)
})
}

#[track_caller]
pub(crate) fn store_tracked_struct_id(&self, key_struct: KeyStruct, id: DatabaseKeyIndex) {
pub(crate) fn store_tracked_struct_id(&self, key_struct: KeyStruct, id: Id) {
debug_assert!(
self.query_in_progress(),
"cannot create a tracked struct disambiguator outside of a tracked function"
Expand Down Expand Up @@ -381,7 +382,7 @@ pub(crate) struct QueryRevisions {
/// previous revision. To handle this, `diff_outputs` compares
/// the structs from the old/new revision and retains
/// only entries that appeared in the new revision.
pub(super) tracked_struct_ids: FxHashMap<KeyStruct, DatabaseKeyIndex>,
pub(super) tracked_struct_ids: FxHashMap<KeyStruct, Id>,

pub(super) accumulated: AccumulatedMap,
}
Expand Down Expand Up @@ -542,7 +543,7 @@ impl ActiveQueryGuard<'_> {
/// Initialize the tracked struct ids with the values from the prior execution.
pub(crate) fn seed_tracked_struct_ids(
&self,
tracked_struct_ids: &FxHashMap<KeyStruct, DatabaseKeyIndex>,
tracked_struct_ids: &FxHashMap<KeyStruct, Id>,
) {
self.local_state.with_query_stack(|stack| {
assert_eq!(stack.len(), self.push_len);
Expand Down

0 comments on commit c6ebf22

Please sign in to comment.