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