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