Skip to content

Commit f7fed56

Browse files
committed
Pass QueryVTable to two functions instead of two fn pointers.
Specifically, `DepGraph::with_feed_task` and `incremental_verify_ich` This makes some things shorter, at the cost of making module `dep_graph` depend directly on module `query`. (It already depends indirectly via module `verify_ich`.)
1 parent 9ffa26f commit f7fed56

File tree

4 files changed

+17
-38
lines changed

4 files changed

+17
-38
lines changed

compiler/rustc_middle/src/dep_graph/graph.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use super::serialized::{GraphEncoder, SerializedDepGraph, SerializedDepNodeIndex
2727
use super::{DepKind, DepNode, WorkProductId, read_deps, with_deps};
2828
use crate::dep_graph::edges::EdgesVec;
2929
use crate::ich::StableHashingContext;
30+
use crate::query::{QueryCache, QueryVTable};
3031
use crate::ty::TyCtxt;
3132
use crate::verify_ich::incremental_verify_ich;
3233

@@ -572,13 +573,12 @@ impl DepGraph {
572573
/// FIXME: If the code is changed enough for this node to be marked before requiring the
573574
/// caller's node, we suppose that those changes will be enough to mark this node red and
574575
/// force a recomputation using the "normal" way.
575-
pub fn with_feed_task<'tcx, R>(
576+
pub fn with_feed_task<'tcx, C: QueryCache>(
576577
&self,
577-
node: DepNode,
578578
tcx: TyCtxt<'tcx>,
579-
result: &R,
580-
hash_result: Option<fn(&mut StableHashingContext<'_>, &R) -> Fingerprint>,
581-
format_value_fn: fn(&R) -> String,
579+
query: &'tcx QueryVTable<'tcx, C>,
580+
node: DepNode,
581+
value: &C::Value,
582582
) -> DepNodeIndex {
583583
if let Some(data) = self.data.as_ref() {
584584
// The caller query has more dependencies than the node we are creating. We may
@@ -590,17 +590,10 @@ impl DepGraph {
590590
if let Some(prev_index) = data.previous.node_to_index_opt(&node) {
591591
let dep_node_index = data.colors.current(prev_index);
592592
if let Some(dep_node_index) = dep_node_index {
593-
incremental_verify_ich(
594-
tcx,
595-
data,
596-
result,
597-
prev_index,
598-
hash_result,
599-
format_value_fn,
600-
);
593+
incremental_verify_ich(tcx, data, query, value, prev_index);
601594

602595
#[cfg(debug_assertions)]
603-
if hash_result.is_some() {
596+
if query.hash_value_fn.is_some() {
604597
data.current.record_edge(
605598
dep_node_index,
606599
node,
@@ -624,7 +617,7 @@ impl DepGraph {
624617
}
625618
});
626619

627-
data.hash_result_and_alloc_node(tcx, node, edges, result, hash_result)
620+
data.hash_result_and_alloc_node(tcx, node, edges, value, query.hash_value_fn)
628621
} else {
629622
// Incremental compilation is turned off. We just execute the task
630623
// without tracking. We still provide a dep-node index that uniquely

compiler/rustc_middle/src/query/inner.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,7 @@ pub(crate) fn query_feed<'tcx, C>(
158158
// There is no cached value for this key, so feed the query by
159159
// adding the provided value to the cache.
160160
let dep_node = dep_graph::DepNode::construct(tcx, query.dep_kind, &key);
161-
let dep_node_index = tcx.dep_graph.with_feed_task(
162-
dep_node,
163-
tcx,
164-
&value,
165-
query.hash_value_fn,
166-
query.format_value,
167-
);
161+
let dep_node_index = tcx.dep_graph.with_feed_task(tcx, query, dep_node, &value);
168162
query.cache.complete(key, value, dep_node_index);
169163
}
170164
}

compiler/rustc_middle/src/verify_ich.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,30 @@ use rustc_data_structures::fingerprint::Fingerprint;
44
use tracing::instrument;
55

66
use crate::dep_graph::{DepGraphData, SerializedDepNodeIndex};
7-
use crate::ich::StableHashingContext;
7+
use crate::query::{QueryCache, QueryVTable};
88
use crate::ty::TyCtxt;
99

1010
#[inline]
11-
#[instrument(skip(tcx, dep_graph_data, result, hash_result, format_value), level = "debug")]
12-
pub fn incremental_verify_ich<'tcx, V>(
11+
#[instrument(skip(tcx, query, dep_graph_data, result), level = "debug")]
12+
pub fn incremental_verify_ich<'tcx, C: QueryCache>(
1313
tcx: TyCtxt<'tcx>,
1414
dep_graph_data: &DepGraphData,
15-
result: &V,
15+
query: &'tcx QueryVTable<'tcx, C>,
16+
result: &C::Value,
1617
prev_index: SerializedDepNodeIndex,
17-
hash_result: Option<fn(&mut StableHashingContext<'_>, &V) -> Fingerprint>,
18-
format_value: fn(&V) -> String,
1918
) {
2019
if !dep_graph_data.is_index_green(prev_index) {
2120
incremental_verify_ich_not_green(tcx, prev_index)
2221
}
2322

24-
let new_hash = hash_result.map_or(Fingerprint::ZERO, |f| {
23+
let new_hash = query.hash_value_fn.map_or(Fingerprint::ZERO, |f| {
2524
tcx.with_stable_hashing_context(|mut hcx| f(&mut hcx, result))
2625
});
2726

2827
let old_hash = dep_graph_data.prev_value_fingerprint_of(prev_index);
2928

3029
if new_hash != old_hash {
31-
incremental_verify_ich_failed(tcx, prev_index, &|| format_value(result));
30+
incremental_verify_ich_failed(tcx, prev_index, &|| (query.format_value)(result));
3231
}
3332
}
3433

compiler/rustc_query_impl/src/execution.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -475,14 +475,7 @@ fn execute_job_incr<'tcx, C: QueryCache>(
475475
//
476476
// See issue #82920 for an example of a miscompilation that would get turned into an
477477
// ICE by this check.
478-
incremental_verify_ich(
479-
tcx,
480-
dep_graph_data,
481-
&value,
482-
prev_index,
483-
query.hash_value_fn,
484-
query.format_value,
485-
);
478+
incremental_verify_ich(tcx, dep_graph_data, query, &value, prev_index);
486479
}
487480

488481
(value, dep_node_index)

0 commit comments

Comments
 (0)