mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-15 01:39:25 +00:00
Respect constructor_name
option input, interned and tracked structs
This commit is contained in:
parent
6cb1cb0a47
commit
2970c16e77
4 changed files with 17 additions and 6 deletions
|
@ -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);
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue