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