remove debug_name from function ingredients

This commit is contained in:
Niko Matsakis 2024-07-06 08:42:15 -04:00
parent aaf8f0bf4f
commit 380b19cc39
3 changed files with 14 additions and 9 deletions

View file

@ -1,6 +1,9 @@
use proc_macro2::Literal;
use crate::xform::ChangeLt;
pub(crate) struct Configuration {
pub(crate) debug_name: Literal,
pub(crate) db_lt: syn::Lifetime,
pub(crate) jar_ty: syn::Type,
pub(crate) salsa_struct_ty: syn::Type,
@ -15,6 +18,7 @@ pub(crate) struct Configuration {
impl Configuration {
pub(crate) fn to_impl(&self, self_ty: &syn::Type) -> syn::ItemImpl {
let Configuration {
debug_name,
db_lt,
jar_ty,
salsa_struct_ty,
@ -27,6 +31,7 @@ impl Configuration {
} = self;
parse_quote! {
impl salsa::function::Configuration for #self_ty {
const DEBUG_NAME: &'static str = #debug_name;
type Jar = #jar_ty;
type SalsaStruct<#db_lt> = #salsa_struct_ty;
type Input<#db_lt> = #input_ty;

View file

@ -498,7 +498,11 @@ fn fn_configuration(args: &FnArgs, item_fn: &syn::ItemFn) -> Configuration {
}
};
// get the name of the function as a string literal
let debug_name = crate::literal(&item_fn.sig.ident);
Configuration {
debug_name,
db_lt,
jar_ty,
salsa_struct_ty,
@ -550,9 +554,6 @@ 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 = crate::literal(&item_fn.sig.ident);
parse_quote! {
impl salsa::storage::IngredientsFor for #config_ty {
type Ingredients = Self;
@ -579,7 +580,7 @@ fn ingredients_for_impl(
<_ as salsa::storage::HasIngredientsFor<Self::Ingredients>>::ingredient_mut(jar);
&mut ingredients.function
});
let ingredient = salsa::function::FunctionIngredient::new(index, #debug_name);
let ingredient = salsa::function::FunctionIngredient::new(index);
ingredient.set_capacity(#lru);
ingredient
}

View file

@ -72,11 +72,11 @@ pub struct FunctionIngredient<C: Configuration> {
/// Set to true once we invoke `register_dependent_fn` for `C::SalsaStruct`.
/// Prevents us from registering more than once.
registered: AtomicCell<bool>,
debug_name: &'static str,
}
pub trait Configuration: 'static {
const DEBUG_NAME: &'static str;
type Jar: Jar;
/// The "salsa struct type" that this function is associated with.
@ -132,7 +132,7 @@ impl<C> FunctionIngredient<C>
where
C: Configuration,
{
pub fn new(index: IngredientIndex, debug_name: &'static str) -> Self {
pub fn new(index: IngredientIndex) -> Self {
Self {
index,
memo_map: memo::MemoMap::default(),
@ -140,7 +140,6 @@ where
sync_map: Default::default(),
deleted_entries: Default::default(),
registered: Default::default(),
debug_name,
}
}
@ -269,7 +268,7 @@ where
}
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)
}
}