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