rename FromQueryGroupDescriptor and add comments

This commit is contained in:
Niko Matsakis 2019-01-24 05:18:43 -05:00
parent 860a1ab1bf
commit 1c415b0c9d
3 changed files with 13 additions and 4 deletions

View file

@ -80,7 +80,7 @@ pub(crate) fn database_storage(input: TokenStream) -> TokenStream {
// rewrite the last identifier (`MyGroup`, above) to
// (e.g.) `MyGroupGroupStorage`.
descriptor_impls.extend(quote! {
impl ::salsa::plumbing::FromQueryGroupDescriptor<#group_descriptor> for #database_name {
impl ::salsa::plumbing::GetDatabaseDescriptor<#group_descriptor> for #database_name {
fn from(descriptor: #group_descriptor) -> __SalsaQueryDescriptor {
__SalsaQueryDescriptor {
kind: __SalsaQueryDescriptorKind::#group_name(descriptor),
@ -226,7 +226,7 @@ pub(crate) fn database_storage(input: TokenStream) -> TokenStream {
db: &Self,
key: <#query_type as ::salsa::Query<Self>>::Key,
) -> <Self as ::salsa::plumbing::DatabaseStorageTypes>::QueryDescriptor {
<Self as ::salsa::plumbing::FromQueryGroupDescriptor<_>>::from(#group_descriptor::#query_name(key))
<Self as ::salsa::plumbing::GetDatabaseDescriptor<_>>::from(#group_descriptor::#query_name(key))
}
}
});

View file

@ -206,7 +206,7 @@ pub(crate) fn query_group(args: TokenStream, input: TokenStream) -> TokenStream
where
T: #(salsa::plumbing::GetQueryTable<#qts> +)* #bounds,
T: ::salsa::plumbing::GetQueryGroupStorage<#group_storage<T>>,
T: ::salsa::plumbing::FromQueryGroupDescriptor<#group_descriptor>,
T: ::salsa::plumbing::GetDatabaseDescriptor<#group_descriptor>,
{
#query_fn_definitions
}

View file

@ -81,11 +81,20 @@ pub trait GetQueryTable<Q: Query<Self>>: Database {
fn descriptor(db: &Self, key: Q::Key) -> Self::QueryDescriptor;
}
/// Access the "group storage" with type `S` from the database.
///
/// This basically moves from the full context of the database to the context
/// of one query group.
pub trait GetQueryGroupStorage<S>: Database {
fn from(db: &Self) -> &S;
}
pub trait FromQueryGroupDescriptor<D>: Database {
/// Given a group descriptor of type `D`, convert it to a full
/// database query descriptor.
///
/// This basically moves a descriptor from the context of the query
/// group into the full context of the database.
pub trait GetDatabaseDescriptor<D>: Database {
fn from(descriptor: D) -> Self::QueryDescriptor;
}