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