mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-02-02 09:46:06 +00:00
remove DatabaseKey associated type
This commit is contained in:
parent
799ddce157
commit
1a07944efe
3 changed files with 1 additions and 77 deletions
|
@ -34,29 +34,18 @@ pub(crate) fn database(args: TokenStream, input: TokenStream) -> TokenStream {
|
|||
})
|
||||
.collect();
|
||||
|
||||
let query_group_key_names: Vec<_> = query_groups
|
||||
.iter()
|
||||
.map(|QueryGroup { group_path }| {
|
||||
quote! {
|
||||
<#group_path as salsa::plumbing::QueryGroup<#database_name>>::GroupKey
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
// For each query group `foo::MyGroup` create a link to its
|
||||
// `foo::MyGroupGroupStorage`
|
||||
let mut storage_fields = proc_macro2::TokenStream::new();
|
||||
let mut storage_initializers = proc_macro2::TokenStream::new();
|
||||
let mut has_group_impls = proc_macro2::TokenStream::new();
|
||||
for ((((query_group, group_name_snake), group_storage), group_key), group_index) in query_groups
|
||||
for (((query_group, group_name_snake), group_storage), group_index) in query_groups
|
||||
.iter()
|
||||
.zip(&query_group_names_snake)
|
||||
.zip(&query_group_storage_names)
|
||||
.zip(&query_group_key_names)
|
||||
.zip(0_u16..)
|
||||
{
|
||||
let group_path = &query_group.group_path;
|
||||
let group_name = query_group.name();
|
||||
|
||||
// rewrite the last identifier (`MyGroup`, above) to
|
||||
// (e.g.) `MyGroupGroupStorage`.
|
||||
|
@ -77,12 +66,6 @@ pub(crate) fn database(args: TokenStream, input: TokenStream) -> TokenStream {
|
|||
let runtime = salsa::Database::salsa_runtime(db);
|
||||
&runtime.storage().#group_name_snake
|
||||
}
|
||||
|
||||
fn database_key(group_key: #group_key) -> __SalsaDatabaseKey {
|
||||
__SalsaDatabaseKey {
|
||||
kind: __SalsaDatabaseKeyKind::#group_name(group_key),
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
// ANCHOR_END:HasQueryGroup
|
||||
|
@ -104,34 +87,6 @@ pub(crate) fn database(args: TokenStream, input: TokenStream) -> TokenStream {
|
|||
}
|
||||
});
|
||||
|
||||
// create query database_key wrapper struct
|
||||
output.extend(quote! {
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
#[doc(hidden)]
|
||||
#visibility struct __SalsaDatabaseKey {
|
||||
kind: __SalsaDatabaseKeyKind
|
||||
}
|
||||
});
|
||||
|
||||
// For each query `fn foo() for FooType` create
|
||||
//
|
||||
// ```
|
||||
// foo(<FooType as salsa::Query<#database_name>>::Key),
|
||||
// ```
|
||||
let mut variants = proc_macro2::TokenStream::new();
|
||||
for (query_group, group_key) in query_groups.iter().zip(&query_group_key_names) {
|
||||
let group_name = query_group.name();
|
||||
variants.extend(quote!(
|
||||
#group_name(#group_key),
|
||||
));
|
||||
}
|
||||
output.extend(quote! {
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
enum __SalsaDatabaseKeyKind {
|
||||
#variants
|
||||
}
|
||||
});
|
||||
|
||||
// Create a tuple (D1, D2, ...) where Di is the data for a given query group.
|
||||
let mut database_data = vec![];
|
||||
for QueryGroup { group_path } in query_groups {
|
||||
|
@ -143,7 +98,6 @@ pub(crate) fn database(args: TokenStream, input: TokenStream) -> TokenStream {
|
|||
// ANCHOR:DatabaseStorageTypes
|
||||
output.extend(quote! {
|
||||
impl salsa::plumbing::DatabaseStorageTypes for #database_name {
|
||||
type DatabaseKey = __SalsaDatabaseKey;
|
||||
type DatabaseStorage = __SalsaDatabaseStorage;
|
||||
}
|
||||
});
|
||||
|
@ -212,13 +166,6 @@ pub(crate) fn database(args: TokenStream, input: TokenStream) -> TokenStream {
|
|||
});
|
||||
// ANCHOR_END:DatabaseOps
|
||||
|
||||
// ANCHOR:DatabaseKey
|
||||
output.extend(quote! {
|
||||
impl salsa::plumbing::DatabaseKey<#database_name> for __SalsaDatabaseKey {
|
||||
}
|
||||
});
|
||||
// ANCHOR_END:DatabaseKey
|
||||
|
||||
output.extend(has_group_impls);
|
||||
|
||||
if std::env::var("SALSA_DUMP").is_ok() {
|
||||
|
|
|
@ -1026,7 +1026,6 @@ where
|
|||
Q: QueryFunction<DB>,
|
||||
DB: Database + HasQueryGroup<Q::Group>,
|
||||
MP: MemoizationPolicy<DB, Q>,
|
||||
DB::DatabaseKey: Send + Sync,
|
||||
Q::Key: Send + Sync,
|
||||
Q::Value: Send + Sync,
|
||||
{
|
||||
|
|
|
@ -30,14 +30,6 @@ pub struct CycleDetected {
|
|||
/// the `database_storage` macro, so you shouldn't need to mess
|
||||
/// with this trait directly.
|
||||
pub trait DatabaseStorageTypes: Sized {
|
||||
/// A "query descriptor" packages up all the possible queries and a key.
|
||||
/// It is used to store information about (e.g.) the stack.
|
||||
///
|
||||
/// At runtime, it can be implemented in various ways: a monster enum
|
||||
/// works for a fixed set of queries, but a boxed trait object is good
|
||||
/// for a more open-ended option.
|
||||
type DatabaseKey: DatabaseKey<Self>;
|
||||
|
||||
/// Defines the "storage type", where all the query data is kept.
|
||||
/// This type is defined by the `database_storage` macro.
|
||||
type DatabaseStorage: Default;
|
||||
|
@ -95,9 +87,6 @@ pub trait GetQueryTable<Q: Query<Self>>: Database {
|
|||
/// Create a mutable query table, which has access to the storage
|
||||
/// for the query and offers methods like `set`.
|
||||
fn get_query_table_mut(db: &mut Self) -> QueryTableMut<'_, Self, Q>;
|
||||
|
||||
/// Create a query descriptor given a key for this query.
|
||||
fn database_key(db: &Self, key: Q::Key) -> Self::DatabaseKey;
|
||||
}
|
||||
|
||||
impl<DB, Q> GetQueryTable<Q> for DB
|
||||
|
@ -117,14 +106,6 @@ where
|
|||
let query_storage = Q::query_storage(group_storage).clone();
|
||||
QueryTableMut::new(db, query_storage)
|
||||
}
|
||||
|
||||
fn database_key(
|
||||
_db: &DB,
|
||||
key: <Q as Query<DB>>::Key,
|
||||
) -> <DB as DatabaseStorageTypes>::DatabaseKey {
|
||||
let group_key = Q::group_key(key);
|
||||
<DB as HasQueryGroup<_>>::database_key(group_key)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait QueryGroup<DB: Database> {
|
||||
|
@ -140,9 +121,6 @@ where
|
|||
{
|
||||
/// Access the group storage struct from the database.
|
||||
fn group_storage(db: &Self) -> &G::GroupStorage;
|
||||
|
||||
/// "Upcast" a group key into a database key.
|
||||
fn database_key(group_key: G::GroupKey) -> Self::DatabaseKey;
|
||||
}
|
||||
|
||||
pub trait QueryStorageOps<DB, Q>
|
||||
|
|
Loading…
Reference in a new issue