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