Skip to content

Commit 50ccd17

Browse files
authored
Rollup merge of #110886 - nnethercote:dep-graph-cleanups, r=cjgillot
`DepGraph` cleanups r? `@cjgillot`
2 parents 1091a7a + 793b2ff commit 50ccd17

File tree

1 file changed

+32
-64
lines changed
  • compiler/rustc_query_system/src/dep_graph

1 file changed

+32
-64
lines changed

compiler/rustc_query_system/src/dep_graph/graph.rs

+32-64
Original file line numberDiff line numberDiff line change
@@ -354,24 +354,20 @@ impl<K: DepKind> DepGraphData<K> {
354354
- dep-node: {key:?}"
355355
);
356356

357-
let task_deps = if cx.dep_context().is_eval_always(key.kind) {
358-
None
357+
let with_deps = |task_deps| K::with_deps(task_deps, || task(cx, arg));
358+
let (result, edges) = if cx.dep_context().is_eval_always(key.kind) {
359+
(with_deps(TaskDepsRef::EvalAlways), smallvec![])
359360
} else {
360-
Some(Lock::new(TaskDeps {
361+
let task_deps = Lock::new(TaskDeps {
361362
#[cfg(debug_assertions)]
362363
node: Some(key),
363364
reads: SmallVec::new(),
364365
read_set: Default::default(),
365366
phantom_data: PhantomData,
366-
}))
367+
});
368+
(with_deps(TaskDepsRef::Allow(&task_deps)), task_deps.into_inner().reads)
367369
};
368370

369-
let task_deps_ref =
370-
task_deps.as_ref().map(TaskDepsRef::Allow).unwrap_or(TaskDepsRef::EvalAlways);
371-
372-
let result = K::with_deps(task_deps_ref, || task(cx, arg));
373-
let edges = task_deps.map_or_else(|| smallvec![], |lock| lock.into_inner().reads);
374-
375371
let dcx = cx.dep_context();
376372
let hashing_timer = dcx.profiler().incr_result_hashing();
377373
let current_fingerprint =
@@ -1236,76 +1232,48 @@ impl<K: DepKind> CurrentDepGraph<K> {
12361232
self.node_intern_event_id.map(|eid| profiler.generic_activity_with_event_id(eid));
12371233

12381234
if let Some(prev_index) = prev_graph.node_to_index_opt(&key) {
1235+
let get_dep_node_index = |color, fingerprint| {
1236+
if print_status {
1237+
eprintln!("[task::{color:}] {key:?}");
1238+
}
1239+
1240+
let mut prev_index_to_index = self.prev_index_to_index.lock();
1241+
1242+
let dep_node_index = match prev_index_to_index[prev_index] {
1243+
Some(dep_node_index) => dep_node_index,
1244+
None => {
1245+
let dep_node_index =
1246+
self.encoder.borrow().send(profiler, key, fingerprint, edges);
1247+
prev_index_to_index[prev_index] = Some(dep_node_index);
1248+
dep_node_index
1249+
}
1250+
};
1251+
1252+
#[cfg(debug_assertions)]
1253+
self.record_edge(dep_node_index, key, fingerprint);
1254+
1255+
dep_node_index
1256+
};
1257+
12391258
// Determine the color and index of the new `DepNode`.
12401259
if let Some(fingerprint) = fingerprint {
12411260
if fingerprint == prev_graph.fingerprint_by_index(prev_index) {
1242-
if print_status {
1243-
eprintln!("[task::green] {key:?}");
1244-
}
1245-
12461261
// This is a green node: it existed in the previous compilation,
12471262
// its query was re-executed, and it has the same result as before.
1248-
let mut prev_index_to_index = self.prev_index_to_index.lock();
1249-
1250-
let dep_node_index = match prev_index_to_index[prev_index] {
1251-
Some(dep_node_index) => dep_node_index,
1252-
None => {
1253-
let dep_node_index =
1254-
self.encoder.borrow().send(profiler, key, fingerprint, edges);
1255-
prev_index_to_index[prev_index] = Some(dep_node_index);
1256-
dep_node_index
1257-
}
1258-
};
1259-
1260-
#[cfg(debug_assertions)]
1261-
self.record_edge(dep_node_index, key, fingerprint);
1263+
let dep_node_index = get_dep_node_index("green", fingerprint);
12621264
(dep_node_index, Some((prev_index, DepNodeColor::Green(dep_node_index))))
12631265
} else {
1264-
if print_status {
1265-
eprintln!("[task::red] {key:?}");
1266-
}
1267-
12681266
// This is a red node: it existed in the previous compilation, its query
12691267
// was re-executed, but it has a different result from before.
1270-
let mut prev_index_to_index = self.prev_index_to_index.lock();
1271-
1272-
let dep_node_index = match prev_index_to_index[prev_index] {
1273-
Some(dep_node_index) => dep_node_index,
1274-
None => {
1275-
let dep_node_index =
1276-
self.encoder.borrow().send(profiler, key, fingerprint, edges);
1277-
prev_index_to_index[prev_index] = Some(dep_node_index);
1278-
dep_node_index
1279-
}
1280-
};
1281-
1282-
#[cfg(debug_assertions)]
1283-
self.record_edge(dep_node_index, key, fingerprint);
1268+
let dep_node_index = get_dep_node_index("red", fingerprint);
12841269
(dep_node_index, Some((prev_index, DepNodeColor::Red)))
12851270
}
12861271
} else {
1287-
if print_status {
1288-
eprintln!("[task::unknown] {key:?}");
1289-
}
1290-
12911272
// This is a red node, effectively: it existed in the previous compilation
12921273
// session, its query was re-executed, but it doesn't compute a result hash
12931274
// (i.e. it represents a `no_hash` query), so we have no way of determining
12941275
// whether or not the result was the same as before.
1295-
let mut prev_index_to_index = self.prev_index_to_index.lock();
1296-
1297-
let dep_node_index = match prev_index_to_index[prev_index] {
1298-
Some(dep_node_index) => dep_node_index,
1299-
None => {
1300-
let dep_node_index =
1301-
self.encoder.borrow().send(profiler, key, Fingerprint::ZERO, edges);
1302-
prev_index_to_index[prev_index] = Some(dep_node_index);
1303-
dep_node_index
1304-
}
1305-
};
1306-
1307-
#[cfg(debug_assertions)]
1308-
self.record_edge(dep_node_index, key, Fingerprint::ZERO);
1276+
let dep_node_index = get_dep_node_index("unknown", Fingerprint::ZERO);
13091277
(dep_node_index, Some((prev_index, DepNodeColor::Red)))
13101278
}
13111279
} else {

0 commit comments

Comments
 (0)