Skip to content

Commit abe6032

Browse files
committed
remove code duplication when hashing query result and interning node
Refactored the duplicated code into a function. `with_feed_task` currently passes the query key to `debug_assert!`. This commit changes that, so it debug prints the `DepNode`, as in `with_task`.
1 parent 7a202a9 commit abe6032

File tree

2 files changed

+36
-43
lines changed

2 files changed

+36
-43
lines changed

Diff for: compiler/rustc_middle/src/query/plumbing.rs

-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,6 @@ macro_rules! define_feedable {
548548
let dep_node_index = tcx.dep_graph.with_feed_task(
549549
dep_node,
550550
tcx,
551-
key,
552551
&value,
553552
hash_result!([$($modifiers)*]),
554553
);

Diff for: compiler/rustc_query_system/src/dep_graph/graph.rs

+36-42
Original file line numberDiff line numberDiff line change
@@ -376,25 +376,8 @@ impl<D: Deps> DepGraphData<D> {
376376
};
377377

378378
let dcx = cx.dep_context();
379-
let hashing_timer = dcx.profiler().incr_result_hashing();
380-
let current_fingerprint =
381-
hash_result.map(|f| dcx.with_stable_hashing_context(|mut hcx| f(&mut hcx, &result)));
382-
383-
// Intern the new `DepNode`.
384-
let (dep_node_index, prev_and_color) =
385-
self.current.intern_node(&self.previous, key, edges, current_fingerprint);
386-
387-
hashing_timer.finish_with_query_invocation_id(dep_node_index.into());
388-
389-
if let Some((prev_index, color)) = prev_and_color {
390-
debug_assert!(
391-
self.colors.get(prev_index).is_none(),
392-
"DepGraph::with_task() - Duplicate DepNodeColor \
393-
insertion for {key:?}"
394-
);
395-
396-
self.colors.insert(prev_index, color);
397-
}
379+
let dep_node_index =
380+
self.hash_result_and_intern_node(dcx, key, edges, &result, hash_result);
398381

399382
(result, dep_node_index)
400383
}
@@ -462,6 +445,38 @@ impl<D: Deps> DepGraphData<D> {
462445

463446
(result, dep_node_index)
464447
}
448+
449+
/// Intern the new `DepNode` with the dependencies up-to-now.
450+
fn hash_result_and_intern_node<Ctxt: DepContext<Deps = D>, R>(
451+
&self,
452+
cx: &Ctxt,
453+
node: DepNode,
454+
edges: EdgesVec,
455+
result: &R,
456+
hash_result: Option<fn(&mut StableHashingContext<'_>, &R) -> Fingerprint>,
457+
) -> DepNodeIndex {
458+
let hashing_timer = cx.profiler().incr_result_hashing();
459+
let current_fingerprint = hash_result.map(|hash_result| {
460+
cx.with_stable_hashing_context(|mut hcx| hash_result(&mut hcx, result))
461+
});
462+
463+
// Intern the new `DepNode` with the dependencies up-to-now.
464+
let (dep_node_index, prev_and_color) =
465+
self.current.intern_node(&self.previous, node, edges, current_fingerprint);
466+
467+
hashing_timer.finish_with_query_invocation_id(dep_node_index.into());
468+
469+
if let Some((prev_index, color)) = prev_and_color {
470+
debug_assert!(
471+
self.colors.get(prev_index).is_none(),
472+
"DepGraph::with_task() - Duplicate DepNodeColor insertion for {node:?}",
473+
);
474+
475+
self.colors.insert(prev_index, color);
476+
}
477+
478+
dep_node_index
479+
}
465480
}
466481

467482
impl<D: Deps> DepGraph<D> {
@@ -536,11 +551,10 @@ impl<D: Deps> DepGraph<D> {
536551
/// FIXME: If the code is changed enough for this node to be marked before requiring the
537552
/// caller's node, we suppose that those changes will be enough to mark this node red and
538553
/// force a recomputation using the "normal" way.
539-
pub fn with_feed_task<Ctxt: DepContext<Deps = D>, A: Debug, R: Debug>(
554+
pub fn with_feed_task<Ctxt: DepContext<Deps = D>, R: Debug>(
540555
&self,
541556
node: DepNode,
542557
cx: Ctxt,
543-
key: A,
544558
result: &R,
545559
hash_result: Option<fn(&mut StableHashingContext<'_>, &R) -> Fingerprint>,
546560
) -> DepNodeIndex {
@@ -588,27 +602,7 @@ impl<D: Deps> DepGraph<D> {
588602
}
589603
});
590604

591-
let hashing_timer = cx.profiler().incr_result_hashing();
592-
let current_fingerprint = hash_result.map(|hash_result| {
593-
cx.with_stable_hashing_context(|mut hcx| hash_result(&mut hcx, result))
594-
});
595-
596-
// Intern the new `DepNode` with the dependencies up-to-now.
597-
let (dep_node_index, prev_and_color) =
598-
data.current.intern_node(&data.previous, node, edges, current_fingerprint);
599-
600-
hashing_timer.finish_with_query_invocation_id(dep_node_index.into());
601-
602-
if let Some((prev_index, color)) = prev_and_color {
603-
debug_assert!(
604-
data.colors.get(prev_index).is_none(),
605-
"DepGraph::with_task() - Duplicate DepNodeColor insertion for {key:?}",
606-
);
607-
608-
data.colors.insert(prev_index, color);
609-
}
610-
611-
dep_node_index
605+
data.hash_result_and_intern_node(&cx, node, edges, result, hash_result)
612606
} else {
613607
// Incremental compilation is turned off. We just execute the task
614608
// without tracking. We still provide a dep-node index that uniquely

0 commit comments

Comments
 (0)