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