From c84f88d23ab0ae34e4bb35eaa35a3d6f461a8b78 Mon Sep 17 00:00:00 2001 From: zjp Date: Sun, 21 Aug 2022 23:47:27 +0800 Subject: [PATCH 01/17] fmt --- components/salsa-2022/src/function.rs | 34 ++++++++++++++----------- components/salsa-2022/src/ingredient.rs | 25 ++++++++++-------- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/components/salsa-2022/src/function.rs b/components/salsa-2022/src/function.rs index cfadc8c4..9603f6df 100644 --- a/components/salsa-2022/src/function.rs +++ b/components/salsa-2022/src/function.rs @@ -30,15 +30,17 @@ mod store; mod sync; /// Function ingredients are the "workhorse" of salsa. -/// They are used for tracked functions, for the "value" fields of tracked structs, and for the fields of input structs. -/// The function ingredient is fairly complex and so its code is spread across multiple modules, typically one per method. -/// The main entry points are: +/// They are used for tracked functions, for the "value" fields of tracked structs, and for the +/// fields of input structs. The function ingredient is fairly complex and so its code is +/// spread across multiple modules, typically one per method. The main entry points are: /// -/// * the `fetch` method, which is invoked when the function is called by the user's code; -/// it will return a memoized value if one exists, or execute the function otherwise. -/// * the `specify` method, which can only be used when the key is an entity created by the active query. -/// It sets the value of the function imperatively, so that when later fetches occur, they'll return this value. -/// * the `store` method, which can only be invoked with an `&mut` reference, and is to set input fields. +/// * the `fetch` method, which is invoked when the function is called by the user's code; it +/// will return a memoized value if one exists, or execute the function otherwise. +/// * the `specify` method, which can only be used when the key is an entity created by the +/// active query. It sets the value of the function imperatively, so that when later fetches +/// occur, they'll return this value. +/// * the `store` method, which can only be invoked with an `&mut` reference, and is to set +/// input fields. pub struct FunctionIngredient { /// The ingredient index we were assigned in the database. /// Used to construct `DatabaseKeyIndex` values. @@ -95,8 +97,8 @@ pub trait Configuration { /// Invokes after a new result `new_value`` has been computed for which an older memoized /// value existed `old_value`. Returns true if the new value is equal to the older one - /// and hence should be "backdated" (i.e., marked as having last changed in an older revision, - /// even though it was recomputed). + /// and hence should be "backdated" (i.e., marked as having last changed in an older + /// revision, even though it was recomputed). /// /// This invokes user's code in form of the `Eq` impl. fn should_backdate_value(old_value: &Self::Value, new_value: &Self::Value) -> bool; @@ -183,8 +185,9 @@ where self.register(db); let memo = Arc::new(memo); let value = unsafe { - // Unsafety conditions: memo must be in the map (it's not yet, but it will be by the time this - // value is returned) and anything removed from map is added to deleted entries (ensured elsewhere). + // Unsafety conditions: memo must be in the map (it's not yet, but it will be by the + // time this value is returned) and anything removed from map is added to + // deleted entries (ensured elsewhere). self.extend_memo_lifetime(&memo) }; if let Some(old_value) = self.memo_map.insert(key, memo) { @@ -241,9 +244,10 @@ where _executor: DatabaseKeyIndex, _stale_output_key: Option, ) { - // This function is invoked when a query Q specifies the value for `stale_output_key` in rev 1, - // but not in rev 2. We don't do anything in this case, we just leave the (now stale) memo. - // Since its `verified_at` field has not changed, it will be considered dirty if it is invoked. + // This function is invoked when a query Q specifies the value for `stale_output_key` + // in rev 1, but not in rev 2. We don't do anything in this case, we just leave + // the (now stale) memo. Since its `verified_at` field has not changed, it will + // be considered dirty if it is invoked. } fn reset_for_new_revision(&mut self) { diff --git a/components/salsa-2022/src/ingredient.rs b/components/salsa-2022/src/ingredient.rs index 06b1a903..89ebb4cf 100644 --- a/components/salsa-2022/src/ingredient.rs +++ b/components/salsa-2022/src/ingredient.rs @@ -7,11 +7,13 @@ use super::Revision; /// "Ingredients" are the bits of data that are stored within the database to make salsa work. /// Each jar will define some number of ingredients that it requires. -/// Each use salsa macro (e.g., `#[salsa::tracked]`, `#[salsa::interned]`) adds one or more ingredients to the jar struct -/// that together are used to create the salsa concept. -/// For example, a tracked struct defines a [`crate::interned::InternedIngredient`] to store its identity -/// plus [`crate::function::FunctionIngredient`] values to store its fields. -/// The exact ingredients are determined by [`IngredientsFor`](`crate::storage::IngredientsFor`) implementations generated by the macro. +/// Each use salsa macro (e.g., `#[salsa::tracked]`, `#[salsa::interned]`) adds one or more +/// ingredients to the jar struct that together are used to create the salsa concept. +/// For example, a tracked struct defines a [`crate::interned::InternedIngredient`] to store +/// its identity plus [`crate::function::FunctionIngredient`] values to store its fields. +/// The exact ingredients are determined by +/// [`IngredientsFor`](`crate::storage::IngredientsFor`) implementations generated by the +/// macro. pub trait Ingredient { /// If this ingredient is a participant in a cycle, what is its cycle recovery strategy? /// (Really only relevant to [`crate::function::FunctionIngredient`], @@ -25,7 +27,8 @@ pub trait Ingredient { fn origin(&self, key_index: Id) -> Option; /// Invoked when the value `output_key` should be marked as valid in the current revision. - /// This occurs because the value for `executor`, which generated it, was marked as valid in the current revision. + /// This occurs because the value for `executor`, which generated it, was marked as valid + /// in the current revision. fn mark_validated_output(&self, db: &DB, executor: DatabaseKeyIndex, output_key: Option); /// Invoked when the value `stale_output` was output by `executor` in a previous @@ -46,11 +49,12 @@ pub trait Ingredient { fn salsa_struct_deleted(&self, db: &DB, id: Id); /// Invoked when a new revision is about to start. - /// This moment is important because it means that we have an `&mut`-reference to the database, - /// and hence any pre-existing `&`-references must have expired. + /// This moment is important because it means that we have an `&mut`-reference to the + /// database, and hence any pre-existing `&`-references must have expired. /// Many ingredients, given an `&'db`-reference to the database, /// use unsafe code to return `&'db`-references to internal values. - /// The backing memory for those values can only be freed once an `&mut`-reference to the database is created. + /// The backing memory for those values can only be freed once an `&mut`-reference to the + /// database is created. /// /// **Important:** to actually receive resets, the ingredient must set /// [`IngredientRequiresReset::RESET_ON_NEW_REVISION`] to true. @@ -58,7 +62,8 @@ pub trait Ingredient { } /// Defines a const indicating if an ingredient needs to be reset each round. -/// This const probably *should* be a member of `Ingredient` trait but then `Ingredient` would not be dyn-safe. +/// This const probably *should* be a member of `Ingredient` trait but then `Ingredient` would +/// not be dyn-safe. pub trait IngredientRequiresReset { /// If this is true, then `reset_for_new_revision` will be called every new revision. const RESET_ON_NEW_REVISION: bool; From 70b0340b81cc4acaaf09efd56c1c255122cd4289 Mon Sep 17 00:00:00 2001 From: zjp Date: Sun, 21 Aug 2022 23:55:29 +0800 Subject: [PATCH 02/17] feat(fmt_index): added in `Ingredient` trait --- components/salsa-2022-macros/src/db.rs | 4 ++++ components/salsa-2022-macros/src/input.rs | 3 ++- components/salsa-2022-macros/src/tracked_fn.rs | 5 ++++- components/salsa-2022/src/accumulator.rs | 8 ++++++++ components/salsa-2022/src/function.rs | 13 ++++++++++++- components/salsa-2022/src/ingredient.rs | 6 ++++++ components/salsa-2022/src/input.rs | 12 +++++++++++- components/salsa-2022/src/input_field.rs | 8 ++++++++ components/salsa-2022/src/interned.rs | 8 ++++++++ components/salsa-2022/src/storage.rs | 6 ++++++ components/salsa-2022/src/tracked_struct.rs | 8 ++++++++ 11 files changed, 77 insertions(+), 4 deletions(-) diff --git a/components/salsa-2022-macros/src/db.rs b/components/salsa-2022-macros/src/db.rs index 54c22ab8..b6fe5720 100644 --- a/components/salsa-2022-macros/src/db.rs +++ b/components/salsa-2022-macros/src/db.rs @@ -159,6 +159,10 @@ fn has_jars_dyn_impl(input: &syn::ItemStruct, storage: &syn::Ident) -> syn::Item let ingredient = self.#storage.ingredient(ingredient); ingredient.salsa_struct_deleted(self, id); } + fn fmt_index(&self, index: salsa::DependencyIndex, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let ingredient = self.#storage.ingredient(ingredient); + ingredient.fmt_index(self, index, fmt) + } } } } diff --git a/components/salsa-2022-macros/src/input.rs b/components/salsa-2022-macros/src/input.rs index 9932226b..d2d5c9e4 100644 --- a/components/salsa-2022-macros/src/input.rs +++ b/components/salsa-2022-macros/src/input.rs @@ -135,6 +135,7 @@ impl InputStruct { let jar_ty = self.jar_ty(); let all_field_indices: Vec = self.all_field_indices(); let input_index: Literal = self.input_index(); + let debug_name = Literal::string(&format!("{}", self.id_ident())); parse_quote! { impl salsa::storage::IngredientsFor for #ident { @@ -183,7 +184,7 @@ impl InputStruct { &mut ingredients.#input_index }, ); - salsa::input::InputIngredient::new(index) + salsa::input::InputIngredient::new(index, #debug_name) }, ) } diff --git a/components/salsa-2022-macros/src/tracked_fn.rs b/components/salsa-2022-macros/src/tracked_fn.rs index 355a7668..0af8393d 100644 --- a/components/salsa-2022-macros/src/tracked_fn.rs +++ b/components/salsa-2022-macros/src/tracked_fn.rs @@ -242,6 +242,9 @@ fn ingredients_for_impl( // set 0 as default to disable LRU let lru = args.lru.unwrap_or(0); + // get the name of the function as a string literal + let debug_name = Literal::string(&format!("{}", item_fn.sig.ident)); + parse_quote! { impl salsa::storage::IngredientsFor for #config_ty { type Ingredients = Self; @@ -268,7 +271,7 @@ fn ingredients_for_impl( <_ as salsa::storage::HasIngredientsFor>::ingredient_mut(jar); &mut ingredients.function }); - let ingredient = salsa::function::FunctionIngredient::new(index); + let ingredient = salsa::function::FunctionIngredient::new(index, #debug_name); ingredient.set_capacity(#lru); ingredient } diff --git a/components/salsa-2022/src/accumulator.rs b/components/salsa-2022/src/accumulator.rs index 1d91a405..1df998d0 100644 --- a/components/salsa-2022/src/accumulator.rs +++ b/components/salsa-2022/src/accumulator.rs @@ -148,6 +148,14 @@ where fn salsa_struct_deleted(&self, _db: &DB, _id: crate::Id) { panic!("unexpected call: accumulator is not registered as a dependent fn"); } + + fn fmt_index( + &self, + _index: Option, + _fmt: &mut std::fmt::Formatter<'_>, + ) -> std::fmt::Result { + todo!() + } } impl IngredientRequiresReset for AccumulatorIngredient diff --git a/components/salsa-2022/src/function.rs b/components/salsa-2022/src/function.rs index 9603f6df..929e9b56 100644 --- a/components/salsa-2022/src/function.rs +++ b/components/salsa-2022/src/function.rs @@ -73,6 +73,8 @@ pub struct FunctionIngredient { /// Set to true once we invoke `register_dependent_fn` for `C::SalsaStruct`. /// Prevents us from registering more than once. registered: AtomicCell, + + debug_name: &'static str, } pub trait Configuration { @@ -139,7 +141,7 @@ impl FunctionIngredient where C: Configuration, { - pub fn new(index: IngredientIndex) -> Self { + pub fn new(index: IngredientIndex, debug_name: &'static str) -> Self { Self { index, memo_map: memo::MemoMap::default(), @@ -147,6 +149,7 @@ where sync_map: Default::default(), deleted_entries: Default::default(), registered: Default::default(), + debug_name, } } @@ -273,6 +276,14 @@ where } } } + + fn fmt_index( + &self, + _index: Option, + _fmt: &mut std::fmt::Formatter<'_>, + ) -> std::fmt::Result { + todo!() + } } impl IngredientRequiresReset for FunctionIngredient diff --git a/components/salsa-2022/src/ingredient.rs b/components/salsa-2022/src/ingredient.rs index 89ebb4cf..729011dc 100644 --- a/components/salsa-2022/src/ingredient.rs +++ b/components/salsa-2022/src/ingredient.rs @@ -59,6 +59,12 @@ pub trait Ingredient { /// **Important:** to actually receive resets, the ingredient must set /// [`IngredientRequiresReset::RESET_ON_NEW_REVISION`] to true. fn reset_for_new_revision(&mut self); + + fn fmt_index( + &self, + index: Option, + fmt: &mut std::fmt::Formatter<'_>, + ) -> std::fmt::Result; } /// Defines a const indicating if an ingredient needs to be reset each round. diff --git a/components/salsa-2022/src/input.rs b/components/salsa-2022/src/input.rs index f6dc35cf..7059ca6f 100644 --- a/components/salsa-2022/src/input.rs +++ b/components/salsa-2022/src/input.rs @@ -15,6 +15,7 @@ where { ingredient_index: IngredientIndex, counter: u32, + debug_name: &'static str, _phantom: std::marker::PhantomData, } @@ -22,10 +23,11 @@ impl InputIngredient where Id: InputId, { - pub fn new(index: IngredientIndex) -> Self { + pub fn new(index: IngredientIndex, debug_name: &'static str) -> Self { Self { ingredient_index: index, counter: Default::default(), + debug_name, _phantom: std::marker::PhantomData, } } @@ -95,6 +97,14 @@ where "unexpected call: input ingredients do not register for salsa struct deletion events" ); } + + fn fmt_index( + &self, + _index: Option, + _fmt: &mut std::fmt::Formatter<'_>, + ) -> std::fmt::Result { + todo!() + } } impl IngredientRequiresReset for InputIngredient diff --git a/components/salsa-2022/src/input_field.rs b/components/salsa-2022/src/input_field.rs index 8204e60b..54ce093a 100644 --- a/components/salsa-2022/src/input_field.rs +++ b/components/salsa-2022/src/input_field.rs @@ -113,6 +113,14 @@ where fn reset_for_new_revision(&mut self) { panic!("unexpected call: input fields don't register for resets"); } + + fn fmt_index( + &self, + _index: Option, + _fmt: &mut std::fmt::Formatter<'_>, + ) -> std::fmt::Result { + todo!() + } } impl IngredientRequiresReset for InputFieldIngredient diff --git a/components/salsa-2022/src/interned.rs b/components/salsa-2022/src/interned.rs index e30c1235..e6bd7f6e 100644 --- a/components/salsa-2022/src/interned.rs +++ b/components/salsa-2022/src/interned.rs @@ -234,6 +234,14 @@ where fn salsa_struct_deleted(&self, _db: &DB, _id: crate::Id) { panic!("unexpected call: interned ingredients do not register for salsa struct deletion events"); } + + fn fmt_index( + &self, + _index: Option, + _fmt: &mut std::fmt::Formatter<'_>, + ) -> std::fmt::Result { + todo!() + } } impl IngredientRequiresReset for InternedIngredient diff --git a/components/salsa-2022/src/storage.rs b/components/salsa-2022/src/storage.rs index bf5ba0ea..7d37fd75 100644 --- a/components/salsa-2022/src/storage.rs +++ b/components/salsa-2022/src/storage.rs @@ -220,6 +220,12 @@ pub trait HasJarsDyn { /// as a dependent function using /// [`SalsaStructInDb::register_dependent_fn`](`crate::salsa_struct::SalsaStructInDb::register_dependent_fn`). fn salsa_struct_deleted(&self, ingredient: IngredientIndex, id: Id); + + fn fmt_index( + &self, + index: DependencyIndex, + fmt: &mut std::fmt::Formatter<'_>, + ) -> std::fmt::Result; } // ANCHOR_END: HasJarsDyn diff --git a/components/salsa-2022/src/tracked_struct.rs b/components/salsa-2022/src/tracked_struct.rs index 98ebf6d4..675a3985 100644 --- a/components/salsa-2022/src/tracked_struct.rs +++ b/components/salsa-2022/src/tracked_struct.rs @@ -175,6 +175,14 @@ where fn salsa_struct_deleted(&self, _db: &DB, _id: crate::Id) { panic!("unexpected call: interned ingredients do not register for salsa struct deletion events"); } + + fn fmt_index( + &self, + _index: Option, + _fmt: &mut std::fmt::Formatter<'_>, + ) -> std::fmt::Result { + todo!() + } } impl IngredientRequiresReset for TrackedStructIngredient From 0d7066c554a6940689df78b81f6d186e17b4b4b8 Mon Sep 17 00:00:00 2001 From: zjp Date: Mon, 22 Aug 2022 00:57:09 +0800 Subject: [PATCH 03/17] fix(clippy): follow the advice --- components/salsa-2022-macros/src/db.rs | 4 ++-- .../salsa-2022-macros/src/tracked_fn.rs | 22 ++++++++----------- .../salsa-2022-macros/src/tracked_struct.rs | 4 ++-- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/components/salsa-2022-macros/src/db.rs b/components/salsa-2022-macros/src/db.rs index b6fe5720..62ae6ad9 100644 --- a/components/salsa-2022-macros/src/db.rs +++ b/components/salsa-2022-macros/src/db.rs @@ -55,10 +55,10 @@ impl syn::parse::Parse for Args { } fn find_storage_field(input: &syn::ItemStruct) -> Result { - let storage = format!("storage"); + let storage = "storage"; for field in input.fields.iter() { if let Some(i) = &field.ident { - if i.to_string() == storage { + if i == storage { return Ok(i.clone()); } } else { diff --git a/components/salsa-2022-macros/src/tracked_fn.rs b/components/salsa-2022-macros/src/tracked_fn.rs index 0af8393d..9e05c77f 100644 --- a/components/salsa-2022-macros/src/tracked_fn.rs +++ b/components/salsa-2022-macros/src/tracked_fn.rs @@ -12,7 +12,7 @@ pub(crate) fn tracked( let args = syn::parse_macro_input!(args as Args); match tracked_fn(args, item_fn) { Ok(p) => p.into(), - Err(e) => return e.into_compile_error().into(), + Err(e) => e.into_compile_error().into(), } } @@ -145,7 +145,7 @@ fn fn_configuration(args: &Args, item_fn: &syn::ItemFn) -> Configuration { let fn_ty = item_fn.sig.ident.clone(); - let indices = (0..item_fn.sig.inputs.len() - 1).map(|i| Literal::usize_unsuffixed(i)); + let indices = (0..item_fn.sig.inputs.len() - 1).map(Literal::usize_unsuffixed); let (cycle_strategy, recover_fn) = if let Some(recovery_fn) = &args.recovery_fn { // Create the `recover_from_cycle` function, which (a) maps from the interned id to the actual // keys and then (b) invokes the recover function itself. @@ -181,7 +181,7 @@ fn fn_configuration(args: &Args, item_fn: &syn::ItemFn) -> Configuration { // Create the `execute` function, which (a) maps from the interned id to the actual // keys and then (b) invokes the function itself (which we embed within). - let indices = (0..item_fn.sig.inputs.len() - 1).map(|i| Literal::usize_unsuffixed(i)); + let indices = (0..item_fn.sig.inputs.len() - 1).map(Literal::usize_unsuffixed); let execute_fn = parse_quote! { fn execute(__db: &salsa::function::DynDb, __id: Self::Key) -> Self::Value { #inner_fn @@ -487,9 +487,7 @@ fn make_fn_return_ref(mut ref_getter_fn: syn::ItemFn) -> syn::Result syn::Result<(syn::Lifetime, &syn::Type)> { match &mut func.sig.inputs[0] { - syn::FnArg::Receiver(r) => { - return Err(syn::Error::new(r.span(), "expected database, not self")) - } + syn::FnArg::Receiver(r) => Err(syn::Error::new(r.span(), "expected database, not self")), syn::FnArg::Typed(pat_ty) => match &mut *pat_ty.ty { syn::Type::Reference(ty) => match &ty.lifetime { Some(lt) => Ok((lt.clone(), &pat_ty.ty)), @@ -517,12 +515,10 @@ fn db_lifetime_and_ty(func: &mut syn::ItemFn) -> syn::Result<(syn::Lifetime, &sy Ok((db_lifetime, &pat_ty.ty)) } }, - _ => { - return Err(syn::Error::new( - pat_ty.span(), - "expected database to be a `&` type", - )) - } + _ => Err(syn::Error::new( + pat_ty.span(), + "expected database to be a `&` type", + )), }, } } @@ -574,7 +570,7 @@ fn accumulated_fn( /// * the name(s) of the key arguments fn fn_args(item_fn: &syn::ItemFn) -> syn::Result<(proc_macro2::Ident, Vec)> { // Check that we have no receiver and that all argments have names - if item_fn.sig.inputs.len() == 0 { + if item_fn.sig.inputs.is_empty() { return Err(syn::Error::new( item_fn.sig.span(), "method needs a database argument", diff --git a/components/salsa-2022-macros/src/tracked_struct.rs b/components/salsa-2022-macros/src/tracked_struct.rs index 5212e5b0..3bc47ae6 100644 --- a/components/salsa-2022-macros/src/tracked_struct.rs +++ b/components/salsa-2022-macros/src/tracked_struct.rs @@ -279,14 +279,14 @@ impl TrackedStruct { /// of the function ingredients within that tuple. fn value_field_indices(&self) -> Vec { (0..self.value_fields().count()) - .map(|i| Literal::usize_unsuffixed(i)) + .map(Literal::usize_unsuffixed) .collect() } /// Indices of each of the id fields fn id_field_indices(&self) -> Vec { (0..self.id_fields().count()) - .map(|i| Literal::usize_unsuffixed(i)) + .map(Literal::usize_unsuffixed) .collect() } } From 525a9fec4c718aba14c893d5b5a45ebf2d75f6aa Mon Sep 17 00:00:00 2001 From: zjp Date: Mon, 22 Aug 2022 01:00:16 +0800 Subject: [PATCH 04/17] fix(fmt_index): proc macro expansion --- components/salsa-2022-macros/src/db.rs | 6 +++--- components/salsa-2022-macros/src/tracked_fn.rs | 2 +- components/salsa-2022-macros/src/tracked_struct.rs | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/components/salsa-2022-macros/src/db.rs b/components/salsa-2022-macros/src/db.rs index 62ae6ad9..fabb706e 100644 --- a/components/salsa-2022-macros/src/db.rs +++ b/components/salsa-2022-macros/src/db.rs @@ -159,9 +159,9 @@ fn has_jars_dyn_impl(input: &syn::ItemStruct, storage: &syn::Ident) -> syn::Item let ingredient = self.#storage.ingredient(ingredient); ingredient.salsa_struct_deleted(self, id); } - fn fmt_index(&self, index: salsa::DependencyIndex, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let ingredient = self.#storage.ingredient(ingredient); - ingredient.fmt_index(self, index, fmt) + fn fmt_index(&self, index: salsa::key::DependencyIndex, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let ingredient = self.#storage.ingredient(index.ingredient_index()); + ingredient.fmt_index(index.key_index(), fmt) } } } diff --git a/components/salsa-2022-macros/src/tracked_fn.rs b/components/salsa-2022-macros/src/tracked_fn.rs index 9e05c77f..39547d1f 100644 --- a/components/salsa-2022-macros/src/tracked_fn.rs +++ b/components/salsa-2022-macros/src/tracked_fn.rs @@ -243,7 +243,7 @@ fn ingredients_for_impl( let lru = args.lru.unwrap_or(0); // get the name of the function as a string literal - let debug_name = Literal::string(&format!("{}", item_fn.sig.ident)); + let debug_name = Literal::string(&item_fn.sig.ident.to_string()); parse_quote! { impl salsa::storage::IngredientsFor for #config_ty { diff --git a/components/salsa-2022-macros/src/tracked_struct.rs b/components/salsa-2022-macros/src/tracked_struct.rs index 3bc47ae6..c20e298a 100644 --- a/components/salsa-2022-macros/src/tracked_struct.rs +++ b/components/salsa-2022-macros/src/tracked_struct.rs @@ -159,6 +159,7 @@ impl TrackedStruct { let value_field_indices: Vec = self.value_field_indices(); let tracked_struct_index: Literal = self.tracked_struct_index(); let config_struct_names = config_structs.iter().map(|s| &s.ident); + let debug_name = Literal::string(&self.id_ident().to_string()); parse_quote! { impl salsa::storage::IngredientsFor for #ident { @@ -191,7 +192,7 @@ impl TrackedStruct { &mut ingredients.#value_field_indices }, ); - salsa::function::FunctionIngredient::new(index) + salsa::function::FunctionIngredient::new(index, #debug_name) }, )* { From 9f9b46f5e0f8ae9f62768fb0a9eb71843348d834 Mon Sep 17 00:00:00 2001 From: zjp Date: Mon, 22 Aug 2022 08:36:13 +0800 Subject: [PATCH 05/17] revert fmt --- components/salsa-2022/src/function.rs | 34 ++++++++++++--------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/components/salsa-2022/src/function.rs b/components/salsa-2022/src/function.rs index 929e9b56..d531a02b 100644 --- a/components/salsa-2022/src/function.rs +++ b/components/salsa-2022/src/function.rs @@ -30,17 +30,15 @@ mod store; mod sync; /// Function ingredients are the "workhorse" of salsa. -/// They are used for tracked functions, for the "value" fields of tracked structs, and for the -/// fields of input structs. The function ingredient is fairly complex and so its code is -/// spread across multiple modules, typically one per method. The main entry points are: +/// They are used for tracked functions, for the "value" fields of tracked structs, and for the fields of input structs. +/// The function ingredient is fairly complex and so its code is spread across multiple modules, typically one per method. +/// The main entry points are: /// -/// * the `fetch` method, which is invoked when the function is called by the user's code; it -/// will return a memoized value if one exists, or execute the function otherwise. -/// * the `specify` method, which can only be used when the key is an entity created by the -/// active query. It sets the value of the function imperatively, so that when later fetches -/// occur, they'll return this value. -/// * the `store` method, which can only be invoked with an `&mut` reference, and is to set -/// input fields. +/// * the `fetch` method, which is invoked when the function is called by the user's code; +/// it will return a memoized value if one exists, or execute the function otherwise. +/// * the `specify` method, which can only be used when the key is an entity created by the active query. +/// It sets the value of the function imperatively, so that when later fetches occur, they'll return this value. +/// * the `store` method, which can only be invoked with an `&mut` reference, and is to set input fields. pub struct FunctionIngredient { /// The ingredient index we were assigned in the database. /// Used to construct `DatabaseKeyIndex` values. @@ -99,8 +97,8 @@ pub trait Configuration { /// Invokes after a new result `new_value`` has been computed for which an older memoized /// value existed `old_value`. Returns true if the new value is equal to the older one - /// and hence should be "backdated" (i.e., marked as having last changed in an older - /// revision, even though it was recomputed). + /// and hence should be "backdated" (i.e., marked as having last changed in an older revision, + /// even though it was recomputed). /// /// This invokes user's code in form of the `Eq` impl. fn should_backdate_value(old_value: &Self::Value, new_value: &Self::Value) -> bool; @@ -188,9 +186,8 @@ where self.register(db); let memo = Arc::new(memo); let value = unsafe { - // Unsafety conditions: memo must be in the map (it's not yet, but it will be by the - // time this value is returned) and anything removed from map is added to - // deleted entries (ensured elsewhere). + // Unsafety conditions: memo must be in the map (it's not yet, but it will be by the time this + // value is returned) and anything removed from map is added to deleted entries (ensured elsewhere). self.extend_memo_lifetime(&memo) }; if let Some(old_value) = self.memo_map.insert(key, memo) { @@ -247,10 +244,9 @@ where _executor: DatabaseKeyIndex, _stale_output_key: Option, ) { - // This function is invoked when a query Q specifies the value for `stale_output_key` - // in rev 1, but not in rev 2. We don't do anything in this case, we just leave - // the (now stale) memo. Since its `verified_at` field has not changed, it will - // be considered dirty if it is invoked. + // This function is invoked when a query Q specifies the value for `stale_output_key` in rev 1, + // but not in rev 2. We don't do anything in this case, we just leave the (now stale) memo. + // Since its `verified_at` field has not changed, it will be considered dirty if it is invoked. } fn reset_for_new_revision(&mut self) { From 67fd9792f095c4c9989ca5b19501ecf11002a4e9 Mon Sep 17 00:00:00 2001 From: zjp Date: Mon, 22 Aug 2022 10:03:03 +0800 Subject: [PATCH 06/17] fix(fmt_index): implement with the helper function --- components/salsa-2022/src/function.rs | 14 +++++++------- components/salsa-2022/src/ingredient.rs | 21 ++++++++++++++++----- components/salsa-2022/src/input.rs | 12 +++++------- components/salsa-2022/src/storage.rs | 8 ++------ 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/components/salsa-2022/src/function.rs b/components/salsa-2022/src/function.rs index d531a02b..ad43f3d3 100644 --- a/components/salsa-2022/src/function.rs +++ b/components/salsa-2022/src/function.rs @@ -1,11 +1,11 @@ -use std::sync::Arc; +use std::{sync::Arc, fmt}; use arc_swap::ArcSwap; use crossbeam::{atomic::AtomicCell, queue::SegQueue}; use crate::{ cycle::CycleRecoveryStrategy, - ingredient::IngredientRequiresReset, + ingredient::{IngredientRequiresReset, fmt_index}, jar::Jar, key::{DatabaseKeyIndex, DependencyIndex}, runtime::local_state::QueryOrigin, @@ -89,7 +89,7 @@ pub trait Configuration { type Key: AsId; /// The value computed by the function. - type Value: std::fmt::Debug; + type Value: fmt::Debug; /// Determines whether this function can recover from being a participant in a cycle /// (and, if so, how). @@ -275,10 +275,10 @@ where fn fmt_index( &self, - _index: Option, - _fmt: &mut std::fmt::Formatter<'_>, - ) -> std::fmt::Result { - todo!() + index: Option, + fmt: &mut fmt::Formatter<'_>, + ) -> fmt::Result { + fmt_index(self.debug_name, index, fmt) } } diff --git a/components/salsa-2022/src/ingredient.rs b/components/salsa-2022/src/ingredient.rs index 729011dc..5d051289 100644 --- a/components/salsa-2022/src/ingredient.rs +++ b/components/salsa-2022/src/ingredient.rs @@ -1,3 +1,5 @@ +use std::fmt; + use crate::{ cycle::CycleRecoveryStrategy, key::DependencyIndex, runtime::local_state::QueryOrigin, DatabaseKeyIndex, Id, @@ -60,11 +62,20 @@ pub trait Ingredient { /// [`IngredientRequiresReset::RESET_ON_NEW_REVISION`] to true. fn reset_for_new_revision(&mut self); - fn fmt_index( - &self, - index: Option, - fmt: &mut std::fmt::Formatter<'_>, - ) -> std::fmt::Result; + fn fmt_index(&self, index: Option, fmt: &mut fmt::Formatter<'_>) -> fmt::Result; +} + +/// A helper function to show human readable fmt. +pub(crate) fn fmt_index( + debug_name: &str, + id: Option, + fmt: &mut fmt::Formatter<'_>, +) -> fmt::Result { + if let Some(i) = id { + write!(fmt, "{}({})", debug_name, u32::from(i)) + } else { + write!(fmt, "{}()", debug_name) + } } /// Defines a const indicating if an ingredient needs to be reset each round. diff --git a/components/salsa-2022/src/input.rs b/components/salsa-2022/src/input.rs index 7059ca6f..f304e051 100644 --- a/components/salsa-2022/src/input.rs +++ b/components/salsa-2022/src/input.rs @@ -1,6 +1,8 @@ +use std::fmt; + use crate::{ cycle::CycleRecoveryStrategy, - ingredient::{Ingredient, IngredientRequiresReset}, + ingredient::{Ingredient, IngredientRequiresReset, fmt_index}, key::{DatabaseKeyIndex, DependencyIndex}, runtime::{local_state::QueryOrigin, Runtime}, AsId, IngredientIndex, Revision, @@ -98,12 +100,8 @@ where ); } - fn fmt_index( - &self, - _index: Option, - _fmt: &mut std::fmt::Formatter<'_>, - ) -> std::fmt::Result { - todo!() + fn fmt_index(&self, index: Option, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt_index(self.debug_name, index, fmt) } } diff --git a/components/salsa-2022/src/storage.rs b/components/salsa-2022/src/storage.rs index 7d37fd75..83e3d617 100644 --- a/components/salsa-2022/src/storage.rs +++ b/components/salsa-2022/src/storage.rs @@ -1,4 +1,4 @@ -use std::sync::Arc; +use std::{fmt, sync::Arc}; use parking_lot::Condvar; @@ -221,11 +221,7 @@ pub trait HasJarsDyn { /// [`SalsaStructInDb::register_dependent_fn`](`crate::salsa_struct::SalsaStructInDb::register_dependent_fn`). fn salsa_struct_deleted(&self, ingredient: IngredientIndex, id: Id); - fn fmt_index( - &self, - index: DependencyIndex, - fmt: &mut std::fmt::Formatter<'_>, - ) -> std::fmt::Result; + fn fmt_index(&self, index: DependencyIndex, fmt: &mut fmt::Formatter<'_>) -> fmt::Result; } // ANCHOR_END: HasJarsDyn From af747c1aca2dc36a2e878303c546720797b7b95a Mon Sep 17 00:00:00 2001 From: zjp Date: Mon, 22 Aug 2022 10:04:47 +0800 Subject: [PATCH 07/17] fix(fmt_index): impl for accumulator --- .../salsa-2022-macros/src/accumulator.rs | 38 ++++++++++--------- components/salsa-2022/src/accumulator.rs | 16 +++++--- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/components/salsa-2022-macros/src/accumulator.rs b/components/salsa-2022-macros/src/accumulator.rs index 55cb3f54..2f6b6221 100644 --- a/components/salsa-2022-macros/src/accumulator.rs +++ b/components/salsa-2022-macros/src/accumulator.rs @@ -48,7 +48,7 @@ fn accumulator_contents( let struct_ty = &parse_quote! {#struct_name}; let inherent_impl = inherent_impl(args, struct_ty, data_ty); - let ingredients_for_impl = ingredients_for_impl(args, struct_ty, data_ty); + let ingredients_for_impl = ingredients_for_impl(args, struct_name, data_ty); let struct_item_out = struct_item_out(args, struct_item, data_ty); let accumulator_impl = accumulator_impl(args, struct_ty, data_ty); @@ -61,23 +61,20 @@ fn accumulator_contents( } fn data_ty(struct_item: &syn::ItemStruct) -> syn::Result<&syn::Type> { - match &struct_item.fields { - syn::Fields::Unnamed(fields) => { - if fields.unnamed.len() != 1 { - return Err(syn::Error::new( - struct_item.ident.span(), - "accumulator structs should have only one anonymous field", - )); - } else { - Ok(&fields.unnamed[0].ty) - } - } - _ => { - return Err(syn::Error::new( + if let syn::Fields::Unnamed(fields) = &struct_item.fields { + if fields.unnamed.len() != 1 { + Err(syn::Error::new( struct_item.ident.span(), "accumulator structs should have only one anonymous field", - )); + )) + } else { + Ok(&fields.unnamed[0].ty) } + } else { + Err(syn::Error::new( + struct_item.ident.span(), + "accumulator structs should have only one anonymous field", + )) } } @@ -109,10 +106,15 @@ fn inherent_impl(args: &Args, struct_ty: &syn::Type, data_ty: &syn::Type) -> syn } } -fn ingredients_for_impl(args: &Args, struct_ty: &syn::Type, data_ty: &syn::Type) -> syn::ItemImpl { +fn ingredients_for_impl( + args: &Args, + struct_name: &syn::Ident, + data_ty: &syn::Type, +) -> syn::ItemImpl { let jar_ty = args.jar_ty(); + let debug_name = proc_macro2::Literal::string(&struct_name.to_string()); parse_quote! { - impl salsa::storage::IngredientsFor for #struct_ty { + impl salsa::storage::IngredientsFor for #struct_name { type Ingredients = salsa::accumulator::AccumulatorIngredient<#data_ty>; type Jar = #jar_ty; @@ -130,7 +132,7 @@ fn ingredients_for_impl(args: &Args, struct_ty: &syn::Type, data_ty: &syn::Type) <_ as salsa::storage::HasIngredientsFor>::ingredient_mut(jar) }, ); - salsa::accumulator::AccumulatorIngredient::new(index) + salsa::accumulator::AccumulatorIngredient::new(index, #debug_name) } } } diff --git a/components/salsa-2022/src/accumulator.rs b/components/salsa-2022/src/accumulator.rs index 1df998d0..7ea320b6 100644 --- a/components/salsa-2022/src/accumulator.rs +++ b/components/salsa-2022/src/accumulator.rs @@ -1,9 +1,11 @@ //! Basic test of accumulator functionality. +use std::fmt; + use crate::{ cycle::CycleRecoveryStrategy, hash::FxDashMap, - ingredient::{Ingredient, IngredientRequiresReset}, + ingredient::{Ingredient, IngredientRequiresReset, fmt_index}, key::DependencyIndex, runtime::local_state::QueryOrigin, storage::HasJar, @@ -21,6 +23,7 @@ pub trait Accumulator { pub struct AccumulatorIngredient { index: IngredientIndex, map: FxDashMap>, + debug_name: &'static str, } struct AccumulatedValues { @@ -29,10 +32,11 @@ struct AccumulatedValues { } impl AccumulatorIngredient { - pub fn new(index: IngredientIndex) -> Self { + pub fn new(index: IngredientIndex, debug_name: &'static str) -> Self { Self { map: FxDashMap::default(), index, + debug_name } } @@ -151,10 +155,10 @@ where fn fmt_index( &self, - _index: Option, - _fmt: &mut std::fmt::Formatter<'_>, - ) -> std::fmt::Result { - todo!() + index: Option, + fmt: &mut fmt::Formatter<'_>, + ) -> fmt::Result { + fmt_index(self.debug_name, index, fmt) } } From 78d78942667190ac1f576904512a955de31f5e71 Mon Sep 17 00:00:00 2001 From: zjp Date: Mon, 22 Aug 2022 10:10:57 +0800 Subject: [PATCH 08/17] fix(fmt_index): impl for InternedIngredient --- components/salsa-2022/src/interned.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/components/salsa-2022/src/interned.rs b/components/salsa-2022/src/interned.rs index e6bd7f6e..28119a9a 100644 --- a/components/salsa-2022/src/interned.rs +++ b/components/salsa-2022/src/interned.rs @@ -1,11 +1,12 @@ use crossbeam::atomic::AtomicCell; use crossbeam::queue::SegQueue; +use std::fmt; use std::hash::Hash; use std::marker::PhantomData; use crate::durability::Durability; use crate::id::AsId; -use crate::ingredient::IngredientRequiresReset; +use crate::ingredient::{fmt_index, IngredientRequiresReset}; use crate::key::DependencyIndex; use crate::runtime::local_state::QueryOrigin; use crate::runtime::Runtime; @@ -54,6 +55,8 @@ pub struct InternedIngredient { /// `&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>, + + debug_name: &'static str, } impl InternedIngredient @@ -69,6 +72,7 @@ where counter: AtomicCell::default(), reset_at: Revision::start(), deleted_entries: Default::default(), + debug_name: "InternedIngredient", } } @@ -235,12 +239,8 @@ where panic!("unexpected call: interned ingredients do not register for salsa struct deletion events"); } - fn fmt_index( - &self, - _index: Option, - _fmt: &mut std::fmt::Formatter<'_>, - ) -> std::fmt::Result { - todo!() + fn fmt_index(&self, index: Option, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt_index(self.debug_name, index, fmt) } } From b76ac29a0973efe45093b1337fa53946fdf3ab9c Mon Sep 17 00:00:00 2001 From: zjp Date: Mon, 22 Aug 2022 10:33:39 +0800 Subject: [PATCH 09/17] fix(fmt_index): impl for InputFieldIngredient --- components/salsa-2022-macros/src/input.rs | 11 ++++++++--- components/salsa-2022/src/input_field.rs | 15 +++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/components/salsa-2022-macros/src/input.rs b/components/salsa-2022-macros/src/input.rs index d2d5c9e4..aa7fbf6b 100644 --- a/components/salsa-2022-macros/src/input.rs +++ b/components/salsa-2022-macros/src/input.rs @@ -135,7 +135,12 @@ impl InputStruct { let jar_ty = self.jar_ty(); let all_field_indices: Vec = self.all_field_indices(); let input_index: Literal = self.input_index(); - let debug_name = Literal::string(&format!("{}", self.id_ident())); + let debug_name_struct = Literal::string(&self.id_ident().to_string()); + let debug_name_fields: Vec<_> = self + .all_field_names() + .into_iter() + .map(|ident| Literal::string(&ident.to_string())) + .collect(); parse_quote! { impl salsa::storage::IngredientsFor for #ident { @@ -168,7 +173,7 @@ impl InputStruct { &mut ingredients.#all_field_indices }, ); - salsa::input_field::InputFieldIngredient::new(index) + salsa::input_field::InputFieldIngredient::new(index, #debug_name_fields) }, )* { @@ -184,7 +189,7 @@ impl InputStruct { &mut ingredients.#input_index }, ); - salsa::input::InputIngredient::new(index, #debug_name) + salsa::input::InputIngredient::new(index, #debug_name_struct) }, ) } diff --git a/components/salsa-2022/src/input_field.rs b/components/salsa-2022/src/input_field.rs index 54ce093a..0ad5cd78 100644 --- a/components/salsa-2022/src/input_field.rs +++ b/components/salsa-2022/src/input_field.rs @@ -1,10 +1,11 @@ use crate::cycle::CycleRecoveryStrategy; -use crate::ingredient::{Ingredient, IngredientRequiresReset}; +use crate::ingredient::{fmt_index, Ingredient, IngredientRequiresReset}; use crate::key::DependencyIndex; use crate::runtime::local_state::QueryOrigin; use crate::runtime::StampedValue; use crate::{AsId, DatabaseKeyIndex, Durability, Id, IngredientIndex, Revision, Runtime}; use rustc_hash::FxHashMap; +use std::fmt; use std::hash::Hash; /// Ingredient used to represent the fields of a `#[salsa::input]`. @@ -15,16 +16,18 @@ use std::hash::Hash; pub struct InputFieldIngredient { index: IngredientIndex, map: FxHashMap>, + debug_name: &'static str, } impl InputFieldIngredient where K: Eq + Hash + AsId, { - pub fn new(index: IngredientIndex) -> Self { + pub fn new(index: IngredientIndex, debug_name: &'static str) -> Self { Self { index, map: Default::default(), + debug_name, } } @@ -114,12 +117,8 @@ where panic!("unexpected call: input fields don't register for resets"); } - fn fmt_index( - &self, - _index: Option, - _fmt: &mut std::fmt::Formatter<'_>, - ) -> std::fmt::Result { - todo!() + fn fmt_index(&self, index: Option, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt_index(self.debug_name, index, fmt) } } From f69d80b2c57b73e50ece40b38a0f6d650a55a154 Mon Sep 17 00:00:00 2001 From: zjp Date: Mon, 22 Aug 2022 10:43:41 +0800 Subject: [PATCH 10/17] ix(fmt_index): impl for TrackedStructIngredient --- .../salsa-2022-macros/src/tracked_struct.rs | 11 ++++++++--- components/salsa-2022/src/tracked_struct.rs | 17 +++++++++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/components/salsa-2022-macros/src/tracked_struct.rs b/components/salsa-2022-macros/src/tracked_struct.rs index c20e298a..f8a49070 100644 --- a/components/salsa-2022-macros/src/tracked_struct.rs +++ b/components/salsa-2022-macros/src/tracked_struct.rs @@ -159,7 +159,12 @@ impl TrackedStruct { let value_field_indices: Vec = self.value_field_indices(); let tracked_struct_index: Literal = self.tracked_struct_index(); let config_struct_names = config_structs.iter().map(|s| &s.ident); - let debug_name = Literal::string(&self.id_ident().to_string()); + let debug_name_struct = Literal::string(&self.id_ident().to_string()); + let debug_name_fields: Vec<_> = self + .all_field_names() + .into_iter() + .map(|ident| Literal::string(&ident.to_string())) + .collect(); parse_quote! { impl salsa::storage::IngredientsFor for #ident { @@ -192,7 +197,7 @@ impl TrackedStruct { &mut ingredients.#value_field_indices }, ); - salsa::function::FunctionIngredient::new(index, #debug_name) + salsa::function::FunctionIngredient::new(index, #debug_name_fields) }, )* { @@ -208,7 +213,7 @@ impl TrackedStruct { &mut ingredients.#tracked_struct_index }, ); - salsa::tracked_struct::TrackedStructIngredient::new(index) + salsa::tracked_struct::TrackedStructIngredient::new(index, #debug_name_struct) }, ) } diff --git a/components/salsa-2022/src/tracked_struct.rs b/components/salsa-2022/src/tracked_struct.rs index 675a3985..3a306f8f 100644 --- a/components/salsa-2022/src/tracked_struct.rs +++ b/components/salsa-2022/src/tracked_struct.rs @@ -1,6 +1,8 @@ +use std::fmt; + use crate::{ cycle::CycleRecoveryStrategy, - ingredient::{Ingredient, IngredientRequiresReset}, + ingredient::{fmt_index, Ingredient, IngredientRequiresReset}, ingredient_list::IngredientList, interned::{InternedData, InternedId, InternedIngredient}, key::{DatabaseKeyIndex, DependencyIndex}, @@ -42,6 +44,8 @@ where /// each of these functions will be notified /// so they can remove any data tied to that instance. dependent_fns: IngredientList, + + debug_name: &'static str, } #[derive(Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Copy, Clone)] @@ -59,10 +63,11 @@ where Id: TrackedStructId, Data: TrackedStructData, { - pub fn new(index: IngredientIndex) -> Self { + pub fn new(index: IngredientIndex, debug_name: &'static str) -> Self { Self { interned: InternedIngredient::new(index), dependent_fns: IngredientList::new(), + debug_name, } } @@ -176,12 +181,8 @@ where panic!("unexpected call: interned ingredients do not register for salsa struct deletion events"); } - fn fmt_index( - &self, - _index: Option, - _fmt: &mut std::fmt::Formatter<'_>, - ) -> std::fmt::Result { - todo!() + fn fmt_index(&self, index: Option, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt_index(self.debug_name, index, fmt) } } From 44e9c639742456279180039b6765a7d2f6b0d9b0 Mon Sep 17 00:00:00 2001 From: zjp Date: Mon, 22 Aug 2022 11:22:47 +0800 Subject: [PATCH 11/17] feat(fmt_index): impl for DependencyIndex --- components/salsa-2022/src/key.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/salsa-2022/src/key.rs b/components/salsa-2022/src/key.rs index d1369bdb..c443b7bb 100644 --- a/components/salsa-2022/src/key.rs +++ b/components/salsa-2022/src/key.rs @@ -38,8 +38,8 @@ impl crate::debug::DebugWithDb for DependencyIndex where Db: ?Sized + Database, { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>, _db: &Db) -> std::fmt::Result { - write!(f, "{:?}", *self) // FIXME + fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &Db) -> std::fmt::Result { + db.fmt_index(*self, f) } } From dfee2b8cee627823330b38d4b38800b2a37ef173 Mon Sep 17 00:00:00 2001 From: zjp Date: Mon, 22 Aug 2022 15:23:58 +0800 Subject: [PATCH 12/17] update tests --- salsa-2022-tests/tests/accumulate.rs | 3 +- salsa-2022-tests/tests/cycles.rs | 44 ++++----- salsa-2022-tests/tests/deletion-cascade.rs | 14 +-- salsa-2022-tests/tests/deletion.rs | 8 +- .../parallel/parallel_cycle_none_recover.rs | 4 +- .../specify_tracked_fn_in_rev_1_but_not_2.rs | 96 +++++++++---------- 6 files changed, 85 insertions(+), 84 deletions(-) diff --git a/salsa-2022-tests/tests/accumulate.rs b/salsa-2022-tests/tests/accumulate.rs index c12298df..deb46aee 100644 --- a/salsa-2022-tests/tests/accumulate.rs +++ b/salsa-2022-tests/tests/accumulate.rs @@ -174,7 +174,8 @@ fn get_a_logs_after_changing_b() { [ "log_a(0 of 2)", "log_a(1 of 2)", - ]"#]] + ] + "#]] .assert_debug_eq(&logs); db.assert_logs(expect!["[]"]); } diff --git a/salsa-2022-tests/tests/cycles.rs b/salsa-2022-tests/tests/cycles.rs index 5a88ed9a..035f2794 100644 --- a/salsa-2022-tests/tests/cycles.rs +++ b/salsa-2022-tests/tests/cycles.rs @@ -190,8 +190,8 @@ fn cycle_memoized() { let cycle = extract_cycle(|| memoized_a(&db, input)); let expected = expect![[r#" [ - "DependencyIndex { ingredient_index: IngredientIndex(1), key_index: Some(Id { value: 1 }) }", - "DependencyIndex { ingredient_index: IngredientIndex(2), key_index: Some(Id { value: 1 }) }", + "memoized_a(0)", + "memoized_b(0)", ] "#]]; expected.assert_debug_eq(&cycle.all_participants(&db)); @@ -204,8 +204,8 @@ fn cycle_volatile() { let cycle = extract_cycle(|| volatile_a(&db, input)); let expected = expect![[r#" [ - "DependencyIndex { ingredient_index: IngredientIndex(3), key_index: Some(Id { value: 1 }) }", - "DependencyIndex { ingredient_index: IngredientIndex(4), key_index: Some(Id { value: 1 }) }", + "volatile_a(0)", + "volatile_b(0)", ] "#]]; expected.assert_debug_eq(&cycle.all_participants(&db)); @@ -233,8 +233,8 @@ fn inner_cycle() { assert!(err.is_err()); let expected = expect![[r#" [ - "DependencyIndex { ingredient_index: IngredientIndex(9), key_index: Some(Id { value: 1 }) }", - "DependencyIndex { ingredient_index: IngredientIndex(10), key_index: Some(Id { value: 1 }) }", + "cycle_a(0)", + "cycle_b(0)", ] "#]]; expected.assert_debug_eq(&err.unwrap_err().cycle); @@ -306,8 +306,8 @@ fn cycle_mixed_1() { let expected = expect![[r#" [ - "DependencyIndex { ingredient_index: IngredientIndex(10), key_index: Some(Id { value: 1 }) }", - "DependencyIndex { ingredient_index: IngredientIndex(11), key_index: Some(Id { value: 1 }) }", + "cycle_b(0)", + "cycle_c(0)", ] "#]]; expected.assert_debug_eq(&cycle_c(&db, abc).unwrap_err().cycle); @@ -325,9 +325,9 @@ fn cycle_mixed_2() { let abc = ABC::new(&mut db, CycleQuery::B, CycleQuery::C, CycleQuery::A); let expected = expect![[r#" [ - "DependencyIndex { ingredient_index: IngredientIndex(9), key_index: Some(Id { value: 1 }) }", - "DependencyIndex { ingredient_index: IngredientIndex(10), key_index: Some(Id { value: 1 }) }", - "DependencyIndex { ingredient_index: IngredientIndex(11), key_index: Some(Id { value: 1 }) }", + "cycle_a(0)", + "cycle_b(0)", + "cycle_c(0)", ] "#]]; expected.assert_debug_eq(&cycle_a(&db, abc).unwrap_err().cycle); @@ -352,12 +352,12 @@ fn cycle_deterministic_order() { let expected = expect![[r#" ( [ - "DependencyIndex { ingredient_index: IngredientIndex(9), key_index: Some(Id { value: 1 }) }", - "DependencyIndex { ingredient_index: IngredientIndex(10), key_index: Some(Id { value: 1 }) }", + "cycle_a(0)", + "cycle_b(0)", ], [ - "DependencyIndex { ingredient_index: IngredientIndex(9), key_index: Some(Id { value: 1 }) }", - "DependencyIndex { ingredient_index: IngredientIndex(10), key_index: Some(Id { value: 1 }) }", + "cycle_a(0)", + "cycle_b(0)", ], ) "#]]; @@ -387,16 +387,16 @@ fn cycle_multiple() { let expected = expect![[r#" ( [ - "DependencyIndex { ingredient_index: IngredientIndex(9), key_index: Some(Id { value: 1 }) }", - "DependencyIndex { ingredient_index: IngredientIndex(10), key_index: Some(Id { value: 1 }) }", + "cycle_a(0)", + "cycle_b(0)", ], [ - "DependencyIndex { ingredient_index: IngredientIndex(9), key_index: Some(Id { value: 1 }) }", - "DependencyIndex { ingredient_index: IngredientIndex(10), key_index: Some(Id { value: 1 }) }", + "cycle_a(0)", + "cycle_b(0)", ], [ - "DependencyIndex { ingredient_index: IngredientIndex(9), key_index: Some(Id { value: 1 }) }", - "DependencyIndex { ingredient_index: IngredientIndex(10), key_index: Some(Id { value: 1 }) }", + "cycle_a(0)", + "cycle_b(0)", ], ) "#]]; @@ -420,7 +420,7 @@ fn cycle_recovery_set_but_not_participating() { let r = extract_cycle(|| drop(cycle_a(&db, abc))); let expected = expect![[r#" [ - "DependencyIndex { ingredient_index: IngredientIndex(11), key_index: Some(Id { value: 1 }) }", + "cycle_c(0)", ] "#]]; expected.assert_debug_eq(&r.all_participants(&db)); diff --git a/salsa-2022-tests/tests/deletion-cascade.rs b/salsa-2022-tests/tests/deletion-cascade.rs index d52f698b..8a32e2e1 100644 --- a/salsa-2022-tests/tests/deletion-cascade.rs +++ b/salsa-2022-tests/tests/deletion-cascade.rs @@ -122,13 +122,13 @@ fn basic() { db.assert_logs(expect![[r#" [ "intermediate_result(MyInput(Id { value: 1 }))", - "salsa_event(WillDiscardStaleOutput { execute_key: DependencyIndex { ingredient_index: IngredientIndex(5), key_index: Some(Id { value: 1 }) }, output_key: DependencyIndex { ingredient_index: IngredientIndex(3), key_index: Some(Id { value: 3 }) } })", - "salsa_event(DidDiscard { key: DependencyIndex { ingredient_index: IngredientIndex(3), key_index: Some(Id { value: 3 }) } })", - "salsa_event(DidDiscard { key: DependencyIndex { ingredient_index: IngredientIndex(2), key_index: Some(Id { value: 3 }) } })", - "salsa_event(DidDiscard { key: DependencyIndex { ingredient_index: IngredientIndex(6), key_index: Some(Id { value: 3 }) } })", - "salsa_event(DidDiscard { key: DependencyIndex { ingredient_index: IngredientIndex(3), key_index: Some(Id { value: 6 }) } })", - "salsa_event(DidDiscard { key: DependencyIndex { ingredient_index: IngredientIndex(2), key_index: Some(Id { value: 6 }) } })", - "salsa_event(DidDiscard { key: DependencyIndex { ingredient_index: IngredientIndex(7), key_index: Some(Id { value: 6 }) } })", + "salsa_event(WillDiscardStaleOutput { execute_key: create_tracked_structs(0), output_key: MyTracked(2) })", + "salsa_event(DidDiscard { key: MyTracked(2) })", + "salsa_event(DidDiscard { key: field(2) })", + "salsa_event(DidDiscard { key: contribution_from_struct(2) })", + "salsa_event(DidDiscard { key: MyTracked(5) })", + "salsa_event(DidDiscard { key: field(5) })", + "salsa_event(DidDiscard { key: copy_field(5) })", "final_result(MyInput(Id { value: 1 }))", ]"#]]); } diff --git a/salsa-2022-tests/tests/deletion.rs b/salsa-2022-tests/tests/deletion.rs index b5c756b4..b0d460f8 100644 --- a/salsa-2022-tests/tests/deletion.rs +++ b/salsa-2022-tests/tests/deletion.rs @@ -108,10 +108,10 @@ fn basic() { db.assert_logs(expect![[r#" [ "intermediate_result(MyInput(Id { value: 1 }))", - "salsa_event(WillDiscardStaleOutput { execute_key: DependencyIndex { ingredient_index: IngredientIndex(5), key_index: Some(Id { value: 1 }) }, output_key: DependencyIndex { ingredient_index: IngredientIndex(3), key_index: Some(Id { value: 3 }) } })", - "salsa_event(DidDiscard { key: DependencyIndex { ingredient_index: IngredientIndex(3), key_index: Some(Id { value: 3 }) } })", - "salsa_event(DidDiscard { key: DependencyIndex { ingredient_index: IngredientIndex(2), key_index: Some(Id { value: 3 }) } })", - "salsa_event(DidDiscard { key: DependencyIndex { ingredient_index: IngredientIndex(6), key_index: Some(Id { value: 3 }) } })", + "salsa_event(WillDiscardStaleOutput { execute_key: create_tracked_structs(0), output_key: MyTracked(2) })", + "salsa_event(DidDiscard { key: MyTracked(2) })", + "salsa_event(DidDiscard { key: field(2) })", + "salsa_event(DidDiscard { key: contribution_from_struct(2) })", "final_result(MyInput(Id { value: 1 }))", ]"#]]); } diff --git a/salsa-2022-tests/tests/parallel/parallel_cycle_none_recover.rs b/salsa-2022-tests/tests/parallel/parallel_cycle_none_recover.rs index 5a0227f2..5851f948 100644 --- a/salsa-2022-tests/tests/parallel/parallel_cycle_none_recover.rs +++ b/salsa-2022-tests/tests/parallel/parallel_cycle_none_recover.rs @@ -64,8 +64,8 @@ fn execute() { if let Some(c) = err_b.downcast_ref::() { let expected = expect![[r#" [ - "DependencyIndex { ingredient_index: IngredientIndex(8), key_index: Some(Id { value: 1 }) }", - "DependencyIndex { ingredient_index: IngredientIndex(9), key_index: Some(Id { value: 1 }) }", + "a(0)", + "b(0)", ] "#]]; expected.assert_debug_eq(&c.all_participants(&db)); diff --git a/salsa-2022-tests/tests/specify_tracked_fn_in_rev_1_but_not_2.rs b/salsa-2022-tests/tests/specify_tracked_fn_in_rev_1_but_not_2.rs index c1ab5003..3cf6036a 100644 --- a/salsa-2022-tests/tests/specify_tracked_fn_in_rev_1_but_not_2.rs +++ b/salsa-2022-tests/tests/specify_tracked_fn_in_rev_1_but_not_2.rs @@ -98,13 +98,13 @@ fn test_run_0() { db.assert_logs(expect![[r#" [ "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(7), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: final_result(0) } }", "final_result(MyInput(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(6), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }", "create_tracked(MyInput(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(5), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: read_maybe_specified(0) } }", "read_maybe_specified(MyTracked(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", ]"#]]); @@ -119,13 +119,13 @@ fn test_run_5() { db.assert_logs(expect![[r#" [ "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(7), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: final_result(0) } }", "final_result(MyInput(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(6), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }", "create_tracked(MyInput(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(5), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: read_maybe_specified(0) } }", "read_maybe_specified(MyTracked(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", ]"#]]); @@ -140,16 +140,16 @@ fn test_run_10() { db.assert_logs(expect![[r#" [ "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(7), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: final_result(0) } }", "final_result(MyInput(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(6), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }", "create_tracked(MyInput(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(5), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: read_maybe_specified(0) } }", "read_maybe_specified(MyTracked(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(4), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: maybe_specified(0) } }", "maybe_specified(MyTracked(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", ]"#]]); @@ -164,16 +164,16 @@ fn test_run_20() { db.assert_logs(expect![[r#" [ "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(7), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: final_result(0) } }", "final_result(MyInput(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(6), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }", "create_tracked(MyInput(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(5), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: read_maybe_specified(0) } }", "read_maybe_specified(MyTracked(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(4), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: maybe_specified(0) } }", "maybe_specified(MyTracked(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", ]"#]]); @@ -192,13 +192,13 @@ fn test_run_0_then_5_then_20() { db.assert_logs(expect![[r#" [ "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(7), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: final_result(0) } }", "final_result(MyInput(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(6), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }", "create_tracked(MyInput(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(5), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: read_maybe_specified(0) } }", "read_maybe_specified(MyTracked(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", ]"#]]); @@ -213,12 +213,12 @@ fn test_run_0_then_5_then_20() { [ "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(6), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }", "create_tracked(MyInput(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: DidValidateMemoizedValue { database_key: DependencyIndex { ingredient_index: IngredientIndex(5), key_index: Some(Id { value: 1 }) } } }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: DidValidateMemoizedValue { database_key: DependencyIndex { ingredient_index: IngredientIndex(7), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: DidValidateMemoizedValue { database_key: read_maybe_specified(0) } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: DidValidateMemoizedValue { database_key: final_result(0) } }", ]"#]]); // Set input to 20: @@ -232,18 +232,18 @@ fn test_run_0_then_5_then_20() { [ "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(6), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }", "create_tracked(MyInput(Id { value: 1 }))", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillDiscardStaleOutput { execute_key: DependencyIndex { ingredient_index: IngredientIndex(6), key_index: Some(Id { value: 1 }) }, output_key: DependencyIndex { ingredient_index: IngredientIndex(4), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillDiscardStaleOutput { execute_key: create_tracked(0), output_key: maybe_specified(0) } }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(4), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: maybe_specified(0) } }", "maybe_specified(MyTracked(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(5), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: read_maybe_specified(0) } }", "read_maybe_specified(MyTracked(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(7), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: final_result(0) } }", "final_result(MyInput(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", @@ -263,13 +263,13 @@ fn test_run_0_then_5_then_10_then_20() { db.assert_logs(expect![[r#" [ "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(7), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: final_result(0) } }", "final_result(MyInput(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(6), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }", "create_tracked(MyInput(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(5), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: read_maybe_specified(0) } }", "read_maybe_specified(MyTracked(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", ]"#]]); @@ -284,12 +284,12 @@ fn test_run_0_then_5_then_10_then_20() { [ "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(6), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }", "create_tracked(MyInput(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: DidValidateMemoizedValue { database_key: DependencyIndex { ingredient_index: IngredientIndex(5), key_index: Some(Id { value: 1 }) } } }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: DidValidateMemoizedValue { database_key: DependencyIndex { ingredient_index: IngredientIndex(7), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: DidValidateMemoizedValue { database_key: read_maybe_specified(0) } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: DidValidateMemoizedValue { database_key: final_result(0) } }", ]"#]]); // Set input to 10: @@ -303,16 +303,16 @@ fn test_run_0_then_5_then_10_then_20() { [ "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(6), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }", "create_tracked(MyInput(Id { value: 1 }))", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillDiscardStaleOutput { execute_key: DependencyIndex { ingredient_index: IngredientIndex(6), key_index: Some(Id { value: 1 }) }, output_key: DependencyIndex { ingredient_index: IngredientIndex(4), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillDiscardStaleOutput { execute_key: create_tracked(0), output_key: maybe_specified(0) } }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(4), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: maybe_specified(0) } }", "maybe_specified(MyTracked(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: DidValidateMemoizedValue { database_key: DependencyIndex { ingredient_index: IngredientIndex(5), key_index: Some(Id { value: 1 }) } } }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: DidValidateMemoizedValue { database_key: DependencyIndex { ingredient_index: IngredientIndex(7), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: DidValidateMemoizedValue { database_key: read_maybe_specified(0) } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: DidValidateMemoizedValue { database_key: final_result(0) } }", ]"#]]); // Set input to 20: @@ -324,18 +324,18 @@ fn test_run_0_then_5_then_10_then_20() { [ "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(6), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }", "create_tracked(MyInput(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(4), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: maybe_specified(0) } }", "maybe_specified(MyTracked(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(5), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: read_maybe_specified(0) } }", "read_maybe_specified(MyTracked(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(7), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: final_result(0) } }", "final_result(MyInput(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", @@ -351,13 +351,13 @@ fn test_run_5_then_20() { db.assert_logs(expect![[r#" [ "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(7), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: final_result(0) } }", "final_result(MyInput(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(6), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }", "create_tracked(MyInput(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(5), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: read_maybe_specified(0) } }", "read_maybe_specified(MyTracked(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", ]"#]]); @@ -368,18 +368,18 @@ fn test_run_5_then_20() { [ "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(6), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: create_tracked(0) } }", "create_tracked(MyInput(Id { value: 1 }))", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillDiscardStaleOutput { execute_key: DependencyIndex { ingredient_index: IngredientIndex(6), key_index: Some(Id { value: 1 }) }, output_key: DependencyIndex { ingredient_index: IngredientIndex(4), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillDiscardStaleOutput { execute_key: create_tracked(0), output_key: maybe_specified(0) } }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(4), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: maybe_specified(0) } }", "maybe_specified(MyTracked(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(5), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: read_maybe_specified(0) } }", "read_maybe_specified(MyTracked(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", - "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(7), key_index: Some(Id { value: 1 }) } } }", + "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: final_result(0) } }", "final_result(MyInput(Id { value: 1 }))", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", "Event { runtime_id: RuntimeId { counter: 0 }, kind: WillCheckCancellation }", From bf00d4217f47361f9dae24c9b73c418cb428d57b Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 22 Aug 2022 06:21:23 -0400 Subject: [PATCH 13/17] apply cargo fmt --- components/salsa-2022/src/accumulator.rs | 10 +++------- components/salsa-2022/src/function.rs | 10 +++------- components/salsa-2022/src/input.rs | 2 +- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/components/salsa-2022/src/accumulator.rs b/components/salsa-2022/src/accumulator.rs index 7ea320b6..fcae3d05 100644 --- a/components/salsa-2022/src/accumulator.rs +++ b/components/salsa-2022/src/accumulator.rs @@ -5,7 +5,7 @@ use std::fmt; use crate::{ cycle::CycleRecoveryStrategy, hash::FxDashMap, - ingredient::{Ingredient, IngredientRequiresReset, fmt_index}, + ingredient::{fmt_index, Ingredient, IngredientRequiresReset}, key::DependencyIndex, runtime::local_state::QueryOrigin, storage::HasJar, @@ -36,7 +36,7 @@ impl AccumulatorIngredient { Self { map: FxDashMap::default(), index, - debug_name + debug_name, } } @@ -153,11 +153,7 @@ where panic!("unexpected call: accumulator is not registered as a dependent fn"); } - fn fmt_index( - &self, - index: Option, - fmt: &mut fmt::Formatter<'_>, - ) -> fmt::Result { + fn fmt_index(&self, index: Option, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt_index(self.debug_name, index, fmt) } } diff --git a/components/salsa-2022/src/function.rs b/components/salsa-2022/src/function.rs index ad43f3d3..f88187b7 100644 --- a/components/salsa-2022/src/function.rs +++ b/components/salsa-2022/src/function.rs @@ -1,11 +1,11 @@ -use std::{sync::Arc, fmt}; +use std::{fmt, sync::Arc}; use arc_swap::ArcSwap; use crossbeam::{atomic::AtomicCell, queue::SegQueue}; use crate::{ cycle::CycleRecoveryStrategy, - ingredient::{IngredientRequiresReset, fmt_index}, + ingredient::{fmt_index, IngredientRequiresReset}, jar::Jar, key::{DatabaseKeyIndex, DependencyIndex}, runtime::local_state::QueryOrigin, @@ -273,11 +273,7 @@ where } } - fn fmt_index( - &self, - index: Option, - fmt: &mut fmt::Formatter<'_>, - ) -> fmt::Result { + fn fmt_index(&self, index: Option, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt_index(self.debug_name, index, fmt) } } diff --git a/components/salsa-2022/src/input.rs b/components/salsa-2022/src/input.rs index f304e051..fa908f6a 100644 --- a/components/salsa-2022/src/input.rs +++ b/components/salsa-2022/src/input.rs @@ -2,7 +2,7 @@ use std::fmt; use crate::{ cycle::CycleRecoveryStrategy, - ingredient::{Ingredient, IngredientRequiresReset, fmt_index}, + ingredient::{fmt_index, Ingredient, IngredientRequiresReset}, key::{DatabaseKeyIndex, DependencyIndex}, runtime::{local_state::QueryOrigin, Runtime}, AsId, IngredientIndex, Revision, From d835b0782c3b9ee4d134e454d7d120df07ad2d89 Mon Sep 17 00:00:00 2001 From: zjp Date: Mon, 22 Aug 2022 19:19:22 +0800 Subject: [PATCH 14/17] add empty/default rustfmt.toml --- rustfmt.toml | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 rustfmt.toml diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 00000000..e69de29b From 4966acbc64879fa85278d015b402774fb1ebd8c9 Mon Sep 17 00:00:00 2001 From: zjp Date: Mon, 22 Aug 2022 20:22:57 +0800 Subject: [PATCH 15/17] feat(literal): a helper to convert Ident to Literal --- components/salsa-2022-macros/src/accumulator.rs | 2 +- components/salsa-2022-macros/src/input.rs | 9 +++------ components/salsa-2022-macros/src/lib.rs | 5 +++++ components/salsa-2022-macros/src/tracked_fn.rs | 2 +- components/salsa-2022-macros/src/tracked_struct.rs | 9 +++------ 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/components/salsa-2022-macros/src/accumulator.rs b/components/salsa-2022-macros/src/accumulator.rs index 2f6b6221..4a6537d4 100644 --- a/components/salsa-2022-macros/src/accumulator.rs +++ b/components/salsa-2022-macros/src/accumulator.rs @@ -112,7 +112,7 @@ fn ingredients_for_impl( data_ty: &syn::Type, ) -> syn::ItemImpl { let jar_ty = args.jar_ty(); - let debug_name = proc_macro2::Literal::string(&struct_name.to_string()); + let debug_name = crate::literal(struct_name); parse_quote! { impl salsa::storage::IngredientsFor for #struct_name { type Ingredients = salsa::accumulator::AccumulatorIngredient<#data_ty>; diff --git a/components/salsa-2022-macros/src/input.rs b/components/salsa-2022-macros/src/input.rs index aa7fbf6b..9dc26d4a 100644 --- a/components/salsa-2022-macros/src/input.rs +++ b/components/salsa-2022-macros/src/input.rs @@ -130,17 +130,14 @@ impl InputStruct { /// The entity's ingredients include both the main entity ingredient along with a /// function ingredient for each of the value fields. fn input_ingredients(&self) -> syn::ItemImpl { + use crate::literal; let ident = self.id_ident(); let field_ty = self.all_field_tys(); let jar_ty = self.jar_ty(); let all_field_indices: Vec = self.all_field_indices(); let input_index: Literal = self.input_index(); - let debug_name_struct = Literal::string(&self.id_ident().to_string()); - let debug_name_fields: Vec<_> = self - .all_field_names() - .into_iter() - .map(|ident| Literal::string(&ident.to_string())) - .collect(); + let debug_name_struct = literal(self.id_ident()); + let debug_name_fields: Vec<_> = self.all_field_names().into_iter().map(literal).collect(); parse_quote! { impl salsa::storage::IngredientsFor for #ident { diff --git a/components/salsa-2022-macros/src/lib.rs b/components/salsa-2022-macros/src/lib.rs index 13263b3b..45b31e67 100644 --- a/components/salsa-2022-macros/src/lib.rs +++ b/components/salsa-2022-macros/src/lib.rs @@ -25,6 +25,11 @@ macro_rules! parse_quote_spanned { } } +/// Convert a single Ident to Literal: useful when &'static str is needed. +pub(crate) fn literal(ident: &proc_macro2::Ident) -> proc_macro2::Literal { + proc_macro2::Literal::string(&ident.to_string()) +} + mod accumulator; mod configuration; mod db; diff --git a/components/salsa-2022-macros/src/tracked_fn.rs b/components/salsa-2022-macros/src/tracked_fn.rs index 39547d1f..e62b5e54 100644 --- a/components/salsa-2022-macros/src/tracked_fn.rs +++ b/components/salsa-2022-macros/src/tracked_fn.rs @@ -243,7 +243,7 @@ fn ingredients_for_impl( let lru = args.lru.unwrap_or(0); // get the name of the function as a string literal - let debug_name = Literal::string(&item_fn.sig.ident.to_string()); + let debug_name = crate::literal(&item_fn.sig.ident); parse_quote! { impl salsa::storage::IngredientsFor for #config_ty { diff --git a/components/salsa-2022-macros/src/tracked_struct.rs b/components/salsa-2022-macros/src/tracked_struct.rs index f8a49070..99f12b53 100644 --- a/components/salsa-2022-macros/src/tracked_struct.rs +++ b/components/salsa-2022-macros/src/tracked_struct.rs @@ -153,18 +153,15 @@ impl TrackedStruct { /// The tracked struct's ingredients include both the main tracked struct ingredient along with a /// function ingredient for each of the value fields. fn tracked_struct_ingredients(&self, config_structs: &[syn::ItemStruct]) -> syn::ItemImpl { + use crate::literal; let ident = self.id_ident(); let jar_ty = self.jar_ty(); let id_field_tys: Vec<&syn::Type> = self.id_fields().map(SalsaField::ty).collect(); let value_field_indices: Vec = self.value_field_indices(); let tracked_struct_index: Literal = self.tracked_struct_index(); let config_struct_names = config_structs.iter().map(|s| &s.ident); - let debug_name_struct = Literal::string(&self.id_ident().to_string()); - let debug_name_fields: Vec<_> = self - .all_field_names() - .into_iter() - .map(|ident| Literal::string(&ident.to_string())) - .collect(); + let debug_name_struct = literal(self.id_ident()); + let debug_name_fields: Vec<_> = self.all_field_names().into_iter().map(literal).collect(); parse_quote! { impl salsa::storage::IngredientsFor for #ident { From 863ec4ac7f7f007924c0e19c76deb5c6c42bac90 Mon Sep 17 00:00:00 2001 From: zjp Date: Mon, 22 Aug 2022 21:17:48 +0800 Subject: [PATCH 16/17] fix(debug_name): impl for InternedIngredient --- components/salsa-2022-macros/src/interned.rs | 3 ++- components/salsa-2022-macros/src/tracked_fn.rs | 3 ++- components/salsa-2022/src/interned.rs | 4 ++-- components/salsa-2022/src/tracked_struct.rs | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/components/salsa-2022-macros/src/interned.rs b/components/salsa-2022-macros/src/interned.rs index 629a23de..54df62ab 100644 --- a/components/salsa-2022-macros/src/interned.rs +++ b/components/salsa-2022-macros/src/interned.rs @@ -120,6 +120,7 @@ impl InternedStruct { /// For a memoized type, the only ingredient is an `InternedIngredient`. fn ingredients_for_impl(&self) -> syn::ItemImpl { let id_ident = self.id_ident(); + let debug_name = crate::literal(id_ident); let jar_ty = self.jar_ty(); let data_ident = self.data_ident(); parse_quote! { @@ -143,7 +144,7 @@ impl InternedStruct { <_ as salsa::storage::HasIngredientsFor>::ingredient_mut(jar) }, ); - salsa::interned::InternedIngredient::new(index) + salsa::interned::InternedIngredient::new(index, #debug_name) } } } diff --git a/components/salsa-2022-macros/src/tracked_fn.rs b/components/salsa-2022-macros/src/tracked_fn.rs index e62b5e54..0a8c28f1 100644 --- a/components/salsa-2022-macros/src/tracked_fn.rs +++ b/components/salsa-2022-macros/src/tracked_fn.rs @@ -212,6 +212,7 @@ fn ingredients_for_impl( config_ty: &syn::Type, ) -> syn::ItemImpl { let jar_ty = args.jar_ty(); + let debug_name = crate::literal(&item_fn.sig.ident); let intern_map: syn::Expr = if requires_interning(item_fn) { parse_quote! { @@ -230,7 +231,7 @@ fn ingredients_for_impl( &mut ingredients.intern_map } ); - salsa::interned::InternedIngredient::new(index) + salsa::interned::InternedIngredient::new(index, #debug_name) } } } else { diff --git a/components/salsa-2022/src/interned.rs b/components/salsa-2022/src/interned.rs index 28119a9a..eab2354a 100644 --- a/components/salsa-2022/src/interned.rs +++ b/components/salsa-2022/src/interned.rs @@ -64,7 +64,7 @@ where Id: InternedId, Data: InternedData, { - pub fn new(ingredient_index: IngredientIndex) -> Self { + pub fn new(ingredient_index: IngredientIndex, debug_name: &'static str) -> Self { Self { ingredient_index, key_map: Default::default(), @@ -72,7 +72,7 @@ where counter: AtomicCell::default(), reset_at: Revision::start(), deleted_entries: Default::default(), - debug_name: "InternedIngredient", + debug_name, } } diff --git a/components/salsa-2022/src/tracked_struct.rs b/components/salsa-2022/src/tracked_struct.rs index 3a306f8f..9f749097 100644 --- a/components/salsa-2022/src/tracked_struct.rs +++ b/components/salsa-2022/src/tracked_struct.rs @@ -65,7 +65,7 @@ where { pub fn new(index: IngredientIndex, debug_name: &'static str) -> Self { Self { - interned: InternedIngredient::new(index), + interned: InternedIngredient::new(index, debug_name), dependent_fns: IngredientList::new(), debug_name, } From edc44e44f89f7af48c218145f4ca89d20c384f3e Mon Sep 17 00:00:00 2001 From: zjp Date: Mon, 22 Aug 2022 21:32:50 +0800 Subject: [PATCH 17/17] update tests --- calc-example/calc/src/parser.rs | 2 +- calc-example/calc/src/type_check.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/calc-example/calc/src/parser.rs b/calc-example/calc/src/parser.rs index 5869e945..c01acb39 100644 --- a/calc-example/calc/src/parser.rs +++ b/calc-example/calc/src/parser.rs @@ -624,7 +624,7 @@ fn parse_error() { statements: [], }, [ - Diagnostic { position: 10, message: "unexpected character" }, + Diagnostic { start: 10, end: 11, message: "unexpected character" }, ], )"#]]; expected.assert_eq(&actual); diff --git a/calc-example/calc/src/type_check.rs b/calc-example/calc/src/type_check.rs index f62b2086..57d9b13f 100644 --- a/calc-example/calc/src/type_check.rs +++ b/calc-example/calc/src/type_check.rs @@ -246,8 +246,8 @@ fn fix_bad_variable_in_function() { "#]], expect![[r#" [ - "Event: Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(15), key_index: Some(Id { value: 1 }) } } }", - "Event: Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: DependencyIndex { ingredient_index: IngredientIndex(18), key_index: Some(Id { value: 1 }) } } }", + "Event: Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: parse_statements(0) } }", + "Event: Event { runtime_id: RuntimeId { counter: 0 }, kind: WillExecute { database_key: type_check_function(0) } }", ] "#]], )],