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