Skip to content

Commit 8ac769f

Browse files
committed
Remove rustc_feedable_queries and define_feedable macros.
`rustc_queries!` produces two macros: `rustc_with_all_queries` and `rustc_feedable_queries`. The latter is similar to the former but only includes feedable queries. But feedable queries don't need a separate mechanism because we can identify feedable queries within `define_callbacks!` by just looking for the `feedable` modifier. (That's what we do with every modifier other than `feedable`.) This commit removes the special handling and treats feedable queries like everything else. Note that this commit exposes and fixes a latent doc bug. The doc comment for query `explicit_predicates_of` links to `Self::predicates_of`. `explicit_predicates_of` is a feedable query but `predicates_of` is not, so for `TyCtxtFeed` this link is invalid. This wasn't manifesting because `TyCtxtFeed` wasn't getting doc comments attached. It now is, so I changed the link to `TyCtxt::predicates_of`.
1 parent d3e8bd9 commit 8ac769f

3 files changed

Lines changed: 36 additions & 45 deletions

File tree

compiler/rustc_macros/src/query.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,6 @@ pub(super) fn rustc_queries(input: TokenStream) -> TokenStream {
399399

400400
let mut query_stream = quote! {};
401401
let mut helpers = HelperTokenStreams::default();
402-
let mut feedable_queries = quote! {};
403402
let mut analyzer_stream = quote! {};
404403
let mut errors = quote! {};
405404

@@ -480,10 +479,6 @@ pub(super) fn rustc_queries(input: TokenStream) -> TokenStream {
480479
feedable.span(),
481480
"Query {name} cannot be both `feedable` and `eval_always`."
482481
);
483-
feedable_queries.extend(quote! {
484-
[#modifiers_stream]
485-
fn #name(#key_ty) #return_ty,
486-
});
487482
}
488483

489484
add_to_analyzer_stream(&query, &mut analyzer_stream);
@@ -514,11 +509,6 @@ pub(super) fn rustc_queries(input: TokenStream) -> TokenStream {
514509
}
515510
}
516511
}
517-
macro_rules! rustc_feedable_queries {
518-
( $macro:ident! ) => {
519-
$macro!(#feedable_queries);
520-
}
521-
}
522512

523513
// Add hints for rust-analyzer
524514
mod _analyzer_hints {

compiler/rustc_middle/src/queries.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ rustc_queries! {
825825
/// Returns the explicitly user-written *predicates* of the definition given by `DefId`
826826
/// that must be proven true at usage sites (and which can be assumed at definition site).
827827
///
828-
/// You should probably use [`Self::predicates_of`] unless you're looking for
828+
/// You should probably use [`TyCtxt::predicates_of`] unless you're looking for
829829
/// predicates with explicit spans for diagnostics purposes.
830830
query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
831831
desc { "computing explicit predicates of `{}`", tcx.def_path_str(key) }
@@ -2780,4 +2780,3 @@ rustc_queries! {
27802780
}
27812781

27822782
rustc_with_all_queries! { define_callbacks! }
2783-
rustc_feedable_queries! { define_feedable! }

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,17 @@ macro_rules! if_return_result_from_ensure_ok {
295295
};
296296
}
297297

298+
// Expands to `$item` if the `feedable` modifier is present.
299+
macro_rules! item_if_feedable {
300+
([] $($item:tt)*) => {};
301+
([(feedable) $($rest:tt)*] $($item:tt)*) => {
302+
$($item)*
303+
};
304+
([$other:tt $($modifiers:tt)*] $($item:tt)*) => {
305+
item_if_feedable! { [$($modifiers)*] $($item)* }
306+
};
307+
}
308+
298309
macro_rules! define_callbacks {
299310
(
300311
// You might expect the key to be `$K:ty`, but it needs to be `$($K:tt)*` so that
@@ -489,6 +500,30 @@ macro_rules! define_callbacks {
489500
)*
490501
}
491502

503+
$(
504+
item_if_feedable! {
505+
[$($modifiers)*]
506+
impl<'tcx, K: $crate::query::IntoQueryParam<$name::Key<'tcx>> + Copy>
507+
TyCtxtFeed<'tcx, K>
508+
{
509+
$(#[$attr])*
510+
#[inline(always)]
511+
pub fn $name(self, value: $name::ProvidedValue<'tcx>) {
512+
let key = self.key().into_query_param();
513+
let erased_value = $name::provided_to_erased(self.tcx, value);
514+
$crate::query::inner::query_feed(
515+
self.tcx,
516+
dep_graph::DepKind::$name,
517+
&self.tcx.query_system.query_vtables.$name,
518+
&self.tcx.query_system.caches.$name,
519+
key,
520+
erased_value,
521+
);
522+
}
523+
}
524+
}
525+
)*
526+
492527
/// Holds a `QueryVTable` for each query.
493528
///
494529
/// ("Per" just makes this pluralized name more visually distinct.)
@@ -578,39 +613,6 @@ macro_rules! define_callbacks {
578613
};
579614
}
580615

581-
// Note: `$V` is unused but present so this can be called by `rustc_with_all_queries`.
582-
macro_rules! define_feedable {
583-
(
584-
$(
585-
$(#[$attr:meta])*
586-
[$($modifiers:tt)*]
587-
fn $name:ident($K:ty) -> $V:ty,
588-
)*
589-
) => {
590-
$(
591-
impl<'tcx, K: $crate::query::IntoQueryParam<$K> + Copy> TyCtxtFeed<'tcx, K> {
592-
$(#[$attr])*
593-
#[inline(always)]
594-
pub fn $name(self, value: $name::ProvidedValue<'tcx>) {
595-
let key = self.key().into_query_param();
596-
597-
let tcx = self.tcx;
598-
let erased_value = $name::provided_to_erased(tcx, value);
599-
600-
$crate::query::inner::query_feed(
601-
tcx,
602-
dep_graph::DepKind::$name,
603-
&tcx.query_system.query_vtables.$name,
604-
&tcx.query_system.caches.$name,
605-
key,
606-
erased_value,
607-
);
608-
}
609-
}
610-
)*
611-
}
612-
}
613-
614616
// Each of these queries corresponds to a function pointer field in the
615617
// `Providers` struct for requesting a value of that type, and a method
616618
// on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way

0 commit comments

Comments
 (0)