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