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