From 7b8e2a52ff29d400b4d869fad1d917ffa9bdce59 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 24 Aug 2022 00:02:37 -0500 Subject: [PATCH 1/2] Simplify the syntax for macros generated by `rustc_queries` - Disallow multiple macros callbacks in the same invocation. In practice, this was never used. - Remove the `[]` brackets around the macro name - Require an `ident`, not an arbitrary `tt` --- compiler/rustc_macros/src/query.rs | 12 ++++++------ compiler/rustc_middle/src/dep_graph/dep_node.rs | 2 +- compiler/rustc_middle/src/ty/query.rs | 2 +- compiler/rustc_query_impl/src/lib.rs | 2 +- compiler/rustc_query_impl/src/profiling_support.rs | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_macros/src/query.rs b/compiler/rustc_macros/src/query.rs index 32a15413c6fef..d80d35cb1fa32 100644 --- a/compiler/rustc_macros/src/query.rs +++ b/compiler/rustc_macros/src/query.rs @@ -400,15 +400,15 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream { TokenStream::from(quote! { #[macro_export] macro_rules! rustc_query_append { - ([$($macro:tt)*]) => { - $($macro)* { + ($macro:ident !) => { + $macro! { #query_stream } } } macro_rules! rustc_dep_node_append { - ([$($macro:tt)*][$($other:tt)*]) => { - $($macro)*( + ($macro:ident! [$($other:tt)*]) => { + $macro!( $($other)* #dep_node_def_stream @@ -417,8 +417,8 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream { } #[macro_export] macro_rules! rustc_cached_queries { - ($($macro:tt)*) => { - $($macro)*(#cached_queries); + ( $macro:ident! ) => { + $macro!(#cached_queries); } } #[macro_export] diff --git a/compiler/rustc_middle/src/dep_graph/dep_node.rs b/compiler/rustc_middle/src/dep_graph/dep_node.rs index 156a9641272f5..65fc8a2e9cf5a 100644 --- a/compiler/rustc_middle/src/dep_graph/dep_node.rs +++ b/compiler/rustc_middle/src/dep_graph/dep_node.rs @@ -179,7 +179,7 @@ macro_rules! define_dep_nodes { ); } -rustc_dep_node_append!([define_dep_nodes!][ +rustc_dep_node_append!(define_dep_nodes![ // We use this for most things when incr. comp. is turned off. [] Null, diff --git a/compiler/rustc_middle/src/ty/query.rs b/compiler/rustc_middle/src/ty/query.rs index 736ab69c81219..5665bb866d46c 100644 --- a/compiler/rustc_middle/src/ty/query.rs +++ b/compiler/rustc_middle/src/ty/query.rs @@ -332,7 +332,7 @@ macro_rules! define_callbacks { // Queries marked with `fatal_cycle` do not need the latter implementation, // as they will raise an fatal error on query cycles instead. -rustc_query_append! { [define_callbacks!] } +rustc_query_append! { define_callbacks! } mod sealed { use super::{DefId, LocalDefId}; diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index 946bc34fea101..8ea09880694ea 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -54,7 +54,7 @@ fn describe_as_module(def_id: LocalDefId, tcx: TyCtxt<'_>) -> String { } } -rustc_query_append! { [define_queries!] } +rustc_query_append! { define_queries! } impl<'tcx> Queries<'tcx> { // Force codegen in the dyn-trait transformation in this crate. diff --git a/compiler/rustc_query_impl/src/profiling_support.rs b/compiler/rustc_query_impl/src/profiling_support.rs index 3458675094713..260af0d540815 100644 --- a/compiler/rustc_query_impl/src/profiling_support.rs +++ b/compiler/rustc_query_impl/src/profiling_support.rs @@ -320,5 +320,5 @@ pub fn alloc_self_profile_query_strings(tcx: TyCtxt<'_>) { } } - rustc_query_append! { [alloc_once!] } + rustc_query_append! { alloc_once! } } From b061550ed351751db4bb3dcc356f44daa9a3542d Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 24 Aug 2022 00:22:27 -0500 Subject: [PATCH 2/2] Remove the `$tcx:tt` parameter from `rustc_query_description` It's unnecessary. --- compiler/rustc_macros/src/query.rs | 10 +++++----- compiler/rustc_query_impl/src/plumbing.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_macros/src/query.rs b/compiler/rustc_macros/src/query.rs index d80d35cb1fa32..cfbc80b97569b 100644 --- a/compiler/rustc_macros/src/query.rs +++ b/compiler/rustc_macros/src/query.rs @@ -258,13 +258,13 @@ fn add_query_description_impl(query: &Query, impls: &mut proc_macro2::TokenStrea let try_load_from_disk = if let Some((tcx, id, block)) = modifiers.load_cached.as_ref() { // Use custom code to load the query from disk quote! { - const TRY_LOAD_FROM_DISK: Option, SerializedDepNodeIndex) -> Option> + const TRY_LOAD_FROM_DISK: Option, SerializedDepNodeIndex) -> Option> = Some(|#tcx, #id| { #block }); } } else { // Use the default code to load the query from disk quote! { - const TRY_LOAD_FROM_DISK: Option, SerializedDepNodeIndex) -> Option> + const TRY_LOAD_FROM_DISK: Option, SerializedDepNodeIndex) -> Option> = Some(|tcx, id| tcx.on_disk_cache().as_ref()?.try_load_query_result(*tcx, id)); } }; @@ -291,7 +291,7 @@ fn add_query_description_impl(query: &Query, impls: &mut proc_macro2::TokenStrea false } - const TRY_LOAD_FROM_DISK: Option, SerializedDepNodeIndex) -> Option> = None; + const TRY_LOAD_FROM_DISK: Option, SerializedDepNodeIndex) -> Option> = None; } }; @@ -300,7 +300,7 @@ fn add_query_description_impl(query: &Query, impls: &mut proc_macro2::TokenStrea let desc = quote! { #[allow(unused_variables)] - fn describe(tcx: QueryCtxt<$tcx>, key: Self::Key) -> String { + fn describe(tcx: QueryCtxt<'tcx>, key: Self::Key) -> String { let (#tcx, #key) = (*tcx, key); ::rustc_middle::ty::print::with_no_trimmed_paths!( format!(#desc) @@ -309,7 +309,7 @@ fn add_query_description_impl(query: &Query, impls: &mut proc_macro2::TokenStrea }; impls.extend(quote! { - (#name<$tcx:tt>) => { + (#name) => { #desc #cache }; diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 7b4ff850df67d..462f9a42aea7e 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -322,7 +322,7 @@ macro_rules! define_queries { } impl<'tcx> QueryDescription> for queries::$name<'tcx> { - rustc_query_description! { $name<'tcx> } + rustc_query_description! { $name } type Cache = query_storage::$name<'tcx>;