]> git.lizzy.rs Git - rust.git/blob - src/librustc/query/mod.rs
Rollup merge of #60327 - matthewjasper:handle-local-outlives-lbl, r=nikomatsakis
[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) -> Lrc<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) -> Lrc<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) -> Lrc<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             -> Lrc<ty::GenericPredicates<'tcx>> {}
170
171         /// Returns the predicates written explicit by the user.
172         query explicit_predicates_of(_: DefId)
173             -> Lrc<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) -> Lrc<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             -> Lrc<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         /// True if this is a const fn, use the `is_const_fn` to know whether your crate actually
220         /// sees it as const fn (e.g., the const-fn-ness might be unstable and you might not have
221         /// 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         /// 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         /// Get a map with the variance of every item; use `item_variance`
247         /// instead.
248         query crate_variances(_: CrateNum) -> Lrc<ty::CrateVariancesMap<'tcx>> {
249             desc { "computing the variances for items in this crate" }
250         }
251
252         /// Maps from def-id of a type or region parameter to its
253         /// (inferred) variance.
254         query variances_of(_: DefId) -> &'tcx [ty::Variance] {}
255     }
256
257     TypeChecking {
258         /// Maps from def-id of a type to its (inferred) outlives.
259         query inferred_outlives_crate(_: CrateNum)
260             -> Lrc<ty::CratePredicatesMap<'tcx>> {
261             desc { "computing the inferred outlives predicates for items in this crate" }
262         }
263     }
264
265     Other {
266         /// Maps from an impl/trait def-id to a list of the def-ids of its items
267         query associated_item_def_ids(_: DefId) -> Lrc<Vec<DefId>> {}
268
269         /// Maps from a trait item to the trait item "descriptor"
270         query associated_item(_: DefId) -> ty::AssociatedItem {}
271
272         query impl_trait_ref(_: DefId) -> Option<ty::TraitRef<'tcx>> {}
273         query impl_polarity(_: DefId) -> hir::ImplPolarity {}
274
275         query issue33140_self_ty(_: DefId) -> Option<ty::Ty<'tcx>> {}
276     }
277
278     TypeChecking {
279         /// Maps a DefId of a type to a list of its inherent impls.
280         /// Contains implementations of methods that are inherent to a type.
281         /// Methods in these implementations don't need to be exported.
282         query inherent_impls(_: DefId) -> Lrc<Vec<DefId>> {
283             eval_always
284         }
285     }
286
287     TypeChecking {
288         /// The result of unsafety-checking this `DefId`.
289         query unsafety_check_result(_: DefId) -> mir::UnsafetyCheckResult {}
290
291         /// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error
292         query unsafe_derive_on_repr_packed(_: DefId) -> () {}
293
294         /// The signature of functions and closures.
295         query fn_sig(_: DefId) -> ty::PolyFnSig<'tcx> {}
296     }
297
298     Other {
299         query lint_mod(key: DefId) -> () {
300             desc { |tcx| "linting {}", key.describe_as_module(tcx) }
301         }
302
303         /// Checks the attributes in the module
304         query check_mod_attrs(key: DefId) -> () {
305             desc { |tcx| "checking attributes in {}", key.describe_as_module(tcx) }
306         }
307
308         query check_mod_unstable_api_usage(key: DefId) -> () {
309             desc { |tcx| "checking for unstable API usage in {}", key.describe_as_module(tcx) }
310         }
311
312         /// Checks the loops in the module
313         query check_mod_loops(key: DefId) -> () {
314             desc { |tcx| "checking loops in {}", key.describe_as_module(tcx) }
315         }
316
317         query check_mod_item_types(key: DefId) -> () {
318             desc { |tcx| "checking item types in {}", key.describe_as_module(tcx) }
319         }
320
321         query check_mod_privacy(key: DefId) -> () {
322             desc { |tcx| "checking privacy in {}", key.describe_as_module(tcx) }
323         }
324
325         query check_mod_intrinsics(key: DefId) -> () {
326             desc { |tcx| "checking intrinsics in {}", key.describe_as_module(tcx) }
327         }
328
329         query check_mod_liveness(key: DefId) -> () {
330             desc { |tcx| "checking liveness of variables in {}", key.describe_as_module(tcx) }
331         }
332
333         query check_mod_impl_wf(key: DefId) -> () {
334             desc { |tcx| "checking that impls are well-formed in {}", key.describe_as_module(tcx) }
335         }
336
337         query collect_mod_item_types(key: DefId) -> () {
338             desc { |tcx| "collecting item types in {}", key.describe_as_module(tcx) }
339         }
340
341         /// Caches CoerceUnsized kinds for impls on custom types.
342         query coerce_unsized_info(_: DefId)
343             -> ty::adjustment::CoerceUnsizedInfo {}
344     }
345
346     TypeChecking {
347         query typeck_item_bodies(_: CrateNum) -> () {
348             desc { "type-checking all item bodies" }
349         }
350
351         query typeck_tables_of(key: DefId) -> &'tcx ty::TypeckTables<'tcx> {
352             cache { key.is_local() }
353             load_cached(tcx, id) {
354                 let typeck_tables: Option<ty::TypeckTables<'tcx>> = tcx
355                     .queries.on_disk_cache
356                     .try_load_query_result(tcx, id);
357
358                 typeck_tables.map(|tables| tcx.alloc_tables(tables))
359             }
360         }
361     }
362
363     Other {
364         query used_trait_imports(_: DefId) -> Lrc<DefIdSet> {}
365     }
366
367     TypeChecking {
368         query has_typeck_tables(_: DefId) -> bool {}
369
370         query coherent_trait(def_id: DefId) -> () {
371             desc { |tcx| "coherence checking all impls of trait `{}`", tcx.def_path_str(def_id) }
372         }
373     }
374
375     BorrowChecking {
376         query borrowck(_: DefId) -> Lrc<BorrowCheckResult> {}
377
378         /// Borrow checks the function body. If this is a closure, returns
379         /// additional requirements that the closure's creator must verify.
380         query mir_borrowck(_: DefId) -> mir::BorrowCheckResult<'tcx> {}
381     }
382
383     TypeChecking {
384         /// Gets a complete map from all types to their inherent impls.
385         /// Not meant to be used directly outside of coherence.
386         /// (Defined only for `LOCAL_CRATE`.)
387         query crate_inherent_impls(k: CrateNum)
388             -> Lrc<CrateInherentImpls> {
389             eval_always
390             desc { "all inherent impls defined in crate `{:?}`", k }
391         }
392
393         /// Checks all types in the crate for overlap in their inherent impls. Reports errors.
394         /// Not meant to be used directly outside of coherence.
395         /// (Defined only for `LOCAL_CRATE`.)
396         query crate_inherent_impls_overlap_check(_: CrateNum)
397             -> () {
398             eval_always
399             desc { "check for overlap between inherent impls defined in this crate" }
400         }
401     }
402
403     Other {
404         /// Evaluate a constant without running sanity checks
405         ///
406         /// **Do not use this** outside const eval. Const eval uses this to break query cycles
407         /// during validation. Please add a comment to every use site explaining why using
408         /// `const_eval` isn't sufficient
409         query const_eval_raw(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
410             -> ConstEvalRawResult<'tcx> {
411             no_force
412             desc { |tcx|
413                 "const-evaluating `{}`",
414                 tcx.def_path_str(key.value.instance.def.def_id())
415             }
416             cache { true }
417             load_cached(tcx, id) {
418                 tcx.queries.on_disk_cache.try_load_query_result(tcx, id).map(Ok)
419             }
420         }
421
422         /// Results of evaluating const items or constants embedded in
423         /// other items (such as enum variant explicit discriminants).
424         query const_eval(key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
425             -> ConstEvalResult<'tcx> {
426             no_force
427             desc { |tcx|
428                 "const-evaluating + checking `{}`",
429                 tcx.def_path_str(key.value.instance.def.def_id())
430             }
431             cache { true }
432             load_cached(tcx, id) {
433                 tcx.queries.on_disk_cache.try_load_query_result(tcx, id).map(Ok)
434             }
435         }
436     }
437
438     TypeChecking {
439         query check_match(_: DefId) -> () {}
440
441         /// Performs part of the privacy check and computes "access levels".
442         query privacy_access_levels(_: CrateNum) -> Lrc<AccessLevels> {
443             eval_always
444             desc { "privacy access levels" }
445         }
446         query check_private_in_public(_: CrateNum) -> () {
447             eval_always
448             desc { "checking for private elements in public interfaces" }
449         }
450     }
451
452     Other {
453         query reachable_set(_: CrateNum) -> ReachableSet {
454             desc { "reachability" }
455         }
456
457         /// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
458         /// in the case of closures, this will be redirected to the enclosing function.
459         query region_scope_tree(_: DefId) -> &'tcx region::ScopeTree {}
460
461         query mir_shims(key: ty::InstanceDef<'tcx>) -> &'tcx mir::Mir<'tcx> {
462             no_force
463             desc { |tcx| "generating MIR shim for `{}`", tcx.def_path_str(key.def_id()) }
464         }
465
466         query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName {
467             no_force
468             desc { "computing the symbol for `{}`", key }
469             cache { true }
470         }
471
472         query describe_def(_: DefId) -> Option<Def> {}
473         query def_span(_: DefId) -> Span {
474             // FIXME(mw): DefSpans are not really inputs since they are derived from
475             // HIR. But at the moment HIR hashing still contains some hacks that allow
476             // to make type debuginfo to be source location independent. Declaring
477             // DefSpan an input makes sure that changes to these are always detected
478             // regardless of HIR hashing.
479             eval_always
480         }
481         query lookup_stability(_: DefId) -> Option<&'tcx attr::Stability> {}
482         query lookup_deprecation_entry(_: DefId) -> Option<DeprecationEntry> {}
483         query item_attrs(_: DefId) -> Lrc<[ast::Attribute]> {}
484     }
485
486     Codegen {
487         query codegen_fn_attrs(_: DefId) -> CodegenFnAttrs {}
488     }
489
490     Other {
491         query fn_arg_names(_: DefId) -> Vec<ast::Name> {}
492         /// Gets the rendered value of the specified constant or associated constant.
493         /// Used by rustdoc.
494         query rendered_const(_: DefId) -> String {}
495         query impl_parent(_: DefId) -> Option<DefId> {}
496     }
497
498     TypeChecking {
499         query trait_of_item(_: DefId) -> Option<DefId> {}
500         query const_is_rvalue_promotable_to_static(key: DefId) -> bool {
501             desc { |tcx|
502                 "const checking if rvalue is promotable to static `{}`",
503                 tcx.def_path_str(key)
504             }
505             cache { true }
506         }
507         query rvalue_promotable_map(key: DefId) -> &'tcx ItemLocalSet {
508             desc { |tcx|
509                 "checking which parts of `{}` are promotable to static",
510                 tcx.def_path_str(key)
511             }
512         }
513     }
514
515     Codegen {
516         query is_mir_available(key: DefId) -> bool {
517             desc { |tcx| "checking if item has mir available: `{}`", tcx.def_path_str(key) }
518         }
519     }
520
521     Other {
522         query vtable_methods(key: ty::PolyTraitRef<'tcx>)
523                             -> &'tcx [Option<(DefId, SubstsRef<'tcx>)>] {
524             no_force
525             desc { |tcx| "finding all methods for trait {}", tcx.def_path_str(key.def_id()) }
526         }
527     }
528
529     Codegen {
530         query codegen_fulfill_obligation(
531             key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)
532         ) -> Vtable<'tcx, ()> {
533             no_force
534             cache { true }
535             desc { |tcx|
536                 "checking if `{}` fulfills its obligations",
537                 tcx.def_path_str(key.1.def_id())
538             }
539         }
540     }
541
542     TypeChecking {
543         query trait_impls_of(key: DefId) -> &'tcx ty::trait_def::TraitImpls {
544             desc { |tcx| "trait impls of `{}`", tcx.def_path_str(key) }
545         }
546         query specialization_graph_of(_: DefId) -> &'tcx specialization_graph::Graph {}
547         query is_object_safe(key: DefId) -> bool {
548             desc { |tcx| "determine object safety of trait `{}`", tcx.def_path_str(key) }
549         }
550
551         /// Gets the ParameterEnvironment for a given item; this environment
552         /// will be in "user-facing" mode, meaning that it is suitabe for
553         /// type-checking etc, and it does not normalize specializable
554         /// associated types. This is almost always what you want,
555         /// unless you are doing MIR optimizations, in which case you
556         /// might want to use `reveal_all()` method to change modes.
557         query param_env(_: DefId) -> ty::ParamEnv<'tcx> {}
558
559         /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`,
560         /// `ty.is_copy()`, etc, since that will prune the environment where possible.
561         query is_copy_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
562             no_force
563             desc { "computing whether `{}` is `Copy`", env.value }
564         }
565         query is_sized_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
566             no_force
567             desc { "computing whether `{}` is `Sized`", env.value }
568         }
569         query is_freeze_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool {
570             no_force
571             desc { "computing whether `{}` is freeze", env.value }
572         }
573
574         // The cycle error here should be reported as an error by `check_representable`.
575         // We consider the type as not needing drop in the meanwhile to avoid
576         // further errors (done in impl Value for NeedsDrop).
577         // Use `cycle_delay_bug` to delay the cycle error here to be emitted later
578         // in case we accidentally otherwise don't emit an error.
579         query needs_drop_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> NeedsDrop {
580             cycle_delay_bug
581             no_force
582             desc { "computing whether `{}` needs drop", env.value }
583         }
584
585         query layout_raw(
586             env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
587         ) -> Result<&'tcx ty::layout::LayoutDetails, ty::layout::LayoutError<'tcx>> {
588             no_force
589             desc { "computing layout of `{}`", env.value }
590         }
591     }
592
593     Other {
594         query dylib_dependency_formats(_: CrateNum)
595                                         -> Lrc<Vec<(CrateNum, LinkagePreference)>> {
596             desc { "dylib dependency formats of crate" }
597         }
598     }
599
600     Codegen {
601         query is_compiler_builtins(_: CrateNum) -> bool {
602             fatal_cycle
603             desc { "checking if the crate is_compiler_builtins" }
604         }
605         query has_global_allocator(_: CrateNum) -> bool {
606             fatal_cycle
607             desc { "checking if the crate has_global_allocator" }
608         }
609         query has_panic_handler(_: CrateNum) -> bool {
610             fatal_cycle
611             desc { "checking if the crate has_panic_handler" }
612         }
613         query is_sanitizer_runtime(_: CrateNum) -> bool {
614             fatal_cycle
615             desc { "query a crate is #![sanitizer_runtime]" }
616         }
617         query is_profiler_runtime(_: CrateNum) -> bool {
618             fatal_cycle
619             desc { "query a crate is #![profiler_runtime]" }
620         }
621         query panic_strategy(_: CrateNum) -> PanicStrategy {
622             fatal_cycle
623             desc { "query a crate's configured panic strategy" }
624         }
625         query is_no_builtins(_: CrateNum) -> bool {
626             fatal_cycle
627             desc { "test whether a crate has #![no_builtins]" }
628         }
629
630         query extern_crate(_: DefId) -> Lrc<Option<ExternCrate>> {
631             eval_always
632             desc { "getting crate's ExternCrateData" }
633         }
634     }
635
636     TypeChecking {
637         query specializes(_: (DefId, DefId)) -> bool {
638             no_force
639             desc { "computing whether impls specialize one another" }
640         }
641         query in_scope_traits_map(_: DefIndex)
642             -> Option<Lrc<FxHashMap<ItemLocalId, Lrc<StableVec<TraitCandidate>>>>> {
643             eval_always
644             desc { "traits in scope at a block" }
645         }
646     }
647
648     Other {
649         query module_exports(_: DefId) -> Option<Lrc<Vec<Export<hir::HirId>>>> {
650             eval_always
651         }
652     }
653
654     TypeChecking {
655         query impl_defaultness(_: DefId) -> hir::Defaultness {}
656
657         query check_item_well_formed(_: DefId) -> () {}
658         query check_trait_item_well_formed(_: DefId) -> () {}
659         query check_impl_item_well_formed(_: DefId) -> () {}
660     }
661
662     Linking {
663         // The DefIds of all non-generic functions and statics in the given crate
664         // that can be reached from outside the crate.
665         //
666         // We expect this items to be available for being linked to.
667         //
668         // This query can also be called for LOCAL_CRATE. In this case it will
669         // compute which items will be reachable to other crates, taking into account
670         // the kind of crate that is currently compiled. Crates with only a
671         // C interface have fewer reachable things.
672         //
673         // Does not include external symbols that don't have a corresponding DefId,
674         // like the compiler-generated `main` function and so on.
675         query reachable_non_generics(_: CrateNum)
676             -> Lrc<DefIdMap<SymbolExportLevel>> {
677             desc { "looking up the exported symbols of a crate" }
678         }
679         query is_reachable_non_generic(_: DefId) -> bool {}
680         query is_unreachable_local_definition(_: DefId) -> bool {}
681     }
682
683     Codegen {
684         query upstream_monomorphizations(
685             k: CrateNum
686         ) -> Lrc<DefIdMap<Lrc<FxHashMap<SubstsRef<'tcx>, CrateNum>>>> {
687             desc { "collecting available upstream monomorphizations `{:?}`", k }
688         }
689         query upstream_monomorphizations_for(_: DefId)
690             -> Option<Lrc<FxHashMap<SubstsRef<'tcx>, CrateNum>>> {}
691     }
692
693     Other {
694         query foreign_modules(_: CrateNum) -> Lrc<Vec<ForeignModule>> {
695             desc { "looking up the foreign modules of a linked crate" }
696         }
697
698         /// Identifies the entry-point (e.g., the `main` function) for a given
699         /// crate, returning `None` if there is no entry point (such as for library crates).
700         query entry_fn(_: CrateNum) -> Option<(DefId, EntryFnType)> {
701             desc { "looking up the entry function of a crate" }
702         }
703         query plugin_registrar_fn(_: CrateNum) -> Option<DefId> {
704             desc { "looking up the plugin registrar for a crate" }
705         }
706         query proc_macro_decls_static(_: CrateNum) -> Option<DefId> {
707             desc { "looking up the derive registrar for a crate" }
708         }
709         query crate_disambiguator(_: CrateNum) -> CrateDisambiguator {
710             eval_always
711             desc { "looking up the disambiguator a crate" }
712         }
713         query crate_hash(_: CrateNum) -> Svh {
714             eval_always
715             desc { "looking up the hash a crate" }
716         }
717         query original_crate_name(_: CrateNum) -> Symbol {
718             eval_always
719             desc { "looking up the original name a crate" }
720         }
721         query extra_filename(_: CrateNum) -> String {
722             eval_always
723             desc { "looking up the extra filename for a crate" }
724         }
725     }
726
727     TypeChecking {
728         query implementations_of_trait(_: (CrateNum, DefId))
729             -> Lrc<Vec<DefId>> {
730             no_force
731             desc { "looking up implementations of a trait in a crate" }
732         }
733         query all_trait_implementations(_: CrateNum)
734             -> Lrc<Vec<DefId>> {
735             desc { "looking up all (?) trait implementations" }
736         }
737     }
738
739     Other {
740         query dllimport_foreign_items(_: CrateNum)
741             -> Lrc<FxHashSet<DefId>> {
742             desc { "dllimport_foreign_items" }
743         }
744         query is_dllimport_foreign_item(_: DefId) -> bool {}
745         query is_statically_included_foreign_item(_: DefId) -> bool {}
746         query native_library_kind(_: DefId)
747             -> Option<NativeLibraryKind> {}
748     }
749
750     Linking {
751         query link_args(_: CrateNum) -> Lrc<Vec<String>> {
752             eval_always
753             desc { "looking up link arguments for a crate" }
754         }
755     }
756
757     BorrowChecking {
758         // Lifetime resolution. See `middle::resolve_lifetimes`.
759         query resolve_lifetimes(_: CrateNum) -> Lrc<ResolveLifetimes> {
760             desc { "resolving lifetimes" }
761         }
762         query named_region_map(_: DefIndex) ->
763             Option<Lrc<FxHashMap<ItemLocalId, Region>>> {
764             desc { "looking up a named region" }
765         }
766         query is_late_bound_map(_: DefIndex) ->
767             Option<Lrc<FxHashSet<ItemLocalId>>> {
768             desc { "testing if a region is late bound" }
769         }
770         query object_lifetime_defaults_map(_: DefIndex)
771             -> Option<Lrc<FxHashMap<ItemLocalId, Lrc<Vec<ObjectLifetimeDefault>>>>> {
772             desc { "looking up lifetime defaults for a region" }
773         }
774     }
775
776     TypeChecking {
777         query visibility(_: DefId) -> ty::Visibility {}
778     }
779
780     Other {
781         query dep_kind(_: CrateNum) -> DepKind {
782             eval_always
783             desc { "fetching what a dependency looks like" }
784         }
785         query crate_name(_: CrateNum) -> Symbol {
786             eval_always
787             desc { "fetching what a crate is named" }
788         }
789         query item_children(_: DefId) -> Lrc<Vec<Export<hir::HirId>>> {}
790         query extern_mod_stmt_cnum(_: DefId) -> Option<CrateNum> {}
791
792         query get_lib_features(_: CrateNum) -> Lrc<LibFeatures> {
793             eval_always
794             desc { "calculating the lib features map" }
795         }
796         query defined_lib_features(_: CrateNum)
797             -> Lrc<Vec<(Symbol, Option<Symbol>)>> {
798             desc { "calculating the lib features defined in a crate" }
799         }
800         query get_lang_items(_: CrateNum) -> Lrc<LanguageItems> {
801             eval_always
802             desc { "calculating the lang items map" }
803         }
804         query defined_lang_items(_: CrateNum) -> Lrc<Vec<(DefId, usize)>> {
805             desc { "calculating the lang items defined in a crate" }
806         }
807         query missing_lang_items(_: CrateNum) -> Lrc<Vec<LangItem>> {
808             desc { "calculating the missing lang items in a crate" }
809         }
810         query visible_parent_map(_: CrateNum)
811             -> Lrc<DefIdMap<DefId>> {
812             desc { "calculating the visible parent map" }
813         }
814         query missing_extern_crate_item(_: CrateNum) -> bool {
815             eval_always
816             desc { "seeing if we're missing an `extern crate` item for this crate" }
817         }
818         query used_crate_source(_: CrateNum) -> Lrc<CrateSource> {
819             eval_always
820             desc { "looking at the source for a crate" }
821         }
822         query postorder_cnums(_: CrateNum) -> Lrc<Vec<CrateNum>> {
823             eval_always
824             desc { "generating a postorder list of CrateNums" }
825         }
826
827         query freevars(_: DefId) -> Option<Lrc<Vec<hir::Freevar>>> {
828             eval_always
829         }
830         query maybe_unused_trait_import(_: DefId) -> bool {
831             eval_always
832         }
833         query maybe_unused_extern_crates(_: CrateNum)
834             -> Lrc<Vec<(DefId, Span)>> {
835             eval_always
836             desc { "looking up all possibly unused extern crates" }
837         }
838         query names_imported_by_glob_use(_: DefId)
839             -> Lrc<FxHashSet<ast::Name>> {
840             eval_always
841         }
842
843         query stability_index(_: CrateNum) -> Lrc<stability::Index<'tcx>> {
844             eval_always
845             desc { "calculating the stability index for the local crate" }
846         }
847         query all_crate_nums(_: CrateNum) -> Lrc<Vec<CrateNum>> {
848             eval_always
849             desc { "fetching all foreign CrateNum instances" }
850         }
851
852         /// A vector of every trait accessible in the whole crate
853         /// (i.e., including those from subcrates). This is used only for
854         /// error reporting.
855         query all_traits(_: CrateNum) -> Lrc<Vec<DefId>> {
856             desc { "fetching all foreign and local traits" }
857         }
858     }
859
860     Linking {
861         query exported_symbols(_: CrateNum)
862             -> Arc<Vec<(ExportedSymbol<'tcx>, SymbolExportLevel)>> {
863             desc { "exported_symbols" }
864         }
865     }
866
867     Codegen {
868         query collect_and_partition_mono_items(_: CrateNum)
869             -> (Arc<DefIdSet>, Arc<Vec<Arc<CodegenUnit<'tcx>>>>) {
870             eval_always
871             desc { "collect_and_partition_mono_items" }
872         }
873         query is_codegened_item(_: DefId) -> bool {}
874         query codegen_unit(_: InternedString) -> Arc<CodegenUnit<'tcx>> {
875             no_force
876             desc { "codegen_unit" }
877         }
878         query backend_optimization_level(_: CrateNum) -> OptLevel {
879             desc { "optimization level used by backend" }
880         }
881     }
882
883     Other {
884         query output_filenames(_: CrateNum) -> Arc<OutputFilenames> {
885             eval_always
886             desc { "output_filenames" }
887         }
888     }
889
890     TypeChecking {
891         /// Do not call this query directly: invoke `normalize` instead.
892         query normalize_projection_ty(
893             goal: CanonicalProjectionGoal<'tcx>
894         ) -> Result<
895             &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
896             NoSolution,
897         > {
898             no_force
899             desc { "normalizing `{:?}`", goal }
900         }
901
902         /// Do not call this query directly: invoke `normalize_erasing_regions` instead.
903         query normalize_ty_after_erasing_regions(
904             goal: ParamEnvAnd<'tcx, Ty<'tcx>>
905         ) -> Ty<'tcx> {
906             no_force
907             desc { "normalizing `{:?}`", goal }
908         }
909
910         query implied_outlives_bounds(
911             goal: CanonicalTyGoal<'tcx>
912         ) -> Result<
913             &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>,
914             NoSolution,
915         > {
916             no_force
917             desc { "computing implied outlives bounds for `{:?}`", goal }
918         }
919
920         /// Do not call this query directly: invoke `infcx.at().dropck_outlives()` instead.
921         query dropck_outlives(
922             goal: CanonicalTyGoal<'tcx>
923         ) -> Result<
924             &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>,
925             NoSolution,
926         > {
927             no_force
928             desc { "computing dropck types for `{:?}`", goal }
929         }
930
931         /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
932         /// `infcx.predicate_must_hold()` instead.
933         query evaluate_obligation(
934             goal: CanonicalPredicateGoal<'tcx>
935         ) -> Result<traits::EvaluationResult, traits::OverflowError> {
936             no_force
937             desc { "evaluating trait selection obligation `{}`", goal.value.value }
938         }
939
940         query evaluate_goal(
941             goal: traits::ChalkCanonicalGoal<'tcx>
942         ) -> Result<
943             &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
944             NoSolution
945         > {
946             no_force
947             desc { "evaluating trait selection obligation `{}`", goal.value.goal }
948         }
949
950         /// Do not call this query directly: part of the `Eq` type-op
951         query type_op_ascribe_user_type(
952             goal: CanonicalTypeOpAscribeUserTypeGoal<'tcx>
953         ) -> Result<
954             &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
955             NoSolution,
956         > {
957             no_force
958             desc { "evaluating `type_op_ascribe_user_type` `{:?}`", goal }
959         }
960
961         /// Do not call this query directly: part of the `Eq` type-op
962         query type_op_eq(
963             goal: CanonicalTypeOpEqGoal<'tcx>
964         ) -> Result<
965             &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
966             NoSolution,
967         > {
968             no_force
969             desc { "evaluating `type_op_eq` `{:?}`", goal }
970         }
971
972         /// Do not call this query directly: part of the `Subtype` type-op
973         query type_op_subtype(
974             goal: CanonicalTypeOpSubtypeGoal<'tcx>
975         ) -> Result<
976             &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
977             NoSolution,
978         > {
979             no_force
980             desc { "evaluating `type_op_subtype` `{:?}`", goal }
981         }
982
983         /// Do not call this query directly: part of the `ProvePredicate` type-op
984         query type_op_prove_predicate(
985             goal: CanonicalTypeOpProvePredicateGoal<'tcx>
986         ) -> Result<
987             &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
988             NoSolution,
989         > {
990             no_force
991             desc { "evaluating `type_op_prove_predicate` `{:?}`", goal }
992         }
993
994         /// Do not call this query directly: part of the `Normalize` type-op
995         query type_op_normalize_ty(
996             goal: CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
997         ) -> Result<
998             &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>,
999             NoSolution,
1000         > {
1001             no_force
1002             desc { "normalizing `{:?}`", goal }
1003         }
1004
1005         /// Do not call this query directly: part of the `Normalize` type-op
1006         query type_op_normalize_predicate(
1007             goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
1008         ) -> Result<
1009             &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>,
1010             NoSolution,
1011         > {
1012             no_force
1013             desc { "normalizing `{:?}`", goal }
1014         }
1015
1016         /// Do not call this query directly: part of the `Normalize` type-op
1017         query type_op_normalize_poly_fn_sig(
1018             goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
1019         ) -> Result<
1020             &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>,
1021             NoSolution,
1022         > {
1023             no_force
1024             desc { "normalizing `{:?}`", goal }
1025         }
1026
1027         /// Do not call this query directly: part of the `Normalize` type-op
1028         query type_op_normalize_fn_sig(
1029             goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
1030         ) -> Result<
1031             &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>,
1032             NoSolution,
1033         > {
1034             no_force
1035             desc { "normalizing `{:?}`", goal }
1036         }
1037
1038         query substitute_normalize_and_test_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
1039             no_force
1040             desc { |tcx|
1041                 "testing substituted normalized predicates:`{}`",
1042                 tcx.def_path_str(key.0)
1043             }
1044         }
1045
1046         query method_autoderef_steps(
1047             goal: CanonicalTyGoal<'tcx>
1048         ) -> MethodAutoderefStepsResult<'tcx> {
1049             no_force
1050             desc { "computing autoderef types for `{:?}`", goal }
1051         }
1052     }
1053
1054     Other {
1055         query target_features_whitelist(_: CrateNum) -> Lrc<FxHashMap<String, Option<String>>> {
1056             eval_always
1057             desc { "looking up the whitelist of target features" }
1058         }
1059
1060         // Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.
1061         query instance_def_size_estimate(def: ty::InstanceDef<'tcx>)
1062             -> usize {
1063             no_force
1064             desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) }
1065         }
1066
1067         query features_query(_: CrateNum) -> Lrc<feature_gate::Features> {
1068             eval_always
1069             desc { "looking up enabled feature gates" }
1070         }
1071     }
1072 }