Skip to content

Commit 7d4ee74

Browse files
committed
Don't pass a separate DepKind to query_feed
The query's dep kind can be obtained from its vtable instead. This commit also renames the `query_vtable` parameter to `query`, to be more consistent with other functions that take a QueryVTable.
1 parent a0e206b commit 7d4ee74

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

compiler/rustc_middle/src/queries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ use crate::ty::{
120120
self, CrateInherentImpls, GenericArg, GenericArgsRef, LitToConstInput, PseudoCanonicalInput,
121121
SizedTraitKind, Ty, TyCtxt, TyCtxtFeed,
122122
};
123-
use crate::{dep_graph, mir, thir};
123+
use crate::{mir, thir};
124124

125125
// Each of these queries corresponds to a function pointer field in the
126126
// `Providers` struct for requesting a value of that type, and a method

compiler/rustc_middle/src/query/inner.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};
55

66
use crate::dep_graph;
7-
use crate::dep_graph::{DepKind, DepNodeKey};
7+
use crate::dep_graph::DepNodeKey;
88
use crate::query::erase::{self, Erasable, Erased};
99
use crate::query::plumbing::QueryVTable;
1010
use crate::query::{EnsureMode, QueryCache, QueryMode};
@@ -98,26 +98,26 @@ where
9898
}
9999
}
100100

101-
/// Common implementation of query feeding, used by `define_feedable!`.
101+
/// "Feeds" a feedable query by adding a given key/value pair to its in-memory cache.
102+
/// Called by macro-generated methods of [`rustc_middle::ty::TyCtxtFeed`].
102103
pub(crate) fn query_feed<'tcx, C>(
103104
tcx: TyCtxt<'tcx>,
104-
dep_kind: DepKind,
105-
query_vtable: &QueryVTable<'tcx, C>,
105+
query: &'tcx QueryVTable<'tcx, C>,
106106
key: C::Key,
107107
value: C::Value,
108108
) where
109109
C: QueryCache,
110110
C::Key: DepNodeKey<'tcx>,
111111
{
112-
let format_value = query_vtable.format_value;
112+
let format_value = query.format_value;
113113

114114
// Check whether the in-memory cache already has a value for this key.
115-
match try_get_cached(tcx, &query_vtable.cache, key) {
115+
match try_get_cached(tcx, &query.cache, key) {
116116
Some(old) => {
117117
// The query already has a cached value for this key.
118118
// That's OK if both values are the same, i.e. they have the same hash,
119119
// so now we check their hashes.
120-
if let Some(hash_value_fn) = query_vtable.hash_value_fn {
120+
if let Some(hash_value_fn) = query.hash_value_fn {
121121
let (old_hash, value_hash) = tcx.with_stable_hashing_context(|ref mut hcx| {
122122
(hash_value_fn(hcx, &old), hash_value_fn(hcx, &value))
123123
});
@@ -126,7 +126,7 @@ pub(crate) fn query_feed<'tcx, C>(
126126
// results is tainted by errors. In this case, delay a bug to
127127
// ensure compilation is doomed, and keep the `old` value.
128128
tcx.dcx().delayed_bug(format!(
129-
"Trying to feed an already recorded value for query {dep_kind:?} key={key:?}:\n\
129+
"Trying to feed an already recorded value for query {query:?} key={key:?}:\n\
130130
old value: {old}\nnew value: {value}",
131131
old = format_value(&old),
132132
value = format_value(&value),
@@ -137,7 +137,7 @@ pub(crate) fn query_feed<'tcx, C>(
137137
// If feeding the same value multiple times needs to be supported,
138138
// the query should not be marked `no_hash`.
139139
bug!(
140-
"Trying to feed an already recorded value for query {dep_kind:?} key={key:?}:\n\
140+
"Trying to feed an already recorded value for query {query:?} key={key:?}:\n\
141141
old value: {old}\nnew value: {value}",
142142
old = format_value(&old),
143143
value = format_value(&value),
@@ -147,15 +147,15 @@ pub(crate) fn query_feed<'tcx, C>(
147147
None => {
148148
// There is no cached value for this key, so feed the query by
149149
// adding the provided value to the cache.
150-
let dep_node = dep_graph::DepNode::construct(tcx, dep_kind, &key);
150+
let dep_node = dep_graph::DepNode::construct(tcx, query.dep_kind, &key);
151151
let dep_node_index = tcx.dep_graph.with_feed_task(
152152
dep_node,
153153
tcx,
154154
&value,
155-
query_vtable.hash_value_fn,
156-
query_vtable.format_value,
155+
query.hash_value_fn,
156+
query.format_value,
157157
);
158-
query_vtable.cache.complete(key, value, dep_node_index);
158+
query.cache.complete(key, value, dep_node_index);
159159
}
160160
}
161161
}

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,6 @@ macro_rules! define_callbacks {
493493
let erased_value = $name::provided_to_erased(self.tcx, value);
494494
$crate::query::inner::query_feed(
495495
self.tcx,
496-
dep_graph::DepKind::$name,
497496
&self.tcx.query_system.query_vtables.$name,
498497
key,
499498
erased_value,

0 commit comments

Comments
 (0)