diff --git a/compiler/rustc_macros/src/query.rs b/compiler/rustc_macros/src/query.rs index bd20c7689ea..48b74bdaf1e 100644 --- a/compiler/rustc_macros/src/query.rs +++ b/compiler/rustc_macros/src/query.rs @@ -97,7 +97,7 @@ impl Parse for QueryModifier { Ok(QueryModifier::Cache(args, block)) } else if modifier == "load_cached" { // Parse a load_cached modifier like: - // `load_cached(tcx, id) { tcx.queries.on_disk_cache.try_load_query_result(tcx, id) }` + // `load_cached(tcx, id) { tcx.on_disk_cache.try_load_query_result(tcx, id) }` let args; parenthesized!(args in input); let tcx = args.parse()?; @@ -368,7 +368,7 @@ fn add_query_description_impl( tcx: TyCtxt<'tcx>, id: SerializedDepNodeIndex ) -> Option { - tcx.queries.on_disk_cache.as_ref().and_then(|c| c.try_load_query_result(tcx, id)) + tcx.on_disk_cache.as_ref()?.try_load_query_result(tcx, id) } } }; diff --git a/compiler/rustc_middle/src/dep_graph/dep_node.rs b/compiler/rustc_middle/src/dep_graph/dep_node.rs index 1cb75757379..669d7ea8d36 100644 --- a/compiler/rustc_middle/src/dep_graph/dep_node.rs +++ b/compiler/rustc_middle/src/dep_graph/dep_node.rs @@ -414,10 +414,7 @@ impl DepNodeExt for DepNode { /// has been removed. fn extract_def_id(&self, tcx: TyCtxt<'tcx>) -> Option { if self.kind.can_reconstruct_query_key() { - tcx.queries - .on_disk_cache - .as_ref()? - .def_path_hash_to_def_id(tcx, DefPathHash(self.hash.into())) + tcx.on_disk_cache.as_ref()?.def_path_hash_to_def_id(tcx, DefPathHash(self.hash.into())) } else { None } @@ -472,7 +469,7 @@ impl<'tcx> DepNodeParams> for DefId { // we will use the old DefIndex as an initial guess for // a lookup into the crate metadata. if !self.is_local() { - if let Some(cache) = &tcx.queries.on_disk_cache { + if let Some(cache) = &tcx.on_disk_cache { cache.store_foreign_def_id_hash(*self, hash); } } diff --git a/compiler/rustc_middle/src/dep_graph/mod.rs b/compiler/rustc_middle/src/dep_graph/mod.rs index eaf414ccaa6..4746004cfca 100644 --- a/compiler/rustc_middle/src/dep_graph/mod.rs +++ b/compiler/rustc_middle/src/dep_graph/mod.rs @@ -94,7 +94,7 @@ impl<'tcx> DepContext for TyCtxt<'tcx> { type StableHashingContext = StableHashingContext<'tcx>; fn register_reused_dep_node(&self, dep_node: &DepNode) { - if let Some(cache) = self.queries.on_disk_cache.as_ref() { + if let Some(cache) = self.on_disk_cache.as_ref() { cache.register_reused_dep_node(*self, dep_node) } } @@ -185,15 +185,14 @@ impl<'tcx> DepContext for TyCtxt<'tcx> { } fn load_diagnostics(&self, prev_dep_node_index: SerializedDepNodeIndex) -> Vec { - self.queries - .on_disk_cache + self.on_disk_cache .as_ref() .map(|c| c.load_diagnostics(*self, prev_dep_node_index)) .unwrap_or_default() } fn store_diagnostics(&self, dep_node_index: DepNodeIndex, diagnostics: ThinVec) { - if let Some(c) = self.queries.on_disk_cache.as_ref() { + if let Some(c) = self.on_disk_cache.as_ref() { c.store_diagnostics(dep_node_index, diagnostics) } } @@ -203,7 +202,7 @@ impl<'tcx> DepContext for TyCtxt<'tcx> { dep_node_index: DepNodeIndex, diagnostics: ThinVec, ) { - if let Some(c) = self.queries.on_disk_cache.as_ref() { + if let Some(c) = self.on_disk_cache.as_ref() { c.store_diagnostics_for_anon_node(dep_node_index, diagnostics) } } diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 475f47c65bd..47b77bed906 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -125,11 +125,6 @@ rustc_queries! { desc { |tcx| "computing generics of `{}`", tcx.def_path_str(key) } storage(ArenaCacheSelector<'tcx>) cache_on_disk_if { key.is_local() } - load_cached(tcx, id) { - let generics: Option = tcx.queries.on_disk_cache.as_ref() - .and_then(|c| c.try_load_query_result(tcx, id)); - generics - } } /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the @@ -702,7 +697,7 @@ rustc_queries! { cache_on_disk_if { true } load_cached(tcx, id) { let typeck_results: Option> = tcx - .queries.on_disk_cache.as_ref() + .on_disk_cache.as_ref() .and_then(|c| c.try_load_query_result(tcx, id)); typeck_results.map(|x| &*tcx.arena.alloc(x)) diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 4654a842470..fa176193a93 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -14,7 +14,7 @@ use crate::middle::stability; use crate::mir::interpret::{self, Allocation, ConstValue, Scalar}; use crate::mir::{Body, Field, Local, Place, PlaceElem, ProjectionKind, Promoted}; use crate::traits; -use crate::ty::query::{self, TyCtxtAt}; +use crate::ty::query::{self, OnDiskCache, TyCtxtAt}; use crate::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst, SubstsRef, UserSubsts}; use crate::ty::TyKind::*; use crate::ty::{ @@ -962,6 +962,12 @@ pub struct GlobalCtxt<'tcx> { pub(crate) untracked_crate: &'tcx hir::Crate<'tcx>, pub(crate) definitions: &'tcx Definitions, + /// This provides access to the incremental compilation on-disk cache for query results. + /// Do not access this directly. It is only meant to be used by + /// `DepGraph::try_mark_green()` and the query infrastructure. + /// This is `None` if we are not incremental compilation mode + pub(crate) on_disk_cache: Option>, + pub queries: query::Queries<'tcx>, pub query_caches: query::QueryCaches<'tcx>, @@ -1110,7 +1116,7 @@ impl<'tcx> TyCtxt<'tcx> { krate: &'tcx hir::Crate<'tcx>, definitions: &'tcx Definitions, dep_graph: DepGraph, - on_disk_query_result_cache: Option>, + on_disk_cache: Option>, crate_name: &str, output_filenames: &OutputFilenames, ) -> GlobalCtxt<'tcx> { @@ -1154,7 +1160,8 @@ impl<'tcx> TyCtxt<'tcx> { extern_prelude: resolutions.extern_prelude, untracked_crate: krate, definitions, - queries: query::Queries::new(providers, extern_providers, on_disk_query_result_cache), + on_disk_cache, + queries: query::Queries::new(providers, extern_providers), query_caches: query::QueryCaches::default(), ty_rcache: Default::default(), pred_rcache: Default::default(), @@ -1320,7 +1327,7 @@ impl<'tcx> TyCtxt<'tcx> { } pub fn serialize_query_result_cache(self, encoder: &mut FileEncoder) -> FileEncodeResult { - self.queries.on_disk_cache.as_ref().map_or(Ok(()), |c| c.serialize(self, encoder)) + self.on_disk_cache.as_ref().map_or(Ok(()), |c| c.serialize(self, encoder)) } /// If `true`, we should use the MIR-based borrowck, but also 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 efe04786933..9f9f6bc4c51 100644 --- a/compiler/rustc_middle/src/ty/query/on_disk_cache.rs +++ b/compiler/rustc_middle/src/ty/query/on_disk_cache.rs @@ -918,7 +918,6 @@ impl<'a, 'tcx> Decodable> for DefId { // which means that the definition with this hash is guaranteed to // still exist in the current compilation session. Ok(d.tcx() - .queries .on_disk_cache .as_ref() .unwrap() diff --git a/compiler/rustc_middle/src/ty/query/plumbing.rs b/compiler/rustc_middle/src/ty/query/plumbing.rs index ea889549e43..8eb060a39a5 100644 --- a/compiler/rustc_middle/src/ty/query/plumbing.rs +++ b/compiler/rustc_middle/src/ty/query/plumbing.rs @@ -534,12 +534,6 @@ macro_rules! define_queries_struct { (tcx: $tcx:tt, input: ($(([$($modifiers:tt)*] [$($attr:tt)*] [$name:ident]))*)) => { pub struct Queries<$tcx> { - /// This provides access to the incremental compilation on-disk cache for query results. - /// Do not access this directly. It is only meant to be used by - /// `DepGraph::try_mark_green()` and the query infrastructure. - /// This is `None` if we are not incremental compilation mode - pub(crate) on_disk_cache: Option>, - providers: IndexVec, fallback_extern_providers: Box, @@ -554,12 +548,10 @@ macro_rules! define_queries_struct { pub(crate) fn new( providers: IndexVec, fallback_extern_providers: Providers, - on_disk_cache: Option>, ) -> Self { Queries { providers, fallback_extern_providers: Box::new(fallback_extern_providers), - on_disk_cache, $($name: Default::default()),* } }