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