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