From ea3d465c95ce027aabfe7423c3d9f2161bdc2eb1 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 5 Jan 2021 18:37:42 +0100 Subject: [PATCH] Move try_load_from_on_disk_cache to the QueryContext. --- compiler/rustc_middle/src/dep_graph/dep_node.rs | 9 ++++----- compiler/rustc_middle/src/dep_graph/mod.rs | 4 ---- compiler/rustc_middle/src/ty/query/on_disk_cache.rs | 2 +- compiler/rustc_middle/src/ty/query/plumbing.rs | 9 +++++++++ compiler/rustc_query_system/src/dep_graph/graph.rs | 6 ++++-- compiler/rustc_query_system/src/dep_graph/mod.rs | 3 --- compiler/rustc_query_system/src/query/mod.rs | 5 ++++- 7 files changed, 22 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_middle/src/dep_graph/dep_node.rs b/compiler/rustc_middle/src/dep_graph/dep_node.rs index 94a17f4645ac3..14a10e84e9cd4 100644 --- a/compiler/rustc_middle/src/dep_graph/dep_node.rs +++ b/compiler/rustc_middle/src/dep_graph/dep_node.rs @@ -138,7 +138,7 @@ pub struct DepKindStruct { pub(super) force_from_dep_node: fn(tcx: TyCtxt<'_>, dep_node: &DepNode) -> bool, /// Invoke a query to put the on-disk cached value in memory. - pub(super) try_load_from_on_disk_cache: fn(TyCtxt<'_>, &DepNode), + pub(crate) try_load_from_on_disk_cache: fn(QueryCtxt<'_>, &DepNode), } impl std::ops::Deref for DepKind { @@ -273,7 +273,7 @@ pub mod dep_kind { false } - fn try_load_from_on_disk_cache(tcx: TyCtxt<'_>, dep_node: &DepNode) { + fn try_load_from_on_disk_cache(tcx: QueryCtxt<'_>, dep_node: &DepNode) { if is_anon { return } @@ -287,9 +287,8 @@ pub mod dep_kind { .map(|c| c.is_green()) .unwrap_or(false)); - let key = recover(tcx, dep_node).unwrap_or_else(|| panic!("Failed to recover key for {:?} with hash {}", dep_node, dep_node.hash)); - let qcx = QueryCtxt { tcx, queries: tcx.queries }; - if queries::$variant::cache_on_disk(qcx, &key, None) { + let key = recover(*tcx, dep_node).unwrap_or_else(|| panic!("Failed to recover key for {:?} with hash {}", dep_node, dep_node.hash)); + if queries::$variant::cache_on_disk(tcx, &key, None) { let _ = tcx.$variant(key); } } diff --git a/compiler/rustc_middle/src/dep_graph/mod.rs b/compiler/rustc_middle/src/dep_graph/mod.rs index 4746004cfca23..193bf3c91319a 100644 --- a/compiler/rustc_middle/src/dep_graph/mod.rs +++ b/compiler/rustc_middle/src/dep_graph/mod.rs @@ -180,10 +180,6 @@ impl<'tcx> DepContext for TyCtxt<'tcx> { } // Interactions with on_disk_cache - fn try_load_from_on_disk_cache(&self, dep_node: &DepNode) { - (dep_node.kind.try_load_from_on_disk_cache)(*self, dep_node) - } - fn load_diagnostics(&self, prev_dep_node_index: SerializedDepNodeIndex) -> Vec { self.on_disk_cache .as_ref() diff --git a/compiler/rustc_middle/src/ty/query/on_disk_cache.rs b/compiler/rustc_middle/src/ty/query/on_disk_cache.rs index db3449ed2e2af..69352df152739 100644 --- a/compiler/rustc_middle/src/ty/query/on_disk_cache.rs +++ b/compiler/rustc_middle/src/ty/query/on_disk_cache.rs @@ -285,7 +285,7 @@ impl<'sess> OnDiskCache<'sess> { // Do this *before* we clone 'latest_foreign_def_path_hashes', since // loading existing queries may cause us to create new DepNodes, which // may in turn end up invoking `store_foreign_def_id_hash` - tcx.dep_graph.exec_cache_promotions(tcx); + tcx.queries.exec_cache_promotions(tcx); let latest_foreign_def_path_hashes = self.latest_foreign_def_path_hashes.lock().clone(); let hygiene_encode_context = HygieneEncodeContext::default(); diff --git a/compiler/rustc_middle/src/ty/query/plumbing.rs b/compiler/rustc_middle/src/ty/query/plumbing.rs index 6aa9d88798fa7..83dbe4875cf01 100644 --- a/compiler/rustc_middle/src/ty/query/plumbing.rs +++ b/compiler/rustc_middle/src/ty/query/plumbing.rs @@ -68,6 +68,10 @@ impl QueryContext for QueryCtxt<'tcx> { self.queries.try_collect_active_jobs() } + fn try_load_from_on_disk_cache(&self, dep_node: &dep_graph::DepNode) { + (dep_node.kind.try_load_from_on_disk_cache)(*self, dep_node) + } + /// Executes a job by changing the `ImplicitCtxt` to point to the /// new query job while it executes. It returns the diagnostics /// captured during execution and the actual result. @@ -603,6 +607,11 @@ macro_rules! define_queries_struct { tcx.encode_query_results(encoder, query_result_index) } + fn exec_cache_promotions(&'tcx self, tcx: TyCtxt<'tcx>) { + let tcx = QueryCtxt { tcx, queries: self }; + tcx.dep_graph.exec_cache_promotions(tcx) + } + $($(#[$attr])* #[inline(always)] fn $name( diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs index 9b0810e03f741..8b0ab33f3f5f7 100644 --- a/compiler/rustc_query_system/src/dep_graph/graph.rs +++ b/compiler/rustc_query_system/src/dep_graph/graph.rs @@ -24,6 +24,7 @@ use super::prev::PreviousDepGraph; use super::query::DepGraphQuery; use super::serialized::SerializedDepNodeIndex; use super::{DepContext, DepKind, DepNode, HasDepContext, WorkProductId}; +use crate::query::QueryContext; #[derive(Clone)] pub struct DepGraph { @@ -875,7 +876,8 @@ impl DepGraph { // // This method will only load queries that will end up in the disk cache. // Other queries will not be executed. - pub fn exec_cache_promotions>(&self, tcx: Ctxt) { + pub fn exec_cache_promotions>(&self, qcx: Ctxt) { + let tcx = qcx.dep_context(); let _prof_timer = tcx.profiler().generic_activity("incr_comp_query_cache_promotion"); let data = self.data.as_ref().unwrap(); @@ -883,7 +885,7 @@ impl DepGraph { match data.colors.get(prev_index) { Some(DepNodeColor::Green(_)) => { let dep_node = data.previous.index_to_node(prev_index); - tcx.try_load_from_on_disk_cache(&dep_node); + qcx.try_load_from_on_disk_cache(&dep_node); } None | Some(DepNodeColor::Red) => { // We can skip red nodes because a node can only be marked diff --git a/compiler/rustc_query_system/src/dep_graph/mod.rs b/compiler/rustc_query_system/src/dep_graph/mod.rs index db192d1cfe77a..a1a6ca9dacc16 100644 --- a/compiler/rustc_query_system/src/dep_graph/mod.rs +++ b/compiler/rustc_query_system/src/dep_graph/mod.rs @@ -43,9 +43,6 @@ pub trait DepContext: Copy { /// Return the diagnostic handler. fn diagnostic(&self) -> &rustc_errors::Handler; - /// Load data from the on-disk cache. - fn try_load_from_on_disk_cache(&self, dep_node: &DepNode); - /// Load diagnostics associated to the node in the previous session. fn load_diagnostics(&self, prev_dep_node_index: SerializedDepNodeIndex) -> Vec; diff --git a/compiler/rustc_query_system/src/query/mod.rs b/compiler/rustc_query_system/src/query/mod.rs index 2d678035d4d51..8d5c9d7bea7e4 100644 --- a/compiler/rustc_query_system/src/query/mod.rs +++ b/compiler/rustc_query_system/src/query/mod.rs @@ -14,7 +14,7 @@ pub use self::caches::{ mod config; pub use self::config::{QueryAccessors, QueryConfig, QueryDescription}; -use crate::dep_graph::HasDepContext; +use crate::dep_graph::{DepNode, HasDepContext}; use crate::query::job::QueryMap; use rustc_data_structures::stable_hasher::HashStable; @@ -37,6 +37,9 @@ pub trait QueryContext: HasDepContext { fn try_collect_active_jobs(&self) -> Option>; + /// Load data from the on-disk cache. + fn try_load_from_on_disk_cache(&self, dep_node: &DepNode); + /// Executes a job by changing the `ImplicitCtxt` to point to the /// new query job while it executes. It returns the diagnostics /// captured during execution and the actual result.