Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions compiler/rustc_macros/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ pub(super) fn rustc_queries(input: TokenStream) -> TokenStream {

let mut query_stream = quote! {};
let mut helpers = HelperTokenStreams::default();
let mut feedable_queries = quote! {};
let mut analyzer_stream = quote! {};
let mut errors = quote! {};

Expand Down Expand Up @@ -480,10 +479,6 @@ pub(super) fn rustc_queries(input: TokenStream) -> TokenStream {
feedable.span(),
"Query {name} cannot be both `feedable` and `eval_always`."
);
feedable_queries.extend(quote! {
[#modifiers_stream]
fn #name(#key_ty) #return_ty,
});
}

add_to_analyzer_stream(&query, &mut analyzer_stream);
Expand Down Expand Up @@ -514,11 +509,6 @@ pub(super) fn rustc_queries(input: TokenStream) -> TokenStream {
}
}
}
macro_rules! rustc_feedable_queries {
( $macro:ident! ) => {
$macro!(#feedable_queries);
}
}

// Add hints for rust-analyzer
mod _analyzer_hints {
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_middle/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ rustc_queries! {
/// Returns the explicitly user-written *predicates* of the definition given by `DefId`
/// that must be proven true at usage sites (and which can be assumed at definition site).
///
/// You should probably use [`Self::predicates_of`] unless you're looking for
/// You should probably use [`TyCtxt::predicates_of`] unless you're looking for
/// predicates with explicit spans for diagnostics purposes.
query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
desc { "computing explicit predicates of `{}`", tcx.def_path_str(key) }
Expand Down Expand Up @@ -2780,4 +2780,3 @@ rustc_queries! {
}

rustc_with_all_queries! { define_callbacks! }
rustc_feedable_queries! { define_feedable! }
68 changes: 35 additions & 33 deletions compiler/rustc_middle/src/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,17 @@ macro_rules! if_return_result_from_ensure_ok {
};
}

// Expands to `$item` if the `feedable` modifier is present.
macro_rules! item_if_feedable {
([] $($item:tt)*) => {};
([(feedable) $($rest:tt)*] $($item:tt)*) => {
$($item)*
};
([$other:tt $($modifiers:tt)*] $($item:tt)*) => {
item_if_feedable! { [$($modifiers)*] $($item)* }
};
}

macro_rules! define_callbacks {
(
// You might expect the key to be `$K:ty`, but it needs to be `$($K:tt)*` so that
Expand Down Expand Up @@ -489,6 +500,30 @@ macro_rules! define_callbacks {
)*
}

$(
item_if_feedable! {
[$($modifiers)*]
impl<'tcx, K: $crate::query::IntoQueryParam<$name::Key<'tcx>> + Copy>
TyCtxtFeed<'tcx, K>
{
$(#[$attr])*
#[inline(always)]
pub fn $name(self, value: $name::ProvidedValue<'tcx>) {
let key = self.key().into_query_param();
let erased_value = $name::provided_to_erased(self.tcx, value);
$crate::query::inner::query_feed(
self.tcx,
dep_graph::DepKind::$name,
&self.tcx.query_system.query_vtables.$name,
&self.tcx.query_system.caches.$name,
key,
erased_value,
);
}
}
}
)*

/// Holds a `QueryVTable` for each query.
///
/// ("Per" just makes this pluralized name more visually distinct.)
Expand Down Expand Up @@ -578,39 +613,6 @@ macro_rules! define_callbacks {
};
}

// Note: `$V` is unused but present so this can be called by `rustc_with_all_queries`.
macro_rules! define_feedable {
(
$(
$(#[$attr:meta])*
[$($modifiers:tt)*]
fn $name:ident($K:ty) -> $V:ty,
)*
) => {
$(
impl<'tcx, K: $crate::query::IntoQueryParam<$K> + Copy> TyCtxtFeed<'tcx, K> {
$(#[$attr])*
#[inline(always)]
pub fn $name(self, value: $name::ProvidedValue<'tcx>) {
let key = self.key().into_query_param();

let tcx = self.tcx;
let erased_value = $name::provided_to_erased(tcx, value);

$crate::query::inner::query_feed(
tcx,
dep_graph::DepKind::$name,
&tcx.query_system.query_vtables.$name,
&tcx.query_system.caches.$name,
key,
erased_value,
);
}
}
)*
}
}

// Each of these queries corresponds to a function pointer field in the
// `Providers` struct for requesting a value of that type, and a method
// on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way
Expand Down
Loading