Repository navigation
Beta ICE: ItemLocalIds not assigned densely #56128
Description
Activity
probably a backport of whatever is causing #55475
- addedI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️regression-from-stable-to-betaPerformance or correctness regression from stable to beta.Performance or correctness regression from stable to beta.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
on Nov 21, 2018 It's funny how
Keep resolved defs in path prefixesis exactly what I was doing in the rust-analyzer's PR that triggered the issue 😆Building the beta locally, I get this error, which is a slightly different message
thread 'main' panicked at 'librustc/hir/map/collector.rs:219: inconsistent DepNode for `PathSegment(PathSegment { ident: super#0, id: Some(NodeId(28192)), def: Some(Err), args: None, infer_types: false })`: current_dep_node_owner=::grammar[0]::expressions[0]::{{?}}[2] (DefIndex(0:1648)), hir_id.owner=::grammar[0]::expressions[0]::{{?}}[1] (DefIndex(0:1647))', librustc/util/bug.rs:47:26(Though it seems to be related to the same root problem)
(Ah, this check is only done when
debug_assertionsare enabled.)Minimized reproduction:
mod bar { pub(super) use self::baz::{x, y}; // ^^^^^ assert has to do with this path // // the other thing you need is the `{x, y}` part, which I think causes this to expand into // two copies of the same `pub use` internally mod baz { pub fn x() { } pub fn y() { } } } fn main() { }
OK I see the bug I think
My theory wasn't quite right. Clearly it has something to do with sharing ids. You can see that in some paths, we clone the ids from the visibility kind:
rust/src/librustc/hir/lowering.rs
Lines 3023 to 3028 in 4b3a1d9
let mut path = path.clone(); for seg in path.segments.iter_mut() { if seg.id.is_some() { seg.id = Some(this.next_id().node_id); } } But in others, we do not:
rust/src/librustc/hir/lowering.rs
Lines 3111 to 3118 in 4b3a1d9
hir::VisibilityKind::Restricted { ref path, id: _, hir_id: _ } => { let id = this.next_id(); hir::VisibilityKind::Restricted { path: path.clone(), id: id.node_id, hir_id: id.hir_id, } } However, just adding clone operations to both paths didn't quite suffice.
Oh, actually, it sort of did. It solves my immediate ICE, but now I am getting another ICE, and this one matches the original message ("not dense").
I think the problem is that we are cloning the restricted paths that are getting duplicated and then never using the original, un-cloned paths.
OK, so, I have a fix but there is one part I do not understand. In particular, I have to remove this line:
rust/src/librustc/hir/lowering.rs
Line 3142 in 4b3a1d9
*vis = respan(prefix.span.shrink_to_lo(), hir::VisibilityKind::Inherited); which seems to have been there since @pietroalbini originally added this code. But from what I can tell it is this line that makes the ICE, because the "original" visibility never winds up in the tree anywhere (we always clone it for all the derived HIR paths).
I'll open my PR and cc the relevant folks.
@pietroalbini and I have been conversing on Zulip, log here.
Pending fix in #56143
- added a commit that references this issue
on Nov 22, 2018
Hi! I am seeing an ICE in rust-analyzer, when updating rustc from
rustc 1.31.0-beta.14torustc 1.31.0-beta.15(so, seems pretty bad?).Error message:
Details
Steps to reproduce: