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