Get rid of the emitted rustc_query_names and rustc_cached_queries macro

We can avoid these by adding slightly more information to `rustc_query_append` instead.
This commit is contained in:
Joshua Nelson 2022-09-06 21:26:02 -05:00
parent c630c87ceb
commit 3a4e3c7788
4 changed files with 38 additions and 40 deletions

View File

@ -328,7 +328,6 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
let mut query_stream = quote! {}; let mut query_stream = quote! {};
let mut query_description_stream = quote! {}; let mut query_description_stream = quote! {};
let mut all_names = quote! {};
let mut cached_queries = quote! {}; let mut cached_queries = quote! {};
for query in queries.0 { for query in queries.0 {
@ -384,6 +383,10 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
if let Some(remap_env_constness) = &modifiers.remap_env_constness { if let Some(remap_env_constness) = &modifiers.remap_env_constness {
attributes.push(quote! { (#remap_env_constness) }); attributes.push(quote! { (#remap_env_constness) });
} }
// Pass on the const modifier
if modifiers.cache.is_some() {
attributes.push(quote! { (cache) });
}
// This uses the span of the query definition for the commas, // This uses the span of the query definition for the commas,
// which can be important if we later encounter any ambiguity // which can be important if we later encounter any ambiguity
@ -400,38 +403,20 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
[#attribute_stream] fn #name(#arg) #result, [#attribute_stream] fn #name(#arg) #result,
}); });
all_names.extend(quote! {
#(#doc_comments)*
#name,
});
add_query_description_impl(&query, &mut query_description_stream); add_query_description_impl(&query, &mut query_description_stream);
} }
TokenStream::from(quote! { TokenStream::from(quote! {
#[macro_export] #[macro_export]
macro_rules! rustc_query_append { macro_rules! rustc_query_append {
($macro:ident!) => { ($macro:ident! $( [$($other:tt)*] )?) => {
$macro! { $macro! {
$( $($other)* )?
#query_stream #query_stream
} }
} }
} }
#[macro_export]
macro_rules! rustc_query_names {
($macro:ident! $( [$($other:tt)*] )?) => {
$macro!(
$( $($other)* )?
#all_names
);
}
}
#[macro_export]
macro_rules! rustc_cached_queries {
($macro:ident!) => {
$macro!(#cached_queries);
}
}
#[macro_export] #[macro_export]
macro_rules! rustc_query_description { macro_rules! rustc_query_description {
#query_description_stream #query_description_stream

View File

@ -144,8 +144,9 @@ impl DepKind {
macro_rules! define_dep_nodes { macro_rules! define_dep_nodes {
( (
$( $( #[$attr:meta] )* $variant:ident, )+ $($(#[$attr:meta])*
) => ( [$($modifiers:tt)*] fn $variant:ident($($K:tt)*) -> $V:ty,)*) => {
#[macro_export] #[macro_export]
macro_rules! make_dep_kind_array { macro_rules! make_dep_kind_array {
($mod:ident) => {[ $($mod::$variant()),* ]}; ($mod:ident) => {[ $($mod::$variant()),* ]};
@ -173,17 +174,17 @@ macro_rules! define_dep_nodes {
pub const $variant: &str = stringify!($variant); pub const $variant: &str = stringify!($variant);
)* )*
} }
); };
} }
rustc_query_names!(define_dep_nodes![ rustc_query_append!(define_dep_nodes![
/// We use this for most things when incr. comp. is turned off. /// We use this for most things when incr. comp. is turned off.
Null, [] fn Null() -> (),
/// We use this to create a forever-red node. /// We use this to create a forever-red node.
Red, [] fn Red() -> (),
TraitSelect, [] fn TraitSelect() -> (),
CompileCodegenUnit, [] fn CompileCodegenUnit() -> (),
CompileMonoItem, [] fn CompileMonoItem() -> (),
]); ]);
// WARNING: `construct` is generic and does not know that `CompileCodegenUnit` takes `Symbol`s as keys. // WARNING: `construct` is generic and does not know that `CompileCodegenUnit` takes `Symbol`s as keys.

View File

@ -148,19 +148,31 @@ impl<'tcx> QueryCtxt<'tcx> {
encoder: &mut on_disk_cache::CacheEncoder<'_, 'tcx>, encoder: &mut on_disk_cache::CacheEncoder<'_, 'tcx>,
query_result_index: &mut on_disk_cache::EncodedDepNodeIndex, query_result_index: &mut on_disk_cache::EncodedDepNodeIndex,
) { ) {
macro_rules! expand_if_cached {
([] $encode:expr) => {};
([(cache) $($rest:tt)*] $encode:expr) => {
$encode
};
([$other:tt $($modifiers:tt)*] $encode:expr) => {
expand_if_cached!([$($modifiers)*] $encode)
};
}
macro_rules! encode_queries { macro_rules! encode_queries {
($($query:ident,)*) => { (
$($(#[$attr:meta])*
[$($modifiers:tt)*] fn $query:ident($($K:tt)*) -> $V:ty,)*) => {
$( $(
on_disk_cache::encode_query_results::<_, super::queries::$query<'_>>( expand_if_cached!([$($modifiers)*] on_disk_cache::encode_query_results::<_, super::queries::$query<'_>>(
self, self,
encoder, encoder,
query_result_index query_result_index
); ));
)* )*
} }
} }
rustc_cached_queries!(encode_queries!); rustc_query_append!(encode_queries!);
} }
pub fn try_print_query_stack( pub fn try_print_query_stack(

View File

@ -307,18 +307,18 @@ pub fn alloc_self_profile_query_strings(tcx: TyCtxt<'_>) {
macro_rules! alloc_once { macro_rules! alloc_once {
( (
$( $( #[$attr:meta] )* $name:ident, )+ $($(#[$attr:meta])*
) => { [$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => {
$({ $(
alloc_self_profile_query_strings_for_query_cache( alloc_self_profile_query_strings_for_query_cache(
tcx, tcx,
stringify!($name), stringify!($name),
&tcx.query_caches.$name, &tcx.query_caches.$name,
&mut string_cache, &mut string_cache,
); );
})+ )+
} }
} }
rustc_query_names! { alloc_once! } rustc_query_append! { alloc_once! }
} }