Skip to content

Commit 119eea2

Browse files
authored
Rollup merge of #151577 - Zalathar:dep-kind-vtable, r=Kivooeo
Rename `DepKindStruct` to `DepKindVTable` This type is used by dependency-tracking code in the query system, for looking up function pointers and other metadata associated with a particular `DepKind`. Calling it “struct” is not particularly helpful, whereas calling it a “vtable” at least gives some basic intuition for what it is and how it is used. Some associated identifiers have also drifted a bit over time, and this PR adjusts those as well. There should be no change to compiler behaviour. r? nnethercote (or compiler)
2 parents 17ba7f2 + 4b25ccd commit 119eea2

10 files changed

Lines changed: 60 additions & 52 deletions

File tree

compiler/rustc_interface/src/callbacks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn def_id_debug(def_id: rustc_hir::def_id::DefId, f: &mut fmt::Formatter<'_>) ->
7272
pub fn dep_kind_debug(kind: DepKind, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
7373
tls::with_opt(|opt_tcx| {
7474
if let Some(tcx) = opt_tcx {
75-
write!(f, "{}", tcx.dep_kind_info(kind).name)
75+
write!(f, "{}", tcx.dep_kind_vtable(kind).name)
7676
} else {
7777
default_dep_kind_debug(kind, f)
7878
}

compiler/rustc_interface/src/passes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ pub fn create_and_enter_global_ctxt<T, F: for<'tcx> FnOnce(TyCtxt<'tcx>) -> T>(
992992
hir_arena,
993993
untracked,
994994
dep_graph,
995-
rustc_query_impl::query_callbacks(arena),
995+
rustc_query_impl::make_dep_kind_vtables(arena),
996996
rustc_query_impl::query_system(
997997
providers.queries,
998998
providers.extern_queries,

compiler/rustc_middle/src/arena.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ macro_rules! arena_types {
104104
[decode] is_late_bound_map: rustc_data_structures::fx::FxIndexSet<rustc_hir::ItemLocalId>,
105105
[decode] impl_source: rustc_middle::traits::ImplSource<'tcx, ()>,
106106

107-
[] dep_kind: rustc_middle::dep_graph::DepKindStruct<'tcx>,
107+
[] dep_kind_vtable: rustc_middle::dep_graph::DepKindVTable<'tcx>,
108108

109109
[decode] trait_impl_trait_tys:
110110
rustc_data_structures::unord::UnordMap<

compiler/rustc_middle/src/dep_graph/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub use rustc_query_system::dep_graph::{
1818

1919
pub type DepGraph = rustc_query_system::dep_graph::DepGraph<DepsType>;
2020

21-
pub type DepKindStruct<'tcx> = rustc_query_system::dep_graph::DepKindStruct<TyCtxt<'tcx>>;
21+
pub type DepKindVTable<'tcx> = rustc_query_system::dep_graph::DepKindVTable<TyCtxt<'tcx>>;
2222

2323
pub struct DepsType;
2424

@@ -79,8 +79,8 @@ impl<'tcx> DepContext for TyCtxt<'tcx> {
7979
}
8080

8181
#[inline]
82-
fn dep_kind_info(&self, dk: DepKind) -> &DepKindStruct<'tcx> {
83-
&self.query_kinds[dk.as_usize()]
82+
fn dep_kind_vtable(&self, dk: DepKind) -> &DepKindVTable<'tcx> {
83+
&self.dep_kind_vtables[dk.as_usize()]
8484
}
8585

8686
fn with_reduced_queries<T>(self, f: impl FnOnce() -> T) -> T {

compiler/rustc_middle/src/ty/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use rustc_type_ir::{
5959
use tracing::{debug, instrument};
6060

6161
use crate::arena::Arena;
62-
use crate::dep_graph::{DepGraph, DepKindStruct};
62+
use crate::dep_graph::{DepGraph, DepKindVTable};
6363
use crate::infer::canonical::{CanonicalParamEnvCache, CanonicalVarKind, CanonicalVarKinds};
6464
use crate::lint::lint_level;
6565
use crate::metadata::ModChild;
@@ -1580,7 +1580,7 @@ pub struct GlobalCtxt<'tcx> {
15801580
untracked: Untracked,
15811581

15821582
pub query_system: QuerySystem<'tcx>,
1583-
pub(crate) query_kinds: &'tcx [DepKindStruct<'tcx>],
1583+
pub(crate) dep_kind_vtables: &'tcx [DepKindVTable<'tcx>],
15841584

15851585
// Internal caches for metadata decoding. No need to track deps on this.
15861586
pub ty_rcache: Lock<FxHashMap<ty::CReaderCacheKey, Ty<'tcx>>>,
@@ -1801,7 +1801,7 @@ impl<'tcx> TyCtxt<'tcx> {
18011801
hir_arena: &'tcx WorkerLocal<hir::Arena<'tcx>>,
18021802
untracked: Untracked,
18031803
dep_graph: DepGraph,
1804-
query_kinds: &'tcx [DepKindStruct<'tcx>],
1804+
dep_kind_vtables: &'tcx [DepKindVTable<'tcx>],
18051805
query_system: QuerySystem<'tcx>,
18061806
hooks: crate::hooks::Providers,
18071807
current_gcx: CurrentGcx,
@@ -1831,7 +1831,7 @@ impl<'tcx> TyCtxt<'tcx> {
18311831
consts: common_consts,
18321832
untracked,
18331833
query_system,
1834-
query_kinds,
1834+
dep_kind_vtables,
18351835
ty_rcache: Default::default(),
18361836
selection_cache: Default::default(),
18371837
evaluation_cache: Default::default(),

compiler/rustc_query_impl/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use rustc_data_structures::stable_hasher::HashStable;
1010
use rustc_data_structures::sync::AtomicU64;
1111
use rustc_middle::arena::Arena;
12-
use rustc_middle::dep_graph::{self, DepKind, DepKindStruct, DepNodeIndex};
12+
use rustc_middle::dep_graph::{self, DepKind, DepKindVTable, DepNodeIndex};
1313
use rustc_middle::query::erase::{Erase, erase, restore};
1414
use rustc_middle::query::on_disk_cache::{CacheEncoder, EncodedDepNodeIndex, OnDiskCache};
1515
use rustc_middle::query::plumbing::{DynamicQuery, QuerySystem, QuerySystemFns};

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_hir::limit::Limit;
1212
use rustc_index::Idx;
1313
use rustc_middle::bug;
1414
use rustc_middle::dep_graph::{
15-
self, DepContext, DepKind, DepKindStruct, DepNode, DepNodeIndex, SerializedDepNodeIndex,
15+
self, DepContext, DepKind, DepKindVTable, DepNode, DepNodeIndex, SerializedDepNodeIndex,
1616
dep_kinds,
1717
};
1818
use rustc_middle::query::Key;
@@ -489,14 +489,17 @@ where
489489
}
490490
}
491491

492-
pub(crate) fn query_callback<'tcx, Q>(is_anon: bool, is_eval_always: bool) -> DepKindStruct<'tcx>
492+
pub(crate) fn make_dep_kind_vtable_for_query<'tcx, Q>(
493+
is_anon: bool,
494+
is_eval_always: bool,
495+
) -> DepKindVTable<'tcx>
493496
where
494497
Q: QueryConfigRestored<'tcx>,
495498
{
496499
let fingerprint_style = <Q::Config as QueryConfig<QueryCtxt<'tcx>>>::Key::fingerprint_style();
497500

498501
if is_anon || !fingerprint_style.reconstructible() {
499-
return DepKindStruct {
502+
return DepKindVTable {
500503
is_anon,
501504
is_eval_always,
502505
fingerprint_style,
@@ -506,7 +509,7 @@ where
506509
};
507510
}
508511

509-
DepKindStruct {
512+
DepKindVTable {
510513
is_anon,
511514
is_eval_always,
512515
fingerprint_style,
@@ -811,15 +814,19 @@ macro_rules! define_queries {
811814
for<'tcx> fn(TyCtxt<'tcx>)
812815
] = &[$(query_impl::$name::query_key_hash_verify),*];
813816

814-
#[allow(nonstandard_style)]
815-
mod query_callbacks {
817+
/// Module containing a named function for each dep kind (including queries)
818+
/// that creates a `DepKindVTable`.
819+
///
820+
/// Consumed via `make_dep_kind_array!` to create a list of vtables.
821+
#[expect(non_snake_case)]
822+
mod _dep_kind_vtable_ctors {
816823
use super::*;
817824
use rustc_middle::bug;
818825
use rustc_query_system::dep_graph::FingerprintStyle;
819826

820827
// We use this for most things when incr. comp. is turned off.
821-
pub(crate) fn Null<'tcx>() -> DepKindStruct<'tcx> {
822-
DepKindStruct {
828+
pub(crate) fn Null<'tcx>() -> DepKindVTable<'tcx> {
829+
DepKindVTable {
823830
is_anon: false,
824831
is_eval_always: false,
825832
fingerprint_style: FingerprintStyle::Unit,
@@ -830,8 +837,8 @@ macro_rules! define_queries {
830837
}
831838

832839
// We use this for the forever-red node.
833-
pub(crate) fn Red<'tcx>() -> DepKindStruct<'tcx> {
834-
DepKindStruct {
840+
pub(crate) fn Red<'tcx>() -> DepKindVTable<'tcx> {
841+
DepKindVTable {
835842
is_anon: false,
836843
is_eval_always: false,
837844
fingerprint_style: FingerprintStyle::Unit,
@@ -841,8 +848,8 @@ macro_rules! define_queries {
841848
}
842849
}
843850

844-
pub(crate) fn SideEffect<'tcx>() -> DepKindStruct<'tcx> {
845-
DepKindStruct {
851+
pub(crate) fn SideEffect<'tcx>() -> DepKindVTable<'tcx> {
852+
DepKindVTable {
846853
is_anon: false,
847854
is_eval_always: false,
848855
fingerprint_style: FingerprintStyle::Unit,
@@ -855,8 +862,8 @@ macro_rules! define_queries {
855862
}
856863
}
857864

858-
pub(crate) fn AnonZeroDeps<'tcx>() -> DepKindStruct<'tcx> {
859-
DepKindStruct {
865+
pub(crate) fn AnonZeroDeps<'tcx>() -> DepKindVTable<'tcx> {
866+
DepKindVTable {
860867
is_anon: true,
861868
is_eval_always: false,
862869
fingerprint_style: FingerprintStyle::Opaque,
@@ -866,8 +873,8 @@ macro_rules! define_queries {
866873
}
867874
}
868875

869-
pub(crate) fn TraitSelect<'tcx>() -> DepKindStruct<'tcx> {
870-
DepKindStruct {
876+
pub(crate) fn TraitSelect<'tcx>() -> DepKindVTable<'tcx> {
877+
DepKindVTable {
871878
is_anon: true,
872879
is_eval_always: false,
873880
fingerprint_style: FingerprintStyle::Unit,
@@ -877,8 +884,8 @@ macro_rules! define_queries {
877884
}
878885
}
879886

880-
pub(crate) fn CompileCodegenUnit<'tcx>() -> DepKindStruct<'tcx> {
881-
DepKindStruct {
887+
pub(crate) fn CompileCodegenUnit<'tcx>() -> DepKindVTable<'tcx> {
888+
DepKindVTable {
882889
is_anon: false,
883890
is_eval_always: false,
884891
fingerprint_style: FingerprintStyle::Opaque,
@@ -888,8 +895,8 @@ macro_rules! define_queries {
888895
}
889896
}
890897

891-
pub(crate) fn CompileMonoItem<'tcx>() -> DepKindStruct<'tcx> {
892-
DepKindStruct {
898+
pub(crate) fn CompileMonoItem<'tcx>() -> DepKindVTable<'tcx> {
899+
DepKindVTable {
893900
is_anon: false,
894901
is_eval_always: false,
895902
fingerprint_style: FingerprintStyle::Opaque,
@@ -899,8 +906,8 @@ macro_rules! define_queries {
899906
}
900907
}
901908

902-
pub(crate) fn Metadata<'tcx>() -> DepKindStruct<'tcx> {
903-
DepKindStruct {
909+
pub(crate) fn Metadata<'tcx>() -> DepKindVTable<'tcx> {
910+
DepKindVTable {
904911
is_anon: false,
905912
is_eval_always: false,
906913
fingerprint_style: FingerprintStyle::Unit,
@@ -910,16 +917,17 @@ macro_rules! define_queries {
910917
}
911918
}
912919

913-
$(pub(crate) fn $name<'tcx>()-> DepKindStruct<'tcx> {
914-
$crate::plumbing::query_callback::<query_impl::$name::QueryType<'tcx>>(
920+
$(pub(crate) fn $name<'tcx>() -> DepKindVTable<'tcx> {
921+
use $crate::query_impl::$name::QueryType;
922+
$crate::plumbing::make_dep_kind_vtable_for_query::<QueryType<'tcx>>(
915923
is_anon!([$($modifiers)*]),
916924
is_eval_always!([$($modifiers)*]),
917925
)
918926
})*
919927
}
920928

921-
pub fn query_callbacks<'tcx>(arena: &'tcx Arena<'tcx>) -> &'tcx [DepKindStruct<'tcx>] {
922-
arena.alloc_from_iter(rustc_middle::make_dep_kind_array!(query_callbacks))
929+
pub fn make_dep_kind_vtables<'tcx>(arena: &'tcx Arena<'tcx>) -> &'tcx [DepKindVTable<'tcx>] {
930+
arena.alloc_from_iter(rustc_middle::make_dep_kind_array!(_dep_kind_vtable_ctors))
923931
}
924932
}
925933
}

compiler/rustc_query_system/src/dep_graph/dep_node.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,12 @@ where
221221
}
222222
}
223223

224-
/// This struct stores metadata about each DepKind.
224+
/// This struct stores function pointers and other metadata for a particular DepKind.
225225
///
226226
/// Information is retrieved by indexing the `DEP_KINDS` array using the integer value
227227
/// of the `DepKind`. Overall, this allows to implement `DepContext` using this manual
228228
/// jump table instead of large matches.
229-
pub struct DepKindStruct<Tcx: DepContext> {
229+
pub struct DepKindVTable<Tcx: DepContext> {
230230
/// Anonymous queries cannot be replayed from one compiler invocation to the next.
231231
/// When their result is needed, it is recomputed. They are useful for fine-grained
232232
/// dependency tracking, and caching within one compiler invocation.

compiler/rustc_query_system/src/dep_graph/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod serialized;
77

88
use std::panic;
99

10-
pub use dep_node::{DepKind, DepKindStruct, DepNode, DepNodeParams, WorkProductId};
10+
pub use dep_node::{DepKind, DepKindVTable, DepNode, DepNodeParams, WorkProductId};
1111
pub(crate) use graph::DepGraphData;
1212
pub use graph::{DepGraph, DepNodeIndex, TaskDepsRef, WorkProduct, WorkProductMap, hash_result};
1313
pub use query::DepGraphQuery;
@@ -35,21 +35,21 @@ pub trait DepContext: Copy {
3535
/// Access the compiler session.
3636
fn sess(&self) -> &Session;
3737

38-
fn dep_kind_info(&self, dep_node: DepKind) -> &DepKindStruct<Self>;
38+
fn dep_kind_vtable(&self, dep_node: DepKind) -> &DepKindVTable<Self>;
3939

4040
#[inline(always)]
4141
fn fingerprint_style(self, kind: DepKind) -> FingerprintStyle {
42-
let data = self.dep_kind_info(kind);
43-
if data.is_anon {
42+
let vtable = self.dep_kind_vtable(kind);
43+
if vtable.is_anon {
4444
return FingerprintStyle::Opaque;
4545
}
46-
data.fingerprint_style
46+
vtable.fingerprint_style
4747
}
4848

4949
#[inline(always)]
5050
/// Return whether this kind always require evaluation.
5151
fn is_eval_always(self, kind: DepKind) -> bool {
52-
self.dep_kind_info(kind).is_eval_always
52+
self.dep_kind_vtable(kind).is_eval_always
5353
}
5454

5555
/// Try to force a dep node to execute and see if it's green.
@@ -65,9 +65,10 @@ pub trait DepContext: Copy {
6565
prev_index: SerializedDepNodeIndex,
6666
frame: &MarkFrame<'_>,
6767
) -> bool {
68-
let cb = self.dep_kind_info(dep_node.kind);
69-
if let Some(f) = cb.force_from_dep_node {
70-
match panic::catch_unwind(panic::AssertUnwindSafe(|| f(self, dep_node, prev_index))) {
68+
if let Some(force_fn) = self.dep_kind_vtable(dep_node.kind).force_from_dep_node {
69+
match panic::catch_unwind(panic::AssertUnwindSafe(|| {
70+
force_fn(self, dep_node, prev_index)
71+
})) {
7172
Err(value) => {
7273
if !value.is::<rustc_errors::FatalErrorMarker>() {
7374
print_markframe_trace(self.dep_graph(), frame);
@@ -83,9 +84,8 @@ pub trait DepContext: Copy {
8384

8485
/// Load data from the on-disk cache.
8586
fn try_load_from_on_disk_cache(self, dep_node: DepNode) {
86-
let cb = self.dep_kind_info(dep_node.kind);
87-
if let Some(f) = cb.try_load_from_on_disk_cache {
88-
f(self, dep_node)
87+
if let Some(try_load_fn) = self.dep_kind_vtable(dep_node.kind).try_load_from_on_disk_cache {
88+
try_load_fn(self, dep_node)
8989
}
9090
}
9191

compiler/rustc_query_system/src/query/job.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ pub fn print_query_stack<Qcx: QueryContext>(
626626
file,
627627
"#{} [{}] {}",
628628
count_total,
629-
qcx.dep_context().dep_kind_info(query_info.query.dep_kind).name,
629+
qcx.dep_context().dep_kind_vtable(query_info.query.dep_kind).name,
630630
query_info.query.description
631631
);
632632
}

0 commit comments

Comments
 (0)