Skip to content

Commit dab9b89

Browse files
committed
Decouple the on-disk cache from the query engine.
1 parent 49c1b07 commit dab9b89

File tree

7 files changed

+20
-31
lines changed

7 files changed

+20
-31
lines changed

compiler/rustc_macros/src/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl Parse for QueryModifier {
9797
Ok(QueryModifier::Cache(args, block))
9898
} else if modifier == "load_cached" {
9999
// Parse a load_cached modifier like:
100-
// `load_cached(tcx, id) { tcx.queries.on_disk_cache.try_load_query_result(tcx, id) }`
100+
// `load_cached(tcx, id) { tcx.on_disk_cache.try_load_query_result(tcx, id) }`
101101
let args;
102102
parenthesized!(args in input);
103103
let tcx = args.parse()?;
@@ -368,7 +368,7 @@ fn add_query_description_impl(
368368
tcx: TyCtxt<'tcx>,
369369
id: SerializedDepNodeIndex
370370
) -> Option<Self::Value> {
371-
tcx.queries.on_disk_cache.as_ref().and_then(|c| c.try_load_query_result(tcx, id))
371+
tcx.on_disk_cache.as_ref()?.try_load_query_result(tcx, id)
372372
}
373373
}
374374
};

compiler/rustc_middle/src/dep_graph/dep_node.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,7 @@ impl DepNodeExt for DepNode {
414414
/// has been removed.
415415
fn extract_def_id(&self, tcx: TyCtxt<'tcx>) -> Option<DefId> {
416416
if self.kind.can_reconstruct_query_key() {
417-
tcx.queries
418-
.on_disk_cache
419-
.as_ref()?
420-
.def_path_hash_to_def_id(tcx, DefPathHash(self.hash.into()))
417+
tcx.on_disk_cache.as_ref()?.def_path_hash_to_def_id(tcx, DefPathHash(self.hash.into()))
421418
} else {
422419
None
423420
}
@@ -472,7 +469,7 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for DefId {
472469
// we will use the old DefIndex as an initial guess for
473470
// a lookup into the crate metadata.
474471
if !self.is_local() {
475-
if let Some(cache) = &tcx.queries.on_disk_cache {
472+
if let Some(cache) = &tcx.on_disk_cache {
476473
cache.store_foreign_def_id_hash(*self, hash);
477474
}
478475
}

compiler/rustc_middle/src/dep_graph/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<'tcx> DepContext for TyCtxt<'tcx> {
9494
type StableHashingContext = StableHashingContext<'tcx>;
9595

9696
fn register_reused_dep_node(&self, dep_node: &DepNode) {
97-
if let Some(cache) = self.queries.on_disk_cache.as_ref() {
97+
if let Some(cache) = self.on_disk_cache.as_ref() {
9898
cache.register_reused_dep_node(*self, dep_node)
9999
}
100100
}
@@ -185,15 +185,14 @@ impl<'tcx> DepContext for TyCtxt<'tcx> {
185185
}
186186

187187
fn load_diagnostics(&self, prev_dep_node_index: SerializedDepNodeIndex) -> Vec<Diagnostic> {
188-
self.queries
189-
.on_disk_cache
188+
self.on_disk_cache
190189
.as_ref()
191190
.map(|c| c.load_diagnostics(*self, prev_dep_node_index))
192191
.unwrap_or_default()
193192
}
194193

195194
fn store_diagnostics(&self, dep_node_index: DepNodeIndex, diagnostics: ThinVec<Diagnostic>) {
196-
if let Some(c) = self.queries.on_disk_cache.as_ref() {
195+
if let Some(c) = self.on_disk_cache.as_ref() {
197196
c.store_diagnostics(dep_node_index, diagnostics)
198197
}
199198
}
@@ -203,7 +202,7 @@ impl<'tcx> DepContext for TyCtxt<'tcx> {
203202
dep_node_index: DepNodeIndex,
204203
diagnostics: ThinVec<Diagnostic>,
205204
) {
206-
if let Some(c) = self.queries.on_disk_cache.as_ref() {
205+
if let Some(c) = self.on_disk_cache.as_ref() {
207206
c.store_diagnostics_for_anon_node(dep_node_index, diagnostics)
208207
}
209208
}

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,6 @@ rustc_queries! {
125125
desc { |tcx| "computing generics of `{}`", tcx.def_path_str(key) }
126126
storage(ArenaCacheSelector<'tcx>)
127127
cache_on_disk_if { key.is_local() }
128-
load_cached(tcx, id) {
129-
let generics: Option<ty::Generics> = tcx.queries.on_disk_cache.as_ref()
130-
.and_then(|c| c.try_load_query_result(tcx, id));
131-
generics
132-
}
133128
}
134129

135130
/// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
@@ -702,7 +697,7 @@ rustc_queries! {
702697
cache_on_disk_if { true }
703698
load_cached(tcx, id) {
704699
let typeck_results: Option<ty::TypeckResults<'tcx>> = tcx
705-
.queries.on_disk_cache.as_ref()
700+
.on_disk_cache.as_ref()
706701
.and_then(|c| c.try_load_query_result(tcx, id));
707702

708703
typeck_results.map(|x| &*tcx.arena.alloc(x))

compiler/rustc_middle/src/ty/context.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::middle::stability;
1414
use crate::mir::interpret::{self, Allocation, ConstValue, Scalar};
1515
use crate::mir::{Body, Field, Local, Place, PlaceElem, ProjectionKind, Promoted};
1616
use crate::traits;
17-
use crate::ty::query::{self, TyCtxtAt};
17+
use crate::ty::query::{self, OnDiskCache, TyCtxtAt};
1818
use crate::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst, SubstsRef, UserSubsts};
1919
use crate::ty::TyKind::*;
2020
use crate::ty::{
@@ -962,6 +962,12 @@ pub struct GlobalCtxt<'tcx> {
962962
pub(crate) untracked_crate: &'tcx hir::Crate<'tcx>,
963963
pub(crate) definitions: &'tcx Definitions,
964964

965+
/// This provides access to the incremental compilation on-disk cache for query results.
966+
/// Do not access this directly. It is only meant to be used by
967+
/// `DepGraph::try_mark_green()` and the query infrastructure.
968+
/// This is `None` if we are not incremental compilation mode
969+
pub(crate) on_disk_cache: Option<OnDiskCache<'tcx>>,
970+
965971
pub queries: query::Queries<'tcx>,
966972
pub query_caches: query::QueryCaches<'tcx>,
967973

@@ -1110,7 +1116,7 @@ impl<'tcx> TyCtxt<'tcx> {
11101116
krate: &'tcx hir::Crate<'tcx>,
11111117
definitions: &'tcx Definitions,
11121118
dep_graph: DepGraph,
1113-
on_disk_query_result_cache: Option<query::OnDiskCache<'tcx>>,
1119+
on_disk_cache: Option<query::OnDiskCache<'tcx>>,
11141120
crate_name: &str,
11151121
output_filenames: &OutputFilenames,
11161122
) -> GlobalCtxt<'tcx> {
@@ -1154,7 +1160,8 @@ impl<'tcx> TyCtxt<'tcx> {
11541160
extern_prelude: resolutions.extern_prelude,
11551161
untracked_crate: krate,
11561162
definitions,
1157-
queries: query::Queries::new(providers, extern_providers, on_disk_query_result_cache),
1163+
on_disk_cache,
1164+
queries: query::Queries::new(providers, extern_providers),
11581165
query_caches: query::QueryCaches::default(),
11591166
ty_rcache: Default::default(),
11601167
pred_rcache: Default::default(),
@@ -1320,7 +1327,7 @@ impl<'tcx> TyCtxt<'tcx> {
13201327
}
13211328

13221329
pub fn serialize_query_result_cache(self, encoder: &mut FileEncoder) -> FileEncodeResult {
1323-
self.queries.on_disk_cache.as_ref().map_or(Ok(()), |c| c.serialize(self, encoder))
1330+
self.on_disk_cache.as_ref().map_or(Ok(()), |c| c.serialize(self, encoder))
13241331
}
13251332

13261333
/// If `true`, we should use the MIR-based borrowck, but also

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,6 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for DefId {
918918
// which means that the definition with this hash is guaranteed to
919919
// still exist in the current compilation session.
920920
Ok(d.tcx()
921-
.queries
922921
.on_disk_cache
923922
.as_ref()
924923
.unwrap()

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -534,12 +534,6 @@ macro_rules! define_queries_struct {
534534
(tcx: $tcx:tt,
535535
input: ($(([$($modifiers:tt)*] [$($attr:tt)*] [$name:ident]))*)) => {
536536
pub struct Queries<$tcx> {
537-
/// This provides access to the incremental compilation on-disk cache for query results.
538-
/// Do not access this directly. It is only meant to be used by
539-
/// `DepGraph::try_mark_green()` and the query infrastructure.
540-
/// This is `None` if we are not incremental compilation mode
541-
pub(crate) on_disk_cache: Option<OnDiskCache<'tcx>>,
542-
543537
providers: IndexVec<CrateNum, Providers>,
544538
fallback_extern_providers: Box<Providers>,
545539

@@ -554,12 +548,10 @@ macro_rules! define_queries_struct {
554548
pub(crate) fn new(
555549
providers: IndexVec<CrateNum, Providers>,
556550
fallback_extern_providers: Providers,
557-
on_disk_cache: Option<OnDiskCache<'tcx>>,
558551
) -> Self {
559552
Queries {
560553
providers,
561554
fallback_extern_providers: Box::new(fallback_extern_providers),
562-
on_disk_cache,
563555
$($name: Default::default()),*
564556
}
565557
}

0 commit comments

Comments
 (0)