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