From fd036a4f154c46253443b3a79b6f4400c40e87b1 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 6 Jul 2020 21:48:14 +0000 Subject: [PATCH] do not generate `in_db_mut` when it is inappropriate --- components/salsa-macros/src/query_group.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/components/salsa-macros/src/query_group.rs b/components/salsa-macros/src/query_group.rs index 307584fb..917dea2d 100644 --- a/components/salsa-macros/src/query_group.rs +++ b/components/salsa-macros/src/query_group.rs @@ -364,7 +364,9 @@ pub(crate) fn query_group(args: TokenStream, input: TokenStream) -> TokenStream output.extend(quote! { #[derive(Default, Debug)] #trait_vis struct #qt; + }); + output.extend(quote! { impl #qt { /// Get access to extra methods pertaining to this query. For /// example, you can use this to run the GC (`sweep`) across a @@ -375,7 +377,12 @@ pub(crate) fn query_group(args: TokenStream, input: TokenStream) -> TokenStream { salsa::plumbing::get_query_table::<#qt>(db) } + } + }); + if query.storage.supports_mut() {} + output.extend(quote! { + impl #qt { /// Like `in_db`, but gives access to methods for setting the /// value of an input. Not applicable to derived queries. /// @@ -651,6 +658,7 @@ enum QueryStorage { } impl QueryStorage { + /// Do we need a `QueryFunction` impl for this type of query? fn needs_query_function(&self) -> bool { match self { QueryStorage::Input @@ -660,4 +668,16 @@ impl QueryStorage { QueryStorage::Memoized | QueryStorage::Dependencies => true, } } + + /// Does this type of query support `&mut` operations? + fn supports_mut(&self) -> bool { + match self { + QueryStorage::Input => true, + QueryStorage::Interned + | QueryStorage::InternedLookup { .. } + | QueryStorage::Transparent + | QueryStorage::Memoized + | QueryStorage::Dependencies => false, + } + } }