mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-15 09:48:53 +00:00
give each function a SalsaStruct assoc type
This commit is contained in:
parent
27a240aa86
commit
85d88b8df0
4 changed files with 14 additions and 5 deletions
|
@ -1,5 +1,6 @@
|
||||||
pub(crate) struct Configuration {
|
pub(crate) struct Configuration {
|
||||||
pub(crate) jar_ty: syn::Type,
|
pub(crate) jar_ty: syn::Type,
|
||||||
|
pub(crate) salsa_struct_ty: syn::Type,
|
||||||
pub(crate) key_ty: syn::Type,
|
pub(crate) key_ty: syn::Type,
|
||||||
pub(crate) value_ty: syn::Type,
|
pub(crate) value_ty: syn::Type,
|
||||||
pub(crate) cycle_strategy: CycleRecoveryStrategy,
|
pub(crate) cycle_strategy: CycleRecoveryStrategy,
|
||||||
|
@ -12,6 +13,7 @@ impl Configuration {
|
||||||
pub(crate) fn to_impl(&self, self_ty: &syn::Type) -> syn::ItemImpl {
|
pub(crate) fn to_impl(&self, self_ty: &syn::Type) -> syn::ItemImpl {
|
||||||
let Configuration {
|
let Configuration {
|
||||||
jar_ty,
|
jar_ty,
|
||||||
|
salsa_struct_ty,
|
||||||
key_ty,
|
key_ty,
|
||||||
value_ty,
|
value_ty,
|
||||||
cycle_strategy,
|
cycle_strategy,
|
||||||
|
@ -22,6 +24,7 @@ impl Configuration {
|
||||||
parse_quote! {
|
parse_quote! {
|
||||||
impl salsa::function::Configuration for #self_ty {
|
impl salsa::function::Configuration for #self_ty {
|
||||||
type Jar = #jar_ty;
|
type Jar = #jar_ty;
|
||||||
|
type SalsaStruct = #salsa_struct_ty;
|
||||||
type Key = #key_ty;
|
type Key = #key_ty;
|
||||||
type Value = #value_ty;
|
type Value = #value_ty;
|
||||||
const CYCLE_STRATEGY: salsa::cycle::CycleRecoveryStrategy = #cycle_strategy;
|
const CYCLE_STRATEGY: salsa::cycle::CycleRecoveryStrategy = #cycle_strategy;
|
||||||
|
|
|
@ -221,6 +221,7 @@ impl SalsaStruct {
|
||||||
let item_impl: syn::ItemImpl = parse_quote! {
|
let item_impl: syn::ItemImpl = parse_quote! {
|
||||||
impl salsa::function::Configuration for #config_name {
|
impl salsa::function::Configuration for #config_name {
|
||||||
type Jar = #jar_ty;
|
type Jar = #jar_ty;
|
||||||
|
type SalsaStruct = #ident;
|
||||||
type Key = #ident;
|
type Key = #ident;
|
||||||
type Value = #value_field_ty;
|
type Value = #value_field_ty;
|
||||||
const CYCLE_STRATEGY: salsa::cycle::CycleRecoveryStrategy = salsa::cycle::CycleRecoveryStrategy::Panic;
|
const CYCLE_STRATEGY: salsa::cycle::CycleRecoveryStrategy = salsa::cycle::CycleRecoveryStrategy::Panic;
|
||||||
|
|
|
@ -101,10 +101,7 @@ fn configuration_struct(item_fn: &syn::ItemFn) -> syn::ItemStruct {
|
||||||
|
|
||||||
parse_quote! {
|
parse_quote! {
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
#visibility struct #fn_name
|
#visibility struct #fn_name {
|
||||||
where
|
|
||||||
#salsa_struct_ty: salsa::AsId, // require that the salsa struct is, well, a salsa struct!
|
|
||||||
{
|
|
||||||
intern_map: #intern_map,
|
intern_map: #intern_map,
|
||||||
function: salsa::function::FunctionIngredient<Self>,
|
function: salsa::function::FunctionIngredient<Self>,
|
||||||
}
|
}
|
||||||
|
@ -127,10 +124,11 @@ fn salsa_struct_ty(item_fn: &syn::ItemFn) -> &syn::Type {
|
||||||
|
|
||||||
fn fn_configuration(args: &Args, item_fn: &syn::ItemFn) -> Configuration {
|
fn fn_configuration(args: &Args, item_fn: &syn::ItemFn) -> Configuration {
|
||||||
let jar_ty = args.jar_ty();
|
let jar_ty = args.jar_ty();
|
||||||
|
let salsa_struct_ty = salsa_struct_ty(item_fn).clone();
|
||||||
let key_ty = if requires_interning(item_fn) {
|
let key_ty = if requires_interning(item_fn) {
|
||||||
parse_quote!(salsa::id::Id)
|
parse_quote!(salsa::id::Id)
|
||||||
} else {
|
} else {
|
||||||
salsa_struct_ty(item_fn).clone()
|
salsa_struct_ty.clone()
|
||||||
};
|
};
|
||||||
let value_ty = configuration::value_ty(&item_fn.sig);
|
let value_ty = configuration::value_ty(&item_fn.sig);
|
||||||
|
|
||||||
|
@ -187,6 +185,7 @@ fn fn_configuration(args: &Args, item_fn: &syn::ItemFn) -> Configuration {
|
||||||
|
|
||||||
Configuration {
|
Configuration {
|
||||||
jar_ty,
|
jar_ty,
|
||||||
|
salsa_struct_ty,
|
||||||
key_ty,
|
key_ty,
|
||||||
value_ty,
|
value_ty,
|
||||||
cycle_strategy,
|
cycle_strategy,
|
||||||
|
|
|
@ -9,6 +9,7 @@ use crate::{
|
||||||
jar::Jar,
|
jar::Jar,
|
||||||
key::{DatabaseKeyIndex, DependencyIndex},
|
key::{DatabaseKeyIndex, DependencyIndex},
|
||||||
runtime::local_state::QueryInputs,
|
runtime::local_state::QueryInputs,
|
||||||
|
salsa_struct::SalsaStructInDb,
|
||||||
Cycle, DbWithJar, Id, Revision,
|
Cycle, DbWithJar, Id, Revision,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -69,6 +70,11 @@ pub struct FunctionIngredient<C: Configuration> {
|
||||||
pub trait Configuration {
|
pub trait Configuration {
|
||||||
type Jar: for<'db> Jar<'db>;
|
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<DynDb<'db, Self>>;
|
||||||
|
|
||||||
/// What key is used to index the memo. Typically a salsa struct id,
|
/// 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`
|
/// but if this memoized function has multiple argments it will be a `salsa::Id`
|
||||||
/// that results from interning those arguments.
|
/// that results from interning those arguments.
|
||||||
|
|
Loading…
Reference in a new issue