]> git.lizzy.rs Git - rust.git/commitdiff
incr.comp.: Allow for recovering from missing on-disk cache entries.
authorMichael Woerister <michaelwoerister@posteo>
Tue, 28 Nov 2017 16:32:28 +0000 (17:32 +0100)
committerMichael Woerister <michaelwoerister@posteo>
Fri, 1 Dec 2017 12:48:59 +0000 (13:48 +0100)
src/librustc/ty/maps/config.rs
src/librustc/ty/maps/on_disk_cache.rs
src/librustc/ty/maps/plumbing.rs

index 066b80cefa4b5073a7d41ee83ee32c056470a228..ffddde557da124b18c385e7274aa044d18537893 100644 (file)
@@ -31,9 +31,9 @@ fn cache_on_disk(_: Self::Key) -> bool {
         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.")
     }
 }
@@ -556,12 +556,14 @@ fn cache_on_disk(def_id: Self::Key) -> bool {
         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))
     }
 }
 
index 0d09692bc353000e70a75f19b00baf277841912f..ca0c3bafea8df5ca4eaa918a41541848315cc5e2 100644 (file)
@@ -289,21 +289,18 @@ pub fn store_diagnostics(&self,
         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.
index 3121cceeea03ecc0bf744131314847f7cd20e202..fdaa13e7fd16fd82848e2688697092fd698843c0 100644 (file)
@@ -392,12 +392,31 @@ fn load_from_disk_and_cache_in_memory(tcx: TyCtxt<'a, $tcx, 'lcx>,
             {
                 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