Skip to content

Commit 05886e2

Browse files
committed
Further simplify the macros generated by rustc_queries
- 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`.
1 parent 699bfa8 commit 05886e2

File tree

3 files changed

+18
-32
lines changed

3 files changed

+18
-32
lines changed

compiler/rustc_macros/src/query.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
328328

329329
let mut query_stream = quote! {};
330330
let mut query_description_stream = quote! {};
331-
let mut dep_node_def_stream = quote! {};
331+
let mut all_names = quote! {};
332332
let mut cached_queries = quote! {};
333333

334334
for query in queries.0 {
@@ -344,6 +344,7 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
344344
#name,
345345
});
346346
}
347+
all_names.extend(quote! { #name, });
347348

348349
let mut attributes = Vec::new();
349350

@@ -400,35 +401,30 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
400401
[#attribute_stream] fn #name(#arg) #result,
401402
});
402403

403-
// Create a dep node for the query
404-
dep_node_def_stream.extend(quote! {
405-
[#attribute_stream] #name(#arg),
406-
});
407-
408404
add_query_description_impl(&query, &mut query_description_stream);
409405
}
410406

411407
TokenStream::from(quote! {
412408
#[macro_export]
413409
macro_rules! rustc_query_append {
414-
($macro:ident !) => {
410+
($macro:ident!) => {
415411
$macro! {
416412
#query_stream
417413
}
418414
}
419415
}
420-
macro_rules! rustc_dep_node_append {
421-
($macro:ident! [$($other:tt)*]) => {
416+
#[macro_export]
417+
macro_rules! rustc_query_names {
418+
($macro:ident! $( [$($other:tt)*] )?) => {
422419
$macro!(
423-
$($other)*
424-
425-
#dep_node_def_stream
420+
$( $($other)* )?
421+
#all_names
426422
);
427423
}
428424
}
429425
#[macro_export]
430426
macro_rules! rustc_cached_queries {
431-
( $macro:ident! ) => {
427+
($macro:ident!) => {
432428
$macro!(#cached_queries);
433429
}
434430
}

compiler/rustc_middle/src/dep_graph/dep_node.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,7 @@ impl DepKind {
144144

145145
macro_rules! define_dep_nodes {
146146
(
147-
$(
148-
[$($attrs:tt)*]
149-
$variant:ident $(( $tuple_arg_ty:ty $(,)? ))*
150-
,)*
147+
$( $variant:ident, )*
151148
) => (
152149
#[macro_export]
153150
macro_rules! make_dep_kind_array {
@@ -179,21 +176,14 @@ macro_rules! define_dep_nodes {
179176
);
180177
}
181178

182-
rustc_dep_node_append!(define_dep_nodes![
179+
rustc_query_names!(define_dep_nodes![
183180
// We use this for most things when incr. comp. is turned off.
184-
[] Null,
185-
181+
Null,
186182
// We use this to create a forever-red node.
187-
[] Red,
188-
189-
[anon] TraitSelect,
190-
191-
// WARNING: if `Symbol` is changed, make sure you update `make_compile_codegen_unit` below.
192-
[] CompileCodegenUnit(Symbol),
193-
194-
// WARNING: if `MonoItem` is changed, make sure you update `make_compile_mono_item` below.
195-
// Only used by rustc_codegen_cranelift
196-
[] CompileMonoItem(MonoItem),
183+
Red,
184+
TraitSelect,
185+
CompileCodegenUnit,
186+
CompileMonoItem,
197187
]);
198188

199189
// WARNING: `construct` is generic and does not know that `CompileCodegenUnit` takes `Symbol`s as keys.

compiler/rustc_query_impl/src/profiling_support.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ pub fn alloc_self_profile_query_strings(tcx: TyCtxt<'_>) {
307307

308308
macro_rules! alloc_once {
309309
(
310-
$($(#[$attr:meta])* [$($modifiers:tt)*] fn $name:ident($K:ty) -> $V:ty,)*
310+
$($name:ident,)*
311311
) => {
312312
$({
313313
alloc_self_profile_query_strings_for_query_cache(
@@ -320,5 +320,5 @@ pub fn alloc_self_profile_query_strings(tcx: TyCtxt<'_>) {
320320
}
321321
}
322322

323-
rustc_query_append! { alloc_once! }
323+
rustc_query_names! { alloc_once! }
324324
}

0 commit comments

Comments
 (0)