-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't ICE on path-collision in dep-graph #68289
Don't ICE on path-collision in dep-graph #68289
Conversation
r? @cramertj (rust_highfive has picked a reviewer for you, use r? to override) |
its possible you had some more targeted fix in mind, e.g. trying to tease out what particular edge in the dep-graph construction this was arising from. In case you want to know more, this gist has a dot-file with the curr and prev dep-graphs that caused this bug to arise: https://gist.github.com/pnkfelix/7e0d820945fbde43011e2690b96cf312 |
Thanks for the PR, @pnkfelix! I'll try to get a closer look next week. |
I'm not sure this is a valid fix. IIRC, it's an invariant of the system that we mark all HIR nodes with colors before the query system kicks in. A def-path being re-used should not really change that. I'll try to dig a little deeper. |
@pnkfelix Do you have a small reproduction for the issue somewhere? |
D'oh! ... regression test ... |
Hm, now I understand what's going on: In revision 1 So a more targeted fix would be something like: if let Some(def_id) = dep_dep_node.extract_def_id(tcx) {
if is_something_that_corresponds_to_a_dep_node(def_id) {
// If the node does exist, it should have
// been marked as either red or green
bug!(
"DepNode {:?} should have been \
pre-marked as red or green but wasn't.",
dep_dep_node
)
} else {
// This is something that has a valid DefPath
// but does not have a corresponding `DepNode`,
// e.g. a struct field. This branch is hit if
// a proper item with the given DefPath existed
// in the previous compilation session.
return None;
}
} else {
// If the node does not exist anymore, we
// just fail to mark green.
return None;
} The tricky part is coming up with a solid implementation for |
Here is an option for implementing the above check: fn def_id_corresponds_to_hir_dep_node(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
let hir_id = tcx.hir.as_local_hir_id(def_id).unwrap();
match tcx.hir.get(hir_id) {
Node::Item(_) |
Node::TraitItem(_) |
Node::ImplItem(_) |
Node::Crate => true,
Node::Param(_) |
Node::ForeignItem(_) |
Node::Variant(_) |
Node::Field(_) |
Node::AnonConst(_|
Node::Expr(_) |
Node::Stmt(_) |
Node::PathSegment(_) |
Node::Ty(_) |
Node::TraitRef(_) |
Node::Binding(_) |
Node::Pat(_) |
Node::Arm(_) |
Node::Block(_) |
Node::Local(_) |
Node::MacroDef(_) |
Node::Ctor(_) |
Node::Lifetime(_|
Node::GenericParam(_) |
Node::Visibility(_) => false
}
} Hopefully the whole notion of pre-allocating HIR dep-nodes will go away at some point. |
Here's an improved, less brittle option: fn def_id_corresponds_to_hir_dep_node(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
let hir_id = tcx.hir.as_local_hir_id(def_id).unwrap();
def_id.index == hir_id.owner
} |
@michaelwoerister I'll look into using your revised approach |
So, instead of ICE'ing, just fail to mark green in such cases (for `DepKind::{Hir, HirBody, CrateMetadata}`). Fix rust-lang#62649.
128843d
to
6f4b904
Compare
@michaelwoerister okay I've incorporated your proposal into this version. |
📌 Commit 6f4b904 has been approved by |
…th-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.
Rollup of 8 pull requests Successful merges: - #68289 (Don't ICE on path-collision in dep-graph) - #68378 (Add BTreeMap::remove_entry) - #68553 (Fix run button positionning in case of scrolling) - #68556 (rustdoc: Fix re-exporting primitive types) - #68582 (Add E0727 long explanation) - #68592 (fix: typo in vec.rs) - #68619 (Fix a few spelling mistakes) - #68620 (Update links to WASI docs in time.rs module) Failed merges: r? @ghost
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 #62649.