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