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