diff options
| author | bors <bors@rust-lang.org> | 2022-10-15 13:30:15 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-10-15 13:30:15 +0000 |
| commit | b8c35ca26b191bb9a9ac669a4b3f4d3d52d97fb1 (patch) | |
| tree | b46adf1305800806469189e68b66e8899940a302 /compiler/rustc_query_impl | |
| parent | c93ef33700e4e4f84fd85690df71b14c1d2b0aa3 (diff) | |
| parent | 24ce4cfa205da0afc8500684465bf8158bd4adae (diff) | |
| download | rust-b8c35ca26b191bb9a9ac669a4b3f4d3d52d97fb1.tar.gz rust-b8c35ca26b191bb9a9ac669a4b3f4d3d52d97fb1.zip | |
Auto merge of #102895 - Nilstrieb:query-cleanups, r=cjgillot
Get rid of `rustc_query_description!` **I am not entirely sure whether this is an improvement and would like to get your feedback on it.** Helps with #96524. Queries can provide an arbitrary expression for their description and their caching behavior. Before, these expressions where stored in a `rustc_query_description` macro emitted by the `rustc_queries` macro, and then used in `rustc_query_impl` to fill out the methods for the `QueryDescription` trait. Instead, we now emit two new modules from `rustc_queries` containing the functions with the expressions. `rustc_query_impl` calls these functions now instead of invoking the macro. Since we are now defining some of the functions in `rustc_middle::query`, we now need all the imports for the key types mthere as well. r? `@cjgillot`
Diffstat (limited to 'compiler/rustc_query_impl')
| -rw-r--r-- | compiler/rustc_query_impl/src/lib.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_query_impl/src/plumbing.rs | 13 |
2 files changed, 9 insertions, 15 deletions
diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index 8e018d3e4a4..11d4c97e71c 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -22,8 +22,7 @@ use rustc_middle::arena::Arena; use rustc_middle::dep_graph::{self, DepKindStruct}; use rustc_middle::ty::query::{query_keys, query_storage, query_stored, query_values}; use rustc_middle::ty::query::{ExternProviders, Providers, QueryEngine}; -use rustc_middle::ty::{self, TyCtxt}; -use rustc_span::def_id::{LocalDefId, LOCAL_CRATE}; +use rustc_middle::ty::TyCtxt; use rustc_span::Span; #[macro_use] @@ -45,14 +44,6 @@ pub use on_disk_cache::OnDiskCache; mod profiling_support; pub use self::profiling_support::alloc_self_profile_query_strings; -fn describe_as_module(def_id: LocalDefId, tcx: TyCtxt<'_>) -> String { - if def_id.is_top_level_module() { - "top-level module".to_string() - } else { - format!("module `{}`", tcx.def_path_str(def_id.to_def_id())) - } -} - rustc_query_append! { define_queries! } impl<'tcx> Queries<'tcx> { diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index aaeaa3bd51d..1d17f422196 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -298,7 +298,7 @@ pub(crate) fn create_query_frame< K: Copy + Key + for<'a> HashStable<StableHashingContext<'a>>, >( tcx: QueryCtxt<'tcx>, - do_describe: fn(QueryCtxt<'tcx>, K) -> String, + do_describe: fn(TyCtxt<'tcx>, K) -> String, key: K, kind: DepKind, name: &'static str, @@ -307,7 +307,7 @@ pub(crate) fn create_query_frame< // Showing visible path instead of any path is not that important in production. let description = ty::print::with_no_visible_paths!( // Force filename-line mode to avoid invoking `type_of` query. - ty::print::with_forced_impl_filename_line!(do_describe(tcx, key)) + ty::print::with_forced_impl_filename_line!(do_describe(tcx.tcx, key)) ); let description = if tcx.sess.verbose() { format!("{} [{}]", description, name) } else { description }; @@ -466,7 +466,10 @@ macro_rules! define_queries { } impl<'tcx> QueryDescription<QueryCtxt<'tcx>> for queries::$name<'tcx> { - rustc_query_description! { $name } + #[inline] + fn cache_on_disk(tcx: TyCtxt<'tcx>, key: &Self::Key) -> bool { + ::rustc_middle::query::cached::$name(tcx, key) + } type Cache = query_storage::$name<'tcx>; @@ -576,7 +579,7 @@ macro_rules! define_queries { use rustc_middle::ty::TyCtxt; use $crate::plumbing::{QueryStruct, QueryCtxt}; use $crate::profiling_support::QueryKeyStringCache; - use rustc_query_system::query::{QueryDescription, QueryMap}; + use rustc_query_system::query::QueryMap; pub(super) const fn dummy_query_struct<'tcx>() -> QueryStruct<'tcx> { fn noop_try_collect_active_jobs(_: QueryCtxt<'_>, _: &mut QueryMap) -> Option<()> { @@ -603,7 +606,7 @@ macro_rules! define_queries { let make_query = |tcx, key| { let kind = rustc_middle::dep_graph::DepKind::$name; let name = stringify!($name); - $crate::plumbing::create_query_frame(tcx, super::queries::$name::describe, key, kind, name) + $crate::plumbing::create_query_frame(tcx, rustc_middle::query::descs::$name, key, kind, name) }; tcx.queries.$name.try_collect_active_jobs( tcx, |
