Skip to content

Commit 06d3be4

Browse files
committed
Auto merge of #152791 - nnethercote:rm-const-FLAGS, r=<try>
Remove `const FLAGS`.
2 parents e0cb264 + 940ba86 commit 06d3be4

File tree

5 files changed

+186
-279
lines changed

5 files changed

+186
-279
lines changed

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::fmt::Debug;
1+
use std::fmt;
22
use std::ops::Deref;
33

44
use rustc_data_structures::fingerprint::Fingerprint;
@@ -12,7 +12,7 @@ use rustc_span::{ErrorGuaranteed, Span};
1212
pub use sealed::IntoQueryParam;
1313

1414
use crate::dep_graph;
15-
use crate::dep_graph::{DepKind, DepNodeIndex, SerializedDepNodeIndex};
15+
use crate::dep_graph::{DepKind, DepNode, DepNodeIndex, SerializedDepNodeIndex};
1616
use crate::ich::StableHashingContext;
1717
use crate::queries::{
1818
ExternProviders, PerQueryVTables, Providers, QueryArenas, QueryCaches, QueryEngine, QueryStates,
@@ -104,7 +104,15 @@ pub enum QueryMode {
104104
/// Stores function pointers and other metadata for a particular query.
105105
pub struct QueryVTable<'tcx, C: QueryCache> {
106106
pub name: &'static str,
107+
/// True if this query has the `anon` modifier.
108+
pub anon: bool,
109+
/// True if this query has the `eval_always` modifier.
107110
pub eval_always: bool,
111+
/// True if this query has the `depth_limit` modifier.
112+
pub depth_limit: bool,
113+
/// True if this query has the `feedable` modifier.
114+
pub feedable: bool,
115+
108116
pub dep_kind: DepKind,
109117
/// How this query deals with query cycle errors.
110118
pub cycle_error_handling: CycleErrorHandling,
@@ -142,6 +150,85 @@ pub struct QueryVTable<'tcx, C: QueryCache> {
142150
pub description_fn: fn(TyCtxt<'tcx>, C::Key) -> String,
143151
}
144152

153+
impl<'tcx, C: QueryCache> fmt::Debug for QueryVTable<'tcx, C> {
154+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
155+
// When debug-printing a query vtable (e.g. for ICE or tracing),
156+
// just print the query name to know what query we're dealing with.
157+
// The other fields and flags are probably just unhelpful noise.
158+
//
159+
// If there is need for a more detailed dump of all flags and fields,
160+
// consider writing a separate dump method and calling it explicitly.
161+
f.write_str(self.name)
162+
}
163+
}
164+
165+
impl<'tcx, C: QueryCache> QueryVTable<'tcx, C> {
166+
#[inline(always)]
167+
pub fn will_cache_on_disk_for_key(&self, tcx: TyCtxt<'tcx>, key: &C::Key) -> bool {
168+
self.will_cache_on_disk_for_key_fn.map_or(false, |f| f(tcx, key))
169+
}
170+
171+
// Don't use this method to access query results, instead use the methods on TyCtxt.
172+
#[inline(always)]
173+
pub fn query_state(&self, tcx: TyCtxt<'tcx>) -> &'tcx QueryState<'tcx, C::Key> {
174+
// Safety:
175+
// This is just manually doing the subfield referencing through pointer math.
176+
unsafe {
177+
&*(&tcx.query_system.states as *const QueryStates<'tcx>)
178+
.byte_add(self.query_state)
179+
.cast::<QueryState<'tcx, C::Key>>()
180+
}
181+
}
182+
183+
// Don't use this method to access query results, instead use the methods on TyCtxt.
184+
#[inline(always)]
185+
pub fn query_cache(&self, tcx: TyCtxt<'tcx>) -> &'tcx C {
186+
// Safety:
187+
// This is just manually doing the subfield referencing through pointer math.
188+
unsafe {
189+
&*(&tcx.query_system.caches as *const QueryCaches<'tcx>)
190+
.byte_add(self.query_cache)
191+
.cast::<C>()
192+
}
193+
}
194+
195+
#[inline(always)]
196+
pub fn try_load_from_disk(
197+
&self,
198+
tcx: TyCtxt<'tcx>,
199+
key: &C::Key,
200+
prev_index: SerializedDepNodeIndex,
201+
index: DepNodeIndex,
202+
) -> Option<C::Value> {
203+
// `?` will return None immediately for queries that never cache to disk.
204+
self.try_load_from_disk_fn?(tcx, key, prev_index, index)
205+
}
206+
207+
#[inline]
208+
pub fn is_loadable_from_disk(
209+
&self,
210+
tcx: TyCtxt<'tcx>,
211+
key: &C::Key,
212+
index: SerializedDepNodeIndex,
213+
) -> bool {
214+
self.is_loadable_from_disk_fn.map_or(false, |f| f(tcx, key, index))
215+
}
216+
217+
/// Synthesize an error value to let compilation continue after a cycle.
218+
pub fn value_from_cycle_error(
219+
&self,
220+
tcx: TyCtxt<'tcx>,
221+
cycle_error: &CycleError,
222+
guar: ErrorGuaranteed,
223+
) -> C::Value {
224+
(self.value_from_cycle_error)(tcx, cycle_error, guar)
225+
}
226+
227+
pub fn construct_dep_node(&self, tcx: TyCtxt<'tcx>, key: &C::Key) -> DepNode {
228+
DepNode::construct(tcx, self.dep_kind, key)
229+
}
230+
}
231+
145232
pub struct QuerySystemFns {
146233
pub engine: QueryEngine,
147234
pub local_providers: Providers,

compiler/rustc_query_impl/src/dep_kind_vtables.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use rustc_middle::bug;
22
use rustc_middle::dep_graph::{DepKindVTable, DepNodeKey, KeyFingerprintStyle};
33
use rustc_middle::query::QueryCache;
44

5+
use crate::QueryDispatcherUnerased;
56
use crate::plumbing::{force_from_dep_node_inner, try_load_from_on_disk_cache_inner};
6-
use crate::{QueryDispatcherUnerased, QueryFlags};
77

88
/// [`DepKindVTable`] constructors for special dep kinds that aren't queries.
99
#[expect(non_snake_case, reason = "use non-snake case to avoid collision with query names")]
@@ -110,14 +110,14 @@ mod non_query {
110110

111111
/// Shared implementation of the [`DepKindVTable`] constructor for queries.
112112
/// Called from macro-generated code for each query.
113-
pub(crate) fn make_dep_kind_vtable_for_query<'tcx, Q, Cache, const FLAGS: QueryFlags>(
113+
pub(crate) fn make_dep_kind_vtable_for_query<'tcx, Q, Cache>(
114+
is_anon: bool,
114115
is_eval_always: bool,
115116
) -> DepKindVTable<'tcx>
116117
where
117-
Q: QueryDispatcherUnerased<'tcx, Cache, FLAGS>,
118+
Q: QueryDispatcherUnerased<'tcx, Cache>,
118119
Cache: QueryCache + 'tcx,
119120
{
120-
let is_anon = FLAGS.is_anon;
121121
let key_fingerprint_style = if is_anon {
122122
KeyFingerprintStyle::Opaque
123123
} else {
@@ -140,6 +140,7 @@ where
140140
is_eval_always,
141141
key_fingerprint_style,
142142
force_from_dep_node: Some(|tcx, dep_node, _| {
143+
// njn: hmm
143144
force_from_dep_node_inner(Q::query_dispatcher(tcx), tcx, dep_node)
144145
}),
145146
try_load_from_on_disk_cache: Some(|tcx, dep_node| {

0 commit comments

Comments
 (0)