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