Decouple the on-disk cache from the query engine.
This commit is contained in:
parent
49c1b07a9e
commit
dab9b89221
7 changed files with 20 additions and 31 deletions
|
@ -97,7 +97,7 @@ impl Parse for QueryModifier {
|
||||||
Ok(QueryModifier::Cache(args, block))
|
Ok(QueryModifier::Cache(args, block))
|
||||||
} else if modifier == "load_cached" {
|
} else if modifier == "load_cached" {
|
||||||
// Parse a load_cached modifier like:
|
// 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;
|
let args;
|
||||||
parenthesized!(args in input);
|
parenthesized!(args in input);
|
||||||
let tcx = args.parse()?;
|
let tcx = args.parse()?;
|
||||||
|
@ -368,7 +368,7 @@ fn add_query_description_impl(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
id: SerializedDepNodeIndex
|
id: SerializedDepNodeIndex
|
||||||
) -> Option<Self::Value> {
|
) -> Option<Self::Value> {
|
||||||
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -414,10 +414,7 @@ impl DepNodeExt for DepNode {
|
||||||
/// has been removed.
|
/// has been removed.
|
||||||
fn extract_def_id(&self, tcx: TyCtxt<'tcx>) -> Option<DefId> {
|
fn extract_def_id(&self, tcx: TyCtxt<'tcx>) -> Option<DefId> {
|
||||||
if self.kind.can_reconstruct_query_key() {
|
if self.kind.can_reconstruct_query_key() {
|
||||||
tcx.queries
|
tcx.on_disk_cache.as_ref()?.def_path_hash_to_def_id(tcx, DefPathHash(self.hash.into()))
|
||||||
.on_disk_cache
|
|
||||||
.as_ref()?
|
|
||||||
.def_path_hash_to_def_id(tcx, DefPathHash(self.hash.into()))
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -472,7 +469,7 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for DefId {
|
||||||
// we will use the old DefIndex as an initial guess for
|
// we will use the old DefIndex as an initial guess for
|
||||||
// a lookup into the crate metadata.
|
// a lookup into the crate metadata.
|
||||||
if !self.is_local() {
|
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);
|
cache.store_foreign_def_id_hash(*self, hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,7 +94,7 @@ impl<'tcx> DepContext for TyCtxt<'tcx> {
|
||||||
type StableHashingContext = StableHashingContext<'tcx>;
|
type StableHashingContext = StableHashingContext<'tcx>;
|
||||||
|
|
||||||
fn register_reused_dep_node(&self, dep_node: &DepNode) {
|
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)
|
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<Diagnostic> {
|
fn load_diagnostics(&self, prev_dep_node_index: SerializedDepNodeIndex) -> Vec<Diagnostic> {
|
||||||
self.queries
|
self.on_disk_cache
|
||||||
.on_disk_cache
|
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|c| c.load_diagnostics(*self, prev_dep_node_index))
|
.map(|c| c.load_diagnostics(*self, prev_dep_node_index))
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn store_diagnostics(&self, dep_node_index: DepNodeIndex, diagnostics: ThinVec<Diagnostic>) {
|
fn store_diagnostics(&self, dep_node_index: DepNodeIndex, diagnostics: ThinVec<Diagnostic>) {
|
||||||
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)
|
c.store_diagnostics(dep_node_index, diagnostics)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -203,7 +202,7 @@ impl<'tcx> DepContext for TyCtxt<'tcx> {
|
||||||
dep_node_index: DepNodeIndex,
|
dep_node_index: DepNodeIndex,
|
||||||
diagnostics: ThinVec<Diagnostic>,
|
diagnostics: ThinVec<Diagnostic>,
|
||||||
) {
|
) {
|
||||||
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)
|
c.store_diagnostics_for_anon_node(dep_node_index, diagnostics)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,11 +125,6 @@ rustc_queries! {
|
||||||
desc { |tcx| "computing generics of `{}`", tcx.def_path_str(key) }
|
desc { |tcx| "computing generics of `{}`", tcx.def_path_str(key) }
|
||||||
storage(ArenaCacheSelector<'tcx>)
|
storage(ArenaCacheSelector<'tcx>)
|
||||||
cache_on_disk_if { key.is_local() }
|
cache_on_disk_if { key.is_local() }
|
||||||
load_cached(tcx, id) {
|
|
||||||
let generics: Option<ty::Generics> = 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
|
/// Maps from the `DefId` of an item (trait/struct/enum/fn) to the
|
||||||
|
@ -702,7 +697,7 @@ rustc_queries! {
|
||||||
cache_on_disk_if { true }
|
cache_on_disk_if { true }
|
||||||
load_cached(tcx, id) {
|
load_cached(tcx, id) {
|
||||||
let typeck_results: Option<ty::TypeckResults<'tcx>> = tcx
|
let typeck_results: Option<ty::TypeckResults<'tcx>> = tcx
|
||||||
.queries.on_disk_cache.as_ref()
|
.on_disk_cache.as_ref()
|
||||||
.and_then(|c| c.try_load_query_result(tcx, id));
|
.and_then(|c| c.try_load_query_result(tcx, id));
|
||||||
|
|
||||||
typeck_results.map(|x| &*tcx.arena.alloc(x))
|
typeck_results.map(|x| &*tcx.arena.alloc(x))
|
||||||
|
|
|
@ -14,7 +14,7 @@ use crate::middle::stability;
|
||||||
use crate::mir::interpret::{self, Allocation, ConstValue, Scalar};
|
use crate::mir::interpret::{self, Allocation, ConstValue, Scalar};
|
||||||
use crate::mir::{Body, Field, Local, Place, PlaceElem, ProjectionKind, Promoted};
|
use crate::mir::{Body, Field, Local, Place, PlaceElem, ProjectionKind, Promoted};
|
||||||
use crate::traits;
|
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::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst, SubstsRef, UserSubsts};
|
||||||
use crate::ty::TyKind::*;
|
use crate::ty::TyKind::*;
|
||||||
use crate::ty::{
|
use crate::ty::{
|
||||||
|
@ -962,6 +962,12 @@ pub struct GlobalCtxt<'tcx> {
|
||||||
pub(crate) untracked_crate: &'tcx hir::Crate<'tcx>,
|
pub(crate) untracked_crate: &'tcx hir::Crate<'tcx>,
|
||||||
pub(crate) definitions: &'tcx Definitions,
|
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<OnDiskCache<'tcx>>,
|
||||||
|
|
||||||
pub queries: query::Queries<'tcx>,
|
pub queries: query::Queries<'tcx>,
|
||||||
pub query_caches: query::QueryCaches<'tcx>,
|
pub query_caches: query::QueryCaches<'tcx>,
|
||||||
|
|
||||||
|
@ -1110,7 +1116,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
krate: &'tcx hir::Crate<'tcx>,
|
krate: &'tcx hir::Crate<'tcx>,
|
||||||
definitions: &'tcx Definitions,
|
definitions: &'tcx Definitions,
|
||||||
dep_graph: DepGraph,
|
dep_graph: DepGraph,
|
||||||
on_disk_query_result_cache: Option<query::OnDiskCache<'tcx>>,
|
on_disk_cache: Option<query::OnDiskCache<'tcx>>,
|
||||||
crate_name: &str,
|
crate_name: &str,
|
||||||
output_filenames: &OutputFilenames,
|
output_filenames: &OutputFilenames,
|
||||||
) -> GlobalCtxt<'tcx> {
|
) -> GlobalCtxt<'tcx> {
|
||||||
|
@ -1154,7 +1160,8 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
extern_prelude: resolutions.extern_prelude,
|
extern_prelude: resolutions.extern_prelude,
|
||||||
untracked_crate: krate,
|
untracked_crate: krate,
|
||||||
definitions,
|
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(),
|
query_caches: query::QueryCaches::default(),
|
||||||
ty_rcache: Default::default(),
|
ty_rcache: Default::default(),
|
||||||
pred_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 {
|
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
|
/// If `true`, we should use the MIR-based borrowck, but also
|
||||||
|
|
|
@ -918,7 +918,6 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for DefId {
|
||||||
// which means that the definition with this hash is guaranteed to
|
// which means that the definition with this hash is guaranteed to
|
||||||
// still exist in the current compilation session.
|
// still exist in the current compilation session.
|
||||||
Ok(d.tcx()
|
Ok(d.tcx()
|
||||||
.queries
|
|
||||||
.on_disk_cache
|
.on_disk_cache
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
|
@ -534,12 +534,6 @@ macro_rules! define_queries_struct {
|
||||||
(tcx: $tcx:tt,
|
(tcx: $tcx:tt,
|
||||||
input: ($(([$($modifiers:tt)*] [$($attr:tt)*] [$name:ident]))*)) => {
|
input: ($(([$($modifiers:tt)*] [$($attr:tt)*] [$name:ident]))*)) => {
|
||||||
pub struct Queries<$tcx> {
|
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<OnDiskCache<'tcx>>,
|
|
||||||
|
|
||||||
providers: IndexVec<CrateNum, Providers>,
|
providers: IndexVec<CrateNum, Providers>,
|
||||||
fallback_extern_providers: Box<Providers>,
|
fallback_extern_providers: Box<Providers>,
|
||||||
|
|
||||||
|
@ -554,12 +548,10 @@ macro_rules! define_queries_struct {
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
providers: IndexVec<CrateNum, Providers>,
|
providers: IndexVec<CrateNum, Providers>,
|
||||||
fallback_extern_providers: Providers,
|
fallback_extern_providers: Providers,
|
||||||
on_disk_cache: Option<OnDiskCache<'tcx>>,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Queries {
|
Queries {
|
||||||
providers,
|
providers,
|
||||||
fallback_extern_providers: Box::new(fallback_extern_providers),
|
fallback_extern_providers: Box::new(fallback_extern_providers),
|
||||||
on_disk_cache,
|
|
||||||
$($name: Default::default()),*
|
$($name: Default::default()),*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue