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