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