summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_query_system/src/dep_graph/graph.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /compiler/rustc_query_system/src/dep_graph/graph.rs
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_query_system/src/dep_graph/graph.rs')
-rw-r--r--compiler/rustc_query_system/src/dep_graph/graph.rs106
1 files changed, 37 insertions, 69 deletions
diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs
index a9a2e6dd0..c0d7386dd 100644
--- a/compiler/rustc_query_system/src/dep_graph/graph.rs
+++ b/compiler/rustc_query_system/src/dep_graph/graph.rs
@@ -6,7 +6,7 @@ use rustc_data_structures::sharded::{self, Sharded};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::steal::Steal;
use rustc_data_structures::sync::{AtomicU32, AtomicU64, Lock, Lrc, Ordering};
-use rustc_index::vec::IndexVec;
+use rustc_index::IndexVec;
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
use smallvec::{smallvec, SmallVec};
use std::assert_matches::assert_matches;
@@ -249,7 +249,7 @@ impl<K: DepKind> DepGraph<K> {
/// get an ICE. Normally, we would have tried (and failed) to mark
/// some other query green (e.g. `item_children`) which was used
/// to obtain `C`, which would prevent us from ever trying to force
- /// a non-existent `D`.
+ /// a nonexistent `D`.
///
/// It might be possible to enforce that all `DepNode`s read during
/// deserialization already exist in the previous `DepGraph`. In
@@ -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 =
@@ -660,7 +656,7 @@ impl<K: DepKind> DepGraphData<K> {
/// current compilation session. Used in various assertions
#[inline]
pub fn is_index_green(&self, prev_index: SerializedDepNodeIndex) -> bool {
- self.colors.get(prev_index).map_or(false, |c| c.is_green())
+ self.colors.get(prev_index).is_some_and(|c| c.is_green())
}
#[inline]
@@ -681,7 +677,7 @@ impl<K: DepKind> DepGraphData<K> {
impl<K: DepKind> DepGraph<K> {
#[inline]
pub fn dep_node_exists(&self, dep_node: &DepNode<K>) -> bool {
- self.data.as_ref().map_or(false, |data| data.dep_node_exists(dep_node))
+ self.data.as_ref().is_some_and(|data| data.dep_node_exists(dep_node))
}
/// Checks whether a previous work product exists for `v` and, if
@@ -959,7 +955,7 @@ impl<K: DepKind> DepGraph<K> {
/// Returns true if the given node has been marked as green during the
/// current compilation session. Used in various assertions
pub fn is_green(&self, dep_node: &DepNode<K>) -> bool {
- self.node_color(dep_node).map_or(false, |c| c.is_green())
+ self.node_color(dep_node).is_some_and(|c| c.is_green())
}
/// This method loads all on-disk cacheable query results into memory, so
@@ -1236,76 +1232,48 @@ impl<K: DepKind> CurrentDepGraph<K> {
self.node_intern_event_id.map(|eid| profiler.generic_activity_with_event_id(eid));
if let Some(prev_index) = prev_graph.node_to_index_opt(&key) {
+ let get_dep_node_index = |color, fingerprint| {
+ if print_status {
+ eprintln!("[task::{color:}] {key:?}");
+ }
+
+ let mut prev_index_to_index = self.prev_index_to_index.lock();
+
+ let dep_node_index = match prev_index_to_index[prev_index] {
+ Some(dep_node_index) => dep_node_index,
+ None => {
+ let dep_node_index =
+ self.encoder.borrow().send(profiler, key, fingerprint, edges);
+ prev_index_to_index[prev_index] = Some(dep_node_index);
+ dep_node_index
+ }
+ };
+
+ #[cfg(debug_assertions)]
+ self.record_edge(dep_node_index, key, fingerprint);
+
+ dep_node_index
+ };
+
// Determine the color and index of the new `DepNode`.
if let Some(fingerprint) = fingerprint {
if fingerprint == prev_graph.fingerprint_by_index(prev_index) {
- if print_status {
- eprintln!("[task::green] {key:?}");
- }
-
// This is a green node: it existed in the previous compilation,
// its query was re-executed, and it has the same result as before.
- let mut prev_index_to_index = self.prev_index_to_index.lock();
-
- let dep_node_index = match prev_index_to_index[prev_index] {
- Some(dep_node_index) => dep_node_index,
- None => {
- let dep_node_index =
- self.encoder.borrow().send(profiler, key, fingerprint, edges);
- prev_index_to_index[prev_index] = Some(dep_node_index);
- dep_node_index
- }
- };
-
- #[cfg(debug_assertions)]
- self.record_edge(dep_node_index, key, fingerprint);
+ let dep_node_index = get_dep_node_index("green", fingerprint);
(dep_node_index, Some((prev_index, DepNodeColor::Green(dep_node_index))))
} else {
- if print_status {
- eprintln!("[task::red] {key:?}");
- }
-
// This is a red node: it existed in the previous compilation, its query
// was re-executed, but it has a different result from before.
- let mut prev_index_to_index = self.prev_index_to_index.lock();
-
- let dep_node_index = match prev_index_to_index[prev_index] {
- Some(dep_node_index) => dep_node_index,
- None => {
- let dep_node_index =
- self.encoder.borrow().send(profiler, key, fingerprint, edges);
- prev_index_to_index[prev_index] = Some(dep_node_index);
- dep_node_index
- }
- };
-
- #[cfg(debug_assertions)]
- self.record_edge(dep_node_index, key, fingerprint);
+ let dep_node_index = get_dep_node_index("red", fingerprint);
(dep_node_index, Some((prev_index, DepNodeColor::Red)))
}
} else {
- if print_status {
- eprintln!("[task::unknown] {key:?}");
- }
-
// This is a red node, effectively: it existed in the previous compilation
// session, its query was re-executed, but it doesn't compute a result hash
// (i.e. it represents a `no_hash` query), so we have no way of determining
// whether or not the result was the same as before.
- let mut prev_index_to_index = self.prev_index_to_index.lock();
-
- let dep_node_index = match prev_index_to_index[prev_index] {
- Some(dep_node_index) => dep_node_index,
- None => {
- let dep_node_index =
- self.encoder.borrow().send(profiler, key, Fingerprint::ZERO, edges);
- prev_index_to_index[prev_index] = Some(dep_node_index);
- dep_node_index
- }
- };
-
- #[cfg(debug_assertions)]
- self.record_edge(dep_node_index, key, Fingerprint::ZERO);
+ let dep_node_index = get_dep_node_index("unknown", Fingerprint::ZERO);
(dep_node_index, Some((prev_index, DepNodeColor::Red)))
}
} else {