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