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