Pass in dep kind names to the duplicate dep node check

This commit is contained in:
John Kåre Alsaker 2025-03-18 22:26:44 +01:00
parent f5dc674bf8
commit 68fd771bc1
7 changed files with 38 additions and 10 deletions

View file

@ -91,7 +91,10 @@ fn delete_dirty_work_product(sess: &Session, swp: SerializedWorkProduct) {
work_product::delete_workproduct_files(sess, &swp.work_product);
}
fn load_dep_graph(sess: &Session) -> LoadResult<(Arc<SerializedDepGraph>, WorkProductMap)> {
fn load_dep_graph(
sess: &Session,
deps: &DepsType,
) -> LoadResult<(Arc<SerializedDepGraph>, WorkProductMap)> {
let prof = sess.prof.clone();
if sess.opts.incremental.is_none() {
@ -171,7 +174,7 @@ fn load_dep_graph(sess: &Session) -> LoadResult<(Arc<SerializedDepGraph>, WorkPr
return LoadResult::DataOutOfDate;
}
let dep_graph = SerializedDepGraph::decode::<DepsType>(&mut decoder);
let dep_graph = SerializedDepGraph::decode::<DepsType>(&mut decoder, deps);
LoadResult::Ok { data: (dep_graph, prev_work_products) }
}
@ -205,11 +208,11 @@ pub fn load_query_result_cache(sess: &Session) -> Option<OnDiskCache> {
/// Setups the dependency graph by loading an existing graph from disk and set up streaming of a
/// new graph to an incremental session directory.
pub fn setup_dep_graph(sess: &Session, crate_name: Symbol) -> DepGraph {
pub fn setup_dep_graph(sess: &Session, crate_name: Symbol, deps: &DepsType) -> DepGraph {
// `load_dep_graph` can only be called after `prepare_session_directory`.
prepare_session_directory(sess, crate_name);
let res = sess.opts.build_dep_graph().then(|| load_dep_graph(sess));
let res = sess.opts.build_dep_graph().then(|| load_dep_graph(sess, deps));
if sess.opts.incremental.is_some() {
sess.time("incr_comp_garbage_collect_session_directories", || {

View file

@ -19,6 +19,7 @@ use rustc_incremental::setup_dep_graph;
use rustc_lint::{BufferedEarlyLint, EarlyCheckNode, LintStore, unerased_lint_store};
use rustc_metadata::creader::CStore;
use rustc_middle::arena::Arena;
use rustc_middle::dep_graph::DepsType;
use rustc_middle::ty::{self, CurrentGcx, GlobalCtxt, RegisteredTools, TyCtxt};
use rustc_middle::util::Providers;
use rustc_parse::{
@ -774,7 +775,9 @@ pub fn create_and_enter_global_ctxt<T, F: for<'tcx> FnOnce(TyCtxt<'tcx>) -> T>(
sess.cfg_version,
);
let outputs = util::build_output_filenames(&pre_configured_attrs, sess);
let dep_graph = setup_dep_graph(sess, crate_name);
let dep_type = DepsType { dep_names: rustc_query_impl::dep_kind_names() };
let dep_graph = setup_dep_graph(sess, crate_name, &dep_type);
let cstore =
FreezeLock::new(Box::new(CStore::new(compiler.codegen_backend.metadata_loader())) as _);

View file

@ -21,6 +21,15 @@ macro_rules! define_dep_nodes {
($mod:ident) => {[ $($mod::$variant()),* ]};
}
#[macro_export]
macro_rules! make_dep_kind_name_array {
($mod:ident) => {
vec! {
$(*$mod::$variant().name),*
}
};
}
/// This enum serves as an index into arrays built by `make_dep_kind_array`.
// This enum has more than u8::MAX variants so we need some kind of multi-byte
// encoding. The derived Encodable/Decodable uses leb128 encoding which is

View file

@ -20,7 +20,9 @@ pub type DepGraph = rustc_query_system::dep_graph::DepGraph<DepsType>;
pub type DepKindStruct<'tcx> = rustc_query_system::dep_graph::DepKindStruct<TyCtxt<'tcx>>;
#[derive(Clone)]
pub struct DepsType;
pub struct DepsType {
pub dep_names: Vec<&'static str>,
}
impl Deps for DepsType {
fn with_deps<OP, R>(task_deps: TaskDepsRef<'_>, op: OP) -> R
@ -44,6 +46,10 @@ impl Deps for DepsType {
})
}
fn name(&self, dep_kind: DepKind) -> &'static str {
self.dep_names[dep_kind.as_usize()]
}
const DEP_KIND_NULL: DepKind = dep_kinds::Null;
const DEP_KIND_RED: DepKind = dep_kinds::Red;
const DEP_KIND_SIDE_EFFECT: DepKind = dep_kinds::SideEffect;

View file

@ -863,5 +863,9 @@ macro_rules! define_queries {
pub fn query_callbacks<'tcx>(arena: &'tcx Arena<'tcx>) -> &'tcx [DepKindStruct<'tcx>] {
arena.alloc_from_iter(rustc_middle::make_dep_kind_array!(query_callbacks))
}
pub fn dep_kind_names() -> Vec<&'static str> {
rustc_middle::make_dep_kind_name_array!(query_callbacks)
}
}
}

View file

@ -100,6 +100,8 @@ pub trait Deps {
where
OP: for<'a> FnOnce(TaskDepsRef<'a>);
fn name(&self, dep_kind: DepKind) -> &'static str;
/// We use this for most things when incr. comp. is turned off.
const DEP_KIND_NULL: DepKind;
@ -154,7 +156,7 @@ pub enum FingerprintStyle {
impl FingerprintStyle {
#[inline]
pub fn reconstructible(self) -> bool {
pub const fn reconstructible(self) -> bool {
match self {
FingerprintStyle::DefPathHash | FingerprintStyle::Unit | FingerprintStyle::HirId => {
true

View file

@ -179,8 +179,8 @@ fn mask(bits: usize) -> usize {
}
impl SerializedDepGraph {
#[instrument(level = "debug", skip(d))]
pub fn decode<D: Deps>(d: &mut MemDecoder<'_>) -> Arc<SerializedDepGraph> {
#[instrument(level = "debug", skip(d, deps))]
pub fn decode<D: Deps>(d: &mut MemDecoder<'_>, deps: &D) -> Arc<SerializedDepGraph> {
// The last 16 bytes are the node count and edge count.
debug!("position: {:?}", d.position());
let (node_count, edge_count) =
@ -253,8 +253,9 @@ impl SerializedDepGraph {
for (idx, node) in nodes.iter_enumerated() {
if index[node.kind.as_usize()].insert(node.hash, idx).is_some() {
let name = deps.name(node.kind);
panic!(
"Error: A dep graph node does not have an unique index. \
"Error: A dep graph node ({name}) does not have an unique index. \
Running a clean build on a nightly compiler with `-Z incremental-verify-ich` \
can help narrow down the issue for reporting. A clean build may also work around the issue.\n
DepNode: {node:?}"