Skip to content

Commit c531d9f

Browse files
incr.comp.: Allow for recovering from missing on-disk cache entries.
1 parent 059bd80 commit c531d9f

File tree

3 files changed

+43
-25
lines changed

3 files changed

+43
-25
lines changed

src/librustc/ty/maps/config.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ pub(super) trait QueryDescription<'tcx>: QueryConfig {
3131
false
3232
}
3333

34-
fn load_from_disk<'a>(_: TyCtxt<'a, 'tcx, 'tcx>,
35-
_: SerializedDepNodeIndex)
36-
-> Self::Value {
34+
fn try_load_from_disk<'a>(_: TyCtxt<'a, 'tcx, 'tcx>,
35+
_: SerializedDepNodeIndex)
36+
-> Option<Self::Value> {
3737
bug!("QueryDescription::load_from_disk() called for unsupport query.")
3838
}
3939
}
@@ -556,12 +556,14 @@ impl<'tcx> QueryDescription<'tcx> for queries::typeck_tables_of<'tcx> {
556556
def_id.is_local()
557557
}
558558

559-
fn load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
560-
id: SerializedDepNodeIndex)
561-
-> Self::Value {
562-
let typeck_tables: ty::TypeckTables<'tcx> = tcx.on_disk_query_result_cache
563-
.load_query_result(tcx, id);
564-
tcx.alloc_tables(typeck_tables)
559+
fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
560+
id: SerializedDepNodeIndex)
561+
-> Option<Self::Value> {
562+
let typeck_tables: Option<ty::TypeckTables<'tcx>> = tcx
563+
.on_disk_query_result_cache
564+
.try_load_query_result(tcx, id);
565+
566+
typeck_tables.map(|tables| tcx.alloc_tables(tables))
565567
}
566568
}
567569

src/librustc/ty/maps/on_disk_cache.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -289,21 +289,18 @@ impl<'sess> OnDiskCache<'sess> {
289289
debug_assert!(prev.is_none());
290290
}
291291

292-
pub fn load_query_result<'a, 'tcx, T>(&self,
293-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
294-
dep_node_index: SerializedDepNodeIndex)
295-
-> T
292+
/// Returns the cached query result if there is something in the cache for
293+
/// the given SerializedDepNodeIndex. Otherwise returns None.
294+
pub fn try_load_query_result<'a, 'tcx, T>(&self,
295+
tcx: TyCtxt<'a, 'tcx, 'tcx>,
296+
dep_node_index: SerializedDepNodeIndex)
297+
-> Option<T>
296298
where T: Decodable
297299
{
298-
let result = self.load_indexed(tcx,
299-
dep_node_index,
300-
&self.query_result_index,
301-
"query result");
302-
if let Some(result) = result {
303-
result
304-
} else {
305-
bug!("Could not find query result for key {:?}", dep_node_index)
306-
}
300+
self.load_indexed(tcx,
301+
dep_node_index,
302+
&self.query_result_index,
303+
"query result")
307304
}
308305

309306
/// Store a diagnostic emitted during computation of an anonymous query.

src/librustc/ty/maps/plumbing.rs

+22-3
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,31 @@ macro_rules! define_maps {
392392
{
393393
debug_assert!(tcx.dep_graph.is_green(dep_node_index));
394394

395-
let result = if tcx.sess.opts.debugging_opts.incremental_queries &&
396-
Self::cache_on_disk(key) {
395+
// First we try to load the result from the on-disk cache
396+
let result = if Self::cache_on_disk(key) &&
397+
tcx.sess.opts.debugging_opts.incremental_queries {
397398
let prev_dep_node_index =
398399
tcx.dep_graph.prev_dep_node_index_of(dep_node);
399-
Self::load_from_disk(tcx.global_tcx(), prev_dep_node_index)
400+
let result = Self::try_load_from_disk(tcx.global_tcx(),
401+
prev_dep_node_index);
402+
403+
// We always expect to find a cached result for things that
404+
// can be forced from DepNode.
405+
debug_assert!(!dep_node.kind.can_reconstruct_query_key() ||
406+
result.is_some(),
407+
"Missing on-disk cache entry for {:?}",
408+
dep_node);
409+
result
410+
} else {
411+
// Some things are never cached on disk.
412+
None
413+
};
414+
415+
let result = if let Some(result) = result {
416+
result
400417
} else {
418+
// We could not load a result from the on-disk cache, so
419+
// recompute.
401420
let (result, _ ) = tcx.cycle_check(span, Query::$name(key), || {
402421
// The diagnostics for this query have already been
403422
// promoted to the current session during

0 commit comments

Comments
 (0)