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