From 204f4eea6f9226294691712a10929f91a7e376cd Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sat, 6 Jul 2024 08:34:59 -0400 Subject: [PATCH] move struct debug name to Configuration --- components/salsa-macros/src/tracked_struct.rs | 11 ++++++++--- src/tracked_struct.rs | 10 ++++------ src/tracked_struct/tracked_field.rs | 3 +-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/components/salsa-macros/src/tracked_struct.rs b/components/salsa-macros/src/tracked_struct.rs index 5cd549d..9d4c59d 100644 --- a/components/salsa-macros/src/tracked_struct.rs +++ b/components/salsa-macros/src/tracked_struct.rs @@ -1,6 +1,9 @@ use proc_macro2::{Literal, Span, TokenStream}; -use crate::salsa_struct::{SalsaField, SalsaStruct, TheStructKind}; +use crate::{ + literal, + salsa_struct::{SalsaField, SalsaStruct, TheStructKind}, +}; /// For an tracked struct `Foo` with fields `f1: T1, ..., fN: TN`, we generate... /// @@ -105,6 +108,7 @@ impl TrackedStruct { let arity = self.all_field_count(); let the_ident = self.the_ident(); let lt_db = &self.named_db_lifetime(); + let debug_name_struct = literal(self.the_ident()); // Create the function body that will update the revisions for each field. // If a field is a "backdate field" (the default), then we first check if @@ -143,6 +147,8 @@ impl TrackedStruct { parse_quote! { impl salsa::tracked_struct::Configuration for #config_ident { + const DEBUG_NAME: &'static str = #debug_name_struct; + type Fields<#lt_db> = ( #(#field_tys,)* ); type Struct<#lt_db> = #the_ident<#lt_db>; @@ -263,7 +269,6 @@ impl TrackedStruct { let arity = self.all_field_count(); let tracked_struct_ingredient: Literal = self.tracked_struct_ingredient_index(); let tracked_fields_ingredients: Literal = self.tracked_field_ingredients_index(); - let debug_name_struct = literal(self.the_ident()); let debug_name_fields: Vec<_> = self.all_field_names().into_iter().map(literal).collect(); parse_quote! { @@ -294,7 +299,7 @@ impl TrackedStruct { &mut ingredients.#tracked_struct_ingredient }, ); - salsa::tracked_struct::TrackedStructIngredient::new(index, #debug_name_struct) + salsa::tracked_struct::TrackedStructIngredient::new(index) }; let field_ingredients = [ diff --git a/src/tracked_struct.rs b/src/tracked_struct.rs index b1a9238..95b5386 100644 --- a/src/tracked_struct.rs +++ b/src/tracked_struct.rs @@ -26,6 +26,8 @@ mod tracked_field; /// Implemented by the `#[salsa::tracked]` macro when applied /// to a struct. pub trait Configuration: Sized + 'static { + const DEBUG_NAME: &'static str; + /// A (possibly empty) tuple of the fields for this struct. type Fields<'db>; @@ -134,8 +136,6 @@ 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, } /// Defines the identity of a tracked struct. @@ -215,14 +215,13 @@ where /// Create a tracked struct ingredient. Generated by the `#[tracked]` macro, /// not meant to be called directly by end-users. - pub fn new(index: IngredientIndex, debug_name: &'static str) -> Self { + pub fn new(index: IngredientIndex) -> Self { Self { ingredient_index: index, keys: FxDashMap::default(), counter: AtomicCell::new(0), struct_map: StructMap::new(), dependent_fns: IngredientList::new(), - debug_name, } } @@ -243,7 +242,6 @@ where ingredient_index: field_ingredient_index, field_index, struct_map: self.struct_map.view(), - struct_debug_name: self.debug_name, field_debug_name, } } @@ -457,7 +455,7 @@ where } fn fmt_index(&self, index: Option, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt_index(self.debug_name, index, fmt) + fmt_index(C::DEBUG_NAME, index, fmt) } } diff --git a/src/tracked_struct/tracked_field.rs b/src/tracked_struct/tracked_field.rs index 5e7bc1b..0774a47 100644 --- a/src/tracked_struct/tracked_field.rs +++ b/src/tracked_struct/tracked_field.rs @@ -23,7 +23,6 @@ where pub(super) ingredient_index: IngredientIndex, pub(super) field_index: u32, pub(super) struct_map: StructMapView, - pub(super) struct_debug_name: &'static str, pub(super) field_debug_name: &'static str, } @@ -122,7 +121,7 @@ where write!( fmt, "{}.{}({:?})", - self.struct_debug_name, + C::DEBUG_NAME, self.field_debug_name, index.unwrap() )