1 // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use dep_graph::SerializedDepNodeIndex;
12 use dep_graph::DepNode;
13 use hir::def_id::{CrateNum, DefId, DefIndex};
14 use mir::interpret::GlobalId;
16 CanonicalPredicateGoal, CanonicalProjectionGoal, CanonicalTyGoal, CanonicalTypeOpEqGoal,
17 CanonicalTypeOpNormalizeGoal, CanonicalTypeOpProvePredicateGoal, CanonicalTypeOpSubtypeGoal,
19 use ty::{self, ParamEnvAnd, Ty, TyCtxt};
20 use ty::subst::Substs;
21 use ty::query::queries;
23 use ty::query::QueryCache;
27 use syntax_pos::symbol::InternedString;
28 use rustc_data_structures::sync::Lock;
29 use rustc_data_structures::stable_hasher::HashStable;
30 use ich::StableHashingContext;
32 // Query configuration and description traits.
34 pub trait QueryConfig<'tcx> {
35 const NAME: &'static str;
37 type Key: Eq + Hash + Clone + Debug;
38 type Value: Clone + for<'a> HashStable<StableHashingContext<'a>>;
41 pub(super) trait QueryAccessors<'tcx>: QueryConfig<'tcx> {
42 fn query(key: Self::Key) -> Query<'tcx>;
44 // Don't use this method to access query results, instead use the methods on TyCtxt
45 fn query_cache<'a>(tcx: TyCtxt<'a, 'tcx, '_>) -> &'a Lock<QueryCache<'tcx, Self>>;
47 fn to_dep_node(tcx: TyCtxt<'_, 'tcx, '_>, key: &Self::Key) -> DepNode;
49 // Don't use this method to compute query results, instead use the methods on TyCtxt
50 fn compute(tcx: TyCtxt<'_, 'tcx, '_>, key: Self::Key) -> Self::Value;
52 fn handle_cycle_error(tcx: TyCtxt<'_, 'tcx, '_>) -> Self::Value;
55 pub(super) trait QueryDescription<'tcx>: QueryAccessors<'tcx> {
56 fn describe(tcx: TyCtxt, key: Self::Key) -> String;
59 fn cache_on_disk(_: Self::Key) -> bool {
63 fn try_load_from_disk(_: TyCtxt<'_, 'tcx, 'tcx>,
64 _: SerializedDepNodeIndex)
65 -> Option<Self::Value> {
66 bug!("QueryDescription::load_from_disk() called for an unsupported query.")
70 impl<'tcx, M: QueryAccessors<'tcx, Key=DefId>> QueryDescription<'tcx> for M {
71 default fn describe(tcx: TyCtxt, def_id: DefId) -> String {
72 if !tcx.sess.verbose() {
73 format!("processing `{}`", tcx.item_path_str(def_id))
75 let name = unsafe { ::std::intrinsics::type_name::<M>() };
76 format!("processing `{}` applied to `{:?}`", name, def_id)
81 impl<'tcx> QueryDescription<'tcx> for queries::normalize_projection_ty<'tcx> {
84 goal: CanonicalProjectionGoal<'tcx>,
86 format!("normalizing `{:?}`", goal)
90 impl<'tcx> QueryDescription<'tcx> for queries::dropck_outlives<'tcx> {
91 fn describe(_tcx: TyCtxt, goal: CanonicalTyGoal<'tcx>) -> String {
92 format!("computing dropck types for `{:?}`", goal)
96 impl<'tcx> QueryDescription<'tcx> for queries::normalize_ty_after_erasing_regions<'tcx> {
97 fn describe(_tcx: TyCtxt, goal: ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
98 format!("normalizing `{:?}`", goal)
102 impl<'tcx> QueryDescription<'tcx> for queries::evaluate_obligation<'tcx> {
103 fn describe(_tcx: TyCtxt, goal: CanonicalPredicateGoal<'tcx>) -> String {
104 format!("evaluating trait selection obligation `{}`", goal.value.value)
108 impl<'tcx> QueryDescription<'tcx> for queries::type_op_eq<'tcx> {
109 fn describe(_tcx: TyCtxt, goal: CanonicalTypeOpEqGoal<'tcx>) -> String {
110 format!("evaluating `type_op_eq` `{:?}`", goal)
114 impl<'tcx> QueryDescription<'tcx> for queries::type_op_subtype<'tcx> {
115 fn describe(_tcx: TyCtxt, goal: CanonicalTypeOpSubtypeGoal<'tcx>) -> String {
116 format!("evaluating `type_op_subtype` `{:?}`", goal)
120 impl<'tcx> QueryDescription<'tcx> for queries::type_op_prove_predicate<'tcx> {
121 fn describe(_tcx: TyCtxt, goal: CanonicalTypeOpProvePredicateGoal<'tcx>) -> String {
122 format!("evaluating `type_op_prove_predicate` `{:?}`", goal)
126 impl<'tcx> QueryDescription<'tcx> for queries::type_op_normalize_ty<'tcx> {
127 fn describe(_tcx: TyCtxt, goal: CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>) -> String {
128 format!("normalizing `{:?}`", goal)
132 impl<'tcx> QueryDescription<'tcx> for queries::type_op_normalize_predicate<'tcx> {
135 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>,
137 format!("normalizing `{:?}`", goal)
141 impl<'tcx> QueryDescription<'tcx> for queries::type_op_normalize_poly_fn_sig<'tcx> {
144 goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>,
146 format!("normalizing `{:?}`", goal)
150 impl<'tcx> QueryDescription<'tcx> for queries::type_op_normalize_fn_sig<'tcx> {
151 fn describe(_tcx: TyCtxt, goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>) -> String {
152 format!("normalizing `{:?}`", goal)
156 impl<'tcx> QueryDescription<'tcx> for queries::is_copy_raw<'tcx> {
157 fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
158 format!("computing whether `{}` is `Copy`", env.value)
162 impl<'tcx> QueryDescription<'tcx> for queries::is_sized_raw<'tcx> {
163 fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
164 format!("computing whether `{}` is `Sized`", env.value)
168 impl<'tcx> QueryDescription<'tcx> for queries::is_freeze_raw<'tcx> {
169 fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
170 format!("computing whether `{}` is freeze", env.value)
174 impl<'tcx> QueryDescription<'tcx> for queries::needs_drop_raw<'tcx> {
175 fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
176 format!("computing whether `{}` needs drop", env.value)
180 impl<'tcx> QueryDescription<'tcx> for queries::layout_raw<'tcx> {
181 fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
182 format!("computing layout of `{}`", env.value)
186 impl<'tcx> QueryDescription<'tcx> for queries::super_predicates_of<'tcx> {
187 fn describe(tcx: TyCtxt, def_id: DefId) -> String {
188 format!("computing the supertraits of `{}`",
189 tcx.item_path_str(def_id))
193 impl<'tcx> QueryDescription<'tcx> for queries::const_value_to_allocation<'tcx> {
194 fn describe(_tcx: TyCtxt, val: &'tcx ty::Const<'tcx>) -> String {
195 format!("converting value `{:?}` to an allocation", val)
199 impl<'tcx> QueryDescription<'tcx> for queries::erase_regions_ty<'tcx> {
200 fn describe(_tcx: TyCtxt, ty: Ty<'tcx>) -> String {
201 format!("erasing regions from `{:?}`", ty)
205 impl<'tcx> QueryDescription<'tcx> for queries::type_param_predicates<'tcx> {
206 fn describe(tcx: TyCtxt, (_, def_id): (DefId, DefId)) -> String {
207 let id = tcx.hir.as_local_node_id(def_id).unwrap();
208 format!("computing the bounds for type parameter `{}`",
209 tcx.hir.ty_param_name(id))
213 impl<'tcx> QueryDescription<'tcx> for queries::coherent_trait<'tcx> {
214 fn describe(tcx: TyCtxt, def_id: DefId) -> String {
215 format!("coherence checking all impls of trait `{}`",
216 tcx.item_path_str(def_id))
220 impl<'tcx> QueryDescription<'tcx> for queries::upstream_monomorphizations<'tcx> {
221 fn describe(_: TyCtxt, k: CrateNum) -> String {
222 format!("collecting available upstream monomorphizations `{:?}`", k)
226 impl<'tcx> QueryDescription<'tcx> for queries::crate_inherent_impls<'tcx> {
227 fn describe(_: TyCtxt, k: CrateNum) -> String {
228 format!("all inherent impls defined in crate `{:?}`", k)
232 impl<'tcx> QueryDescription<'tcx> for queries::crate_inherent_impls_overlap_check<'tcx> {
233 fn describe(_: TyCtxt, _: CrateNum) -> String {
234 format!("check for overlap between inherent impls defined in this crate")
238 impl<'tcx> QueryDescription<'tcx> for queries::crate_variances<'tcx> {
239 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
240 format!("computing the variances for items in this crate")
244 impl<'tcx> QueryDescription<'tcx> for queries::inferred_outlives_crate<'tcx> {
245 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
246 format!("computing the inferred outlives predicates for items in this crate")
250 impl<'tcx> QueryDescription<'tcx> for queries::mir_shims<'tcx> {
251 fn describe(tcx: TyCtxt, def: ty::InstanceDef<'tcx>) -> String {
252 format!("generating MIR shim for `{}`",
253 tcx.item_path_str(def.def_id()))
257 impl<'tcx> QueryDescription<'tcx> for queries::privacy_access_levels<'tcx> {
258 fn describe(_: TyCtxt, _: CrateNum) -> String {
259 format!("privacy access levels")
263 impl<'tcx> QueryDescription<'tcx> for queries::typeck_item_bodies<'tcx> {
264 fn describe(_: TyCtxt, _: CrateNum) -> String {
265 format!("type-checking all item bodies")
269 impl<'tcx> QueryDescription<'tcx> for queries::reachable_set<'tcx> {
270 fn describe(_: TyCtxt, _: CrateNum) -> String {
271 format!("reachability")
275 impl<'tcx> QueryDescription<'tcx> for queries::const_eval<'tcx> {
276 fn describe(tcx: TyCtxt, key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>) -> String {
277 format!("const-evaluating `{}`", tcx.item_path_str(key.value.instance.def.def_id()))
281 fn cache_on_disk(_key: Self::Key) -> bool {
286 fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
287 id: SerializedDepNodeIndex)
288 -> Option<Self::Value> {
289 tcx.queries.on_disk_cache.try_load_query_result(tcx, id).map(Ok)
293 impl<'tcx> QueryDescription<'tcx> for queries::mir_keys<'tcx> {
294 fn describe(_: TyCtxt, _: CrateNum) -> String {
295 format!("getting a list of all mir_keys")
299 impl<'tcx> QueryDescription<'tcx> for queries::symbol_name<'tcx> {
300 fn describe(_tcx: TyCtxt, instance: ty::Instance<'tcx>) -> String {
301 format!("computing the symbol for `{}`", instance)
305 fn cache_on_disk(_: Self::Key) -> bool {
310 fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
311 id: SerializedDepNodeIndex)
312 -> Option<Self::Value> {
313 tcx.queries.on_disk_cache.try_load_query_result(tcx, id)
317 impl<'tcx> QueryDescription<'tcx> for queries::describe_def<'tcx> {
318 fn describe(_: TyCtxt, _: DefId) -> String {
323 impl<'tcx> QueryDescription<'tcx> for queries::def_span<'tcx> {
324 fn describe(_: TyCtxt, _: DefId) -> String {
330 impl<'tcx> QueryDescription<'tcx> for queries::lookup_stability<'tcx> {
331 fn describe(_: TyCtxt, _: DefId) -> String {
336 impl<'tcx> QueryDescription<'tcx> for queries::lookup_deprecation_entry<'tcx> {
337 fn describe(_: TyCtxt, _: DefId) -> String {
342 impl<'tcx> QueryDescription<'tcx> for queries::item_attrs<'tcx> {
343 fn describe(_: TyCtxt, _: DefId) -> String {
348 impl<'tcx> QueryDescription<'tcx> for queries::is_reachable_non_generic<'tcx> {
349 fn describe(_: TyCtxt, _: DefId) -> String {
350 bug!("is_reachable_non_generic")
354 impl<'tcx> QueryDescription<'tcx> for queries::fn_arg_names<'tcx> {
355 fn describe(_: TyCtxt, _: DefId) -> String {
360 impl<'tcx> QueryDescription<'tcx> for queries::impl_parent<'tcx> {
361 fn describe(_: TyCtxt, _: DefId) -> String {
366 impl<'tcx> QueryDescription<'tcx> for queries::trait_of_item<'tcx> {
367 fn describe(_: TyCtxt, _: DefId) -> String {
368 bug!("trait_of_item")
372 impl<'tcx> QueryDescription<'tcx> for queries::const_is_rvalue_promotable_to_static<'tcx> {
373 fn describe(tcx: TyCtxt, def_id: DefId) -> String {
374 format!("const checking if rvalue is promotable to static `{}`",
375 tcx.item_path_str(def_id))
379 fn cache_on_disk(_: Self::Key) -> bool {
384 fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
385 id: SerializedDepNodeIndex)
386 -> Option<Self::Value> {
387 tcx.queries.on_disk_cache.try_load_query_result(tcx, id)
391 impl<'tcx> QueryDescription<'tcx> for queries::rvalue_promotable_map<'tcx> {
392 fn describe(tcx: TyCtxt, def_id: DefId) -> String {
393 format!("checking which parts of `{}` are promotable to static",
394 tcx.item_path_str(def_id))
398 impl<'tcx> QueryDescription<'tcx> for queries::is_mir_available<'tcx> {
399 fn describe(tcx: TyCtxt, def_id: DefId) -> String {
400 format!("checking if item is mir available: `{}`",
401 tcx.item_path_str(def_id))
405 impl<'tcx> QueryDescription<'tcx> for queries::codegen_fulfill_obligation<'tcx> {
406 fn describe(tcx: TyCtxt, key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)) -> String {
407 format!("checking if `{}` fulfills its obligations", tcx.item_path_str(key.1.def_id()))
411 fn cache_on_disk(_: Self::Key) -> bool {
416 fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
417 id: SerializedDepNodeIndex)
418 -> Option<Self::Value> {
419 tcx.queries.on_disk_cache.try_load_query_result(tcx, id)
423 impl<'tcx> QueryDescription<'tcx> for queries::trait_impls_of<'tcx> {
424 fn describe(tcx: TyCtxt, def_id: DefId) -> String {
425 format!("trait impls of `{}`", tcx.item_path_str(def_id))
429 impl<'tcx> QueryDescription<'tcx> for queries::is_object_safe<'tcx> {
430 fn describe(tcx: TyCtxt, def_id: DefId) -> String {
431 format!("determine object safety of trait `{}`", tcx.item_path_str(def_id))
435 impl<'tcx> QueryDescription<'tcx> for queries::is_const_fn<'tcx> {
436 fn describe(tcx: TyCtxt, def_id: DefId) -> String {
437 format!("checking if item is const fn: `{}`", tcx.item_path_str(def_id))
441 impl<'tcx> QueryDescription<'tcx> for queries::dylib_dependency_formats<'tcx> {
442 fn describe(_: TyCtxt, _: CrateNum) -> String {
443 "dylib dependency formats of crate".to_string()
447 impl<'tcx> QueryDescription<'tcx> for queries::is_panic_runtime<'tcx> {
448 fn describe(_: TyCtxt, _: CrateNum) -> String {
449 "checking if the crate is_panic_runtime".to_string()
453 impl<'tcx> QueryDescription<'tcx> for queries::is_compiler_builtins<'tcx> {
454 fn describe(_: TyCtxt, _: CrateNum) -> String {
455 "checking if the crate is_compiler_builtins".to_string()
459 impl<'tcx> QueryDescription<'tcx> for queries::has_global_allocator<'tcx> {
460 fn describe(_: TyCtxt, _: CrateNum) -> String {
461 "checking if the crate has_global_allocator".to_string()
465 impl<'tcx> QueryDescription<'tcx> for queries::extern_crate<'tcx> {
466 fn describe(_: TyCtxt, _: DefId) -> String {
467 "getting crate's ExternCrateData".to_string()
471 impl<'tcx> QueryDescription<'tcx> for queries::lint_levels<'tcx> {
472 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
473 format!("computing the lint levels for items in this crate")
477 impl<'tcx> QueryDescription<'tcx> for queries::specializes<'tcx> {
478 fn describe(_tcx: TyCtxt, _: (DefId, DefId)) -> String {
479 format!("computing whether impls specialize one another")
483 impl<'tcx> QueryDescription<'tcx> for queries::in_scope_traits_map<'tcx> {
484 fn describe(_tcx: TyCtxt, _: DefIndex) -> String {
485 format!("traits in scope at a block")
489 impl<'tcx> QueryDescription<'tcx> for queries::is_no_builtins<'tcx> {
490 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
491 format!("test whether a crate has #![no_builtins]")
495 impl<'tcx> QueryDescription<'tcx> for queries::panic_strategy<'tcx> {
496 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
497 format!("query a crate's configured panic strategy")
501 impl<'tcx> QueryDescription<'tcx> for queries::is_profiler_runtime<'tcx> {
502 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
503 format!("query a crate is #![profiler_runtime]")
507 impl<'tcx> QueryDescription<'tcx> for queries::is_sanitizer_runtime<'tcx> {
508 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
509 format!("query a crate is #![sanitizer_runtime]")
513 impl<'tcx> QueryDescription<'tcx> for queries::reachable_non_generics<'tcx> {
514 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
515 format!("looking up the exported symbols of a crate")
519 impl<'tcx> QueryDescription<'tcx> for queries::native_libraries<'tcx> {
520 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
521 format!("looking up the native libraries of a linked crate")
525 impl<'tcx> QueryDescription<'tcx> for queries::foreign_modules<'tcx> {
526 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
527 format!("looking up the foreign modules of a linked crate")
531 impl<'tcx> QueryDescription<'tcx> for queries::plugin_registrar_fn<'tcx> {
532 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
533 format!("looking up the plugin registrar for a crate")
537 impl<'tcx> QueryDescription<'tcx> for queries::derive_registrar_fn<'tcx> {
538 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
539 format!("looking up the derive registrar for a crate")
543 impl<'tcx> QueryDescription<'tcx> for queries::crate_disambiguator<'tcx> {
544 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
545 format!("looking up the disambiguator a crate")
549 impl<'tcx> QueryDescription<'tcx> for queries::crate_hash<'tcx> {
550 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
551 format!("looking up the hash a crate")
555 impl<'tcx> QueryDescription<'tcx> for queries::original_crate_name<'tcx> {
556 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
557 format!("looking up the original name a crate")
561 impl<'tcx> QueryDescription<'tcx> for queries::extra_filename<'tcx> {
562 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
563 format!("looking up the extra filename for a crate")
567 impl<'tcx> QueryDescription<'tcx> for queries::implementations_of_trait<'tcx> {
568 fn describe(_tcx: TyCtxt, _: (CrateNum, DefId)) -> String {
569 format!("looking up implementations of a trait in a crate")
573 impl<'tcx> QueryDescription<'tcx> for queries::all_trait_implementations<'tcx> {
574 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
575 format!("looking up all (?) trait implementations")
579 impl<'tcx> QueryDescription<'tcx> for queries::link_args<'tcx> {
580 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
581 format!("looking up link arguments for a crate")
585 impl<'tcx> QueryDescription<'tcx> for queries::resolve_lifetimes<'tcx> {
586 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
587 format!("resolving lifetimes")
591 impl<'tcx> QueryDescription<'tcx> for queries::named_region_map<'tcx> {
592 fn describe(_tcx: TyCtxt, _: DefIndex) -> String {
593 format!("looking up a named region")
597 impl<'tcx> QueryDescription<'tcx> for queries::is_late_bound_map<'tcx> {
598 fn describe(_tcx: TyCtxt, _: DefIndex) -> String {
599 format!("testing if a region is late bound")
603 impl<'tcx> QueryDescription<'tcx> for queries::object_lifetime_defaults_map<'tcx> {
604 fn describe(_tcx: TyCtxt, _: DefIndex) -> String {
605 format!("looking up lifetime defaults for a region")
609 impl<'tcx> QueryDescription<'tcx> for queries::dep_kind<'tcx> {
610 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
611 format!("fetching what a dependency looks like")
615 impl<'tcx> QueryDescription<'tcx> for queries::crate_name<'tcx> {
616 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
617 format!("fetching what a crate is named")
621 impl<'tcx> QueryDescription<'tcx> for queries::get_lang_items<'tcx> {
622 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
623 format!("calculating the lang items map")
627 impl<'tcx> QueryDescription<'tcx> for queries::defined_lang_items<'tcx> {
628 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
629 format!("calculating the lang items defined in a crate")
633 impl<'tcx> QueryDescription<'tcx> for queries::missing_lang_items<'tcx> {
634 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
635 format!("calculating the missing lang items in a crate")
639 impl<'tcx> QueryDescription<'tcx> for queries::visible_parent_map<'tcx> {
640 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
641 format!("calculating the visible parent map")
645 impl<'tcx> QueryDescription<'tcx> for queries::missing_extern_crate_item<'tcx> {
646 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
647 format!("seeing if we're missing an `extern crate` item for this crate")
651 impl<'tcx> QueryDescription<'tcx> for queries::used_crate_source<'tcx> {
652 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
653 format!("looking at the source for a crate")
657 impl<'tcx> QueryDescription<'tcx> for queries::postorder_cnums<'tcx> {
658 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
659 format!("generating a postorder list of CrateNums")
663 impl<'tcx> QueryDescription<'tcx> for queries::maybe_unused_extern_crates<'tcx> {
664 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
665 format!("looking up all possibly unused extern crates")
669 impl<'tcx> QueryDescription<'tcx> for queries::stability_index<'tcx> {
670 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
671 format!("calculating the stability index for the local crate")
675 impl<'tcx> QueryDescription<'tcx> for queries::all_traits<'tcx> {
676 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
677 format!("fetching all foreign and local traits")
681 impl<'tcx> QueryDescription<'tcx> for queries::all_crate_nums<'tcx> {
682 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
683 format!("fetching all foreign CrateNum instances")
687 impl<'tcx> QueryDescription<'tcx> for queries::exported_symbols<'tcx> {
688 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
689 format!("exported_symbols")
693 impl<'tcx> QueryDescription<'tcx> for queries::collect_and_partition_mono_items<'tcx> {
694 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
695 format!("collect_and_partition_mono_items")
699 impl<'tcx> QueryDescription<'tcx> for queries::codegen_unit<'tcx> {
700 fn describe(_tcx: TyCtxt, _: InternedString) -> String {
701 format!("codegen_unit")
705 impl<'tcx> QueryDescription<'tcx> for queries::compile_codegen_unit<'tcx> {
706 fn describe(_tcx: TyCtxt, _: InternedString) -> String {
707 format!("compile_codegen_unit")
711 impl<'tcx> QueryDescription<'tcx> for queries::output_filenames<'tcx> {
712 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
713 format!("output_filenames")
717 impl<'tcx> QueryDescription<'tcx> for queries::vtable_methods<'tcx> {
718 fn describe(tcx: TyCtxt, key: ty::PolyTraitRef<'tcx> ) -> String {
719 format!("finding all methods for trait {}", tcx.item_path_str(key.def_id()))
723 impl<'tcx> QueryDescription<'tcx> for queries::features_query<'tcx> {
724 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
725 format!("looking up enabled feature gates")
729 impl<'tcx> QueryDescription<'tcx> for queries::typeck_tables_of<'tcx> {
731 fn cache_on_disk(def_id: Self::Key) -> bool {
735 fn try_load_from_disk(tcx: TyCtxt<'_, 'tcx, 'tcx>,
736 id: SerializedDepNodeIndex)
737 -> Option<Self::Value> {
738 let typeck_tables: Option<ty::TypeckTables<'tcx>> = tcx
739 .queries.on_disk_cache
740 .try_load_query_result(tcx, id);
742 typeck_tables.map(|tables| tcx.alloc_tables(tables))
746 impl<'tcx> QueryDescription<'tcx> for queries::optimized_mir<'tcx> {
748 fn cache_on_disk(def_id: Self::Key) -> bool {
752 fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
753 id: SerializedDepNodeIndex)
754 -> Option<Self::Value> {
755 let mir: Option<::mir::Mir<'tcx>> = tcx.queries.on_disk_cache
756 .try_load_query_result(tcx, id);
757 mir.map(|x| tcx.alloc_mir(x))
761 impl<'tcx> QueryDescription<'tcx> for queries::substitute_normalize_and_test_predicates<'tcx> {
762 fn describe(tcx: TyCtxt, key: (DefId, &'tcx Substs<'tcx>)) -> String {
763 format!("testing substituted normalized predicates:`{}`", tcx.item_path_str(key.0))
767 impl<'tcx> QueryDescription<'tcx> for queries::target_features_whitelist<'tcx> {
768 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
769 format!("looking up the whitelist of target features")
773 impl<'tcx> QueryDescription<'tcx> for queries::instance_def_size_estimate<'tcx> {
774 fn describe(tcx: TyCtxt, def: ty::InstanceDef<'tcx>) -> String {
775 format!("estimating size for `{}`", tcx.item_path_str(def.def_id()))
779 impl<'tcx> QueryDescription<'tcx> for queries::wasm_custom_sections<'tcx> {
780 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
781 format!("custom wasm sections for a crate")
785 impl<'tcx> QueryDescription<'tcx> for queries::generics_of<'tcx> {
787 fn cache_on_disk(def_id: Self::Key) -> bool {
791 fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
792 id: SerializedDepNodeIndex)
793 -> Option<Self::Value> {
794 let generics: Option<ty::Generics> = tcx.queries.on_disk_cache
795 .try_load_query_result(tcx, id);
796 generics.map(|x| tcx.alloc_generics(x))
800 impl<'tcx> QueryDescription<'tcx> for queries::program_clauses_for<'tcx> {
801 fn describe(_tcx: TyCtxt, _: DefId) -> String {
802 format!("generating chalk-style clauses")
806 impl<'tcx> QueryDescription<'tcx> for queries::program_clauses_for_env<'tcx> {
807 fn describe(_tcx: TyCtxt, _: ty::ParamEnv<'tcx>) -> String {
808 format!("generating chalk-style clauses for param env")
812 impl<'tcx> QueryDescription<'tcx> for queries::wasm_import_module_map<'tcx> {
813 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
814 format!("wasm import module map")
818 impl<'tcx> QueryDescription<'tcx> for queries::dllimport_foreign_items<'tcx> {
819 fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
820 format!("wasm import module map")
824 macro_rules! impl_disk_cacheable_query(
825 ($query_name:ident, |$key:tt| $cond:expr) => {
826 impl<'tcx> QueryDescription<'tcx> for queries::$query_name<'tcx> {
828 fn cache_on_disk($key: Self::Key) -> bool {
833 fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
834 id: SerializedDepNodeIndex)
835 -> Option<Self::Value> {
836 tcx.queries.on_disk_cache.try_load_query_result(tcx, id)
842 impl_disk_cacheable_query!(unsafety_check_result, |def_id| def_id.is_local());
843 impl_disk_cacheable_query!(borrowck, |def_id| def_id.is_local());
844 impl_disk_cacheable_query!(mir_borrowck, |def_id| def_id.is_local());
845 impl_disk_cacheable_query!(mir_const_qualif, |def_id| def_id.is_local());
846 impl_disk_cacheable_query!(check_match, |def_id| def_id.is_local());
847 impl_disk_cacheable_query!(def_symbol_name, |_| true);
848 impl_disk_cacheable_query!(type_of, |def_id| def_id.is_local());
849 impl_disk_cacheable_query!(predicates_of, |def_id| def_id.is_local());
850 impl_disk_cacheable_query!(used_trait_imports, |def_id| def_id.is_local());
851 impl_disk_cacheable_query!(codegen_fn_attrs, |_| true);
852 impl_disk_cacheable_query!(specialization_graph_of, |_| true);