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