]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_middle/src/query/mod.rs
Rollup merge of #103852 - compiler-errors:rpitit-early-from-impl, r=lcnr
[rust.git] / compiler / rustc_middle / src / 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 use crate::ty::{self, print::describe_as_module, TyCtxt};
8 use rustc_span::def_id::LOCAL_CRATE;
9
10 // Each of these queries corresponds to a function pointer field in the
11 // `Providers` struct for requesting a value of that type, and a method
12 // on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way
13 // which memoizes and does dep-graph tracking, wrapping around the actual
14 // `Providers` that the driver creates (using several `rustc_*` crates).
15 //
16 // The result type of each query must implement `Clone`, and additionally
17 // `ty::query::values::Value`, which produces an appropriate placeholder
18 // (error) value if the query resulted in a query cycle.
19 // Queries marked with `fatal_cycle` do not need the latter implementation,
20 // as they will raise an fatal error on query cycles instead.
21 rustc_queries! {
22     query trigger_delay_span_bug(key: DefId) -> () {
23         desc { "triggering a delay span bug" }
24     }
25
26     query resolutions(_: ()) -> &'tcx ty::ResolverGlobalCtxt {
27         eval_always
28         no_hash
29         desc { "getting the resolver outputs" }
30     }
31
32     query resolver_for_lowering(_: ()) -> &'tcx Steal<ty::ResolverAstLowering> {
33         eval_always
34         no_hash
35         desc { "getting the resolver for lowering" }
36     }
37
38     /// Return the span for a definition.
39     /// Contrary to `def_span` below, this query returns the full absolute span of the definition.
40     /// This span is meant for dep-tracking rather than diagnostics. It should not be used outside
41     /// of rustc_middle::hir::source_map.
42     query source_span(key: LocalDefId) -> Span {
43         desc { "getting the source span" }
44     }
45
46     /// Represents crate as a whole (as distinct from the top-level crate module).
47     /// If you call `hir_crate` (e.g., indirectly by calling `tcx.hir().krate()`),
48     /// we will have to assume that any change means that you need to be recompiled.
49     /// This is because the `hir_crate` query gives you access to all other items.
50     /// To avoid this fate, do not call `tcx.hir().krate()`; instead,
51     /// prefer wrappers like `tcx.visit_all_items_in_krate()`.
52     query hir_crate(key: ()) -> Crate<'tcx> {
53         arena_cache
54         eval_always
55         desc { "getting the crate HIR" }
56     }
57
58     /// All items in the crate.
59     query hir_crate_items(_: ()) -> rustc_middle::hir::ModuleItems {
60         arena_cache
61         eval_always
62         desc { "getting HIR crate items" }
63     }
64
65     /// The items in a module.
66     ///
67     /// This can be conveniently accessed by `tcx.hir().visit_item_likes_in_module`.
68     /// Avoid calling this query directly.
69     query hir_module_items(key: LocalDefId) -> rustc_middle::hir::ModuleItems {
70         arena_cache
71         desc { |tcx| "getting HIR module items in `{}`", tcx.def_path_str(key.to_def_id()) }
72         cache_on_disk_if { true }
73     }
74
75     /// Gives access to the HIR node for the HIR owner `key`.
76     ///
77     /// This can be conveniently accessed by methods on `tcx.hir()`.
78     /// Avoid calling this query directly.
79     query hir_owner(key: hir::OwnerId) -> Option<crate::hir::Owner<'tcx>> {
80         desc { |tcx| "getting HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) }
81     }
82
83     /// Gives access to the HIR ID for the given `LocalDefId` owner `key`.
84     ///
85     /// This can be conveniently accessed by methods on `tcx.hir()`.
86     /// Avoid calling this query directly.
87     query local_def_id_to_hir_id(key: LocalDefId) -> hir::HirId {
88         desc { |tcx| "getting HIR ID of `{}`", tcx.def_path_str(key.to_def_id()) }
89     }
90
91     /// Gives access to the HIR node's parent for the HIR owner `key`.
92     ///
93     /// This can be conveniently accessed by methods on `tcx.hir()`.
94     /// Avoid calling this query directly.
95     query hir_owner_parent(key: hir::OwnerId) -> hir::HirId {
96         desc { |tcx| "getting HIR parent of `{}`", tcx.def_path_str(key.to_def_id()) }
97     }
98
99     /// Gives access to the HIR nodes and bodies inside the HIR owner `key`.
100     ///
101     /// This can be conveniently accessed by methods on `tcx.hir()`.
102     /// Avoid calling this query directly.
103     query hir_owner_nodes(key: hir::OwnerId) -> hir::MaybeOwner<&'tcx hir::OwnerNodes<'tcx>> {
104         desc { |tcx| "getting HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
105     }
106
107     /// Gives access to the HIR attributes inside the HIR owner `key`.
108     ///
109     /// This can be conveniently accessed by methods on `tcx.hir()`.
110     /// Avoid calling this query directly.
111     query hir_attrs(key: hir::OwnerId) -> &'tcx hir::AttributeMap<'tcx> {
112         desc { |tcx| "getting HIR owner attributes in `{}`", tcx.def_path_str(key.to_def_id()) }
113     }
114
115     /// Computes the `DefId` of the corresponding const parameter in case the `key` is a
116     /// const argument and returns `None` otherwise.
117     ///
118     /// ```ignore (incomplete)
119     /// let a = foo::<7>();
120     /// //            ^ Calling `opt_const_param_of` for this argument,
121     ///
122     /// fn foo<const N: usize>()
123     /// //           ^ returns this `DefId`.
124     ///
125     /// fn bar() {
126     /// // ^ While calling `opt_const_param_of` for other bodies returns `None`.
127     /// }
128     /// ```
129     // It looks like caching this query on disk actually slightly
130     // worsened performance in #74376.
131     //
132     // Once const generics are more prevalently used, we might want to
133     // consider only caching calls returning `Some`.
134     query opt_const_param_of(key: LocalDefId) -> Option<DefId> {
135         desc { |tcx| "computing the optional const parameter of `{}`", tcx.def_path_str(key.to_def_id()) }
136     }
137
138     /// Given the def_id of a const-generic parameter, computes the associated default const
139     /// parameter. e.g. `fn example<const N: usize=3>` called on `N` would return `3`.
140     query const_param_default(param: DefId) -> ty::Const<'tcx> {
141         desc { |tcx| "computing const default for a given parameter `{}`", tcx.def_path_str(param)  }
142         cache_on_disk_if { param.is_local() }
143         separate_provide_extern
144     }
145
146     /// Returns the [`Ty`][rustc_middle::ty::Ty] of the given [`DefId`]. If the [`DefId`] points
147     /// to an alias, it will "skip" this alias to return the aliased type.
148     ///
149     /// [`DefId`]: rustc_hir::def_id::DefId
150     query type_of(key: DefId) -> Ty<'tcx> {
151         desc { |tcx|
152             "{action} `{path}`",
153             action = {
154                 use rustc_hir::def::DefKind;
155                 match tcx.def_kind(key) {
156                     DefKind::TyAlias => "expanding type alias",
157                     DefKind::TraitAlias => "expanding trait alias",
158                     _ => "computing type of",
159                 }
160             },
161             path = tcx.def_path_str(key),
162         }
163         cache_on_disk_if { key.is_local() }
164         separate_provide_extern
165     }
166
167     query collect_trait_impl_trait_tys(key: DefId)
168         -> Result<&'tcx FxHashMap<DefId, Ty<'tcx>>, ErrorGuaranteed>
169     {
170         desc { "comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process" }
171         cache_on_disk_if { key.is_local() }
172         separate_provide_extern
173     }
174
175     query analysis(key: ()) -> Result<(), ErrorGuaranteed> {
176         eval_always
177         desc { "running analysis passes on this crate" }
178     }
179
180     /// This query checks the fulfillment of collected lint expectations.
181     /// All lint emitting queries have to be done before this is executed
182     /// to ensure that all expectations can be fulfilled.
183     ///
184     /// This is an extra query to enable other drivers (like rustdoc) to
185     /// only execute a small subset of the `analysis` query, while allowing
186     /// lints to be expected. In rustc, this query will be executed as part of
187     /// the `analysis` query and doesn't have to be called a second time.
188     ///
189     /// Tools can additionally pass in a tool filter. That will restrict the
190     /// expectations to only trigger for lints starting with the listed tool
191     /// name. This is useful for cases were not all linting code from rustc
192     /// was called. With the default `None` all registered lints will also
193     /// be checked for expectation fulfillment.
194     query check_expectations(key: Option<Symbol>) -> () {
195         eval_always
196         desc { "checking lint expectations (RFC 2383)" }
197     }
198
199     /// Maps from the `DefId` of an item (trait/struct/enum/fn) to its
200     /// associated generics.
201     query generics_of(key: DefId) -> ty::Generics {
202         desc { |tcx| "computing generics of `{}`", tcx.def_path_str(key) }
203         arena_cache
204         cache_on_disk_if { key.is_local() }
205         separate_provide_extern
206     }
207
208     /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
209     /// predicates (where-clauses) that must be proven true in order
210     /// to reference it. This is almost always the "predicates query"
211     /// that you want.
212     ///
213     /// `predicates_of` builds on `predicates_defined_on` -- in fact,
214     /// it is almost always the same as that query, except for the
215     /// case of traits. For traits, `predicates_of` contains
216     /// an additional `Self: Trait<...>` predicate that users don't
217     /// actually write. This reflects the fact that to invoke the
218     /// trait (e.g., via `Default::default`) you must supply types
219     /// that actually implement the trait. (However, this extra
220     /// predicate gets in the way of some checks, which are intended
221     /// to operate over only the actual where-clauses written by the
222     /// user.)
223     query predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
224         desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
225         cache_on_disk_if { key.is_local() }
226     }
227
228     /// Returns the list of bounds that can be used for
229     /// `SelectionCandidate::ProjectionCandidate(_)` and
230     /// `ProjectionTyCandidate::TraitDef`.
231     /// Specifically this is the bounds written on the trait's type
232     /// definition, or those after the `impl` keyword
233     ///
234     /// ```ignore (incomplete)
235     /// type X: Bound + 'lt
236     /// //      ^^^^^^^^^^^
237     /// impl Debug + Display
238     /// //   ^^^^^^^^^^^^^^^
239     /// ```
240     ///
241     /// `key` is the `DefId` of the associated type or opaque type.
242     ///
243     /// Bounds from the parent (e.g. with nested impl trait) are not included.
244     query explicit_item_bounds(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
245         desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) }
246         cache_on_disk_if { key.is_local() }
247         separate_provide_extern
248     }
249
250     /// Elaborated version of the predicates from `explicit_item_bounds`.
251     ///
252     /// For example:
253     ///
254     /// ```
255     /// trait MyTrait {
256     ///     type MyAType: Eq + ?Sized;
257     /// }
258     /// ```
259     ///
260     /// `explicit_item_bounds` returns `[<Self as MyTrait>::MyAType: Eq]`,
261     /// and `item_bounds` returns
262     /// ```text
263     /// [
264     ///     <Self as Trait>::MyAType: Eq,
265     ///     <Self as Trait>::MyAType: PartialEq<<Self as Trait>::MyAType>
266     /// ]
267     /// ```
268     ///
269     /// Bounds from the parent (e.g. with nested impl trait) are not included.
270     query item_bounds(key: DefId) -> &'tcx ty::List<ty::Predicate<'tcx>> {
271         desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) }
272     }
273
274     /// Look up all native libraries this crate depends on.
275     /// These are assembled from the following places:
276     /// - `extern` blocks (depending on their `link` attributes)
277     /// - the `libs` (`-l`) option
278     query native_libraries(_: CrateNum) -> Vec<NativeLib> {
279         arena_cache
280         desc { "looking up the native libraries of a linked crate" }
281         separate_provide_extern
282     }
283
284     query shallow_lint_levels_on(key: hir::OwnerId) -> rustc_middle::lint::ShallowLintLevelMap {
285         eval_always // fetches `resolutions`
286         arena_cache
287         desc { |tcx| "looking up lint levels for `{}`", tcx.def_path_str(key.to_def_id()) }
288     }
289
290     query lint_expectations(_: ()) -> Vec<(LintExpectationId, LintExpectation)> {
291         arena_cache
292         desc { "computing `#[expect]`ed lints in this crate" }
293     }
294
295     query parent_module_from_def_id(key: LocalDefId) -> LocalDefId {
296         eval_always
297         desc { |tcx| "getting the parent module of `{}`", tcx.def_path_str(key.to_def_id()) }
298     }
299
300     query expn_that_defined(key: DefId) -> rustc_span::ExpnId {
301         desc { |tcx| "getting the expansion that defined `{}`", tcx.def_path_str(key) }
302         separate_provide_extern
303     }
304
305     query is_panic_runtime(_: CrateNum) -> bool {
306         fatal_cycle
307         desc { "checking if the crate is_panic_runtime" }
308         separate_provide_extern
309     }
310
311     /// Checks whether a type is representable or infinitely sized
312     query representability(_: LocalDefId) -> rustc_middle::ty::Representability {
313         desc { "checking if `{}` is representable", tcx.def_path_str(key.to_def_id()) }
314         // infinitely sized types will cause a cycle
315         cycle_delay_bug
316         // we don't want recursive representability calls to be forced with
317         // incremental compilation because, if a cycle occurs, we need the
318         // entire cycle to be in memory for diagnostics
319         anon
320     }
321
322     /// An implementation detail for the `representability` query
323     query representability_adt_ty(_: Ty<'tcx>) -> rustc_middle::ty::Representability {
324         desc { "checking if `{}` is representable", key }
325         cycle_delay_bug
326         anon
327     }
328
329     /// Set of param indexes for type params that are in the type's representation
330     query params_in_repr(key: DefId) -> rustc_index::bit_set::BitSet<u32> {
331         desc { "finding type parameters in the representation" }
332         arena_cache
333         no_hash
334         separate_provide_extern
335     }
336
337     /// Fetch the THIR for a given body. If typeck for that body failed, returns an empty `Thir`.
338     query thir_body(key: ty::WithOptConstParam<LocalDefId>)
339         -> Result<(&'tcx Steal<thir::Thir<'tcx>>, thir::ExprId), ErrorGuaranteed>
340     {
341         // Perf tests revealed that hashing THIR is inefficient (see #85729).
342         no_hash
343         desc { |tcx| "building THIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
344     }
345
346     /// Create a THIR tree for debugging.
347     query thir_tree(key: ty::WithOptConstParam<LocalDefId>) -> String {
348         no_hash
349         arena_cache
350         desc { |tcx| "constructing THIR tree for `{}`", tcx.def_path_str(key.did.to_def_id()) }
351     }
352
353     /// Set of all the `DefId`s in this crate that have MIR associated with
354     /// them. This includes all the body owners, but also things like struct
355     /// constructors.
356     query mir_keys(_: ()) -> rustc_data_structures::fx::FxIndexSet<LocalDefId> {
357         arena_cache
358         desc { "getting a list of all mir_keys" }
359     }
360
361     /// Maps DefId's that have an associated `mir::Body` to the result
362     /// of the MIR const-checking pass. This is the set of qualifs in
363     /// the final value of a `const`.
364     query mir_const_qualif(key: DefId) -> mir::ConstQualifs {
365         desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
366         cache_on_disk_if { key.is_local() }
367         separate_provide_extern
368     }
369     query mir_const_qualif_const_arg(
370         key: (LocalDefId, DefId)
371     ) -> mir::ConstQualifs {
372         desc {
373             |tcx| "const checking the const argument `{}`",
374             tcx.def_path_str(key.0.to_def_id())
375         }
376     }
377
378     /// Fetch the MIR for a given `DefId` right after it's built - this includes
379     /// unreachable code.
380     query mir_built(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
381         desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
382     }
383
384     /// Fetch the MIR for a given `DefId` up till the point where it is
385     /// ready for const qualification.
386     ///
387     /// See the README for the `mir` module for details.
388     query mir_const(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
389         desc {
390             |tcx| "preparing {}`{}` for borrow checking",
391             if key.const_param_did.is_some() { "the const argument " } else { "" },
392             tcx.def_path_str(key.did.to_def_id()),
393         }
394         no_hash
395     }
396
397     /// Try to build an abstract representation of the given constant.
398     query thir_abstract_const(
399         key: DefId
400     ) -> Result<Option<&'tcx [ty::abstract_const::Node<'tcx>]>, ErrorGuaranteed> {
401         desc {
402             |tcx| "building an abstract representation for `{}`", tcx.def_path_str(key),
403         }
404         separate_provide_extern
405     }
406     /// Try to build an abstract representation of the given constant.
407     query thir_abstract_const_of_const_arg(
408         key: (LocalDefId, DefId)
409     ) -> Result<Option<&'tcx [ty::abstract_const::Node<'tcx>]>, ErrorGuaranteed> {
410         desc {
411             |tcx|
412             "building an abstract representation for the const argument `{}`",
413             tcx.def_path_str(key.0.to_def_id()),
414         }
415     }
416
417     query try_unify_abstract_consts(key:
418         ty::ParamEnvAnd<'tcx, (ty::UnevaluatedConst<'tcx>, ty::UnevaluatedConst<'tcx>
419     )>) -> bool {
420         desc {
421             |tcx| "trying to unify the generic constants `{}` and `{}`",
422             tcx.def_path_str(key.value.0.def.did), tcx.def_path_str(key.value.1.def.did)
423         }
424     }
425
426     query mir_drops_elaborated_and_const_checked(
427         key: ty::WithOptConstParam<LocalDefId>
428     ) -> &'tcx Steal<mir::Body<'tcx>> {
429         no_hash
430         desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.did.to_def_id()) }
431     }
432
433     query mir_for_ctfe(
434         key: DefId
435     ) -> &'tcx mir::Body<'tcx> {
436         desc { |tcx| "caching mir of `{}` for CTFE", tcx.def_path_str(key) }
437         cache_on_disk_if { key.is_local() }
438         separate_provide_extern
439     }
440
441     query mir_for_ctfe_of_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::Body<'tcx> {
442         desc {
443             |tcx| "caching MIR for CTFE of the const argument `{}`",
444             tcx.def_path_str(key.0.to_def_id())
445         }
446     }
447
448     query mir_promoted(key: ty::WithOptConstParam<LocalDefId>) ->
449         (
450             &'tcx Steal<mir::Body<'tcx>>,
451             &'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
452         ) {
453         no_hash
454         desc {
455             |tcx| "processing MIR for {}`{}`",
456             if key.const_param_did.is_some() { "the const argument " } else { "" },
457             tcx.def_path_str(key.did.to_def_id()),
458         }
459     }
460
461     query symbols_for_closure_captures(
462         key: (LocalDefId, LocalDefId)
463     ) -> Vec<rustc_span::Symbol> {
464         arena_cache
465         desc {
466             |tcx| "finding symbols for captures of closure `{}` in `{}`",
467             tcx.def_path_str(key.1.to_def_id()),
468             tcx.def_path_str(key.0.to_def_id())
469         }
470     }
471
472     /// MIR after our optimization passes have run. This is MIR that is ready
473     /// for codegen. This is also the only query that can fetch non-local MIR, at present.
474     query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> {
475         desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key) }
476         cache_on_disk_if { key.is_local() }
477         separate_provide_extern
478     }
479
480     /// Returns coverage summary info for a function, after executing the `InstrumentCoverage`
481     /// MIR pass (assuming the -Cinstrument-coverage option is enabled).
482     query coverageinfo(key: ty::InstanceDef<'tcx>) -> mir::CoverageInfo {
483         desc { |tcx| "retrieving coverage info from MIR for `{}`", tcx.def_path_str(key.def_id()) }
484         arena_cache
485     }
486
487     /// Returns the `CodeRegions` for a function that has instrumented coverage, in case the
488     /// function was optimized out before codegen, and before being added to the Coverage Map.
489     query covered_code_regions(key: DefId) -> Vec<&'tcx mir::coverage::CodeRegion> {
490         desc {
491             |tcx| "retrieving the covered `CodeRegion`s, if instrumented, for `{}`",
492             tcx.def_path_str(key)
493         }
494         arena_cache
495         cache_on_disk_if { key.is_local() }
496     }
497
498     /// The `DefId` is the `DefId` of the containing MIR body. Promoteds do not have their own
499     /// `DefId`. This function returns all promoteds in the specified body. The body references
500     /// promoteds by the `DefId` and the `mir::Promoted` index. This is necessary, because
501     /// after inlining a body may refer to promoteds from other bodies. In that case you still
502     /// need to use the `DefId` of the original body.
503     query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
504         desc { |tcx| "optimizing promoted MIR for `{}`", tcx.def_path_str(key) }
505         cache_on_disk_if { key.is_local() }
506         separate_provide_extern
507     }
508     query promoted_mir_of_const_arg(
509         key: (LocalDefId, DefId)
510     ) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
511         desc {
512             |tcx| "optimizing promoted MIR for the const argument `{}`",
513             tcx.def_path_str(key.0.to_def_id()),
514         }
515     }
516
517     /// Erases regions from `ty` to yield a new type.
518     /// Normally you would just use `tcx.erase_regions(value)`,
519     /// however, which uses this query as a kind of cache.
520     query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
521         // This query is not expected to have input -- as a result, it
522         // is not a good candidates for "replay" because it is essentially a
523         // pure function of its input (and hence the expectation is that
524         // no caller would be green **apart** from just these
525         // queries). Making it anonymous avoids hashing the result, which
526         // may save a bit of time.
527         anon
528         desc { "erasing regions from `{}`", ty }
529     }
530
531     query wasm_import_module_map(_: CrateNum) -> FxHashMap<DefId, String> {
532         arena_cache
533         desc { "getting wasm import module map" }
534     }
535
536     /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
537     /// predicates (where-clauses) directly defined on it. This is
538     /// equal to the `explicit_predicates_of` predicates plus the
539     /// `inferred_outlives_of` predicates.
540     query predicates_defined_on(key: DefId) -> ty::GenericPredicates<'tcx> {
541         desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
542     }
543
544     /// Returns everything that looks like a predicate written explicitly
545     /// by the user on a trait item.
546     ///
547     /// Traits are unusual, because predicates on associated types are
548     /// converted into bounds on that type for backwards compatibility:
549     ///
550     /// trait X where Self::U: Copy { type U; }
551     ///
552     /// becomes
553     ///
554     /// trait X { type U: Copy; }
555     ///
556     /// `explicit_predicates_of` and `explicit_item_bounds` will then take
557     /// the appropriate subsets of the predicates here.
558     query trait_explicit_predicates_and_bounds(key: LocalDefId) -> ty::GenericPredicates<'tcx> {
559         desc { |tcx| "computing explicit predicates of trait `{}`", tcx.def_path_str(key.to_def_id()) }
560     }
561
562     /// Returns the predicates written explicitly by the user.
563     query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
564         desc { |tcx| "computing explicit predicates of `{}`", tcx.def_path_str(key) }
565         cache_on_disk_if { key.is_local() }
566         separate_provide_extern
567     }
568
569     /// Returns the inferred outlives predicates (e.g., for `struct
570     /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
571     query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
572         desc { |tcx| "computing inferred outlives predicates of `{}`", tcx.def_path_str(key) }
573         cache_on_disk_if { key.is_local() }
574         separate_provide_extern
575     }
576
577     /// Maps from the `DefId` of a trait to the list of
578     /// super-predicates. This is a subset of the full list of
579     /// predicates. We store these in a separate map because we must
580     /// evaluate them even during type conversion, often before the
581     /// full predicates are available (note that supertraits have
582     /// additional acyclicity requirements).
583     query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
584         desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) }
585         cache_on_disk_if { key.is_local() }
586         separate_provide_extern
587     }
588
589     /// The `Option<Ident>` is the name of an associated type. If it is `None`, then this query
590     /// returns the full set of predicates. If `Some<Ident>`, then the query returns only the
591     /// subset of super-predicates that reference traits that define the given associated type.
592     /// This is used to avoid cycles in resolving types like `T::Item`.
593     query super_predicates_that_define_assoc_type(key: (DefId, Option<rustc_span::symbol::Ident>)) -> ty::GenericPredicates<'tcx> {
594         desc { |tcx| "computing the super traits of `{}`{}",
595             tcx.def_path_str(key.0),
596             if let Some(assoc_name) = key.1 { format!(" with associated type name `{}`", assoc_name) } else { "".to_string() },
597         }
598     }
599
600     /// To avoid cycles within the predicates of a single item we compute
601     /// per-type-parameter predicates for resolving `T::AssocTy`.
602     query type_param_predicates(key: (DefId, LocalDefId, rustc_span::symbol::Ident)) -> ty::GenericPredicates<'tcx> {
603         desc { |tcx| "computing the bounds for type parameter `{}`", tcx.hir().ty_param_name(key.1) }
604     }
605
606     query trait_def(key: DefId) -> ty::TraitDef {
607         desc { |tcx| "computing trait definition for `{}`", tcx.def_path_str(key) }
608         arena_cache
609         cache_on_disk_if { key.is_local() }
610         separate_provide_extern
611     }
612     query adt_def(key: DefId) -> ty::AdtDef<'tcx> {
613         desc { |tcx| "computing ADT definition for `{}`", tcx.def_path_str(key) }
614         cache_on_disk_if { key.is_local() }
615         separate_provide_extern
616     }
617     query adt_destructor(key: DefId) -> Option<ty::Destructor> {
618         desc { |tcx| "computing `Drop` impl for `{}`", tcx.def_path_str(key) }
619         cache_on_disk_if { key.is_local() }
620         separate_provide_extern
621     }
622
623     query adt_sized_constraint(key: DefId) -> &'tcx [Ty<'tcx>] {
624         desc { |tcx| "computing `Sized` constraints for `{}`", tcx.def_path_str(key) }
625     }
626
627     query adt_dtorck_constraint(
628         key: DefId
629     ) -> Result<&'tcx DropckConstraint<'tcx>, NoSolution> {
630         desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) }
631     }
632
633     /// Returns `true` if this is a const fn, use the `is_const_fn` to know whether your crate
634     /// actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might
635     /// not have the feature gate active).
636     ///
637     /// **Do not call this function manually.** It is only meant to cache the base data for the
638     /// `is_const_fn` function. Consider using `is_const_fn` or `is_const_fn_raw` instead.
639     query constness(key: DefId) -> hir::Constness {
640         desc { |tcx| "checking if item is const: `{}`", tcx.def_path_str(key) }
641         cache_on_disk_if { key.is_local() }
642         separate_provide_extern
643     }
644
645     query asyncness(key: DefId) -> hir::IsAsync {
646         desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
647         cache_on_disk_if { key.is_local() }
648         separate_provide_extern
649     }
650
651     /// Returns `true` if calls to the function may be promoted.
652     ///
653     /// This is either because the function is e.g., a tuple-struct or tuple-variant
654     /// constructor, or because it has the `#[rustc_promotable]` attribute. The attribute should
655     /// be removed in the future in favour of some form of check which figures out whether the
656     /// function does not inspect the bits of any of its arguments (so is essentially just a
657     /// constructor function).
658     query is_promotable_const_fn(key: DefId) -> bool {
659         desc { |tcx| "checking if item is promotable: `{}`", tcx.def_path_str(key) }
660     }
661
662     /// Returns `true` if this is a foreign item (i.e., linked via `extern { ... }`).
663     query is_foreign_item(key: DefId) -> bool {
664         desc { |tcx| "checking if `{}` is a foreign item", tcx.def_path_str(key) }
665         cache_on_disk_if { key.is_local() }
666         separate_provide_extern
667     }
668
669     /// Returns `Some(generator_kind)` if the node pointed to by `def_id` is a generator.
670     query generator_kind(def_id: DefId) -> Option<hir::GeneratorKind> {
671         desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) }
672         cache_on_disk_if { def_id.is_local() }
673         separate_provide_extern
674     }
675
676     /// Gets a map with the variance of every item; use `item_variance` instead.
677     query crate_variances(_: ()) -> ty::CrateVariancesMap<'tcx> {
678         arena_cache
679         desc { "computing the variances for items in this crate" }
680     }
681
682     /// Maps from the `DefId` of a type or region parameter to its (inferred) variance.
683     query variances_of(def_id: DefId) -> &'tcx [ty::Variance] {
684         desc { |tcx| "computing the variances of `{}`", tcx.def_path_str(def_id) }
685         cache_on_disk_if { def_id.is_local() }
686         separate_provide_extern
687     }
688
689     /// Maps from thee `DefId` of a type to its (inferred) outlives.
690     query inferred_outlives_crate(_: ()) -> ty::CratePredicatesMap<'tcx> {
691         arena_cache
692         desc { "computing the inferred outlives predicates for items in this crate" }
693     }
694
695     /// Maps from an impl/trait `DefId` to a list of the `DefId`s of its items.
696     query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
697         desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
698         cache_on_disk_if { key.is_local() }
699         separate_provide_extern
700     }
701
702     /// Maps from a trait item to the trait item "descriptor".
703     query associated_item(key: DefId) -> ty::AssocItem {
704         desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) }
705         arena_cache
706         cache_on_disk_if { key.is_local() }
707         separate_provide_extern
708     }
709
710     /// Collects the associated items defined on a trait or impl.
711     query associated_items(key: DefId) -> ty::AssocItems<'tcx> {
712         arena_cache
713         desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
714     }
715
716     /// Maps from associated items on a trait to the corresponding associated
717     /// item on the impl specified by `impl_id`.
718     ///
719     /// For example, with the following code
720     ///
721     /// ```
722     /// struct Type {}
723     ///                         // DefId
724     /// trait Trait {           // trait_id
725     ///     fn f();             // trait_f
726     ///     fn g() {}           // trait_g
727     /// }
728     ///
729     /// impl Trait for Type {   // impl_id
730     ///     fn f() {}           // impl_f
731     ///     fn g() {}           // impl_g
732     /// }
733     /// ```
734     ///
735     /// The map returned for `tcx.impl_item_implementor_ids(impl_id)` would be
736     ///`{ trait_f: impl_f, trait_g: impl_g }`
737     query impl_item_implementor_ids(impl_id: DefId) -> FxHashMap<DefId, DefId> {
738         arena_cache
739         desc { |tcx| "comparing impl items against trait for `{}`", tcx.def_path_str(impl_id) }
740     }
741
742     /// Given an `impl_id`, return the trait it implements.
743     /// Return `None` if this is an inherent impl.
744     query impl_trait_ref(impl_id: DefId) -> Option<ty::TraitRef<'tcx>> {
745         desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
746         cache_on_disk_if { impl_id.is_local() }
747         separate_provide_extern
748     }
749     query impl_polarity(impl_id: DefId) -> ty::ImplPolarity {
750         desc { |tcx| "computing implementation polarity of `{}`", tcx.def_path_str(impl_id) }
751         cache_on_disk_if { impl_id.is_local() }
752         separate_provide_extern
753     }
754
755     query issue33140_self_ty(key: DefId) -> Option<ty::Ty<'tcx>> {
756         desc { |tcx| "computing Self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
757     }
758
759     /// Maps a `DefId` of a type to a list of its inherent impls.
760     /// Contains implementations of methods that are inherent to a type.
761     /// Methods in these implementations don't need to be exported.
762     query inherent_impls(key: DefId) -> &'tcx [DefId] {
763         desc { |tcx| "collecting inherent impls for `{}`", tcx.def_path_str(key) }
764         cache_on_disk_if { key.is_local() }
765         separate_provide_extern
766     }
767
768     query incoherent_impls(key: SimplifiedType) -> &'tcx [DefId] {
769         desc { |tcx| "collecting all inherent impls for `{:?}`", key }
770     }
771
772     /// The result of unsafety-checking this `LocalDefId`.
773     query unsafety_check_result(key: LocalDefId) -> &'tcx mir::UnsafetyCheckResult {
774         desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
775         cache_on_disk_if { true }
776     }
777     query unsafety_check_result_for_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::UnsafetyCheckResult {
778         desc {
779             |tcx| "unsafety-checking the const argument `{}`",
780             tcx.def_path_str(key.0.to_def_id())
781         }
782     }
783
784     /// Unsafety-check this `LocalDefId` with THIR unsafeck. This should be
785     /// used with `-Zthir-unsafeck`.
786     query thir_check_unsafety(key: LocalDefId) {
787         desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) }
788         cache_on_disk_if { true }
789     }
790     query thir_check_unsafety_for_const_arg(key: (LocalDefId, DefId)) {
791         desc {
792             |tcx| "unsafety-checking the const argument `{}`",
793             tcx.def_path_str(key.0.to_def_id())
794         }
795     }
796
797     /// HACK: when evaluated, this reports an "unsafe derive on repr(packed)" error.
798     ///
799     /// Unsafety checking is executed for each method separately, but we only want
800     /// to emit this error once per derive. As there are some impls with multiple
801     /// methods, we use a query for deduplication.
802     query unsafe_derive_on_repr_packed(key: LocalDefId) -> () {
803         desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
804     }
805
806     /// Returns the types assumed to be well formed while "inside" of the given item.
807     ///
808     /// Note that we've liberated the late bound regions of function signatures, so
809     /// this can not be used to check whether these types are well formed.
810     query assumed_wf_types(key: DefId) -> &'tcx ty::List<Ty<'tcx>> {
811         desc { |tcx| "computing the implied bounds of `{}`", tcx.def_path_str(key) }
812     }
813
814     /// Computes the signature of the function.
815     query fn_sig(key: DefId) -> ty::PolyFnSig<'tcx> {
816         desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) }
817         cache_on_disk_if { key.is_local() }
818         separate_provide_extern
819         cycle_delay_bug
820     }
821
822     /// Performs lint checking for the module.
823     query lint_mod(key: LocalDefId) -> () {
824         desc { |tcx| "linting {}", describe_as_module(key, tcx) }
825     }
826
827     /// Checks the attributes in the module.
828     query check_mod_attrs(key: LocalDefId) -> () {
829         desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
830     }
831
832     /// Checks for uses of unstable APIs in the module.
833     query check_mod_unstable_api_usage(key: LocalDefId) -> () {
834         desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
835     }
836
837     /// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`).
838     query check_mod_const_bodies(key: LocalDefId) -> () {
839         desc { |tcx| "checking consts in {}", describe_as_module(key, tcx) }
840     }
841
842     /// Checks the loops in the module.
843     query check_mod_loops(key: LocalDefId) -> () {
844         desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) }
845     }
846
847     query check_mod_naked_functions(key: LocalDefId) -> () {
848         desc { |tcx| "checking naked functions in {}", describe_as_module(key, tcx) }
849     }
850
851     query check_mod_item_types(key: LocalDefId) -> () {
852         desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) }
853     }
854
855     query check_mod_privacy(key: LocalDefId) -> () {
856         desc { |tcx| "checking privacy in {}", describe_as_module(key, tcx) }
857     }
858
859     query check_liveness(key: DefId) {
860         desc { |tcx| "checking liveness of variables in `{}`", tcx.def_path_str(key) }
861     }
862
863     /// Return the live symbols in the crate for dead code check.
864     ///
865     /// The second return value maps from ADTs to ignored derived traits (e.g. Debug and Clone) and
866     /// their respective impl (i.e., part of the derive macro)
867     query live_symbols_and_ignored_derived_traits(_: ()) -> (
868         FxHashSet<LocalDefId>,
869         FxHashMap<LocalDefId, Vec<(DefId, DefId)>>
870     ) {
871         arena_cache
872         desc { "finding live symbols in crate" }
873     }
874
875     query check_mod_deathness(key: LocalDefId) -> () {
876         desc { |tcx| "checking deathness of variables in {}", describe_as_module(key, tcx) }
877     }
878
879     query check_mod_impl_wf(key: LocalDefId) -> () {
880         desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
881     }
882
883     query check_mod_type_wf(key: LocalDefId) -> () {
884         desc { |tcx| "checking that types are well-formed in {}", describe_as_module(key, tcx) }
885     }
886
887     query collect_mod_item_types(key: LocalDefId) -> () {
888         desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) }
889     }
890
891     /// Caches `CoerceUnsized` kinds for impls on custom types.
892     query coerce_unsized_info(key: DefId) -> ty::adjustment::CoerceUnsizedInfo {
893         desc { |tcx| "computing CoerceUnsized info for `{}`", tcx.def_path_str(key) }
894         cache_on_disk_if { key.is_local() }
895         separate_provide_extern
896     }
897
898     query typeck_item_bodies(_: ()) -> () {
899         desc { "type-checking all item bodies" }
900     }
901
902     query typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
903         desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
904         cache_on_disk_if { true }
905     }
906     query typeck_const_arg(
907         key: (LocalDefId, DefId)
908     ) -> &'tcx ty::TypeckResults<'tcx> {
909         desc {
910             |tcx| "type-checking the const argument `{}`",
911             tcx.def_path_str(key.0.to_def_id()),
912         }
913     }
914     query diagnostic_only_typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
915         desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
916         cache_on_disk_if { true }
917     }
918
919     query used_trait_imports(key: LocalDefId) -> &'tcx UnordSet<LocalDefId> {
920         desc { |tcx| "finding used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) }
921         cache_on_disk_if { true }
922     }
923
924     query has_typeck_results(def_id: DefId) -> bool {
925         desc { |tcx| "checking whether `{}` has a body", tcx.def_path_str(def_id) }
926     }
927
928     query coherent_trait(def_id: DefId) -> () {
929         desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
930     }
931
932     /// Borrow-checks the function body. If this is a closure, returns
933     /// additional requirements that the closure's creator must verify.
934     query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
935         desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
936         cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) }
937     }
938     query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> {
939         desc {
940             |tcx| "borrow-checking the const argument`{}`",
941             tcx.def_path_str(key.0.to_def_id())
942         }
943     }
944
945     /// Gets a complete map from all types to their inherent impls.
946     /// Not meant to be used directly outside of coherence.
947     query crate_inherent_impls(k: ()) -> CrateInherentImpls {
948         arena_cache
949         desc { "finding all inherent impls defined in crate" }
950     }
951
952     /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
953     /// Not meant to be used directly outside of coherence.
954     query crate_inherent_impls_overlap_check(_: ()) -> () {
955         desc { "check for overlap between inherent impls defined in this crate" }
956     }
957
958     /// Checks whether all impls in the crate pass the overlap check, returning
959     /// which impls fail it. If all impls are correct, the returned slice is empty.
960     query orphan_check_impl(key: LocalDefId) -> Result<(), ErrorGuaranteed> {
961         desc { |tcx|
962             "checking whether impl `{}` follows the orphan rules",
963             tcx.def_path_str(key.to_def_id()),
964         }
965     }
966
967     /// Check whether the function has any recursion that could cause the inliner to trigger
968     /// a cycle. Returns the call stack causing the cycle. The call stack does not contain the
969     /// current function, just all intermediate functions.
970     query mir_callgraph_reachable(key: (ty::Instance<'tcx>, LocalDefId)) -> bool {
971         fatal_cycle
972         desc { |tcx|
973             "computing if `{}` (transitively) calls `{}`",
974             key.0,
975             tcx.def_path_str(key.1.to_def_id()),
976         }
977     }
978
979     /// Obtain all the calls into other local functions
980     query mir_inliner_callees(key: ty::InstanceDef<'tcx>) -> &'tcx [(DefId, SubstsRef<'tcx>)] {
981         fatal_cycle
982         desc { |tcx|
983             "computing all local function calls in `{}`",
984             tcx.def_path_str(key.def_id()),
985         }
986     }
987
988     /// Evaluates a constant and returns the computed allocation.
989     ///
990     /// **Do not use this** directly, use the `tcx.eval_static_initializer` wrapper.
991     query eval_to_allocation_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
992         -> EvalToAllocationRawResult<'tcx> {
993         desc { |tcx|
994             "const-evaluating + checking `{}`",
995             key.value.display(tcx)
996         }
997         cache_on_disk_if { true }
998     }
999
1000     /// Evaluates const items or anonymous constants
1001     /// (such as enum variant explicit discriminants or array lengths)
1002     /// into a representation suitable for the type system and const generics.
1003     ///
1004     /// **Do not use this** directly, use one of the following wrappers: `tcx.const_eval_poly`,
1005     /// `tcx.const_eval_resolve`, `tcx.const_eval_instance`, or `tcx.const_eval_global_id`.
1006     query eval_to_const_value_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
1007         -> EvalToConstValueResult<'tcx> {
1008         desc { |tcx|
1009             "simplifying constant for the type system `{}`",
1010             key.value.display(tcx)
1011         }
1012         cache_on_disk_if { true }
1013     }
1014
1015     /// Evaluate a constant and convert it to a type level constant or
1016     /// return `None` if that is not possible.
1017     query eval_to_valtree(
1018         key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>
1019     ) -> EvalToValTreeResult<'tcx> {
1020         desc { "evaluating type-level constant" }
1021     }
1022
1023     /// Converts a type level constant value into `ConstValue`
1024     query valtree_to_const_val(key: (Ty<'tcx>, ty::ValTree<'tcx>)) -> ConstValue<'tcx> {
1025         desc { "converting type-level constant value to mir constant value"}
1026     }
1027
1028     /// Destructures array, ADT or tuple constants into the constants
1029     /// of their fields.
1030     query destructure_const(key: ty::Const<'tcx>) -> ty::DestructuredConst<'tcx> {
1031         desc { "destructuring type level constant"}
1032     }
1033
1034     /// Tries to destructure an `mir::ConstantKind` ADT or array into its variant index
1035     /// and its field values.
1036     query try_destructure_mir_constant(
1037         key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1038     ) -> Option<mir::DestructuredConstant<'tcx>> {
1039         desc { "destructuring MIR constant"}
1040         remap_env_constness
1041     }
1042
1043     /// Dereference a constant reference or raw pointer and turn the result into a constant
1044     /// again.
1045     query deref_mir_constant(
1046         key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1047     ) -> mir::ConstantKind<'tcx> {
1048         desc { "dereferencing MIR constant" }
1049         remap_env_constness
1050     }
1051
1052     query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> ConstValue<'tcx> {
1053         desc { "getting a &core::panic::Location referring to a span" }
1054     }
1055
1056     // FIXME get rid of this with valtrees
1057     query lit_to_const(
1058         key: LitToConstInput<'tcx>
1059     ) -> Result<ty::Const<'tcx>, LitToConstError> {
1060         desc { "converting literal to const" }
1061     }
1062
1063     query lit_to_mir_constant(key: LitToConstInput<'tcx>) -> Result<mir::ConstantKind<'tcx>, LitToConstError> {
1064         desc { "converting literal to mir constant" }
1065     }
1066
1067     query check_match(key: DefId) {
1068         desc { |tcx| "match-checking `{}`", tcx.def_path_str(key) }
1069         cache_on_disk_if { key.is_local() }
1070     }
1071
1072     /// Performs part of the privacy check and computes effective visibilities.
1073     query effective_visibilities(_: ()) -> &'tcx EffectiveVisibilities {
1074         eval_always
1075         desc { "checking effective visibilities" }
1076     }
1077     query check_private_in_public(_: ()) -> () {
1078         eval_always
1079         desc { "checking for private elements in public interfaces" }
1080     }
1081
1082     query reachable_set(_: ()) -> FxHashSet<LocalDefId> {
1083         arena_cache
1084         desc { "reachability" }
1085     }
1086
1087     /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
1088     /// in the case of closures, this will be redirected to the enclosing function.
1089     query region_scope_tree(def_id: DefId) -> &'tcx crate::middle::region::ScopeTree {
1090         desc { |tcx| "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
1091     }
1092
1093     /// Generates a MIR body for the shim.
1094     query mir_shims(key: ty::InstanceDef<'tcx>) -> mir::Body<'tcx> {
1095         arena_cache
1096         desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
1097     }
1098
1099     /// The `symbol_name` query provides the symbol name for calling a
1100     /// given instance from the local crate. In particular, it will also
1101     /// look up the correct symbol name of instances from upstream crates.
1102     query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName<'tcx> {
1103         desc { "computing the symbol for `{}`", key }
1104         cache_on_disk_if { true }
1105     }
1106
1107     query opt_def_kind(def_id: DefId) -> Option<DefKind> {
1108         desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
1109         cache_on_disk_if { def_id.is_local() }
1110         separate_provide_extern
1111     }
1112
1113     /// Gets the span for the definition.
1114     query def_span(def_id: DefId) -> Span {
1115         desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }
1116         cache_on_disk_if { def_id.is_local() }
1117         separate_provide_extern
1118     }
1119
1120     /// Gets the span for the identifier of the definition.
1121     query def_ident_span(def_id: DefId) -> Option<Span> {
1122         desc { |tcx| "looking up span for `{}`'s identifier", tcx.def_path_str(def_id) }
1123         cache_on_disk_if { def_id.is_local() }
1124         separate_provide_extern
1125     }
1126
1127     query lookup_stability(def_id: DefId) -> Option<attr::Stability> {
1128         desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
1129         cache_on_disk_if { def_id.is_local() }
1130         separate_provide_extern
1131     }
1132
1133     query lookup_const_stability(def_id: DefId) -> Option<attr::ConstStability> {
1134         desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
1135         cache_on_disk_if { def_id.is_local() }
1136         separate_provide_extern
1137     }
1138
1139     query lookup_default_body_stability(def_id: DefId) -> Option<attr::DefaultBodyStability> {
1140         desc { |tcx| "looking up default body stability of `{}`", tcx.def_path_str(def_id) }
1141         separate_provide_extern
1142     }
1143
1144     query should_inherit_track_caller(def_id: DefId) -> bool {
1145         desc { |tcx| "computing should_inherit_track_caller of `{}`", tcx.def_path_str(def_id) }
1146     }
1147
1148     query lookup_deprecation_entry(def_id: DefId) -> Option<DeprecationEntry> {
1149         desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) }
1150         cache_on_disk_if { def_id.is_local() }
1151         separate_provide_extern
1152     }
1153
1154     /// Determines whether an item is annotated with `doc(hidden)`.
1155     query is_doc_hidden(def_id: DefId) -> bool {
1156         desc { |tcx| "checking whether `{}` is `doc(hidden)`", tcx.def_path_str(def_id) }
1157     }
1158
1159     /// Determines whether an item is annotated with `doc(notable_trait)`.
1160     query is_doc_notable_trait(def_id: DefId) -> bool {
1161         desc { |tcx| "checking whether `{}` is `doc(notable_trait)`", tcx.def_path_str(def_id) }
1162     }
1163
1164     /// Returns the attributes on the item at `def_id`.
1165     ///
1166     /// Do not use this directly, use `tcx.get_attrs` instead.
1167     query item_attrs(def_id: DefId) -> &'tcx [ast::Attribute] {
1168         desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
1169         separate_provide_extern
1170     }
1171
1172     query codegen_fn_attrs(def_id: DefId) -> CodegenFnAttrs {
1173         desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) }
1174         arena_cache
1175         cache_on_disk_if { def_id.is_local() }
1176         separate_provide_extern
1177     }
1178
1179     query asm_target_features(def_id: DefId) -> &'tcx FxHashSet<Symbol> {
1180         desc { |tcx| "computing target features for inline asm of `{}`", tcx.def_path_str(def_id) }
1181     }
1182
1183     query fn_arg_names(def_id: DefId) -> &'tcx [rustc_span::symbol::Ident] {
1184         desc { |tcx| "looking up function parameter names for `{}`", tcx.def_path_str(def_id) }
1185         cache_on_disk_if { def_id.is_local() }
1186         separate_provide_extern
1187     }
1188     /// Gets the rendered value of the specified constant or associated constant.
1189     /// Used by rustdoc.
1190     query rendered_const(def_id: DefId) -> String {
1191         arena_cache
1192         desc { |tcx| "rendering constant initializer of `{}`", tcx.def_path_str(def_id) }
1193         cache_on_disk_if { def_id.is_local() }
1194         separate_provide_extern
1195     }
1196     query impl_parent(def_id: DefId) -> Option<DefId> {
1197         desc { |tcx| "computing specialization parent impl of `{}`", tcx.def_path_str(def_id) }
1198         cache_on_disk_if { def_id.is_local() }
1199         separate_provide_extern
1200     }
1201
1202     query is_ctfe_mir_available(key: DefId) -> bool {
1203         desc { |tcx| "checking if item has CTFE MIR available: `{}`", tcx.def_path_str(key) }
1204         cache_on_disk_if { key.is_local() }
1205         separate_provide_extern
1206     }
1207     query is_mir_available(key: DefId) -> bool {
1208         desc { |tcx| "checking if item has MIR available: `{}`", tcx.def_path_str(key) }
1209         cache_on_disk_if { key.is_local() }
1210         separate_provide_extern
1211     }
1212
1213     query own_existential_vtable_entries(
1214         key: DefId
1215     ) -> &'tcx [DefId] {
1216         desc { |tcx| "finding all existential vtable entries for trait `{}`", tcx.def_path_str(key) }
1217     }
1218
1219     query vtable_entries(key: ty::PolyTraitRef<'tcx>)
1220                         -> &'tcx [ty::VtblEntry<'tcx>] {
1221         desc { |tcx| "finding all vtable entries for trait `{}`", tcx.def_path_str(key.def_id()) }
1222     }
1223
1224     query vtable_trait_upcasting_coercion_new_vptr_slot(key: (Ty<'tcx>, Ty<'tcx>)) -> Option<usize> {
1225         desc { |tcx| "finding the slot within vtable for trait object `{}` vtable ptr during trait upcasting coercion from `{}` vtable",
1226             key.1, key.0 }
1227     }
1228
1229     query vtable_allocation(key: (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>)) -> mir::interpret::AllocId {
1230         desc { |tcx| "vtable const allocation for <{} as {}>",
1231             key.0,
1232             key.1.map(|trait_ref| format!("{}", trait_ref)).unwrap_or("_".to_owned())
1233         }
1234     }
1235
1236     query codegen_select_candidate(
1237         key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)
1238     ) -> Result<&'tcx ImplSource<'tcx, ()>, traits::CodegenObligationError> {
1239         cache_on_disk_if { true }
1240         desc { |tcx| "computing candidate for `{}`", key.1 }
1241     }
1242
1243     /// Return all `impl` blocks in the current crate.
1244     query all_local_trait_impls(_: ()) -> &'tcx rustc_data_structures::fx::FxIndexMap<DefId, Vec<LocalDefId>> {
1245         desc { "finding local trait impls" }
1246     }
1247
1248     /// Given a trait `trait_id`, return all known `impl` blocks.
1249     query trait_impls_of(trait_id: DefId) -> ty::trait_def::TraitImpls {
1250         arena_cache
1251         desc { |tcx| "finding trait impls of `{}`", tcx.def_path_str(trait_id) }
1252     }
1253
1254     query specialization_graph_of(trait_id: DefId) -> specialization_graph::Graph {
1255         arena_cache
1256         desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
1257         cache_on_disk_if { true }
1258     }
1259     query object_safety_violations(trait_id: DefId) -> &'tcx [traits::ObjectSafetyViolation] {
1260         desc { |tcx| "determining object safety of trait `{}`", tcx.def_path_str(trait_id) }
1261     }
1262
1263     /// Gets the ParameterEnvironment for a given item; this environment
1264     /// will be in "user-facing" mode, meaning that it is suitable for
1265     /// type-checking etc, and it does not normalize specializable
1266     /// associated types. This is almost always what you want,
1267     /// unless you are doing MIR optimizations, in which case you
1268     /// might want to use `reveal_all()` method to change modes.
1269     query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
1270         desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
1271     }
1272
1273     /// Like `param_env`, but returns the `ParamEnv` in `Reveal::All` mode.
1274     /// Prefer this over `tcx.param_env(def_id).with_reveal_all_normalized(tcx)`,
1275     /// as this method is more efficient.
1276     query param_env_reveal_all_normalized(def_id: DefId) -> ty::ParamEnv<'tcx> {
1277         desc { |tcx| "computing revealed normalized predicates of `{}`", tcx.def_path_str(def_id) }
1278     }
1279
1280     /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
1281     /// `ty.is_copy()`, etc, since that will prune the environment where possible.
1282     query is_copy_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1283         desc { "computing whether `{}` is `Copy`", env.value }
1284         remap_env_constness
1285     }
1286     /// Query backing `Ty::is_sized`.
1287     query is_sized_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1288         desc { "computing whether `{}` is `Sized`", env.value }
1289         remap_env_constness
1290     }
1291     /// Query backing `Ty::is_freeze`.
1292     query is_freeze_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1293         desc { "computing whether `{}` is freeze", env.value }
1294         remap_env_constness
1295     }
1296     /// Query backing `Ty::is_unpin`.
1297     query is_unpin_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1298         desc { "computing whether `{}` is `Unpin`", env.value }
1299         remap_env_constness
1300     }
1301     /// Query backing `Ty::needs_drop`.
1302     query needs_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1303         desc { "computing whether `{}` needs drop", env.value }
1304         remap_env_constness
1305     }
1306     /// Query backing `Ty::has_significant_drop_raw`.
1307     query has_significant_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1308         desc { "computing whether `{}` has a significant drop", env.value }
1309         remap_env_constness
1310     }
1311
1312     /// Query backing `Ty::is_structural_eq_shallow`.
1313     ///
1314     /// This is only correct for ADTs. Call `is_structural_eq_shallow` to handle all types
1315     /// correctly.
1316     query has_structural_eq_impls(ty: Ty<'tcx>) -> bool {
1317         desc {
1318             "computing whether `{}` implements `PartialStructuralEq` and `StructuralEq`",
1319             ty
1320         }
1321     }
1322
1323     /// A list of types where the ADT requires drop if and only if any of
1324     /// those types require drop. If the ADT is known to always need drop
1325     /// then `Err(AlwaysRequiresDrop)` is returned.
1326     query adt_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1327         desc { |tcx| "computing when `{}` needs drop", tcx.def_path_str(def_id) }
1328         cache_on_disk_if { true }
1329     }
1330
1331     /// A list of types where the ADT requires drop if and only if any of those types
1332     /// has significant drop. A type marked with the attribute `rustc_insignificant_dtor`
1333     /// is considered to not be significant. A drop is significant if it is implemented
1334     /// by the user or does anything that will have any observable behavior (other than
1335     /// freeing up memory). If the ADT is known to have a significant destructor then
1336     /// `Err(AlwaysRequiresDrop)` is returned.
1337     query adt_significant_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1338         desc { |tcx| "computing when `{}` has a significant destructor", tcx.def_path_str(def_id) }
1339         cache_on_disk_if { false }
1340     }
1341
1342     /// Computes the layout of a type. Note that this implicitly
1343     /// executes in "reveal all" mode, and will normalize the input type.
1344     query layout_of(
1345         key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1346     ) -> Result<ty::layout::TyAndLayout<'tcx>, ty::layout::LayoutError<'tcx>> {
1347         depth_limit
1348         desc { "computing layout of `{}`", key.value }
1349         remap_env_constness
1350     }
1351
1352     /// Compute a `FnAbi` suitable for indirect calls, i.e. to `fn` pointers.
1353     ///
1354     /// NB: this doesn't handle virtual calls - those should use `fn_abi_of_instance`
1355     /// instead, where the instance is an `InstanceDef::Virtual`.
1356     query fn_abi_of_fn_ptr(
1357         key: ty::ParamEnvAnd<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1358     ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1359         desc { "computing call ABI of `{}` function pointers", key.value.0 }
1360         remap_env_constness
1361     }
1362
1363     /// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for
1364     /// direct calls to an `fn`.
1365     ///
1366     /// NB: that includes virtual calls, which are represented by "direct calls"
1367     /// to an `InstanceDef::Virtual` instance (of `<dyn Trait as Trait>::fn`).
1368     query fn_abi_of_instance(
1369         key: ty::ParamEnvAnd<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1370     ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1371         desc { "computing call ABI of `{}`", key.value.0 }
1372         remap_env_constness
1373     }
1374
1375     query dylib_dependency_formats(_: CrateNum)
1376                                     -> &'tcx [(CrateNum, LinkagePreference)] {
1377         desc { "getting dylib dependency formats of crate" }
1378         separate_provide_extern
1379     }
1380
1381     query dependency_formats(_: ()) -> Lrc<crate::middle::dependency_format::Dependencies> {
1382         arena_cache
1383         desc { "getting the linkage format of all dependencies" }
1384     }
1385
1386     query is_compiler_builtins(_: CrateNum) -> bool {
1387         fatal_cycle
1388         desc { "checking if the crate is_compiler_builtins" }
1389         separate_provide_extern
1390     }
1391     query has_global_allocator(_: CrateNum) -> bool {
1392         // This query depends on untracked global state in CStore
1393         eval_always
1394         fatal_cycle
1395         desc { "checking if the crate has_global_allocator" }
1396         separate_provide_extern
1397     }
1398     query has_alloc_error_handler(_: CrateNum) -> bool {
1399         // This query depends on untracked global state in CStore
1400         eval_always
1401         fatal_cycle
1402         desc { "checking if the crate has_alloc_error_handler" }
1403         separate_provide_extern
1404     }
1405     query has_panic_handler(_: CrateNum) -> bool {
1406         fatal_cycle
1407         desc { "checking if the crate has_panic_handler" }
1408         separate_provide_extern
1409     }
1410     query is_profiler_runtime(_: CrateNum) -> bool {
1411         fatal_cycle
1412         desc { "checking if a crate is `#![profiler_runtime]`" }
1413         separate_provide_extern
1414     }
1415     query has_ffi_unwind_calls(key: LocalDefId) -> bool {
1416         desc { |tcx| "checking if `{}` contains FFI-unwind calls", tcx.def_path_str(key.to_def_id()) }
1417         cache_on_disk_if { true }
1418     }
1419     query required_panic_strategy(_: CrateNum) -> Option<PanicStrategy> {
1420         fatal_cycle
1421         desc { "getting a crate's required panic strategy" }
1422         separate_provide_extern
1423     }
1424     query panic_in_drop_strategy(_: CrateNum) -> PanicStrategy {
1425         fatal_cycle
1426         desc { "getting a crate's configured panic-in-drop strategy" }
1427         separate_provide_extern
1428     }
1429     query is_no_builtins(_: CrateNum) -> bool {
1430         fatal_cycle
1431         desc { "getting whether a crate has `#![no_builtins]`" }
1432         separate_provide_extern
1433     }
1434     query symbol_mangling_version(_: CrateNum) -> SymbolManglingVersion {
1435         fatal_cycle
1436         desc { "getting a crate's symbol mangling version" }
1437         separate_provide_extern
1438     }
1439
1440     query extern_crate(def_id: DefId) -> Option<&'tcx ExternCrate> {
1441         eval_always
1442         desc { "getting crate's ExternCrateData" }
1443         separate_provide_extern
1444     }
1445
1446     query specializes(_: (DefId, DefId)) -> bool {
1447         desc { "computing whether impls specialize one another" }
1448     }
1449     query in_scope_traits_map(_: hir::OwnerId)
1450         -> Option<&'tcx FxHashMap<ItemLocalId, Box<[TraitCandidate]>>> {
1451         desc { "getting traits in scope at a block" }
1452     }
1453
1454     query module_reexports(def_id: LocalDefId) -> Option<&'tcx [ModChild]> {
1455         desc { |tcx| "looking up reexports of module `{}`", tcx.def_path_str(def_id.to_def_id()) }
1456     }
1457
1458     query impl_defaultness(def_id: DefId) -> hir::Defaultness {
1459         desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
1460         cache_on_disk_if { def_id.is_local() }
1461         separate_provide_extern
1462     }
1463
1464     query check_well_formed(key: hir::OwnerId) -> () {
1465         desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1466     }
1467
1468     // The `DefId`s of all non-generic functions and statics in the given crate
1469     // that can be reached from outside the crate.
1470     //
1471     // We expect this items to be available for being linked to.
1472     //
1473     // This query can also be called for `LOCAL_CRATE`. In this case it will
1474     // compute which items will be reachable to other crates, taking into account
1475     // the kind of crate that is currently compiled. Crates with only a
1476     // C interface have fewer reachable things.
1477     //
1478     // Does not include external symbols that don't have a corresponding DefId,
1479     // like the compiler-generated `main` function and so on.
1480     query reachable_non_generics(_: CrateNum)
1481         -> DefIdMap<SymbolExportInfo> {
1482         arena_cache
1483         desc { "looking up the exported symbols of a crate" }
1484         separate_provide_extern
1485     }
1486     query is_reachable_non_generic(def_id: DefId) -> bool {
1487         desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
1488         cache_on_disk_if { def_id.is_local() }
1489         separate_provide_extern
1490     }
1491     query is_unreachable_local_definition(def_id: LocalDefId) -> bool {
1492         desc { |tcx|
1493             "checking whether `{}` is reachable from outside the crate",
1494             tcx.def_path_str(def_id.to_def_id()),
1495         }
1496     }
1497
1498     /// The entire set of monomorphizations the local crate can safely link
1499     /// to because they are exported from upstream crates. Do not depend on
1500     /// this directly, as its value changes anytime a monomorphization gets
1501     /// added or removed in any upstream crate. Instead use the narrower
1502     /// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even
1503     /// better, `Instance::upstream_monomorphization()`.
1504     query upstream_monomorphizations(_: ()) -> DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1505         arena_cache
1506         desc { "collecting available upstream monomorphizations" }
1507     }
1508
1509     /// Returns the set of upstream monomorphizations available for the
1510     /// generic function identified by the given `def_id`. The query makes
1511     /// sure to make a stable selection if the same monomorphization is
1512     /// available in multiple upstream crates.
1513     ///
1514     /// You likely want to call `Instance::upstream_monomorphization()`
1515     /// instead of invoking this query directly.
1516     query upstream_monomorphizations_for(def_id: DefId)
1517         -> Option<&'tcx FxHashMap<SubstsRef<'tcx>, CrateNum>>
1518     {
1519         arena_cache
1520         desc { |tcx|
1521             "collecting available upstream monomorphizations for `{}`",
1522             tcx.def_path_str(def_id),
1523         }
1524         separate_provide_extern
1525     }
1526
1527     /// Returns the upstream crate that exports drop-glue for the given
1528     /// type (`substs` is expected to be a single-item list containing the
1529     /// type one wants drop-glue for).
1530     ///
1531     /// This is a subset of `upstream_monomorphizations_for` in order to
1532     /// increase dep-tracking granularity. Otherwise adding or removing any
1533     /// type with drop-glue in any upstream crate would invalidate all
1534     /// functions calling drop-glue of an upstream type.
1535     ///
1536     /// You likely want to call `Instance::upstream_monomorphization()`
1537     /// instead of invoking this query directly.
1538     ///
1539     /// NOTE: This query could easily be extended to also support other
1540     ///       common functions that have are large set of monomorphizations
1541     ///       (like `Clone::clone` for example).
1542     query upstream_drop_glue_for(substs: SubstsRef<'tcx>) -> Option<CrateNum> {
1543         desc { "available upstream drop-glue for `{:?}`", substs }
1544     }
1545
1546     /// Returns a list of all `extern` blocks of a crate.
1547     query foreign_modules(_: CrateNum) -> FxHashMap<DefId, ForeignModule> {
1548         arena_cache
1549         desc { "looking up the foreign modules of a linked crate" }
1550         separate_provide_extern
1551     }
1552
1553     /// Identifies the entry-point (e.g., the `main` function) for a given
1554     /// crate, returning `None` if there is no entry point (such as for library crates).
1555     query entry_fn(_: ()) -> Option<(DefId, EntryFnType)> {
1556         desc { "looking up the entry function of a crate" }
1557     }
1558
1559     /// Finds the `rustc_proc_macro_decls` item of a crate.
1560     query proc_macro_decls_static(_: ()) -> Option<LocalDefId> {
1561         desc { "looking up the proc macro declarations for a crate" }
1562     }
1563
1564     // The macro which defines `rustc_metadata::provide_extern` depends on this query's name.
1565     // Changing the name should cause a compiler error, but in case that changes, be aware.
1566     query crate_hash(_: CrateNum) -> Svh {
1567         eval_always
1568         desc { "looking up the hash a crate" }
1569         separate_provide_extern
1570     }
1571
1572     /// Gets the hash for the host proc macro. Used to support -Z dual-proc-macro.
1573     query crate_host_hash(_: CrateNum) -> Option<Svh> {
1574         eval_always
1575         desc { "looking up the hash of a host version of a crate" }
1576         separate_provide_extern
1577     }
1578
1579     /// Gets the extra data to put in each output filename for a crate.
1580     /// For example, compiling the `foo` crate with `extra-filename=-a` creates a `libfoo-b.rlib` file.
1581     query extra_filename(_: CrateNum) -> String {
1582         arena_cache
1583         eval_always
1584         desc { "looking up the extra filename for a crate" }
1585         separate_provide_extern
1586     }
1587
1588     /// Gets the paths where the crate came from in the file system.
1589     query crate_extern_paths(_: CrateNum) -> Vec<PathBuf> {
1590         arena_cache
1591         eval_always
1592         desc { "looking up the paths for extern crates" }
1593         separate_provide_extern
1594     }
1595
1596     /// Given a crate and a trait, look up all impls of that trait in the crate.
1597     /// Return `(impl_id, self_ty)`.
1598     query implementations_of_trait(_: (CrateNum, DefId)) -> &'tcx [(DefId, Option<SimplifiedType>)] {
1599         desc { "looking up implementations of a trait in a crate" }
1600         separate_provide_extern
1601     }
1602
1603     /// Collects all incoherent impls for the given crate and type.
1604     ///
1605     /// Do not call this directly, but instead use the `incoherent_impls` query.
1606     /// This query is only used to get the data necessary for that query.
1607     query crate_incoherent_impls(key: (CrateNum, SimplifiedType)) -> &'tcx [DefId] {
1608         desc { |tcx| "collecting all impls for a type in a crate" }
1609         separate_provide_extern
1610     }
1611
1612     /// Get the corresponding native library from the `native_libraries` query
1613     query native_library(def_id: DefId) -> Option<&'tcx NativeLib> {
1614         desc { |tcx| "getting the native library for `{}`", tcx.def_path_str(def_id) }
1615     }
1616
1617     /// Does lifetime resolution on items. Importantly, we can't resolve
1618     /// lifetimes directly on things like trait methods, because of trait params.
1619     /// See `rustc_resolve::late::lifetimes for details.
1620     query resolve_lifetimes(_: hir::OwnerId) -> ResolveLifetimes {
1621         arena_cache
1622         desc { "resolving lifetimes" }
1623     }
1624     query named_region_map(_: hir::OwnerId) ->
1625         Option<&'tcx FxHashMap<ItemLocalId, Region>> {
1626         desc { "looking up a named region" }
1627     }
1628     query is_late_bound_map(_: LocalDefId) -> Option<&'tcx FxIndexSet<LocalDefId>> {
1629         desc { "testing if a region is late bound" }
1630     }
1631     /// For a given item's generic parameter, gets the default lifetimes to be used
1632     /// for each parameter if a trait object were to be passed for that parameter.
1633     /// For example, for `T` in `struct Foo<'a, T>`, this would be `'static`.
1634     /// For `T` in `struct Foo<'a, T: 'a>`, this would instead be `'a`.
1635     /// This query will panic if passed something that is not a type parameter.
1636     query object_lifetime_default(key: DefId) -> ObjectLifetimeDefault {
1637         desc { "looking up lifetime defaults for generic parameter `{}`", tcx.def_path_str(key) }
1638         separate_provide_extern
1639     }
1640     query late_bound_vars_map(_: hir::OwnerId)
1641         -> Option<&'tcx FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>> {
1642         desc { "looking up late bound vars" }
1643     }
1644
1645     /// Computes the visibility of the provided `def_id`.
1646     ///
1647     /// If the item from the `def_id` doesn't have a visibility, it will panic. For example
1648     /// a generic type parameter will panic if you call this method on it:
1649     ///
1650     /// ```
1651     /// pub trait Foo<T: Debug> {}
1652     /// ```
1653     ///
1654     /// In here, if you call `visibility` on `T`, it'll panic.
1655     query visibility(def_id: DefId) -> ty::Visibility<DefId> {
1656         desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
1657         separate_provide_extern
1658     }
1659
1660     query inhabited_predicate_adt(key: DefId) -> ty::inhabitedness::InhabitedPredicate<'tcx> {
1661         desc { "computing the uninhabited predicate of `{:?}`", key }
1662     }
1663
1664     /// Do not call this query directly: invoke `Ty::inhabited_predicate` instead.
1665     query inhabited_predicate_type(key: Ty<'tcx>) -> ty::inhabitedness::InhabitedPredicate<'tcx> {
1666         desc { "computing the uninhabited predicate of `{}`", key }
1667     }
1668
1669     query dep_kind(_: CrateNum) -> CrateDepKind {
1670         eval_always
1671         desc { "fetching what a dependency looks like" }
1672         separate_provide_extern
1673     }
1674
1675     /// Gets the name of the crate.
1676     query crate_name(_: CrateNum) -> Symbol {
1677         eval_always
1678         desc { "fetching what a crate is named" }
1679         separate_provide_extern
1680     }
1681     query module_children(def_id: DefId) -> &'tcx [ModChild] {
1682         desc { |tcx| "collecting child items of module `{}`", tcx.def_path_str(def_id) }
1683         separate_provide_extern
1684     }
1685     query extern_mod_stmt_cnum(def_id: LocalDefId) -> Option<CrateNum> {
1686         desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1687     }
1688
1689     query lib_features(_: ()) -> LibFeatures {
1690         arena_cache
1691         desc { "calculating the lib features map" }
1692     }
1693     query defined_lib_features(_: CrateNum) -> &'tcx [(Symbol, Option<Symbol>)] {
1694         desc { "calculating the lib features defined in a crate" }
1695         separate_provide_extern
1696     }
1697     query stability_implications(_: CrateNum) -> FxHashMap<Symbol, Symbol> {
1698         arena_cache
1699         desc { "calculating the implications between `#[unstable]` features defined in a crate" }
1700         separate_provide_extern
1701     }
1702     /// Whether the function is an intrinsic
1703     query is_intrinsic(def_id: DefId) -> bool {
1704         desc { |tcx| "checking whether `{}` is an intrinsic", tcx.def_path_str(def_id) }
1705         separate_provide_extern
1706     }
1707     /// Returns the lang items defined in another crate by loading it from metadata.
1708     query get_lang_items(_: ()) -> LanguageItems {
1709         arena_cache
1710         eval_always
1711         desc { "calculating the lang items map" }
1712     }
1713
1714     /// Returns all diagnostic items defined in all crates.
1715     query all_diagnostic_items(_: ()) -> rustc_hir::diagnostic_items::DiagnosticItems {
1716         arena_cache
1717         eval_always
1718         desc { "calculating the diagnostic items map" }
1719     }
1720
1721     /// Returns the lang items defined in another crate by loading it from metadata.
1722     query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, LangItem)] {
1723         desc { "calculating the lang items defined in a crate" }
1724         separate_provide_extern
1725     }
1726
1727     /// Returns the diagnostic items defined in a crate.
1728     query diagnostic_items(_: CrateNum) -> rustc_hir::diagnostic_items::DiagnosticItems {
1729         arena_cache
1730         desc { "calculating the diagnostic items map in a crate" }
1731         separate_provide_extern
1732     }
1733
1734     query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
1735         desc { "calculating the missing lang items in a crate" }
1736         separate_provide_extern
1737     }
1738     query visible_parent_map(_: ()) -> DefIdMap<DefId> {
1739         arena_cache
1740         desc { "calculating the visible parent map" }
1741     }
1742     query trimmed_def_paths(_: ()) -> FxHashMap<DefId, Symbol> {
1743         arena_cache
1744         desc { "calculating trimmed def paths" }
1745     }
1746     query missing_extern_crate_item(_: CrateNum) -> bool {
1747         eval_always
1748         desc { "seeing if we're missing an `extern crate` item for this crate" }
1749         separate_provide_extern
1750     }
1751     query used_crate_source(_: CrateNum) -> Lrc<CrateSource> {
1752         arena_cache
1753         eval_always
1754         desc { "looking at the source for a crate" }
1755         separate_provide_extern
1756     }
1757     /// Returns the debugger visualizers defined for this crate.
1758     query debugger_visualizers(_: CrateNum) -> Vec<rustc_span::DebuggerVisualizerFile> {
1759         arena_cache
1760         desc { "looking up the debugger visualizers for this crate" }
1761         separate_provide_extern
1762     }
1763     query postorder_cnums(_: ()) -> &'tcx [CrateNum] {
1764         eval_always
1765         desc { "generating a postorder list of CrateNums" }
1766     }
1767     /// Returns whether or not the crate with CrateNum 'cnum'
1768     /// is marked as a private dependency
1769     query is_private_dep(c: CrateNum) -> bool {
1770         eval_always
1771         desc { "checking whether crate `{}` is a private dependency", c }
1772         separate_provide_extern
1773     }
1774     query allocator_kind(_: ()) -> Option<AllocatorKind> {
1775         eval_always
1776         desc { "getting the allocator kind for the current crate" }
1777     }
1778     query alloc_error_handler_kind(_: ()) -> Option<AllocatorKind> {
1779         eval_always
1780         desc { "alloc error handler kind for the current crate" }
1781     }
1782
1783     query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
1784         desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) }
1785     }
1786     query maybe_unused_trait_imports(_: ()) -> &'tcx FxIndexSet<LocalDefId> {
1787         desc { "fetching potentially unused trait imports" }
1788     }
1789     query maybe_unused_extern_crates(_: ()) -> &'tcx [(LocalDefId, Span)] {
1790         desc { "looking up all possibly unused extern crates" }
1791     }
1792     query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx FxHashSet<Symbol> {
1793         desc { |tcx| "finding names imported by glob use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1794     }
1795
1796     query stability_index(_: ()) -> stability::Index {
1797         arena_cache
1798         eval_always
1799         desc { "calculating the stability index for the local crate" }
1800     }
1801     query crates(_: ()) -> &'tcx [CrateNum] {
1802         eval_always
1803         desc { "fetching all foreign CrateNum instances" }
1804     }
1805
1806     /// A list of all traits in a crate, used by rustdoc and error reporting.
1807     /// NOTE: Not named just `traits` due to a naming conflict.
1808     query traits_in_crate(_: CrateNum) -> &'tcx [DefId] {
1809         desc { "fetching all traits in a crate" }
1810         separate_provide_extern
1811     }
1812
1813     /// The list of symbols exported from the given crate.
1814     ///
1815     /// - All names contained in `exported_symbols(cnum)` are guaranteed to
1816     ///   correspond to a publicly visible symbol in `cnum` machine code.
1817     /// - The `exported_symbols` sets of different crates do not intersect.
1818     query exported_symbols(cnum: CrateNum) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] {
1819         desc { "collecting exported symbols for crate `{}`", cnum}
1820         cache_on_disk_if { *cnum == LOCAL_CRATE }
1821         separate_provide_extern
1822     }
1823
1824     query collect_and_partition_mono_items(_: ()) -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
1825         eval_always
1826         desc { "collect_and_partition_mono_items" }
1827     }
1828
1829     query is_codegened_item(def_id: DefId) -> bool {
1830         desc { |tcx| "determining whether `{}` needs codegen", tcx.def_path_str(def_id) }
1831     }
1832
1833     /// All items participating in code generation together with items inlined into them.
1834     query codegened_and_inlined_items(_: ()) -> &'tcx DefIdSet {
1835         eval_always
1836         desc { "collecting codegened and inlined items" }
1837     }
1838
1839     query codegen_unit(sym: Symbol) -> &'tcx CodegenUnit<'tcx> {
1840         desc { "getting codegen unit `{sym}`" }
1841     }
1842
1843     query unused_generic_params(key: ty::InstanceDef<'tcx>) -> FiniteBitSet<u32> {
1844         cache_on_disk_if { key.def_id().is_local() }
1845         desc {
1846             |tcx| "determining which generic parameters are unused by `{}`",
1847                 tcx.def_path_str(key.def_id())
1848         }
1849         separate_provide_extern
1850     }
1851
1852     query backend_optimization_level(_: ()) -> OptLevel {
1853         desc { "optimization level used by backend" }
1854     }
1855
1856     /// Return the filenames where output artefacts shall be stored.
1857     ///
1858     /// This query returns an `&Arc` because codegen backends need the value even after the `TyCtxt`
1859     /// has been destroyed.
1860     query output_filenames(_: ()) -> &'tcx Arc<OutputFilenames> {
1861         eval_always
1862         desc { "getting output filenames" }
1863     }
1864
1865     /// Do not call this query directly: invoke `normalize` instead.
1866     query normalize_projection_ty(
1867         goal: CanonicalProjectionGoal<'tcx>
1868     ) -> Result<
1869         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
1870         NoSolution,
1871     > {
1872         desc { "normalizing `{}`", goal.value.value }
1873         remap_env_constness
1874     }
1875
1876     /// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
1877     query try_normalize_generic_arg_after_erasing_regions(
1878         goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
1879     ) -> Result<GenericArg<'tcx>, NoSolution> {
1880         desc { "normalizing `{}`", goal.value }
1881         remap_env_constness
1882     }
1883
1884     query implied_outlives_bounds(
1885         goal: CanonicalTyGoal<'tcx>
1886     ) -> Result<
1887         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
1888         NoSolution,
1889     > {
1890         desc { "computing implied outlives bounds for `{}`", goal.value.value }
1891         remap_env_constness
1892     }
1893
1894     /// Do not call this query directly:
1895     /// invoke `DropckOutlives::new(dropped_ty)).fully_perform(typeck.infcx)` instead.
1896     query dropck_outlives(
1897         goal: CanonicalTyGoal<'tcx>
1898     ) -> Result<
1899         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>,
1900         NoSolution,
1901     > {
1902         desc { "computing dropck types for `{}`", goal.value.value }
1903         remap_env_constness
1904     }
1905
1906     /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
1907     /// `infcx.predicate_must_hold()` instead.
1908     query evaluate_obligation(
1909         goal: CanonicalPredicateGoal<'tcx>
1910     ) -> Result<traits::EvaluationResult, traits::OverflowError> {
1911         desc { "evaluating trait selection obligation `{}`", goal.value.value }
1912     }
1913
1914     query evaluate_goal(
1915         goal: traits::CanonicalChalkEnvironmentAndGoal<'tcx>
1916     ) -> Result<
1917         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1918         NoSolution
1919     > {
1920         desc { "evaluating trait selection obligation `{}`", goal.value }
1921     }
1922
1923     /// Do not call this query directly: part of the `Eq` type-op
1924     query type_op_ascribe_user_type(
1925         goal: CanonicalTypeOpAscribeUserTypeGoal<'tcx>
1926     ) -> Result<
1927         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1928         NoSolution,
1929     > {
1930         desc { "evaluating `type_op_ascribe_user_type` `{:?}`", goal.value.value }
1931         remap_env_constness
1932     }
1933
1934     /// Do not call this query directly: part of the `Eq` type-op
1935     query type_op_eq(
1936         goal: CanonicalTypeOpEqGoal<'tcx>
1937     ) -> Result<
1938         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1939         NoSolution,
1940     > {
1941         desc { "evaluating `type_op_eq` `{:?}`", goal.value.value }
1942         remap_env_constness
1943     }
1944
1945     /// Do not call this query directly: part of the `Subtype` type-op
1946     query type_op_subtype(
1947         goal: CanonicalTypeOpSubtypeGoal<'tcx>
1948     ) -> Result<
1949         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1950         NoSolution,
1951     > {
1952         desc { "evaluating `type_op_subtype` `{:?}`", goal.value.value }
1953         remap_env_constness
1954     }
1955
1956     /// Do not call this query directly: part of the `ProvePredicate` type-op
1957     query type_op_prove_predicate(
1958         goal: CanonicalTypeOpProvePredicateGoal<'tcx>
1959     ) -> Result<
1960         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1961         NoSolution,
1962     > {
1963         desc { "evaluating `type_op_prove_predicate` `{:?}`", goal.value.value }
1964     }
1965
1966     /// Do not call this query directly: part of the `Normalize` type-op
1967     query type_op_normalize_ty(
1968         goal: CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
1969     ) -> Result<
1970         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>,
1971         NoSolution,
1972     > {
1973         desc { "normalizing `{}`", goal.value.value.value }
1974         remap_env_constness
1975     }
1976
1977     /// Do not call this query directly: part of the `Normalize` type-op
1978     query type_op_normalize_predicate(
1979         goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
1980     ) -> Result<
1981         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>,
1982         NoSolution,
1983     > {
1984         desc { "normalizing `{:?}`", goal.value.value.value }
1985         remap_env_constness
1986     }
1987
1988     /// Do not call this query directly: part of the `Normalize` type-op
1989     query type_op_normalize_poly_fn_sig(
1990         goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
1991     ) -> Result<
1992         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>,
1993         NoSolution,
1994     > {
1995         desc { "normalizing `{:?}`", goal.value.value.value }
1996         remap_env_constness
1997     }
1998
1999     /// Do not call this query directly: part of the `Normalize` type-op
2000     query type_op_normalize_fn_sig(
2001         goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
2002     ) -> Result<
2003         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>,
2004         NoSolution,
2005     > {
2006         desc { "normalizing `{:?}`", goal.value.value.value }
2007         remap_env_constness
2008     }
2009
2010     query subst_and_check_impossible_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
2011         desc { |tcx|
2012             "checking impossible substituted predicates: `{}`",
2013             tcx.def_path_str(key.0)
2014         }
2015     }
2016
2017     query is_impossible_method(key: (DefId, DefId)) -> bool {
2018         desc { |tcx|
2019             "checking if `{}` is impossible to call within `{}`",
2020             tcx.def_path_str(key.1),
2021             tcx.def_path_str(key.0),
2022         }
2023     }
2024
2025     query method_autoderef_steps(
2026         goal: CanonicalTyGoal<'tcx>
2027     ) -> MethodAutoderefStepsResult<'tcx> {
2028         desc { "computing autoderef types for `{}`", goal.value.value }
2029         remap_env_constness
2030     }
2031
2032     query supported_target_features(_: CrateNum) -> FxHashMap<String, Option<Symbol>> {
2033         arena_cache
2034         eval_always
2035         desc { "looking up supported target features" }
2036     }
2037
2038     /// Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
2039     query instance_def_size_estimate(def: ty::InstanceDef<'tcx>)
2040         -> usize {
2041         desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) }
2042     }
2043
2044     query features_query(_: ()) -> &'tcx rustc_feature::Features {
2045         eval_always
2046         desc { "looking up enabled feature gates" }
2047     }
2048
2049     /// Attempt to resolve the given `DefId` to an `Instance`, for the
2050     /// given generics args (`SubstsRef`), returning one of:
2051     ///  * `Ok(Some(instance))` on success
2052     ///  * `Ok(None)` when the `SubstsRef` are still too generic,
2053     ///    and therefore don't allow finding the final `Instance`
2054     ///  * `Err(ErrorGuaranteed)` when the `Instance` resolution process
2055     ///    couldn't complete due to errors elsewhere - this is distinct
2056     ///    from `Ok(None)` to avoid misleading diagnostics when an error
2057     ///    has already been/will be emitted, for the original cause
2058     query resolve_instance(
2059         key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>
2060     ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
2061         desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) }
2062         remap_env_constness
2063     }
2064
2065     query resolve_instance_of_const_arg(
2066         key: ty::ParamEnvAnd<'tcx, (LocalDefId, DefId, SubstsRef<'tcx>)>
2067     ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
2068         desc {
2069             "resolving instance of the const argument `{}`",
2070             ty::Instance::new(key.value.0.to_def_id(), key.value.2),
2071         }
2072         remap_env_constness
2073     }
2074
2075     query normalize_opaque_types(key: &'tcx ty::List<ty::Predicate<'tcx>>) -> &'tcx ty::List<ty::Predicate<'tcx>> {
2076         desc { "normalizing opaque types in `{:?}`", key }
2077     }
2078
2079     /// Checks whether a type is definitely uninhabited. This is
2080     /// conservative: for some types that are uninhabited we return `false`,
2081     /// but we only return `true` for types that are definitely uninhabited.
2082     /// `ty.conservative_is_privately_uninhabited` implies that any value of type `ty`
2083     /// will be `Abi::Uninhabited`. (Note that uninhabited types may have nonzero
2084     /// size, to account for partial initialisation. See #49298 for details.)
2085     query conservative_is_privately_uninhabited(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
2086         desc { "conservatively checking if `{}` is privately uninhabited", key.value }
2087         remap_env_constness
2088     }
2089
2090     query limits(key: ()) -> Limits {
2091         desc { "looking up limits" }
2092     }
2093
2094     /// Performs an HIR-based well-formed check on the item with the given `HirId`. If
2095     /// we get an `Unimplemented` error that matches the provided `Predicate`, return
2096     /// the cause of the newly created obligation.
2097     ///
2098     /// This is only used by error-reporting code to get a better cause (in particular, a better
2099     /// span) for an *existing* error. Therefore, it is best-effort, and may never handle
2100     /// all of the cases that the normal `ty::Ty`-based wfcheck does. This is fine,
2101     /// because the `ty::Ty`-based wfcheck is always run.
2102     query diagnostic_hir_wf_check(key: (ty::Predicate<'tcx>, traits::WellFormedLoc)) -> Option<traits::ObligationCause<'tcx>> {
2103         arena_cache
2104         eval_always
2105         no_hash
2106         desc { "performing HIR wf-checking for predicate `{:?}` at item `{:?}`", key.0, key.1 }
2107     }
2108
2109
2110     /// The list of backend features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`,
2111     /// `--target` and similar).
2112     query global_backend_features(_: ()) -> Vec<String> {
2113         arena_cache
2114         eval_always
2115         desc { "computing the backend features for CLI flags" }
2116     }
2117
2118     query generator_diagnostic_data(key: DefId) -> Option<GeneratorDiagnosticData<'tcx>> {
2119         arena_cache
2120         desc { |tcx| "looking up generator diagnostic data of `{}`", tcx.def_path_str(key) }
2121         separate_provide_extern
2122     }
2123
2124     query permits_uninit_init(key: TyAndLayout<'tcx>) -> bool {
2125         desc { "checking to see if `{}` permits being left uninit", key.ty }
2126     }
2127
2128     query permits_zero_init(key: TyAndLayout<'tcx>) -> bool {
2129         desc { "checking to see if `{}` permits being left zeroed", key.ty }
2130     }
2131
2132     query compare_assoc_const_impl_item_with_trait_item(
2133         key: (LocalDefId, DefId)
2134     ) -> Result<(), ErrorGuaranteed> {
2135         desc { |tcx| "checking assoc const `{}` has the same type as trait item", tcx.def_path_str(key.0.to_def_id()) }
2136     }
2137
2138     query deduced_param_attrs(def_id: DefId) -> &'tcx [ty::DeducedParamAttrs] {
2139         desc { |tcx| "deducing parameter attributes for {}", tcx.def_path_str(def_id) }
2140         separate_provide_extern
2141     }
2142 }