rustc_middle/query/
mod.rs

1//! Defines the various compiler queries.
2//!
3//! For more information on the query system, see
4//! ["Queries: demand-driven compilation"](https://rustc-dev-guide.rust-lang.org/query.html).
5//! This chapter includes instructions for adding new queries.
6
7#![allow(unused_parens)]
8
9use std::ffi::OsStr;
10use std::mem;
11use std::path::PathBuf;
12use std::sync::Arc;
13
14use rustc_arena::TypedArena;
15use rustc_ast::expand::StrippedCfgItem;
16use rustc_ast::expand::allocator::AllocatorKind;
17use rustc_data_structures::fingerprint::Fingerprint;
18use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
19use rustc_data_structures::sorted_map::SortedMap;
20use rustc_data_structures::steal::Steal;
21use rustc_data_structures::svh::Svh;
22use rustc_data_structures::unord::{UnordMap, UnordSet};
23use rustc_errors::ErrorGuaranteed;
24use rustc_hir::def::{DefKind, DocLinkResMap};
25use rustc_hir::def_id::{
26    CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdMap, LocalDefIdSet, LocalModDefId,
27};
28use rustc_hir::lang_items::{LangItem, LanguageItems};
29use rustc_hir::{Crate, ItemLocalId, ItemLocalMap, PreciseCapturingArgKind, TraitCandidate};
30use rustc_index::IndexVec;
31use rustc_lint_defs::LintId;
32use rustc_macros::rustc_queries;
33use rustc_query_system::ich::StableHashingContext;
34use rustc_query_system::query::{
35    QueryCache, QueryMode, QueryStackDeferred, QueryState, try_get_cached,
36};
37use rustc_session::Limits;
38use rustc_session::config::{EntryFnType, OptLevel, OutputFilenames, SymbolManglingVersion};
39use rustc_session::cstore::{
40    CrateDepKind, CrateSource, ExternCrate, ForeignModule, LinkagePreference, NativeLib,
41};
42use rustc_session::lint::LintExpectationId;
43use rustc_span::def_id::LOCAL_CRATE;
44use rustc_span::source_map::Spanned;
45use rustc_span::{DUMMY_SP, Span, Symbol};
46use rustc_target::spec::PanicStrategy;
47use {rustc_abi as abi, rustc_ast as ast, rustc_attr_data_structures as attr, rustc_hir as hir};
48
49use crate::infer::canonical::{self, Canonical};
50use crate::lint::LintExpectation;
51use crate::metadata::ModChild;
52use crate::middle::codegen_fn_attrs::CodegenFnAttrs;
53use crate::middle::debugger_visualizer::DebuggerVisualizerFile;
54use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo};
55use crate::middle::lib_features::LibFeatures;
56use crate::middle::privacy::EffectiveVisibilities;
57use crate::middle::resolve_bound_vars::{ObjectLifetimeDefault, ResolveBoundVars, ResolvedArg};
58use crate::middle::stability::{self, DeprecationEntry};
59use crate::mir::interpret::{
60    EvalStaticInitializerRawResult, EvalToAllocationRawResult, EvalToConstValueResult,
61    EvalToValTreeResult, GlobalId, LitToConstInput,
62};
63use crate::mir::mono::{CodegenUnit, CollectionMode, MonoItem, MonoItemPartitions};
64use crate::query::erase::{Erase, erase, restore};
65use crate::query::plumbing::{
66    CyclePlaceholder, DynamicQuery, query_ensure, query_ensure_error_guaranteed, query_get_at,
67};
68use crate::traits::query::{
69    CanonicalAliasGoal, CanonicalDropckOutlivesGoal, CanonicalImpliedOutlivesBoundsGoal,
70    CanonicalPredicateGoal, CanonicalTyGoal, CanonicalTypeOpAscribeUserTypeGoal,
71    CanonicalTypeOpNormalizeGoal, CanonicalTypeOpProvePredicateGoal, DropckConstraint,
72    DropckOutlivesResult, MethodAutoderefStepsResult, NoSolution, NormalizationResult,
73    OutlivesBound,
74};
75use crate::traits::{
76    CodegenObligationError, DynCompatibilityViolation, EvaluationResult, ImplSource,
77    ObligationCause, OverflowError, WellFormedLoc, specialization_graph,
78};
79use crate::ty::fast_reject::SimplifiedType;
80use crate::ty::layout::ValidityRequirement;
81use crate::ty::print::{PrintTraitRefExt, describe_as_module};
82use crate::ty::util::AlwaysRequiresDrop;
83use crate::ty::{
84    self, CrateInherentImpls, GenericArg, GenericArgsRef, PseudoCanonicalInput, Ty, TyCtxt,
85    TyCtxtFeed,
86};
87use crate::{dep_graph, mir, thir};
88
89mod arena_cached;
90pub mod erase;
91mod keys;
92pub use keys::{AsLocalKey, Key, LocalCrate};
93pub mod on_disk_cache;
94#[macro_use]
95pub mod plumbing;
96pub use plumbing::{IntoQueryParam, TyCtxtAt, TyCtxtEnsureDone, TyCtxtEnsureOk};
97
98// Each of these queries corresponds to a function pointer field in the
99// `Providers` struct for requesting a value of that type, and a method
100// on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way
101// which memoizes and does dep-graph tracking, wrapping around the actual
102// `Providers` that the driver creates (using several `rustc_*` crates).
103//
104// The result type of each query must implement `Clone`, and additionally
105// `ty::query::values::Value`, which produces an appropriate placeholder
106// (error) value if the query resulted in a query cycle.
107// Queries marked with `fatal_cycle` do not need the latter implementation,
108// as they will raise an fatal error on query cycles instead.
109rustc_queries! {
110    /// This exists purely for testing the interactions between delayed bugs and incremental.
111    query trigger_delayed_bug(key: DefId) {
112        desc { "triggering a delayed bug for testing incremental" }
113    }
114
115    /// Collects the list of all tools registered using `#![register_tool]`.
116    query registered_tools(_: ()) -> &'tcx ty::RegisteredTools {
117        arena_cache
118        desc { "compute registered tools for crate" }
119    }
120
121    query early_lint_checks(_: ()) {
122        desc { "perform lints prior to AST lowering" }
123    }
124
125    /// Tracked access to environment variables.
126    ///
127    /// Useful for the implementation of `std::env!`, `proc-macro`s change
128    /// detection and other changes in the compiler's behaviour that is easier
129    /// to control with an environment variable than a flag.
130    ///
131    /// NOTE: This currently does not work with dependency info in the
132    /// analysis, codegen and linking passes, place extra code at the top of
133    /// `rustc_interface::passes::write_dep_info` to make that work.
134    query env_var_os(key: &'tcx OsStr) -> Option<&'tcx OsStr> {
135        // Environment variables are global state
136        eval_always
137        desc { "get the value of an environment variable" }
138    }
139
140    query resolutions(_: ()) -> &'tcx ty::ResolverGlobalCtxt {
141        no_hash
142        desc { "getting the resolver outputs" }
143    }
144
145    query resolver_for_lowering_raw(_: ()) -> (&'tcx Steal<(ty::ResolverAstLowering, Arc<ast::Crate>)>, &'tcx ty::ResolverGlobalCtxt) {
146        eval_always
147        no_hash
148        desc { "getting the resolver for lowering" }
149    }
150
151    /// Return the span for a definition.
152    ///
153    /// Contrary to `def_span` below, this query returns the full absolute span of the definition.
154    /// This span is meant for dep-tracking rather than diagnostics. It should not be used outside
155    /// of rustc_middle::hir::source_map.
156    query source_span(key: LocalDefId) -> Span {
157        // Accesses untracked data
158        eval_always
159        desc { "getting the source span" }
160    }
161
162    /// Represents crate as a whole (as distinct from the top-level crate module).
163    ///
164    /// If you call `hir_crate` (e.g., indirectly by calling `tcx.hir_crate()`),
165    /// we will have to assume that any change means that you need to be recompiled.
166    /// This is because the `hir_crate` query gives you access to all other items.
167    /// To avoid this fate, do not call `tcx.hir_crate()`; instead,
168    /// prefer wrappers like [`TyCtxt::hir_visit_all_item_likes_in_crate`].
169    query hir_crate(key: ()) -> &'tcx Crate<'tcx> {
170        arena_cache
171        eval_always
172        desc { "getting the crate HIR" }
173    }
174
175    /// All items in the crate.
176    query hir_crate_items(_: ()) -> &'tcx rustc_middle::hir::ModuleItems {
177        arena_cache
178        eval_always
179        desc { "getting HIR crate items" }
180    }
181
182    /// The items in a module.
183    ///
184    /// This can be conveniently accessed by `tcx.hir_visit_item_likes_in_module`.
185    /// Avoid calling this query directly.
186    query hir_module_items(key: LocalModDefId) -> &'tcx rustc_middle::hir::ModuleItems {
187        arena_cache
188        desc { |tcx| "getting HIR module items in `{}`", tcx.def_path_str(key) }
189        cache_on_disk_if { true }
190    }
191
192    /// Returns HIR ID for the given `LocalDefId`.
193    query local_def_id_to_hir_id(key: LocalDefId) -> hir::HirId {
194        desc { |tcx| "getting HIR ID of `{}`", tcx.def_path_str(key) }
195        feedable
196    }
197
198    /// Gives access to the HIR node's parent for the HIR owner `key`.
199    ///
200    /// This can be conveniently accessed by methods on `tcx.hir()`.
201    /// Avoid calling this query directly.
202    query hir_owner_parent(key: hir::OwnerId) -> hir::HirId {
203        desc { |tcx| "getting HIR parent of `{}`", tcx.def_path_str(key) }
204    }
205
206    /// Gives access to the HIR nodes and bodies inside `key` if it's a HIR owner.
207    ///
208    /// This can be conveniently accessed by methods on `tcx.hir()`.
209    /// Avoid calling this query directly.
210    query opt_hir_owner_nodes(key: LocalDefId) -> Option<&'tcx hir::OwnerNodes<'tcx>> {
211        desc { |tcx| "getting HIR owner items in `{}`", tcx.def_path_str(key) }
212        feedable
213    }
214
215    /// Gives access to the HIR attributes inside the HIR owner `key`.
216    ///
217    /// This can be conveniently accessed by methods on `tcx.hir()`.
218    /// Avoid calling this query directly.
219    query hir_attr_map(key: hir::OwnerId) -> &'tcx hir::AttributeMap<'tcx> {
220        desc { |tcx| "getting HIR owner attributes in `{}`", tcx.def_path_str(key) }
221        feedable
222    }
223
224    /// Returns the *default* of the const pararameter given by `DefId`.
225    ///
226    /// E.g., given `struct Ty<const N: usize = 3>;` this returns `3` for `N`.
227    query const_param_default(param: DefId) -> ty::EarlyBinder<'tcx, ty::Const<'tcx>> {
228        desc { |tcx| "computing the default for const parameter `{}`", tcx.def_path_str(param)  }
229        cache_on_disk_if { param.is_local() }
230        separate_provide_extern
231    }
232
233    /// Returns the *type* of the definition given by `DefId`.
234    ///
235    /// For type aliases (whether eager or lazy) and associated types, this returns
236    /// the underlying aliased type (not the corresponding [alias type]).
237    ///
238    /// For opaque types, this returns and thus reveals the hidden type! If you
239    /// want to detect cycle errors use `type_of_opaque` instead.
240    ///
241    /// To clarify, for type definitions, this does *not* return the "type of a type"
242    /// (aka *kind* or *sort*) in the type-theoretical sense! It merely returns
243    /// the type primarily *associated with* it.
244    ///
245    /// # Panics
246    ///
247    /// This query will panic if the given definition doesn't (and can't
248    /// conceptually) have an (underlying) type.
249    ///
250    /// [alias type]: rustc_middle::ty::AliasTy
251    query type_of(key: DefId) -> ty::EarlyBinder<'tcx, Ty<'tcx>> {
252        desc { |tcx|
253            "{action} `{path}`",
254            action = match tcx.def_kind(key) {
255                DefKind::TyAlias => "expanding type alias",
256                DefKind::TraitAlias => "expanding trait alias",
257                _ => "computing type of",
258            },
259            path = tcx.def_path_str(key),
260        }
261        cache_on_disk_if { key.is_local() }
262        separate_provide_extern
263        feedable
264    }
265
266    /// Returns the *hidden type* of the opaque type given by `DefId` unless a cycle occurred.
267    ///
268    /// This is a specialized instance of [`Self::type_of`] that detects query cycles.
269    /// Unless `CyclePlaceholder` needs to be handled separately, call [`Self::type_of`] instead.
270    ///
271    /// # Panics
272    ///
273    /// This query will panic if the given definition is not an opaque type.
274    query type_of_opaque(key: DefId) -> Result<ty::EarlyBinder<'tcx, Ty<'tcx>>, CyclePlaceholder> {
275        desc { |tcx|
276            "computing type of opaque `{path}`",
277            path = tcx.def_path_str(key),
278        }
279        cycle_stash
280    }
281
282    /// Returns whether the type alias given by `DefId` is lazy.
283    ///
284    /// I.e., if the type alias expands / ought to expand to a [weak] [alias type]
285    /// instead of the underyling aliased type.
286    ///
287    /// Relevant for features `lazy_type_alias` and `type_alias_impl_trait`.
288    ///
289    /// # Panics
290    ///
291    /// This query *may* panic if the given definition is not a type alias.
292    ///
293    /// [weak]: rustc_middle::ty::Weak
294    /// [alias type]: rustc_middle::ty::AliasTy
295    query type_alias_is_lazy(key: DefId) -> bool {
296        desc { |tcx|
297            "computing whether the type alias `{path}` is lazy",
298            path = tcx.def_path_str(key),
299        }
300        separate_provide_extern
301    }
302
303    query collect_return_position_impl_trait_in_trait_tys(key: DefId)
304        -> Result<&'tcx DefIdMap<ty::EarlyBinder<'tcx, Ty<'tcx>>>, ErrorGuaranteed>
305    {
306        desc { "comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process" }
307        cache_on_disk_if { key.is_local() }
308        separate_provide_extern
309    }
310
311    query opaque_ty_origin(key: DefId) -> hir::OpaqueTyOrigin<DefId>
312    {
313        desc { "determine where the opaque originates from" }
314        separate_provide_extern
315    }
316
317    query unsizing_params_for_adt(key: DefId) -> &'tcx rustc_index::bit_set::DenseBitSet<u32>
318    {
319        arena_cache
320        desc { |tcx|
321            "determining what parameters of `{}` can participate in unsizing",
322            tcx.def_path_str(key),
323        }
324    }
325
326    /// The root query triggering all analysis passes like typeck or borrowck.
327    query analysis(key: ()) {
328        eval_always
329        desc { "running analysis passes on this crate" }
330    }
331
332    /// This query checks the fulfillment of collected lint expectations.
333    /// All lint emitting queries have to be done before this is executed
334    /// to ensure that all expectations can be fulfilled.
335    ///
336    /// This is an extra query to enable other drivers (like rustdoc) to
337    /// only execute a small subset of the `analysis` query, while allowing
338    /// lints to be expected. In rustc, this query will be executed as part of
339    /// the `analysis` query and doesn't have to be called a second time.
340    ///
341    /// Tools can additionally pass in a tool filter. That will restrict the
342    /// expectations to only trigger for lints starting with the listed tool
343    /// name. This is useful for cases were not all linting code from rustc
344    /// was called. With the default `None` all registered lints will also
345    /// be checked for expectation fulfillment.
346    query check_expectations(key: Option<Symbol>) {
347        eval_always
348        desc { "checking lint expectations (RFC 2383)" }
349    }
350
351    /// Returns the *generics* of the definition given by `DefId`.
352    query generics_of(key: DefId) -> &'tcx ty::Generics {
353        desc { |tcx| "computing generics of `{}`", tcx.def_path_str(key) }
354        arena_cache
355        cache_on_disk_if { key.is_local() }
356        separate_provide_extern
357        feedable
358    }
359
360    /// Returns the (elaborated) *predicates* of the definition given by `DefId`
361    /// that must be proven true at usage sites (and which can be assumed at definition site).
362    ///
363    /// This is almost always *the* "predicates query" that you want.
364    ///
365    /// **Tip**: You can use `#[rustc_dump_predicates]` on an item to basically print
366    /// the result of this query for use in UI tests or for debugging purposes.
367    query predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
368        desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
369        cache_on_disk_if { key.is_local() }
370        feedable
371    }
372
373    query opaque_types_defined_by(
374        key: LocalDefId
375    ) -> &'tcx ty::List<LocalDefId> {
376        desc {
377            |tcx| "computing the opaque types defined by `{}`",
378            tcx.def_path_str(key.to_def_id())
379        }
380    }
381
382    /// Returns the explicitly user-written *bounds* on the associated or opaque type given by `DefId`
383    /// that must be proven true at definition site (and which can be assumed at usage sites).
384    ///
385    /// For associated types, these must be satisfied for an implementation
386    /// to be well-formed, and for opaque types, these are required to be
387    /// satisfied by the hidden type of the opaque.
388    ///
389    /// Bounds from the parent (e.g. with nested `impl Trait`) are not included.
390    ///
391    /// Syntactially, these are the bounds written on associated types in trait
392    /// definitions, or those after the `impl` keyword for an opaque:
393    ///
394    /// ```ignore (illustrative)
395    /// trait Trait { type X: Bound + 'lt; }
396    /// //                    ^^^^^^^^^^^
397    /// fn function() -> impl Debug + Display { /*...*/ }
398    /// //                    ^^^^^^^^^^^^^^^
399    /// ```
400    query explicit_item_bounds(key: DefId) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
401        desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) }
402        cache_on_disk_if { key.is_local() }
403        separate_provide_extern
404        feedable
405    }
406
407    /// Returns the explicitly user-written *bounds* that share the `Self` type of the item.
408    ///
409    /// These are a subset of the [explicit item bounds] that may explicitly be used for things
410    /// like closure signature deduction.
411    ///
412    /// [explicit item bounds]: Self::explicit_item_bounds
413    query explicit_item_self_bounds(key: DefId) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
414        desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) }
415        cache_on_disk_if { key.is_local() }
416        separate_provide_extern
417        feedable
418    }
419
420    /// Returns the (elaborated) *bounds* on the associated or opaque type given by `DefId`
421    /// that must be proven true at definition site (and which can be assumed at usage sites).
422    ///
423    /// Bounds from the parent (e.g. with nested `impl Trait`) are not included.
424    ///
425    /// **Tip**: You can use `#[rustc_dump_item_bounds]` on an item to basically print
426    /// the result of this query for use in UI tests or for debugging purposes.
427    ///
428    /// # Examples
429    ///
430    /// ```
431    /// trait Trait { type Assoc: Eq + ?Sized; }
432    /// ```
433    ///
434    /// While [`Self::explicit_item_bounds`] returns `[<Self as Trait>::Assoc: Eq]`
435    /// here, `item_bounds` returns:
436    ///
437    /// ```text
438    /// [
439    ///     <Self as Trait>::Assoc: Eq,
440    ///     <Self as Trait>::Assoc: PartialEq<<Self as Trait>::Assoc>
441    /// ]
442    /// ```
443    query item_bounds(key: DefId) -> ty::EarlyBinder<'tcx, ty::Clauses<'tcx>> {
444        desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) }
445    }
446
447    query item_self_bounds(key: DefId) -> ty::EarlyBinder<'tcx, ty::Clauses<'tcx>> {
448        desc { |tcx| "elaborating item assumptions for `{}`", tcx.def_path_str(key) }
449    }
450
451    query item_non_self_bounds(key: DefId) -> ty::EarlyBinder<'tcx, ty::Clauses<'tcx>> {
452        desc { |tcx| "elaborating item assumptions for `{}`", tcx.def_path_str(key) }
453    }
454
455    query impl_super_outlives(key: DefId) -> ty::EarlyBinder<'tcx, ty::Clauses<'tcx>> {
456        desc { |tcx| "elaborating supertrait outlives for trait of `{}`", tcx.def_path_str(key) }
457    }
458
459    /// Look up all native libraries this crate depends on.
460    /// These are assembled from the following places:
461    /// - `extern` blocks (depending on their `link` attributes)
462    /// - the `libs` (`-l`) option
463    query native_libraries(_: CrateNum) -> &'tcx Vec<NativeLib> {
464        arena_cache
465        desc { "looking up the native libraries of a linked crate" }
466        separate_provide_extern
467    }
468
469    query shallow_lint_levels_on(key: hir::OwnerId) -> &'tcx rustc_middle::lint::ShallowLintLevelMap {
470        arena_cache
471        desc { |tcx| "looking up lint levels for `{}`", tcx.def_path_str(key) }
472    }
473
474    query lint_expectations(_: ()) -> &'tcx Vec<(LintExpectationId, LintExpectation)> {
475        arena_cache
476        desc { "computing `#[expect]`ed lints in this crate" }
477    }
478
479    query lints_that_dont_need_to_run(_: ()) -> &'tcx FxIndexSet<LintId> {
480        arena_cache
481        desc { "Computing all lints that are explicitly enabled or with a default level greater than Allow" }
482    }
483
484    query expn_that_defined(key: DefId) -> rustc_span::ExpnId {
485        desc { |tcx| "getting the expansion that defined `{}`", tcx.def_path_str(key) }
486        separate_provide_extern
487    }
488
489    query is_panic_runtime(_: CrateNum) -> bool {
490        fatal_cycle
491        desc { "checking if the crate is_panic_runtime" }
492        separate_provide_extern
493    }
494
495    /// Checks whether a type is representable or infinitely sized
496    query representability(_: LocalDefId) -> rustc_middle::ty::Representability {
497        desc { "checking if `{}` is representable", tcx.def_path_str(key) }
498        // infinitely sized types will cause a cycle
499        cycle_delay_bug
500        // we don't want recursive representability calls to be forced with
501        // incremental compilation because, if a cycle occurs, we need the
502        // entire cycle to be in memory for diagnostics
503        anon
504    }
505
506    /// An implementation detail for the `representability` query
507    query representability_adt_ty(_: Ty<'tcx>) -> rustc_middle::ty::Representability {
508        desc { "checking if `{}` is representable", key }
509        cycle_delay_bug
510        anon
511    }
512
513    /// Set of param indexes for type params that are in the type's representation
514    query params_in_repr(key: DefId) -> &'tcx rustc_index::bit_set::DenseBitSet<u32> {
515        desc { "finding type parameters in the representation" }
516        arena_cache
517        no_hash
518        separate_provide_extern
519    }
520
521    /// Fetch the THIR for a given body.
522    query thir_body(key: LocalDefId) -> Result<(&'tcx Steal<thir::Thir<'tcx>>, thir::ExprId), ErrorGuaranteed> {
523        // Perf tests revealed that hashing THIR is inefficient (see #85729).
524        no_hash
525        desc { |tcx| "building THIR for `{}`", tcx.def_path_str(key) }
526    }
527
528    /// Set of all the `DefId`s in this crate that have MIR associated with
529    /// them. This includes all the body owners, but also things like struct
530    /// constructors.
531    query mir_keys(_: ()) -> &'tcx rustc_data_structures::fx::FxIndexSet<LocalDefId> {
532        arena_cache
533        desc { "getting a list of all mir_keys" }
534    }
535
536    /// Maps DefId's that have an associated `mir::Body` to the result
537    /// of the MIR const-checking pass. This is the set of qualifs in
538    /// the final value of a `const`.
539    query mir_const_qualif(key: DefId) -> mir::ConstQualifs {
540        desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
541        cache_on_disk_if { key.is_local() }
542        separate_provide_extern
543    }
544
545    /// Build the MIR for a given `DefId` and prepare it for const qualification.
546    ///
547    /// See the [rustc dev guide] for more info.
548    ///
549    /// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/mir/construction.html
550    query mir_built(key: LocalDefId) -> &'tcx Steal<mir::Body<'tcx>> {
551        desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key) }
552        feedable
553    }
554
555    /// Try to build an abstract representation of the given constant.
556    query thir_abstract_const(
557        key: DefId
558    ) -> Result<Option<ty::EarlyBinder<'tcx, ty::Const<'tcx>>>, ErrorGuaranteed> {
559        desc {
560            |tcx| "building an abstract representation for `{}`", tcx.def_path_str(key),
561        }
562        separate_provide_extern
563    }
564
565    query mir_drops_elaborated_and_const_checked(key: LocalDefId) -> &'tcx Steal<mir::Body<'tcx>> {
566        no_hash
567        desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key) }
568    }
569
570    query mir_for_ctfe(
571        key: DefId
572    ) -> &'tcx mir::Body<'tcx> {
573        desc { |tcx| "caching mir of `{}` for CTFE", tcx.def_path_str(key) }
574        cache_on_disk_if { key.is_local() }
575        separate_provide_extern
576    }
577
578    query mir_promoted(key: LocalDefId) -> (
579        &'tcx Steal<mir::Body<'tcx>>,
580        &'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
581    ) {
582        no_hash
583        desc { |tcx| "promoting constants in MIR for `{}`", tcx.def_path_str(key) }
584    }
585
586    query closure_typeinfo(key: LocalDefId) -> ty::ClosureTypeInfo<'tcx> {
587        desc {
588            |tcx| "finding symbols for captures of closure `{}`",
589            tcx.def_path_str(key)
590        }
591    }
592
593    /// Returns names of captured upvars for closures and coroutines.
594    ///
595    /// Here are some examples:
596    ///  - `name__field1__field2` when the upvar is captured by value.
597    ///  - `_ref__name__field` when the upvar is captured by reference.
598    ///
599    /// For coroutines this only contains upvars that are shared by all states.
600    query closure_saved_names_of_captured_variables(def_id: DefId) -> &'tcx IndexVec<abi::FieldIdx, Symbol> {
601        arena_cache
602        desc { |tcx| "computing debuginfo for closure `{}`", tcx.def_path_str(def_id) }
603        separate_provide_extern
604    }
605
606    query mir_coroutine_witnesses(key: DefId) -> Option<&'tcx mir::CoroutineLayout<'tcx>> {
607        arena_cache
608        desc { |tcx| "coroutine witness types for `{}`", tcx.def_path_str(key) }
609        cache_on_disk_if { key.is_local() }
610        separate_provide_extern
611    }
612
613    query check_coroutine_obligations(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
614        desc { |tcx| "verify auto trait bounds for coroutine interior type `{}`", tcx.def_path_str(key) }
615    }
616
617    /// MIR after our optimization passes have run. This is MIR that is ready
618    /// for codegen. This is also the only query that can fetch non-local MIR, at present.
619    query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> {
620        desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key) }
621        cache_on_disk_if { key.is_local() }
622        separate_provide_extern
623    }
624
625    /// Checks for the nearest `#[coverage(off)]` or `#[coverage(on)]` on
626    /// this def and any enclosing defs, up to the crate root.
627    ///
628    /// Returns `false` if `#[coverage(off)]` was found, or `true` if
629    /// either `#[coverage(on)]` or no coverage attribute was found.
630    query coverage_attr_on(key: LocalDefId) -> bool {
631        desc { |tcx| "checking for `#[coverage(..)]` on `{}`", tcx.def_path_str(key) }
632        feedable
633    }
634
635    /// Scans through a function's MIR after MIR optimizations, to prepare the
636    /// information needed by codegen when `-Cinstrument-coverage` is active.
637    ///
638    /// This includes the details of where to insert `llvm.instrprof.increment`
639    /// intrinsics, and the expression tables to be embedded in the function's
640    /// coverage metadata.
641    ///
642    /// FIXME(Zalathar): This query's purpose has drifted a bit and should
643    /// probably be renamed, but that can wait until after the potential
644    /// follow-ups to #136053 have settled down.
645    ///
646    /// Returns `None` for functions that were not instrumented.
647    query coverage_ids_info(key: ty::InstanceKind<'tcx>) -> Option<&'tcx mir::coverage::CoverageIdsInfo> {
648        desc { |tcx| "retrieving coverage IDs info from MIR for `{}`", tcx.def_path_str(key.def_id()) }
649        arena_cache
650    }
651
652    /// The `DefId` is the `DefId` of the containing MIR body. Promoteds do not have their own
653    /// `DefId`. This function returns all promoteds in the specified body. The body references
654    /// promoteds by the `DefId` and the `mir::Promoted` index. This is necessary, because
655    /// after inlining a body may refer to promoteds from other bodies. In that case you still
656    /// need to use the `DefId` of the original body.
657    query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
658        desc { |tcx| "optimizing promoted MIR for `{}`", tcx.def_path_str(key) }
659        cache_on_disk_if { key.is_local() }
660        separate_provide_extern
661    }
662
663    /// Erases regions from `ty` to yield a new type.
664    /// Normally you would just use `tcx.erase_regions(value)`,
665    /// however, which uses this query as a kind of cache.
666    query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
667        // This query is not expected to have input -- as a result, it
668        // is not a good candidates for "replay" because it is essentially a
669        // pure function of its input (and hence the expectation is that
670        // no caller would be green **apart** from just these
671        // queries). Making it anonymous avoids hashing the result, which
672        // may save a bit of time.
673        anon
674        desc { "erasing regions from `{}`", ty }
675    }
676
677    query wasm_import_module_map(_: CrateNum) -> &'tcx DefIdMap<String> {
678        arena_cache
679        desc { "getting wasm import module map" }
680    }
681
682    /// Returns the explicitly user-written *predicates and bounds* of the trait given by `DefId`.
683    ///
684    /// Traits are unusual, because predicates on associated types are
685    /// converted into bounds on that type for backwards compatibility:
686    ///
687    /// ```
688    /// trait X where Self::U: Copy { type U; }
689    /// ```
690    ///
691    /// becomes
692    ///
693    /// ```
694    /// trait X { type U: Copy; }
695    /// ```
696    ///
697    /// [`Self::explicit_predicates_of`] and [`Self::explicit_item_bounds`] will
698    /// then take the appropriate subsets of the predicates here.
699    ///
700    /// # Panics
701    ///
702    /// This query will panic if the given definition is not a trait.
703    query trait_explicit_predicates_and_bounds(key: LocalDefId) -> ty::GenericPredicates<'tcx> {
704        desc { |tcx| "computing explicit predicates of trait `{}`", tcx.def_path_str(key) }
705    }
706
707    /// Returns the explicitly user-written *predicates* of the definition given by `DefId`
708    /// that must be proven true at usage sites (and which can be assumed at definition site).
709    ///
710    /// You should probably use [`Self::predicates_of`] unless you're looking for
711    /// predicates with explicit spans for diagnostics purposes.
712    query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
713        desc { |tcx| "computing explicit predicates of `{}`", tcx.def_path_str(key) }
714        cache_on_disk_if { key.is_local() }
715        separate_provide_extern
716        feedable
717    }
718
719    /// Returns the *inferred outlives-predicates* of the item given by `DefId`.
720    ///
721    /// E.g., for `struct Foo<'a, T> { x: &'a T }`, this would return `[T: 'a]`.
722    ///
723    /// **Tip**: You can use `#[rustc_outlives]` on an item to basically print the
724    /// result of this query for use in UI tests or for debugging purposes.
725    query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Clause<'tcx>, Span)] {
726        desc { |tcx| "computing inferred outlives-predicates of `{}`", tcx.def_path_str(key) }
727        cache_on_disk_if { key.is_local() }
728        separate_provide_extern
729        feedable
730    }
731
732    /// Returns the explicitly user-written *super-predicates* of the trait given by `DefId`.
733    ///
734    /// These predicates are unelaborated and consequently don't contain transitive super-predicates.
735    ///
736    /// This is a subset of the full list of predicates. We store these in a separate map
737    /// because we must evaluate them even during type conversion, often before the full
738    /// predicates are available (note that super-predicates must not be cyclic).
739    query explicit_super_predicates_of(key: DefId) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
740        desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) }
741        cache_on_disk_if { key.is_local() }
742        separate_provide_extern
743    }
744
745    /// The predicates of the trait that are implied during elaboration.
746    ///
747    /// This is a superset of the super-predicates of the trait, but a subset of the predicates
748    /// of the trait. For regular traits, this includes all super-predicates and their
749    /// associated type bounds. For trait aliases, currently, this includes all of the
750    /// predicates of the trait alias.
751    query explicit_implied_predicates_of(key: DefId) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
752        desc { |tcx| "computing the implied predicates of `{}`", tcx.def_path_str(key) }
753        cache_on_disk_if { key.is_local() }
754        separate_provide_extern
755    }
756
757    /// The Ident is the name of an associated type.The query returns only the subset
758    /// of supertraits that define the given associated type. This is used to avoid
759    /// cycles in resolving type-dependent associated item paths like `T::Item`.
760    query explicit_supertraits_containing_assoc_item(
761        key: (DefId, rustc_span::Ident)
762    ) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
763        desc { |tcx| "computing the super traits of `{}` with associated type name `{}`",
764            tcx.def_path_str(key.0),
765            key.1
766        }
767    }
768
769    /// Compute the conditions that need to hold for a conditionally-const item to be const.
770    /// That is, compute the set of `~const` where clauses for a given item.
771    ///
772    /// This can be thought of as the `~const` equivalent of `predicates_of`. These are the
773    /// predicates that need to be proven at usage sites, and can be assumed at definition.
774    ///
775    /// This query also computes the `~const` where clauses for associated types, which are
776    /// not "const", but which have item bounds which may be `~const`. These must hold for
777    /// the `~const` item bound to hold.
778    query const_conditions(
779        key: DefId
780    ) -> ty::ConstConditions<'tcx> {
781        desc { |tcx| "computing the conditions for `{}` to be considered const",
782            tcx.def_path_str(key)
783        }
784        separate_provide_extern
785    }
786
787    /// Compute the const bounds that are implied for a conditionally-const item.
788    ///
789    /// This can be though of as the `~const` equivalent of `explicit_item_bounds`. These
790    /// are the predicates that need to proven at definition sites, and can be assumed at
791    /// usage sites.
792    query explicit_implied_const_bounds(
793        key: DefId
794    ) -> ty::EarlyBinder<'tcx, &'tcx [(ty::PolyTraitRef<'tcx>, Span)]> {
795        desc { |tcx| "computing the implied `~const` bounds for `{}`",
796            tcx.def_path_str(key)
797        }
798        separate_provide_extern
799    }
800
801    /// To avoid cycles within the predicates of a single item we compute
802    /// per-type-parameter predicates for resolving `T::AssocTy`.
803    query type_param_predicates(
804        key: (LocalDefId, LocalDefId, rustc_span::Ident)
805    ) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
806        desc { |tcx| "computing the bounds for type parameter `{}`", tcx.hir_ty_param_name(key.1) }
807    }
808
809    query trait_def(key: DefId) -> &'tcx ty::TraitDef {
810        desc { |tcx| "computing trait definition for `{}`", tcx.def_path_str(key) }
811        arena_cache
812        cache_on_disk_if { key.is_local() }
813        separate_provide_extern
814    }
815    query adt_def(key: DefId) -> ty::AdtDef<'tcx> {
816        desc { |tcx| "computing ADT definition for `{}`", tcx.def_path_str(key) }
817        cache_on_disk_if { key.is_local() }
818        separate_provide_extern
819    }
820    query adt_destructor(key: DefId) -> Option<ty::Destructor> {
821        desc { |tcx| "computing `Drop` impl for `{}`", tcx.def_path_str(key) }
822        cache_on_disk_if { key.is_local() }
823        separate_provide_extern
824    }
825    query adt_async_destructor(key: DefId) -> Option<ty::AsyncDestructor> {
826        desc { |tcx| "computing `AsyncDrop` impl for `{}`", tcx.def_path_str(key) }
827        cache_on_disk_if { key.is_local() }
828        separate_provide_extern
829    }
830
831    query adt_sized_constraint(key: DefId) -> Option<ty::EarlyBinder<'tcx, Ty<'tcx>>> {
832        desc { |tcx| "computing the `Sized` constraint for `{}`", tcx.def_path_str(key) }
833    }
834
835    query adt_dtorck_constraint(
836        key: DefId
837    ) -> &'tcx DropckConstraint<'tcx> {
838        desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) }
839    }
840
841    /// Returns the constness of the function-like[^1] definition given by `DefId`.
842    ///
843    /// Tuple struct/variant constructors are *always* const, foreign functions are
844    /// *never* const. The rest is const iff marked with keyword `const` (or rather
845    /// its parent in the case of associated functions).
846    ///
847    /// <div class="warning">
848    ///
849    /// **Do not call this query** directly. It is only meant to cache the base data for the
850    /// higher-level functions. Consider using `is_const_fn` or `is_const_trait_impl` instead.
851    ///
852    /// Also note that neither of them takes into account feature gates, stability and
853    /// const predicates/conditions!
854    ///
855    /// </div>
856    ///
857    /// # Panics
858    ///
859    /// This query will panic if the given definition is not function-like[^1].
860    ///
861    /// [^1]: Tuple struct/variant constructors, closures and free, associated and foreign functions.
862    query constness(key: DefId) -> hir::Constness {
863        desc { |tcx| "checking if item is const: `{}`", tcx.def_path_str(key) }
864        separate_provide_extern
865        feedable
866    }
867
868    query asyncness(key: DefId) -> ty::Asyncness {
869        desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
870        separate_provide_extern
871    }
872
873    /// Returns `true` if calls to the function may be promoted.
874    ///
875    /// This is either because the function is e.g., a tuple-struct or tuple-variant
876    /// constructor, or because it has the `#[rustc_promotable]` attribute. The attribute should
877    /// be removed in the future in favour of some form of check which figures out whether the
878    /// function does not inspect the bits of any of its arguments (so is essentially just a
879    /// constructor function).
880    query is_promotable_const_fn(key: DefId) -> bool {
881        desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
882    }
883
884    /// The body of the coroutine, modified to take its upvars by move rather than by ref.
885    ///
886    /// This is used by coroutine-closures, which must return a different flavor of coroutine
887    /// when called using `AsyncFnOnce::call_once`. It is produced by the `ByMoveBody` pass which
888    /// is run right after building the initial MIR, and will only be populated for coroutines
889    /// which come out of the async closure desugaring.
890    query coroutine_by_move_body_def_id(def_id: DefId) -> DefId {
891        desc { |tcx| "looking up the coroutine by-move body for `{}`", tcx.def_path_str(def_id) }
892        separate_provide_extern
893    }
894
895    /// Returns `Some(coroutine_kind)` if the node pointed to by `def_id` is a coroutine.
896    query coroutine_kind(def_id: DefId) -> Option<hir::CoroutineKind> {
897        desc { |tcx| "looking up coroutine kind of `{}`", tcx.def_path_str(def_id) }
898        separate_provide_extern
899        feedable
900    }
901
902    query coroutine_for_closure(def_id: DefId) -> DefId {
903        desc { |_tcx| "Given a coroutine-closure def id, return the def id of the coroutine returned by it" }
904        separate_provide_extern
905    }
906
907    /// Gets a map with the variances of every item in the local crate.
908    ///
909    /// <div class="warning">
910    ///
911    /// **Do not call this query** directly, use [`Self::variances_of`] instead.
912    ///
913    /// </div>
914    query crate_variances(_: ()) -> &'tcx ty::CrateVariancesMap<'tcx> {
915        arena_cache
916        desc { "computing the variances for items in this crate" }
917    }
918
919    /// Returns the (inferred) variances of the item given by `DefId`.
920    ///
921    /// The list of variances corresponds to the list of (early-bound) generic
922    /// parameters of the item (including its parents).
923    ///
924    /// **Tip**: You can use `#[rustc_variance]` on an item to basically print the
925    /// result of this query for use in UI tests or for debugging purposes.
926    query variances_of(def_id: DefId) -> &'tcx [ty::Variance] {
927        desc { |tcx| "computing the variances of `{}`", tcx.def_path_str(def_id) }
928        cache_on_disk_if { def_id.is_local() }
929        separate_provide_extern
930        cycle_delay_bug
931    }
932
933    /// Gets a map with the inferred outlives-predicates of every item in the local crate.
934    ///
935    /// <div class="warning">
936    ///
937    /// **Do not call this query** directly, use [`Self::inferred_outlives_of`] instead.
938    ///
939    /// </div>
940    query inferred_outlives_crate(_: ()) -> &'tcx ty::CratePredicatesMap<'tcx> {
941        arena_cache
942        desc { "computing the inferred outlives-predicates for items in this crate" }
943    }
944
945    /// Maps from an impl/trait or struct/variant `DefId`
946    /// to a list of the `DefId`s of its associated items or fields.
947    query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
948        desc { |tcx| "collecting associated items or fields of `{}`", tcx.def_path_str(key) }
949        cache_on_disk_if { key.is_local() }
950        separate_provide_extern
951    }
952
953    /// Maps from a trait/impl item to the trait/impl item "descriptor".
954    query associated_item(key: DefId) -> ty::AssocItem {
955        desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) }
956        cache_on_disk_if { key.is_local() }
957        separate_provide_extern
958        feedable
959    }
960
961    /// Collects the associated items defined on a trait or impl.
962    query associated_items(key: DefId) -> &'tcx ty::AssocItems {
963        arena_cache
964        desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
965    }
966
967    /// Maps from associated items on a trait to the corresponding associated
968    /// item on the impl specified by `impl_id`.
969    ///
970    /// For example, with the following code
971    ///
972    /// ```
973    /// struct Type {}
974    ///                         // DefId
975    /// trait Trait {           // trait_id
976    ///     fn f();             // trait_f
977    ///     fn g() {}           // trait_g
978    /// }
979    ///
980    /// impl Trait for Type {   // impl_id
981    ///     fn f() {}           // impl_f
982    ///     fn g() {}           // impl_g
983    /// }
984    /// ```
985    ///
986    /// The map returned for `tcx.impl_item_implementor_ids(impl_id)` would be
987    ///`{ trait_f: impl_f, trait_g: impl_g }`
988    query impl_item_implementor_ids(impl_id: DefId) -> &'tcx DefIdMap<DefId> {
989        arena_cache
990        desc { |tcx| "comparing impl items against trait for `{}`", tcx.def_path_str(impl_id) }
991    }
992
993    /// Given `fn_def_id` of a trait or of an impl that implements a given trait:
994    /// if `fn_def_id` is the def id of a function defined inside a trait, then it creates and returns
995    /// the associated items that correspond to each impl trait in return position for that trait.
996    /// if `fn_def_id` is the def id of a function defined inside an impl that implements a trait, then it
997    /// creates and returns the associated items that correspond to each impl trait in return position
998    /// of the implemented trait.
999    query associated_types_for_impl_traits_in_associated_fn(fn_def_id: DefId) -> &'tcx [DefId] {
1000        desc { |tcx| "creating associated items for opaque types returned by `{}`", tcx.def_path_str(fn_def_id) }
1001        cache_on_disk_if { fn_def_id.is_local() }
1002        separate_provide_extern
1003    }
1004
1005    /// Given an impl trait in trait `opaque_ty_def_id`, create and return the corresponding
1006    /// associated item.
1007    query associated_type_for_impl_trait_in_trait(opaque_ty_def_id: LocalDefId) -> LocalDefId {
1008        desc { |tcx| "creating the associated item corresponding to the opaque type `{}`", tcx.def_path_str(opaque_ty_def_id.to_def_id()) }
1009        cache_on_disk_if { true }
1010    }
1011
1012    /// Given an `impl_id`, return the trait it implements along with some header information.
1013    /// Return `None` if this is an inherent impl.
1014    query impl_trait_header(impl_id: DefId) -> Option<ty::ImplTraitHeader<'tcx>> {
1015        desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
1016        cache_on_disk_if { impl_id.is_local() }
1017        separate_provide_extern
1018    }
1019
1020    /// Maps a `DefId` of a type to a list of its inherent impls.
1021    /// Contains implementations of methods that are inherent to a type.
1022    /// Methods in these implementations don't need to be exported.
1023    query inherent_impls(key: DefId) -> &'tcx [DefId] {
1024        desc { |tcx| "collecting inherent impls for `{}`", tcx.def_path_str(key) }
1025        cache_on_disk_if { key.is_local() }
1026        separate_provide_extern
1027    }
1028
1029    query incoherent_impls(key: SimplifiedType) -> &'tcx [DefId] {
1030        desc { |tcx| "collecting all inherent impls for `{:?}`", key }
1031    }
1032
1033    /// Unsafety-check this `LocalDefId`.
1034    query check_unsafety(key: LocalDefId) {
1035        desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key) }
1036        cache_on_disk_if { true }
1037    }
1038
1039    /// Checks well-formedness of tail calls (`become f()`).
1040    query check_tail_calls(key: LocalDefId) -> Result<(), rustc_errors::ErrorGuaranteed> {
1041        desc { |tcx| "tail-call-checking `{}`", tcx.def_path_str(key) }
1042        cache_on_disk_if { true }
1043    }
1044
1045    /// Returns the types assumed to be well formed while "inside" of the given item.
1046    ///
1047    /// Note that we've liberated the late bound regions of function signatures, so
1048    /// this can not be used to check whether these types are well formed.
1049    query assumed_wf_types(key: LocalDefId) -> &'tcx [(Ty<'tcx>, Span)] {
1050        desc { |tcx| "computing the implied bounds of `{}`", tcx.def_path_str(key) }
1051    }
1052
1053    /// We need to store the assumed_wf_types for an RPITIT so that impls of foreign
1054    /// traits with return-position impl trait in traits can inherit the right wf types.
1055    query assumed_wf_types_for_rpitit(key: DefId) -> &'tcx [(Ty<'tcx>, Span)] {
1056        desc { |tcx| "computing the implied bounds of `{}`", tcx.def_path_str(key) }
1057        separate_provide_extern
1058    }
1059
1060    /// Computes the signature of the function.
1061    query fn_sig(key: DefId) -> ty::EarlyBinder<'tcx, ty::PolyFnSig<'tcx>> {
1062        desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) }
1063        cache_on_disk_if { key.is_local() }
1064        separate_provide_extern
1065        cycle_delay_bug
1066    }
1067
1068    /// Performs lint checking for the module.
1069    query lint_mod(key: LocalModDefId) {
1070        desc { |tcx| "linting {}", describe_as_module(key, tcx) }
1071    }
1072
1073    query check_unused_traits(_: ()) {
1074        desc { "checking unused trait imports in crate" }
1075    }
1076
1077    /// Checks the attributes in the module.
1078    query check_mod_attrs(key: LocalModDefId) {
1079        desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
1080    }
1081
1082    /// Checks for uses of unstable APIs in the module.
1083    query check_mod_unstable_api_usage(key: LocalModDefId) {
1084        desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
1085    }
1086
1087    /// Checks the loops in the module.
1088    query check_mod_loops(key: LocalModDefId) {
1089        desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) }
1090    }
1091
1092    query check_mod_naked_functions(key: LocalModDefId) {
1093        desc { |tcx| "checking naked functions in {}", describe_as_module(key, tcx) }
1094    }
1095
1096    query check_mod_privacy(key: LocalModDefId) {
1097        desc { |tcx| "checking privacy in {}", describe_as_module(key.to_local_def_id(), tcx) }
1098    }
1099
1100    query check_liveness(key: LocalDefId) {
1101        desc { |tcx| "checking liveness of variables in `{}`", tcx.def_path_str(key) }
1102    }
1103
1104    /// Return the live symbols in the crate for dead code check.
1105    ///
1106    /// The second return value maps from ADTs to ignored derived traits (e.g. Debug and Clone) and
1107    /// their respective impl (i.e., part of the derive macro)
1108    query live_symbols_and_ignored_derived_traits(_: ()) -> &'tcx (
1109        LocalDefIdSet,
1110        LocalDefIdMap<Vec<(DefId, DefId)>>
1111    ) {
1112        arena_cache
1113        desc { "finding live symbols in crate" }
1114    }
1115
1116    query check_mod_deathness(key: LocalModDefId) {
1117        desc { |tcx| "checking deathness of variables in {}", describe_as_module(key, tcx) }
1118    }
1119
1120    query check_mod_type_wf(key: LocalModDefId) -> Result<(), ErrorGuaranteed> {
1121        desc { |tcx| "checking that types are well-formed in {}", describe_as_module(key, tcx) }
1122        return_result_from_ensure_ok
1123    }
1124
1125    /// Caches `CoerceUnsized` kinds for impls on custom types.
1126    query coerce_unsized_info(key: DefId) -> Result<ty::adjustment::CoerceUnsizedInfo, ErrorGuaranteed> {
1127        desc { |tcx| "computing CoerceUnsized info for `{}`", tcx.def_path_str(key) }
1128        cache_on_disk_if { key.is_local() }
1129        separate_provide_extern
1130        return_result_from_ensure_ok
1131    }
1132
1133    query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
1134        desc { |tcx| "type-checking `{}`", tcx.def_path_str(key) }
1135        cache_on_disk_if(tcx) { !tcx.is_typeck_child(key.to_def_id()) }
1136    }
1137
1138    query used_trait_imports(key: LocalDefId) -> &'tcx UnordSet<LocalDefId> {
1139        desc { |tcx| "finding used_trait_imports `{}`", tcx.def_path_str(key) }
1140        cache_on_disk_if { true }
1141    }
1142
1143    query coherent_trait(def_id: DefId) -> Result<(), ErrorGuaranteed> {
1144        desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
1145        return_result_from_ensure_ok
1146    }
1147
1148    /// Borrow-checks the function body. If this is a closure, returns
1149    /// additional requirements that the closure's creator must verify.
1150    query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
1151        desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key) }
1152        cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) }
1153    }
1154
1155    /// Gets a complete map from all types to their inherent impls.
1156    ///
1157    /// <div class="warning">
1158    ///
1159    /// **Not meant to be used** directly outside of coherence.
1160    ///
1161    /// </div>
1162    query crate_inherent_impls(k: ()) -> (&'tcx CrateInherentImpls, Result<(), ErrorGuaranteed>) {
1163        desc { "finding all inherent impls defined in crate" }
1164    }
1165
1166    /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
1167    ///
1168    /// <div class="warning">
1169    ///
1170    /// **Not meant to be used** directly outside of coherence.
1171    ///
1172    /// </div>
1173    query crate_inherent_impls_validity_check(_: ()) -> Result<(), ErrorGuaranteed> {
1174        desc { "check for inherent impls that should not be defined in crate" }
1175        return_result_from_ensure_ok
1176    }
1177
1178    /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
1179    ///
1180    /// <div class="warning">
1181    ///
1182    /// **Not meant to be used** directly outside of coherence.
1183    ///
1184    /// </div>
1185    query crate_inherent_impls_overlap_check(_: ()) -> Result<(), ErrorGuaranteed> {
1186        desc { "check for overlap between inherent impls defined in this crate" }
1187        return_result_from_ensure_ok
1188    }
1189
1190    /// Checks whether all impls in the crate pass the overlap check, returning
1191    /// which impls fail it. If all impls are correct, the returned slice is empty.
1192    query orphan_check_impl(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
1193        desc { |tcx|
1194            "checking whether impl `{}` follows the orphan rules",
1195            tcx.def_path_str(key),
1196        }
1197        return_result_from_ensure_ok
1198    }
1199
1200    /// Check whether the function has any recursion that could cause the inliner to trigger
1201    /// a cycle.
1202    query mir_callgraph_reachable(key: (ty::Instance<'tcx>, LocalDefId)) -> bool {
1203        fatal_cycle
1204        desc { |tcx|
1205            "computing if `{}` (transitively) calls `{}`",
1206            key.0,
1207            tcx.def_path_str(key.1),
1208        }
1209    }
1210
1211    /// Obtain all the calls into other local functions
1212    query mir_inliner_callees(key: ty::InstanceKind<'tcx>) -> &'tcx [(DefId, GenericArgsRef<'tcx>)] {
1213        fatal_cycle
1214        desc { |tcx|
1215            "computing all local function calls in `{}`",
1216            tcx.def_path_str(key.def_id()),
1217        }
1218    }
1219
1220    /// Computes the tag (if any) for a given type and variant.
1221    ///
1222    /// `None` means that the variant doesn't need a tag (because it is niched).
1223    ///
1224    /// # Panics
1225    ///
1226    /// This query will panic for uninhabited variants and if the passed type is not an enum.
1227    query tag_for_variant(
1228        key: (Ty<'tcx>, abi::VariantIdx)
1229    ) -> Option<ty::ScalarInt> {
1230        desc { "computing variant tag for enum" }
1231    }
1232
1233    /// Evaluates a constant and returns the computed allocation.
1234    ///
1235    /// <div class="warning">
1236    ///
1237    /// **Do not call this query** directly, use [`Self::eval_to_const_value_raw`] or
1238    /// [`Self::eval_to_valtree`] instead.
1239    ///
1240    /// </div>
1241    query eval_to_allocation_raw(key: ty::PseudoCanonicalInput<'tcx, GlobalId<'tcx>>)
1242        -> EvalToAllocationRawResult<'tcx> {
1243        desc { |tcx|
1244            "const-evaluating + checking `{}`",
1245            key.value.display(tcx)
1246        }
1247        cache_on_disk_if { true }
1248    }
1249
1250    /// Evaluate a static's initializer, returning the allocation of the initializer's memory.
1251    query eval_static_initializer(key: DefId) -> EvalStaticInitializerRawResult<'tcx> {
1252        desc { |tcx|
1253            "evaluating initializer of static `{}`",
1254            tcx.def_path_str(key)
1255        }
1256        cache_on_disk_if { key.is_local() }
1257        separate_provide_extern
1258        feedable
1259    }
1260
1261    /// Evaluates const items or anonymous constants[^1] into a representation
1262    /// suitable for the type system and const generics.
1263    ///
1264    /// <div class="warning">
1265    ///
1266    /// **Do not call this** directly, use one of the following wrappers:
1267    /// [`TyCtxt::const_eval_poly`], [`TyCtxt::const_eval_resolve`],
1268    /// [`TyCtxt::const_eval_instance`], or [`TyCtxt::const_eval_global_id`].
1269    ///
1270    /// </div>
1271    ///
1272    /// [^1]: Such as enum variant explicit discriminants or array lengths.
1273    query eval_to_const_value_raw(key: ty::PseudoCanonicalInput<'tcx, GlobalId<'tcx>>)
1274        -> EvalToConstValueResult<'tcx> {
1275        desc { |tcx|
1276            "simplifying constant for the type system `{}`",
1277            key.value.display(tcx)
1278        }
1279        depth_limit
1280        cache_on_disk_if { true }
1281    }
1282
1283    /// Evaluate a constant and convert it to a type level constant or
1284    /// return `None` if that is not possible.
1285    query eval_to_valtree(
1286        key: ty::PseudoCanonicalInput<'tcx, GlobalId<'tcx>>
1287    ) -> EvalToValTreeResult<'tcx> {
1288        desc { "evaluating type-level constant" }
1289    }
1290
1291    /// Converts a type-level constant value into a MIR constant value.
1292    query valtree_to_const_val(key: ty::Value<'tcx>) -> mir::ConstValue<'tcx> {
1293        desc { "converting type-level constant value to MIR constant value"}
1294    }
1295
1296    /// Destructures array, ADT or tuple constants into the constants
1297    /// of their fields.
1298    query destructure_const(key: ty::Const<'tcx>) -> ty::DestructuredConst<'tcx> {
1299        desc { "destructuring type level constant"}
1300    }
1301
1302    // FIXME get rid of this with valtrees
1303    query lit_to_const(
1304        key: LitToConstInput<'tcx>
1305    ) -> ty::Const<'tcx> {
1306        desc { "converting literal to const" }
1307    }
1308
1309    query check_match(key: LocalDefId) -> Result<(), rustc_errors::ErrorGuaranteed> {
1310        desc { |tcx| "match-checking `{}`", tcx.def_path_str(key) }
1311        cache_on_disk_if { true }
1312    }
1313
1314    /// Performs part of the privacy check and computes effective visibilities.
1315    query effective_visibilities(_: ()) -> &'tcx EffectiveVisibilities {
1316        eval_always
1317        desc { "checking effective visibilities" }
1318    }
1319    query check_private_in_public(_: ()) {
1320        eval_always
1321        desc { "checking for private elements in public interfaces" }
1322    }
1323
1324    query reachable_set(_: ()) -> &'tcx LocalDefIdSet {
1325        arena_cache
1326        desc { "reachability" }
1327        cache_on_disk_if { true }
1328    }
1329
1330    /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
1331    /// in the case of closures, this will be redirected to the enclosing function.
1332    query region_scope_tree(def_id: DefId) -> &'tcx crate::middle::region::ScopeTree {
1333        desc { |tcx| "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
1334    }
1335
1336    /// Generates a MIR body for the shim.
1337    query mir_shims(key: ty::InstanceKind<'tcx>) -> &'tcx mir::Body<'tcx> {
1338        arena_cache
1339        desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
1340    }
1341
1342    /// The `symbol_name` query provides the symbol name for calling a
1343    /// given instance from the local crate. In particular, it will also
1344    /// look up the correct symbol name of instances from upstream crates.
1345    query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName<'tcx> {
1346        desc { "computing the symbol for `{}`", key }
1347        cache_on_disk_if { true }
1348    }
1349
1350    query def_kind(def_id: DefId) -> DefKind {
1351        desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
1352        cache_on_disk_if { def_id.is_local() }
1353        separate_provide_extern
1354        feedable
1355    }
1356
1357    /// Gets the span for the definition.
1358    query def_span(def_id: DefId) -> Span {
1359        desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }
1360        cache_on_disk_if { def_id.is_local() }
1361        separate_provide_extern
1362        feedable
1363    }
1364
1365    /// Gets the span for the identifier of the definition.
1366    query def_ident_span(def_id: DefId) -> Option<Span> {
1367        desc { |tcx| "looking up span for `{}`'s identifier", tcx.def_path_str(def_id) }
1368        cache_on_disk_if { def_id.is_local() }
1369        separate_provide_extern
1370        feedable
1371    }
1372
1373    query lookup_stability(def_id: DefId) -> Option<attr::Stability> {
1374        desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
1375        cache_on_disk_if { def_id.is_local() }
1376        separate_provide_extern
1377    }
1378
1379    query lookup_const_stability(def_id: DefId) -> Option<attr::ConstStability> {
1380        desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
1381        cache_on_disk_if { def_id.is_local() }
1382        separate_provide_extern
1383    }
1384
1385    query lookup_default_body_stability(def_id: DefId) -> Option<attr::DefaultBodyStability> {
1386        desc { |tcx| "looking up default body stability of `{}`", tcx.def_path_str(def_id) }
1387        separate_provide_extern
1388    }
1389
1390    query should_inherit_track_caller(def_id: DefId) -> bool {
1391        desc { |tcx| "computing should_inherit_track_caller of `{}`", tcx.def_path_str(def_id) }
1392    }
1393
1394    query lookup_deprecation_entry(def_id: DefId) -> Option<DeprecationEntry> {
1395        desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) }
1396        cache_on_disk_if { def_id.is_local() }
1397        separate_provide_extern
1398    }
1399
1400    /// Determines whether an item is annotated with `#[doc(hidden)]`.
1401    query is_doc_hidden(def_id: DefId) -> bool {
1402        desc { |tcx| "checking whether `{}` is `doc(hidden)`", tcx.def_path_str(def_id) }
1403        separate_provide_extern
1404    }
1405
1406    /// Determines whether an item is annotated with `#[doc(notable_trait)]`.
1407    query is_doc_notable_trait(def_id: DefId) -> bool {
1408        desc { |tcx| "checking whether `{}` is `doc(notable_trait)`", tcx.def_path_str(def_id) }
1409    }
1410
1411    /// Returns the attributes on the item at `def_id`.
1412    ///
1413    /// Do not use this directly, use `tcx.get_attrs` instead.
1414    query attrs_for_def(def_id: DefId) -> &'tcx [hir::Attribute] {
1415        desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
1416        separate_provide_extern
1417    }
1418
1419    query codegen_fn_attrs(def_id: DefId) -> &'tcx CodegenFnAttrs {
1420        desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) }
1421        arena_cache
1422        cache_on_disk_if { def_id.is_local() }
1423        separate_provide_extern
1424        feedable
1425    }
1426
1427    query asm_target_features(def_id: DefId) -> &'tcx FxIndexSet<Symbol> {
1428        desc { |tcx| "computing target features for inline asm of `{}`", tcx.def_path_str(def_id) }
1429    }
1430
1431    query fn_arg_names(def_id: DefId) -> &'tcx [Option<rustc_span::Ident>] {
1432        desc { |tcx| "looking up function parameter names for `{}`", tcx.def_path_str(def_id) }
1433        separate_provide_extern
1434    }
1435
1436    /// Gets the rendered value of the specified constant or associated constant.
1437    /// Used by rustdoc.
1438    query rendered_const(def_id: DefId) -> &'tcx String {
1439        arena_cache
1440        desc { |tcx| "rendering constant initializer of `{}`", tcx.def_path_str(def_id) }
1441        separate_provide_extern
1442    }
1443
1444    /// Gets the rendered precise capturing args for an opaque for use in rustdoc.
1445    query rendered_precise_capturing_args(def_id: DefId) -> Option<&'tcx [PreciseCapturingArgKind<Symbol, Symbol>]> {
1446        desc { |tcx| "rendering precise capturing args for `{}`", tcx.def_path_str(def_id) }
1447        separate_provide_extern
1448    }
1449
1450    query impl_parent(def_id: DefId) -> Option<DefId> {
1451        desc { |tcx| "computing specialization parent impl of `{}`", tcx.def_path_str(def_id) }
1452        separate_provide_extern
1453    }
1454
1455    query is_ctfe_mir_available(key: DefId) -> bool {
1456        desc { |tcx| "checking if item has CTFE MIR available: `{}`", tcx.def_path_str(key) }
1457        cache_on_disk_if { key.is_local() }
1458        separate_provide_extern
1459    }
1460    query is_mir_available(key: DefId) -> bool {
1461        desc { |tcx| "checking if item has MIR available: `{}`", tcx.def_path_str(key) }
1462        cache_on_disk_if { key.is_local() }
1463        separate_provide_extern
1464    }
1465
1466    query own_existential_vtable_entries(
1467        key: DefId
1468    ) -> &'tcx [DefId] {
1469        desc { |tcx| "finding all existential vtable entries for trait `{}`", tcx.def_path_str(key) }
1470    }
1471
1472    query vtable_entries(key: ty::TraitRef<'tcx>)
1473                        -> &'tcx [ty::VtblEntry<'tcx>] {
1474        desc { |tcx| "finding all vtable entries for trait `{}`", tcx.def_path_str(key.def_id) }
1475    }
1476
1477    query first_method_vtable_slot(key: ty::TraitRef<'tcx>) -> usize {
1478        desc { |tcx| "finding the slot within the vtable of `{}` for the implementation of `{}`", key.self_ty(), key.print_only_trait_name() }
1479    }
1480
1481    query supertrait_vtable_slot(key: (Ty<'tcx>, Ty<'tcx>)) -> Option<usize> {
1482        desc { |tcx| "finding the slot within vtable for trait object `{}` vtable ptr during trait upcasting coercion from `{}` vtable",
1483            key.1, key.0 }
1484    }
1485
1486    query vtable_allocation(key: (Ty<'tcx>, Option<ty::ExistentialTraitRef<'tcx>>)) -> mir::interpret::AllocId {
1487        desc { |tcx| "vtable const allocation for <{} as {}>",
1488            key.0,
1489            key.1.map(|trait_ref| format!("{trait_ref}")).unwrap_or("_".to_owned())
1490        }
1491    }
1492
1493    query codegen_select_candidate(
1494        key: PseudoCanonicalInput<'tcx, ty::TraitRef<'tcx>>
1495    ) -> Result<&'tcx ImplSource<'tcx, ()>, CodegenObligationError> {
1496        cache_on_disk_if { true }
1497        desc { |tcx| "computing candidate for `{}`", key.value }
1498    }
1499
1500    /// Return all `impl` blocks in the current crate.
1501    query all_local_trait_impls(_: ()) -> &'tcx rustc_data_structures::fx::FxIndexMap<DefId, Vec<LocalDefId>> {
1502        desc { "finding local trait impls" }
1503    }
1504
1505    /// Given a trait `trait_id`, return all known `impl` blocks.
1506    query trait_impls_of(trait_id: DefId) -> &'tcx ty::trait_def::TraitImpls {
1507        arena_cache
1508        desc { |tcx| "finding trait impls of `{}`", tcx.def_path_str(trait_id) }
1509    }
1510
1511    query specialization_graph_of(trait_id: DefId) -> Result<&'tcx specialization_graph::Graph, ErrorGuaranteed> {
1512        desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
1513        cache_on_disk_if { true }
1514        return_result_from_ensure_ok
1515    }
1516    query dyn_compatibility_violations(trait_id: DefId) -> &'tcx [DynCompatibilityViolation] {
1517        desc { |tcx| "determining dyn-compatibility of trait `{}`", tcx.def_path_str(trait_id) }
1518    }
1519    query is_dyn_compatible(trait_id: DefId) -> bool {
1520        desc { |tcx| "checking if trait `{}` is dyn-compatible", tcx.def_path_str(trait_id) }
1521    }
1522
1523    /// Gets the ParameterEnvironment for a given item; this environment
1524    /// will be in "user-facing" mode, meaning that it is suitable for
1525    /// type-checking etc, and it does not normalize specializable
1526    /// associated types.
1527    ///
1528    /// You should almost certainly not use this. If you already have an InferCtxt, then
1529    /// you should also probably have a `ParamEnv` from when it was built. If you don't,
1530    /// then you should take a `TypingEnv` to ensure that you handle opaque types correctly.
1531    query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
1532        desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
1533        feedable
1534    }
1535
1536    /// Like `param_env`, but returns the `ParamEnv` after all opaque types have been
1537    /// replaced with their hidden type. This is used in the old trait solver
1538    /// when in `PostAnalysis` mode and should not be called directly.
1539    query param_env_normalized_for_post_analysis(def_id: DefId) -> ty::ParamEnv<'tcx> {
1540        desc { |tcx| "computing revealed normalized predicates of `{}`", tcx.def_path_str(def_id) }
1541    }
1542
1543    /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
1544    /// `ty.is_copy()`, etc, since that will prune the environment where possible.
1545    query is_copy_raw(env: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) -> bool {
1546        desc { "computing whether `{}` is `Copy`", env.value }
1547    }
1548    /// Trait selection queries. These are best used by invoking `ty.is_use_cloned_modulo_regions()`,
1549    /// `ty.is_use_cloned()`, etc, since that will prune the environment where possible.
1550    query is_use_cloned_raw(env: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) -> bool {
1551        desc { "computing whether `{}` is `UseCloned`", env.value }
1552    }
1553    /// Query backing `Ty::is_sized`.
1554    query is_sized_raw(env: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) -> bool {
1555        desc { "computing whether `{}` is `Sized`", env.value }
1556    }
1557    /// Query backing `Ty::is_freeze`.
1558    query is_freeze_raw(env: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) -> bool {
1559        desc { "computing whether `{}` is freeze", env.value }
1560    }
1561    /// Query backing `Ty::is_unpin`.
1562    query is_unpin_raw(env: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) -> bool {
1563        desc { "computing whether `{}` is `Unpin`", env.value }
1564    }
1565    /// Query backing `Ty::needs_drop`.
1566    query needs_drop_raw(env: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) -> bool {
1567        desc { "computing whether `{}` needs drop", env.value }
1568    }
1569    /// Query backing `Ty::needs_async_drop`.
1570    query needs_async_drop_raw(env: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) -> bool {
1571        desc { "computing whether `{}` needs async drop", env.value }
1572    }
1573    /// Query backing `Ty::has_significant_drop_raw`.
1574    query has_significant_drop_raw(env: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) -> bool {
1575        desc { "computing whether `{}` has a significant drop", env.value }
1576    }
1577
1578    /// Query backing `Ty::is_structural_eq_shallow`.
1579    ///
1580    /// This is only correct for ADTs. Call `is_structural_eq_shallow` to handle all types
1581    /// correctly.
1582    query has_structural_eq_impl(ty: Ty<'tcx>) -> bool {
1583        desc {
1584            "computing whether `{}` implements `StructuralPartialEq`",
1585            ty
1586        }
1587    }
1588
1589    /// A list of types where the ADT requires drop if and only if any of
1590    /// those types require drop. If the ADT is known to always need drop
1591    /// then `Err(AlwaysRequiresDrop)` is returned.
1592    query adt_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1593        desc { |tcx| "computing when `{}` needs drop", tcx.def_path_str(def_id) }
1594        cache_on_disk_if { true }
1595    }
1596
1597    /// A list of types where the ADT requires drop if and only if any of those types
1598    /// has significant drop. A type marked with the attribute `rustc_insignificant_dtor`
1599    /// is considered to not be significant. A drop is significant if it is implemented
1600    /// by the user or does anything that will have any observable behavior (other than
1601    /// freeing up memory). If the ADT is known to have a significant destructor then
1602    /// `Err(AlwaysRequiresDrop)` is returned.
1603    query adt_significant_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1604        desc { |tcx| "computing when `{}` has a significant destructor", tcx.def_path_str(def_id) }
1605        cache_on_disk_if { false }
1606    }
1607
1608    /// Returns a list of types which (a) have a potentially significant destructor
1609    /// and (b) may be dropped as a result of dropping a value of some type `ty`
1610    /// (in the given environment).
1611    ///
1612    /// The idea of "significant" drop is somewhat informal and is used only for
1613    /// diagnostics and edition migrations. The idea is that a significant drop may have
1614    /// some visible side-effect on execution; freeing memory is NOT considered a side-effect.
1615    /// The rules are as follows:
1616    /// * Type with no explicit drop impl do not have significant drop.
1617    /// * Types with a drop impl are assumed to have significant drop unless they have a `#[rustc_insignificant_dtor]` annotation.
1618    ///
1619    /// Note that insignificant drop is a "shallow" property. A type like `Vec<LockGuard>` does not
1620    /// have significant drop but the type `LockGuard` does, and so if `ty  = Vec<LockGuard>`
1621    /// then the return value would be `&[LockGuard]`.
1622    /// *IMPORTANT*: *DO NOT* run this query before promoted MIR body is constructed,
1623    /// because this query partially depends on that query.
1624    /// Otherwise, there is a risk of query cycles.
1625    query list_significant_drop_tys(ty: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>) -> &'tcx ty::List<Ty<'tcx>> {
1626        desc { |tcx| "computing when `{}` has a significant destructor", ty.value }
1627        cache_on_disk_if { false }
1628    }
1629
1630    /// Computes the layout of a type. Note that this implicitly
1631    /// executes in `TypingMode::PostAnalysis`, and will normalize the input type.
1632    query layout_of(
1633        key: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>
1634    ) -> Result<ty::layout::TyAndLayout<'tcx>, &'tcx ty::layout::LayoutError<'tcx>> {
1635        depth_limit
1636        desc { "computing layout of `{}`", key.value }
1637        // we emit our own error during query cycle handling
1638        cycle_delay_bug
1639    }
1640
1641    /// Compute a `FnAbi` suitable for indirect calls, i.e. to `fn` pointers.
1642    ///
1643    /// NB: this doesn't handle virtual calls - those should use `fn_abi_of_instance`
1644    /// instead, where the instance is an `InstanceKind::Virtual`.
1645    query fn_abi_of_fn_ptr(
1646        key: ty::PseudoCanonicalInput<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1647    ) -> Result<&'tcx rustc_target::callconv::FnAbi<'tcx, Ty<'tcx>>, &'tcx ty::layout::FnAbiError<'tcx>> {
1648        desc { "computing call ABI of `{}` function pointers", key.value.0 }
1649    }
1650
1651    /// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for
1652    /// direct calls to an `fn`.
1653    ///
1654    /// NB: that includes virtual calls, which are represented by "direct calls"
1655    /// to an `InstanceKind::Virtual` instance (of `<dyn Trait as Trait>::fn`).
1656    query fn_abi_of_instance(
1657        key: ty::PseudoCanonicalInput<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1658    ) -> Result<&'tcx rustc_target::callconv::FnAbi<'tcx, Ty<'tcx>>, &'tcx ty::layout::FnAbiError<'tcx>> {
1659        desc { "computing call ABI of `{}`", key.value.0 }
1660    }
1661
1662    query dylib_dependency_formats(_: CrateNum)
1663                                    -> &'tcx [(CrateNum, LinkagePreference)] {
1664        desc { "getting dylib dependency formats of crate" }
1665        separate_provide_extern
1666    }
1667
1668    query dependency_formats(_: ()) -> &'tcx Arc<crate::middle::dependency_format::Dependencies> {
1669        arena_cache
1670        desc { "getting the linkage format of all dependencies" }
1671    }
1672
1673    query is_compiler_builtins(_: CrateNum) -> bool {
1674        fatal_cycle
1675        desc { "checking if the crate is_compiler_builtins" }
1676        separate_provide_extern
1677    }
1678    query has_global_allocator(_: CrateNum) -> bool {
1679        // This query depends on untracked global state in CStore
1680        eval_always
1681        fatal_cycle
1682        desc { "checking if the crate has_global_allocator" }
1683        separate_provide_extern
1684    }
1685    query has_alloc_error_handler(_: CrateNum) -> bool {
1686        // This query depends on untracked global state in CStore
1687        eval_always
1688        fatal_cycle
1689        desc { "checking if the crate has_alloc_error_handler" }
1690        separate_provide_extern
1691    }
1692    query has_panic_handler(_: CrateNum) -> bool {
1693        fatal_cycle
1694        desc { "checking if the crate has_panic_handler" }
1695        separate_provide_extern
1696    }
1697    query is_profiler_runtime(_: CrateNum) -> bool {
1698        fatal_cycle
1699        desc { "checking if a crate is `#![profiler_runtime]`" }
1700        separate_provide_extern
1701    }
1702    query has_ffi_unwind_calls(key: LocalDefId) -> bool {
1703        desc { |tcx| "checking if `{}` contains FFI-unwind calls", tcx.def_path_str(key) }
1704        cache_on_disk_if { true }
1705    }
1706    query required_panic_strategy(_: CrateNum) -> Option<PanicStrategy> {
1707        fatal_cycle
1708        desc { "getting a crate's required panic strategy" }
1709        separate_provide_extern
1710    }
1711    query panic_in_drop_strategy(_: CrateNum) -> PanicStrategy {
1712        fatal_cycle
1713        desc { "getting a crate's configured panic-in-drop strategy" }
1714        separate_provide_extern
1715    }
1716    query is_no_builtins(_: CrateNum) -> bool {
1717        fatal_cycle
1718        desc { "getting whether a crate has `#![no_builtins]`" }
1719        separate_provide_extern
1720    }
1721    query symbol_mangling_version(_: CrateNum) -> SymbolManglingVersion {
1722        fatal_cycle
1723        desc { "getting a crate's symbol mangling version" }
1724        separate_provide_extern
1725    }
1726
1727    query extern_crate(def_id: CrateNum) -> Option<&'tcx ExternCrate> {
1728        eval_always
1729        desc { "getting crate's ExternCrateData" }
1730        separate_provide_extern
1731    }
1732
1733    query specialization_enabled_in(cnum: CrateNum) -> bool {
1734        desc { "checking whether the crate enabled `specialization`/`min_specialization`" }
1735        separate_provide_extern
1736    }
1737
1738    query specializes(_: (DefId, DefId)) -> bool {
1739        desc { "computing whether impls specialize one another" }
1740    }
1741    query in_scope_traits_map(_: hir::OwnerId)
1742        -> Option<&'tcx ItemLocalMap<Box<[TraitCandidate]>>> {
1743        desc { "getting traits in scope at a block" }
1744    }
1745
1746    /// Returns whether the impl or associated function has the `default` keyword.
1747    query defaultness(def_id: DefId) -> hir::Defaultness {
1748        desc { |tcx| "looking up whether `{}` has `default`", tcx.def_path_str(def_id) }
1749        separate_provide_extern
1750        feedable
1751    }
1752
1753    query check_well_formed(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
1754        desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key) }
1755        return_result_from_ensure_ok
1756    }
1757
1758    query enforce_impl_non_lifetime_params_are_constrained(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
1759        desc { |tcx| "checking that `{}`'s generics are constrained by the impl header", tcx.def_path_str(key) }
1760        return_result_from_ensure_ok
1761    }
1762
1763    // The `DefId`s of all non-generic functions and statics in the given crate
1764    // that can be reached from outside the crate.
1765    //
1766    // We expect this items to be available for being linked to.
1767    //
1768    // This query can also be called for `LOCAL_CRATE`. In this case it will
1769    // compute which items will be reachable to other crates, taking into account
1770    // the kind of crate that is currently compiled. Crates with only a
1771    // C interface have fewer reachable things.
1772    //
1773    // Does not include external symbols that don't have a corresponding DefId,
1774    // like the compiler-generated `main` function and so on.
1775    query reachable_non_generics(_: CrateNum)
1776        -> &'tcx DefIdMap<SymbolExportInfo> {
1777        arena_cache
1778        desc { "looking up the exported symbols of a crate" }
1779        separate_provide_extern
1780    }
1781    query is_reachable_non_generic(def_id: DefId) -> bool {
1782        desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
1783        cache_on_disk_if { def_id.is_local() }
1784        separate_provide_extern
1785    }
1786    query is_unreachable_local_definition(def_id: LocalDefId) -> bool {
1787        desc { |tcx|
1788            "checking whether `{}` is reachable from outside the crate",
1789            tcx.def_path_str(def_id),
1790        }
1791    }
1792
1793    /// The entire set of monomorphizations the local crate can safely
1794    /// link to because they are exported from upstream crates. Do
1795    /// not depend on this directly, as its value changes anytime
1796    /// a monomorphization gets added or removed in any upstream
1797    /// crate. Instead use the narrower `upstream_monomorphizations_for`,
1798    /// `upstream_drop_glue_for`, `upstream_async_drop_glue_for`, or,
1799    /// even better, `Instance::upstream_monomorphization()`.
1800    query upstream_monomorphizations(_: ()) -> &'tcx DefIdMap<UnordMap<GenericArgsRef<'tcx>, CrateNum>> {
1801        arena_cache
1802        desc { "collecting available upstream monomorphizations" }
1803    }
1804
1805    /// Returns the set of upstream monomorphizations available for the
1806    /// generic function identified by the given `def_id`. The query makes
1807    /// sure to make a stable selection if the same monomorphization is
1808    /// available in multiple upstream crates.
1809    ///
1810    /// You likely want to call `Instance::upstream_monomorphization()`
1811    /// instead of invoking this query directly.
1812    query upstream_monomorphizations_for(def_id: DefId)
1813        -> Option<&'tcx UnordMap<GenericArgsRef<'tcx>, CrateNum>>
1814    {
1815        desc { |tcx|
1816            "collecting available upstream monomorphizations for `{}`",
1817            tcx.def_path_str(def_id),
1818        }
1819        separate_provide_extern
1820    }
1821
1822    /// Returns the upstream crate that exports drop-glue for the given
1823    /// type (`args` is expected to be a single-item list containing the
1824    /// type one wants drop-glue for).
1825    ///
1826    /// This is a subset of `upstream_monomorphizations_for` in order to
1827    /// increase dep-tracking granularity. Otherwise adding or removing any
1828    /// type with drop-glue in any upstream crate would invalidate all
1829    /// functions calling drop-glue of an upstream type.
1830    ///
1831    /// You likely want to call `Instance::upstream_monomorphization()`
1832    /// instead of invoking this query directly.
1833    ///
1834    /// NOTE: This query could easily be extended to also support other
1835    ///       common functions that have are large set of monomorphizations
1836    ///       (like `Clone::clone` for example).
1837    query upstream_drop_glue_for(args: GenericArgsRef<'tcx>) -> Option<CrateNum> {
1838        desc { "available upstream drop-glue for `{:?}`", args }
1839    }
1840
1841    /// Returns the upstream crate that exports async-drop-glue for
1842    /// the given type (`args` is expected to be a single-item list
1843    /// containing the type one wants async-drop-glue for).
1844    ///
1845    /// This is a subset of `upstream_monomorphizations_for` in order
1846    /// to increase dep-tracking granularity. Otherwise adding or
1847    /// removing any type with async-drop-glue in any upstream crate
1848    /// would invalidate all functions calling async-drop-glue of an
1849    /// upstream type.
1850    ///
1851    /// You likely want to call `Instance::upstream_monomorphization()`
1852    /// instead of invoking this query directly.
1853    ///
1854    /// NOTE: This query could easily be extended to also support other
1855    ///       common functions that have are large set of monomorphizations
1856    ///       (like `Clone::clone` for example).
1857    query upstream_async_drop_glue_for(args: GenericArgsRef<'tcx>) -> Option<CrateNum> {
1858        desc { "available upstream async-drop-glue for `{:?}`", args }
1859    }
1860
1861    /// Returns a list of all `extern` blocks of a crate.
1862    query foreign_modules(_: CrateNum) -> &'tcx FxIndexMap<DefId, ForeignModule> {
1863        arena_cache
1864        desc { "looking up the foreign modules of a linked crate" }
1865        separate_provide_extern
1866    }
1867
1868    /// Lint against `extern fn` declarations having incompatible types.
1869    query clashing_extern_declarations(_: ()) {
1870        desc { "checking `extern fn` declarations are compatible" }
1871    }
1872
1873    /// Identifies the entry-point (e.g., the `main` function) for a given
1874    /// crate, returning `None` if there is no entry point (such as for library crates).
1875    query entry_fn(_: ()) -> Option<(DefId, EntryFnType)> {
1876        desc { "looking up the entry function of a crate" }
1877    }
1878
1879    /// Finds the `rustc_proc_macro_decls` item of a crate.
1880    query proc_macro_decls_static(_: ()) -> Option<LocalDefId> {
1881        desc { "looking up the proc macro declarations for a crate" }
1882    }
1883
1884    // The macro which defines `rustc_metadata::provide_extern` depends on this query's name.
1885    // Changing the name should cause a compiler error, but in case that changes, be aware.
1886    query crate_hash(_: CrateNum) -> Svh {
1887        eval_always
1888        desc { "looking up the hash a crate" }
1889        separate_provide_extern
1890    }
1891
1892    /// Gets the hash for the host proc macro. Used to support -Z dual-proc-macro.
1893    query crate_host_hash(_: CrateNum) -> Option<Svh> {
1894        eval_always
1895        desc { "looking up the hash of a host version of a crate" }
1896        separate_provide_extern
1897    }
1898
1899    /// Gets the extra data to put in each output filename for a crate.
1900    /// For example, compiling the `foo` crate with `extra-filename=-a` creates a `libfoo-b.rlib` file.
1901    query extra_filename(_: CrateNum) -> &'tcx String {
1902        arena_cache
1903        eval_always
1904        desc { "looking up the extra filename for a crate" }
1905        separate_provide_extern
1906    }
1907
1908    /// Gets the paths where the crate came from in the file system.
1909    query crate_extern_paths(_: CrateNum) -> &'tcx Vec<PathBuf> {
1910        arena_cache
1911        eval_always
1912        desc { "looking up the paths for extern crates" }
1913        separate_provide_extern
1914    }
1915
1916    /// Given a crate and a trait, look up all impls of that trait in the crate.
1917    /// Return `(impl_id, self_ty)`.
1918    query implementations_of_trait(_: (CrateNum, DefId)) -> &'tcx [(DefId, Option<SimplifiedType>)] {
1919        desc { "looking up implementations of a trait in a crate" }
1920        separate_provide_extern
1921    }
1922
1923    /// Collects all incoherent impls for the given crate and type.
1924    ///
1925    /// Do not call this directly, but instead use the `incoherent_impls` query.
1926    /// This query is only used to get the data necessary for that query.
1927    query crate_incoherent_impls(key: (CrateNum, SimplifiedType)) -> &'tcx [DefId] {
1928        desc { |tcx| "collecting all impls for a type in a crate" }
1929        separate_provide_extern
1930    }
1931
1932    /// Get the corresponding native library from the `native_libraries` query
1933    query native_library(def_id: DefId) -> Option<&'tcx NativeLib> {
1934        desc { |tcx| "getting the native library for `{}`", tcx.def_path_str(def_id) }
1935    }
1936
1937    query inherit_sig_for_delegation_item(def_id: LocalDefId) -> &'tcx [Ty<'tcx>] {
1938        desc { "inheriting delegation signature" }
1939    }
1940
1941    /// Does lifetime resolution on items. Importantly, we can't resolve
1942    /// lifetimes directly on things like trait methods, because of trait params.
1943    /// See `rustc_resolve::late::lifetimes` for details.
1944    query resolve_bound_vars(owner_id: hir::OwnerId) -> &'tcx ResolveBoundVars {
1945        arena_cache
1946        desc { |tcx| "resolving lifetimes for `{}`", tcx.def_path_str(owner_id) }
1947    }
1948    query named_variable_map(owner_id: hir::OwnerId) -> &'tcx SortedMap<ItemLocalId, ResolvedArg> {
1949        desc { |tcx| "looking up a named region inside `{}`", tcx.def_path_str(owner_id) }
1950    }
1951    query is_late_bound_map(owner_id: hir::OwnerId) -> Option<&'tcx FxIndexSet<ItemLocalId>> {
1952        desc { |tcx| "testing if a region is late bound inside `{}`", tcx.def_path_str(owner_id) }
1953    }
1954    /// Returns the *default lifetime* to be used if a trait object type were to be passed for
1955    /// the type parameter given by `DefId`.
1956    ///
1957    /// **Tip**: You can use `#[rustc_object_lifetime_default]` on an item to basically
1958    /// print the result of this query for use in UI tests or for debugging purposes.
1959    ///
1960    /// # Examples
1961    ///
1962    /// - For `T` in `struct Foo<'a, T: 'a>(&'a T);`, this would be `Param('a)`
1963    /// - For `T` in `struct Bar<'a, T>(&'a T);`, this would be `Empty`
1964    ///
1965    /// # Panics
1966    ///
1967    /// This query will panic if the given definition is not a type parameter.
1968    query object_lifetime_default(def_id: DefId) -> ObjectLifetimeDefault {
1969        desc { "looking up lifetime defaults for type parameter `{}`", tcx.def_path_str(def_id) }
1970        separate_provide_extern
1971    }
1972    query late_bound_vars_map(owner_id: hir::OwnerId)
1973        -> &'tcx SortedMap<ItemLocalId, Vec<ty::BoundVariableKind>> {
1974        desc { |tcx| "looking up late bound vars inside `{}`", tcx.def_path_str(owner_id) }
1975    }
1976    /// For an opaque type, return the list of (captured lifetime, inner generic param).
1977    /// ```ignore (illustrative)
1978    /// fn foo<'a: 'a, 'b, T>(&'b u8) -> impl Into<Self> + 'b { ... }
1979    /// ```
1980    ///
1981    /// We would return `[('a, '_a), ('b, '_b)]`, with `'a` early-bound and `'b` late-bound.
1982    ///
1983    /// After hir_ty_lowering, we get:
1984    /// ```ignore (pseudo-code)
1985    /// opaque foo::<'a>::opaque<'_a, '_b>: Into<Foo<'_a>> + '_b;
1986    ///                          ^^^^^^^^ inner generic params
1987    /// fn foo<'a>: for<'b> fn(&'b u8) -> foo::<'a>::opaque::<'a, 'b>
1988    ///                                                       ^^^^^^ captured lifetimes
1989    /// ```
1990    query opaque_captured_lifetimes(def_id: LocalDefId) -> &'tcx [(ResolvedArg, LocalDefId)] {
1991        desc { |tcx| "listing captured lifetimes for opaque `{}`", tcx.def_path_str(def_id) }
1992    }
1993
1994    /// Computes the visibility of the provided `def_id`.
1995    ///
1996    /// If the item from the `def_id` doesn't have a visibility, it will panic. For example
1997    /// a generic type parameter will panic if you call this method on it:
1998    ///
1999    /// ```
2000    /// use std::fmt::Debug;
2001    ///
2002    /// pub trait Foo<T: Debug> {}
2003    /// ```
2004    ///
2005    /// In here, if you call `visibility` on `T`, it'll panic.
2006    query visibility(def_id: DefId) -> ty::Visibility<DefId> {
2007        desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
2008        separate_provide_extern
2009        feedable
2010    }
2011
2012    query inhabited_predicate_adt(key: DefId) -> ty::inhabitedness::InhabitedPredicate<'tcx> {
2013        desc { "computing the uninhabited predicate of `{:?}`", key }
2014    }
2015
2016    /// Do not call this query directly: invoke `Ty::inhabited_predicate` instead.
2017    query inhabited_predicate_type(key: Ty<'tcx>) -> ty::inhabitedness::InhabitedPredicate<'tcx> {
2018        desc { "computing the uninhabited predicate of `{}`", key }
2019    }
2020
2021    query dep_kind(_: CrateNum) -> CrateDepKind {
2022        eval_always
2023        desc { "fetching what a dependency looks like" }
2024        separate_provide_extern
2025    }
2026
2027    /// Gets the name of the crate.
2028    query crate_name(_: CrateNum) -> Symbol {
2029        feedable
2030        desc { "fetching what a crate is named" }
2031        separate_provide_extern
2032    }
2033    query module_children(def_id: DefId) -> &'tcx [ModChild] {
2034        desc { |tcx| "collecting child items of module `{}`", tcx.def_path_str(def_id) }
2035        separate_provide_extern
2036    }
2037    query extern_mod_stmt_cnum(def_id: LocalDefId) -> Option<CrateNum> {
2038        desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id) }
2039    }
2040
2041    /// Gets the number of definitions in a foreign crate.
2042    ///
2043    /// This allows external tools to iterate over all definitions in a foreign crate.
2044    ///
2045    /// This should never be used for the local crate, instead use `iter_local_def_id`.
2046    query num_extern_def_ids(_: CrateNum) -> usize {
2047        desc { "fetching the number of definitions in a crate" }
2048        separate_provide_extern
2049    }
2050
2051    query lib_features(_: CrateNum) -> &'tcx LibFeatures {
2052        desc { "calculating the lib features defined in a crate" }
2053        separate_provide_extern
2054        arena_cache
2055    }
2056    query stability_implications(_: CrateNum) -> &'tcx UnordMap<Symbol, Symbol> {
2057        arena_cache
2058        desc { "calculating the implications between `#[unstable]` features defined in a crate" }
2059        separate_provide_extern
2060    }
2061    /// Whether the function is an intrinsic
2062    query intrinsic_raw(def_id: DefId) -> Option<rustc_middle::ty::IntrinsicDef> {
2063        desc { |tcx| "fetch intrinsic name if `{}` is an intrinsic", tcx.def_path_str(def_id) }
2064        separate_provide_extern
2065    }
2066    /// Returns the lang items defined in another crate by loading it from metadata.
2067    query get_lang_items(_: ()) -> &'tcx LanguageItems {
2068        arena_cache
2069        eval_always
2070        desc { "calculating the lang items map" }
2071    }
2072
2073    /// Returns all diagnostic items defined in all crates.
2074    query all_diagnostic_items(_: ()) -> &'tcx rustc_hir::diagnostic_items::DiagnosticItems {
2075        arena_cache
2076        eval_always
2077        desc { "calculating the diagnostic items map" }
2078    }
2079
2080    /// Returns the lang items defined in another crate by loading it from metadata.
2081    query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, LangItem)] {
2082        desc { "calculating the lang items defined in a crate" }
2083        separate_provide_extern
2084    }
2085
2086    /// Returns the diagnostic items defined in a crate.
2087    query diagnostic_items(_: CrateNum) -> &'tcx rustc_hir::diagnostic_items::DiagnosticItems {
2088        arena_cache
2089        desc { "calculating the diagnostic items map in a crate" }
2090        separate_provide_extern
2091    }
2092
2093    query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
2094        desc { "calculating the missing lang items in a crate" }
2095        separate_provide_extern
2096    }
2097
2098    /// The visible parent map is a map from every item to a visible parent.
2099    /// It prefers the shortest visible path to an item.
2100    /// Used for diagnostics, for example path trimming.
2101    /// The parents are modules, enums or traits.
2102    query visible_parent_map(_: ()) -> &'tcx DefIdMap<DefId> {
2103        arena_cache
2104        desc { "calculating the visible parent map" }
2105    }
2106    /// Collects the "trimmed", shortest accessible paths to all items for diagnostics.
2107    /// See the [provider docs](`rustc_middle::ty::print::trimmed_def_paths`) for more info.
2108    query trimmed_def_paths(_: ()) -> &'tcx DefIdMap<Symbol> {
2109        arena_cache
2110        desc { "calculating trimmed def paths" }
2111    }
2112    query missing_extern_crate_item(_: CrateNum) -> bool {
2113        eval_always
2114        desc { "seeing if we're missing an `extern crate` item for this crate" }
2115        separate_provide_extern
2116    }
2117    query used_crate_source(_: CrateNum) -> &'tcx Arc<CrateSource> {
2118        arena_cache
2119        eval_always
2120        desc { "looking at the source for a crate" }
2121        separate_provide_extern
2122    }
2123
2124    /// Returns the debugger visualizers defined for this crate.
2125    /// NOTE: This query has to be marked `eval_always` because it reads data
2126    ///       directly from disk that is not tracked anywhere else. I.e. it
2127    ///       represents a genuine input to the query system.
2128    query debugger_visualizers(_: CrateNum) -> &'tcx Vec<DebuggerVisualizerFile> {
2129        arena_cache
2130        desc { "looking up the debugger visualizers for this crate" }
2131        separate_provide_extern
2132        eval_always
2133    }
2134
2135    query postorder_cnums(_: ()) -> &'tcx [CrateNum] {
2136        eval_always
2137        desc { "generating a postorder list of CrateNums" }
2138    }
2139    /// Returns whether or not the crate with CrateNum 'cnum'
2140    /// is marked as a private dependency
2141    query is_private_dep(c: CrateNum) -> bool {
2142        eval_always
2143        desc { "checking whether crate `{}` is a private dependency", c }
2144        separate_provide_extern
2145    }
2146    query allocator_kind(_: ()) -> Option<AllocatorKind> {
2147        eval_always
2148        desc { "getting the allocator kind for the current crate" }
2149    }
2150    query alloc_error_handler_kind(_: ()) -> Option<AllocatorKind> {
2151        eval_always
2152        desc { "alloc error handler kind for the current crate" }
2153    }
2154
2155    query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
2156        desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) }
2157    }
2158    query maybe_unused_trait_imports(_: ()) -> &'tcx FxIndexSet<LocalDefId> {
2159        desc { "fetching potentially unused trait imports" }
2160    }
2161    query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx UnordSet<Symbol> {
2162        desc { |tcx| "finding names imported by glob use for `{}`", tcx.def_path_str(def_id) }
2163    }
2164
2165    query stability_index(_: ()) -> &'tcx stability::Index {
2166        arena_cache
2167        eval_always
2168        desc { "calculating the stability index for the local crate" }
2169    }
2170    /// All available crates in the graph, including those that should not be user-facing
2171    /// (such as private crates).
2172    query crates(_: ()) -> &'tcx [CrateNum] {
2173        eval_always
2174        desc { "fetching all foreign CrateNum instances" }
2175    }
2176    // Crates that are loaded non-speculatively (not for diagnostics or doc links).
2177    // FIXME: This is currently only used for collecting lang items, but should be used instead of
2178    // `crates` in most other cases too.
2179    query used_crates(_: ()) -> &'tcx [CrateNum] {
2180        eval_always
2181        desc { "fetching `CrateNum`s for all crates loaded non-speculatively" }
2182    }
2183
2184    /// A list of all traits in a crate, used by rustdoc and error reporting.
2185    query traits(_: CrateNum) -> &'tcx [DefId] {
2186        desc { "fetching all traits in a crate" }
2187        separate_provide_extern
2188    }
2189
2190    query trait_impls_in_crate(_: CrateNum) -> &'tcx [DefId] {
2191        desc { "fetching all trait impls in a crate" }
2192        separate_provide_extern
2193    }
2194
2195    /// The list of symbols exported from the given crate.
2196    ///
2197    /// - All names contained in `exported_symbols(cnum)` are guaranteed to
2198    ///   correspond to a publicly visible symbol in `cnum` machine code.
2199    /// - The `exported_symbols` sets of different crates do not intersect.
2200    query exported_symbols(cnum: CrateNum) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] {
2201        desc { "collecting exported symbols for crate `{}`", cnum}
2202        cache_on_disk_if { *cnum == LOCAL_CRATE }
2203        separate_provide_extern
2204    }
2205
2206    query collect_and_partition_mono_items(_: ()) -> MonoItemPartitions<'tcx> {
2207        eval_always
2208        desc { "collect_and_partition_mono_items" }
2209    }
2210
2211    query is_codegened_item(def_id: DefId) -> bool {
2212        desc { |tcx| "determining whether `{}` needs codegen", tcx.def_path_str(def_id) }
2213    }
2214
2215    query codegen_unit(sym: Symbol) -> &'tcx CodegenUnit<'tcx> {
2216        desc { "getting codegen unit `{sym}`" }
2217    }
2218
2219    query backend_optimization_level(_: ()) -> OptLevel {
2220        desc { "optimization level used by backend" }
2221    }
2222
2223    /// Return the filenames where output artefacts shall be stored.
2224    ///
2225    /// This query returns an `&Arc` because codegen backends need the value even after the `TyCtxt`
2226    /// has been destroyed.
2227    query output_filenames(_: ()) -> &'tcx Arc<OutputFilenames> {
2228        feedable
2229        desc { "getting output filenames" }
2230        arena_cache
2231    }
2232
2233    /// <div class="warning">
2234    ///
2235    /// Do not call this query directly: Invoke `normalize` instead.
2236    ///
2237    /// </div>
2238    query normalize_canonicalized_projection_ty(
2239        goal: CanonicalAliasGoal<'tcx>
2240    ) -> Result<
2241        &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
2242        NoSolution,
2243    > {
2244        desc { "normalizing `{}`", goal.canonical.value.value }
2245    }
2246
2247    /// <div class="warning">
2248    ///
2249    /// Do not call this query directly: Invoke `normalize` instead.
2250    ///
2251    /// </div>
2252    query normalize_canonicalized_weak_ty(
2253        goal: CanonicalAliasGoal<'tcx>
2254    ) -> Result<
2255        &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
2256        NoSolution,
2257    > {
2258        desc { "normalizing `{}`", goal.canonical.value.value }
2259    }
2260
2261    /// <div class="warning">
2262    ///
2263    /// Do not call this query directly: Invoke `normalize` instead.
2264    ///
2265    /// </div>
2266    query normalize_canonicalized_inherent_projection_ty(
2267        goal: CanonicalAliasGoal<'tcx>
2268    ) -> Result<
2269        &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
2270        NoSolution,
2271    > {
2272        desc { "normalizing `{}`", goal.canonical.value.value }
2273    }
2274
2275    /// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
2276    query try_normalize_generic_arg_after_erasing_regions(
2277        goal: PseudoCanonicalInput<'tcx, GenericArg<'tcx>>
2278    ) -> Result<GenericArg<'tcx>, NoSolution> {
2279        desc { "normalizing `{}`", goal.value }
2280    }
2281
2282    query implied_outlives_bounds(
2283        key: (CanonicalImpliedOutlivesBoundsGoal<'tcx>, bool)
2284    ) -> Result<
2285        &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
2286        NoSolution,
2287    > {
2288        desc { "computing implied outlives bounds for `{}` (hack disabled = {:?})", key.0.canonical.value.value.ty, key.1 }
2289    }
2290
2291    /// Do not call this query directly:
2292    /// invoke `DropckOutlives::new(dropped_ty)).fully_perform(typeck.infcx)` instead.
2293    query dropck_outlives(
2294        goal: CanonicalDropckOutlivesGoal<'tcx>
2295    ) -> Result<
2296        &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>,
2297        NoSolution,
2298    > {
2299        desc { "computing dropck types for `{}`", goal.canonical.value.value.dropped_ty }
2300    }
2301
2302    /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
2303    /// `infcx.predicate_must_hold()` instead.
2304    query evaluate_obligation(
2305        goal: CanonicalPredicateGoal<'tcx>
2306    ) -> Result<EvaluationResult, OverflowError> {
2307        desc { "evaluating trait selection obligation `{}`", goal.canonical.value.value }
2308    }
2309
2310    /// Do not call this query directly: part of the `Eq` type-op
2311    query type_op_ascribe_user_type(
2312        goal: CanonicalTypeOpAscribeUserTypeGoal<'tcx>
2313    ) -> Result<
2314        &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
2315        NoSolution,
2316    > {
2317        desc { "evaluating `type_op_ascribe_user_type` `{:?}`", goal.canonical.value.value }
2318    }
2319
2320    /// Do not call this query directly: part of the `ProvePredicate` type-op
2321    query type_op_prove_predicate(
2322        goal: CanonicalTypeOpProvePredicateGoal<'tcx>
2323    ) -> Result<
2324        &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
2325        NoSolution,
2326    > {
2327        desc { "evaluating `type_op_prove_predicate` `{:?}`", goal.canonical.value.value }
2328    }
2329
2330    /// Do not call this query directly: part of the `Normalize` type-op
2331    query type_op_normalize_ty(
2332        goal: CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
2333    ) -> Result<
2334        &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>,
2335        NoSolution,
2336    > {
2337        desc { "normalizing `{}`", goal.canonical.value.value.value }
2338    }
2339
2340    /// Do not call this query directly: part of the `Normalize` type-op
2341    query type_op_normalize_clause(
2342        goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::Clause<'tcx>>
2343    ) -> Result<
2344        &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Clause<'tcx>>>,
2345        NoSolution,
2346    > {
2347        desc { "normalizing `{:?}`", goal.canonical.value.value.value }
2348    }
2349
2350    /// Do not call this query directly: part of the `Normalize` type-op
2351    query type_op_normalize_poly_fn_sig(
2352        goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
2353    ) -> Result<
2354        &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>,
2355        NoSolution,
2356    > {
2357        desc { "normalizing `{:?}`", goal.canonical.value.value.value }
2358    }
2359
2360    /// Do not call this query directly: part of the `Normalize` type-op
2361    query type_op_normalize_fn_sig(
2362        goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
2363    ) -> Result<
2364        &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>,
2365        NoSolution,
2366    > {
2367        desc { "normalizing `{:?}`", goal.canonical.value.value.value }
2368    }
2369
2370    query instantiate_and_check_impossible_predicates(key: (DefId, GenericArgsRef<'tcx>)) -> bool {
2371        desc { |tcx|
2372            "checking impossible instantiated predicates: `{}`",
2373            tcx.def_path_str(key.0)
2374        }
2375    }
2376
2377    query is_impossible_associated_item(key: (DefId, DefId)) -> bool {
2378        desc { |tcx|
2379            "checking if `{}` is impossible to reference within `{}`",
2380            tcx.def_path_str(key.1),
2381            tcx.def_path_str(key.0),
2382        }
2383    }
2384
2385    query method_autoderef_steps(
2386        goal: CanonicalTyGoal<'tcx>
2387    ) -> MethodAutoderefStepsResult<'tcx> {
2388        desc { "computing autoderef types for `{}`", goal.canonical.value.value }
2389    }
2390
2391    /// Returns the Rust target features for the current target. These are not always the same as LLVM target features!
2392    query rust_target_features(_: CrateNum) -> &'tcx UnordMap<String, rustc_target::target_features::Stability> {
2393        arena_cache
2394        eval_always
2395        desc { "looking up Rust target features" }
2396    }
2397
2398    query implied_target_features(feature: Symbol) -> &'tcx Vec<Symbol> {
2399        arena_cache
2400        eval_always
2401        desc { "looking up implied target features" }
2402    }
2403
2404    query features_query(_: ()) -> &'tcx rustc_feature::Features {
2405        feedable
2406        desc { "looking up enabled feature gates" }
2407    }
2408
2409    query crate_for_resolver((): ()) -> &'tcx Steal<(rustc_ast::Crate, rustc_ast::AttrVec)> {
2410        feedable
2411        no_hash
2412        desc { "the ast before macro expansion and name resolution" }
2413    }
2414
2415    /// Attempt to resolve the given `DefId` to an `Instance`, for the
2416    /// given generics args (`GenericArgsRef`), returning one of:
2417    ///  * `Ok(Some(instance))` on success
2418    ///  * `Ok(None)` when the `GenericArgsRef` are still too generic,
2419    ///    and therefore don't allow finding the final `Instance`
2420    ///  * `Err(ErrorGuaranteed)` when the `Instance` resolution process
2421    ///    couldn't complete due to errors elsewhere - this is distinct
2422    ///    from `Ok(None)` to avoid misleading diagnostics when an error
2423    ///    has already been/will be emitted, for the original cause.
2424    query resolve_instance_raw(
2425        key: ty::PseudoCanonicalInput<'tcx, (DefId, GenericArgsRef<'tcx>)>
2426    ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
2427        desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) }
2428    }
2429
2430    query reveal_opaque_types_in_bounds(key: ty::Clauses<'tcx>) -> ty::Clauses<'tcx> {
2431        desc { "revealing opaque types in `{:?}`", key }
2432    }
2433
2434    query limits(key: ()) -> Limits {
2435        desc { "looking up limits" }
2436    }
2437
2438    /// Performs an HIR-based well-formed check on the item with the given `HirId`. If
2439    /// we get an `Unimplemented` error that matches the provided `Predicate`, return
2440    /// the cause of the newly created obligation.
2441    ///
2442    /// This is only used by error-reporting code to get a better cause (in particular, a better
2443    /// span) for an *existing* error. Therefore, it is best-effort, and may never handle
2444    /// all of the cases that the normal `ty::Ty`-based wfcheck does. This is fine,
2445    /// because the `ty::Ty`-based wfcheck is always run.
2446    query diagnostic_hir_wf_check(
2447        key: (ty::Predicate<'tcx>, WellFormedLoc)
2448    ) -> Option<&'tcx ObligationCause<'tcx>> {
2449        arena_cache
2450        eval_always
2451        no_hash
2452        desc { "performing HIR wf-checking for predicate `{:?}` at item `{:?}`", key.0, key.1 }
2453    }
2454
2455    /// The list of backend features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`,
2456    /// `--target` and similar).
2457    query global_backend_features(_: ()) -> &'tcx Vec<String> {
2458        arena_cache
2459        eval_always
2460        desc { "computing the backend features for CLI flags" }
2461    }
2462
2463    query check_validity_requirement(key: (ValidityRequirement, ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>)) -> Result<bool, &'tcx ty::layout::LayoutError<'tcx>> {
2464        desc { "checking validity requirement for `{}`: {}", key.1.value, key.0 }
2465    }
2466
2467    /// This takes the def-id of an associated item from a impl of a trait,
2468    /// and checks its validity against the trait item it corresponds to.
2469    ///
2470    /// Any other def id will ICE.
2471    query compare_impl_item(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
2472        desc { |tcx| "checking assoc item `{}` is compatible with trait definition", tcx.def_path_str(key) }
2473        return_result_from_ensure_ok
2474    }
2475
2476    query deduced_param_attrs(def_id: DefId) -> &'tcx [ty::DeducedParamAttrs] {
2477        desc { |tcx| "deducing parameter attributes for {}", tcx.def_path_str(def_id) }
2478        separate_provide_extern
2479    }
2480
2481    query doc_link_resolutions(def_id: DefId) -> &'tcx DocLinkResMap {
2482        eval_always
2483        desc { "resolutions for documentation links for a module" }
2484        separate_provide_extern
2485    }
2486
2487    query doc_link_traits_in_scope(def_id: DefId) -> &'tcx [DefId] {
2488        eval_always
2489        desc { "traits in scope for documentation links for a module" }
2490        separate_provide_extern
2491    }
2492
2493    /// Get all item paths that were stripped by a `#[cfg]` in a particular crate.
2494    /// Should not be called for the local crate before the resolver outputs are created, as it
2495    /// is only fed there.
2496    query stripped_cfg_items(cnum: CrateNum) -> &'tcx [StrippedCfgItem] {
2497        desc { "getting cfg-ed out item names" }
2498        separate_provide_extern
2499    }
2500
2501    query generics_require_sized_self(def_id: DefId) -> bool {
2502        desc { "check whether the item has a `where Self: Sized` bound" }
2503    }
2504
2505    query cross_crate_inlinable(def_id: DefId) -> bool {
2506        desc { "whether the item should be made inlinable across crates" }
2507        separate_provide_extern
2508    }
2509
2510    /// Perform monomorphization-time checking on this item.
2511    /// This is used for lints/errors that can only be checked once the instance is fully
2512    /// monomorphized.
2513    query check_mono_item(key: ty::Instance<'tcx>) {
2514        desc { "monomorphization-time checking" }
2515        cache_on_disk_if { true }
2516    }
2517
2518    /// Builds the set of functions that should be skipped for the move-size check.
2519    query skip_move_check_fns(_: ()) -> &'tcx FxIndexSet<DefId> {
2520        arena_cache
2521        desc { "functions to skip for move-size check" }
2522    }
2523
2524    query items_of_instance(key: (ty::Instance<'tcx>, CollectionMode)) -> (&'tcx [Spanned<MonoItem<'tcx>>], &'tcx [Spanned<MonoItem<'tcx>>]) {
2525        desc { "collecting items used by `{}`", key.0 }
2526        cache_on_disk_if { true }
2527    }
2528
2529    query size_estimate(key: ty::Instance<'tcx>) -> usize {
2530        desc { "estimating codegen size of `{}`", key }
2531        cache_on_disk_if { true }
2532    }
2533}
2534
2535rustc_query_append! { define_callbacks! }
2536rustc_feedable_queries! { define_feedable! }