From 53a3235a607c6a7b3e998e78408e5b3857e49024 Mon Sep 17 00:00:00 2001 From: puuuuh Date: Sat, 12 Oct 2024 18:57:30 +0300 Subject: [PATCH 1/5] Add IngredientIndex to KeyStruct --- src/active_query.rs | 12 ++++++++---- src/tracked_struct.rs | 9 +++++++-- src/zalsa_local.rs | 8 ++++++-- tests/hash_collision.rs | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 tests/hash_collision.rs diff --git a/src/active_query.rs b/src/active_query.rs index 6d524b6f..88942bab 100644 --- a/src/active_query.rs +++ b/src/active_query.rs @@ -7,7 +7,7 @@ use crate::{ key::{DatabaseKeyIndex, DependencyIndex}, tracked_struct::{Disambiguator, KeyStruct}, zalsa_local::EMPTY_DEPENDENCIES, - Cycle, Revision, + Cycle, IngredientIndex, Revision, }; use super::zalsa_local::{EdgeKind, QueryEdges, QueryOrigin, QueryRevisions}; @@ -45,7 +45,7 @@ pub(crate) struct ActiveQuery { /// This table starts empty as the query begins and is gradually populated. /// Note that if a query executes in 2 different revisions but creates the same /// set of tracked structs, they will get the same disambiguator values. - disambiguator_map: FxHashMap, + disambiguator_map: FxHashMap<(IngredientIndex, u64), Disambiguator>, /// Map from tracked struct keys (which include the hash + disambiguator) to their /// final id. @@ -155,10 +155,14 @@ impl ActiveQuery { self.input_outputs.clone_from(&cycle_query.input_outputs); } - pub(super) fn disambiguate(&mut self, hash: u64) -> Disambiguator { + pub(super) fn disambiguate( + &mut self, + ingredient_index: IngredientIndex, + hash: u64, + ) -> Disambiguator { let disambiguator = self .disambiguator_map - .entry(hash) + .entry((ingredient_index, hash)) .or_insert(Disambiguator(0)); let result = *disambiguator; disambiguator.0 += 1; diff --git a/src/tracked_struct.rs b/src/tracked_struct.rs index be48489c..27f27c52 100644 --- a/src/tracked_struct.rs +++ b/src/tracked_struct.rs @@ -148,6 +148,9 @@ where /// struct and later moved to the [`Memo`](`crate::function::memo::Memo`). #[derive(Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Copy, Clone)] pub(crate) struct KeyStruct { + /// IngredientIndex of the tracked struct + ingredient_index: IngredientIndex, + /// The hash of the `#[id]` fields of this struct. /// Note that multiple structs may share the same hash. data_hash: u64, @@ -255,11 +258,13 @@ where ) -> C::Struct<'db> { let (zalsa, zalsa_local) = db.zalsas(); - let data_hash = crate::hash::hash(&C::id_fields(&fields)); + let data_hash = crate::hash::hash(&(C::id_fields(&fields))); - let (current_deps, disambiguator) = zalsa_local.disambiguate(data_hash); + let (current_deps, disambiguator) = + zalsa_local.disambiguate(self.ingredient_index, data_hash); let key_struct = KeyStruct { + ingredient_index: self.ingredient_index, disambiguator, data_hash, }; diff --git a/src/zalsa_local.rs b/src/zalsa_local.rs index d5e50832..33a9097c 100644 --- a/src/zalsa_local.rs +++ b/src/zalsa_local.rs @@ -262,7 +262,11 @@ impl ZalsaLocal { /// * the current dependencies (durability, changed_at) of current query /// * the disambiguator index #[track_caller] - pub(crate) fn disambiguate(&self, data_hash: u64) -> (StampedValue<()>, Disambiguator) { + pub(crate) fn disambiguate( + &self, + ingredient_index: IngredientIndex, + data_hash: u64, + ) -> (StampedValue<()>, Disambiguator) { assert!( self.query_in_progress(), "cannot create a tracked struct disambiguator outside of a tracked function" @@ -270,7 +274,7 @@ impl ZalsaLocal { self.with_query_stack(|stack| { let top_query = stack.last_mut().unwrap(); - let disambiguator = top_query.disambiguate(data_hash); + let disambiguator = top_query.disambiguate(ingredient_index, data_hash); ( StampedValue { value: (), diff --git a/tests/hash_collision.rs b/tests/hash_collision.rs new file mode 100644 index 00000000..4efadfa3 --- /dev/null +++ b/tests/hash_collision.rs @@ -0,0 +1,32 @@ +use std::hash::Hash; + +#[test] +fn hello() { + use salsa::{Database, DatabaseImpl, Setter}; + + #[salsa::input] + struct Bool { + value: bool, + } + + #[salsa::tracked] + struct True<'db> {} + + #[salsa::tracked] + struct False<'db> {} + + #[salsa::tracked] + fn hello(db: &dyn Database, bool: Bool) { + if bool.value(db) { + True::new(db); + } else { + False::new(db); + } + } + + let mut db = DatabaseImpl::new(); + let input = Bool::new(&db, false); + hello(&db, input); + input.set_value(&mut db).to(true); + hello(&db, input); +} From 3029f8ccf39a8c33053c62bd9fdfe8a170b0a8f2 Mon Sep 17 00:00:00 2001 From: puuuuh Date: Sat, 12 Oct 2024 20:25:10 +0300 Subject: [PATCH 2/5] Remove IngredientIndex from tracked_struct_ids, use KeyStruct field instead --- src/active_query.rs | 12 ++---------- src/function/diff_outputs.rs | 6 +++--- src/tracked_struct.rs | 4 ++-- src/zalsa_local.rs | 9 +++++---- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/active_query.rs b/src/active_query.rs index 88942bab..7a66eec9 100644 --- a/src/active_query.rs +++ b/src/active_query.rs @@ -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}; @@ -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, + pub(crate) tracked_struct_ids: FxHashMap, /// Stores the values accumulated to the given ingredient. /// The type of accumulated value is erased but known to the ingredient. diff --git a/src/function/diff_outputs.rs b/src/function/diff_outputs.rs index 03316e70..42b647b1 100644 --- a/src/function/diff_outputs.rs +++ b/src/function/diff_outputs.rs @@ -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), }) }); } diff --git a/src/tracked_struct.rs b/src/tracked_struct.rs index 27f27c52..a8137496 100644 --- a/src/tracked_struct.rs +++ b/src/tracked_struct.rs @@ -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. @@ -283,7 +283,7 @@ where let id = self.allocate(zalsa, zalsa_local, current_revision, ¤t_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) } } diff --git a/src/zalsa_local.rs b/src/zalsa_local.rs index 33a9097c..7bc38c60 100644 --- a/src/zalsa_local.rs +++ b/src/zalsa_local.rs @@ -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" @@ -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, + pub(super) tracked_struct_ids: FxHashMap, pub(super) accumulated: AccumulatedMap, } @@ -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, + tracked_struct_ids: &FxHashMap, ) { self.local_state.with_query_stack(|stack| { assert_eq!(stack.len(), self.push_len); From 60208fa80e046b18996c3eb0894aab7009318bd5 Mon Sep 17 00:00:00 2001 From: puuuuh Date: Sat, 12 Oct 2024 20:27:15 +0300 Subject: [PATCH 3/5] Fmt, lints --- src/zalsa_local.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/zalsa_local.rs b/src/zalsa_local.rs index 7bc38c60..ebfb152d 100644 --- a/src/zalsa_local.rs +++ b/src/zalsa_local.rs @@ -295,10 +295,7 @@ impl ZalsaLocal { self.with_query_stack(|stack| { let top_query = stack.last().unwrap(); - top_query - .tracked_struct_ids - .get(key_struct) - .map(|index| *index) + top_query.tracked_struct_ids.get(key_struct).copied() }) } @@ -541,10 +538,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, - ) { + pub(crate) fn seed_tracked_struct_ids(&self, tracked_struct_ids: &FxHashMap) { self.local_state.with_query_stack(|stack| { assert_eq!(stack.len(), self.push_len); let frame = stack.last_mut().unwrap(); From acae02d418e821f7dc77a1069d471cce61b4a420 Mon Sep 17 00:00:00 2001 From: puuuuh Date: Tue, 15 Oct 2024 04:48:18 +0300 Subject: [PATCH 4/5] Use named struct for disambiguation key --- src/active_query.rs | 22 +++++++++++-------- src/function/diff_outputs.rs | 2 +- src/tracked_struct.rs | 41 +++++++++++++++++++++++++----------- src/zalsa_local.rs | 10 +++------ 4 files changed, 46 insertions(+), 29 deletions(-) diff --git a/src/active_query.rs b/src/active_query.rs index 7a66eec9..9874dfe5 100644 --- a/src/active_query.rs +++ b/src/active_query.rs @@ -1,8 +1,16 @@ 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, Id, IngredientIndex, Revision}; - use super::zalsa_local::{EdgeKind, QueryEdges, QueryOrigin, QueryRevisions}; +use crate::tracked_struct::DisambiguationKey; +use crate::{ + accumulator::accumulated_map::AccumulatedMap, + durability::Durability, + hash::FxIndexSet, + key::{DatabaseKeyIndex, DependencyIndex}, + tracked_struct::{Disambiguator, KeyStruct}, + zalsa_local::EMPTY_DEPENDENCIES, + Cycle, Id, Revision, +}; #[derive(Debug)] pub(crate) struct ActiveQuery { @@ -37,7 +45,7 @@ pub(crate) struct ActiveQuery { /// This table starts empty as the query begins and is gradually populated. /// Note that if a query executes in 2 different revisions but creates the same /// set of tracked structs, they will get the same disambiguator values. - disambiguator_map: FxHashMap<(IngredientIndex, u64), Disambiguator>, + disambiguator_map: FxHashMap, /// Map from tracked struct keys (which include the hash + disambiguator) to their /// final id. @@ -147,14 +155,10 @@ impl ActiveQuery { self.input_outputs.clone_from(&cycle_query.input_outputs); } - pub(super) fn disambiguate( - &mut self, - ingredient_index: IngredientIndex, - hash: u64, - ) -> Disambiguator { + pub(super) fn disambiguate(&mut self, key: DisambiguationKey) -> Disambiguator { let disambiguator = self .disambiguator_map - .entry((ingredient_index, hash)) + .entry(key) .or_insert(Disambiguator(0)); let result = *disambiguator; disambiguator.0 += 1; diff --git a/src/function/diff_outputs.rs b/src/function/diff_outputs.rs index 42b647b1..d89f0d52 100644 --- a/src/function/diff_outputs.rs +++ b/src/function/diff_outputs.rs @@ -34,7 +34,7 @@ where // to prevent that the next revision is seeded with a id mapping that no longer exists. revisions.tracked_struct_ids.retain(|k, value| { !old_outputs.contains(&DependencyIndex { - ingredient_index: k.ingredient_index, + ingredient_index: k.ingredient_index(), key_index: Some(*value), }) }); diff --git a/src/tracked_struct.rs b/src/tracked_struct.rs index a8137496..fba9e9eb 100644 --- a/src/tracked_struct.rs +++ b/src/tracked_struct.rs @@ -148,18 +148,34 @@ where /// struct and later moved to the [`Memo`](`crate::function::memo::Memo`). #[derive(Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Copy, Clone)] pub(crate) struct KeyStruct { - /// IngredientIndex of the tracked struct - pub(crate) ingredient_index: IngredientIndex, - - /// The hash of the `#[id]` fields of this struct. - /// Note that multiple structs may share the same hash. - data_hash: u64, + /// Tracked struct key + disambiguation_key: DisambiguationKey, /// The unique disambiguator assigned within the active query - /// to distinguish distinct tracked structs with the same hash. + /// to distinguish distinct tracked structs with the same key. disambiguator: Disambiguator, } +impl KeyStruct { + pub(crate) fn ingredient_index(&self) -> IngredientIndex { + self.disambiguation_key.ingredient_index + } +} + +/// Stores the data that (almost) uniquely identifies a tracked struct. +/// This includes the ingredient index of that struct type plus the hash of its id fields. +/// This is mapped to a disambiguator -- a value that starts as 0 but increments each round, +/// allowing for multiple tracked structs with the same hash and ingredient_index +/// created within the query to each have a unique id. +#[derive(Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Copy, Clone)] +pub struct DisambiguationKey { + /// Index of the tracked struct ingredient. + ingredient_index: IngredientIndex, + + /// Hash of the id fields. + hash: u64, +} + // ANCHOR: ValueStruct #[derive(Debug)] pub struct Value @@ -258,15 +274,16 @@ where ) -> C::Struct<'db> { let (zalsa, zalsa_local) = db.zalsas(); - let data_hash = crate::hash::hash(&(C::id_fields(&fields))); + let disambiguation_key = DisambiguationKey { + ingredient_index: self.ingredient_index, + hash: crate::hash::hash(&C::id_fields(&fields)), + }; - let (current_deps, disambiguator) = - zalsa_local.disambiguate(self.ingredient_index, data_hash); + let (current_deps, disambiguator) = zalsa_local.disambiguate(disambiguation_key); let key_struct = KeyStruct { - ingredient_index: self.ingredient_index, + disambiguation_key, disambiguator, - data_hash, }; let current_revision = zalsa.current_revision(); diff --git a/src/zalsa_local.rs b/src/zalsa_local.rs index ebfb152d..bb12fc18 100644 --- a/src/zalsa_local.rs +++ b/src/zalsa_local.rs @@ -10,8 +10,8 @@ use crate::runtime::StampedValue; use crate::table::PageIndex; use crate::table::Slot; use crate::table::Table; -use crate::tracked_struct::Disambiguator; use crate::tracked_struct::KeyStruct; +use crate::tracked_struct::{DisambiguationKey, Disambiguator}; use crate::zalsa::IngredientIndex; use crate::Accumulator; use crate::Cancelled; @@ -262,11 +262,7 @@ impl ZalsaLocal { /// * the current dependencies (durability, changed_at) of current query /// * the disambiguator index #[track_caller] - pub(crate) fn disambiguate( - &self, - ingredient_index: IngredientIndex, - data_hash: u64, - ) -> (StampedValue<()>, Disambiguator) { + pub(crate) fn disambiguate(&self, key: DisambiguationKey) -> (StampedValue<()>, Disambiguator) { assert!( self.query_in_progress(), "cannot create a tracked struct disambiguator outside of a tracked function" @@ -274,7 +270,7 @@ impl ZalsaLocal { self.with_query_stack(|stack| { let top_query = stack.last_mut().unwrap(); - let disambiguator = top_query.disambiguate(ingredient_index, data_hash); + let disambiguator = top_query.disambiguate(key); ( StampedValue { value: (), From 0744fd8cb0b260972f4505047896d60e1ed27b6e Mon Sep 17 00:00:00 2001 From: puuuuh Date: Thu, 17 Oct 2024 15:50:13 +0300 Subject: [PATCH 5/5] Rename DisambiguationKey to IdentityHash, KeyStruct to Identity --- src/active_query.rs | 10 +++++----- src/tracked_struct.rs | 27 ++++++++++++++------------- src/zalsa_local.rs | 19 +++++++++---------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/active_query.rs b/src/active_query.rs index 9874dfe5..aadcf196 100644 --- a/src/active_query.rs +++ b/src/active_query.rs @@ -1,13 +1,13 @@ use rustc_hash::FxHashMap; use super::zalsa_local::{EdgeKind, QueryEdges, QueryOrigin, QueryRevisions}; -use crate::tracked_struct::DisambiguationKey; +use crate::tracked_struct::IdentityHash; use crate::{ accumulator::accumulated_map::AccumulatedMap, durability::Durability, hash::FxIndexSet, key::{DatabaseKeyIndex, DependencyIndex}, - tracked_struct::{Disambiguator, KeyStruct}, + tracked_struct::{Disambiguator, Identity}, zalsa_local::EMPTY_DEPENDENCIES, Cycle, Id, Revision, }; @@ -45,11 +45,11 @@ pub(crate) struct ActiveQuery { /// This table starts empty as the query begins and is gradually populated. /// Note that if a query executes in 2 different revisions but creates the same /// set of tracked structs, they will get the same disambiguator values. - disambiguator_map: FxHashMap, + disambiguator_map: FxHashMap, /// Map from tracked struct keys (which include the hash + disambiguator) to their /// final id. - pub(crate) tracked_struct_ids: FxHashMap, + pub(crate) tracked_struct_ids: FxHashMap, /// Stores the values accumulated to the given ingredient. /// The type of accumulated value is erased but known to the ingredient. @@ -155,7 +155,7 @@ impl ActiveQuery { self.input_outputs.clone_from(&cycle_query.input_outputs); } - pub(super) fn disambiguate(&mut self, key: DisambiguationKey) -> Disambiguator { + pub(super) fn disambiguate(&mut self, key: IdentityHash) -> Disambiguator { let disambiguator = self .disambiguator_map .entry(key) diff --git a/src/tracked_struct.rs b/src/tracked_struct.rs index fba9e9eb..540bb765 100644 --- a/src/tracked_struct.rs +++ b/src/tracked_struct.rs @@ -147,18 +147,18 @@ where /// stored in the [`ActiveQuery`](`crate::active_query::ActiveQuery`) /// struct and later moved to the [`Memo`](`crate::function::memo::Memo`). #[derive(Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Copy, Clone)] -pub(crate) struct KeyStruct { - /// Tracked struct key - disambiguation_key: DisambiguationKey, +pub(crate) struct Identity { + /// Hash of fields with id attribute + identity_hash: IdentityHash, /// The unique disambiguator assigned within the active query - /// to distinguish distinct tracked structs with the same key. + /// to distinguish distinct tracked structs with the same identity_hash. disambiguator: Disambiguator, } -impl KeyStruct { +impl Identity { pub(crate) fn ingredient_index(&self) -> IngredientIndex { - self.disambiguation_key.ingredient_index + self.identity_hash.ingredient_index } } @@ -168,7 +168,7 @@ impl KeyStruct { /// allowing for multiple tracked structs with the same hash and ingredient_index /// created within the query to each have a unique id. #[derive(Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Copy, Clone)] -pub struct DisambiguationKey { +pub struct IdentityHash { /// Index of the tracked struct ingredient. ingredient_index: IngredientIndex, @@ -274,20 +274,21 @@ where ) -> C::Struct<'db> { let (zalsa, zalsa_local) = db.zalsas(); - let disambiguation_key = DisambiguationKey { + let identity_hash = IdentityHash { ingredient_index: self.ingredient_index, hash: crate::hash::hash(&C::id_fields(&fields)), }; - let (current_deps, disambiguator) = zalsa_local.disambiguate(disambiguation_key); + let (current_deps, disambiguator) = zalsa_local.disambiguate(identity_hash); + + let identity = Identity { + identity_hash, - let key_struct = KeyStruct { - disambiguation_key, disambiguator, }; let current_revision = zalsa.current_revision(); - match zalsa_local.tracked_struct_id(&key_struct) { + match zalsa_local.tracked_struct_id(&identity) { Some(id) => { // The struct already exists in the intern map. zalsa_local.add_output(self.database_key_index(id).into()); @@ -300,7 +301,7 @@ where let id = self.allocate(zalsa, zalsa_local, current_revision, ¤t_deps, fields); let key = self.database_key_index(id); zalsa_local.add_output(key.into()); - zalsa_local.store_tracked_struct_id(key_struct, id); + zalsa_local.store_tracked_struct_id(identity, id); C::struct_from_id(id) } } diff --git a/src/zalsa_local.rs b/src/zalsa_local.rs index bb12fc18..9076ffa9 100644 --- a/src/zalsa_local.rs +++ b/src/zalsa_local.rs @@ -10,8 +10,7 @@ use crate::runtime::StampedValue; use crate::table::PageIndex; use crate::table::Slot; use crate::table::Table; -use crate::tracked_struct::KeyStruct; -use crate::tracked_struct::{DisambiguationKey, Disambiguator}; +use crate::tracked_struct::{Disambiguator, Identity, IdentityHash}; use crate::zalsa::IngredientIndex; use crate::Accumulator; use crate::Cancelled; @@ -262,7 +261,7 @@ impl ZalsaLocal { /// * the current dependencies (durability, changed_at) of current query /// * the disambiguator index #[track_caller] - pub(crate) fn disambiguate(&self, key: DisambiguationKey) -> (StampedValue<()>, Disambiguator) { + pub(crate) fn disambiguate(&self, key: IdentityHash) -> (StampedValue<()>, Disambiguator) { assert!( self.query_in_progress(), "cannot create a tracked struct disambiguator outside of a tracked function" @@ -283,7 +282,7 @@ impl ZalsaLocal { } #[track_caller] - pub(crate) fn tracked_struct_id(&self, key_struct: &KeyStruct) -> Option { + pub(crate) fn tracked_struct_id(&self, identity: &Identity) -> Option { debug_assert!( self.query_in_progress(), "cannot create a tracked struct disambiguator outside of a tracked function" @@ -291,22 +290,22 @@ impl ZalsaLocal { self.with_query_stack(|stack| { let top_query = stack.last().unwrap(); - top_query.tracked_struct_ids.get(key_struct).copied() + top_query.tracked_struct_ids.get(identity).copied() }) } #[track_caller] - pub(crate) fn store_tracked_struct_id(&self, key_struct: KeyStruct, id: Id) { + pub(crate) fn store_tracked_struct_id(&self, identity: Identity, id: Id) { debug_assert!( 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_mut().unwrap(); - let old_id = top_query.tracked_struct_ids.insert(key_struct, id); + let old_id = top_query.tracked_struct_ids.insert(identity, id); assert!( old_id.is_none(), - "overwrote a previous id for `{key_struct:?}`" + "overwrote a previous id for `{identity:?}`" ); }) } @@ -375,7 +374,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, + pub(super) tracked_struct_ids: FxHashMap, pub(super) accumulated: AccumulatedMap, } @@ -534,7 +533,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) { + pub(crate) fn seed_tracked_struct_ids(&self, tracked_struct_ids: &FxHashMap) { self.local_state.with_query_stack(|stack| { assert_eq!(stack.len(), self.push_len); let frame = stack.last_mut().unwrap();