Move try_load_from_on_disk_cache to the QueryContext.
This commit is contained in:
parent
4dbf83a209
commit
ea3d465c95
7 changed files with 22 additions and 16 deletions
|
@ -138,7 +138,7 @@ pub struct DepKindStruct {
|
||||||
pub(super) force_from_dep_node: fn(tcx: TyCtxt<'_>, dep_node: &DepNode) -> bool,
|
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.
|
/// 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 {
|
impl std::ops::Deref for DepKind {
|
||||||
|
@ -273,7 +273,7 @@ pub mod dep_kind {
|
||||||
false
|
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 {
|
if is_anon {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -287,9 +287,8 @@ pub mod dep_kind {
|
||||||
.map(|c| c.is_green())
|
.map(|c| c.is_green())
|
||||||
.unwrap_or(false));
|
.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 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(tcx, &key, None) {
|
||||||
if queries::$variant::cache_on_disk(qcx, &key, None) {
|
|
||||||
let _ = tcx.$variant(key);
|
let _ = tcx.$variant(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,10 +180,6 @@ impl<'tcx> DepContext for TyCtxt<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interactions with on_disk_cache
|
// 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> {
|
fn load_diagnostics(&self, prev_dep_node_index: SerializedDepNodeIndex) -> Vec<Diagnostic> {
|
||||||
self.on_disk_cache
|
self.on_disk_cache
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
|
|
@ -285,7 +285,7 @@ impl<'sess> OnDiskCache<'sess> {
|
||||||
// Do this *before* we clone 'latest_foreign_def_path_hashes', since
|
// Do this *before* we clone 'latest_foreign_def_path_hashes', since
|
||||||
// loading existing queries may cause us to create new DepNodes, which
|
// loading existing queries may cause us to create new DepNodes, which
|
||||||
// may in turn end up invoking `store_foreign_def_id_hash`
|
// 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 latest_foreign_def_path_hashes = self.latest_foreign_def_path_hashes.lock().clone();
|
||||||
let hygiene_encode_context = HygieneEncodeContext::default();
|
let hygiene_encode_context = HygieneEncodeContext::default();
|
||||||
|
|
|
@ -68,6 +68,10 @@ impl QueryContext for QueryCtxt<'tcx> {
|
||||||
self.queries.try_collect_active_jobs()
|
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
|
/// Executes a job by changing the `ImplicitCtxt` to point to the
|
||||||
/// new query job while it executes. It returns the diagnostics
|
/// new query job while it executes. It returns the diagnostics
|
||||||
/// captured during execution and the actual result.
|
/// captured during execution and the actual result.
|
||||||
|
@ -603,6 +607,11 @@ macro_rules! define_queries_struct {
|
||||||
tcx.encode_query_results(encoder, query_result_index)
|
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])*
|
$($(#[$attr])*
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn $name(
|
fn $name(
|
||||||
|
|
|
@ -24,6 +24,7 @@ use super::prev::PreviousDepGraph;
|
||||||
use super::query::DepGraphQuery;
|
use super::query::DepGraphQuery;
|
||||||
use super::serialized::SerializedDepNodeIndex;
|
use super::serialized::SerializedDepNodeIndex;
|
||||||
use super::{DepContext, DepKind, DepNode, HasDepContext, WorkProductId};
|
use super::{DepContext, DepKind, DepNode, HasDepContext, WorkProductId};
|
||||||
|
use crate::query::QueryContext;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct DepGraph<K: DepKind> {
|
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.
|
// This method will only load queries that will end up in the disk cache.
|
||||||
// Other queries will not be executed.
|
// 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 _prof_timer = tcx.profiler().generic_activity("incr_comp_query_cache_promotion");
|
||||||
|
|
||||||
let data = self.data.as_ref().unwrap();
|
let data = self.data.as_ref().unwrap();
|
||||||
|
@ -883,7 +885,7 @@ impl<K: DepKind> DepGraph<K> {
|
||||||
match data.colors.get(prev_index) {
|
match data.colors.get(prev_index) {
|
||||||
Some(DepNodeColor::Green(_)) => {
|
Some(DepNodeColor::Green(_)) => {
|
||||||
let dep_node = data.previous.index_to_node(prev_index);
|
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) => {
|
None | Some(DepNodeColor::Red) => {
|
||||||
// We can skip red nodes because a node can only be marked
|
// We can skip red nodes because a node can only be marked
|
||||||
|
|
|
@ -43,9 +43,6 @@ pub trait DepContext: Copy {
|
||||||
/// Return the diagnostic handler.
|
/// Return the diagnostic handler.
|
||||||
fn diagnostic(&self) -> &rustc_errors::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.
|
/// Load diagnostics associated to the node in the previous session.
|
||||||
fn load_diagnostics(&self, prev_dep_node_index: SerializedDepNodeIndex) -> Vec<Diagnostic>;
|
fn load_diagnostics(&self, prev_dep_node_index: SerializedDepNodeIndex) -> Vec<Diagnostic>;
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ pub use self::caches::{
|
||||||
mod config;
|
mod config;
|
||||||
pub use self::config::{QueryAccessors, QueryConfig, QueryDescription};
|
pub use self::config::{QueryAccessors, QueryConfig, QueryDescription};
|
||||||
|
|
||||||
use crate::dep_graph::HasDepContext;
|
use crate::dep_graph::{DepNode, HasDepContext};
|
||||||
use crate::query::job::QueryMap;
|
use crate::query::job::QueryMap;
|
||||||
|
|
||||||
use rustc_data_structures::stable_hasher::HashStable;
|
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>>;
|
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
|
/// Executes a job by changing the `ImplicitCtxt` to point to the
|
||||||
/// new query job while it executes. It returns the diagnostics
|
/// new query job while it executes. It returns the diagnostics
|
||||||
/// captured during execution and the actual result.
|
/// captured during execution and the actual result.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue