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