From 1a07944efe64b67dfb69f6ad5379e7e935be0f98 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 1 Jul 2020 10:04:57 +0000 Subject: [PATCH] remove DatabaseKey associated type --- .../salsa-macros/src/database_storage.rs | 55 +------------------ src/derived/slot.rs | 1 - src/plumbing.rs | 22 -------- 3 files changed, 1 insertion(+), 77 deletions(-) diff --git a/components/salsa-macros/src/database_storage.rs b/components/salsa-macros/src/database_storage.rs index db9125f..6ff006b 100644 --- a/components/salsa-macros/src/database_storage.rs +++ b/components/salsa-macros/src/database_storage.rs @@ -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(>::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() { diff --git a/src/derived/slot.rs b/src/derived/slot.rs index 4db27de..316df92 100644 --- a/src/derived/slot.rs +++ b/src/derived/slot.rs @@ -1026,7 +1026,6 @@ where Q: QueryFunction, DB: Database + HasQueryGroup, MP: MemoizationPolicy, - DB::DatabaseKey: Send + Sync, Q::Key: Send + Sync, Q::Value: Send + Sync, { diff --git a/src/plumbing.rs b/src/plumbing.rs index 806aef5..075d1f8 100644 --- a/src/plumbing.rs +++ b/src/plumbing.rs @@ -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; - /// 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>: 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 GetQueryTable 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: >::Key, - ) -> ::DatabaseKey { - let group_key = Q::group_key(key); - >::database_key(group_key) - } } pub trait QueryGroup { @@ -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