Only create OnDiskCache
in incremental compilation mode
This lets us skip doing useless work when we're not in incremental compilation mode.
This commit is contained in:
parent
fe982319aa
commit
d00ed01876
6 changed files with 33 additions and 17 deletions
|
@ -199,9 +199,14 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_query_result_cache(sess: &Session) -> OnDiskCache<'_> {
|
/// Attempts to load the query result cache from disk
|
||||||
|
///
|
||||||
|
/// If we are not in incremental compilation mode, returns `None`.
|
||||||
|
/// Otherwise, tries to load the query result cache from disk,
|
||||||
|
/// creating an empty cache if it could not be loaded.
|
||||||
|
pub fn load_query_result_cache(sess: &Session) -> Option<OnDiskCache<'_>> {
|
||||||
if sess.opts.incremental.is_none() {
|
if sess.opts.incremental.is_none() {
|
||||||
return OnDiskCache::new_empty(sess.source_map());
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let _prof_timer = sess.prof.generic_activity("incr_comp_load_query_result_cache");
|
let _prof_timer = sess.prof.generic_activity("incr_comp_load_query_result_cache");
|
||||||
|
@ -211,7 +216,9 @@ pub fn load_query_result_cache(sess: &Session) -> OnDiskCache<'_> {
|
||||||
&query_cache_path(sess),
|
&query_cache_path(sess),
|
||||||
sess.is_nightly_build(),
|
sess.is_nightly_build(),
|
||||||
) {
|
) {
|
||||||
LoadResult::Ok { data: (bytes, start_pos) } => OnDiskCache::new(sess, bytes, start_pos),
|
LoadResult::Ok { data: (bytes, start_pos) } => {
|
||||||
_ => OnDiskCache::new_empty(sess.source_map()),
|
Some(OnDiskCache::new(sess, bytes, start_pos))
|
||||||
|
}
|
||||||
|
_ => Some(OnDiskCache::new_empty(sess.source_map())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -353,7 +353,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.try_load_query_result(tcx, id)
|
tcx.queries.on_disk_cache.as_ref().and_then(|c| c.try_load_query_result(tcx, id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -164,11 +164,17 @@ 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.on_disk_cache.load_diagnostics(*self, prev_dep_node_index)
|
self.queries
|
||||||
|
.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<Diagnostic>) {
|
fn store_diagnostics(&self, dep_node_index: DepNodeIndex, diagnostics: ThinVec<Diagnostic>) {
|
||||||
self.queries.on_disk_cache.store_diagnostics(dep_node_index, diagnostics)
|
if let Some(c) = self.queries.on_disk_cache.as_ref() {
|
||||||
|
c.store_diagnostics(dep_node_index, diagnostics)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn store_diagnostics_for_anon_node(
|
fn store_diagnostics_for_anon_node(
|
||||||
|
@ -176,7 +182,9 @@ impl<'tcx> DepContext for TyCtxt<'tcx> {
|
||||||
dep_node_index: DepNodeIndex,
|
dep_node_index: DepNodeIndex,
|
||||||
diagnostics: ThinVec<Diagnostic>,
|
diagnostics: ThinVec<Diagnostic>,
|
||||||
) {
|
) {
|
||||||
self.queries.on_disk_cache.store_diagnostics_for_anon_node(dep_node_index, diagnostics)
|
if let Some(c) = self.queries.on_disk_cache.as_ref() {
|
||||||
|
c.store_diagnostics_for_anon_node(dep_node_index, diagnostics)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn profiler(&self) -> &SelfProfilerRef {
|
fn profiler(&self) -> &SelfProfilerRef {
|
||||||
|
|
|
@ -130,8 +130,8 @@ rustc_queries! {
|
||||||
storage(ArenaCacheSelector<'tcx>)
|
storage(ArenaCacheSelector<'tcx>)
|
||||||
cache_on_disk_if { key.is_local() }
|
cache_on_disk_if { key.is_local() }
|
||||||
load_cached(tcx, id) {
|
load_cached(tcx, id) {
|
||||||
let generics: Option<ty::Generics> = tcx.queries.on_disk_cache
|
let generics: Option<ty::Generics> = tcx.queries.on_disk_cache.as_ref()
|
||||||
.try_load_query_result(tcx, id);
|
.and_then(|c| c.try_load_query_result(tcx, id));
|
||||||
generics
|
generics
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -688,8 +688,8 @@ 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
|
.queries.on_disk_cache.as_ref()
|
||||||
.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))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1094,7 +1094,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: query::OnDiskCache<'tcx>,
|
on_disk_query_result_cache: Option<query::OnDiskCache<'tcx>>,
|
||||||
crate_name: &str,
|
crate_name: &str,
|
||||||
output_filenames: &OutputFilenames,
|
output_filenames: &OutputFilenames,
|
||||||
) -> GlobalCtxt<'tcx> {
|
) -> GlobalCtxt<'tcx> {
|
||||||
|
@ -1343,7 +1343,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
where
|
where
|
||||||
E: ty::codec::OpaqueEncoder,
|
E: ty::codec::OpaqueEncoder,
|
||||||
{
|
{
|
||||||
self.queries.on_disk_cache.serialize(self, encoder)
|
self.queries.on_disk_cache.as_ref().map(|c| c.serialize(self, encoder)).unwrap_or(Ok(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If `true`, we should use the MIR-based borrowck, but also
|
/// If `true`, we should use the MIR-based borrowck, but also
|
||||||
|
|
|
@ -507,10 +507,11 @@ 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 incrimental comilation on-disk cache for query results.
|
/// This provides access to the incremental comilation on-disk cache for query results.
|
||||||
/// Do not access this directly. It is only meant to be used by
|
/// Do not access this directly. It is only meant to be used by
|
||||||
/// `DepGraph::try_mark_green()` and the query infrastructure.
|
/// `DepGraph::try_mark_green()` and the query infrastructure.
|
||||||
pub(crate) on_disk_cache: OnDiskCache<'tcx>,
|
/// 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>,
|
||||||
|
@ -526,7 +527,7 @@ 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: OnDiskCache<'tcx>,
|
on_disk_cache: Option<OnDiskCache<'tcx>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Queries {
|
Queries {
|
||||||
providers,
|
providers,
|
||||||
|
|
Loading…
Add table
Reference in a new issue