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