defer for-each-query to the query-group

This commit is contained in:
Niko Matsakis 2019-01-23 10:56:01 -05:00
parent c18914ae1e
commit f3483d1a22
3 changed files with 32 additions and 4 deletions

View file

@ -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! {

View file

@ -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()
}

View file

@ -87,6 +87,7 @@ pub trait GetQueryGroupStorage<S>: Database {
pub trait QueryStorageOps<DB, Q>: Default
where
Self: QueryStorageMassOps<DB>,
DB: Database,
Q: Query<DB>,
{