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_middle/src | |
| 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_middle/src')
| -rw-r--r-- | compiler/rustc_middle/src/query/mod.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/print/mod.rs | 11 |
2 files changed, 14 insertions, 2 deletions
diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 06eb10c9137..cfdc21ac234 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -4,6 +4,9 @@ //! ["Queries: demand-driven compilation"](https://rustc-dev-guide.rust-lang.org/query.html). //! This chapter includes instructions for adding new queries. +use crate::ty::{self, print::describe_as_module, TyCtxt}; +use rustc_span::def_id::LOCAL_CRATE; + // 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 @@ -1214,7 +1217,7 @@ rustc_queries! { desc { |tcx| "finding all vtable entries for trait {}", tcx.def_path_str(key.def_id()) } } - query vtable_trait_upcasting_coercion_new_vptr_slot(key: (ty::Ty<'tcx>, ty::Ty<'tcx>)) -> Option<usize> { + query vtable_trait_upcasting_coercion_new_vptr_slot(key: (Ty<'tcx>, Ty<'tcx>)) -> Option<usize> { desc { |tcx| "finding the slot within vtable for trait object {} vtable ptr during trait upcasting coercion from {} vtable", key.1, key.0 } } diff --git a/compiler/rustc_middle/src/ty/print/mod.rs b/compiler/rustc_middle/src/ty/print/mod.rs index e0a8d58f8a7..44b9548db89 100644 --- a/compiler/rustc_middle/src/ty/print/mod.rs +++ b/compiler/rustc_middle/src/ty/print/mod.rs @@ -3,7 +3,7 @@ use crate::ty::{self, DefIdTree, Ty, TyCtxt}; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sso::SsoHashSet; -use rustc_hir::def_id::{CrateNum, DefId}; +use rustc_hir::def_id::{CrateNum, DefId, LocalDefId}; use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData}; // `pretty` is a separate module only for organization. @@ -325,3 +325,12 @@ impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for ty::Const<'tcx> { cx.print_const(*self) } } + +// This is only used by query descriptions +pub 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())) + } +} |
