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