incr.comp.: Allow for recovering from missing on-disk cache entries.
This commit is contained in:
parent
059bd80526
commit
c531d9f733
3 changed files with 43 additions and 25 deletions
|
@ -31,9 +31,9 @@ pub(super) trait QueryDescription<'tcx>: QueryConfig {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_from_disk<'a>(_: TyCtxt<'a, 'tcx, 'tcx>,
|
fn try_load_from_disk<'a>(_: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
_: SerializedDepNodeIndex)
|
_: SerializedDepNodeIndex)
|
||||||
-> Self::Value {
|
-> Option<Self::Value> {
|
||||||
bug!("QueryDescription::load_from_disk() called for unsupport query.")
|
bug!("QueryDescription::load_from_disk() called for unsupport query.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -556,12 +556,14 @@ impl<'tcx> QueryDescription<'tcx> for queries::typeck_tables_of<'tcx> {
|
||||||
def_id.is_local()
|
def_id.is_local()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
id: SerializedDepNodeIndex)
|
id: SerializedDepNodeIndex)
|
||||||
-> Self::Value {
|
-> Option<Self::Value> {
|
||||||
let typeck_tables: ty::TypeckTables<'tcx> = tcx.on_disk_query_result_cache
|
let typeck_tables: Option<ty::TypeckTables<'tcx>> = tcx
|
||||||
.load_query_result(tcx, id);
|
.on_disk_query_result_cache
|
||||||
tcx.alloc_tables(typeck_tables)
|
.try_load_query_result(tcx, id);
|
||||||
|
|
||||||
|
typeck_tables.map(|tables| tcx.alloc_tables(tables))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -289,21 +289,18 @@ impl<'sess> OnDiskCache<'sess> {
|
||||||
debug_assert!(prev.is_none());
|
debug_assert!(prev.is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_query_result<'a, 'tcx, T>(&self,
|
/// Returns the cached query result if there is something in the cache for
|
||||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
/// the given SerializedDepNodeIndex. Otherwise returns None.
|
||||||
dep_node_index: SerializedDepNodeIndex)
|
pub fn try_load_query_result<'a, 'tcx, T>(&self,
|
||||||
-> T
|
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
|
dep_node_index: SerializedDepNodeIndex)
|
||||||
|
-> Option<T>
|
||||||
where T: Decodable
|
where T: Decodable
|
||||||
{
|
{
|
||||||
let result = self.load_indexed(tcx,
|
self.load_indexed(tcx,
|
||||||
dep_node_index,
|
dep_node_index,
|
||||||
&self.query_result_index,
|
&self.query_result_index,
|
||||||
"query result");
|
"query result")
|
||||||
if let Some(result) = result {
|
|
||||||
result
|
|
||||||
} else {
|
|
||||||
bug!("Could not find query result for key {:?}", dep_node_index)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Store a diagnostic emitted during computation of an anonymous query.
|
/// Store a diagnostic emitted during computation of an anonymous query.
|
||||||
|
|
|
@ -392,12 +392,31 @@ macro_rules! define_maps {
|
||||||
{
|
{
|
||||||
debug_assert!(tcx.dep_graph.is_green(dep_node_index));
|
debug_assert!(tcx.dep_graph.is_green(dep_node_index));
|
||||||
|
|
||||||
let result = if tcx.sess.opts.debugging_opts.incremental_queries &&
|
// First we try to load the result from the on-disk cache
|
||||||
Self::cache_on_disk(key) {
|
let result = if Self::cache_on_disk(key) &&
|
||||||
|
tcx.sess.opts.debugging_opts.incremental_queries {
|
||||||
let prev_dep_node_index =
|
let prev_dep_node_index =
|
||||||
tcx.dep_graph.prev_dep_node_index_of(dep_node);
|
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 {
|
} 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), || {
|
let (result, _ ) = tcx.cycle_check(span, Query::$name(key), || {
|
||||||
// The diagnostics for this query have already been
|
// The diagnostics for this query have already been
|
||||||
// promoted to the current session during
|
// promoted to the current session during
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue