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