Auto merge of #101173 - jyn514:simplify-macro-arguments, r=cjgillot

Further simplify the macros generated by `rustc_queries`

This doesn't actually move anything outside the macros, but it makes them simpler to read.

- Add a new `rustc_query_names` macro. This allows a much simpler syntax for the matchers in the macros passed to it as a callback.
- Convert `define_dep_nodes` and `alloc_once` to use `rustc_query_names`. This is possible because they only use the names
  (despite the quite complicated matchers in `define_dep_nodes`, none of the other arguments are used).
- Get rid of `rustc_dep_node_append`.

r? `@cjgillot`
This commit is contained in:
bors 2022-09-15 11:54:03 +00:00
commit 294f0eef73
4 changed files with 40 additions and 52 deletions

View file

@ -151,19 +151,31 @@ impl<'tcx> QueryCtxt<'tcx> {
encoder: &mut on_disk_cache::CacheEncoder<'_, 'tcx>,
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 {
($($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,
encoder,
query_result_index
);
));
)*
}
}
rustc_cached_queries!(encode_queries!);
rustc_query_append!(encode_queries!);
}
pub fn try_print_query_stack(

View file

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