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