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