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