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 //! The implementation of the query system itself. Defines the macros
12 //! that generate the actual methods on tcx which find and execute the
13 //! provider, manage the caches, and so forth.
15 use dep_graph::{DepNodeIndex, DepNode, DepKind, DepNodeColor};
16 use errors::DiagnosticBuilder;
18 use ty::maps::Query; // NB: actually generated by the macros in this file
19 use ty::maps::config::QueryDescription;
22 use rustc_data_structures::fx::{FxHashMap};
23 use std::cell::{Ref, RefMut};
24 use std::marker::PhantomData;
28 pub(super) struct QueryMap<'tcx, D: QueryDescription<'tcx>> {
29 phantom: PhantomData<(D, &'tcx ())>,
30 pub(super) map: FxHashMap<D::Key, QueryValue<D::Value>>,
33 pub(super) struct QueryValue<T> {
35 pub(super) index: DepNodeIndex,
38 impl<T> QueryValue<T> {
39 pub(super) fn new(value: T,
40 dep_node_index: DepNodeIndex)
44 index: dep_node_index,
49 impl<'tcx, M: QueryDescription<'tcx>> QueryMap<'tcx, M> {
50 pub(super) fn new() -> QueryMap<'tcx, M> {
58 pub(super) trait GetCacheInternal<'tcx>: QueryDescription<'tcx> + Sized {
59 fn get_cache_internal<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
60 -> Ref<'a, QueryMap<'tcx, Self>>;
63 pub(super) struct CycleError<'a, 'tcx: 'a> {
65 cycle: RefMut<'a, [(Span, Query<'tcx>)]>,
68 impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
69 pub(super) fn report_cycle(self, CycleError { span, cycle }: CycleError)
70 -> DiagnosticBuilder<'a>
72 // Subtle: release the refcell lock before invoking `describe()`
73 // below by dropping `cycle`.
74 let stack = cycle.to_vec();
77 assert!(!stack.is_empty());
79 // Disable naming impls with types in this path, since that
80 // sometimes cycles itself, leading to extra cycle errors.
81 // (And cycle errors around impls tend to occur during the
82 // collect/coherence phases anyhow.)
83 item_path::with_forced_impl_filename_line(|| {
84 let span = self.sess.codemap().def_span(span);
86 struct_span_err!(self.sess, span, E0391,
87 "unsupported cyclic reference between types/traits detected");
88 err.span_label(span, "cyclic reference");
90 err.span_note(self.sess.codemap().def_span(stack[0].0),
91 &format!("the cycle begins when {}...", stack[0].1.describe(self)));
93 for &(span, ref query) in &stack[1..] {
94 err.span_note(self.sess.codemap().def_span(span),
95 &format!("...which then requires {}...", query.describe(self)));
98 err.note(&format!("...which then again requires {}, completing the cycle.",
99 stack[0].1.describe(self)));
105 pub(super) fn cycle_check<F, R>(self, span: Span, query: Query<'gcx>, compute: F)
106 -> Result<R, CycleError<'a, 'gcx>>
107 where F: FnOnce() -> R
110 let mut stack = self.maps.query_stack.borrow_mut();
111 if let Some((i, _)) = stack.iter().enumerate().rev()
112 .find(|&(_, &(_, ref q))| *q == query) {
113 return Err(CycleError {
115 cycle: RefMut::map(stack, |stack| &mut stack[i..])
118 stack.push((span, query));
121 let result = compute();
123 self.maps.query_stack.borrow_mut().pop();
128 /// Try to read a node index for the node dep_node.
129 /// A node will have an index, when it's already been marked green, or when we can mark it
130 /// green. This function will mark the current task as a reader of the specified node, when
131 /// the a node index can be found for that node.
132 pub(super) fn try_mark_green_and_read(self, dep_node: &DepNode) -> Option<DepNodeIndex> {
133 match self.dep_graph.node_color(dep_node) {
134 Some(DepNodeColor::Green(dep_node_index)) => {
135 self.dep_graph.read_index(dep_node_index);
138 Some(DepNodeColor::Red) => {
142 // try_mark_green (called below) will panic when full incremental
143 // compilation is disabled. If that's the case, we can't try to mark nodes
144 // as green anyway, so we can safely return None here.
145 if !self.dep_graph.is_fully_enabled() {
148 match self.dep_graph.try_mark_green(self.global_tcx(), &dep_node) {
149 Some(dep_node_index) => {
150 debug_assert!(self.dep_graph.is_green(dep_node_index));
151 self.dep_graph.read_index(dep_node_index);
163 // If enabled, send a message to the profile-queries thread
164 macro_rules! profq_msg {
165 ($tcx:expr, $msg:expr) => {
166 if cfg!(debug_assertions) {
167 if $tcx.sess.profile_queries() {
174 // If enabled, format a key using its debug string, which can be
175 // expensive to compute (in terms of time).
176 macro_rules! profq_key {
177 ($tcx:expr, $key:expr) => {
178 if cfg!(debug_assertions) {
179 if $tcx.sess.profile_queries_and_keys() {
180 Some(format!("{:?}", $key))
186 macro_rules! handle_cycle_error {
187 ([][$this: expr]) => {{
188 Value::from_cycle_error($this.global_tcx())
190 ([fatal_cycle$(, $modifiers:ident)*][$this:expr]) => {{
191 $this.tcx.sess.abort_if_errors();
194 ([$other:ident$(, $modifiers:ident)*][$($args:tt)*]) => {
195 handle_cycle_error!([$($modifiers),*][$($args)*])
199 macro_rules! define_maps {
202 [$($modifiers:tt)*] fn $name:ident: $node:ident($K:ty) -> $V:ty,)*) => {
204 use dep_graph::DepNodeIndex;
205 use std::cell::RefCell;
209 input: ($(([$($modifiers)*] [$($attr)*] [$name]))*)
212 impl<$tcx> Maps<$tcx> {
213 pub fn new(providers: IndexVec<CrateNum, Providers<$tcx>>)
217 query_stack: RefCell::new(vec![]),
218 $($name: RefCell::new(QueryMap::new())),*
224 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
225 pub enum Query<$tcx> {
226 $($(#[$attr])* $name($K)),*
230 #[derive(Clone, Debug, PartialEq, Eq)]
232 $($name(Option<String>)),*
235 impl<$tcx> Query<$tcx> {
236 pub fn describe(&self, tcx: TyCtxt) -> String {
237 let (r, name) = match *self {
238 $(Query::$name(key) => {
239 (queries::$name::describe(tcx, key), stringify!($name))
242 if tcx.sess.verbose() {
243 format!("{} [{}]", r, name)
251 use std::marker::PhantomData;
253 $(#[allow(bad_style)]
254 pub struct $name<$tcx> {
255 data: PhantomData<&$tcx ()>
259 $(impl<$tcx> QueryConfig for queries::$name<$tcx> {
264 impl<$tcx> GetCacheInternal<$tcx> for queries::$name<$tcx> {
265 fn get_cache_internal<'a>(tcx: TyCtxt<'a, $tcx, $tcx>)
266 -> ::std::cell::Ref<'a, QueryMap<$tcx, Self>> {
267 tcx.maps.$name.borrow()
271 impl<'a, $tcx, 'lcx> queries::$name<$tcx> {
274 fn to_dep_node(tcx: TyCtxt<'a, $tcx, 'lcx>, key: &$K) -> DepNode {
275 use dep_graph::DepConstructor::*;
277 DepNode::new(tcx, $node(*key))
280 fn try_get_with(tcx: TyCtxt<'a, $tcx, 'lcx>,
283 -> Result<$V, CycleError<'a, $tcx>>
285 debug!("ty::queries::{}::try_get_with(key={:?}, span={:?})",
291 ProfileQueriesMsg::QueryBegin(
293 QueryMsg::$name(profq_key!(tcx, key))
297 if let Some(value) = tcx.maps.$name.borrow().map.get(&key) {
298 profq_msg!(tcx, ProfileQueriesMsg::CacheHit);
299 tcx.dep_graph.read_index(value.index);
300 return Ok((&value.value).clone());
303 // FIXME(eddyb) Get more valid Span's on queries.
304 // def_span guard is necessary to prevent a recursive loop,
305 // default_span calls def_span query internally.
306 if span == DUMMY_SP && stringify!($name) != "def_span" {
307 span = key.default_span(tcx)
310 // Fast path for when incr. comp. is off. `to_dep_node` is
311 // expensive for some DepKinds.
312 if !tcx.dep_graph.is_fully_enabled() {
313 let null_dep_node = DepNode::new_no_params(::dep_graph::DepKind::Null);
314 return Self::force(tcx, key, span, null_dep_node)
318 let dep_node = Self::to_dep_node(tcx, &key);
320 if dep_node.kind.is_anon() {
321 profq_msg!(tcx, ProfileQueriesMsg::ProviderBegin);
323 let res = tcx.cycle_check(span, Query::$name(key), || {
324 tcx.sess.diagnostic().track_diagnostics(|| {
325 tcx.dep_graph.with_anon_task(dep_node.kind, || {
326 Self::compute_result(tcx.global_tcx(), key)
331 profq_msg!(tcx, ProfileQueriesMsg::ProviderEnd);
332 let ((result, dep_node_index), diagnostics) = res;
334 tcx.dep_graph.read_index(dep_node_index);
336 tcx.on_disk_query_result_cache
337 .store_diagnostics_for_anon_node(dep_node_index, diagnostics);
339 let value = QueryValue::new(result, dep_node_index);
350 if !dep_node.kind.is_input() {
351 if let Some(dep_node_index) = tcx.try_mark_green_and_read(&dep_node) {
352 profq_msg!(tcx, ProfileQueriesMsg::CacheHit);
353 return Self::load_from_disk_and_cache_in_memory(tcx,
361 match Self::force(tcx, key, span, dep_node) {
362 Ok((result, dep_node_index)) => {
363 tcx.dep_graph.read_index(dep_node_index);
370 /// Ensure that either this query has all green inputs or been executed.
371 /// Executing query::ensure(D) is considered a read of the dep-node D.
373 /// This function is particularly useful when executing passes for their
374 /// side-effects -- e.g., in order to report errors for erroneous programs.
376 /// Note: The optimization is only available during incr. comp.
377 pub fn ensure(tcx: TyCtxt<'a, $tcx, 'lcx>, key: $K) -> () {
378 let dep_node = Self::to_dep_node(tcx, &key);
380 // Ensuring an "input" or anonymous query makes no sense
381 assert!(!dep_node.kind.is_anon());
382 assert!(!dep_node.kind.is_input());
383 if tcx.try_mark_green_and_read(&dep_node).is_none() {
384 // A None return from `try_mark_green_and_read` means that this is either
385 // a new dep node or that the dep node has already been marked red.
386 // Either way, we can't call `dep_graph.read()` as we don't have the
387 // DepNodeIndex. We must invoke the query itself. The performance cost
388 // this introduces should be negligible as we'll immediately hit the
389 // in-memory cache, or another query down the line will.
390 let _ = tcx.$name(key);
394 fn compute_result(tcx: TyCtxt<'a, $tcx, 'lcx>, key: $K) -> $V {
395 let provider = tcx.maps.providers[key.map_crate()].$name;
396 provider(tcx.global_tcx(), key)
399 fn load_from_disk_and_cache_in_memory(tcx: TyCtxt<'a, $tcx, 'lcx>,
402 dep_node_index: DepNodeIndex,
404 -> Result<$V, CycleError<'a, $tcx>>
406 debug_assert!(tcx.dep_graph.is_green(dep_node_index));
408 // First we try to load the result from the on-disk cache
409 let result = if Self::cache_on_disk(key) &&
410 tcx.sess.opts.debugging_opts.incremental_queries {
411 let prev_dep_node_index =
412 tcx.dep_graph.prev_dep_node_index_of(dep_node);
413 let result = Self::try_load_from_disk(tcx.global_tcx(),
414 prev_dep_node_index);
416 // We always expect to find a cached result for things that
417 // can be forced from DepNode.
418 debug_assert!(!dep_node.kind.can_reconstruct_query_key() ||
420 "Missing on-disk cache entry for {:?}",
424 // Some things are never cached on disk.
428 let result = if let Some(result) = result {
431 // We could not load a result from the on-disk cache, so
433 let (result, _ ) = tcx.cycle_check(span, Query::$name(key), || {
434 // The diagnostics for this query have already been
435 // promoted to the current session during
436 // try_mark_green(), so we can ignore them here.
437 tcx.sess.diagnostic().track_diagnostics(|| {
438 // The dep-graph for this computation is already in
440 tcx.dep_graph.with_ignore(|| {
441 Self::compute_result(tcx, key)
448 // If -Zincremental-verify-ich is specified, re-hash results from
449 // the cache and make sure that they have the expected fingerprint.
450 if tcx.sess.opts.debugging_opts.incremental_verify_ich {
451 use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
452 use ich::Fingerprint;
454 assert!(Some(tcx.dep_graph.fingerprint_of(dep_node_index)) ==
455 tcx.dep_graph.prev_fingerprint_of(dep_node),
456 "Fingerprint for green query instance not loaded \
457 from cache: {:?}", dep_node);
459 debug!("BEGIN verify_ich({:?})", dep_node);
460 let mut hcx = tcx.create_stable_hashing_context();
461 let mut hasher = StableHasher::new();
463 result.hash_stable(&mut hcx, &mut hasher);
465 let new_hash: Fingerprint = hasher.finish();
466 debug!("END verify_ich({:?})", dep_node);
468 let old_hash = tcx.dep_graph.fingerprint_of(dep_node_index);
470 assert!(new_hash == old_hash, "Found unstable fingerprints \
471 for {:?}", dep_node);
474 if tcx.sess.opts.debugging_opts.query_dep_graph {
475 tcx.dep_graph.mark_loaded_from_cache(dep_node_index, true);
478 let value = QueryValue::new(result, dep_node_index);
489 fn force(tcx: TyCtxt<'a, $tcx, 'lcx>,
493 -> Result<($V, DepNodeIndex), CycleError<'a, $tcx>> {
494 debug_assert!(tcx.dep_graph.node_color(&dep_node).is_none());
496 profq_msg!(tcx, ProfileQueriesMsg::ProviderBegin);
497 let res = tcx.cycle_check(span, Query::$name(key), || {
498 tcx.sess.diagnostic().track_diagnostics(|| {
499 if dep_node.kind.is_eval_always() {
500 tcx.dep_graph.with_eval_always_task(dep_node,
503 Self::compute_result)
505 tcx.dep_graph.with_task(dep_node,
508 Self::compute_result)
512 profq_msg!(tcx, ProfileQueriesMsg::ProviderEnd);
514 let ((result, dep_node_index), diagnostics) = res;
516 if tcx.sess.opts.debugging_opts.query_dep_graph {
517 tcx.dep_graph.mark_loaded_from_cache(dep_node_index, false);
520 if dep_node.kind != ::dep_graph::DepKind::Null {
521 tcx.on_disk_query_result_cache
522 .store_diagnostics(dep_node_index, diagnostics);
525 let value = QueryValue::new(result, dep_node_index);
537 pub fn try_get(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K)
538 -> Result<$V, DiagnosticBuilder<'a>> {
539 match Self::try_get_with(tcx, span, key) {
541 Err(e) => Err(tcx.report_cycle(e)),
546 #[derive(Copy, Clone)]
547 pub struct TyCtxtAt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
548 pub tcx: TyCtxt<'a, 'gcx, 'tcx>,
552 impl<'a, 'gcx, 'tcx> Deref for TyCtxtAt<'a, 'gcx, 'tcx> {
553 type Target = TyCtxt<'a, 'gcx, 'tcx>;
554 fn deref(&self) -> &Self::Target {
559 impl<'a, $tcx, 'lcx> TyCtxt<'a, $tcx, 'lcx> {
560 /// Return a transparent wrapper for `TyCtxt` which uses
561 /// `span` as the location of queries performed through it.
562 pub fn at(self, span: Span) -> TyCtxtAt<'a, $tcx, 'lcx> {
570 pub fn $name(self, key: $K) -> $V {
571 self.at(DUMMY_SP).$name(key)
575 impl<'a, $tcx, 'lcx> TyCtxtAt<'a, $tcx, 'lcx> {
577 pub fn $name(self, key: $K) -> $V {
578 queries::$name::try_get(self.tcx, self.span, key).unwrap_or_else(|mut e| {
580 handle_cycle_error!([$($modifiers)*][self])
585 define_provider_struct! {
587 input: ($(([$($modifiers)*] [$name] [$K] [$V]))*)
590 impl<$tcx> Copy for Providers<$tcx> {}
591 impl<$tcx> Clone for Providers<$tcx> {
592 fn clone(&self) -> Self { *self }
597 macro_rules! define_map_struct {
599 input: ($(([$($modifiers:tt)*] [$($attr:tt)*] [$name:ident]))*)) => {
600 pub struct Maps<$tcx> {
601 providers: IndexVec<CrateNum, Providers<$tcx>>,
602 query_stack: RefCell<Vec<(Span, Query<$tcx>)>>,
603 $($(#[$attr])* $name: RefCell<QueryMap<$tcx, queries::$name<$tcx>>>,)*
608 macro_rules! define_provider_struct {
610 input: ($(([$($modifiers:tt)*] [$name:ident] [$K:ty] [$R:ty]))*)) => {
611 pub struct Providers<$tcx> {
612 $(pub $name: for<'a> fn(TyCtxt<'a, $tcx, $tcx>, $K) -> $R,)*
615 impl<$tcx> Default for Providers<$tcx> {
616 fn default() -> Self {
617 $(fn $name<'a, $tcx>(_: TyCtxt<'a, $tcx, $tcx>, key: $K) -> $R {
618 bug!("tcx.maps.{}({:?}) unsupported by its crate",
619 stringify!($name), key);
621 Providers { $($name),* }
628 /// The red/green evaluation system will try to mark a specific DepNode in the
629 /// dependency graph as green by recursively trying to mark the dependencies of
630 /// that DepNode as green. While doing so, it will sometimes encounter a DepNode
631 /// where we don't know if it is red or green and we therefore actually have
632 /// to recompute its value in order to find out. Since the only piece of
633 /// information that we have at that point is the DepNode we are trying to
634 /// re-evaluate, we need some way to re-run a query from just that. This is what
635 /// `force_from_dep_node()` implements.
637 /// In the general case, a DepNode consists of a DepKind and an opaque
638 /// GUID/fingerprint that will uniquely identify the node. This GUID/fingerprint
639 /// is usually constructed by computing a stable hash of the query-key that the
640 /// DepNode corresponds to. Consequently, it is not in general possible to go
641 /// back from hash to query-key (since hash functions are not reversible). For
642 /// this reason `force_from_dep_node()` is expected to fail from time to time
643 /// because we just cannot find out, from the DepNode alone, what the
644 /// corresponding query-key is and therefore cannot re-run the query.
646 /// The system deals with this case letting `try_mark_green` fail which forces
647 /// the root query to be re-evaluated.
649 /// Now, if force_from_dep_node() would always fail, it would be pretty useless.
650 /// Fortunately, we can use some contextual information that will allow us to
651 /// reconstruct query-keys for certain kinds of DepNodes. In particular, we
652 /// enforce by construction that the GUID/fingerprint of certain DepNodes is a
653 /// valid DefPathHash. Since we also always build a huge table that maps every
654 /// DefPathHash in the current codebase to the corresponding DefId, we have
655 /// everything we need to re-run the query.
657 /// Take the `mir_validated` query as an example. Like many other queries, it
658 /// just has a single parameter: the DefId of the item it will compute the
659 /// validated MIR for. Now, when we call `force_from_dep_node()` on a dep-node
660 /// with kind `MirValidated`, we know that the GUID/fingerprint of the dep-node
661 /// is actually a DefPathHash, and can therefore just look up the corresponding
662 /// DefId in `tcx.def_path_hash_to_def_id`.
664 /// When you implement a new query, it will likely have a corresponding new
665 /// DepKind, and you'll have to support it here in `force_from_dep_node()`. As
666 /// a rule of thumb, if your query takes a DefId or DefIndex as sole parameter,
667 /// then `force_from_dep_node()` should not fail for it. Otherwise, you can just
668 /// add it to the "We don't have enough information to reconstruct..." group in
670 pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
673 use ty::maps::keys::Key;
674 use hir::def_id::LOCAL_CRATE;
676 // We must avoid ever having to call force_from_dep_node() for a
677 // DepNode::CodegenUnit:
678 // Since we cannot reconstruct the query key of a DepNode::CodegenUnit, we
679 // would always end up having to evaluate the first caller of the
680 // `codegen_unit` query that *is* reconstructible. This might very well be
681 // the `compile_codegen_unit` query, thus re-translating the whole CGU just
682 // to re-trigger calling the `codegen_unit` query with the right key. At
683 // that point we would already have re-done all the work we are trying to
684 // avoid doing in the first place.
685 // The solution is simple: Just explicitly call the `codegen_unit` query for
686 // each CGU, right after partitioning. This way `try_mark_green` will always
687 // hit the cache instead of having to go through `force_from_dep_node`.
688 // This assertion makes sure, we actually keep applying the solution above.
689 debug_assert!(dep_node.kind != DepKind::CodegenUnit,
690 "calling force_from_dep_node() on DepKind::CodegenUnit");
692 if !dep_node.kind.can_reconstruct_query_key() {
696 macro_rules! def_id {
698 if let Some(def_id) = dep_node.extract_def_id(tcx) {
701 // return from the whole function
708 () => { (def_id!()).krate }
712 ($query:ident, $key:expr) => {
714 use $crate::util::common::{ProfileQueriesMsg, profq_msg};
716 // FIXME(eddyb) Get more valid Span's on queries.
717 // def_span guard is necessary to prevent a recursive loop,
718 // default_span calls def_span query internally.
719 let span = if stringify!($query) != "def_span" {
720 $key.default_span(tcx)
722 ::syntax_pos::DUMMY_SP
726 ProfileQueriesMsg::QueryBegin(
728 ::ty::maps::QueryMsg::$query(profq_key!(tcx, $key))
732 match ::ty::maps::queries::$query::force(tcx, $key, span, *dep_node) {
735 tcx.report_cycle(e).emit();
742 // FIXME(#45015): We should try move this boilerplate code into a macro
744 match dep_node.kind {
745 // These are inputs that are expected to be pre-allocated and that
746 // should therefore always be red or green already
747 DepKind::AllLocalTraitImpls |
749 DepKind::CrateMetadata |
753 // This are anonymous nodes
754 DepKind::TraitSelect |
756 // We don't have enough information to reconstruct the query key of
764 DepKind::InstanceSymbolName |
766 DepKind::BorrowCheckKrate |
767 DepKind::Specializes |
768 DepKind::ImplementationsOfTrait |
769 DepKind::TypeParamPredicates |
770 DepKind::CodegenUnit |
771 DepKind::CompileCodegenUnit |
772 DepKind::FulfillObligation |
773 DepKind::VtableMethods |
774 DepKind::EraseRegionsTy |
775 DepKind::NormalizeTy |
776 DepKind::SubstituteNormalizeAndTestPredicates |
777 DepKind::InstanceDefSizeEstimate |
779 // This one should never occur in this context
781 bug!("force_from_dep_node() - Encountered {:?}", dep_node)
784 // These are not queries
785 DepKind::CoherenceCheckTrait |
786 DepKind::ItemVarianceConstraints => {
790 DepKind::RegionScopeTree => { force!(region_scope_tree, def_id!()); }
792 DepKind::Coherence => { force!(crate_inherent_impls, LOCAL_CRATE); }
793 DepKind::CoherenceInherentImplOverlapCheck => {
794 force!(crate_inherent_impls_overlap_check, LOCAL_CRATE)
796 DepKind::PrivacyAccessLevels => { force!(privacy_access_levels, LOCAL_CRATE); }
797 DepKind::MirBuilt => { force!(mir_built, def_id!()); }
798 DepKind::MirConstQualif => { force!(mir_const_qualif, def_id!()); }
799 DepKind::MirConst => { force!(mir_const, def_id!()); }
800 DepKind::MirValidated => { force!(mir_validated, def_id!()); }
801 DepKind::MirOptimized => { force!(optimized_mir, def_id!()); }
803 DepKind::BorrowCheck => { force!(borrowck, def_id!()); }
804 DepKind::MirBorrowCheck => { force!(mir_borrowck, def_id!()); }
805 DepKind::UnsafetyCheckResult => { force!(unsafety_check_result, def_id!()); }
806 DepKind::UnsafeDeriveOnReprPacked => { force!(unsafe_derive_on_repr_packed, def_id!()); }
807 DepKind::Reachability => { force!(reachable_set, LOCAL_CRATE); }
808 DepKind::MirKeys => { force!(mir_keys, LOCAL_CRATE); }
809 DepKind::CrateVariances => { force!(crate_variances, LOCAL_CRATE); }
810 DepKind::AssociatedItems => { force!(associated_item, def_id!()); }
811 DepKind::TypeOfItem => { force!(type_of, def_id!()); }
812 DepKind::GenericsOfItem => { force!(generics_of, def_id!()); }
813 DepKind::PredicatesOfItem => { force!(predicates_of, def_id!()); }
814 DepKind::InferredOutlivesOf => { force!(inferred_outlives_of, def_id!()); }
815 DepKind::SuperPredicatesOfItem => { force!(super_predicates_of, def_id!()); }
816 DepKind::TraitDefOfItem => { force!(trait_def, def_id!()); }
817 DepKind::AdtDefOfItem => { force!(adt_def, def_id!()); }
818 DepKind::ImplTraitRef => { force!(impl_trait_ref, def_id!()); }
819 DepKind::ImplPolarity => { force!(impl_polarity, def_id!()); }
820 DepKind::FnSignature => { force!(fn_sig, def_id!()); }
821 DepKind::CoerceUnsizedInfo => { force!(coerce_unsized_info, def_id!()); }
822 DepKind::ItemVariances => { force!(variances_of, def_id!()); }
823 DepKind::IsConstFn => { force!(is_const_fn, def_id!()); }
824 DepKind::IsForeignItem => { force!(is_foreign_item, def_id!()); }
825 DepKind::SizedConstraint => { force!(adt_sized_constraint, def_id!()); }
826 DepKind::DtorckConstraint => { force!(adt_dtorck_constraint, def_id!()); }
827 DepKind::AdtDestructor => { force!(adt_destructor, def_id!()); }
828 DepKind::AssociatedItemDefIds => { force!(associated_item_def_ids, def_id!()); }
829 DepKind::InherentImpls => { force!(inherent_impls, def_id!()); }
830 DepKind::TypeckBodiesKrate => { force!(typeck_item_bodies, LOCAL_CRATE); }
831 DepKind::TypeckTables => { force!(typeck_tables_of, def_id!()); }
832 DepKind::UsedTraitImports => { force!(used_trait_imports, def_id!()); }
833 DepKind::HasTypeckTables => { force!(has_typeck_tables, def_id!()); }
834 DepKind::SymbolName => { force!(def_symbol_name, def_id!()); }
835 DepKind::SpecializationGraph => { force!(specialization_graph_of, def_id!()); }
836 DepKind::ObjectSafety => { force!(is_object_safe, def_id!()); }
837 DepKind::TraitImpls => { force!(trait_impls_of, def_id!()); }
838 DepKind::CheckMatch => { force!(check_match, def_id!()); }
840 DepKind::ParamEnv => { force!(param_env, def_id!()); }
841 DepKind::DescribeDef => { force!(describe_def, def_id!()); }
842 DepKind::DefSpan => { force!(def_span, def_id!()); }
843 DepKind::LookupStability => { force!(lookup_stability, def_id!()); }
844 DepKind::LookupDeprecationEntry => {
845 force!(lookup_deprecation_entry, def_id!());
847 DepKind::ItemBodyNestedBodies => { force!(item_body_nested_bodies, def_id!()); }
848 DepKind::ConstIsRvaluePromotableToStatic => {
849 force!(const_is_rvalue_promotable_to_static, def_id!());
851 DepKind::RvaluePromotableMap => { force!(rvalue_promotable_map, def_id!()); }
852 DepKind::ImplParent => { force!(impl_parent, def_id!()); }
853 DepKind::TraitOfItem => { force!(trait_of_item, def_id!()); }
854 DepKind::IsExportedSymbol => { force!(is_exported_symbol, def_id!()); }
855 DepKind::IsMirAvailable => { force!(is_mir_available, def_id!()); }
856 DepKind::ItemAttrs => { force!(item_attrs, def_id!()); }
857 DepKind::FnArgNames => { force!(fn_arg_names, def_id!()); }
858 DepKind::DylibDepFormats => { force!(dylib_dependency_formats, krate!()); }
859 DepKind::IsPanicRuntime => { force!(is_panic_runtime, krate!()); }
860 DepKind::IsCompilerBuiltins => { force!(is_compiler_builtins, krate!()); }
861 DepKind::HasGlobalAllocator => { force!(has_global_allocator, krate!()); }
862 DepKind::ExternCrate => { force!(extern_crate, def_id!()); }
863 DepKind::LintLevels => { force!(lint_levels, LOCAL_CRATE); }
864 DepKind::InScopeTraits => { force!(in_scope_traits_map, def_id!().index); }
865 DepKind::ModuleExports => { force!(module_exports, def_id!()); }
866 DepKind::IsSanitizerRuntime => { force!(is_sanitizer_runtime, krate!()); }
867 DepKind::IsProfilerRuntime => { force!(is_profiler_runtime, krate!()); }
868 DepKind::GetPanicStrategy => { force!(panic_strategy, krate!()); }
869 DepKind::IsNoBuiltins => { force!(is_no_builtins, krate!()); }
870 DepKind::ImplDefaultness => { force!(impl_defaultness, def_id!()); }
871 DepKind::ExportedSymbolIds => { force!(exported_symbol_ids, krate!()); }
872 DepKind::NativeLibraries => { force!(native_libraries, krate!()); }
873 DepKind::PluginRegistrarFn => { force!(plugin_registrar_fn, krate!()); }
874 DepKind::DeriveRegistrarFn => { force!(derive_registrar_fn, krate!()); }
875 DepKind::CrateDisambiguator => { force!(crate_disambiguator, krate!()); }
876 DepKind::CrateHash => { force!(crate_hash, krate!()); }
877 DepKind::OriginalCrateName => { force!(original_crate_name, krate!()); }
879 DepKind::AllTraitImplementations => {
880 force!(all_trait_implementations, krate!());
883 DepKind::IsDllimportForeignItem => {
884 force!(is_dllimport_foreign_item, def_id!());
886 DepKind::IsStaticallyIncludedForeignItem => {
887 force!(is_statically_included_foreign_item, def_id!());
889 DepKind::NativeLibraryKind => { force!(native_library_kind, def_id!()); }
890 DepKind::LinkArgs => { force!(link_args, LOCAL_CRATE); }
892 DepKind::ResolveLifetimes => { force!(resolve_lifetimes, krate!()); }
893 DepKind::NamedRegion => { force!(named_region_map, def_id!().index); }
894 DepKind::IsLateBound => { force!(is_late_bound_map, def_id!().index); }
895 DepKind::ObjectLifetimeDefaults => {
896 force!(object_lifetime_defaults_map, def_id!().index);
899 DepKind::Visibility => { force!(visibility, def_id!()); }
900 DepKind::DepKind => { force!(dep_kind, krate!()); }
901 DepKind::CrateName => { force!(crate_name, krate!()); }
902 DepKind::ItemChildren => { force!(item_children, def_id!()); }
903 DepKind::ExternModStmtCnum => { force!(extern_mod_stmt_cnum, def_id!()); }
904 DepKind::GetLangItems => { force!(get_lang_items, LOCAL_CRATE); }
905 DepKind::DefinedLangItems => { force!(defined_lang_items, krate!()); }
906 DepKind::MissingLangItems => { force!(missing_lang_items, krate!()); }
907 DepKind::ExternConstBody => { force!(extern_const_body, def_id!()); }
908 DepKind::VisibleParentMap => { force!(visible_parent_map, LOCAL_CRATE); }
909 DepKind::MissingExternCrateItem => {
910 force!(missing_extern_crate_item, krate!());
912 DepKind::UsedCrateSource => { force!(used_crate_source, krate!()); }
913 DepKind::PostorderCnums => { force!(postorder_cnums, LOCAL_CRATE); }
914 DepKind::HasCloneClosures => { force!(has_clone_closures, krate!()); }
915 DepKind::HasCopyClosures => { force!(has_copy_closures, krate!()); }
917 DepKind::Freevars => { force!(freevars, def_id!()); }
918 DepKind::MaybeUnusedTraitImport => {
919 force!(maybe_unused_trait_import, def_id!());
921 DepKind::MaybeUnusedExternCrates => { force!(maybe_unused_extern_crates, LOCAL_CRATE); }
922 DepKind::StabilityIndex => { force!(stability_index, LOCAL_CRATE); }
923 DepKind::AllCrateNums => { force!(all_crate_nums, LOCAL_CRATE); }
924 DepKind::ExportedSymbols => { force!(exported_symbols, krate!()); }
925 DepKind::CollectAndPartitionTranslationItems => {
926 force!(collect_and_partition_translation_items, LOCAL_CRATE);
928 DepKind::ExportName => { force!(export_name, def_id!()); }
929 DepKind::ContainsExternIndicator => {
930 force!(contains_extern_indicator, def_id!());
932 DepKind::IsTranslatedItem => { force!(is_translated_item, def_id!()); }
933 DepKind::OutputFilenames => { force!(output_filenames, LOCAL_CRATE); }
935 DepKind::TargetFeaturesWhitelist => { force!(target_features_whitelist, LOCAL_CRATE); }
936 DepKind::TargetFeaturesEnabled => { force!(target_features_enabled, def_id!()); }
938 DepKind::GetSymbolExportLevel => { force!(symbol_export_level, def_id!()); }
945 // FIXME(#45015): Another piece of boilerplate code that could be generated in
946 // a combined define_dep_nodes!()/define_maps!() macro.
947 macro_rules! impl_load_from_cache {
948 ($($dep_kind:ident => $query_name:ident,)*) => {
950 // Check whether the query invocation corresponding to the given
951 // DepNode is eligible for on-disk-caching.
952 pub fn cache_on_disk(&self, tcx: TyCtxt) -> bool {
953 use ty::maps::queries;
954 use ty::maps::QueryDescription;
957 $(DepKind::$dep_kind => {
958 let def_id = self.extract_def_id(tcx).unwrap();
959 queries::$query_name::cache_on_disk(def_id)
965 // This is method will execute the query corresponding to the given
966 // DepNode. It is only expected to work for DepNodes where the
967 // above `cache_on_disk` methods returns true.
968 // Also, as a sanity check, it expects that the corresponding query
969 // invocation has been marked as green already.
970 pub fn load_from_on_disk_cache(&self, tcx: TyCtxt) {
972 $(DepKind::$dep_kind => {
973 debug_assert!(tcx.dep_graph
975 .map(|c| c.is_green())
978 let def_id = self.extract_def_id(tcx).unwrap();
979 let _ = tcx.$query_name(def_id);
990 impl_load_from_cache!(
991 TypeckTables => typeck_tables_of,
992 MirOptimized => optimized_mir,
993 UnsafetyCheckResult => unsafety_check_result,
994 BorrowCheck => borrowck,
995 MirBorrowCheck => mir_borrowck,
996 MirConstQualif => mir_const_qualif,
997 SymbolName => def_symbol_name,
998 ConstIsRvaluePromotableToStatic => const_is_rvalue_promotable_to_static,
999 ContainsExternIndicator => contains_extern_indicator,
1000 CheckMatch => check_match,
1001 TypeOfItem => type_of,
1002 GenericsOfItem => generics_of,
1003 PredicatesOfItem => predicates_of,
1004 UsedTraitImports => used_trait_imports,