Skip to content

Commit ea3d465

Browse files
committed
Move try_load_from_on_disk_cache to the QueryContext.
1 parent 4dbf83a commit ea3d465

File tree

7 files changed

+22
-16
lines changed

7 files changed

+22
-16
lines changed

compiler/rustc_middle/src/dep_graph/dep_node.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub struct DepKindStruct {
138138
pub(super) force_from_dep_node: fn(tcx: TyCtxt<'_>, dep_node: &DepNode) -> bool,
139139

140140
/// Invoke a query to put the on-disk cached value in memory.
141-
pub(super) try_load_from_on_disk_cache: fn(TyCtxt<'_>, &DepNode),
141+
pub(crate) try_load_from_on_disk_cache: fn(QueryCtxt<'_>, &DepNode),
142142
}
143143

144144
impl std::ops::Deref for DepKind {
@@ -273,7 +273,7 @@ pub mod dep_kind {
273273
false
274274
}
275275

276-
fn try_load_from_on_disk_cache(tcx: TyCtxt<'_>, dep_node: &DepNode) {
276+
fn try_load_from_on_disk_cache(tcx: QueryCtxt<'_>, dep_node: &DepNode) {
277277
if is_anon {
278278
return
279279
}
@@ -287,9 +287,8 @@ pub mod dep_kind {
287287
.map(|c| c.is_green())
288288
.unwrap_or(false));
289289

290-
let key = recover(tcx, dep_node).unwrap_or_else(|| panic!("Failed to recover key for {:?} with hash {}", dep_node, dep_node.hash));
291-
let qcx = QueryCtxt { tcx, queries: tcx.queries };
292-
if queries::$variant::cache_on_disk(qcx, &key, None) {
290+
let key = recover(*tcx, dep_node).unwrap_or_else(|| panic!("Failed to recover key for {:?} with hash {}", dep_node, dep_node.hash));
291+
if queries::$variant::cache_on_disk(tcx, &key, None) {
293292
let _ = tcx.$variant(key);
294293
}
295294
}

compiler/rustc_middle/src/dep_graph/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,6 @@ impl<'tcx> DepContext for TyCtxt<'tcx> {
180180
}
181181

182182
// Interactions with on_disk_cache
183-
fn try_load_from_on_disk_cache(&self, dep_node: &DepNode) {
184-
(dep_node.kind.try_load_from_on_disk_cache)(*self, dep_node)
185-
}
186-
187183
fn load_diagnostics(&self, prev_dep_node_index: SerializedDepNodeIndex) -> Vec<Diagnostic> {
188184
self.on_disk_cache
189185
.as_ref()

compiler/rustc_middle/src/ty/query/on_disk_cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl<'sess> OnDiskCache<'sess> {
285285
// Do this *before* we clone 'latest_foreign_def_path_hashes', since
286286
// loading existing queries may cause us to create new DepNodes, which
287287
// may in turn end up invoking `store_foreign_def_id_hash`
288-
tcx.dep_graph.exec_cache_promotions(tcx);
288+
tcx.queries.exec_cache_promotions(tcx);
289289

290290
let latest_foreign_def_path_hashes = self.latest_foreign_def_path_hashes.lock().clone();
291291
let hygiene_encode_context = HygieneEncodeContext::default();

compiler/rustc_middle/src/ty/query/plumbing.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ impl QueryContext for QueryCtxt<'tcx> {
6868
self.queries.try_collect_active_jobs()
6969
}
7070

71+
fn try_load_from_on_disk_cache(&self, dep_node: &dep_graph::DepNode) {
72+
(dep_node.kind.try_load_from_on_disk_cache)(*self, dep_node)
73+
}
74+
7175
/// Executes a job by changing the `ImplicitCtxt` to point to the
7276
/// new query job while it executes. It returns the diagnostics
7377
/// captured during execution and the actual result.
@@ -603,6 +607,11 @@ macro_rules! define_queries_struct {
603607
tcx.encode_query_results(encoder, query_result_index)
604608
}
605609

610+
fn exec_cache_promotions(&'tcx self, tcx: TyCtxt<'tcx>) {
611+
let tcx = QueryCtxt { tcx, queries: self };
612+
tcx.dep_graph.exec_cache_promotions(tcx)
613+
}
614+
606615
$($(#[$attr])*
607616
#[inline(always)]
608617
fn $name(

compiler/rustc_query_system/src/dep_graph/graph.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use super::prev::PreviousDepGraph;
2424
use super::query::DepGraphQuery;
2525
use super::serialized::SerializedDepNodeIndex;
2626
use super::{DepContext, DepKind, DepNode, HasDepContext, WorkProductId};
27+
use crate::query::QueryContext;
2728

2829
#[derive(Clone)]
2930
pub struct DepGraph<K: DepKind> {
@@ -875,15 +876,16 @@ impl<K: DepKind> DepGraph<K> {
875876
//
876877
// This method will only load queries that will end up in the disk cache.
877878
// Other queries will not be executed.
878-
pub fn exec_cache_promotions<Ctxt: DepContext<DepKind = K>>(&self, tcx: Ctxt) {
879+
pub fn exec_cache_promotions<Ctxt: QueryContext<DepKind = K>>(&self, qcx: Ctxt) {
880+
let tcx = qcx.dep_context();
879881
let _prof_timer = tcx.profiler().generic_activity("incr_comp_query_cache_promotion");
880882

881883
let data = self.data.as_ref().unwrap();
882884
for prev_index in data.colors.values.indices() {
883885
match data.colors.get(prev_index) {
884886
Some(DepNodeColor::Green(_)) => {
885887
let dep_node = data.previous.index_to_node(prev_index);
886-
tcx.try_load_from_on_disk_cache(&dep_node);
888+
qcx.try_load_from_on_disk_cache(&dep_node);
887889
}
888890
None | Some(DepNodeColor::Red) => {
889891
// We can skip red nodes because a node can only be marked

compiler/rustc_query_system/src/dep_graph/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ pub trait DepContext: Copy {
4343
/// Return the diagnostic handler.
4444
fn diagnostic(&self) -> &rustc_errors::Handler;
4545

46-
/// Load data from the on-disk cache.
47-
fn try_load_from_on_disk_cache(&self, dep_node: &DepNode<Self::DepKind>);
48-
4946
/// Load diagnostics associated to the node in the previous session.
5047
fn load_diagnostics(&self, prev_dep_node_index: SerializedDepNodeIndex) -> Vec<Diagnostic>;
5148

compiler/rustc_query_system/src/query/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub use self::caches::{
1414
mod config;
1515
pub use self::config::{QueryAccessors, QueryConfig, QueryDescription};
1616

17-
use crate::dep_graph::HasDepContext;
17+
use crate::dep_graph::{DepNode, HasDepContext};
1818
use crate::query::job::QueryMap;
1919

2020
use rustc_data_structures::stable_hasher::HashStable;
@@ -37,6 +37,9 @@ pub trait QueryContext: HasDepContext {
3737

3838
fn try_collect_active_jobs(&self) -> Option<QueryMap<Self::DepKind, Self::Query>>;
3939

40+
/// Load data from the on-disk cache.
41+
fn try_load_from_on_disk_cache(&self, dep_node: &DepNode<Self::DepKind>);
42+
4043
/// Executes a job by changing the `ImplicitCtxt` to point to the
4144
/// new query job while it executes. It returns the diagnostics
4245
/// captured during execution and the actual result.

0 commit comments

Comments
 (0)