Skip to content

Commit ae7d78a

Browse files
authored
Rollup merge of #140448 - Zalathar:query-append, r=compiler-errors
Rename `rustc_query_append!` to `rustc_with_all_queries!` Whenever I'm trying to make sense of the query system internals, I always get tripped up on this unhelpfully-named macro. The fact that it's a higher-order proc macro is already mind-melting enough on its own. This new name, `rustc_with_all_queries!`, forms a much more intuitive combination with the helper macros that it invokes. And only one of the call sites was even making use of the “append” part of its old name. This PR also reformats the parameters matched by the helper macros, to make the actual argument syntax a bit easier to see. --- Renaming and reformatting only; no functional changes.
2 parents 89ad574 + ed2f4b6 commit ae7d78a

File tree

6 files changed

+36
-13
lines changed

6 files changed

+36
-13
lines changed

compiler/rustc_macros/src/query.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,23 @@ pub(super) fn rustc_queries(input: TokenStream) -> TokenStream {
407407
}
408408

409409
TokenStream::from(quote! {
410+
/// Higher-order macro that invokes the specified macro with a prepared
411+
/// list of all query signatures (including modifiers).
412+
///
413+
/// This allows multiple simpler macros to each have access to the list
414+
/// of queries.
410415
#[macro_export]
411-
macro_rules! rustc_query_append {
412-
($macro:ident! $( [$($other:tt)*] )?) => {
416+
macro_rules! rustc_with_all_queries {
417+
(
418+
// The macro to invoke once, on all queries (plus extras).
419+
$macro:ident!
420+
421+
// Within [], an optional list of extra "query" signatures to
422+
// pass to the given macro, in addition to the actual queries.
423+
$( [$($extra_fake_queries:tt)*] )?
424+
) => {
413425
$macro! {
414-
$( $($other)* )?
426+
$( $($extra_fake_queries)* )?
415427
#query_stream
416428
}
417429
}

compiler/rustc_middle/src/dep_graph/dep_node.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ use crate::ty::TyCtxt;
1313

1414
macro_rules! define_dep_nodes {
1515
(
16-
$($(#[$attr:meta])*
17-
[$($modifiers:tt)*] fn $variant:ident($($K:tt)*) -> $V:ty,)*) => {
16+
$(
17+
$(#[$attr:meta])*
18+
[$($modifiers:tt)*] fn $variant:ident($($K:tt)*) -> $V:ty,
19+
)*
20+
) => {
1821

1922
#[macro_export]
2023
macro_rules! make_dep_kind_array {
@@ -83,7 +86,9 @@ macro_rules! define_dep_nodes {
8386
};
8487
}
8588

86-
rustc_query_append!(define_dep_nodes![
89+
// Create various data structures for each query, and also for a few things
90+
// that aren't queries.
91+
rustc_with_all_queries!(define_dep_nodes![
8792
/// We use this for most things when incr. comp. is turned off.
8893
[] fn Null() -> (),
8994
/// We use this to create a forever-red node.

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2578,5 +2578,5 @@ rustc_queries! {
25782578
}
25792579
}
25802580

2581-
rustc_query_append! { define_callbacks! }
2581+
rustc_with_all_queries! { define_callbacks! }
25822582
rustc_feedable_queries! { define_feedable! }

compiler/rustc_middle/src/query/plumbing.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,11 @@ macro_rules! separate_provide_extern_default {
313313

314314
macro_rules! define_callbacks {
315315
(
316-
$($(#[$attr:meta])*
317-
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => {
316+
$(
317+
$(#[$attr:meta])*
318+
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,
319+
)*
320+
) => {
318321

319322
#[allow(unused_lifetimes)]
320323
pub mod queries {

compiler/rustc_query_impl/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ pub fn query_system<'a>(
234234
}
235235
}
236236

237-
rustc_middle::rustc_query_append! { define_queries! }
237+
rustc_middle::rustc_with_all_queries! { define_queries! }
238238

239239
pub fn provide(providers: &mut rustc_middle::util::Providers) {
240240
providers.hooks.alloc_self_profile_query_strings = alloc_self_profile_query_strings;

compiler/rustc_query_impl/src/plumbing.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -575,11 +575,14 @@ where
575575
}
576576

577577
// NOTE: `$V` isn't used here, but we still need to match on it so it can be passed to other macros
578-
// invoked by `rustc_query_append`.
578+
// invoked by `rustc_with_all_queries`.
579579
macro_rules! define_queries {
580580
(
581-
$($(#[$attr:meta])*
582-
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => {
581+
$(
582+
$(#[$attr:meta])*
583+
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,
584+
)*
585+
) => {
583586

584587
pub(crate) mod query_impl { $(pub(crate) mod $name {
585588
use super::super::*;

0 commit comments

Comments
 (0)