mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-12 16:35:21 +00:00
defer for-each-query to the query-group
This commit is contained in:
parent
c18914ae1e
commit
f3483d1a22
3 changed files with 32 additions and 4 deletions
|
@ -128,11 +128,11 @@ pub(crate) fn database_storage(input: TokenStream) -> TokenStream {
|
|||
|
||||
//
|
||||
let mut for_each_ops = proc_macro2::TokenStream::new();
|
||||
for (query_group, Query { query_name, .. }) in each_query() {
|
||||
for query_group in &query_groups {
|
||||
let group_storage = query_group.group_storage();
|
||||
for_each_ops.extend(quote! {
|
||||
let storage: &#group_storage<#database_name> = ::salsa::plumbing::GetQueryGroupStorage::from(self);
|
||||
op(&storage.#query_name);
|
||||
storage.for_each_query(self, &mut op);
|
||||
});
|
||||
}
|
||||
output.extend(quote! {
|
||||
|
|
|
@ -213,7 +213,7 @@ pub(crate) fn query_group(args: TokenStream, input: TokenStream) -> TokenStream
|
|||
});
|
||||
|
||||
// Emit the query types.
|
||||
for query in queries {
|
||||
for query in &queries {
|
||||
let qt = &query.query_type;
|
||||
let storage = Ident::new(
|
||||
match query.storage {
|
||||
|
@ -255,7 +255,7 @@ pub(crate) fn query_group(args: TokenStream, input: TokenStream) -> TokenStream
|
|||
};
|
||||
let invoke = match &query.invoke {
|
||||
Some(i) => i.into_token_stream(),
|
||||
None => query.fn_name.into_token_stream(),
|
||||
None => query.fn_name.clone().into_token_stream(),
|
||||
};
|
||||
output.extend(quote_spanned! {span=>
|
||||
impl<DB> salsa::plumbing::QueryFunction<DB> for #qt
|
||||
|
@ -296,14 +296,41 @@ pub(crate) fn query_group(args: TokenStream, input: TokenStream) -> TokenStream
|
|||
}
|
||||
});
|
||||
|
||||
let mut for_each_ops = proc_macro2::TokenStream::new();
|
||||
for Query { fn_name, .. } in &queries {
|
||||
for_each_ops.extend(quote! {
|
||||
op(&self.#fn_name);
|
||||
});
|
||||
}
|
||||
|
||||
// Emit query group storage struct
|
||||
output.extend(quote! {
|
||||
#[derive(Default)]
|
||||
#trait_vis struct #group_storage<DB__: #trait_name> {
|
||||
#storage_fields
|
||||
}
|
||||
|
||||
impl<DB__> #group_storage<DB__>
|
||||
where
|
||||
DB__: #trait_name,
|
||||
DB__: ::salsa::plumbing::GetQueryGroupStorage<#group_storage<DB__>>,
|
||||
{
|
||||
#trait_vis fn for_each_query(
|
||||
&self,
|
||||
db: &DB__,
|
||||
mut op: &mut dyn FnMut(&dyn ::salsa::plumbing::QueryStorageMassOps<DB__>),
|
||||
) {
|
||||
#for_each_ops
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if std::env::var("SALSA_DUMP").is_ok() {
|
||||
println!("~~~ query_group");
|
||||
println!("{}", output.to_string());
|
||||
println!("~~~ query_group");
|
||||
}
|
||||
|
||||
output.into()
|
||||
}
|
||||
|
||||
|
|
|
@ -87,6 +87,7 @@ pub trait GetQueryGroupStorage<S>: Database {
|
|||
|
||||
pub trait QueryStorageOps<DB, Q>: Default
|
||||
where
|
||||
Self: QueryStorageMassOps<DB>,
|
||||
DB: Database,
|
||||
Q: Query<DB>,
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue