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