rename from TrackedStruct to just Struct

this will let us use different packages
but the same struct name from salsa struct
This commit is contained in:
Niko Matsakis 2024-05-15 21:13:54 -04:00
parent 5095d79d13
commit 0b8c27bc30
4 changed files with 34 additions and 38 deletions

View file

@ -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

View file

@ -309,8 +309,8 @@ impl<A: AllowedOptions> SalsaStruct<A> {
#(#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 > >
);
})
}

View file

@ -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<TrackedStructKey, Id>,
keys: FxDashMap<KeyStruct, Id>,
/// The number of tracked structs created.
counter: AtomicCell<u32>,
@ -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<C>
pub struct ValueStruct<C>
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<C> {
) -> &'db ValueStruct<C> {
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<C> TrackedStructValue<C>
impl<C> ValueStruct<C>
where
C: Configuration,
{

View file

@ -12,27 +12,27 @@ use crate::{
Id, Runtime,
};
use super::{Configuration, TrackedStructKey, TrackedStructValue};
use super::{Configuration, KeyStruct, ValueStruct};
pub(crate) struct StructMap<C>
where
C: Configuration,
{
map: Arc<FxDashMap<Id, Box<TrackedStructValue<C>>>>,
map: Arc<FxDashMap<Id, Box<ValueStruct<C>>>>,
/// 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<Box<TrackedStructValue<C>>>,
deleted_entries: SegQueue<Box<ValueStruct<C>>>,
}
pub(crate) struct StructMapView<C>
where
C: Configuration,
{
map: Arc<FxDashMap<Id, Box<TrackedStructValue<C>>>>,
map: Arc<FxDashMap<Id, Box<ValueStruct<C>>>>,
}
/// 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<C>),
Current(&'db ValueStruct<C>),
}
impl<C> StructMap<C>
@ -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<C>,
) -> &TrackedStructValue<C> {
pub fn insert<'db>(&'db self, runtime: &'db Runtime, value: ValueStruct<C>) -> &ValueStruct<C> {
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<Id, Box<TrackedStructValue<C>>>,
map: &'db FxDashMap<Id, Box<ValueStruct<C>>>,
runtime: &'db Runtime,
id: Id,
) -> &'db TrackedStructValue<C> {
) -> &'db ValueStruct<C> {
let data = map.get(&id).unwrap();
let data: &TrackedStructValue<C> = &**data;
let data: &ValueStruct<C> = &**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<TrackedStructKey> {
pub fn delete(&self, id: Id) -> Option<KeyStruct> {
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<C> {
pub fn get<'db>(&'db self, runtime: &'db Runtime, id: Id) -> &'db ValueStruct<C> {
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<TrackedStructValue<C>>, FxHasher>,
guard: RefMut<'db, Id, Box<ValueStruct<C>>, 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<C> {
pub fn freeze(self) -> &'db ValueStruct<C> {
// Unsafety clause:
//
// see `get` above
let data: &TrackedStructValue<C> = &*self.guard;
let data: &ValueStruct<C> = &*self.guard;
let dummy: &'db () = &();
unsafe { transmute_lifetime(dummy, data) }
}
@ -246,7 +242,7 @@ impl<C> Deref for UpdateRef<'_, C>
where
C: Configuration,
{
type Target = TrackedStructValue<C>;
type Target = ValueStruct<C>;
fn deref(&self) -> &Self::Target {
&self.guard