Skip to content
/ rust Public
forked from rust-lang/rust

Commit 68fd771

Browse files
committed
Pass in dep kind names to the duplicate dep node check
1 parent f5dc674 commit 68fd771

File tree

7 files changed

+38
-10
lines changed

7 files changed

+38
-10
lines changed

compiler/rustc_incremental/src/persist/load.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ fn delete_dirty_work_product(sess: &Session, swp: SerializedWorkProduct) {
9191
work_product::delete_workproduct_files(sess, &swp.work_product);
9292
}
9393

94-
fn load_dep_graph(sess: &Session) -> LoadResult<(Arc<SerializedDepGraph>, WorkProductMap)> {
94+
fn load_dep_graph(
95+
sess: &Session,
96+
deps: &DepsType,
97+
) -> LoadResult<(Arc<SerializedDepGraph>, WorkProductMap)> {
9598
let prof = sess.prof.clone();
9699

97100
if sess.opts.incremental.is_none() {
@@ -171,7 +174,7 @@ fn load_dep_graph(sess: &Session) -> LoadResult<(Arc<SerializedDepGraph>, WorkPr
171174
return LoadResult::DataOutOfDate;
172175
}
173176

174-
let dep_graph = SerializedDepGraph::decode::<DepsType>(&mut decoder);
177+
let dep_graph = SerializedDepGraph::decode::<DepsType>(&mut decoder, deps);
175178

176179
LoadResult::Ok { data: (dep_graph, prev_work_products) }
177180
}
@@ -205,11 +208,11 @@ pub fn load_query_result_cache(sess: &Session) -> Option<OnDiskCache> {
205208

206209
/// Setups the dependency graph by loading an existing graph from disk and set up streaming of a
207210
/// new graph to an incremental session directory.
208-
pub fn setup_dep_graph(sess: &Session, crate_name: Symbol) -> DepGraph {
211+
pub fn setup_dep_graph(sess: &Session, crate_name: Symbol, deps: &DepsType) -> DepGraph {
209212
// `load_dep_graph` can only be called after `prepare_session_directory`.
210213
prepare_session_directory(sess, crate_name);
211214

212-
let res = sess.opts.build_dep_graph().then(|| load_dep_graph(sess));
215+
let res = sess.opts.build_dep_graph().then(|| load_dep_graph(sess, deps));
213216

214217
if sess.opts.incremental.is_some() {
215218
sess.time("incr_comp_garbage_collect_session_directories", || {

compiler/rustc_interface/src/passes.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rustc_incremental::setup_dep_graph;
1919
use rustc_lint::{BufferedEarlyLint, EarlyCheckNode, LintStore, unerased_lint_store};
2020
use rustc_metadata::creader::CStore;
2121
use rustc_middle::arena::Arena;
22+
use rustc_middle::dep_graph::DepsType;
2223
use rustc_middle::ty::{self, CurrentGcx, GlobalCtxt, RegisteredTools, TyCtxt};
2324
use rustc_middle::util::Providers;
2425
use rustc_parse::{
@@ -774,7 +775,9 @@ pub fn create_and_enter_global_ctxt<T, F: for<'tcx> FnOnce(TyCtxt<'tcx>) -> T>(
774775
sess.cfg_version,
775776
);
776777
let outputs = util::build_output_filenames(&pre_configured_attrs, sess);
777-
let dep_graph = setup_dep_graph(sess, crate_name);
778+
779+
let dep_type = DepsType { dep_names: rustc_query_impl::dep_kind_names() };
780+
let dep_graph = setup_dep_graph(sess, crate_name, &dep_type);
778781

779782
let cstore =
780783
FreezeLock::new(Box::new(CStore::new(compiler.codegen_backend.metadata_loader())) as _);

compiler/rustc_middle/src/dep_graph/dep_node.rs

+9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ macro_rules! define_dep_nodes {
2121
($mod:ident) => {[ $($mod::$variant()),* ]};
2222
}
2323

24+
#[macro_export]
25+
macro_rules! make_dep_kind_name_array {
26+
($mod:ident) => {
27+
vec! {
28+
$(*$mod::$variant().name),*
29+
}
30+
};
31+
}
32+
2433
/// This enum serves as an index into arrays built by `make_dep_kind_array`.
2534
// This enum has more than u8::MAX variants so we need some kind of multi-byte
2635
// encoding. The derived Encodable/Decodable uses leb128 encoding which is

compiler/rustc_middle/src/dep_graph/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ pub type DepGraph = rustc_query_system::dep_graph::DepGraph<DepsType>;
2020
pub type DepKindStruct<'tcx> = rustc_query_system::dep_graph::DepKindStruct<TyCtxt<'tcx>>;
2121

2222
#[derive(Clone)]
23-
pub struct DepsType;
23+
pub struct DepsType {
24+
pub dep_names: Vec<&'static str>,
25+
}
2426

2527
impl Deps for DepsType {
2628
fn with_deps<OP, R>(task_deps: TaskDepsRef<'_>, op: OP) -> R
@@ -44,6 +46,10 @@ impl Deps for DepsType {
4446
})
4547
}
4648

49+
fn name(&self, dep_kind: DepKind) -> &'static str {
50+
self.dep_names[dep_kind.as_usize()]
51+
}
52+
4753
const DEP_KIND_NULL: DepKind = dep_kinds::Null;
4854
const DEP_KIND_RED: DepKind = dep_kinds::Red;
4955
const DEP_KIND_SIDE_EFFECT: DepKind = dep_kinds::SideEffect;

compiler/rustc_query_impl/src/plumbing.rs

+4
Original file line numberDiff line numberDiff line change
@@ -863,5 +863,9 @@ macro_rules! define_queries {
863863
pub fn query_callbacks<'tcx>(arena: &'tcx Arena<'tcx>) -> &'tcx [DepKindStruct<'tcx>] {
864864
arena.alloc_from_iter(rustc_middle::make_dep_kind_array!(query_callbacks))
865865
}
866+
867+
pub fn dep_kind_names() -> Vec<&'static str> {
868+
rustc_middle::make_dep_kind_name_array!(query_callbacks)
869+
}
866870
}
867871
}

compiler/rustc_query_system/src/dep_graph/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ pub trait Deps {
100100
where
101101
OP: for<'a> FnOnce(TaskDepsRef<'a>);
102102

103+
fn name(&self, dep_kind: DepKind) -> &'static str;
104+
103105
/// We use this for most things when incr. comp. is turned off.
104106
const DEP_KIND_NULL: DepKind;
105107

@@ -154,7 +156,7 @@ pub enum FingerprintStyle {
154156

155157
impl FingerprintStyle {
156158
#[inline]
157-
pub fn reconstructible(self) -> bool {
159+
pub const fn reconstructible(self) -> bool {
158160
match self {
159161
FingerprintStyle::DefPathHash | FingerprintStyle::Unit | FingerprintStyle::HirId => {
160162
true

compiler/rustc_query_system/src/dep_graph/serialized.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ fn mask(bits: usize) -> usize {
179179
}
180180

181181
impl SerializedDepGraph {
182-
#[instrument(level = "debug", skip(d))]
183-
pub fn decode<D: Deps>(d: &mut MemDecoder<'_>) -> Arc<SerializedDepGraph> {
182+
#[instrument(level = "debug", skip(d, deps))]
183+
pub fn decode<D: Deps>(d: &mut MemDecoder<'_>, deps: &D) -> Arc<SerializedDepGraph> {
184184
// The last 16 bytes are the node count and edge count.
185185
debug!("position: {:?}", d.position());
186186
let (node_count, edge_count) =
@@ -253,8 +253,9 @@ impl SerializedDepGraph {
253253

254254
for (idx, node) in nodes.iter_enumerated() {
255255
if index[node.kind.as_usize()].insert(node.hash, idx).is_some() {
256+
let name = deps.name(node.kind);
256257
panic!(
257-
"Error: A dep graph node does not have an unique index. \
258+
"Error: A dep graph node ({name}) does not have an unique index. \
258259
Running a clean build on a nightly compiler with `-Z incremental-verify-ich` \
259260
can help narrow down the issue for reporting. A clean build may also work around the issue.\n
260261
DepNode: {node:?}"

0 commit comments

Comments
 (0)