diff --git a/components/salsa-2022-macros/src/input.rs b/components/salsa-2022-macros/src/input.rs index a09794c9..fb605dd7 100644 --- a/components/salsa-2022-macros/src/input.rs +++ b/components/salsa-2022-macros/src/input.rs @@ -103,9 +103,10 @@ impl InputStruct { }) .collect(); + let constructor_name = self.constructor_name(); parse_quote! { impl #ident { - pub fn new(__db: &mut #db_dyn_ty, #(#field_names: #field_tys,)*) -> Self + pub fn #constructor_name(__db: &mut #db_dyn_ty, #(#field_names: #field_tys,)*) -> Self { let (__jar, __runtime) = <_ as salsa::storage::HasJar<#jar_ty>>::jar_mut(__db); let __ingredients = <#jar_ty as salsa::storage::HasIngredientsFor< #ident >>::ingredient_mut(__jar); diff --git a/components/salsa-2022-macros/src/interned.rs b/components/salsa-2022-macros/src/interned.rs index 2d5dc0ff..d465b126 100644 --- a/components/salsa-2022-macros/src/interned.rs +++ b/components/salsa-2022-macros/src/interned.rs @@ -91,8 +91,9 @@ impl InternedStruct { let field_names = self.all_field_names(); let field_tys = self.all_field_tys(); let data_ident = self.data_ident(); + let constructor_name = self.constructor_name(); let new_method: syn::ImplItemMethod = parse_quote! { - #vis fn new( + #vis fn #constructor_name( db: &#db_dyn_ty, #(#field_names: #field_tys,)* ) -> Self { diff --git a/components/salsa-2022-macros/src/salsa_struct.rs b/components/salsa-2022-macros/src/salsa_struct.rs index 3ca774fa..d6785040 100644 --- a/components/salsa-2022-macros/src/salsa_struct.rs +++ b/components/salsa-2022-macros/src/salsa_struct.rs @@ -26,7 +26,7 @@ //! * this could be optimized, particularly for interned fields use heck::CamelCase; -use proc_macro2::Literal; +use proc_macro2::{Ident, Literal, Span}; use crate::{configuration, options::Options}; @@ -195,6 +195,14 @@ impl SalsaStruct { &self.struct_item.vis } + /// Returns the `constructor_name` in `Options` if it is `Some`, else `new` + pub(crate) fn constructor_name(&self) -> syn::Ident { + match self.args.constructor_name.clone() { + Some(name) => name, + None => Ident::new("new", Span::call_site()), + } + } + /// For each of the fields passed as an argument, /// generate a struct named `Ident_Field` and an impl /// of `salsa::function::Configuration` for that struct. @@ -343,12 +351,12 @@ impl SalsaField { Ok(result) } - /// The name of this field (all `EntityField` instances are named). + /// The name of this field (all `SalsaField` instances are named). pub(crate) fn name(&self) -> &syn::Ident { self.field.ident.as_ref().unwrap() } - /// The type of this field (all `EntityField` instances are named). + /// The type of this field (all `SalsaField` instances are named). pub(crate) fn ty(&self) -> &syn::Type { &self.field.ty } diff --git a/components/salsa-2022-macros/src/tracked_struct.rs b/components/salsa-2022-macros/src/tracked_struct.rs index b689ff6d..1de06f03 100644 --- a/components/salsa-2022-macros/src/tracked_struct.rs +++ b/components/salsa-2022-macros/src/tracked_struct.rs @@ -124,10 +124,11 @@ impl TrackedStruct { let all_field_names = self.all_field_names(); let all_field_tys = self.all_field_tys(); + let constructor_name = self.constructor_name(); parse_quote! { impl #ident { - pub fn new(__db: &#db_dyn_ty, #(#all_field_names: #all_field_tys,)*) -> Self + pub fn #constructor_name(__db: &#db_dyn_ty, #(#all_field_names: #all_field_tys,)*) -> Self { let (__jar, __runtime) = <_ as salsa::storage::HasJar<#jar_ty>>::jar(__db); let __ingredients = <#jar_ty as salsa::storage::HasIngredientsFor< #ident >>::ingredient(__jar);