Skip to content

Commit cb3884a

Browse files
authored
Rollup merge of rust-lang#68289 - pnkfelix:issue-62649-dont-ice-on-path-collision-in-dep-graph, r=michaelwoerister
Don't ICE on path-collision in dep-graph Collisions in the dep-graph due to path-reuse are rare but can occur. So, instead of ICE'ing, just fail to mark green in such cases (for `DepKind::{Hir, HirBody, CrateMetadata}`). Fix rust-lang#62649.
2 parents 3761dcd + 6f4b904 commit cb3884a

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

src/librustc/dep_graph/graph.rs

+30-9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_data_structures::sharded::{self, Sharded};
66
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
77
use rustc_data_structures::sync::{AtomicU32, AtomicU64, Lock, Lrc, Ordering};
88
use rustc_errors::Diagnostic;
9+
use rustc_hir::def_id::DefId;
910
use rustc_index::vec::{Idx, IndexVec};
1011
use smallvec::SmallVec;
1112
use std::collections::hash_map::Entry;
@@ -677,18 +678,33 @@ impl DepGraph {
677678
} else {
678679
match dep_dep_node.kind {
679680
DepKind::Hir | DepKind::HirBody | DepKind::CrateMetadata => {
680-
if dep_dep_node.extract_def_id(tcx).is_none() {
681+
if let Some(def_id) = dep_dep_node.extract_def_id(tcx) {
682+
if def_id_corresponds_to_hir_dep_node(tcx, def_id) {
683+
// The `DefPath` has corresponding node,
684+
// and that node should have been marked
685+
// either red or green in `data.colors`.
686+
bug!(
687+
"DepNode {:?} should have been \
688+
pre-marked as red or green but wasn't.",
689+
dep_dep_node
690+
);
691+
} else {
692+
// This `DefPath` does not have a
693+
// corresponding `DepNode` (e.g. a
694+
// struct field), and the ` DefPath`
695+
// collided with the `DefPath` of a
696+
// proper item that existed in the
697+
// previous compilation session.
698+
//
699+
// Since the given `DefPath` does not
700+
// denote the item that previously
701+
// existed, we just fail to mark green.
702+
return None;
703+
}
704+
} else {
681705
// If the node does not exist anymore, we
682706
// just fail to mark green.
683707
return None;
684-
} else {
685-
// If the node does exist, it should have
686-
// been pre-allocated.
687-
bug!(
688-
"DepNode {:?} should have been \
689-
pre-allocated but wasn't.",
690-
dep_dep_node
691-
)
692708
}
693709
}
694710
_ => {
@@ -899,6 +915,11 @@ impl DepGraph {
899915
}
900916
}
901917

918+
fn def_id_corresponds_to_hir_dep_node(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
919+
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
920+
def_id.index == hir_id.owner
921+
}
922+
902923
/// A "work product" is an intermediate result that we save into the
903924
/// incremental directory for later re-use. The primary example are
904925
/// the object files that we save for each partition at code
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// revisions: rpass1 rpass2
2+
3+
#[cfg(rpass1)]
4+
pub trait Something {
5+
fn foo();
6+
}
7+
8+
#[cfg(rpass2)]
9+
pub struct Something {
10+
pub foo: u8,
11+
}
12+
13+
fn main() {}

0 commit comments

Comments
 (0)