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.
This commit is contained in:
Matthias Krüger
2025-04-30 10:18:29 +02:00
committed by GitHub
6 changed files with 36 additions and 13 deletions
+15 -3
View File
@@ -407,11 +407,23 @@ macro_rules! passthrough {
}
TokenStream::from(quote! {
/// Higher-order macro that invokes the specified macro with a prepared
/// list of all query signatures (including modifiers).
///
/// This allows multiple simpler macros to each have access to the list
/// of queries.
#[macro_export]
macro_rules! rustc_query_append {
($macro:ident! $( [$($other:tt)*] )?) => {
macro_rules! rustc_with_all_queries {
(
// The macro to invoke once, on all queries (plus extras).
$macro:ident!
// Within [], an optional list of extra "query" signatures to
// pass to the given macro, in addition to the actual queries.
$( [$($extra_fake_queries:tt)*] )?
) => {
$macro! {
$( $($other)* )?
$( $($extra_fake_queries)* )?
#query_stream
}
}
@@ -13,8 +13,11 @@
macro_rules! define_dep_nodes {
(
$($(#[$attr:meta])*
[$($modifiers:tt)*] fn $variant:ident($($K:tt)*) -> $V:ty,)*) => {
$(
$(#[$attr:meta])*
[$($modifiers:tt)*] fn $variant:ident($($K:tt)*) -> $V:ty,
)*
) => {
#[macro_export]
macro_rules! make_dep_kind_array {
@@ -83,7 +86,9 @@ pub mod label_strs {
};
}
rustc_query_append!(define_dep_nodes![
// Create various data structures for each query, and also for a few things
// that aren't queries.
rustc_with_all_queries!(define_dep_nodes![
/// We use this for most things when incr. comp. is turned off.
[] fn Null() -> (),
/// We use this to create a forever-red node.
+1 -1
View File
@@ -2578,5 +2578,5 @@
}
}
rustc_query_append! { define_callbacks! }
rustc_with_all_queries! { define_callbacks! }
rustc_feedable_queries! { define_feedable! }
+5 -2
View File
@@ -313,8 +313,11 @@ macro_rules! separate_provide_extern_default {
macro_rules! define_callbacks {
(
$($(#[$attr:meta])*
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => {
$(
$(#[$attr:meta])*
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,
)*
) => {
#[allow(unused_lifetimes)]
pub mod queries {
+1 -1
View File
@@ -234,7 +234,7 @@ pub fn query_system<'a>(
}
}
rustc_middle::rustc_query_append! { define_queries! }
rustc_middle::rustc_with_all_queries! { define_queries! }
pub fn provide(providers: &mut rustc_middle::util::Providers) {
providers.hooks.alloc_self_profile_query_strings = alloc_self_profile_query_strings;
+6 -3
View File
@@ -575,11 +575,14 @@ pub(crate) fn __rust_begin_short_backtrace<F, T>(f: F) -> T
}
// NOTE: `$V` isn't used here, but we still need to match on it so it can be passed to other macros
// invoked by `rustc_query_append`.
// invoked by `rustc_with_all_queries`.
macro_rules! define_queries {
(
$($(#[$attr:meta])*
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => {
$(
$(#[$attr:meta])*
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,
)*
) => {
pub(crate) mod query_impl { $(pub(crate) mod $name {
use super::super::*;