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