move struct debug name to Configuration

This commit is contained in:
Niko Matsakis 2024-07-06 08:34:59 -04:00
parent e1920bdda6
commit 204f4eea6f
3 changed files with 13 additions and 11 deletions

View file

@ -1,6 +1,9 @@
use proc_macro2::{Literal, Span, TokenStream}; 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... /// 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 arity = self.all_field_count();
let the_ident = self.the_ident(); let the_ident = self.the_ident();
let lt_db = &self.named_db_lifetime(); 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. // 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 // If a field is a "backdate field" (the default), then we first check if
@ -143,6 +147,8 @@ impl TrackedStruct {
parse_quote! { parse_quote! {
impl salsa::tracked_struct::Configuration for #config_ident { impl salsa::tracked_struct::Configuration for #config_ident {
const DEBUG_NAME: &'static str = #debug_name_struct;
type Fields<#lt_db> = ( #(#field_tys,)* ); type Fields<#lt_db> = ( #(#field_tys,)* );
type Struct<#lt_db> = #the_ident<#lt_db>; type Struct<#lt_db> = #the_ident<#lt_db>;
@ -263,7 +269,6 @@ impl TrackedStruct {
let arity = self.all_field_count(); let arity = self.all_field_count();
let tracked_struct_ingredient: Literal = self.tracked_struct_ingredient_index(); let tracked_struct_ingredient: Literal = self.tracked_struct_ingredient_index();
let tracked_fields_ingredients: Literal = self.tracked_field_ingredients_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(); let debug_name_fields: Vec<_> = self.all_field_names().into_iter().map(literal).collect();
parse_quote! { parse_quote! {
@ -294,7 +299,7 @@ impl TrackedStruct {
&mut ingredients.#tracked_struct_ingredient &mut ingredients.#tracked_struct_ingredient
}, },
); );
salsa::tracked_struct::TrackedStructIngredient::new(index, #debug_name_struct) salsa::tracked_struct::TrackedStructIngredient::new(index)
}; };
let field_ingredients = [ let field_ingredients = [

View file

@ -26,6 +26,8 @@ mod tracked_field;
/// Implemented by the `#[salsa::tracked]` macro when applied /// Implemented by the `#[salsa::tracked]` macro when applied
/// to a struct. /// to a struct.
pub trait Configuration: Sized + 'static { pub trait Configuration: Sized + 'static {
const DEBUG_NAME: &'static str;
/// A (possibly empty) tuple of the fields for this struct. /// A (possibly empty) tuple of the fields for this struct.
type Fields<'db>; type Fields<'db>;
@ -134,8 +136,6 @@ where
/// each of these functions will be notified /// each of these functions will be notified
/// so they can remove any data tied to that instance. /// so they can remove any data tied to that instance.
dependent_fns: IngredientList, dependent_fns: IngredientList,
debug_name: &'static str,
} }
/// Defines the identity of a tracked struct. /// Defines the identity of a tracked struct.
@ -215,14 +215,13 @@ where
/// Create a tracked struct ingredient. Generated by the `#[tracked]` macro, /// Create a tracked struct ingredient. Generated by the `#[tracked]` macro,
/// not meant to be called directly by end-users. /// 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 { Self {
ingredient_index: index, ingredient_index: index,
keys: FxDashMap::default(), keys: FxDashMap::default(),
counter: AtomicCell::new(0), counter: AtomicCell::new(0),
struct_map: StructMap::new(), struct_map: StructMap::new(),
dependent_fns: IngredientList::new(), dependent_fns: IngredientList::new(),
debug_name,
} }
} }
@ -243,7 +242,6 @@ where
ingredient_index: field_ingredient_index, ingredient_index: field_ingredient_index,
field_index, field_index,
struct_map: self.struct_map.view(), struct_map: self.struct_map.view(),
struct_debug_name: self.debug_name,
field_debug_name, field_debug_name,
} }
} }
@ -457,7 +455,7 @@ where
} }
fn fmt_index(&self, index: Option<crate::Id>, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt_index(&self, index: Option<crate::Id>, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt_index(self.debug_name, index, fmt) fmt_index(C::DEBUG_NAME, index, fmt)
} }
} }

View file

@ -23,7 +23,6 @@ where
pub(super) ingredient_index: IngredientIndex, pub(super) ingredient_index: IngredientIndex,
pub(super) field_index: u32, pub(super) field_index: u32,
pub(super) struct_map: StructMapView<C>, pub(super) struct_map: StructMapView<C>,
pub(super) struct_debug_name: &'static str,
pub(super) field_debug_name: &'static str, pub(super) field_debug_name: &'static str,
} }
@ -122,7 +121,7 @@ where
write!( write!(
fmt, fmt,
"{}.{}({:?})", "{}.{}({:?})",
self.struct_debug_name, C::DEBUG_NAME,
self.field_debug_name, self.field_debug_name,
index.unwrap() index.unwrap()
) )