diff --git a/book/src/plumbing/tracked_structs.md b/book/src/plumbing/tracked_structs.md index 4444b463..8fbf46a9 100644 --- a/book/src/plumbing/tracked_structs.md +++ b/book/src/plumbing/tracked_structs.md @@ -10,12 +10,12 @@ For a single tracked struct we create multiple ingredients. The **tracked struct ingredient** is the ingredient created first. It offers methods to create new instances of the struct and therefore has unique access to the interner and hashtables used to create the struct id. -It also shares access to a hashtable that stores the `TrackedStructValue` that +It also shares access to a hashtable that stores the `ValueStruct` that contains the field data. For each field, we create a **tracked field ingredient** that moderates access to a particular field. All of these ingredients use that same shared hashtable -to access the `TrackedStructValue` instance for a given id. The `TrackedStructValue` +to access the `ValueStruct` instance for a given id. The `ValueStruct` contains both the field values but also the revisions when they last changed value. ## Each tracked struct has a globally unique id @@ -26,13 +26,13 @@ This will begin by creating a *globally unique, 32-bit id* for the tracked struc * a u64 hash of the `#[id]` fields; * a *disambiguator* that makes this hash unique within the current query. i.e., when a query starts executing, it creates an empty map, and the first time a tracked struct with a given hash is created, it gets disambiguator 0. The next one will be given 1, etc. -## Each tracked struct has a `TrackedStructValue` storing its data +## Each tracked struct has a `ValueStruct` storing its data The struct and field ingredients share access to a hashmap that maps each field id to a value struct: ```rust,ignore -{{#include ../../../components/salsa-2022/src/tracked_struct.rs:TrackedStructValue}} +{{#include ../../../components/salsa-2022/src/tracked_struct.rs:ValueStruct}} ``` The value struct stores the values of the fields but also the revisions when diff --git a/components/salsa-2022-macros/src/salsa_struct.rs b/components/salsa-2022-macros/src/salsa_struct.rs index 00093e34..7d3d8d98 100644 --- a/components/salsa-2022-macros/src/salsa_struct.rs +++ b/components/salsa-2022-macros/src/salsa_struct.rs @@ -309,8 +309,8 @@ impl SalsaStruct { #(#attrs)* #[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Debug)] #visibility struct #ident #generics ( - *const salsa::tracked_struct::TrackedStructValue < #config_ident >, - std::marker::PhantomData < & #lifetime salsa::tracked_struct::TrackedStructValue < #config_ident > > + *const salsa::tracked_struct::ValueStruct < #config_ident >, + std::marker::PhantomData < & #lifetime salsa::tracked_struct::ValueStruct < #config_ident > > ); }) } diff --git a/components/salsa-2022/src/tracked_struct.rs b/components/salsa-2022/src/tracked_struct.rs index d4db3f9f..0540ece4 100644 --- a/components/salsa-2022/src/tracked_struct.rs +++ b/components/salsa-2022/src/tracked_struct.rs @@ -98,7 +98,7 @@ where /// Entries are added to this map when a new struct is created. /// They are removed when that struct is deleted /// (i.e., a query completes without having recreated the struct). - keys: FxDashMap, + keys: FxDashMap, /// The number of tracked structs created. counter: AtomicCell, @@ -119,7 +119,7 @@ where /// Defines the identity of a tracked struct. #[derive(Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Copy, Clone)] -struct TrackedStructKey { +struct KeyStruct { /// The active query (i.e., tracked function) that created this tracked struct. query_key: DatabaseKeyIndex, @@ -132,13 +132,13 @@ struct TrackedStructKey { disambiguator: Disambiguator, } -impl crate::interned::Configuration for TrackedStructKey { - type Data<'db> = TrackedStructKey; +impl crate::interned::Configuration for KeyStruct { + type Data<'db> = KeyStruct; } -// ANCHOR: TrackedStructValue +// ANCHOR: ValueStruct #[derive(Debug)] -pub struct TrackedStructValue +pub struct ValueStruct where C: Configuration, { @@ -149,7 +149,7 @@ where id: Id, /// The key used to create the id. - key: TrackedStructKey, + key: KeyStruct, /// The durability minimum durability of all inputs consumed /// by the creator query prior to creating this tracked struct. @@ -175,7 +175,7 @@ where /// current revision if the value is different. revisions: C::Revisions, } -// ANCHOR_END: TrackedStructValue +// ANCHOR_END: ValueStruct #[derive(Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Copy, Clone)] pub struct Disambiguator(pub u32); @@ -241,7 +241,7 @@ where /// Intern a tracked struct key to get a unique tracked struct id. /// Also returns a bool indicating whether this id was newly created or whether it already existed. - fn intern(&self, key: TrackedStructKey) -> (Id, bool) { + fn intern(&self, key: KeyStruct) -> (Id, bool) { let (id, new_id) = if let Some(g) = self.keys.get(&key) { (*g.value(), false) } else { @@ -262,13 +262,13 @@ where &'db self, runtime: &'db Runtime, fields: C::Fields<'db>, - ) -> &'db TrackedStructValue { + ) -> &'db ValueStruct { let data_hash = crate::hash::hash(&C::id_fields(&fields)); let (query_key, current_deps, disambiguator) = runtime.disambiguate_entity(self.ingredient_index, Revision::start(), data_hash); - let entity_key = TrackedStructKey { + let entity_key = KeyStruct { query_key, disambiguator, data_hash, @@ -283,7 +283,7 @@ where self.struct_map.insert( runtime, - TrackedStructValue { + ValueStruct { id, key: entity_key, struct_ingredient_index: self.ingredient_index, @@ -441,7 +441,7 @@ where const RESET_ON_NEW_REVISION: bool = true; } -impl TrackedStructValue +impl ValueStruct where C: Configuration, { diff --git a/components/salsa-2022/src/tracked_struct/struct_map.rs b/components/salsa-2022/src/tracked_struct/struct_map.rs index b95cd294..b9607b05 100644 --- a/components/salsa-2022/src/tracked_struct/struct_map.rs +++ b/components/salsa-2022/src/tracked_struct/struct_map.rs @@ -12,27 +12,27 @@ use crate::{ Id, Runtime, }; -use super::{Configuration, TrackedStructKey, TrackedStructValue}; +use super::{Configuration, KeyStruct, ValueStruct}; pub(crate) struct StructMap where C: Configuration, { - map: Arc>>>, + map: Arc>>>, /// When specific entities are deleted, their data is added /// to this vector rather than being immediately freed. This is because we may` have /// references to that data floating about that are tied to the lifetime of some /// `&db` reference. This queue itself is not freed until we have an `&mut db` reference, /// guaranteeing that there are no more references to it. - deleted_entries: SegQueue>>, + deleted_entries: SegQueue>>, } pub(crate) struct StructMapView where C: Configuration, { - map: Arc>>>, + map: Arc>>>, } /// Return value for [`StructMap`][]'s `update` method. @@ -49,7 +49,7 @@ where /// to this struct creation were up-to-date, and therefore the field contents /// ought not to have changed (barring user error). Returns a shared reference /// because caller cannot safely modify fields at this point. - Current(&'db TrackedStructValue), + Current(&'db ValueStruct), } impl StructMap @@ -76,11 +76,7 @@ where /// /// * If value with same `value.id` is already present in the map. /// * If value not created in current revision. - pub fn insert<'db>( - &'db self, - runtime: &'db Runtime, - value: TrackedStructValue, - ) -> &TrackedStructValue { + pub fn insert<'db>(&'db self, runtime: &'db Runtime, value: ValueStruct) -> &ValueStruct { assert_eq!(value.created_at, runtime.current_revision()); let boxed_value = Box::new(value); @@ -159,12 +155,12 @@ where /// * If the value is not present in the map. /// * If the value has not been updated in this revision. fn get_from_map<'db>( - map: &'db FxDashMap>>, + map: &'db FxDashMap>>, runtime: &'db Runtime, id: Id, - ) -> &'db TrackedStructValue { + ) -> &'db ValueStruct { let data = map.get(&id).unwrap(); - let data: &TrackedStructValue = &**data; + let data: &ValueStruct = &**data; // Before we drop the lock, check that the value has // been updated in this revision. This is what allows us to return a `` @@ -186,7 +182,7 @@ where /// Remove the entry for `id` from the map. /// /// NB. the data won't actually be freed until `drop_deleted_entries` is called. - pub fn delete(&self, id: Id) -> Option { + pub fn delete(&self, id: Id) -> Option { if let Some((_, data)) = self.map.remove(&id) { let key = data.key; self.deleted_entries.push(data); @@ -212,7 +208,7 @@ where /// /// * If the value is not present in the map. /// * If the value has not been updated in this revision. - pub fn get<'db>(&'db self, runtime: &'db Runtime, id: Id) -> &'db TrackedStructValue { + pub fn get<'db>(&'db self, runtime: &'db Runtime, id: Id) -> &'db ValueStruct { StructMap::get_from_map(&self.map, runtime, id) } } @@ -224,7 +220,7 @@ pub(crate) struct UpdateRef<'db, C> where C: Configuration, { - guard: RefMut<'db, Id, Box>, FxHasher>, + guard: RefMut<'db, Id, Box>, FxHasher>, } impl<'db, C> UpdateRef<'db, C> @@ -232,11 +228,11 @@ where C: Configuration, { /// Finalize this update, freezing the value for the rest of the revision. - pub fn freeze(self) -> &'db TrackedStructValue { + pub fn freeze(self) -> &'db ValueStruct { // Unsafety clause: // // see `get` above - let data: &TrackedStructValue = &*self.guard; + let data: &ValueStruct = &*self.guard; let dummy: &'db () = &(); unsafe { transmute_lifetime(dummy, data) } } @@ -246,7 +242,7 @@ impl Deref for UpdateRef<'_, C> where C: Configuration, { - type Target = TrackedStructValue; + type Target = ValueStruct; fn deref(&self) -> &Self::Target { &self.guard