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