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