mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-26 13:01:27 +03:00
Remove the _description_fns module.
`rustc_queries` generates a macro and two modules. One of the modules
looks like this:
```
mod _description_fns {
...
#[allow(unused_variables)]
pub fn hir_module_items<'tcx>(tcx: TyCtxt<'tcx>, key: LocalModDefId) -> String {
format!("getting HIR module items in `{}`", tcx.def_path_str(key))
}
...
}
```
Members of this module are then used in `TaggedQueryKey::description`.
This commit removes the `_description_fns` module entirely. For each
query we now instead generate a description closure that is used
instead. This closure is passed in the modifiers list.
This change simplifies `rustc_queries` quite a bit. It requires adding
another query modifier, but query modifiers are how other query-specific
details are already passed to the declarative macros, so it's more
consistent.
This commit is contained in:
@@ -243,7 +243,7 @@ fn make_modifiers_stream(query: &Query) -> proc_macro2::TokenStream {
|
||||
arena_cache,
|
||||
cache_on_disk,
|
||||
depth_limit,
|
||||
desc: _,
|
||||
desc,
|
||||
eval_always,
|
||||
feedable,
|
||||
no_force,
|
||||
@@ -256,7 +256,18 @@ fn make_modifiers_stream(query: &Query) -> proc_macro2::TokenStream {
|
||||
let arena_cache = arena_cache.is_some();
|
||||
let cache_on_disk = cache_on_disk.is_some();
|
||||
let depth_limit = depth_limit.is_some();
|
||||
// `desc` is not handled here
|
||||
let desc = {
|
||||
// Put a description closure in the `desc` modifier.
|
||||
let key_pat = &query.key_pat;
|
||||
let key_ty = &query.key_ty;
|
||||
let desc_expr_list = &desc.expr_list;
|
||||
quote! {
|
||||
{
|
||||
#[allow(unused_variables)]
|
||||
|tcx: TyCtxt<'tcx>, #key_pat: #key_ty| format!(#desc_expr_list)
|
||||
}
|
||||
}
|
||||
};
|
||||
let eval_always = eval_always.is_some();
|
||||
let feedable = feedable.is_some();
|
||||
let no_force = no_force.is_some();
|
||||
@@ -276,7 +287,7 @@ fn make_modifiers_stream(query: &Query) -> proc_macro2::TokenStream {
|
||||
arena_cache: #arena_cache,
|
||||
cache_on_disk: #cache_on_disk,
|
||||
depth_limit: #depth_limit,
|
||||
// `desc` is not handled here
|
||||
desc: #desc,
|
||||
eval_always: #eval_always,
|
||||
feedable: #feedable,
|
||||
no_force: #no_force,
|
||||
@@ -314,37 +325,6 @@ fn doc_comment_from_desc(list: &Punctuated<Expr, token::Comma>) -> Result<Attrib
|
||||
Ok(parse_quote! { #[doc = #doc_string] })
|
||||
}
|
||||
|
||||
/// Contains token streams that are used to accumulate per-query helper
|
||||
/// functions, to be used by the final output of `rustc_queries!`.
|
||||
///
|
||||
/// Helper items typically have the same name as the query they relate to,
|
||||
/// and expect to be interpolated into a dedicated module.
|
||||
#[derive(Default)]
|
||||
struct HelperTokenStreams {
|
||||
description_fns_stream: proc_macro2::TokenStream,
|
||||
}
|
||||
|
||||
fn make_helpers_for_query(query: &Query, streams: &mut HelperTokenStreams) {
|
||||
let Query { name, key_pat, key_ty, modifiers, .. } = &query;
|
||||
|
||||
// Replace span for `name` to make rust-analyzer ignore it.
|
||||
let mut erased_name = name.clone();
|
||||
erased_name.set_span(Span::call_site());
|
||||
|
||||
let Desc { expr_list, .. } = &modifiers.desc;
|
||||
|
||||
let desc = quote! {
|
||||
#[allow(unused_variables)]
|
||||
pub fn #erased_name<'tcx>(tcx: TyCtxt<'tcx>, #key_pat: #key_ty) -> String {
|
||||
format!(#expr_list)
|
||||
}
|
||||
};
|
||||
|
||||
streams.description_fns_stream.extend(quote! {
|
||||
#desc
|
||||
});
|
||||
}
|
||||
|
||||
/// Add hints for rust-analyzer
|
||||
fn add_to_analyzer_stream(query: &Query, analyzer_stream: &mut proc_macro2::TokenStream) {
|
||||
// Add links to relevant modifiers
|
||||
@@ -419,7 +399,6 @@ pub(super) fn rustc_queries(input: TokenStream) -> TokenStream {
|
||||
|
||||
let mut query_stream = quote! {};
|
||||
let mut non_query_stream = quote! {};
|
||||
let mut helpers = HelperTokenStreams::default();
|
||||
let mut analyzer_stream = quote! {};
|
||||
let mut errors = quote! {};
|
||||
|
||||
@@ -472,11 +451,8 @@ fn #name(#key_ty) #return_ty
|
||||
}
|
||||
|
||||
add_to_analyzer_stream(&query, &mut analyzer_stream);
|
||||
make_helpers_for_query(&query, &mut helpers);
|
||||
}
|
||||
|
||||
let HelperTokenStreams { description_fns_stream } = helpers;
|
||||
|
||||
TokenStream::from(quote! {
|
||||
/// Higher-order macro that invokes the specified macro with (a) a list of all query
|
||||
/// signatures (including modifiers), and (b) a list of non-query names. This allows
|
||||
@@ -500,17 +476,6 @@ mod _analyzer_hints {
|
||||
#analyzer_stream
|
||||
}
|
||||
|
||||
/// Functions that format a human-readable description of each query
|
||||
/// and its key, as specified by the `desc` query modifier.
|
||||
///
|
||||
/// (The leading `_` avoids collisions with actual query names when
|
||||
/// expanded in `rustc_middle::queries`, and makes this macro-generated
|
||||
/// module easier to search for.)
|
||||
pub mod _description_fns {
|
||||
use super::*;
|
||||
#description_fns_stream
|
||||
}
|
||||
|
||||
#errors
|
||||
})
|
||||
}
|
||||
|
||||
@@ -301,6 +301,7 @@ fn $name:ident($($K:tt)*) -> $V:ty
|
||||
arena_cache: $arena_cache:literal,
|
||||
cache_on_disk: $cache_on_disk:literal,
|
||||
depth_limit: $depth_limit:literal,
|
||||
desc: $desc:expr,
|
||||
eval_always: $eval_always:literal,
|
||||
feedable: $feedable:literal,
|
||||
no_force: $no_force:literal,
|
||||
@@ -435,8 +436,7 @@ pub fn query_name(&self) -> &'static str {
|
||||
pub fn description(&self, tcx: TyCtxt<'tcx>) -> String {
|
||||
let (name, description) = ty::print::with_no_queries!(match self {
|
||||
$(
|
||||
TaggedQueryKey::$name(key) =>
|
||||
(stringify!($name), _description_fns::$name(tcx, *key)),
|
||||
TaggedQueryKey::$name(key) => (stringify!($name), ($desc)(tcx, *key)),
|
||||
)*
|
||||
});
|
||||
if tcx.sess.verbose_internals() {
|
||||
|
||||
@@ -135,6 +135,7 @@ fn $name:ident($K:ty) -> $V:ty
|
||||
arena_cache: $arena_cache:literal,
|
||||
cache_on_disk: $cache_on_disk:literal,
|
||||
depth_limit: $depth_limit:literal,
|
||||
desc: $desc:expr,
|
||||
eval_always: $eval_always:literal,
|
||||
feedable: $feedable:literal,
|
||||
no_force: $no_force:literal,
|
||||
|
||||
@@ -19,6 +19,7 @@ fn $name:ident($K:ty) -> $V:ty
|
||||
arena_cache: $arena_cache:literal,
|
||||
cache_on_disk: $cache_on_disk:literal,
|
||||
depth_limit: $depth_limit:literal,
|
||||
desc: $desc:expr,
|
||||
eval_always: $eval_always:literal,
|
||||
feedable: $feedable:literal,
|
||||
no_force: $no_force:literal,
|
||||
|
||||
Reference in New Issue
Block a user