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.")
}
}
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))
}
}
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.
{
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