]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_middle/src/query/mod.rs
Rollup merge of #95441 - AlecGoncharow:issue-95204-fix, r=Mark-Simulacrum
[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     /// Returns the [`Ty`][rustc_middle::ty::Ty] of the given [`DefId`]. If the [`DefId`] points
128     /// to an alias, it will "skip" this alias to return the aliased type.
129     ///
130     /// [`DefId`]: rustc_hir::def_id::DefId
131     query type_of(key: DefId) -> Ty<'tcx> {
132         desc { |tcx|
133             "{action} `{path}`",
134             action = {
135                 use rustc_hir::def::DefKind;
136                 match tcx.def_kind(key) {
137                     DefKind::TyAlias => "expanding type alias",
138                     DefKind::TraitAlias => "expanding trait alias",
139                     _ => "computing type of",
140                 }
141             },
142             path = tcx.def_path_str(key),
143         }
144         cache_on_disk_if { key.is_local() }
145         separate_provide_extern
146     }
147
148     query analysis(key: ()) -> Result<(), ErrorGuaranteed> {
149         eval_always
150         desc { "running analysis passes on this crate" }
151     }
152
153     /// Maps from the `DefId` of an item (trait/struct/enum/fn) to its
154     /// associated generics.
155     query generics_of(key: DefId) -> ty::Generics {
156         desc { |tcx| "computing generics of `{}`", tcx.def_path_str(key) }
157         storage(ArenaCacheSelector<'tcx>)
158         cache_on_disk_if { key.is_local() }
159         separate_provide_extern
160     }
161
162     /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
163     /// predicates (where-clauses) that must be proven true in order
164     /// to reference it. This is almost always the "predicates query"
165     /// that you want.
166     ///
167     /// `predicates_of` builds on `predicates_defined_on` -- in fact,
168     /// it is almost always the same as that query, except for the
169     /// case of traits. For traits, `predicates_of` contains
170     /// an additional `Self: Trait<...>` predicate that users don't
171     /// actually write. This reflects the fact that to invoke the
172     /// trait (e.g., via `Default::default`) you must supply types
173     /// that actually implement the trait. (However, this extra
174     /// predicate gets in the way of some checks, which are intended
175     /// to operate over only the actual where-clauses written by the
176     /// user.)
177     query predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
178         desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
179         cache_on_disk_if { key.is_local() }
180     }
181
182     /// Returns the list of bounds that can be used for
183     /// `SelectionCandidate::ProjectionCandidate(_)` and
184     /// `ProjectionTyCandidate::TraitDef`.
185     /// Specifically this is the bounds written on the trait's type
186     /// definition, or those after the `impl` keyword
187     ///
188     /// ```ignore (incomplete)
189     /// type X: Bound + 'lt
190     /// //      ^^^^^^^^^^^
191     /// impl Debug + Display
192     /// //   ^^^^^^^^^^^^^^^
193     /// ```
194     ///
195     /// `key` is the `DefId` of the associated type or opaque type.
196     ///
197     /// Bounds from the parent (e.g. with nested impl trait) are not included.
198     query explicit_item_bounds(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
199         desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) }
200         separate_provide_extern
201     }
202
203     /// Elaborated version of the predicates from `explicit_item_bounds`.
204     ///
205     /// For example:
206     ///
207     /// ```
208     /// trait MyTrait {
209     ///     type MyAType: Eq + ?Sized;
210     /// }
211     /// ```
212     ///
213     /// `explicit_item_bounds` returns `[<Self as MyTrait>::MyAType: Eq]`,
214     /// and `item_bounds` returns
215     /// ```text
216     /// [
217     ///     <Self as Trait>::MyAType: Eq,
218     ///     <Self as Trait>::MyAType: PartialEq<<Self as Trait>::MyAType>
219     /// ]
220     /// ```
221     ///
222     /// Bounds from the parent (e.g. with nested impl trait) are not included.
223     query item_bounds(key: DefId) -> &'tcx ty::List<ty::Predicate<'tcx>> {
224         desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) }
225     }
226
227     query native_libraries(_: CrateNum) -> Vec<NativeLib> {
228         storage(ArenaCacheSelector<'tcx>)
229         desc { "looking up the native libraries of a linked crate" }
230         separate_provide_extern
231     }
232
233     query lint_levels(_: ()) -> LintLevelMap {
234         storage(ArenaCacheSelector<'tcx>)
235         eval_always
236         desc { "computing the lint levels for items in this crate" }
237     }
238
239     query parent_module_from_def_id(key: LocalDefId) -> LocalDefId {
240         eval_always
241         desc { |tcx| "parent module of `{}`", tcx.def_path_str(key.to_def_id()) }
242     }
243
244     query expn_that_defined(key: DefId) -> rustc_span::ExpnId {
245         // This query reads from untracked data in definitions.
246         eval_always
247         desc { |tcx| "expansion that defined `{}`", tcx.def_path_str(key) }
248         separate_provide_extern
249     }
250
251     query is_panic_runtime(_: CrateNum) -> bool {
252         fatal_cycle
253         desc { "checking if the crate is_panic_runtime" }
254         separate_provide_extern
255     }
256
257     /// Fetch the THIR for a given body. If typeck for that body failed, returns an empty `Thir`.
258     query thir_body(key: ty::WithOptConstParam<LocalDefId>)
259         -> Result<(&'tcx Steal<thir::Thir<'tcx>>, thir::ExprId), ErrorGuaranteed>
260     {
261         // Perf tests revealed that hashing THIR is inefficient (see #85729).
262         no_hash
263         desc { |tcx| "building THIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
264     }
265
266     /// Create a THIR tree for debugging.
267     query thir_tree(key: ty::WithOptConstParam<LocalDefId>) -> String {
268         no_hash
269         storage(ArenaCacheSelector<'tcx>)
270         desc { |tcx| "constructing THIR tree for `{}`", tcx.def_path_str(key.did.to_def_id()) }
271     }
272
273     /// Set of all the `DefId`s in this crate that have MIR associated with
274     /// them. This includes all the body owners, but also things like struct
275     /// constructors.
276     query mir_keys(_: ()) -> rustc_data_structures::fx::FxIndexSet<LocalDefId> {
277         storage(ArenaCacheSelector<'tcx>)
278         desc { "getting a list of all mir_keys" }
279     }
280
281     /// Maps DefId's that have an associated `mir::Body` to the result
282     /// of the MIR const-checking pass. This is the set of qualifs in
283     /// the final value of a `const`.
284     query mir_const_qualif(key: DefId) -> mir::ConstQualifs {
285         desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
286         cache_on_disk_if { key.is_local() }
287         separate_provide_extern
288     }
289     query mir_const_qualif_const_arg(
290         key: (LocalDefId, DefId)
291     ) -> mir::ConstQualifs {
292         desc {
293             |tcx| "const checking the const argument `{}`",
294             tcx.def_path_str(key.0.to_def_id())
295         }
296     }
297
298     /// Fetch the MIR for a given `DefId` right after it's built - this includes
299     /// unreachable code.
300     query mir_built(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
301         desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
302     }
303
304     /// Fetch the MIR for a given `DefId` up till the point where it is
305     /// ready for const qualification.
306     ///
307     /// See the README for the `mir` module for details.
308     query mir_const(key: ty::WithOptConstParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
309         desc {
310             |tcx| "processing MIR for {}`{}`",
311             if key.const_param_did.is_some() { "the const argument " } else { "" },
312             tcx.def_path_str(key.did.to_def_id()),
313         }
314         no_hash
315     }
316
317     /// Try to build an abstract representation of the given constant.
318     query thir_abstract_const(
319         key: DefId
320     ) -> Result<Option<&'tcx [thir::abstract_const::Node<'tcx>]>, ErrorGuaranteed> {
321         desc {
322             |tcx| "building an abstract representation for {}", tcx.def_path_str(key),
323         }
324         separate_provide_extern
325     }
326     /// Try to build an abstract representation of the given constant.
327     query thir_abstract_const_of_const_arg(
328         key: (LocalDefId, DefId)
329     ) -> Result<Option<&'tcx [thir::abstract_const::Node<'tcx>]>, ErrorGuaranteed> {
330         desc {
331             |tcx|
332             "building an abstract representation for the const argument {}",
333             tcx.def_path_str(key.0.to_def_id()),
334         }
335     }
336
337     query try_unify_abstract_consts(key:
338         ty::ParamEnvAnd<'tcx, (ty::Unevaluated<'tcx, ()>, ty::Unevaluated<'tcx, ()>
339     )>) -> bool {
340         desc {
341             |tcx| "trying to unify the generic constants {} and {}",
342             tcx.def_path_str(key.value.0.def.did), tcx.def_path_str(key.value.1.def.did)
343         }
344     }
345
346     query mir_drops_elaborated_and_const_checked(
347         key: ty::WithOptConstParam<LocalDefId>
348     ) -> &'tcx Steal<mir::Body<'tcx>> {
349         no_hash
350         desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.did.to_def_id()) }
351     }
352
353     query mir_for_ctfe(
354         key: DefId
355     ) -> &'tcx mir::Body<'tcx> {
356         desc { |tcx| "caching mir of `{}` for CTFE", tcx.def_path_str(key) }
357         cache_on_disk_if { key.is_local() }
358         separate_provide_extern
359     }
360
361     query mir_for_ctfe_of_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::Body<'tcx> {
362         desc {
363             |tcx| "MIR for CTFE of the const argument `{}`",
364             tcx.def_path_str(key.0.to_def_id())
365         }
366     }
367
368     query mir_promoted(key: ty::WithOptConstParam<LocalDefId>) ->
369         (
370             &'tcx Steal<mir::Body<'tcx>>,
371             &'tcx Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>>
372         ) {
373         no_hash
374         desc {
375             |tcx| "processing {}`{}`",
376             if key.const_param_did.is_some() { "the const argument " } else { "" },
377             tcx.def_path_str(key.did.to_def_id()),
378         }
379     }
380
381     query symbols_for_closure_captures(
382         key: (LocalDefId, DefId)
383     ) -> Vec<rustc_span::Symbol> {
384         storage(ArenaCacheSelector<'tcx>)
385         desc {
386             |tcx| "symbols for captures of closure `{}` in `{}`",
387             tcx.def_path_str(key.1),
388             tcx.def_path_str(key.0.to_def_id())
389         }
390     }
391
392     /// MIR after our optimization passes have run. This is MIR that is ready
393     /// for codegen. This is also the only query that can fetch non-local MIR, at present.
394     query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> {
395         desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key) }
396         cache_on_disk_if { key.is_local() }
397         separate_provide_extern
398     }
399
400     /// Returns coverage summary info for a function, after executing the `InstrumentCoverage`
401     /// MIR pass (assuming the -Cinstrument-coverage option is enabled).
402     query coverageinfo(key: ty::InstanceDef<'tcx>) -> mir::CoverageInfo {
403         desc { |tcx| "retrieving coverage info from MIR for `{}`", tcx.def_path_str(key.def_id()) }
404         storage(ArenaCacheSelector<'tcx>)
405     }
406
407     /// Returns the `CodeRegions` for a function that has instrumented coverage, in case the
408     /// function was optimized out before codegen, and before being added to the Coverage Map.
409     query covered_code_regions(key: DefId) -> Vec<&'tcx mir::coverage::CodeRegion> {
410         desc {
411             |tcx| "retrieving the covered `CodeRegion`s, if instrumented, for `{}`",
412             tcx.def_path_str(key)
413         }
414         storage(ArenaCacheSelector<'tcx>)
415         cache_on_disk_if { key.is_local() }
416     }
417
418     /// The `DefId` is the `DefId` of the containing MIR body. Promoteds do not have their own
419     /// `DefId`. This function returns all promoteds in the specified body. The body references
420     /// promoteds by the `DefId` and the `mir::Promoted` index. This is necessary, because
421     /// after inlining a body may refer to promoteds from other bodies. In that case you still
422     /// need to use the `DefId` of the original body.
423     query promoted_mir(key: DefId) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
424         desc { |tcx| "optimizing promoted MIR for `{}`", tcx.def_path_str(key) }
425         cache_on_disk_if { key.is_local() }
426         separate_provide_extern
427     }
428     query promoted_mir_of_const_arg(
429         key: (LocalDefId, DefId)
430     ) -> &'tcx IndexVec<mir::Promoted, mir::Body<'tcx>> {
431         desc {
432             |tcx| "optimizing promoted MIR for the const argument `{}`",
433             tcx.def_path_str(key.0.to_def_id()),
434         }
435     }
436
437     /// Erases regions from `ty` to yield a new type.
438     /// Normally you would just use `tcx.erase_regions(value)`,
439     /// however, which uses this query as a kind of cache.
440     query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
441         // This query is not expected to have input -- as a result, it
442         // is not a good candidates for "replay" because it is essentially a
443         // pure function of its input (and hence the expectation is that
444         // no caller would be green **apart** from just these
445         // queries). Making it anonymous avoids hashing the result, which
446         // may save a bit of time.
447         anon
448         desc { "erasing regions from `{:?}`", ty }
449     }
450
451     query wasm_import_module_map(_: CrateNum) -> FxHashMap<DefId, String> {
452         storage(ArenaCacheSelector<'tcx>)
453         desc { "wasm import module map" }
454     }
455
456     /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
457     /// predicates (where-clauses) directly defined on it. This is
458     /// equal to the `explicit_predicates_of` predicates plus the
459     /// `inferred_outlives_of` predicates.
460     query predicates_defined_on(key: DefId) -> ty::GenericPredicates<'tcx> {
461         desc { |tcx| "computing predicates of `{}`", tcx.def_path_str(key) }
462     }
463
464     /// Returns everything that looks like a predicate written explicitly
465     /// by the user on a trait item.
466     ///
467     /// Traits are unusual, because predicates on associated types are
468     /// converted into bounds on that type for backwards compatibility:
469     ///
470     /// trait X where Self::U: Copy { type U; }
471     ///
472     /// becomes
473     ///
474     /// trait X { type U: Copy; }
475     ///
476     /// `explicit_predicates_of` and `explicit_item_bounds` will then take
477     /// the appropriate subsets of the predicates here.
478     query trait_explicit_predicates_and_bounds(key: LocalDefId) -> ty::GenericPredicates<'tcx> {
479         desc { |tcx| "computing explicit predicates of trait `{}`", tcx.def_path_str(key.to_def_id()) }
480     }
481
482     /// Returns the predicates written explicitly by the user.
483     query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
484         desc { |tcx| "computing explicit predicates of `{}`", tcx.def_path_str(key) }
485         separate_provide_extern
486     }
487
488     /// Returns the inferred outlives predicates (e.g., for `struct
489     /// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
490     query inferred_outlives_of(key: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
491         desc { |tcx| "computing inferred outlives predicates of `{}`", tcx.def_path_str(key) }
492         separate_provide_extern
493     }
494
495     /// Maps from the `DefId` of a trait to the list of
496     /// super-predicates. This is a subset of the full list of
497     /// predicates. We store these in a separate map because we must
498     /// evaluate them even during type conversion, often before the
499     /// full predicates are available (note that supertraits have
500     /// additional acyclicity requirements).
501     query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
502         desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) }
503         separate_provide_extern
504     }
505
506     /// The `Option<Ident>` is the name of an associated type. If it is `None`, then this query
507     /// returns the full set of predicates. If `Some<Ident>`, then the query returns only the
508     /// subset of super-predicates that reference traits that define the given associated type.
509     /// This is used to avoid cycles in resolving types like `T::Item`.
510     query super_predicates_that_define_assoc_type(key: (DefId, Option<rustc_span::symbol::Ident>)) -> ty::GenericPredicates<'tcx> {
511         desc { |tcx| "computing the super traits of `{}`{}",
512             tcx.def_path_str(key.0),
513             if let Some(assoc_name) = key.1 { format!(" with associated type name `{}`", assoc_name) } else { "".to_string() },
514         }
515     }
516
517     /// To avoid cycles within the predicates of a single item we compute
518     /// per-type-parameter predicates for resolving `T::AssocTy`.
519     query type_param_predicates(key: (DefId, LocalDefId, rustc_span::symbol::Ident)) -> ty::GenericPredicates<'tcx> {
520         desc { |tcx| "computing the bounds for type parameter `{}`", tcx.hir().ty_param_name(key.1) }
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 DropckConstraint<'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 impl_constness(key: DefId) -> hir::Constness {
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(generator_kind)` if the node pointed to by `def_id` is a generator.
590     query generator_kind(def_id: DefId) -> Option<hir::GeneratorKind> {
591         desc { |tcx| "looking up generator kind of `{}`", tcx.def_path_str(def_id) }
592         separate_provide_extern
593     }
594
595     /// Gets a map with the variance of every item; use `item_variance` instead.
596     query crate_variances(_: ()) -> ty::CrateVariancesMap<'tcx> {
597         storage(ArenaCacheSelector<'tcx>)
598         desc { "computing the variances for items in this crate" }
599     }
600
601     /// Maps from the `DefId` of a type or region parameter to its (inferred) variance.
602     query variances_of(def_id: DefId) -> &'tcx [ty::Variance] {
603         desc { |tcx| "computing the variances of `{}`", tcx.def_path_str(def_id) }
604         separate_provide_extern
605     }
606
607     /// Maps from thee `DefId` of a type to its (inferred) outlives.
608     query inferred_outlives_crate(_: ()) -> ty::CratePredicatesMap<'tcx> {
609         storage(ArenaCacheSelector<'tcx>)
610         desc { "computing the inferred outlives predicates for items in this crate" }
611     }
612
613     /// Maps from an impl/trait `DefId` to a list of the `DefId`s of its items.
614     query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
615         desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
616         separate_provide_extern
617     }
618
619     /// Maps from a trait item to the trait item "descriptor".
620     query associated_item(key: DefId) -> ty::AssocItem {
621         desc { |tcx| "computing associated item data for `{}`", tcx.def_path_str(key) }
622         storage(ArenaCacheSelector<'tcx>)
623         separate_provide_extern
624     }
625
626     /// Collects the associated items defined on a trait or impl.
627     query associated_items(key: DefId) -> ty::AssocItems<'tcx> {
628         storage(ArenaCacheSelector<'tcx>)
629         desc { |tcx| "collecting associated items of {}", tcx.def_path_str(key) }
630     }
631
632     /// Maps from associated items on a trait to the corresponding associated
633     /// item on the impl specified by `impl_id`.
634     ///
635     /// For example, with the following code
636     ///
637     /// ```
638     /// struct Type {}
639     ///                         // DefId
640     /// trait Trait {           // trait_id
641     ///     fn f();             // trait_f
642     ///     fn g() {}           // trait_g
643     /// }
644     ///
645     /// impl Trait for Type {   // impl_id
646     ///     fn f() {}           // impl_f
647     ///     fn g() {}           // impl_g
648     /// }
649     /// ```
650     ///
651     /// The map returned for `tcx.impl_item_implementor_ids(impl_id)` would be
652     ///`{ trait_f: impl_f, trait_g: impl_g }`
653     query impl_item_implementor_ids(impl_id: DefId) -> FxHashMap<DefId, DefId> {
654         storage(ArenaCacheSelector<'tcx>)
655         desc { |tcx| "comparing impl items against trait for {}", tcx.def_path_str(impl_id) }
656     }
657
658     /// Given an `impl_id`, return the trait it implements.
659     /// Return `None` if this is an inherent impl.
660     query impl_trait_ref(impl_id: DefId) -> Option<ty::TraitRef<'tcx>> {
661         desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
662         separate_provide_extern
663     }
664     query impl_polarity(impl_id: DefId) -> ty::ImplPolarity {
665         desc { |tcx| "computing implementation polarity of `{}`", tcx.def_path_str(impl_id) }
666         separate_provide_extern
667     }
668
669     query issue33140_self_ty(key: DefId) -> Option<ty::Ty<'tcx>> {
670         desc { |tcx| "computing Self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
671     }
672
673     /// Maps a `DefId` of a type to a list of its inherent impls.
674     /// Contains implementations of methods that are inherent to a type.
675     /// Methods in these implementations don't need to be exported.
676     query inherent_impls(key: DefId) -> &'tcx [DefId] {
677         desc { |tcx| "collecting inherent impls for `{}`", tcx.def_path_str(key) }
678         separate_provide_extern
679     }
680
681     query incoherent_impls(key: SimplifiedType) -> &'tcx [DefId] {
682         desc { |tcx| "collecting all inherent impls for `{:?}`", key }
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     // FIXME get rid of this with valtrees
957     query lit_to_const(
958         key: LitToConstInput<'tcx>
959     ) -> Result<ty::Const<'tcx>, LitToConstError> {
960         desc { "converting literal to const" }
961     }
962
963     query check_match(key: DefId) {
964         desc { |tcx| "match-checking `{}`", tcx.def_path_str(key) }
965         cache_on_disk_if { key.is_local() }
966     }
967
968     /// Performs part of the privacy check and computes "access levels".
969     query privacy_access_levels(_: ()) -> &'tcx AccessLevels {
970         eval_always
971         desc { "privacy access levels" }
972     }
973     query check_private_in_public(_: ()) -> () {
974         eval_always
975         desc { "checking for private elements in public interfaces" }
976     }
977
978     query reachable_set(_: ()) -> FxHashSet<LocalDefId> {
979         storage(ArenaCacheSelector<'tcx>)
980         desc { "reachability" }
981     }
982
983     /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
984     /// in the case of closures, this will be redirected to the enclosing function.
985     query region_scope_tree(def_id: DefId) -> &'tcx region::ScopeTree {
986         desc { |tcx| "computing drop scopes for `{}`", tcx.def_path_str(def_id) }
987     }
988
989     /// Generates a MIR body for the shim.
990     query mir_shims(key: ty::InstanceDef<'tcx>) -> mir::Body<'tcx> {
991         storage(ArenaCacheSelector<'tcx>)
992         desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
993     }
994
995     /// The `symbol_name` query provides the symbol name for calling a
996     /// given instance from the local crate. In particular, it will also
997     /// look up the correct symbol name of instances from upstream crates.
998     query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName<'tcx> {
999         desc { "computing the symbol for `{}`", key }
1000         cache_on_disk_if { true }
1001     }
1002
1003     query opt_def_kind(def_id: DefId) -> Option<DefKind> {
1004         desc { |tcx| "looking up definition kind of `{}`", tcx.def_path_str(def_id) }
1005         separate_provide_extern
1006     }
1007
1008     /// Gets the span for the definition.
1009     query def_span(def_id: DefId) -> Span {
1010         desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }
1011         separate_provide_extern
1012     }
1013
1014     /// Gets the span for the identifier of the definition.
1015     query def_ident_span(def_id: DefId) -> Option<Span> {
1016         desc { |tcx| "looking up span for `{}`'s identifier", tcx.def_path_str(def_id) }
1017         separate_provide_extern
1018     }
1019
1020     query lookup_stability(def_id: DefId) -> Option<attr::Stability> {
1021         desc { |tcx| "looking up stability of `{}`", tcx.def_path_str(def_id) }
1022         separate_provide_extern
1023     }
1024
1025     query lookup_const_stability(def_id: DefId) -> Option<attr::ConstStability> {
1026         desc { |tcx| "looking up const stability of `{}`", tcx.def_path_str(def_id) }
1027         separate_provide_extern
1028     }
1029
1030     query should_inherit_track_caller(def_id: DefId) -> bool {
1031         desc { |tcx| "computing should_inherit_track_caller of `{}`", tcx.def_path_str(def_id) }
1032     }
1033
1034     query lookup_deprecation_entry(def_id: DefId) -> Option<DeprecationEntry> {
1035         desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) }
1036         separate_provide_extern
1037     }
1038
1039     /// Determines whether an item is annotated with `doc(hidden)`.
1040     query is_doc_hidden(def_id: DefId) -> bool {
1041         desc { |tcx| "checking whether `{}` is `doc(hidden)`", tcx.def_path_str(def_id) }
1042     }
1043
1044     query item_attrs(def_id: DefId) -> &'tcx [ast::Attribute] {
1045         desc { |tcx| "collecting attributes of `{}`", tcx.def_path_str(def_id) }
1046         separate_provide_extern
1047     }
1048
1049     query codegen_fn_attrs(def_id: DefId) -> CodegenFnAttrs {
1050         desc { |tcx| "computing codegen attributes of `{}`", tcx.def_path_str(def_id) }
1051         storage(ArenaCacheSelector<'tcx>)
1052         cache_on_disk_if { true }
1053     }
1054
1055     query asm_target_features(def_id: DefId) -> &'tcx FxHashSet<Symbol> {
1056         desc { |tcx| "computing target features for inline asm of `{}`", tcx.def_path_str(def_id) }
1057     }
1058
1059     query fn_arg_names(def_id: DefId) -> &'tcx [rustc_span::symbol::Ident] {
1060         desc { |tcx| "looking up function parameter names for `{}`", tcx.def_path_str(def_id) }
1061         separate_provide_extern
1062     }
1063     /// Gets the rendered value of the specified constant or associated constant.
1064     /// Used by rustdoc.
1065     query rendered_const(def_id: DefId) -> String {
1066         storage(ArenaCacheSelector<'tcx>)
1067         desc { |tcx| "rendering constant intializer of `{}`", tcx.def_path_str(def_id) }
1068         separate_provide_extern
1069     }
1070     query impl_parent(def_id: DefId) -> Option<DefId> {
1071         desc { |tcx| "computing specialization parent impl of `{}`", tcx.def_path_str(def_id) }
1072         separate_provide_extern
1073     }
1074
1075     /// Given an `associated_item`, find the trait it belongs to.
1076     /// Return `None` if the `DefId` is not an associated item.
1077     query trait_of_item(associated_item: DefId) -> Option<DefId> {
1078         desc { |tcx| "finding trait defining `{}`", tcx.def_path_str(associated_item) }
1079         separate_provide_extern
1080     }
1081
1082     query is_ctfe_mir_available(key: DefId) -> bool {
1083         desc { |tcx| "checking if item has ctfe mir available: `{}`", tcx.def_path_str(key) }
1084         separate_provide_extern
1085     }
1086     query is_mir_available(key: DefId) -> bool {
1087         desc { |tcx| "checking if item has mir available: `{}`", tcx.def_path_str(key) }
1088         separate_provide_extern
1089     }
1090
1091     query own_existential_vtable_entries(
1092         key: ty::PolyExistentialTraitRef<'tcx>
1093     ) -> &'tcx [DefId] {
1094         desc { |tcx| "finding all existential vtable entries for trait {}", tcx.def_path_str(key.def_id()) }
1095     }
1096
1097     query vtable_entries(key: ty::PolyTraitRef<'tcx>)
1098                         -> &'tcx [ty::VtblEntry<'tcx>] {
1099         desc { |tcx| "finding all vtable entries for trait {}", tcx.def_path_str(key.def_id()) }
1100     }
1101
1102     query vtable_trait_upcasting_coercion_new_vptr_slot(key: (ty::Ty<'tcx>, ty::Ty<'tcx>)) -> Option<usize> {
1103         desc { |tcx| "finding the slot within vtable for trait object {} vtable ptr during trait upcasting coercion from {} vtable",
1104             key.1, key.0 }
1105     }
1106
1107     query vtable_allocation(key: (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>)) -> mir::interpret::AllocId {
1108         desc { |tcx| "vtable const allocation for <{} as {}>",
1109             key.0,
1110             key.1.map(|trait_ref| format!("{}", trait_ref)).unwrap_or("_".to_owned())
1111         }
1112     }
1113
1114     query codegen_fulfill_obligation(
1115         key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)
1116     ) -> Result<&'tcx ImplSource<'tcx, ()>, ErrorGuaranteed> {
1117         cache_on_disk_if { true }
1118         desc { |tcx|
1119             "checking if `{}` fulfills its obligations",
1120             tcx.def_path_str(key.1.def_id())
1121         }
1122     }
1123
1124     /// Return all `impl` blocks in the current crate.
1125     query all_local_trait_impls(_: ()) -> &'tcx rustc_data_structures::fx::FxIndexMap<DefId, Vec<LocalDefId>> {
1126         desc { "local trait impls" }
1127     }
1128
1129     /// Given a trait `trait_id`, return all known `impl` blocks.
1130     query trait_impls_of(trait_id: DefId) -> ty::trait_def::TraitImpls {
1131         storage(ArenaCacheSelector<'tcx>)
1132         desc { |tcx| "trait impls of `{}`", tcx.def_path_str(trait_id) }
1133     }
1134
1135     query specialization_graph_of(trait_id: DefId) -> specialization_graph::Graph {
1136         storage(ArenaCacheSelector<'tcx>)
1137         desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
1138         cache_on_disk_if { true }
1139     }
1140     query object_safety_violations(trait_id: DefId) -> &'tcx [traits::ObjectSafetyViolation] {
1141         desc { |tcx| "determine object safety of trait `{}`", tcx.def_path_str(trait_id) }
1142     }
1143
1144     /// Gets the ParameterEnvironment for a given item; this environment
1145     /// will be in "user-facing" mode, meaning that it is suitable for
1146     /// type-checking etc, and it does not normalize specializable
1147     /// associated types. This is almost always what you want,
1148     /// unless you are doing MIR optimizations, in which case you
1149     /// might want to use `reveal_all()` method to change modes.
1150     query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
1151         desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
1152     }
1153
1154     /// Like `param_env`, but returns the `ParamEnv` in `Reveal::All` mode.
1155     /// Prefer this over `tcx.param_env(def_id).with_reveal_all_normalized(tcx)`,
1156     /// as this method is more efficient.
1157     query param_env_reveal_all_normalized(def_id: DefId) -> ty::ParamEnv<'tcx> {
1158         desc { |tcx| "computing revealed normalized predicates of `{}`", tcx.def_path_str(def_id) }
1159     }
1160
1161     /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
1162     /// `ty.is_copy()`, etc, since that will prune the environment where possible.
1163     query is_copy_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1164         desc { "computing whether `{}` is `Copy`", env.value }
1165         remap_env_constness
1166     }
1167     /// Query backing `Ty::is_sized`.
1168     query is_sized_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1169         desc { "computing whether `{}` is `Sized`", env.value }
1170         remap_env_constness
1171     }
1172     /// Query backing `Ty::is_freeze`.
1173     query is_freeze_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1174         desc { "computing whether `{}` is freeze", env.value }
1175         remap_env_constness
1176     }
1177     /// Query backing `Ty::is_unpin`.
1178     query is_unpin_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1179         desc { "computing whether `{}` is `Unpin`", env.value }
1180         remap_env_constness
1181     }
1182     /// Query backing `Ty::needs_drop`.
1183     query needs_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1184         desc { "computing whether `{}` needs drop", env.value }
1185         remap_env_constness
1186     }
1187     /// Query backing `Ty::has_significant_drop_raw`.
1188     query has_significant_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1189         desc { "computing whether `{}` has a significant drop", env.value }
1190         remap_env_constness
1191     }
1192
1193     /// Query backing `Ty::is_structural_eq_shallow`.
1194     ///
1195     /// This is only correct for ADTs. Call `is_structural_eq_shallow` to handle all types
1196     /// correctly.
1197     query has_structural_eq_impls(ty: Ty<'tcx>) -> bool {
1198         desc {
1199             "computing whether `{:?}` implements `PartialStructuralEq` and `StructuralEq`",
1200             ty
1201         }
1202     }
1203
1204     /// A list of types where the ADT requires drop if and only if any of
1205     /// those types require drop. If the ADT is known to always need drop
1206     /// then `Err(AlwaysRequiresDrop)` is returned.
1207     query adt_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1208         desc { |tcx| "computing when `{}` needs drop", tcx.def_path_str(def_id) }
1209         cache_on_disk_if { true }
1210     }
1211
1212     /// A list of types where the ADT requires drop if and only if any of those types
1213     /// has significant drop. A type marked with the attribute `rustc_insignificant_dtor`
1214     /// is considered to not be significant. A drop is significant if it is implemented
1215     /// by the user or does anything that will have any observable behavior (other than
1216     /// freeing up memory). If the ADT is known to have a significant destructor then
1217     /// `Err(AlwaysRequiresDrop)` is returned.
1218     query adt_significant_drop_tys(def_id: DefId) -> Result<&'tcx ty::List<Ty<'tcx>>, AlwaysRequiresDrop> {
1219         desc { |tcx| "computing when `{}` has a significant destructor", tcx.def_path_str(def_id) }
1220         cache_on_disk_if { false }
1221     }
1222
1223     /// Computes the layout of a type. Note that this implicitly
1224     /// executes in "reveal all" mode, and will normalize the input type.
1225     query layout_of(
1226         key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1227     ) -> Result<ty::layout::TyAndLayout<'tcx>, ty::layout::LayoutError<'tcx>> {
1228         desc { "computing layout of `{}`", key.value }
1229         remap_env_constness
1230     }
1231
1232     /// Compute a `FnAbi` suitable for indirect calls, i.e. to `fn` pointers.
1233     ///
1234     /// NB: this doesn't handle virtual calls - those should use `fn_abi_of_instance`
1235     /// instead, where the instance is an `InstanceDef::Virtual`.
1236     query fn_abi_of_fn_ptr(
1237         key: ty::ParamEnvAnd<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1238     ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1239         desc { "computing call ABI of `{}` function pointers", key.value.0 }
1240         remap_env_constness
1241     }
1242
1243     /// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for
1244     /// direct calls to an `fn`.
1245     ///
1246     /// NB: that includes virtual calls, which are represented by "direct calls"
1247     /// to an `InstanceDef::Virtual` instance (of `<dyn Trait as Trait>::fn`).
1248     query fn_abi_of_instance(
1249         key: ty::ParamEnvAnd<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1250     ) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1251         desc { "computing call ABI of `{}`", key.value.0 }
1252         remap_env_constness
1253     }
1254
1255     query dylib_dependency_formats(_: CrateNum)
1256                                     -> &'tcx [(CrateNum, LinkagePreference)] {
1257         desc { "dylib dependency formats of crate" }
1258         separate_provide_extern
1259     }
1260
1261     query dependency_formats(_: ()) -> Lrc<crate::middle::dependency_format::Dependencies> {
1262         storage(ArenaCacheSelector<'tcx>)
1263         desc { "get the linkage format of all dependencies" }
1264     }
1265
1266     query is_compiler_builtins(_: CrateNum) -> bool {
1267         fatal_cycle
1268         desc { "checking if the crate is_compiler_builtins" }
1269         separate_provide_extern
1270     }
1271     query has_global_allocator(_: CrateNum) -> bool {
1272         // This query depends on untracked global state in CStore
1273         eval_always
1274         fatal_cycle
1275         desc { "checking if the crate has_global_allocator" }
1276         separate_provide_extern
1277     }
1278     query has_panic_handler(_: CrateNum) -> bool {
1279         fatal_cycle
1280         desc { "checking if the crate has_panic_handler" }
1281         separate_provide_extern
1282     }
1283     query is_profiler_runtime(_: CrateNum) -> bool {
1284         fatal_cycle
1285         desc { "query a crate is `#![profiler_runtime]`" }
1286         separate_provide_extern
1287     }
1288     query panic_strategy(_: CrateNum) -> PanicStrategy {
1289         fatal_cycle
1290         desc { "query a crate's configured panic strategy" }
1291         separate_provide_extern
1292     }
1293     query panic_in_drop_strategy(_: CrateNum) -> PanicStrategy {
1294         fatal_cycle
1295         desc { "query a crate's configured panic-in-drop strategy" }
1296         separate_provide_extern
1297     }
1298     query is_no_builtins(_: CrateNum) -> bool {
1299         fatal_cycle
1300         desc { "test whether a crate has `#![no_builtins]`" }
1301         separate_provide_extern
1302     }
1303     query symbol_mangling_version(_: CrateNum) -> SymbolManglingVersion {
1304         fatal_cycle
1305         desc { "query a crate's symbol mangling version" }
1306         separate_provide_extern
1307     }
1308
1309     query extern_crate(def_id: DefId) -> Option<&'tcx ExternCrate> {
1310         eval_always
1311         desc { "getting crate's ExternCrateData" }
1312         separate_provide_extern
1313     }
1314
1315     query specializes(_: (DefId, DefId)) -> bool {
1316         desc { "computing whether impls specialize one another" }
1317     }
1318     query in_scope_traits_map(_: LocalDefId)
1319         -> Option<&'tcx FxHashMap<ItemLocalId, Box<[TraitCandidate]>>> {
1320         desc { "traits in scope at a block" }
1321     }
1322
1323     query module_reexports(def_id: LocalDefId) -> Option<&'tcx [ModChild]> {
1324         desc { |tcx| "looking up reexports of module `{}`", tcx.def_path_str(def_id.to_def_id()) }
1325     }
1326
1327     query impl_defaultness(def_id: DefId) -> hir::Defaultness {
1328         desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
1329         separate_provide_extern
1330     }
1331
1332     query check_item_well_formed(key: LocalDefId) -> () {
1333         desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1334     }
1335     query check_trait_item_well_formed(key: LocalDefId) -> () {
1336         desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1337     }
1338     query check_impl_item_well_formed(key: LocalDefId) -> () {
1339         desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
1340     }
1341
1342     // The `DefId`s of all non-generic functions and statics in the given crate
1343     // that can be reached from outside the crate.
1344     //
1345     // We expect this items to be available for being linked to.
1346     //
1347     // This query can also be called for `LOCAL_CRATE`. In this case it will
1348     // compute which items will be reachable to other crates, taking into account
1349     // the kind of crate that is currently compiled. Crates with only a
1350     // C interface have fewer reachable things.
1351     //
1352     // Does not include external symbols that don't have a corresponding DefId,
1353     // like the compiler-generated `main` function and so on.
1354     query reachable_non_generics(_: CrateNum)
1355         -> DefIdMap<SymbolExportLevel> {
1356         storage(ArenaCacheSelector<'tcx>)
1357         desc { "looking up the exported symbols of a crate" }
1358         separate_provide_extern
1359     }
1360     query is_reachable_non_generic(def_id: DefId) -> bool {
1361         desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
1362         separate_provide_extern
1363     }
1364     query is_unreachable_local_definition(def_id: LocalDefId) -> bool {
1365         desc { |tcx|
1366             "checking whether `{}` is reachable from outside the crate",
1367             tcx.def_path_str(def_id.to_def_id()),
1368         }
1369     }
1370
1371     /// The entire set of monomorphizations the local crate can safely link
1372     /// to because they are exported from upstream crates. Do not depend on
1373     /// this directly, as its value changes anytime a monomorphization gets
1374     /// added or removed in any upstream crate. Instead use the narrower
1375     /// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even
1376     /// better, `Instance::upstream_monomorphization()`.
1377     query upstream_monomorphizations(_: ()) -> DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1378         storage(ArenaCacheSelector<'tcx>)
1379         desc { "collecting available upstream monomorphizations" }
1380     }
1381
1382     /// Returns the set of upstream monomorphizations available for the
1383     /// generic function identified by the given `def_id`. The query makes
1384     /// sure to make a stable selection if the same monomorphization is
1385     /// available in multiple upstream crates.
1386     ///
1387     /// You likely want to call `Instance::upstream_monomorphization()`
1388     /// instead of invoking this query directly.
1389     query upstream_monomorphizations_for(def_id: DefId)
1390         -> Option<&'tcx FxHashMap<SubstsRef<'tcx>, CrateNum>>
1391     {
1392         storage(ArenaCacheSelector<'tcx>)
1393         desc { |tcx|
1394             "collecting available upstream monomorphizations for `{}`",
1395             tcx.def_path_str(def_id),
1396         }
1397         separate_provide_extern
1398     }
1399
1400     /// Returns the upstream crate that exports drop-glue for the given
1401     /// type (`substs` is expected to be a single-item list containing the
1402     /// type one wants drop-glue for).
1403     ///
1404     /// This is a subset of `upstream_monomorphizations_for` in order to
1405     /// increase dep-tracking granularity. Otherwise adding or removing any
1406     /// type with drop-glue in any upstream crate would invalidate all
1407     /// functions calling drop-glue of an upstream type.
1408     ///
1409     /// You likely want to call `Instance::upstream_monomorphization()`
1410     /// instead of invoking this query directly.
1411     ///
1412     /// NOTE: This query could easily be extended to also support other
1413     ///       common functions that have are large set of monomorphizations
1414     ///       (like `Clone::clone` for example).
1415     query upstream_drop_glue_for(substs: SubstsRef<'tcx>) -> Option<CrateNum> {
1416         desc { "available upstream drop-glue for `{:?}`", substs }
1417     }
1418
1419     query foreign_modules(_: CrateNum) -> FxHashMap<DefId, ForeignModule> {
1420         storage(ArenaCacheSelector<'tcx>)
1421         desc { "looking up the foreign modules of a linked crate" }
1422         separate_provide_extern
1423     }
1424
1425     /// Identifies the entry-point (e.g., the `main` function) for a given
1426     /// crate, returning `None` if there is no entry point (such as for library crates).
1427     query entry_fn(_: ()) -> Option<(DefId, EntryFnType)> {
1428         desc { "looking up the entry function of a crate" }
1429     }
1430     query proc_macro_decls_static(_: ()) -> Option<LocalDefId> {
1431         desc { "looking up the derive registrar for a crate" }
1432     }
1433     // The macro which defines `rustc_metadata::provide_extern` depends on this query's name.
1434     // Changing the name should cause a compiler error, but in case that changes, be aware.
1435     query crate_hash(_: CrateNum) -> Svh {
1436         eval_always
1437         desc { "looking up the hash a crate" }
1438         separate_provide_extern
1439     }
1440     query crate_host_hash(_: CrateNum) -> Option<Svh> {
1441         eval_always
1442         desc { "looking up the hash of a host version of a crate" }
1443         separate_provide_extern
1444     }
1445     query extra_filename(_: CrateNum) -> String {
1446         storage(ArenaCacheSelector<'tcx>)
1447         eval_always
1448         desc { "looking up the extra filename for a crate" }
1449         separate_provide_extern
1450     }
1451     query crate_extern_paths(_: CrateNum) -> Vec<PathBuf> {
1452         storage(ArenaCacheSelector<'tcx>)
1453         eval_always
1454         desc { "looking up the paths for extern crates" }
1455         separate_provide_extern
1456     }
1457
1458     /// Given a crate and a trait, look up all impls of that trait in the crate.
1459     /// Return `(impl_id, self_ty)`.
1460     query implementations_of_trait(_: (CrateNum, DefId)) -> &'tcx [(DefId, Option<SimplifiedType>)] {
1461         desc { "looking up implementations of a trait in a crate" }
1462         separate_provide_extern
1463     }
1464
1465     /// Collects all incoherent impls for the given crate and type.
1466     ///
1467     /// Do not call this directly, but instead use the `incoherent_impls` query.
1468     /// This query is only used to get the data necessary for that query.
1469     query crate_incoherent_impls(key: (CrateNum, SimplifiedType)) -> &'tcx [DefId] {
1470         desc { |tcx| "collecting all impls for a type in a crate" }
1471         separate_provide_extern
1472     }
1473
1474     query is_dllimport_foreign_item(def_id: DefId) -> bool {
1475         desc { |tcx| "is_dllimport_foreign_item({})", tcx.def_path_str(def_id) }
1476     }
1477     query is_statically_included_foreign_item(def_id: DefId) -> bool {
1478         desc { |tcx| "is_statically_included_foreign_item({})", tcx.def_path_str(def_id) }
1479     }
1480     query native_library_kind(def_id: DefId)
1481         -> Option<NativeLibKind> {
1482         desc { |tcx| "native_library_kind({})", tcx.def_path_str(def_id) }
1483     }
1484
1485     /// Does lifetime resolution, but does not descend into trait items. This
1486     /// should only be used for resolving lifetimes of on trait definitions,
1487     /// and is used to avoid cycles. Importantly, `resolve_lifetimes` still visits
1488     /// the same lifetimes and is responsible for diagnostics.
1489     /// See `rustc_resolve::late::lifetimes for details.
1490     query resolve_lifetimes_trait_definition(_: LocalDefId) -> ResolveLifetimes {
1491         storage(ArenaCacheSelector<'tcx>)
1492         desc { "resolving lifetimes for a trait definition" }
1493     }
1494     /// Does lifetime resolution on items. Importantly, we can't resolve
1495     /// lifetimes directly on things like trait methods, because of trait params.
1496     /// See `rustc_resolve::late::lifetimes for details.
1497     query resolve_lifetimes(_: LocalDefId) -> ResolveLifetimes {
1498         storage(ArenaCacheSelector<'tcx>)
1499         desc { "resolving lifetimes" }
1500     }
1501     query named_region_map(_: LocalDefId) ->
1502         Option<&'tcx FxHashMap<ItemLocalId, Region>> {
1503         desc { "looking up a named region" }
1504     }
1505     query is_late_bound_map(_: LocalDefId) -> Option<(LocalDefId, &'tcx FxHashSet<LocalDefId>)> {
1506         desc { "testing if a region is late bound" }
1507     }
1508     /// For a given item (like a struct), gets the default lifetimes to be used
1509     /// for each parameter if a trait object were to be passed for that parameter.
1510     /// For example, for `struct Foo<'a, T, U>`, this would be `['static, 'static]`.
1511     /// For `struct Foo<'a, T: 'a, U>`, this would instead be `['a, 'static]`.
1512     query object_lifetime_defaults(_: LocalDefId) -> Option<&'tcx [ObjectLifetimeDefault]> {
1513         desc { "looking up lifetime defaults for a region on an item" }
1514     }
1515     query late_bound_vars_map(_: LocalDefId)
1516         -> Option<&'tcx FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>> {
1517         desc { "looking up late bound vars" }
1518     }
1519
1520     query lifetime_scope_map(_: LocalDefId) -> Option<FxHashMap<ItemLocalId, LifetimeScopeForPath>> {
1521         storage(ArenaCacheSelector<'tcx>)
1522         desc { "finds the lifetime scope for an HirId of a PathSegment" }
1523     }
1524
1525     query visibility(def_id: DefId) -> ty::Visibility {
1526         desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
1527         separate_provide_extern
1528     }
1529
1530     /// Computes the set of modules from which this type is visibly uninhabited.
1531     /// To check whether a type is uninhabited at all (not just from a given module), you could
1532     /// check whether the forest is empty.
1533     query type_uninhabited_from(
1534         key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
1535     ) -> ty::inhabitedness::DefIdForest<'tcx> {
1536         desc { "computing the inhabitedness of `{:?}`", key }
1537         remap_env_constness
1538     }
1539
1540     query dep_kind(_: CrateNum) -> CrateDepKind {
1541         eval_always
1542         desc { "fetching what a dependency looks like" }
1543         separate_provide_extern
1544     }
1545
1546     /// Gets the name of the crate.
1547     query crate_name(_: CrateNum) -> Symbol {
1548         eval_always
1549         desc { "fetching what a crate is named" }
1550         separate_provide_extern
1551     }
1552     query module_children(def_id: DefId) -> &'tcx [ModChild] {
1553         desc { |tcx| "collecting child items of module `{}`", tcx.def_path_str(def_id) }
1554         separate_provide_extern
1555     }
1556     query extern_mod_stmt_cnum(def_id: LocalDefId) -> Option<CrateNum> {
1557         desc { |tcx| "computing crate imported by `{}`", tcx.def_path_str(def_id.to_def_id()) }
1558     }
1559
1560     query lib_features(_: ()) -> LibFeatures {
1561         storage(ArenaCacheSelector<'tcx>)
1562         desc { "calculating the lib features map" }
1563     }
1564     query defined_lib_features(_: CrateNum)
1565         -> &'tcx [(Symbol, Option<Symbol>)] {
1566         desc { "calculating the lib features defined in a crate" }
1567         separate_provide_extern
1568     }
1569     /// Returns the lang items defined in another crate by loading it from metadata.
1570     query get_lang_items(_: ()) -> LanguageItems {
1571         storage(ArenaCacheSelector<'tcx>)
1572         eval_always
1573         desc { "calculating the lang items map" }
1574     }
1575
1576     /// Returns all diagnostic items defined in all crates.
1577     query all_diagnostic_items(_: ()) -> rustc_hir::diagnostic_items::DiagnosticItems {
1578         storage(ArenaCacheSelector<'tcx>)
1579         eval_always
1580         desc { "calculating the diagnostic items map" }
1581     }
1582
1583     /// Returns the lang items defined in another crate by loading it from metadata.
1584     query defined_lang_items(_: CrateNum) -> &'tcx [(DefId, usize)] {
1585         desc { "calculating the lang items defined in a crate" }
1586         separate_provide_extern
1587     }
1588
1589     /// Returns the diagnostic items defined in a crate.
1590     query diagnostic_items(_: CrateNum) -> rustc_hir::diagnostic_items::DiagnosticItems {
1591         storage(ArenaCacheSelector<'tcx>)
1592         desc { "calculating the diagnostic items map in a crate" }
1593         separate_provide_extern
1594     }
1595
1596     query missing_lang_items(_: CrateNum) -> &'tcx [LangItem] {
1597         desc { "calculating the missing lang items in a crate" }
1598         separate_provide_extern
1599     }
1600     query visible_parent_map(_: ()) -> DefIdMap<DefId> {
1601         storage(ArenaCacheSelector<'tcx>)
1602         desc { "calculating the visible parent map" }
1603     }
1604     query trimmed_def_paths(_: ()) -> FxHashMap<DefId, Symbol> {
1605         storage(ArenaCacheSelector<'tcx>)
1606         desc { "calculating trimmed def paths" }
1607     }
1608     query missing_extern_crate_item(_: CrateNum) -> bool {
1609         eval_always
1610         desc { "seeing if we're missing an `extern crate` item for this crate" }
1611         separate_provide_extern
1612     }
1613     query used_crate_source(_: CrateNum) -> Lrc<CrateSource> {
1614         storage(ArenaCacheSelector<'tcx>)
1615         eval_always
1616         desc { "looking at the source for a crate" }
1617         separate_provide_extern
1618     }
1619     query postorder_cnums(_: ()) -> &'tcx [CrateNum] {
1620         eval_always
1621         desc { "generating a postorder list of CrateNums" }
1622     }
1623     /// Returns whether or not the crate with CrateNum 'cnum'
1624     /// is marked as a private dependency
1625     query is_private_dep(c: CrateNum) -> bool {
1626         eval_always
1627         desc { "check whether crate {} is a private dependency", c }
1628         separate_provide_extern
1629     }
1630     query allocator_kind(_: ()) -> Option<AllocatorKind> {
1631         eval_always
1632         desc { "allocator kind for the current crate" }
1633     }
1634
1635     query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
1636         desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) }
1637     }
1638     query maybe_unused_trait_import(def_id: LocalDefId) -> bool {
1639         desc { |tcx| "maybe_unused_trait_import for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1640     }
1641     query maybe_unused_extern_crates(_: ()) -> &'tcx [(LocalDefId, Span)] {
1642         desc { "looking up all possibly unused extern crates" }
1643     }
1644     query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx FxHashSet<Symbol> {
1645         desc { |tcx| "names_imported_by_glob_use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
1646     }
1647
1648     query stability_index(_: ()) -> stability::Index {
1649         storage(ArenaCacheSelector<'tcx>)
1650         eval_always
1651         desc { "calculating the stability index for the local crate" }
1652     }
1653     query crates(_: ()) -> &'tcx [CrateNum] {
1654         eval_always
1655         desc { "fetching all foreign CrateNum instances" }
1656     }
1657
1658     /// A list of all traits in a crate, used by rustdoc and error reporting.
1659     /// NOTE: Not named just `traits` due to a naming conflict.
1660     query traits_in_crate(_: CrateNum) -> &'tcx [DefId] {
1661         desc { "fetching all traits in a crate" }
1662         separate_provide_extern
1663     }
1664
1665     /// The list of symbols exported from the given crate.
1666     ///
1667     /// - All names contained in `exported_symbols(cnum)` are guaranteed to
1668     ///   correspond to a publicly visible symbol in `cnum` machine code.
1669     /// - The `exported_symbols` sets of different crates do not intersect.
1670     query exported_symbols(_: CrateNum)
1671         -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] {
1672         desc { "exported_symbols" }
1673         separate_provide_extern
1674     }
1675
1676     query collect_and_partition_mono_items(_: ()) -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
1677         eval_always
1678         desc { "collect_and_partition_mono_items" }
1679     }
1680     query is_codegened_item(def_id: DefId) -> bool {
1681         desc { |tcx| "determining whether `{}` needs codegen", tcx.def_path_str(def_id) }
1682     }
1683
1684     /// All items participating in code generation together with items inlined into them.
1685     query codegened_and_inlined_items(_: ()) -> &'tcx DefIdSet {
1686         eval_always
1687        desc { "codegened_and_inlined_items" }
1688     }
1689
1690     query codegen_unit(_: Symbol) -> &'tcx CodegenUnit<'tcx> {
1691         desc { "codegen_unit" }
1692     }
1693     query unused_generic_params(key: ty::InstanceDef<'tcx>) -> FiniteBitSet<u32> {
1694         cache_on_disk_if { key.def_id().is_local() }
1695         desc {
1696             |tcx| "determining which generic parameters are unused by `{}`",
1697                 tcx.def_path_str(key.def_id())
1698         }
1699         separate_provide_extern
1700     }
1701     query backend_optimization_level(_: ()) -> OptLevel {
1702         desc { "optimization level used by backend" }
1703     }
1704
1705     /// Return the filenames where output artefacts shall be stored.
1706     ///
1707     /// This query returns an `&Arc` because codegen backends need the value even after the `TyCtxt`
1708     /// has been destroyed.
1709     query output_filenames(_: ()) -> &'tcx Arc<OutputFilenames> {
1710         eval_always
1711         desc { "output_filenames" }
1712     }
1713
1714     /// Do not call this query directly: invoke `normalize` instead.
1715     query normalize_projection_ty(
1716         goal: CanonicalProjectionGoal<'tcx>
1717     ) -> Result<
1718         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
1719         NoSolution,
1720     > {
1721         desc { "normalizing `{:?}`", goal }
1722         remap_env_constness
1723     }
1724
1725     /// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
1726     query try_normalize_generic_arg_after_erasing_regions(
1727         goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
1728     ) -> Result<GenericArg<'tcx>, NoSolution> {
1729         desc { "normalizing `{}`", goal.value }
1730         remap_env_constness
1731     }
1732
1733     /// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
1734     query try_normalize_mir_const_after_erasing_regions(
1735         goal: ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1736     ) -> Result<mir::ConstantKind<'tcx>, NoSolution> {
1737         desc { "normalizing `{}`", goal.value }
1738         remap_env_constness
1739     }
1740
1741     query implied_outlives_bounds(
1742         goal: CanonicalTyGoal<'tcx>
1743     ) -> Result<
1744         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
1745         NoSolution,
1746     > {
1747         desc { "computing implied outlives bounds for `{:?}`", goal }
1748         remap_env_constness
1749     }
1750
1751     /// Do not call this query directly: invoke `infcx.at().dropck_outlives()` instead.
1752     query dropck_outlives(
1753         goal: CanonicalTyGoal<'tcx>
1754     ) -> Result<
1755         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>,
1756         NoSolution,
1757     > {
1758         desc { "computing dropck types for `{:?}`", goal }
1759         remap_env_constness
1760     }
1761
1762     /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
1763     /// `infcx.predicate_must_hold()` instead.
1764     query evaluate_obligation(
1765         goal: CanonicalPredicateGoal<'tcx>
1766     ) -> Result<traits::EvaluationResult, traits::OverflowError> {
1767         desc { "evaluating trait selection obligation `{}`", goal.value.value }
1768     }
1769
1770     query evaluate_goal(
1771         goal: traits::CanonicalChalkEnvironmentAndGoal<'tcx>
1772     ) -> Result<
1773         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1774         NoSolution
1775     > {
1776         desc { "evaluating trait selection obligation `{}`", goal.value }
1777     }
1778
1779     /// Do not call this query directly: part of the `Eq` type-op
1780     query type_op_ascribe_user_type(
1781         goal: CanonicalTypeOpAscribeUserTypeGoal<'tcx>
1782     ) -> Result<
1783         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1784         NoSolution,
1785     > {
1786         desc { "evaluating `type_op_ascribe_user_type` `{:?}`", goal }
1787         remap_env_constness
1788     }
1789
1790     /// Do not call this query directly: part of the `Eq` type-op
1791     query type_op_eq(
1792         goal: CanonicalTypeOpEqGoal<'tcx>
1793     ) -> Result<
1794         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1795         NoSolution,
1796     > {
1797         desc { "evaluating `type_op_eq` `{:?}`", goal }
1798         remap_env_constness
1799     }
1800
1801     /// Do not call this query directly: part of the `Subtype` type-op
1802     query type_op_subtype(
1803         goal: CanonicalTypeOpSubtypeGoal<'tcx>
1804     ) -> Result<
1805         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1806         NoSolution,
1807     > {
1808         desc { "evaluating `type_op_subtype` `{:?}`", goal }
1809         remap_env_constness
1810     }
1811
1812     /// Do not call this query directly: part of the `ProvePredicate` type-op
1813     query type_op_prove_predicate(
1814         goal: CanonicalTypeOpProvePredicateGoal<'tcx>
1815     ) -> Result<
1816         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
1817         NoSolution,
1818     > {
1819         desc { "evaluating `type_op_prove_predicate` `{:?}`", goal }
1820     }
1821
1822     /// Do not call this query directly: part of the `Normalize` type-op
1823     query type_op_normalize_ty(
1824         goal: CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
1825     ) -> Result<
1826         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>,
1827         NoSolution,
1828     > {
1829         desc { "normalizing `{:?}`", goal }
1830         remap_env_constness
1831     }
1832
1833     /// Do not call this query directly: part of the `Normalize` type-op
1834     query type_op_normalize_predicate(
1835         goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
1836     ) -> Result<
1837         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>,
1838         NoSolution,
1839     > {
1840         desc { "normalizing `{:?}`", goal }
1841         remap_env_constness
1842     }
1843
1844     /// Do not call this query directly: part of the `Normalize` type-op
1845     query type_op_normalize_poly_fn_sig(
1846         goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
1847     ) -> Result<
1848         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>,
1849         NoSolution,
1850     > {
1851         desc { "normalizing `{:?}`", goal }
1852         remap_env_constness
1853     }
1854
1855     /// Do not call this query directly: part of the `Normalize` type-op
1856     query type_op_normalize_fn_sig(
1857         goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
1858     ) -> Result<
1859         &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>,
1860         NoSolution,
1861     > {
1862         desc { "normalizing `{:?}`", goal }
1863         remap_env_constness
1864     }
1865
1866     query subst_and_check_impossible_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
1867         desc { |tcx|
1868             "impossible substituted predicates:`{}`",
1869             tcx.def_path_str(key.0)
1870         }
1871     }
1872
1873     query method_autoderef_steps(
1874         goal: CanonicalTyGoal<'tcx>
1875     ) -> MethodAutoderefStepsResult<'tcx> {
1876         desc { "computing autoderef types for `{:?}`", goal }
1877         remap_env_constness
1878     }
1879
1880     query supported_target_features(_: CrateNum) -> FxHashMap<String, Option<Symbol>> {
1881         storage(ArenaCacheSelector<'tcx>)
1882         eval_always
1883         desc { "looking up supported target features" }
1884     }
1885
1886     /// Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
1887     query instance_def_size_estimate(def: ty::InstanceDef<'tcx>)
1888         -> usize {
1889         desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) }
1890     }
1891
1892     query features_query(_: ()) -> &'tcx rustc_feature::Features {
1893         eval_always
1894         desc { "looking up enabled feature gates" }
1895     }
1896
1897     /// Attempt to resolve the given `DefId` to an `Instance`, for the
1898     /// given generics args (`SubstsRef`), returning one of:
1899     ///  * `Ok(Some(instance))` on success
1900     ///  * `Ok(None)` when the `SubstsRef` are still too generic,
1901     ///    and therefore don't allow finding the final `Instance`
1902     ///  * `Err(ErrorGuaranteed)` when the `Instance` resolution process
1903     ///    couldn't complete due to errors elsewhere - this is distinct
1904     ///    from `Ok(None)` to avoid misleading diagnostics when an error
1905     ///    has already been/will be emitted, for the original cause
1906     query resolve_instance(
1907         key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>
1908     ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
1909         desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) }
1910         remap_env_constness
1911     }
1912
1913     query resolve_instance_of_const_arg(
1914         key: ty::ParamEnvAnd<'tcx, (LocalDefId, DefId, SubstsRef<'tcx>)>
1915     ) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
1916         desc {
1917             "resolving instance of the const argument `{}`",
1918             ty::Instance::new(key.value.0.to_def_id(), key.value.2),
1919         }
1920         remap_env_constness
1921     }
1922
1923     query normalize_opaque_types(key: &'tcx ty::List<ty::Predicate<'tcx>>) -> &'tcx ty::List<ty::Predicate<'tcx>> {
1924         desc { "normalizing opaque types in {:?}", key }
1925     }
1926
1927     /// Checks whether a type is definitely uninhabited. This is
1928     /// conservative: for some types that are uninhabited we return `false`,
1929     /// but we only return `true` for types that are definitely uninhabited.
1930     /// `ty.conservative_is_privately_uninhabited` implies that any value of type `ty`
1931     /// will be `Abi::Uninhabited`. (Note that uninhabited types may have nonzero
1932     /// size, to account for partial initialisation. See #49298 for details.)
1933     query conservative_is_privately_uninhabited(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
1934         desc { "conservatively checking if {:?} is privately uninhabited", key }
1935         remap_env_constness
1936     }
1937
1938     query limits(key: ()) -> Limits {
1939         desc { "looking up limits" }
1940     }
1941
1942     /// Performs an HIR-based well-formed check on the item with the given `HirId`. If
1943     /// we get an `Unimplemented` error that matches the provided `Predicate`, return
1944     /// the cause of the newly created obligation.
1945     ///
1946     /// This is only used by error-reporting code to get a better cause (in particular, a better
1947     /// span) for an *existing* error. Therefore, it is best-effort, and may never handle
1948     /// all of the cases that the normal `ty::Ty`-based wfcheck does. This is fine,
1949     /// because the `ty::Ty`-based wfcheck is always run.
1950     query diagnostic_hir_wf_check(key: (ty::Predicate<'tcx>, traits::WellFormedLoc)) -> Option<traits::ObligationCause<'tcx>> {
1951         storage(ArenaCacheSelector<'tcx>)
1952         eval_always
1953         no_hash
1954         desc { "performing HIR wf-checking for predicate {:?} at item {:?}", key.0, key.1 }
1955     }
1956
1957
1958     /// The list of backend features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`,
1959     /// `--target` and similar).
1960     query global_backend_features(_: ()) -> Vec<String> {
1961         storage(ArenaCacheSelector<'tcx>)
1962         eval_always
1963         desc { "computing the backend features for CLI flags" }
1964     }
1965 }