mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-22 21:05:11 +00:00
add a 'db
argument to SalsaStruct
This commit is contained in:
parent
9607638d5d
commit
d361e8adfb
3 changed files with 13 additions and 7 deletions
|
@ -1,4 +1,5 @@
|
|||
pub(crate) struct Configuration {
|
||||
pub(crate) db_lt: syn::Lifetime,
|
||||
pub(crate) jar_ty: syn::Type,
|
||||
pub(crate) salsa_struct_ty: syn::Type,
|
||||
pub(crate) input_ty: syn::Type,
|
||||
|
@ -12,6 +13,7 @@ pub(crate) struct Configuration {
|
|||
impl Configuration {
|
||||
pub(crate) fn to_impl(&self, self_ty: &syn::Type) -> syn::ItemImpl {
|
||||
let Configuration {
|
||||
db_lt,
|
||||
jar_ty,
|
||||
salsa_struct_ty,
|
||||
input_ty,
|
||||
|
@ -24,9 +26,9 @@ impl Configuration {
|
|||
parse_quote! {
|
||||
impl salsa::function::Configuration for #self_ty {
|
||||
type Jar = #jar_ty;
|
||||
type SalsaStruct = #salsa_struct_ty;
|
||||
type Input<'db> = #input_ty;
|
||||
type Value<'db> = #value_ty;
|
||||
type SalsaStruct<#db_lt> = #salsa_struct_ty;
|
||||
type Input<#db_lt> = #input_ty;
|
||||
type Value<#db_lt> = #value_ty;
|
||||
const CYCLE_STRATEGY: salsa::cycle::CycleRecoveryStrategy = #cycle_strategy;
|
||||
#backdate_fn
|
||||
#execute_fn
|
||||
|
|
|
@ -4,13 +4,15 @@ use syn::visit_mut::VisitMut;
|
|||
use syn::{ReturnType, Token};
|
||||
|
||||
use crate::configuration::{self, Configuration, CycleRecoveryStrategy};
|
||||
use crate::db_lifetime::{db_lifetime, require_db_lifetime};
|
||||
use crate::db_lifetime::{self, db_lifetime, require_db_lifetime};
|
||||
use crate::options::Options;
|
||||
|
||||
pub(crate) fn tracked_fn(
|
||||
args: proc_macro::TokenStream,
|
||||
mut item_fn: syn::ItemFn,
|
||||
) -> syn::Result<TokenStream> {
|
||||
db_lifetime::require_db_lifetime(&item_fn.sig.generics)?;
|
||||
|
||||
let fn_ident = item_fn.sig.ident.clone();
|
||||
|
||||
let args: FnArgs = syn::parse(args)?;
|
||||
|
@ -390,6 +392,7 @@ fn salsa_struct_ty(item_fn: &syn::ItemFn) -> syn::Type {
|
|||
|
||||
fn fn_configuration(args: &FnArgs, item_fn: &syn::ItemFn) -> Configuration {
|
||||
let jar_ty = args.jar_ty();
|
||||
let db_lt = db_lifetime(&item_fn.sig.generics);
|
||||
let salsa_struct_ty = salsa_struct_ty(item_fn);
|
||||
let key_ty = match function_type(item_fn) {
|
||||
FunctionType::Constant => parse_quote!(()),
|
||||
|
@ -466,6 +469,7 @@ fn fn_configuration(args: &FnArgs, item_fn: &syn::ItemFn) -> Configuration {
|
|||
};
|
||||
|
||||
Configuration {
|
||||
db_lt,
|
||||
jar_ty,
|
||||
salsa_struct_ty,
|
||||
input_ty: key_ty,
|
||||
|
|
|
@ -82,7 +82,7 @@ pub trait Configuration {
|
|||
/// 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>>;
|
||||
type SalsaStruct<'db>: SalsaStructInDb<DynDb<'db, Self>>;
|
||||
|
||||
/// The input to the function
|
||||
type Input<'db>;
|
||||
|
@ -194,9 +194,9 @@ where
|
|||
/// Register this function as a dependent fn of the given salsa struct.
|
||||
/// When instances of that salsa struct are deleted, we'll get a callback
|
||||
/// so we can remove any data keyed by them.
|
||||
fn register(&self, db: &DynDb<'_, C>) {
|
||||
fn register<'db>(&self, db: &'db DynDb<'db, C>) {
|
||||
if !self.registered.fetch_or(true) {
|
||||
<C::SalsaStruct as SalsaStructInDb<_>>::register_dependent_fn(db, self.index)
|
||||
<C::SalsaStruct<'db> as SalsaStructInDb<_>>::register_dependent_fn(db, self.index)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue