Skip to content

Commit

Permalink
incr.comp.: Allow for recovering from missing on-disk cache entries.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwoerister committed Dec 1, 2017
1 parent 059bd80 commit c531d9f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 25 deletions.
20 changes: 11 additions & 9 deletions src/librustc/ty/maps/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ pub(super) trait QueryDescription<'tcx>: QueryConfig {
false
}

fn load_from_disk<'a>(_: TyCtxt<'a, 'tcx, 'tcx>,
_: SerializedDepNodeIndex)
-> Self::Value {
fn try_load_from_disk<'a>(_: TyCtxt<'a, 'tcx, 'tcx>,
_: SerializedDepNodeIndex)
-> Option<Self::Value> {
bug!("QueryDescription::load_from_disk() called for unsupport query.")
}
}
Expand Down Expand Up @@ -556,12 +556,14 @@ impl<'tcx> QueryDescription<'tcx> for queries::typeck_tables_of<'tcx> {
def_id.is_local()
}

fn load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
id: SerializedDepNodeIndex)
-> Self::Value {
let typeck_tables: ty::TypeckTables<'tcx> = tcx.on_disk_query_result_cache
.load_query_result(tcx, id);
tcx.alloc_tables(typeck_tables)
fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
id: SerializedDepNodeIndex)
-> Option<Self::Value> {
let typeck_tables: Option<ty::TypeckTables<'tcx>> = tcx
.on_disk_query_result_cache
.try_load_query_result(tcx, id);

typeck_tables.map(|tables| tcx.alloc_tables(tables))
}
}

23 changes: 10 additions & 13 deletions src/librustc/ty/maps/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,21 +289,18 @@ impl<'sess> OnDiskCache<'sess> {
debug_assert!(prev.is_none());
}

pub fn load_query_result<'a, 'tcx, T>(&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
dep_node_index: SerializedDepNodeIndex)
-> T
/// Returns the cached query result if there is something in the cache for
/// the given SerializedDepNodeIndex. Otherwise returns None.
pub fn try_load_query_result<'a, 'tcx, T>(&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
dep_node_index: SerializedDepNodeIndex)
-> Option<T>
where T: Decodable
{
let result = self.load_indexed(tcx,
dep_node_index,
&self.query_result_index,
"query result");
if let Some(result) = result {
result
} else {
bug!("Could not find query result for key {:?}", dep_node_index)
}
self.load_indexed(tcx,
dep_node_index,
&self.query_result_index,
"query result")
}

/// Store a diagnostic emitted during computation of an anonymous query.
Expand Down
25 changes: 22 additions & 3 deletions src/librustc/ty/maps/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,31 @@ macro_rules! define_maps {
{
debug_assert!(tcx.dep_graph.is_green(dep_node_index));

let result = if tcx.sess.opts.debugging_opts.incremental_queries &&
Self::cache_on_disk(key) {
// First we try to load the result from the on-disk cache
let result = if Self::cache_on_disk(key) &&
tcx.sess.opts.debugging_opts.incremental_queries {
let prev_dep_node_index =
tcx.dep_graph.prev_dep_node_index_of(dep_node);
Self::load_from_disk(tcx.global_tcx(), prev_dep_node_index)
let result = Self::try_load_from_disk(tcx.global_tcx(),
prev_dep_node_index);

// We always expect to find a cached result for things that
// can be forced from DepNode.
debug_assert!(!dep_node.kind.can_reconstruct_query_key() ||
result.is_some(),
"Missing on-disk cache entry for {:?}",
dep_node);
result
} else {
// Some things are never cached on disk.
None
};

let result = if let Some(result) = result {
result
} else {
// We could not load a result from the on-disk cache, so
// recompute.
let (result, _ ) = tcx.cycle_check(span, Query::$name(key), || {
// The diagnostics for this query have already been
// promoted to the current session during
Expand Down

0 comments on commit c531d9f

Please sign in to comment.