]> git.lizzy.rs Git - rust.git/commitdiff
Move dep_graph checking into try_load_from_disk_and_cache_in_memory.
authorCamille GILLOT <gillot.camille@gmail.com>
Mon, 2 Nov 2020 21:17:29 +0000 (22:17 +0100)
committerCamille GILLOT <gillot.camille@gmail.com>
Sat, 21 Aug 2021 23:00:01 +0000 (01:00 +0200)
compiler/rustc_query_system/src/query/plumbing.rs

index a7511846cadb61abc218b1278a9ecd62bd27a8cf..c3627910341dd81ebd68cac34737fafa26519df0 100644 (file)
@@ -2,8 +2,7 @@
 //! generate the actual methods on tcx which find and execute the provider,
 //! manage the caches, and so forth.
 
-use crate::dep_graph::{DepContext, DepKind, DepNode, DepNodeParams};
-use crate::dep_graph::{DepNodeIndex, SerializedDepNodeIndex};
+use crate::dep_graph::{DepContext, DepKind, DepNode, DepNodeIndex, DepNodeParams};
 use crate::query::caches::QueryCache;
 use crate::query::config::{QueryDescription, QueryVtable, QueryVtableExt};
 use crate::query::job::{
@@ -496,21 +495,7 @@ fn try_execute_query<CTX, C>(
         // promoted to the current session during
         // `try_mark_green()`, so we can ignore them here.
         let loaded = tcx.start_query(job.id, None, || {
-            let marked = dep_graph.try_mark_green_and_read(tcx, &dep_node);
-            marked.map(|(prev_dep_node_index, dep_node_index)| {
-                (
-                    load_from_disk_and_cache_in_memory(
-                        tcx,
-                        key.clone(),
-                        prev_dep_node_index,
-                        dep_node_index,
-                        &dep_node,
-                        query,
-                        compute,
-                    ),
-                    dep_node_index,
-                )
-            })
+            try_load_from_disk_and_cache_in_memory(tcx, key.clone(), &dep_node, query, compute)
         });
         if let Some((result, dep_node_index)) = loaded {
             return job.complete(result, dep_node_index);
@@ -522,21 +507,23 @@ fn try_execute_query<CTX, C>(
     result
 }
 
-fn load_from_disk_and_cache_in_memory<CTX, K, V: Debug>(
+fn try_load_from_disk_and_cache_in_memory<CTX, K, V>(
     tcx: CTX,
     key: K,
-    prev_dep_node_index: SerializedDepNodeIndex,
-    dep_node_index: DepNodeIndex,
     dep_node: &DepNode<CTX::DepKind>,
     query: &QueryVtable<CTX, K, V>,
     compute: fn(CTX::DepContext, K) -> V,
-) -> V
+) -> Option<(V, DepNodeIndex)>
 where
     CTX: QueryContext,
+    V: Debug,
 {
     // Note this function can be called concurrently from the same query
     // We must ensure that this is handled correctly.
 
+    let (prev_dep_node_index, dep_node_index) =
+        tcx.dep_context().dep_graph().try_mark_green_and_read(tcx, &dep_node)?;
+
     debug_assert!(tcx.dep_context().dep_graph().is_green(dep_node));
 
     // First we try to load the result from the on-disk cache.
@@ -558,7 +545,7 @@ fn load_from_disk_and_cache_in_memory<CTX, K, V: Debug>(
         None
     };
 
-    if let Some(result) = result {
+    let result = if let Some(result) = result {
         // If `-Zincremental-verify-ich` is specified, re-hash results from
         // the cache and make sure that they have the expected fingerprint.
         if unlikely!(tcx.dep_context().sess().opts.debugging_opts.incremental_verify_ich) {
@@ -588,7 +575,9 @@ fn load_from_disk_and_cache_in_memory<CTX, K, V: Debug>(
         incremental_verify_ich(*tcx.dep_context(), &result, dep_node, query);
 
         result
-    }
+    };
+
+    Some((result, dep_node_index))
 }
 
 fn incremental_verify_ich<CTX, K, V: Debug>(