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