]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_middle/src/query/mod.rs
Rollup merge of #93250 - Aaron1011:remove-early-dedup, r=oli-obk
[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             #[cfg(bootstrap)]
788             {
789                 match match tcx.on_disk_cache().as_ref() {
790                     Some(c) => c.try_load_query_result(*tcx, id),
791                     None => None,
792                 } {
793                     Some(x) => Some(&*tcx.arena.alloc(x)),
794                     None => None,
795                 }
796             }
797             #[cfg(not(bootstrap))]
798             {
799                 let typeck_results: Option<ty::TypeckResults<'tcx>> = tcx
800                     .on_disk_cache().as_ref()
801                     .and_then(|c| c.try_load_query_result(*tcx, id));
802
803                 typeck_results.map(|x| &*tcx.arena.alloc(x))
804             }
805         }
806     }
807
808     query used_trait_imports(key: LocalDefId) -> &'tcx FxHashSet<LocalDefId> {
809         desc { |tcx| "used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) }
810         cache_on_disk_if { true }
811     }
812
813     query has_typeck_results(def_id: DefId) -> bool {
814         desc { |tcx| "checking whether `{}` has a body", tcx.def_path_str(def_id) }
815     }
816
817     query coherent_trait(def_id: DefId) -> () {
818         desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
819     }
820
821     /// Borrow-checks the function body. If this is a closure, returns
822     /// additional requirements that the closure's creator must verify.
823     query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
824         desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
825         cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) }
826     }
827     query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> {
828         desc {
829             |tcx| "borrow-checking the const argument`{}`",
830             tcx.def_path_str(key.0.to_def_id())
831         }
832     }
833
834     /// Gets a complete map from all types to their inherent impls.
835     /// Not meant to be used directly outside of coherence.
836     query crate_inherent_impls(k: ()) -> CrateInherentImpls {
837         storage(ArenaCacheSelector<'tcx>)
838         desc { "all inherent impls defined in crate" }
839     }
840
841     /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
842     /// Not meant to be used directly outside of coherence.
843     query crate_inherent_impls_overlap_check(_: ()) -> () {
844         desc { "check for overlap between inherent impls defined in this crate" }
845     }
846
847     /// Checks whether all impls in the crate pass the overlap check, returning
848     /// which impls fail it. If all impls are correct, the returned slice is empty.
849     query orphan_check_crate(_: ()) -> &'tcx [LocalDefId] {
850         desc {
851             "checking whether the immpl in the this crate follow the orphan rules",
852         }
853     }
854
855     /// Check whether the function has any recursion that could cause the inliner to trigger
856     /// a cycle. Returns the call stack causing the cycle. The call stack does not contain the
857     /// current function, just all intermediate functions.
858     query mir_callgraph_reachable(key: (ty::Instance<'tcx>, LocalDefId)) -> bool {
859         fatal_cycle
860         desc { |tcx|
861             "computing if `{}` (transitively) calls `{}`",
862             key.0,
863             tcx.def_path_str(key.1.to_def_id()),
864         }
865     }
866
867     /// Obtain all the calls into other local functions
868     query mir_inliner_callees(key: ty::InstanceDef<'tcx>) -> &'tcx [(DefId, SubstsRef<'tcx>)] {
869         fatal_cycle
870         desc { |tcx|
871             "computing all local function calls in `{}`",
872             tcx.def_path_str(key.def_id()),
873         }
874     }
875
876     /// Evaluates a constant and returns the computed allocation.
877     ///
878     /// **Do not use this** directly, use the `tcx.eval_static_initializer` wrapper.
879     query eval_to_allocation_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
880         -> EvalToAllocationRawResult<'tcx> {
881         desc { |tcx|
882             "const-evaluating + checking `{}`",
883             key.value.display(tcx)
884         }
885         cache_on_disk_if { true }
886     }
887
888     /// Evaluates const items or anonymous constants
889     /// (such as enum variant explicit discriminants or array lengths)
890     /// into a representation suitable for the type system and const generics.
891     ///
892     /// **Do not use this** directly, use one of the following wrappers: `tcx.const_eval_poly`,
893     /// `tcx.const_eval_resolve`, `tcx.const_eval_instance`, or `tcx.const_eval_global_id`.
894     query eval_to_const_value_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
895         -> EvalToConstValueResult<'tcx> {
896         desc { |tcx|
897             "simplifying constant for the type system `{}`",
898             key.value.display(tcx)
899         }
900         cache_on_disk_if { true }
901     }
902
903     /// Convert an evaluated constant to a type level constant or
904     /// return `None` if that is not possible.
905     query const_to_valtree(
906         key: ty::ParamEnvAnd<'tcx, ConstAlloc<'tcx>>
907     ) -> Option<ty::ValTree<'tcx>> {
908         desc { "destructure constant" }
909         remap_env_constness
910     }
911
912     /// Destructure a constant ADT or array into its variant index and its
913     /// field values.
914     query destructure_const(
915         key: ty::ParamEnvAnd<'tcx, &'tcx ty::Const<'tcx>>
916     ) -> mir::DestructuredConst<'tcx> {
917         desc { "destructure constant" }
918         remap_env_constness
919     }
920
921     /// Dereference a constant reference or raw pointer and turn the result into a constant
922     /// again.
923     query deref_const(
924         key: ty::ParamEnvAnd<'tcx, &'tcx ty::Const<'tcx>>
925     ) -> &'tcx ty::Const<'tcx> {
926         desc { "deref constant" }
927         remap_env_constness
928     }
929
930     query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> ConstValue<'tcx> {
931         desc { "get a &core::panic::Location referring to a span" }
932     }
933
934     query lit_to_const(
935         key: LitToConstInput<'tcx>
936     ) -> Result<&'tcx ty::Const<'tcx>, LitToConstError> {
937         desc { "converting literal to const" }
938     }
939
940     query check_match(key: DefId) {
941         desc { |tcx| "match-checking `{}`", tcx.def_path_str(key) }
942         cache_on_disk_if { key.is_local() }
943     }
944
945     /// Performs part of the privacy check and computes "access levels".
946     query privacy_access_levels(_: ()) -> &'tcx AccessLevels {
947         eval_always
948         desc { "privacy access levels" }
949     }
950     query check_private_in_public(_: ()) -> () {
951         eval_always
952         desc { "checking for private elements in public interfaces" }
953     }
954
955     query reachable_set(_: ()) -> FxHashSet<LocalDefId> {
956         storage(ArenaCacheSelector<'tcx>)
957         desc { "reachability" }
958     }
959
960     /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
961     /// in the case of closures, this will be redirected to the enclosing function.
962     query region_scope_tree(def_id: DefId) -> &'tcx region::ScopeTree {
963         desc { |tcx| "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
964     }
965
966     /// Generates a MIR body for the shim.
967     query mir_shims(key: ty::InstanceDef<'tcx>) -> mir::Body<'tcx> {
968         storage(ArenaCacheSelector<'tcx>)
969         desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
970     }
971
972     /// The `symbol_name` query provides the symbol name for calling a
973     /// given instance from the local crate. In particular, it will also
974     /// look up the correct symbol name of instances from upstream crates.
975     query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName<'tcx> {
976         desc { "computing the symbol for `{}`", key }
977         cache_on_disk_if { true }
978     }
979
980     query opt_def_kind(def_id: DefId) -> Option<DefKind> {
981         desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
982         separate_provide_extern
983     }
984
985     /// Gets the span for the definition.
986     query def_span(def_id: DefId) -> Span {
987         desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }
988         separate_provide_extern
989     }
990
991     /// Gets the span for the identifier of the definition.
992     query def_ident_span(def_id: DefId) -> Option<Span> {
993         desc { |tcx| "looking up span for `{}`'s identifier", tcx.def_path_str(def_id) }
994         separate_provide_extern
995     }
996
997     query lookup_stability(def_id: DefId) -> Option<&'tcx attr::Stability> {
998         desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
999         separate_provide_extern
1000     }
1001
1002     query lookup_const_stability(def_id: DefId) -> Option<&'tcx attr::ConstStability> {
1003         desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
1004         separate_provide_extern
1005     }
1006
1007     query should_inherit_track_caller(def_id: DefId) -> bool {
1008         desc { |tcx| "computing should_inherit_track_caller of `{}`", tcx.def_path_str(def_id) }
1009     }
1010
1011     query lookup_deprecation_entry(def_id: DefId) -> Option<DeprecationEntry> {
1012         desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) }
1013         separate_provide_extern
1014     }
1015
1016     query item_attrs(def_id: DefId) -> &'tcx [ast::Attribute] {
1017         desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
1018         separate_provide_extern
1019     }
1020
1021     query codegen_fn_attrs(def_id: DefId) -> CodegenFnAttrs {
1022         desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) }
1023         storage(ArenaCacheSelector<'tcx>)
1024         cache_on_disk_if { true }
1025     }
1026
1027     query fn_arg_names(def_id: DefId) -> &'tcx [rustc_span::symbol::Ident] {
1028         desc { |tcx| "looking up function parameter names for `{}`", tcx.def_path_str(def_id) }
1029         separate_provide_extern
1030     }
1031     /// Gets the rendered value of the specified constant or associated constant.
1032     /// Used by rustdoc.
1033     query rendered_const(def_id: DefId) -> String {
1034         desc { |tcx| "rendering constant intializer of `{}`", tcx.def_path_str(def_id) }
1035         separate_provide_extern
1036     }
1037     query impl_parent(def_id: DefId) -> Option<DefId> {
1038         desc { |tcx| "computing specialization parent impl of `{}`", tcx.def_path_str(def_id) }
1039         separate_provide_extern
1040     }
1041
1042     /// Given an `associated_item`, find the trait it belongs to.
1043     /// Return `None` if the `DefId` is not an associated item.
1044     query trait_of_item(associated_item: DefId) -> Option<DefId> {
1045         desc { |tcx| "finding trait defining `{}`", tcx.def_path_str(associated_item) }
1046         separate_provide_extern
1047     }
1048
1049     query is_ctfe_mir_available(key: DefId) -> bool {
1050         desc { |tcx| "checking if item has ctfe mir available: `{}`", tcx.def_path_str(key) }
1051         separate_provide_extern
1052     }
1053     query is_mir_available(key: DefId) -> bool {
1054         desc { |tcx| "checking if item has mir available: `{}`", tcx.def_path_str(key) }
1055         separate_provide_extern
1056     }
1057
1058     query own_existential_vtable_entries(
1059         key: ty::PolyExistentialTraitRef<'tcx>
1060     ) -> &'tcx [DefId] {
1061         desc { |tcx| "finding all existential vtable entries for trait {}", tcx.def_path_str(key.def_id()) }
1062     }
1063
1064     query vtable_entries(key: ty::PolyTraitRef<'tcx>)
1065                         -> &'tcx [ty::VtblEntry<'tcx>] {
1066         desc { |tcx| "finding all vtable entries for trait {}", tcx.def_path_str(key.def_id()) }
1067     }
1068
1069     query vtable_trait_upcasting_coercion_new_vptr_slot(key: (ty::Ty<'tcx>, ty::Ty<'tcx>)) -> Option<usize> {
1070         desc { |tcx| "finding the slot within vtable for trait object {} vtable ptr during trait upcasting coercion from {} vtable",
1071             key.1, key.0 }
1072     }
1073
1074     query vtable_allocation(key: (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>)) -> mir::interpret::AllocId {
1075         desc { |tcx| "vtable const allocation for <{} as {}>",
1076             key.0,
1077             key.1.map(|trait_ref| format!("{}", trait_ref)).unwrap_or("_".to_owned())
1078         }
1079     }
1080
1081     query codegen_fulfill_obligation(
1082         key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)
1083     ) -> Result<ImplSource<'tcx, ()>, ErrorReported> {
1084         cache_on_disk_if { true }
1085         desc { |tcx|
1086             "checking if `{}` fulfills its obligations",
1087             tcx.def_path_str(key.1.def_id())
1088         }
1089     }
1090
1091     /// Return all `impl` blocks in the current crate.
1092     query all_local_trait_impls(_: ()) -> &'tcx BTreeMap<DefId, Vec<LocalDefId>> {
1093         desc { "local trait impls" }
1094     }
1095
1096     /// Given a trait `trait_id`, return all known `impl` blocks.
1097     query trait_impls_of(trait_id: DefId) -> ty::trait_def::TraitImpls {
1098         storage(ArenaCacheSelector<'tcx>)
1099         desc { |tcx| "trait impls of `{}`", tcx.def_path_str(trait_id) }
1100     }
1101
1102     query specialization_graph_of(trait_id: DefId) -> specialization_graph::Graph {
1103         storage(ArenaCacheSelector<'tcx>)
1104         desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
1105         cache_on_disk_if { true }
1106     }
1107     query object_safety_violations(trait_id: DefId) -> &'tcx [traits::ObjectSafetyViolation] {
1108         desc { |tcx| "determine object safety of trait `{}`", tcx.def_path_str(trait_id) }
1109     }
1110
1111     /// Gets the ParameterEnvironment for a given item; this environment
1112     /// will be in "user-facing" mode, meaning that it is suitable for
1113     /// type-checking etc, and it does not normalize specializable
1114     /// associated types. This is almost always what you want,
1115     /// unless you are doing MIR optimizations, in which case you
1116     /// might want to use `reveal_all()` method to change modes.
1117     query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
1118         desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
1119     }
1120
1121     /// Like `param_env`, but returns the `ParamEnv` in `Reveal::All` mode.
1122     /// Prefer this over `tcx.param_env(def_id).with_reveal_all_normalized(tcx)`,
1123     /// as this method is more efficient.
1124     query param_env_reveal_all_normalized(def_id: DefId) -> ty::ParamEnv<'tcx> {
1125         desc { |tcx| "computing revealed normalized predicates of `{}`", tcx.def_path_str(def_id) }
1126     }
1127
1128     /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
1129     /// `ty.is_copy()`, etc, since that will prune the environment where possible.
1130     query is_copy_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1131         desc { "computing whether `{}` is `Copy`", env.value }
1132         remap_env_constness
1133     }
1134     /// Query backing `TyS::is_sized`.
1135     query is_sized_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1136         desc { "computing whether `{}` is `Sized`", env.value }
1137         remap_env_constness
1138     }
1139     /// Query backing `TyS::is_freeze`.
1140     query is_freeze_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1141         desc { "computing whether `{}` is freeze", env.value }
1142         remap_env_constness
1143     }
1144     /// Query backing `TyS::is_unpin`.
1145     query is_unpin_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1146         desc { "computing whether `{}` is `Unpin`", env.value }
1147         remap_env_constness
1148     }
1149     /// Query backing `TyS::needs_drop`.
1150     query needs_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1151         desc { "computing whether `{}` needs drop", env.value }
1152         remap_env_constness
1153     }
1154     /// Query backing `TyS::has_significant_drop_raw`.
1155     query has_significant_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1156         desc { "computing whether `{}` has a significant drop", env.value }
1157         remap_env_constness
1158     }
1159
1160     /// Query backing `TyS::is_structural_eq_shallow`.
1161     ///
1162     /// This is only correct for ADTs. Call `is_structural_eq_shallow` to handle all types
1163     /// correctly.
1164     query has_structural_eq_impls(ty: Ty<'tcx>) -> bool {
1165         desc {
1166             "computing whether `{:?}` implements `PartialStructuralEq` and `StructuralEq`",
1167             ty
1168         }
1169     }
1170
1171     /// A list of types where the ADT requires drop if and only if any of
1172     /// those types require drop. If the ADT is known to always need drop
1173     /// then `Err(AlwaysRequiresDrop)` is returned.
1174     query adt_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1175         desc { |tcx| "computing when `{}` needs drop", tcx.def_path_str(def_id) }
1176         cache_on_disk_if { true }
1177     }
1178
1179     /// A list of types where the ADT requires drop if and only if any of those types
1180     /// has significant drop. A type marked with the attribute `rustc_insignificant_dtor`
1181     /// is considered to not be significant. A drop is significant if it is implemented
1182     /// by the user or does anything that will have any observable behavior (other than
1183     /// freeing up memory). If the ADT is known to have a significant destructor then
1184     /// `Err(AlwaysRequiresDrop)` is returned.
1185     query adt_significant_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1186         desc { |tcx| "computing when `{}` has a significant destructor", tcx.def_path_str(def_id) }
1187         cache_on_disk_if { false }
1188     }
1189
1190     /// Computes the layout of a type. Note that this implicitly
1191     /// executes in "reveal all" mode, and will normalize the input type.
1192     query layout_of(
1193         key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1194     ) -> Result<ty::layout::TyAndLayout<'tcx>, ty::layout::LayoutError<'tcx>> {
1195         desc { "computing layout of `{}`", key.value }
1196         remap_env_constness
1197     }
1198
1199     /// Compute a `FnAbi` suitable for indirect calls, i.e. to `fn` pointers.
1200     ///
1201     /// NB: this doesn't handle virtual calls - those should use `fn_abi_of_instance`
1202     /// instead, where the instance is an `InstanceDef::Virtual`.
1203     query fn_abi_of_fn_ptr(
1204         key: ty::ParamEnvAnd<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1205     ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1206         desc { "computing call ABI of `{}` function pointers", key.value.0 }
1207         remap_env_constness
1208     }
1209
1210     /// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for
1211     /// direct calls to an `fn`.
1212     ///
1213     /// NB: that includes virtual calls, which are represented by "direct calls"
1214     /// to an `InstanceDef::Virtual` instance (of `<dyn Trait as Trait>::fn`).
1215     query fn_abi_of_instance(
1216         key: ty::ParamEnvAnd<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1217     ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1218         desc { "computing call ABI of `{}`", key.value.0 }
1219         remap_env_constness
1220     }
1221
1222     query dylib_dependency_formats(_: CrateNum)
1223                                     -> &'tcx [(CrateNum, LinkagePreference)] {
1224         desc { "dylib dependency formats of crate" }
1225         separate_provide_extern
1226     }
1227
1228     query dependency_formats(_: ()) -> Lrc<crate::middle::dependency_format::Dependencies> {
1229         desc { "get the linkage format of all dependencies" }
1230     }
1231
1232     query is_compiler_builtins(_: CrateNum) -> bool {
1233         fatal_cycle
1234         desc { "checking if the crate is_compiler_builtins" }
1235         separate_provide_extern
1236     }
1237     query has_global_allocator(_: CrateNum) -> bool {
1238         // This query depends on untracked global state in CStore
1239         eval_always
1240         fatal_cycle
1241         desc { "checking if the crate has_global_allocator" }
1242         separate_provide_extern
1243     }
1244     query has_panic_handler(_: CrateNum) -> bool {
1245         fatal_cycle
1246         desc { "checking if the crate has_panic_handler" }
1247         separate_provide_extern
1248     }
1249     query is_profiler_runtime(_: CrateNum) -> bool {
1250         fatal_cycle
1251         desc { "query a crate is `#![profiler_runtime]`" }
1252         separate_provide_extern
1253     }
1254     query panic_strategy(_: CrateNum) -> PanicStrategy {
1255         fatal_cycle
1256         desc { "query a crate's configured panic strategy" }
1257         separate_provide_extern
1258     }
1259     query panic_in_drop_strategy(_: CrateNum) -> PanicStrategy {
1260         fatal_cycle
1261         desc { "query a crate's configured panic-in-drop strategy" }
1262         separate_provide_extern
1263     }
1264     query is_no_builtins(_: CrateNum) -> bool {
1265         fatal_cycle
1266         desc { "test whether a crate has `#![no_builtins]`" }
1267         separate_provide_extern
1268     }
1269     query symbol_mangling_version(_: CrateNum) -> SymbolManglingVersion {
1270         fatal_cycle
1271         desc { "query a crate's symbol mangling version" }
1272         separate_provide_extern
1273     }
1274
1275     query extern_crate(def_id: DefId) -> Option<&'tcx ExternCrate> {
1276         eval_always
1277         desc { "getting crate's ExternCrateData" }
1278         separate_provide_extern
1279     }
1280
1281     query specializes(_: (DefId, DefId)) -> bool {
1282         desc { "computing whether impls specialize one another" }
1283     }
1284     query in_scope_traits_map(_: LocalDefId)
1285         -> Option<&'tcx FxHashMap<ItemLocalId, Box<[TraitCandidate]>>> {
1286         desc { "traits in scope at a block" }
1287     }
1288
1289     query module_reexports(def_id: LocalDefId) -> Option<&'tcx [ModChild]> {
1290         desc { |tcx| "looking up reexports of module `{}`", tcx.def_path_str(def_id.to_def_id()) }
1291     }
1292
1293     query impl_defaultness(def_id: DefId) -> hir::Defaultness {
1294         desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
1295         separate_provide_extern
1296     }
1297
1298     query impl_constness(def_id: DefId) -> hir::Constness {
1299         desc { |tcx| "looking up whether `{}` is a const impl", tcx.def_path_str(def_id) }
1300         separate_provide_extern
1301     }
1302
1303     query check_item_well_formed(key: LocalDefId) -> () {
1304         desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1305     }
1306     query check_trait_item_well_formed(key: LocalDefId) -> () {
1307         desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1308     }
1309     query check_impl_item_well_formed(key: LocalDefId) -> () {
1310         desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1311     }
1312
1313     // The `DefId`s of all non-generic functions and statics in the given crate
1314     // that can be reached from outside the crate.
1315     //
1316     // We expect this items to be available for being linked to.
1317     //
1318     // This query can also be called for `LOCAL_CRATE`. In this case it will
1319     // compute which items will be reachable to other crates, taking into account
1320     // the kind of crate that is currently compiled. Crates with only a
1321     // C interface have fewer reachable things.
1322     //
1323     // Does not include external symbols that don't have a corresponding DefId,
1324     // like the compiler-generated `main` function and so on.
1325     query reachable_non_generics(_: CrateNum)
1326         -> DefIdMap<SymbolExportLevel> {
1327         storage(ArenaCacheSelector<'tcx>)
1328         desc { "looking up the exported symbols of a crate" }
1329         separate_provide_extern
1330     }
1331     query is_reachable_non_generic(def_id: DefId) -> bool {
1332         desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
1333         separate_provide_extern
1334     }
1335     query is_unreachable_local_definition(def_id: LocalDefId) -> bool {
1336         desc { |tcx|
1337             "checking whether `{}` is reachable from outside the crate",
1338             tcx.def_path_str(def_id.to_def_id()),
1339         }
1340     }
1341
1342     /// The entire set of monomorphizations the local crate can safely link
1343     /// to because they are exported from upstream crates. Do not depend on
1344     /// this directly, as its value changes anytime a monomorphization gets
1345     /// added or removed in any upstream crate. Instead use the narrower
1346     /// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even
1347     /// better, `Instance::upstream_monomorphization()`.
1348     query upstream_monomorphizations(_: ()) -> DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1349         storage(ArenaCacheSelector<'tcx>)
1350         desc { "collecting available upstream monomorphizations" }
1351     }
1352
1353     /// Returns the set of upstream monomorphizations available for the
1354     /// generic function identified by the given `def_id`. The query makes
1355     /// sure to make a stable selection if the same monomorphization is
1356     /// available in multiple upstream crates.
1357     ///
1358     /// You likely want to call `Instance::upstream_monomorphization()`
1359     /// instead of invoking this query directly.
1360     query upstream_monomorphizations_for(def_id: DefId)
1361         -> Option<&'tcx FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1362             desc { |tcx|
1363                 "collecting available upstream monomorphizations for `{}`",
1364                 tcx.def_path_str(def_id),
1365             }
1366             separate_provide_extern
1367         }
1368
1369     /// Returns the upstream crate that exports drop-glue for the given
1370     /// type (`substs` is expected to be a single-item list containing the
1371     /// type one wants drop-glue for).
1372     ///
1373     /// This is a subset of `upstream_monomorphizations_for` in order to
1374     /// increase dep-tracking granularity. Otherwise adding or removing any
1375     /// type with drop-glue in any upstream crate would invalidate all
1376     /// functions calling drop-glue of an upstream type.
1377     ///
1378     /// You likely want to call `Instance::upstream_monomorphization()`
1379     /// instead of invoking this query directly.
1380     ///
1381     /// NOTE: This query could easily be extended to also support other
1382     ///       common functions that have are large set of monomorphizations
1383     ///       (like `Clone::clone` for example).
1384     query upstream_drop_glue_for(substs: SubstsRef<'tcx>) -> Option<CrateNum> {
1385         desc { "available upstream drop-glue for `{:?}`", substs }
1386     }
1387
1388     query foreign_modules(_: CrateNum) -> Lrc<FxHashMap<DefId, ForeignModule>> {
1389         desc { "looking up the foreign modules of a linked crate" }
1390         separate_provide_extern
1391     }
1392
1393     /// Identifies the entry-point (e.g., the `main` function) for a given
1394     /// crate, returning `None` if there is no entry point (such as for library crates).
1395     query entry_fn(_: ()) -> Option<(DefId, EntryFnType)> {
1396         desc { "looking up the entry function of a crate" }
1397     }
1398     query proc_macro_decls_static(_: ()) -> Option<LocalDefId> {
1399         desc { "looking up the derive registrar for a crate" }
1400     }
1401     // The macro which defines `rustc_metadata::provide_extern` depends on this query's name.
1402     // Changing the name should cause a compiler error, but in case that changes, be aware.
1403     query crate_hash(_: CrateNum) -> Svh {
1404         eval_always
1405         desc { "looking up the hash a crate" }
1406         separate_provide_extern
1407     }
1408     query crate_host_hash(_: CrateNum) -> Option<Svh> {
1409         eval_always
1410         desc { "looking up the hash of a host version of a crate" }
1411         separate_provide_extern
1412     }
1413     query extra_filename(_: CrateNum) -> String {
1414         eval_always
1415         desc { "looking up the extra filename for a crate" }
1416         separate_provide_extern
1417     }
1418     query crate_extern_paths(_: CrateNum) -> Vec<PathBuf> {
1419         eval_always
1420         desc { "looking up the paths for extern crates" }
1421         separate_provide_extern
1422     }
1423
1424     /// Given a crate and a trait, look up all impls of that trait in the crate.
1425     /// Return `(impl_id, self_ty)`.
1426     query implementations_of_trait(_: (CrateNum, DefId)) -> &'tcx [(DefId, Option<SimplifiedType>)] {
1427         desc { "looking up implementations of a trait in a crate" }
1428         separate_provide_extern
1429     }
1430
1431     query is_dllimport_foreign_item(def_id: DefId) -> bool {
1432         desc { |tcx| "is_dllimport_foreign_item({})", tcx.def_path_str(def_id) }
1433     }
1434     query is_statically_included_foreign_item(def_id: DefId) -> bool {
1435         desc { |tcx| "is_statically_included_foreign_item({})", tcx.def_path_str(def_id) }
1436     }
1437     query native_library_kind(def_id: DefId)
1438         -> Option<NativeLibKind> {
1439         desc { |tcx| "native_library_kind({})", tcx.def_path_str(def_id) }
1440     }
1441
1442     /// Does lifetime resolution, but does not descend into trait items. This
1443     /// should only be used for resolving lifetimes of on trait definitions,
1444     /// and is used to avoid cycles. Importantly, `resolve_lifetimes` still visits
1445     /// the same lifetimes and is responsible for diagnostics.
1446     /// See `rustc_resolve::late::lifetimes for details.
1447     query resolve_lifetimes_trait_definition(_: LocalDefId) -> ResolveLifetimes {
1448         storage(ArenaCacheSelector<'tcx>)
1449         desc { "resolving lifetimes for a trait definition" }
1450     }
1451     /// Does lifetime resolution on items. Importantly, we can't resolve
1452     /// lifetimes directly on things like trait methods, because of trait params.
1453     /// See `rustc_resolve::late::lifetimes for details.
1454     query resolve_lifetimes(_: LocalDefId) -> ResolveLifetimes {
1455         storage(ArenaCacheSelector<'tcx>)
1456         desc { "resolving lifetimes" }
1457     }
1458     query named_region_map(_: LocalDefId) ->
1459         Option<&'tcx FxHashMap<ItemLocalId, Region>> {
1460         desc { "looking up a named region" }
1461     }
1462     query is_late_bound_map(_: LocalDefId) ->
1463         Option<(LocalDefId, &'tcx FxHashSet<ItemLocalId>)> {
1464         desc { "testing if a region is late bound" }
1465     }
1466     /// For a given item (like a struct), gets the default lifetimes to be used
1467     /// for each parameter if a trait object were to be passed for that parameter.
1468     /// For example, for `struct Foo<'a, T, U>`, this would be `['static, 'static]`.
1469     /// For `struct Foo<'a, T: 'a, U>`, this would instead be `['a, 'static]`.
1470     query object_lifetime_defaults_map(_: LocalDefId)
1471         -> Option<Vec<ObjectLifetimeDefault>> {
1472         desc { "looking up lifetime defaults for a region on an item" }
1473     }
1474     query late_bound_vars_map(_: LocalDefId)
1475         -> Option<&'tcx FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>> {
1476         desc { "looking up late bound vars" }
1477     }
1478
1479     query lifetime_scope_map(_: LocalDefId) -> Option<FxHashMap<ItemLocalId, LifetimeScopeForPath>> {
1480         desc { "finds the lifetime scope for an HirId of a PathSegment" }
1481     }
1482
1483     query visibility(def_id: DefId) -> ty::Visibility {
1484         desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
1485         separate_provide_extern
1486     }
1487
1488     /// Computes the set of modules from which this type is visibly uninhabited.
1489     /// To check whether a type is uninhabited at all (not just from a given module), you could
1490     /// check whether the forest is empty.
1491     query type_uninhabited_from(
1492         key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1493     ) -> ty::inhabitedness::DefIdForest {
1494         desc { "computing the inhabitedness of `{:?}`", key }
1495         remap_env_constness
1496     }
1497
1498     query dep_kind(_: CrateNum) -> CrateDepKind {
1499         eval_always
1500         desc { "fetching what a dependency looks like" }
1501         separate_provide_extern
1502     }
1503
1504     /// Gets the name of the crate.
1505     query crate_name(_: CrateNum) -> Symbol {
1506         eval_always
1507         desc { "fetching what a crate is named" }
1508         separate_provide_extern
1509     }
1510     query module_children(def_id: DefId) -> &'tcx [ModChild] {
1511         desc { |tcx| "collecting child items of module `{}`", tcx.def_path_str(def_id) }
1512         separate_provide_extern
1513     }
1514     query extern_mod_stmt_cnum(def_id: LocalDefId) -> Option<CrateNum> {
1515         desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1516     }
1517
1518     query lib_features(_: ()) -> LibFeatures {
1519         storage(ArenaCacheSelector<'tcx>)
1520         desc { "calculating the lib features map" }
1521     }
1522     query defined_lib_features(_: CrateNum)
1523         -> &'tcx [(Symbol, Option<Symbol>)] {
1524         desc { "calculating the lib features defined in a crate" }
1525         separate_provide_extern
1526     }
1527     /// Returns the lang items defined in another crate by loading it from metadata.
1528     query get_lang_items(_: ()) -> LanguageItems {
1529         storage(ArenaCacheSelector<'tcx>)
1530         eval_always
1531         desc { "calculating the lang items map" }
1532     }
1533
1534     /// Returns all diagnostic items defined in all crates.
1535     query all_diagnostic_items(_: ()) -> rustc_hir::diagnostic_items::DiagnosticItems {
1536         storage(ArenaCacheSelector<'tcx>)
1537         eval_always
1538         desc { "calculating the diagnostic items map" }
1539     }
1540
1541     /// Returns the lang items defined in another crate by loading it from metadata.
1542     query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, usize)] {
1543         desc { "calculating the lang items defined in a crate" }
1544         separate_provide_extern
1545     }
1546
1547     /// Returns the diagnostic items defined in a crate.
1548     query diagnostic_items(_: CrateNum) -> rustc_hir::diagnostic_items::DiagnosticItems {
1549         storage(ArenaCacheSelector<'tcx>)
1550         desc { "calculating the diagnostic items map in a crate" }
1551         separate_provide_extern
1552     }
1553
1554     query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
1555         desc { "calculating the missing lang items in a crate" }
1556         separate_provide_extern
1557     }
1558     query visible_parent_map(_: ()) -> Lrc<DefIdMap<DefId>> {
1559         desc { "calculating the visible parent map" }
1560     }
1561     query trimmed_def_paths(_: ()) -> FxHashMap<DefId, Symbol> {
1562         storage(ArenaCacheSelector<'tcx>)
1563         desc { "calculating trimmed def paths" }
1564     }
1565     query missing_extern_crate_item(_: CrateNum) -> bool {
1566         eval_always
1567         desc { "seeing if we're missing an `extern crate` item for this crate" }
1568         separate_provide_extern
1569     }
1570     query used_crate_source(_: CrateNum) -> Lrc<CrateSource> {
1571         eval_always
1572         desc { "looking at the source for a crate" }
1573         separate_provide_extern
1574     }
1575     query postorder_cnums(_: ()) -> &'tcx [CrateNum] {
1576         eval_always
1577         desc { "generating a postorder list of CrateNums" }
1578     }
1579     /// Returns whether or not the crate with CrateNum 'cnum'
1580     /// is marked as a private dependency
1581     query is_private_dep(c: CrateNum) -> bool {
1582         eval_always
1583         desc { "check whether crate {} is a private dependency", c }
1584         separate_provide_extern
1585     }
1586     query allocator_kind(_: ()) -> Option<AllocatorKind> {
1587         eval_always
1588         desc { "allocator kind for the current crate" }
1589     }
1590
1591     query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
1592         desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) }
1593     }
1594     query maybe_unused_trait_import(def_id: LocalDefId) -> bool {
1595         desc { |tcx| "maybe_unused_trait_import for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1596     }
1597     query maybe_unused_extern_crates(_: ()) -> &'tcx [(LocalDefId, Span)] {
1598         desc { "looking up all possibly unused extern crates" }
1599     }
1600     query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx FxHashSet<Symbol> {
1601         desc { |tcx| "names_imported_by_glob_use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1602     }
1603
1604     query stability_index(_: ()) -> stability::Index<'tcx> {
1605         storage(ArenaCacheSelector<'tcx>)
1606         eval_always
1607         desc { "calculating the stability index for the local crate" }
1608     }
1609     query crates(_: ()) -> &'tcx [CrateNum] {
1610         eval_always
1611         desc { "fetching all foreign CrateNum instances" }
1612     }
1613
1614     /// A list of all traits in a crate, used by rustdoc and error reporting.
1615     /// NOTE: Not named just `traits` due to a naming conflict.
1616     query traits_in_crate(_: CrateNum) -> &'tcx [DefId] {
1617         desc { "fetching all traits in a crate" }
1618         separate_provide_extern
1619     }
1620
1621     /// The list of symbols exported from the given crate.
1622     ///
1623     /// - All names contained in `exported_symbols(cnum)` are guaranteed to
1624     ///   correspond to a publicly visible symbol in `cnum` machine code.
1625     /// - The `exported_symbols` sets of different crates do not intersect.
1626     query exported_symbols(_: CrateNum)
1627         -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] {
1628         desc { "exported_symbols" }
1629         separate_provide_extern
1630     }
1631
1632     query collect_and_partition_mono_items(_: ()) -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
1633         eval_always
1634         desc { "collect_and_partition_mono_items" }
1635     }
1636     query is_codegened_item(def_id: DefId) -> bool {
1637         desc { |tcx| "determining whether `{}` needs codegen", tcx.def_path_str(def_id) }
1638     }
1639
1640     /// All items participating in code generation together with items inlined into them.
1641     query codegened_and_inlined_items(_: ()) -> &'tcx DefIdSet {
1642         eval_always
1643        desc { "codegened_and_inlined_items" }
1644     }
1645
1646     query codegen_unit(_: Symbol) -> &'tcx CodegenUnit<'tcx> {
1647         desc { "codegen_unit" }
1648     }
1649     query unused_generic_params(key: ty::InstanceDef<'tcx>) -> FiniteBitSet<u32> {
1650         cache_on_disk_if { key.def_id().is_local() }
1651         desc {
1652             |tcx| "determining which generic parameters are unused by `{}`",
1653                 tcx.def_path_str(key.def_id())
1654         }
1655         separate_provide_extern
1656     }
1657     query backend_optimization_level(_: ()) -> OptLevel {
1658         desc { "optimization level used by backend" }
1659     }
1660
1661     query output_filenames(_: ()) -> Arc<OutputFilenames> {
1662         eval_always
1663         desc { "output_filenames" }
1664     }
1665
1666     /// Do not call this query directly: invoke `normalize` instead.
1667     query normalize_projection_ty(
1668         goal: CanonicalProjectionGoal<'tcx>
1669     ) -> Result<
1670         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
1671         NoSolution,
1672     > {
1673         desc { "normalizing `{:?}`", goal }
1674         remap_env_constness
1675     }
1676
1677     /// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
1678     query try_normalize_generic_arg_after_erasing_regions(
1679         goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
1680     ) -> Result<GenericArg<'tcx>, NoSolution> {
1681         desc { "normalizing `{}`", goal.value }
1682         remap_env_constness
1683     }
1684
1685     /// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
1686     query try_normalize_mir_const_after_erasing_regions(
1687         goal: ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1688     ) -> Result<mir::ConstantKind<'tcx>, NoSolution> {
1689         desc { "normalizing `{}`", goal.value }
1690         remap_env_constness
1691     }
1692
1693     query implied_outlives_bounds(
1694         goal: CanonicalTyGoal<'tcx>
1695     ) -> Result<
1696         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
1697         NoSolution,
1698     > {
1699         desc { "computing implied outlives bounds for `{:?}`", goal }
1700         remap_env_constness
1701     }
1702
1703     /// Do not call this query directly: invoke `infcx.at().dropck_outlives()` instead.
1704     query dropck_outlives(
1705         goal: CanonicalTyGoal<'tcx>
1706     ) -> Result<
1707         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>,
1708         NoSolution,
1709     > {
1710         desc { "computing dropck types for `{:?}`", goal }
1711         remap_env_constness
1712     }
1713
1714     /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
1715     /// `infcx.predicate_must_hold()` instead.
1716     query evaluate_obligation(
1717         goal: CanonicalPredicateGoal<'tcx>
1718     ) -> Result<traits::EvaluationResult, traits::OverflowError> {
1719         desc { "evaluating trait selection obligation `{}`", goal.value.value }
1720     }
1721
1722     query evaluate_goal(
1723         goal: traits::CanonicalChalkEnvironmentAndGoal<'tcx>
1724     ) -> Result<
1725         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1726         NoSolution
1727     > {
1728         desc { "evaluating trait selection obligation `{}`", goal.value }
1729     }
1730
1731     /// Do not call this query directly: part of the `Eq` type-op
1732     query type_op_ascribe_user_type(
1733         goal: CanonicalTypeOpAscribeUserTypeGoal<'tcx>
1734     ) -> Result<
1735         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1736         NoSolution,
1737     > {
1738         desc { "evaluating `type_op_ascribe_user_type` `{:?}`", goal }
1739         remap_env_constness
1740     }
1741
1742     /// Do not call this query directly: part of the `Eq` type-op
1743     query type_op_eq(
1744         goal: CanonicalTypeOpEqGoal<'tcx>
1745     ) -> Result<
1746         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1747         NoSolution,
1748     > {
1749         desc { "evaluating `type_op_eq` `{:?}`", goal }
1750         remap_env_constness
1751     }
1752
1753     /// Do not call this query directly: part of the `Subtype` type-op
1754     query type_op_subtype(
1755         goal: CanonicalTypeOpSubtypeGoal<'tcx>
1756     ) -> Result<
1757         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1758         NoSolution,
1759     > {
1760         desc { "evaluating `type_op_subtype` `{:?}`", goal }
1761         remap_env_constness
1762     }
1763
1764     /// Do not call this query directly: part of the `ProvePredicate` type-op
1765     query type_op_prove_predicate(
1766         goal: CanonicalTypeOpProvePredicateGoal<'tcx>
1767     ) -> Result<
1768         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1769         NoSolution,
1770     > {
1771         desc { "evaluating `type_op_prove_predicate` `{:?}`", goal }
1772     }
1773
1774     /// Do not call this query directly: part of the `Normalize` type-op
1775     query type_op_normalize_ty(
1776         goal: CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
1777     ) -> Result<
1778         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>,
1779         NoSolution,
1780     > {
1781         desc { "normalizing `{:?}`", goal }
1782         remap_env_constness
1783     }
1784
1785     /// Do not call this query directly: part of the `Normalize` type-op
1786     query type_op_normalize_predicate(
1787         goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
1788     ) -> Result<
1789         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>,
1790         NoSolution,
1791     > {
1792         desc { "normalizing `{:?}`", goal }
1793         remap_env_constness
1794     }
1795
1796     /// Do not call this query directly: part of the `Normalize` type-op
1797     query type_op_normalize_poly_fn_sig(
1798         goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
1799     ) -> Result<
1800         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>,
1801         NoSolution,
1802     > {
1803         desc { "normalizing `{:?}`", goal }
1804         remap_env_constness
1805     }
1806
1807     /// Do not call this query directly: part of the `Normalize` type-op
1808     query type_op_normalize_fn_sig(
1809         goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
1810     ) -> Result<
1811         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>,
1812         NoSolution,
1813     > {
1814         desc { "normalizing `{:?}`", goal }
1815         remap_env_constness
1816     }
1817
1818     query subst_and_check_impossible_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
1819         desc { |tcx|
1820             "impossible substituted predicates:`{}`",
1821             tcx.def_path_str(key.0)
1822         }
1823     }
1824
1825     query method_autoderef_steps(
1826         goal: CanonicalTyGoal<'tcx>
1827     ) -> MethodAutoderefStepsResult<'tcx> {
1828         desc { "computing autoderef types for `{:?}`", goal }
1829         remap_env_constness
1830     }
1831
1832     query supported_target_features(_: CrateNum) -> FxHashMap<String, Option<Symbol>> {
1833         storage(ArenaCacheSelector<'tcx>)
1834         eval_always
1835         desc { "looking up supported target features" }
1836     }
1837
1838     /// Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
1839     query instance_def_size_estimate(def: ty::InstanceDef<'tcx>)
1840         -> usize {
1841         desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) }
1842     }
1843
1844     query features_query(_: ()) -> &'tcx rustc_feature::Features {
1845         eval_always
1846         desc { "looking up enabled feature gates" }
1847     }
1848
1849     /// Attempt to resolve the given `DefId` to an `Instance`, for the
1850     /// given generics args (`SubstsRef`), returning one of:
1851     ///  * `Ok(Some(instance))` on success
1852     ///  * `Ok(None)` when the `SubstsRef` are still too generic,
1853     ///    and therefore don't allow finding the final `Instance`
1854     ///  * `Err(ErrorReported)` when the `Instance` resolution process
1855     ///    couldn't complete due to errors elsewhere - this is distinct
1856     ///    from `Ok(None)` to avoid misleading diagnostics when an error
1857     ///    has already been/will be emitted, for the original cause
1858     query resolve_instance(
1859         key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>
1860     ) -> Result<Option<ty::Instance<'tcx>>, ErrorReported> {
1861         desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) }
1862         remap_env_constness
1863     }
1864
1865     query resolve_instance_of_const_arg(
1866         key: ty::ParamEnvAnd<'tcx, (LocalDefId, DefId, SubstsRef<'tcx>)>
1867     ) -> Result<Option<ty::Instance<'tcx>>, ErrorReported> {
1868         desc {
1869             "resolving instance of the const argument `{}`",
1870             ty::Instance::new(key.value.0.to_def_id(), key.value.2),
1871         }
1872         remap_env_constness
1873     }
1874
1875     query normalize_opaque_types(key: &'tcx ty::List<ty::Predicate<'tcx>>) -> &'tcx ty::List<ty::Predicate<'tcx>> {
1876         desc { "normalizing opaque types in {:?}", key }
1877     }
1878
1879     /// Checks whether a type is definitely uninhabited. This is
1880     /// conservative: for some types that are uninhabited we return `false`,
1881     /// but we only return `true` for types that are definitely uninhabited.
1882     /// `ty.conservative_is_privately_uninhabited` implies that any value of type `ty`
1883     /// will be `Abi::Uninhabited`. (Note that uninhabited types may have nonzero
1884     /// size, to account for partial initialisation. See #49298 for details.)
1885     query conservative_is_privately_uninhabited(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1886         desc { "conservatively checking if {:?} is privately uninhabited", key }
1887         remap_env_constness
1888     }
1889
1890     query limits(key: ()) -> Limits {
1891         desc { "looking up limits" }
1892     }
1893
1894     /// Performs an HIR-based well-formed check on the item with the given `HirId`. If
1895     /// we get an `Unimplemented` error that matches the provided `Predicate`, return
1896     /// the cause of the newly created obligation.
1897     ///
1898     /// This is only used by error-reporting code to get a better cause (in particular, a better
1899     /// span) for an *existing* error. Therefore, it is best-effort, and may never handle
1900     /// all of the cases that the normal `ty::Ty`-based wfcheck does. This is fine,
1901     /// because the `ty::Ty`-based wfcheck is always run.
1902     query diagnostic_hir_wf_check(key: (ty::Predicate<'tcx>, traits::WellFormedLoc)) -> Option<traits::ObligationCause<'tcx>> {
1903         eval_always
1904         no_hash
1905         desc { "performing HIR wf-checking for predicate {:?} at item {:?}", key.0, key.1 }
1906     }
1907 }