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