about summary refs log tree commit diff
path: root/compiler/rustc_query_system
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2023-04-27 15:04:18 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2023-04-27 17:48:15 +1000
commit207cec017f7ba30a15ab6faf60f28f6e027400a4 (patch)
tree1dd06701f31ac7c1f9f4654354480e68b65978c5 /compiler/rustc_query_system
parent458d4dae845ec155b285681a5b88305641abb868 (diff)
downloadrust-207cec017f7ba30a15ab6faf60f28f6e027400a4.tar.gz
rust-207cec017f7ba30a15ab6faf60f28f6e027400a4.zip
Clean up `with_task`.
Currently it creates an `Option` and then does `map`/`unwrap_or` and
`map_or_else` on it, which is hard to read.

This commit simplifies things by moving more code into the two arms of
the if/else.
Diffstat (limited to 'compiler/rustc_query_system')
-rw-r--r--compiler/rustc_query_system/src/dep_graph/graph.rs16
1 files changed, 6 insertions, 10 deletions
diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs
index b9922b26afc..aada94ab266 100644
--- a/compiler/rustc_query_system/src/dep_graph/graph.rs
+++ b/compiler/rustc_query_system/src/dep_graph/graph.rs
@@ -354,24 +354,20 @@ impl<K: DepKind> DepGraphData<K> {
                  - dep-node: {key:?}"
         );
 
-        let task_deps = if cx.dep_context().is_eval_always(key.kind) {
-            None
+        let with_deps = |task_deps| K::with_deps(task_deps, || task(cx, arg));
+        let (result, edges) = if cx.dep_context().is_eval_always(key.kind) {
+            (with_deps(TaskDepsRef::EvalAlways), smallvec![])
         } else {
-            Some(Lock::new(TaskDeps {
+            let task_deps = Lock::new(TaskDeps {
                 #[cfg(debug_assertions)]
                 node: Some(key),
                 reads: SmallVec::new(),
                 read_set: Default::default(),
                 phantom_data: PhantomData,
-            }))
+            });
+            (with_deps(TaskDepsRef::Allow(&task_deps)), task_deps.into_inner().reads)
         };
 
-        let task_deps_ref =
-            task_deps.as_ref().map(TaskDepsRef::Allow).unwrap_or(TaskDepsRef::EvalAlways);
-
-        let result = K::with_deps(task_deps_ref, || task(cx, arg));
-        let edges = task_deps.map_or_else(|| smallvec![], |lock| lock.into_inner().reads);
-
         let dcx = cx.dep_context();
         let hashing_timer = dcx.profiler().incr_result_hashing();
         let current_fingerprint =