diff --git a/components/salsa-2022-macros/src/configuration.rs b/components/salsa-2022-macros/src/configuration.rs index 27ba779e..12a03bc9 100644 --- a/components/salsa-2022-macros/src/configuration.rs +++ b/components/salsa-2022-macros/src/configuration.rs @@ -1,5 +1,6 @@ pub(crate) struct Configuration { pub(crate) jar_ty: syn::Type, + pub(crate) salsa_struct_ty: syn::Type, pub(crate) key_ty: syn::Type, pub(crate) value_ty: syn::Type, pub(crate) cycle_strategy: CycleRecoveryStrategy, @@ -12,6 +13,7 @@ impl Configuration { pub(crate) fn to_impl(&self, self_ty: &syn::Type) -> syn::ItemImpl { let Configuration { jar_ty, + salsa_struct_ty, key_ty, value_ty, cycle_strategy, @@ -22,6 +24,7 @@ impl Configuration { parse_quote! { impl salsa::function::Configuration for #self_ty { type Jar = #jar_ty; + type SalsaStruct = #salsa_struct_ty; type Key = #key_ty; type Value = #value_ty; const CYCLE_STRATEGY: salsa::cycle::CycleRecoveryStrategy = #cycle_strategy; diff --git a/components/salsa-2022-macros/src/salsa_struct.rs b/components/salsa-2022-macros/src/salsa_struct.rs index 72bf27ce..8f270328 100644 --- a/components/salsa-2022-macros/src/salsa_struct.rs +++ b/components/salsa-2022-macros/src/salsa_struct.rs @@ -221,6 +221,7 @@ impl SalsaStruct { let item_impl: syn::ItemImpl = parse_quote! { impl salsa::function::Configuration for #config_name { type Jar = #jar_ty; + type SalsaStruct = #ident; type Key = #ident; type Value = #value_field_ty; const CYCLE_STRATEGY: salsa::cycle::CycleRecoveryStrategy = salsa::cycle::CycleRecoveryStrategy::Panic; diff --git a/components/salsa-2022-macros/src/tracked_fn.rs b/components/salsa-2022-macros/src/tracked_fn.rs index ee101837..feb362d0 100644 --- a/components/salsa-2022-macros/src/tracked_fn.rs +++ b/components/salsa-2022-macros/src/tracked_fn.rs @@ -101,10 +101,7 @@ fn configuration_struct(item_fn: &syn::ItemFn) -> syn::ItemStruct { parse_quote! { #[allow(non_camel_case_types)] - #visibility struct #fn_name - where - #salsa_struct_ty: salsa::AsId, // require that the salsa struct is, well, a salsa struct! - { + #visibility struct #fn_name { intern_map: #intern_map, function: salsa::function::FunctionIngredient, } @@ -127,10 +124,11 @@ fn salsa_struct_ty(item_fn: &syn::ItemFn) -> &syn::Type { fn fn_configuration(args: &Args, item_fn: &syn::ItemFn) -> Configuration { let jar_ty = args.jar_ty(); + let salsa_struct_ty = salsa_struct_ty(item_fn).clone(); let key_ty = if requires_interning(item_fn) { parse_quote!(salsa::id::Id) } else { - salsa_struct_ty(item_fn).clone() + salsa_struct_ty.clone() }; let value_ty = configuration::value_ty(&item_fn.sig); @@ -187,6 +185,7 @@ fn fn_configuration(args: &Args, item_fn: &syn::ItemFn) -> Configuration { Configuration { jar_ty, + salsa_struct_ty, key_ty, value_ty, cycle_strategy, diff --git a/components/salsa-2022/src/function.rs b/components/salsa-2022/src/function.rs index e533bdd2..fddd3a88 100644 --- a/components/salsa-2022/src/function.rs +++ b/components/salsa-2022/src/function.rs @@ -9,6 +9,7 @@ use crate::{ jar::Jar, key::{DatabaseKeyIndex, DependencyIndex}, runtime::local_state::QueryInputs, + salsa_struct::SalsaStructInDb, Cycle, DbWithJar, Id, Revision, }; @@ -69,6 +70,11 @@ pub struct FunctionIngredient { pub trait Configuration { type Jar: for<'db> Jar<'db>; + /// The "salsa struct type" that this function is associated with. + /// This can be just `salsa::Id` for functions that intern their arguments + /// and are not clearly associated with any one salsa struct. + type SalsaStruct: for<'db> SalsaStructInDb>; + /// What key is used to index the memo. Typically a salsa struct id, /// but if this memoized function has multiple argments it will be a `salsa::Id` /// that results from interning those arguments.