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