From 958b063a60150f3836ba235ec425f988f6b657c0 Mon Sep 17 00:00:00 2001 From: Mihail Mihov Date: Sun, 21 Aug 2022 01:24:27 +0300 Subject: [PATCH] Update input, interned and tracked structs to use specified getter and setter names --- components/salsa-2022-macros/src/input.rs | 13 +++++++------ components/salsa-2022-macros/src/interned.rs | 5 +++-- components/salsa-2022-macros/src/tracked_struct.rs | 14 ++++++++------ 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/components/salsa-2022-macros/src/input.rs b/components/salsa-2022-macros/src/input.rs index fb605dd7..9932226b 100644 --- a/components/salsa-2022-macros/src/input.rs +++ b/components/salsa-2022-macros/src/input.rs @@ -64,13 +64,14 @@ impl InputStruct { let input_index = self.input_index(); let field_indices = self.all_field_indices(); - let field_names: Vec<_> = self.all_field_names(); + let field_names = self.all_field_names(); let field_tys: Vec<_> = self.all_field_tys(); let field_clones: Vec<_> = self.all_fields().map(SalsaField::is_clone_field).collect(); - let field_getters: Vec = field_indices.iter().zip(&field_names).zip(&field_tys).zip(&field_clones).map(|(((field_index, field_name), field_ty), is_clone_field)| + let get_field_names: Vec<_> = self.all_get_field_names(); + let field_getters: Vec = field_indices.iter().zip(&get_field_names).zip(&field_tys).zip(&field_clones).map(|(((field_index, get_field_name), field_ty), is_clone_field)| if !*is_clone_field { parse_quote! { - pub fn #field_name<'db>(self, __db: &'db #db_dyn_ty) -> &'db #field_ty + pub fn #get_field_name<'db>(self, __db: &'db #db_dyn_ty) -> &'db #field_ty { let (__jar, __runtime) = <_ as salsa::storage::HasJar<#jar_ty>>::jar(__db); let __ingredients = <#jar_ty as salsa::storage::HasIngredientsFor< #ident >>::ingredient(__jar); @@ -79,7 +80,7 @@ impl InputStruct { } } else { parse_quote! { - pub fn #field_name<'db>(self, __db: &'db #db_dyn_ty) -> #field_ty + pub fn #get_field_name<'db>(self, __db: &'db #db_dyn_ty) -> #field_ty { let (__jar, __runtime) = <_ as salsa::storage::HasJar<#jar_ty>>::jar(__db); let __ingredients = <#jar_ty as salsa::storage::HasIngredientsFor< #ident >>::ingredient(__jar); @@ -90,8 +91,8 @@ impl InputStruct { ) .collect(); - let field_setters: Vec = field_indices.iter().zip(&field_names).zip(&field_tys).map(|((field_index, field_name), field_ty)| { - let set_field_name = syn::Ident::new(&format!("set_{}", field_name), field_name.span()); + let set_field_names = self.all_set_field_names(); + let field_setters: Vec = field_indices.iter().zip(&set_field_names).zip(&field_tys).map(|((field_index, set_field_name), field_ty)| { parse_quote! { pub fn #set_field_name<'db>(self, __db: &'db mut #db_dyn_ty, __value: #field_ty) -> #field_ty { diff --git a/components/salsa-2022-macros/src/interned.rs b/components/salsa-2022-macros/src/interned.rs index d465b126..629a23de 100644 --- a/components/salsa-2022-macros/src/interned.rs +++ b/components/salsa-2022-macros/src/interned.rs @@ -68,9 +68,10 @@ impl InternedStruct { .map(|field| { let field_name = field.name(); let field_ty = field.ty(); + let field_get_name = field.get_name(); if field.is_clone_field() { parse_quote! { - #vis fn #field_name(self, db: &#db_dyn_ty) -> #field_ty { + #vis fn #field_get_name(self, db: &#db_dyn_ty) -> #field_ty { let (jar, runtime) = <_ as salsa::storage::HasJar<#jar_ty>>::jar(db); let ingredients = <#jar_ty as salsa::storage::HasIngredientsFor< #id_ident >>::ingredient(jar); std::clone::Clone::clone(&ingredients.data(runtime, self).#field_name) @@ -78,7 +79,7 @@ impl InternedStruct { } } else { parse_quote! { - #vis fn #field_name<'db>(self, db: &'db #db_dyn_ty) -> &'db #field_ty { + #vis fn #field_get_name<'db>(self, db: &'db #db_dyn_ty) -> &'db #field_ty { let (jar, runtime) = <_ as salsa::storage::HasJar<#jar_ty>>::jar(db); let ingredients = <#jar_ty as salsa::storage::HasIngredientsFor< #id_ident >>::ingredient(jar); &ingredients.data(runtime, self).#field_name diff --git a/components/salsa-2022-macros/src/tracked_struct.rs b/components/salsa-2022-macros/src/tracked_struct.rs index 1de06f03..5212e5b0 100644 --- a/components/salsa-2022-macros/src/tracked_struct.rs +++ b/components/salsa-2022-macros/src/tracked_struct.rs @@ -67,12 +67,13 @@ impl TrackedStruct { let id_field_indices: Vec<_> = self.id_field_indices(); let id_field_names: Vec<_> = self.id_fields().map(SalsaField::name).collect(); + let id_field_get_names: Vec<_> = self.id_fields().map(SalsaField::get_name).collect(); let id_field_tys: Vec<_> = self.id_fields().map(SalsaField::ty).collect(); let id_field_clones: Vec<_> = self.id_fields().map(SalsaField::is_clone_field).collect(); - let id_field_getters: Vec = id_field_indices.iter().zip(&id_field_names).zip(&id_field_tys).zip(&id_field_clones).map(|(((field_index, field_name), field_ty), is_clone_field)| + let id_field_getters: Vec = id_field_indices.iter().zip(&id_field_get_names).zip(&id_field_tys).zip(&id_field_clones).map(|(((field_index, field_get_name), field_ty), is_clone_field)| if !*is_clone_field { parse_quote! { - pub fn #field_name<'db>(self, __db: &'db #db_dyn_ty) -> &'db #field_ty + pub fn #field_get_name<'db>(self, __db: &'db #db_dyn_ty) -> &'db #field_ty { let (__jar, __runtime) = <_ as salsa::storage::HasJar<#jar_ty>>::jar(__db); let __ingredients = <#jar_ty as salsa::storage::HasIngredientsFor< #ident >>::ingredient(__jar); @@ -81,7 +82,7 @@ impl TrackedStruct { } } else { parse_quote! { - pub fn #field_name<'db>(self, __db: &'db #db_dyn_ty) -> #field_ty + pub fn #field_get_name<'db>(self, __db: &'db #db_dyn_ty) -> #field_ty { let (__jar, __runtime) = <_ as salsa::storage::HasJar<#jar_ty>>::jar(__db); let __ingredients = <#jar_ty as salsa::storage::HasIngredientsFor< #ident >>::ingredient(__jar); @@ -95,14 +96,15 @@ impl TrackedStruct { let value_field_indices = self.value_field_indices(); let value_field_names: Vec<_> = self.value_fields().map(SalsaField::name).collect(); let value_field_tys: Vec<_> = self.value_fields().map(SalsaField::ty).collect(); + let value_field_get_names: Vec<_> = self.value_fields().map(SalsaField::get_name).collect(); let value_field_clones: Vec<_> = self .value_fields() .map(SalsaField::is_clone_field) .collect(); - let value_field_getters: Vec = value_field_indices.iter().zip(&value_field_names).zip(&value_field_tys).zip(&value_field_clones).map(|(((field_index, field_name), field_ty), is_clone_field)| + let value_field_getters: Vec = value_field_indices.iter().zip(&value_field_get_names).zip(&value_field_tys).zip(&value_field_clones).map(|(((field_index, field_get_name), field_ty), is_clone_field)| if !*is_clone_field { parse_quote! { - pub fn #field_name<'db>(self, __db: &'db #db_dyn_ty) -> &'db #field_ty + pub fn #field_get_name<'db>(self, __db: &'db #db_dyn_ty) -> &'db #field_ty { let (__jar, __runtime) = <_ as salsa::storage::HasJar<#jar_ty>>::jar(__db); let __ingredients = <#jar_ty as salsa::storage::HasIngredientsFor< #ident >>::ingredient(__jar); @@ -111,7 +113,7 @@ impl TrackedStruct { } } else { parse_quote! { - pub fn #field_name<'db>(self, __db: &'db #db_dyn_ty) -> #field_ty + pub fn #field_get_name<'db>(self, __db: &'db #db_dyn_ty) -> #field_ty { let (__jar, __runtime) = <_ as salsa::storage::HasJar<#jar_ty>>::jar(__db); let __ingredients = <#jar_ty as salsa::storage::HasIngredientsFor< #ident >>::ingredient(__jar);