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