Skip to content

Commit 0c18ab7

Browse files
Rollup merge of #153009 - nnethercote:rm-define_feedable, r=oli-obk
Remove `rustc_feedable_queries` and `define_feedable` macros. The can be folded into `rustc_with_all_queries` and `define_callbacks`. Details in individual commits. r? @oli-obk
2 parents ba6430d + 8ac769f commit 0c18ab7

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
@@ -383,6 +383,17 @@ macro_rules! if_return_result_from_ensure_ok {
383383
};
384384
}
385385

386+
// Expands to `$item` if the `feedable` modifier is present.
387+
macro_rules! item_if_feedable {
388+
([] $($item:tt)*) => {};
389+
([(feedable) $($rest:tt)*] $($item:tt)*) => {
390+
$($item)*
391+
};
392+
([$other:tt $($modifiers:tt)*] $($item:tt)*) => {
393+
item_if_feedable! { [$($modifiers)*] $($item)* }
394+
};
395+
}
396+
386397
macro_rules! define_callbacks {
387398
(
388399
// You might expect the key to be `$K:ty`, but it needs to be `$($K:tt)*` so that
@@ -577,6 +588,30 @@ macro_rules! define_callbacks {
577588
)*
578589
}
579590

591+
$(
592+
item_if_feedable! {
593+
[$($modifiers)*]
594+
impl<'tcx, K: $crate::query::IntoQueryParam<$name::Key<'tcx>> + Copy>
595+
TyCtxtFeed<'tcx, K>
596+
{
597+
$(#[$attr])*
598+
#[inline(always)]
599+
pub fn $name(self, value: $name::ProvidedValue<'tcx>) {
600+
let key = self.key().into_query_param();
601+
let erased_value = $name::provided_to_erased(self.tcx, value);
602+
$crate::query::inner::query_feed(
603+
self.tcx,
604+
dep_graph::DepKind::$name,
605+
&self.tcx.query_system.query_vtables.$name,
606+
&self.tcx.query_system.caches.$name,
607+
key,
608+
erased_value,
609+
);
610+
}
611+
}
612+
}
613+
)*
614+
580615
/// Holds a `QueryVTable` for each query.
581616
///
582617
/// ("Per" just makes this pluralized name more visually distinct.)
@@ -666,39 +701,6 @@ macro_rules! define_callbacks {
666701
};
667702
}
668703

669-
// Note: `$V` is unused but present so this can be called by `rustc_with_all_queries`.
670-
macro_rules! define_feedable {
671-
(
672-
$(
673-
$(#[$attr:meta])*
674-
[$($modifiers:tt)*]
675-
fn $name:ident($K:ty) -> $V:ty,
676-
)*
677-
) => {
678-
$(
679-
impl<'tcx, K: $crate::query::IntoQueryParam<$K> + Copy> TyCtxtFeed<'tcx, K> {
680-
$(#[$attr])*
681-
#[inline(always)]
682-
pub fn $name(self, value: $name::ProvidedValue<'tcx>) {
683-
let key = self.key().into_query_param();
684-
685-
let tcx = self.tcx;
686-
let erased_value = $name::provided_to_erased(tcx, value);
687-
688-
$crate::query::inner::query_feed(
689-
tcx,
690-
dep_graph::DepKind::$name,
691-
&tcx.query_system.query_vtables.$name,
692-
&tcx.query_system.caches.$name,
693-
key,
694-
erased_value,
695-
);
696-
}
697-
}
698-
)*
699-
}
700-
}
701-
702704
// Each of these queries corresponds to a function pointer field in the
703705
// `Providers` struct for requesting a value of that type, and a method
704706
// on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way

0 commit comments

Comments
 (0)