Move try_load_from_on_disk_cache to the QueryContext.

This commit is contained in:
Camille GILLOT 2021-01-05 18:37:42 +01:00
parent 4dbf83a209
commit ea3d465c95
7 changed files with 22 additions and 16 deletions

View file

@ -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);
}
}

View file

@ -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<Diagnostic> {
self.on_disk_cache
.as_ref()

View file

@ -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();

View file

@ -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(

View file

@ -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<K: DepKind> {
@ -875,7 +876,8 @@ impl<K: DepKind> DepGraph<K> {
//
// 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<Ctxt: DepContext<DepKind = K>>(&self, tcx: Ctxt) {
pub fn exec_cache_promotions<Ctxt: QueryContext<DepKind = K>>(&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<K: DepKind> DepGraph<K> {
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

View file

@ -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<Self::DepKind>);
/// Load diagnostics associated to the node in the previous session.
fn load_diagnostics(&self, prev_dep_node_index: SerializedDepNodeIndex) -> Vec<Diagnostic>;

View file

@ -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<QueryMap<Self::DepKind, Self::Query>>;
/// Load data from the on-disk cache.
fn try_load_from_on_disk_cache(&self, dep_node: &DepNode<Self::DepKind>);
/// 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.