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