Rollup merge of #107758 - Zoxc:arena-enref, r=cjgillot

Change `arena_cache` to not alter the declared query result

This makes the return types a bit clearer, limiting `arena_cache`'s effect to just the computation side. It also makes it easier to potentially remove `arena_cache`.

r? ```@cjgillot```
This commit is contained in:
Matthias Krüger 2023-02-08 18:32:43 +01:00 committed by GitHub
commit abc2203e36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 78 additions and 70 deletions

View File

@ -54,14 +54,14 @@ rustc_queries! {
/// This is because the `hir_crate` query gives you access to all other items. /// This is because the `hir_crate` query gives you access to all other items.
/// To avoid this fate, do not call `tcx.hir().krate()`; instead, /// To avoid this fate, do not call `tcx.hir().krate()`; instead,
/// prefer wrappers like `tcx.visit_all_items_in_krate()`. /// prefer wrappers like `tcx.visit_all_items_in_krate()`.
query hir_crate(key: ()) -> Crate<'tcx> { query hir_crate(key: ()) -> &'tcx Crate<'tcx> {
arena_cache arena_cache
eval_always eval_always
desc { "getting the crate HIR" } desc { "getting the crate HIR" }
} }
/// All items in the crate. /// All items in the crate.
query hir_crate_items(_: ()) -> rustc_middle::hir::ModuleItems { query hir_crate_items(_: ()) -> &'tcx rustc_middle::hir::ModuleItems {
arena_cache arena_cache
eval_always eval_always
desc { "getting HIR crate items" } desc { "getting HIR crate items" }
@ -71,7 +71,7 @@ rustc_queries! {
/// ///
/// This can be conveniently accessed by `tcx.hir().visit_item_likes_in_module`. /// This can be conveniently accessed by `tcx.hir().visit_item_likes_in_module`.
/// Avoid calling this query directly. /// Avoid calling this query directly.
query hir_module_items(key: LocalDefId) -> rustc_middle::hir::ModuleItems { query hir_module_items(key: LocalDefId) -> &'tcx rustc_middle::hir::ModuleItems {
arena_cache arena_cache
desc { |tcx| "getting HIR module items in `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "getting HIR module items in `{}`", tcx.def_path_str(key.to_def_id()) }
cache_on_disk_if { true } cache_on_disk_if { true }
@ -183,7 +183,7 @@ rustc_queries! {
separate_provide_extern separate_provide_extern
} }
query unsizing_params_for_adt(key: DefId) -> rustc_index::bit_set::BitSet<u32> query unsizing_params_for_adt(key: DefId) -> &'tcx rustc_index::bit_set::BitSet<u32>
{ {
arena_cache arena_cache
desc { |tcx| desc { |tcx|
@ -218,7 +218,7 @@ rustc_queries! {
/// Maps from the `DefId` of an item (trait/struct/enum/fn) to its /// Maps from the `DefId` of an item (trait/struct/enum/fn) to its
/// associated generics. /// associated generics.
query generics_of(key: DefId) -> ty::Generics { query generics_of(key: DefId) -> &'tcx ty::Generics {
desc { |tcx| "computing generics of `{}`", tcx.def_path_str(key) } desc { |tcx| "computing generics of `{}`", tcx.def_path_str(key) }
arena_cache arena_cache
cache_on_disk_if { key.is_local() } cache_on_disk_if { key.is_local() }
@ -295,19 +295,19 @@ rustc_queries! {
/// These are assembled from the following places: /// These are assembled from the following places:
/// - `extern` blocks (depending on their `link` attributes) /// - `extern` blocks (depending on their `link` attributes)
/// - the `libs` (`-l`) option /// - the `libs` (`-l`) option
query native_libraries(_: CrateNum) -> Vec<NativeLib> { query native_libraries(_: CrateNum) -> &'tcx Vec<NativeLib> {
arena_cache arena_cache
desc { "looking up the native libraries of a linked crate" } desc { "looking up the native libraries of a linked crate" }
separate_provide_extern separate_provide_extern
} }
query shallow_lint_levels_on(key: hir::OwnerId) -> rustc_middle::lint::ShallowLintLevelMap { query shallow_lint_levels_on(key: hir::OwnerId) -> &'tcx rustc_middle::lint::ShallowLintLevelMap {
eval_always // fetches `resolutions` eval_always // fetches `resolutions`
arena_cache arena_cache
desc { |tcx| "looking up lint levels for `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "looking up lint levels for `{}`", tcx.def_path_str(key.to_def_id()) }
} }
query lint_expectations(_: ()) -> Vec<(LintExpectationId, LintExpectation)> { query lint_expectations(_: ()) -> &'tcx Vec<(LintExpectationId, LintExpectation)> {
arena_cache arena_cache
desc { "computing `#[expect]`ed lints in this crate" } desc { "computing `#[expect]`ed lints in this crate" }
} }
@ -347,7 +347,7 @@ rustc_queries! {
} }
/// Set of param indexes for type params that are in the type's representation /// Set of param indexes for type params that are in the type's representation
query params_in_repr(key: DefId) -> rustc_index::bit_set::BitSet<u32> { query params_in_repr(key: DefId) -> &'tcx rustc_index::bit_set::BitSet<u32> {
desc { "finding type parameters in the representation" } desc { "finding type parameters in the representation" }
arena_cache arena_cache
no_hash no_hash
@ -364,14 +364,14 @@ rustc_queries! {
} }
/// Create a THIR tree for debugging. /// Create a THIR tree for debugging.
query thir_tree(key: ty::WithOptConstParam<LocalDefId>) -> String { query thir_tree(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx String {
no_hash no_hash
arena_cache arena_cache
desc { |tcx| "constructing THIR tree for `{}`", tcx.def_path_str(key.did.to_def_id()) } desc { |tcx| "constructing THIR tree for `{}`", tcx.def_path_str(key.did.to_def_id()) }
} }
/// Create a list-like THIR representation for debugging. /// Create a list-like THIR representation for debugging.
query thir_flat(key: ty::WithOptConstParam<LocalDefId>) -> String { query thir_flat(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx String {
no_hash no_hash
arena_cache arena_cache
desc { |tcx| "constructing flat THIR representation for `{}`", tcx.def_path_str(key.did.to_def_id()) } desc { |tcx| "constructing flat THIR representation for `{}`", tcx.def_path_str(key.did.to_def_id()) }
@ -380,7 +380,7 @@ rustc_queries! {
/// Set of all the `DefId`s in this crate that have MIR associated with /// Set of all the `DefId`s in this crate that have MIR associated with
/// them. This includes all the body owners, but also things like struct /// them. This includes all the body owners, but also things like struct
/// constructors. /// constructors.
query mir_keys(_: ()) -> rustc_data_structures::fx::FxIndexSet<LocalDefId> { query mir_keys(_: ()) -> &'tcx rustc_data_structures::fx::FxIndexSet<LocalDefId> {
arena_cache arena_cache
desc { "getting a list of all mir_keys" } desc { "getting a list of all mir_keys" }
} }
@ -478,7 +478,7 @@ rustc_queries! {
query symbols_for_closure_captures( query symbols_for_closure_captures(
key: (LocalDefId, LocalDefId) key: (LocalDefId, LocalDefId)
) -> Vec<rustc_span::Symbol> { ) -> &'tcx Vec<rustc_span::Symbol> {
arena_cache arena_cache
desc { desc {
|tcx| "finding symbols for captures of closure `{}` in `{}`", |tcx| "finding symbols for captures of closure `{}` in `{}`",
@ -487,7 +487,7 @@ rustc_queries! {
} }
} }
query mir_generator_witnesses(key: DefId) -> mir::GeneratorLayout<'tcx> { query mir_generator_witnesses(key: DefId) -> &'tcx mir::GeneratorLayout<'tcx> {
arena_cache arena_cache
desc { |tcx| "generator witness types for `{}`", tcx.def_path_str(key) } desc { |tcx| "generator witness types for `{}`", tcx.def_path_str(key) }
cache_on_disk_if { key.is_local() } cache_on_disk_if { key.is_local() }
@ -508,14 +508,14 @@ rustc_queries! {
/// Returns coverage summary info for a function, after executing the `InstrumentCoverage` /// Returns coverage summary info for a function, after executing the `InstrumentCoverage`
/// MIR pass (assuming the -Cinstrument-coverage option is enabled). /// MIR pass (assuming the -Cinstrument-coverage option is enabled).
query coverageinfo(key: ty::InstanceDef<'tcx>) -> mir::CoverageInfo { query coverageinfo(key: ty::InstanceDef<'tcx>) -> &'tcx mir::CoverageInfo {
desc { |tcx| "retrieving coverage info from MIR for `{}`", tcx.def_path_str(key.def_id()) } desc { |tcx| "retrieving coverage info from MIR for `{}`", tcx.def_path_str(key.def_id()) }
arena_cache arena_cache
} }
/// Returns the `CodeRegions` for a function that has instrumented coverage, in case the /// Returns the `CodeRegions` for a function that has instrumented coverage, in case the
/// function was optimized out before codegen, and before being added to the Coverage Map. /// function was optimized out before codegen, and before being added to the Coverage Map.
query covered_code_regions(key: DefId) -> Vec<&'tcx mir::coverage::CodeRegion> { query covered_code_regions(key: DefId) -> &'tcx Vec<&'tcx mir::coverage::CodeRegion> {
desc { desc {
|tcx| "retrieving the covered `CodeRegion`s, if instrumented, for `{}`", |tcx| "retrieving the covered `CodeRegion`s, if instrumented, for `{}`",
tcx.def_path_str(key) tcx.def_path_str(key)
@ -557,7 +557,7 @@ rustc_queries! {
desc { "erasing regions from `{}`", ty } desc { "erasing regions from `{}`", ty }
} }
query wasm_import_module_map(_: CrateNum) -> FxHashMap<DefId, String> { query wasm_import_module_map(_: CrateNum) -> &'tcx FxHashMap<DefId, String> {
arena_cache arena_cache
desc { "getting wasm import module map" } desc { "getting wasm import module map" }
} }
@ -632,7 +632,7 @@ rustc_queries! {
desc { |tcx| "computing the bounds for type parameter `{}`", tcx.hir().ty_param_name(key.1) } desc { |tcx| "computing the bounds for type parameter `{}`", tcx.hir().ty_param_name(key.1) }
} }
query trait_def(key: DefId) -> ty::TraitDef { query trait_def(key: DefId) -> &'tcx ty::TraitDef {
desc { |tcx| "computing trait definition for `{}`", tcx.def_path_str(key) } desc { |tcx| "computing trait definition for `{}`", tcx.def_path_str(key) }
arena_cache arena_cache
cache_on_disk_if { key.is_local() } cache_on_disk_if { key.is_local() }
@ -703,7 +703,7 @@ rustc_queries! {
} }
/// Gets a map with the variance of every item; use `item_variance` instead. /// Gets a map with the variance of every item; use `item_variance` instead.
query crate_variances(_: ()) -> ty::CrateVariancesMap<'tcx> { query crate_variances(_: ()) -> &'tcx ty::CrateVariancesMap<'tcx> {
arena_cache arena_cache
desc { "computing the variances for items in this crate" } desc { "computing the variances for items in this crate" }
} }
@ -716,7 +716,7 @@ rustc_queries! {
} }
/// Maps from thee `DefId` of a type to its (inferred) outlives. /// Maps from thee `DefId` of a type to its (inferred) outlives.
query inferred_outlives_crate(_: ()) -> ty::CratePredicatesMap<'tcx> { query inferred_outlives_crate(_: ()) -> &'tcx ty::CratePredicatesMap<'tcx> {
arena_cache arena_cache
desc { "computing the inferred outlives predicates for items in this crate" } desc { "computing the inferred outlives predicates for items in this crate" }
} }
@ -729,7 +729,7 @@ rustc_queries! {
} }
/// Maps from a trait item to the trait item "descriptor". /// Maps from a trait item to the trait item "descriptor".
query associated_item(key: DefId) -> ty::AssocItem { query associated_item(key: DefId) -> &'tcx ty::AssocItem {
desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) } desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) }
arena_cache arena_cache
cache_on_disk_if { key.is_local() } cache_on_disk_if { key.is_local() }
@ -737,7 +737,7 @@ rustc_queries! {
} }
/// Collects the associated items defined on a trait or impl. /// Collects the associated items defined on a trait or impl.
query associated_items(key: DefId) -> ty::AssocItems<'tcx> { query associated_items(key: DefId) -> &'tcx ty::AssocItems<'tcx> {
arena_cache arena_cache
desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) } desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
} }
@ -763,7 +763,7 @@ rustc_queries! {
/// ///
/// The map returned for `tcx.impl_item_implementor_ids(impl_id)` would be /// The map returned for `tcx.impl_item_implementor_ids(impl_id)` would be
///`{ trait_f: impl_f, trait_g: impl_g }` ///`{ trait_f: impl_f, trait_g: impl_g }`
query impl_item_implementor_ids(impl_id: DefId) -> FxHashMap<DefId, DefId> { query impl_item_implementor_ids(impl_id: DefId) -> &'tcx FxHashMap<DefId, DefId> {
arena_cache arena_cache
desc { |tcx| "comparing impl items against trait for `{}`", tcx.def_path_str(impl_id) } desc { |tcx| "comparing impl items against trait for `{}`", tcx.def_path_str(impl_id) }
} }
@ -884,7 +884,7 @@ rustc_queries! {
/// ///
/// The second return value maps from ADTs to ignored derived traits (e.g. Debug and Clone) and /// The second return value maps from ADTs to ignored derived traits (e.g. Debug and Clone) and
/// their respective impl (i.e., part of the derive macro) /// their respective impl (i.e., part of the derive macro)
query live_symbols_and_ignored_derived_traits(_: ()) -> ( query live_symbols_and_ignored_derived_traits(_: ()) -> &'tcx (
FxHashSet<LocalDefId>, FxHashSet<LocalDefId>,
FxHashMap<LocalDefId, Vec<(DefId, DefId)>> FxHashMap<LocalDefId, Vec<(DefId, DefId)>>
) { ) {
@ -964,7 +964,7 @@ rustc_queries! {
/// Gets a complete map from all types to their inherent impls. /// Gets a complete map from all types to their inherent impls.
/// Not meant to be used directly outside of coherence. /// Not meant to be used directly outside of coherence.
query crate_inherent_impls(k: ()) -> CrateInherentImpls { query crate_inherent_impls(k: ()) -> &'tcx CrateInherentImpls {
arena_cache arena_cache
desc { "finding all inherent impls defined in crate" } desc { "finding all inherent impls defined in crate" }
} }
@ -1099,7 +1099,7 @@ rustc_queries! {
desc { "checking for private elements in public interfaces" } desc { "checking for private elements in public interfaces" }
} }
query reachable_set(_: ()) -> FxHashSet<LocalDefId> { query reachable_set(_: ()) -> &'tcx FxHashSet<LocalDefId> {
arena_cache arena_cache
desc { "reachability" } desc { "reachability" }
} }
@ -1111,7 +1111,7 @@ rustc_queries! {
} }
/// Generates a MIR body for the shim. /// Generates a MIR body for the shim.
query mir_shims(key: ty::InstanceDef<'tcx>) -> mir::Body<'tcx> { query mir_shims(key: ty::InstanceDef<'tcx>) -> &'tcx mir::Body<'tcx> {
arena_cache arena_cache
desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) } desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
} }
@ -1191,7 +1191,7 @@ rustc_queries! {
separate_provide_extern separate_provide_extern
} }
query codegen_fn_attrs(def_id: DefId) -> CodegenFnAttrs { query codegen_fn_attrs(def_id: DefId) -> &'tcx CodegenFnAttrs {
desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) } desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) }
arena_cache arena_cache
cache_on_disk_if { def_id.is_local() } cache_on_disk_if { def_id.is_local() }
@ -1209,7 +1209,7 @@ rustc_queries! {
} }
/// Gets the rendered value of the specified constant or associated constant. /// Gets the rendered value of the specified constant or associated constant.
/// Used by rustdoc. /// Used by rustdoc.
query rendered_const(def_id: DefId) -> String { query rendered_const(def_id: DefId) -> &'tcx String {
arena_cache arena_cache
desc { |tcx| "rendering constant initializer of `{}`", tcx.def_path_str(def_id) } desc { |tcx| "rendering constant initializer of `{}`", tcx.def_path_str(def_id) }
cache_on_disk_if { def_id.is_local() } cache_on_disk_if { def_id.is_local() }
@ -1268,12 +1268,12 @@ rustc_queries! {
} }
/// Given a trait `trait_id`, return all known `impl` blocks. /// Given a trait `trait_id`, return all known `impl` blocks.
query trait_impls_of(trait_id: DefId) -> ty::trait_def::TraitImpls { query trait_impls_of(trait_id: DefId) -> &'tcx ty::trait_def::TraitImpls {
arena_cache arena_cache
desc { |tcx| "finding trait impls of `{}`", tcx.def_path_str(trait_id) } desc { |tcx| "finding trait impls of `{}`", tcx.def_path_str(trait_id) }
} }
query specialization_graph_of(trait_id: DefId) -> specialization_graph::Graph { query specialization_graph_of(trait_id: DefId) -> &'tcx specialization_graph::Graph {
arena_cache arena_cache
desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) } desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
cache_on_disk_if { true } cache_on_disk_if { true }
@ -1403,7 +1403,7 @@ rustc_queries! {
separate_provide_extern separate_provide_extern
} }
query dependency_formats(_: ()) -> Lrc<crate::middle::dependency_format::Dependencies> { query dependency_formats(_: ()) -> &'tcx Lrc<crate::middle::dependency_format::Dependencies> {
arena_cache arena_cache
desc { "getting the linkage format of all dependencies" } desc { "getting the linkage format of all dependencies" }
} }
@ -1503,7 +1503,7 @@ rustc_queries! {
// Does not include external symbols that don't have a corresponding DefId, // Does not include external symbols that don't have a corresponding DefId,
// like the compiler-generated `main` function and so on. // like the compiler-generated `main` function and so on.
query reachable_non_generics(_: CrateNum) query reachable_non_generics(_: CrateNum)
-> DefIdMap<SymbolExportInfo> { -> &'tcx DefIdMap<SymbolExportInfo> {
arena_cache arena_cache
desc { "looking up the exported symbols of a crate" } desc { "looking up the exported symbols of a crate" }
separate_provide_extern separate_provide_extern
@ -1526,7 +1526,7 @@ rustc_queries! {
/// added or removed in any upstream crate. Instead use the narrower /// added or removed in any upstream crate. Instead use the narrower
/// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even /// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even
/// better, `Instance::upstream_monomorphization()`. /// better, `Instance::upstream_monomorphization()`.
query upstream_monomorphizations(_: ()) -> DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> { query upstream_monomorphizations(_: ()) -> &'tcx DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
arena_cache arena_cache
desc { "collecting available upstream monomorphizations" } desc { "collecting available upstream monomorphizations" }
} }
@ -1568,7 +1568,7 @@ rustc_queries! {
} }
/// Returns a list of all `extern` blocks of a crate. /// Returns a list of all `extern` blocks of a crate.
query foreign_modules(_: CrateNum) -> FxHashMap<DefId, ForeignModule> { query foreign_modules(_: CrateNum) -> &'tcx FxHashMap<DefId, ForeignModule> {
arena_cache arena_cache
desc { "looking up the foreign modules of a linked crate" } desc { "looking up the foreign modules of a linked crate" }
separate_provide_extern separate_provide_extern
@ -1602,7 +1602,7 @@ rustc_queries! {
/// Gets the extra data to put in each output filename for a crate. /// Gets the extra data to put in each output filename for a crate.
/// For example, compiling the `foo` crate with `extra-filename=-a` creates a `libfoo-b.rlib` file. /// For example, compiling the `foo` crate with `extra-filename=-a` creates a `libfoo-b.rlib` file.
query extra_filename(_: CrateNum) -> String { query extra_filename(_: CrateNum) -> &'tcx String {
arena_cache arena_cache
eval_always eval_always
desc { "looking up the extra filename for a crate" } desc { "looking up the extra filename for a crate" }
@ -1610,7 +1610,7 @@ rustc_queries! {
} }
/// Gets the paths where the crate came from in the file system. /// Gets the paths where the crate came from in the file system.
query crate_extern_paths(_: CrateNum) -> Vec<PathBuf> { query crate_extern_paths(_: CrateNum) -> &'tcx Vec<PathBuf> {
arena_cache arena_cache
eval_always eval_always
desc { "looking up the paths for extern crates" } desc { "looking up the paths for extern crates" }
@ -1641,7 +1641,7 @@ rustc_queries! {
/// Does lifetime resolution on items. Importantly, we can't resolve /// Does lifetime resolution on items. Importantly, we can't resolve
/// lifetimes directly on things like trait methods, because of trait params. /// lifetimes directly on things like trait methods, because of trait params.
/// See `rustc_resolve::late::lifetimes for details. /// See `rustc_resolve::late::lifetimes for details.
query resolve_lifetimes(_: hir::OwnerId) -> ResolveLifetimes { query resolve_lifetimes(_: hir::OwnerId) -> &'tcx ResolveLifetimes {
arena_cache arena_cache
desc { "resolving lifetimes" } desc { "resolving lifetimes" }
} }
@ -1712,7 +1712,7 @@ rustc_queries! {
desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) } desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
} }
query lib_features(_: ()) -> LibFeatures { query lib_features(_: ()) -> &'tcx LibFeatures {
arena_cache arena_cache
desc { "calculating the lib features map" } desc { "calculating the lib features map" }
} }
@ -1720,7 +1720,7 @@ rustc_queries! {
desc { "calculating the lib features defined in a crate" } desc { "calculating the lib features defined in a crate" }
separate_provide_extern separate_provide_extern
} }
query stability_implications(_: CrateNum) -> FxHashMap<Symbol, Symbol> { query stability_implications(_: CrateNum) -> &'tcx FxHashMap<Symbol, Symbol> {
arena_cache arena_cache
desc { "calculating the implications between `#[unstable]` features defined in a crate" } desc { "calculating the implications between `#[unstable]` features defined in a crate" }
separate_provide_extern separate_provide_extern
@ -1731,14 +1731,14 @@ rustc_queries! {
separate_provide_extern separate_provide_extern
} }
/// Returns the lang items defined in another crate by loading it from metadata. /// Returns the lang items defined in another crate by loading it from metadata.
query get_lang_items(_: ()) -> LanguageItems { query get_lang_items(_: ()) -> &'tcx LanguageItems {
arena_cache arena_cache
eval_always eval_always
desc { "calculating the lang items map" } desc { "calculating the lang items map" }
} }
/// Returns all diagnostic items defined in all crates. /// Returns all diagnostic items defined in all crates.
query all_diagnostic_items(_: ()) -> rustc_hir::diagnostic_items::DiagnosticItems { query all_diagnostic_items(_: ()) -> &'tcx rustc_hir::diagnostic_items::DiagnosticItems {
arena_cache arena_cache
eval_always eval_always
desc { "calculating the diagnostic items map" } desc { "calculating the diagnostic items map" }
@ -1751,7 +1751,7 @@ rustc_queries! {
} }
/// Returns the diagnostic items defined in a crate. /// Returns the diagnostic items defined in a crate.
query diagnostic_items(_: CrateNum) -> rustc_hir::diagnostic_items::DiagnosticItems { query diagnostic_items(_: CrateNum) -> &'tcx rustc_hir::diagnostic_items::DiagnosticItems {
arena_cache arena_cache
desc { "calculating the diagnostic items map in a crate" } desc { "calculating the diagnostic items map in a crate" }
separate_provide_extern separate_provide_extern
@ -1761,11 +1761,11 @@ rustc_queries! {
desc { "calculating the missing lang items in a crate" } desc { "calculating the missing lang items in a crate" }
separate_provide_extern separate_provide_extern
} }
query visible_parent_map(_: ()) -> DefIdMap<DefId> { query visible_parent_map(_: ()) -> &'tcx DefIdMap<DefId> {
arena_cache arena_cache
desc { "calculating the visible parent map" } desc { "calculating the visible parent map" }
} }
query trimmed_def_paths(_: ()) -> FxHashMap<DefId, Symbol> { query trimmed_def_paths(_: ()) -> &'tcx FxHashMap<DefId, Symbol> {
arena_cache arena_cache
desc { "calculating trimmed def paths" } desc { "calculating trimmed def paths" }
} }
@ -1774,14 +1774,14 @@ rustc_queries! {
desc { "seeing if we're missing an `extern crate` item for this crate" } desc { "seeing if we're missing an `extern crate` item for this crate" }
separate_provide_extern separate_provide_extern
} }
query used_crate_source(_: CrateNum) -> Lrc<CrateSource> { query used_crate_source(_: CrateNum) -> &'tcx Lrc<CrateSource> {
arena_cache arena_cache
eval_always eval_always
desc { "looking at the source for a crate" } desc { "looking at the source for a crate" }
separate_provide_extern separate_provide_extern
} }
/// Returns the debugger visualizers defined for this crate. /// Returns the debugger visualizers defined for this crate.
query debugger_visualizers(_: CrateNum) -> Vec<rustc_span::DebuggerVisualizerFile> { query debugger_visualizers(_: CrateNum) -> &'tcx Vec<rustc_span::DebuggerVisualizerFile> {
arena_cache arena_cache
desc { "looking up the debugger visualizers for this crate" } desc { "looking up the debugger visualizers for this crate" }
separate_provide_extern separate_provide_extern
@ -1819,7 +1819,7 @@ rustc_queries! {
desc { |tcx| "finding names imported by glob use for `{}`", tcx.def_path_str(def_id.to_def_id()) } desc { |tcx| "finding names imported by glob use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
} }
query stability_index(_: ()) -> stability::Index { query stability_index(_: ()) -> &'tcx stability::Index {
arena_cache arena_cache
eval_always eval_always
desc { "calculating the stability index for the local crate" } desc { "calculating the stability index for the local crate" }
@ -1883,7 +1883,7 @@ rustc_queries! {
/// ///
/// This query returns an `&Arc` because codegen backends need the value even after the `TyCtxt` /// This query returns an `&Arc` because codegen backends need the value even after the `TyCtxt`
/// has been destroyed. /// has been destroyed.
query output_filenames(_: ()) -> Arc<OutputFilenames> { query output_filenames(_: ()) -> &'tcx Arc<OutputFilenames> {
feedable feedable
desc { "getting output filenames" } desc { "getting output filenames" }
arena_cache arena_cache
@ -2056,7 +2056,7 @@ rustc_queries! {
remap_env_constness remap_env_constness
} }
query supported_target_features(_: CrateNum) -> FxHashMap<String, Option<Symbol>> { query supported_target_features(_: CrateNum) -> &'tcx FxHashMap<String, Option<Symbol>> {
arena_cache arena_cache
eval_always eval_always
desc { "looking up supported target features" } desc { "looking up supported target features" }
@ -2115,23 +2115,24 @@ rustc_queries! {
/// span) for an *existing* error. Therefore, it is best-effort, and may never handle /// span) for an *existing* error. Therefore, it is best-effort, and may never handle
/// all of the cases that the normal `ty::Ty`-based wfcheck does. This is fine, /// all of the cases that the normal `ty::Ty`-based wfcheck does. This is fine,
/// because the `ty::Ty`-based wfcheck is always run. /// because the `ty::Ty`-based wfcheck is always run.
query diagnostic_hir_wf_check(key: (ty::Predicate<'tcx>, traits::WellFormedLoc)) -> Option<traits::ObligationCause<'tcx>> { query diagnostic_hir_wf_check(
key: (ty::Predicate<'tcx>, traits::WellFormedLoc)
) -> &'tcx Option<traits::ObligationCause<'tcx>> {
arena_cache arena_cache
eval_always eval_always
no_hash no_hash
desc { "performing HIR wf-checking for predicate `{:?}` at item `{:?}`", key.0, key.1 } desc { "performing HIR wf-checking for predicate `{:?}` at item `{:?}`", key.0, key.1 }
} }
/// The list of backend features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`, /// The list of backend features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`,
/// `--target` and similar). /// `--target` and similar).
query global_backend_features(_: ()) -> Vec<String> { query global_backend_features(_: ()) -> &'tcx Vec<String> {
arena_cache arena_cache
eval_always eval_always
desc { "computing the backend features for CLI flags" } desc { "computing the backend features for CLI flags" }
} }
query generator_diagnostic_data(key: DefId) -> Option<GeneratorDiagnosticData<'tcx>> { query generator_diagnostic_data(key: DefId) -> &'tcx Option<GeneratorDiagnosticData<'tcx>> {
arena_cache arena_cache
desc { |tcx| "looking up generator diagnostic data of `{}`", tcx.def_path_str(key) } desc { |tcx| "looking up generator diagnostic data of `{}`", tcx.def_path_str(key) }
separate_provide_extern separate_provide_extern

View File

@ -112,15 +112,15 @@ macro_rules! query_helper_param_ty {
($K:ty) => { $K }; ($K:ty) => { $K };
} }
macro_rules! query_storage { macro_rules! query_if_arena {
([][$K:ty, $V:ty]) => { ([] $arena:ty, $no_arena:ty) => {
<<$K as Key>::CacheSelector as CacheSelector<'tcx, $V>>::Cache $no_arena
}; };
([(arena_cache) $($rest:tt)*][$K:ty, $V:ty]) => { ([(arena_cache) $($rest:tt)*] $arena:ty, $no_arena:ty) => {
<<$K as Key>::CacheSelector as CacheSelector<'tcx, $V>>::ArenaCache $arena
}; };
([$other:tt $($modifiers:tt)*][$($args:tt)*]) => { ([$other:tt $($modifiers:tt)*]$($args:tt)*) => {
query_storage!([$($modifiers)*][$($args)*]) query_if_arena!([$($modifiers)*]$($args)*)
}; };
} }
@ -184,23 +184,30 @@ macro_rules! define_callbacks {
$(pub type $name<'tcx> = $($K)*;)* $(pub type $name<'tcx> = $($K)*;)*
} }
#[allow(nonstandard_style, unused_lifetimes)] #[allow(nonstandard_style, unused_lifetimes, unused_parens)]
pub mod query_values { pub mod query_values {
use super::*; use super::*;
$(pub type $name<'tcx> = $V;)* $(pub type $name<'tcx> = query_if_arena!([$($modifiers)*] <$V as Deref>::Target, $V);)*
} }
#[allow(nonstandard_style, unused_lifetimes)] #[allow(nonstandard_style, unused_lifetimes, unused_parens)]
pub mod query_storage { pub mod query_storage {
use super::*; use super::*;
$(pub type $name<'tcx> = query_storage!([$($modifiers)*][$($K)*, $V]);)* $(
pub type $name<'tcx> = query_if_arena!([$($modifiers)*]
<<$($K)* as Key>::CacheSelector
as CacheSelector<'tcx, <$V as Deref>::Target>>::ArenaCache,
<<$($K)* as Key>::CacheSelector as CacheSelector<'tcx, $V>>::Cache
);
)*
} }
#[allow(nonstandard_style, unused_lifetimes)] #[allow(nonstandard_style, unused_lifetimes)]
pub mod query_stored { pub mod query_stored {
use super::*; use super::*;
$(pub type $name<'tcx> = <query_storage::$name<'tcx> as QueryStorage>::Stored;)* $(pub type $name<'tcx> = $V;)*
} }
#[derive(Default)] #[derive(Default)]
@ -226,7 +233,7 @@ macro_rules! define_callbacks {
$($(#[$attr])* $($(#[$attr])*
#[inline(always)] #[inline(always)]
#[must_use] #[must_use]
pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> query_stored::$name<'tcx> pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> $V
{ {
self.at(DUMMY_SP).$name(key) self.at(DUMMY_SP).$name(key)
})* })*
@ -235,7 +242,7 @@ macro_rules! define_callbacks {
impl<'tcx> TyCtxtAt<'tcx> { impl<'tcx> TyCtxtAt<'tcx> {
$($(#[$attr])* $($(#[$attr])*
#[inline(always)] #[inline(always)]
pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> query_stored::$name<'tcx> pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> $V
{ {
let key = key.into_query_param(); let key = key.into_query_param();
opt_remap_env_constness!([$($modifiers)*][key]); opt_remap_env_constness!([$($modifiers)*][key]);
@ -306,7 +313,7 @@ macro_rules! define_callbacks {
span: Span, span: Span,
key: query_keys::$name<'tcx>, key: query_keys::$name<'tcx>,
mode: QueryMode, mode: QueryMode,
) -> Option<query_stored::$name<'tcx>>;)* ) -> Option<$V>;)*
} }
}; };
} }
@ -328,7 +335,7 @@ macro_rules! define_feedable {
$(impl<'tcx, K: IntoQueryParam<$($K)*> + Copy> TyCtxtFeed<'tcx, K> { $(impl<'tcx, K: IntoQueryParam<$($K)*> + Copy> TyCtxtFeed<'tcx, K> {
$(#[$attr])* $(#[$attr])*
#[inline(always)] #[inline(always)]
pub fn $name(self, value: $V) -> query_stored::$name<'tcx> { pub fn $name(self, value: query_values::$name<'tcx>) -> $V {
let key = self.key().into_query_param(); let key = self.key().into_query_param();
opt_remap_env_constness!([$($modifiers)*][key]); opt_remap_env_constness!([$($modifiers)*][key]);