Skip to content

Commit 40b2274

Browse files
committed
Change how query vtables are constructed.
Currently `define_dep_nodes` produces a macro `make_dep_kind_array` that encodes the names of non-queries followed by queries. This macro is used by `make_dep_kind_vtables` to make the full array of vtables, by referring to vtable constructor functions that are put into `mod _dep_kind_vtable_ctors`. Pretty weird! This commit takes advantage of the previous commit's changes to `rustc_with_all_queries`, which makes both query and non-query information available. A new call to `rustc_with_all_queries` is used to construct the vtable array. (This moves some dep_kind_vtable code from `plumbing.rs` to `dep_kind_vtables.rs`, which is good.) It's straightforward now with iterator chaining, and `mod _dep_kind_vtable_ctors` is no longer needed.
1 parent 253c696 commit 40b2274

3 files changed

Lines changed: 46 additions & 45 deletions

File tree

compiler/rustc_middle/src/dep_graph/dep_node.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,6 @@ macro_rules! define_dep_nodes {
284284
)*
285285
}
286286
) => {
287-
#[macro_export]
288-
macro_rules! make_dep_kind_array {
289-
($mod:ident) => {[
290-
$( $mod::$nq_name(), )*
291-
$( $mod::$q_name(), )*
292-
]};
293-
}
294-
295-
/// This enum serves as an index into arrays built by `make_dep_kind_array`.
296287
// This enum has more than u8::MAX variants so we need some kind of multi-byte
297288
// encoding. The derived Encodable/Decodable uses leb128 encoding which is
298289
// dense when only considering this enum. But DepKind is encoded in a larger

compiler/rustc_query_impl/src/dep_kind_vtables.rs

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use rustc_middle::arena::Arena;
12
use rustc_middle::bug;
23
use rustc_middle::dep_graph::{DepKindVTable, DepNodeKey, KeyFingerprintStyle};
34
use rustc_middle::query::QueryCache;
@@ -133,24 +134,51 @@ where
133134
}
134135
}
135136

136-
/// Helper module containing a [`DepKindVTable`] constructor for each dep kind,
137-
/// for use with [`rustc_middle::make_dep_kind_array`].
138-
///
139-
/// That macro will check that we gave it a constructor for every known dep kind.
140-
mod _dep_kind_vtable_ctors {
141-
// Re-export all of the vtable constructors for non-query and query dep kinds.
142-
143-
// Non-query vtable constructors are defined in normal code.
144-
pub(crate) use super::non_query::*;
145-
// Query vtable constructors are defined via a macro.
146-
pub(crate) use crate::_dep_kind_vtable_ctors_for_queries::*;
137+
macro_rules! define_dep_kind_vtables {
138+
(
139+
queries {
140+
$(
141+
$(#[$attr:meta])*
142+
[$($modifiers:tt)*]
143+
fn $name:ident($K:ty) -> $V:ty,
144+
)*
145+
}
146+
non_queries {
147+
$(
148+
$(#[$nq_attr:meta])*
149+
$nq_name:ident,
150+
)*
151+
}
152+
) => {{
153+
// The small number of non-query vtables: `Null`, `Red`, etc.
154+
let nq_vtables = [
155+
$(
156+
non_query::$nq_name(),
157+
)*
158+
];
159+
160+
// The large number of query vtables.
161+
let q_vtables: [DepKindVTable<'tcx>; _] = [
162+
$(
163+
$crate::dep_kind_vtables::make_dep_kind_vtable_for_query::<
164+
$crate::query_impl::$name::VTableGetter,
165+
>(
166+
is_anon!([$($modifiers)*]),
167+
if_cache_on_disk!([$($modifiers)*] true false),
168+
is_eval_always!([$($modifiers)*]),
169+
)
170+
),*
171+
];
172+
173+
(nq_vtables, q_vtables)
174+
}}
147175
}
148176

149-
pub fn make_dep_kind_vtables<'tcx>(
150-
arena: &'tcx rustc_middle::arena::Arena<'tcx>,
151-
) -> &'tcx [DepKindVTable<'tcx>] {
152-
// Create an array of vtables, one for each dep kind (non-query and query).
153-
let dep_kind_vtables: [DepKindVTable<'tcx>; _] =
154-
rustc_middle::make_dep_kind_array!(_dep_kind_vtable_ctors);
155-
arena.alloc_from_iter(dep_kind_vtables)
177+
// Create an array of vtables, one for each dep kind (non-query and query).
178+
pub fn make_dep_kind_vtables<'tcx>(arena: &'tcx Arena<'tcx>) -> &'tcx [DepKindVTable<'tcx>] {
179+
let (nq_vtables, q_vtables) =
180+
rustc_middle::rustc_with_all_queries! { define_dep_kind_vtables! };
181+
182+
// Non-query vtables must come before query vtables, to match the order of `DepKind`.
183+
arena.alloc_from_iter(nq_vtables.into_iter().chain(q_vtables.into_iter()))
156184
}

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -693,23 +693,5 @@ macro_rules! define_queries {
693693
})
694694
}
695695
}
696-
697-
/// Declares a dep-kind vtable constructor for each query.
698-
mod _dep_kind_vtable_ctors_for_queries {
699-
use ::rustc_middle::dep_graph::DepKindVTable;
700-
use $crate::dep_kind_vtables::make_dep_kind_vtable_for_query;
701-
702-
$(
703-
/// `DepKindVTable` constructor for this query.
704-
pub(crate) fn $name<'tcx>() -> DepKindVTable<'tcx> {
705-
use $crate::query_impl::$name::VTableGetter;
706-
make_dep_kind_vtable_for_query::<VTableGetter>(
707-
is_anon!([$($modifiers)*]),
708-
if_cache_on_disk!([$($modifiers)*] true false),
709-
is_eval_always!([$($modifiers)*]),
710-
)
711-
}
712-
)*
713-
}
714696
}
715697
}

0 commit comments

Comments
 (0)