Skip to content
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

Beta ICE: ItemLocalIds not assigned densely #56128

Closed
matklad opened this issue Nov 21, 2018 · 15 comments · Fixed by #56143
Closed

Beta ICE: ItemLocalIds not assigned densely #56128

matklad opened this issue Nov 21, 2018 · 15 comments · Fixed by #56143
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matklad
Copy link
Member

matklad commented Nov 21, 2018

Hi! I am seeing an ICE in rust-analyzer, when updating rustc from rustc 1.31.0-beta.14 to rustc 1.31.0-beta.15 (so, seems pretty bad?).

Error message:

   Compiling ra_syntax v0.1.0 (/home/matklad/projects/rust-analyzer/crates/ra_syntax)               
thread 'main' panicked at 'librustc/hir/map/hir_id_validator.rs:31:                                 
ItemLocalIds not assigned densely in ::grammar[0]::expressions[0]::{{?}}[1]. Max ItemLocalId = 4, missing IDs = ["[local_id: 1, node:unknown node (id=28193)]", "[local_id: 2, node:path segment super (id=28192)]"]; seens IDs = ["(NodeId(28191) use grammar::expressions::{{?}} (id=28191))", "(NodeId(28195) path segment atom (id=28195))", "(NodeId(28194) path segment self (id=28194))"]
HirIdValidator: The recorded owner of path segment super (id=28192) is ::grammar[0]::expressions[0]::{{?}}[1] instead of ::grammar[0]::expressions[0]::{{?}}[2]
HirIdValidator: Same HirId ::grammar[0]::expressions[0]::{{?}}[2]/2 assigned for nodes path segment super (id=28192) and path segment atom (id=92512)
HirIdValidator: The recorded owner of path segment super (id=28192) is ::grammar[0]::expressions[0]::{{?}}[1] instead of ::grammar[0]::expressions[0]::{{?}}[3]
HirIdValidator: Same HirId ::grammar[0]::expressions[0]::{{?}}[3]/2 assigned for nodes path segment super (id=28192) and path segment atom (id=92515)', librustc/util/bug.rs:47:26
note: Run with `RUST_BACKTRACE=1` for a backtrace.                                                  
                                                                                                    
error: internal compiler error: unexpected panic                                                    
                                                                                                    
note: the compiler unexpectedly panicked. this is a bug.                                            
                                                                                                    
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
                                                                                                    
note: rustc 1.31.0-beta.15 (4b3a1d911 2018-11-20) running on x86_64-unknown-linux-gnu               
                                                                                                    
note: compiler flags: -C debuginfo=2 -C incremental --crate-type lib                                
                                                                                                    
note: some of the compiler flags provided by cargo are hidden                                       
                                                                                                    
error: Could not compile `ra_syntax`.                                                               
warning: build failed, waiting for other jobs to finish...
thread 'main' panicked at 'librustc/hir/map/hir_id_validator.rs:31:                                 
ItemLocalIds not assigned densely in ::grammar[0]::expressions[0]::{{?}}[1]. Max ItemLocalId = 4, missing IDs = ["[local_id: 1, node:unknown node (id=28200)]", "[local_id: 2, node:path segment super (id=28199)]"]; seens IDs = ["(NodeId(28198) use grammar::expressions::{{?}} (id=28198))", "(NodeId(28202) path segment atom (id=28202))", "(NodeId(28201) path segment self (id=28201))"]
HirIdValidator: The recorded owner of path segment super (id=28199) is ::grammar[0]::expressions[0]::{{?}}[1] instead of ::grammar[0]::expressions[0]::{{?}}[2]
HirIdValidator: Same HirId ::grammar[0]::expressions[0]::{{?}}[2]/2 assigned for nodes path segment super (id=28199) and path segment atom (id=104341)
HirIdValidator: The recorded owner of path segment super (id=28199) is ::grammar[0]::expressions[0]::{{?}}[1] instead of ::grammar[0]::expressions[0]::{{?}}[3]
HirIdValidator: Same HirId ::grammar[0]::expressions[0]::{{?}}[3]/2 assigned for nodes path segment super (id=28199) and path segment atom (id=104344)', librustc/util/bug.rs:47:26
note: Run with `RUST_BACKTRACE=1` for a backtrace.                                                  
                                                                                                    
error: internal compiler error: unexpected panic                                                    
                                                                                                    
note: the compiler unexpectedly panicked. this is a bug.                                            
                                                                                                    
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
                                                                                                    
note: rustc 1.31.0-beta.15 (4b3a1d911 2018-11-20) running on x86_64-unknown-linux-gnu               
                                                                                                    
note: compiler flags: -C debuginfo=2 -C incremental                                                 
                                                                                                    
note: some of the compiler flags provided by cargo are hidden  

Steps to reproduce:

$ git clone git@github.com:rust-analyzer/rust-analyzer.git
$ cd rust-analyzer
$ git reset --hard 049f8df93cca05af395ce873738dc85d5a25f3fc
$ cargo test
@oli-obk
Copy link
Contributor

oli-obk commented Nov 21, 2018

probably a backport of whatever is causing #55475

@oli-obk oli-obk added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 21, 2018
matklad added a commit to rust-lang/rust-analyzer that referenced this issue Nov 21, 2018
@petrochenkov
Copy link
Contributor

ping @nrc
This is a regression from #54145 that's now in beta.

@matklad
Copy link
Member Author

matklad commented Nov 21, 2018

It's funny how Keep resolved defs in path prefixes is exactly what I was doing in the rust-analyzer's PR that triggered the issue 😆

@nikomatsakis
Copy link
Contributor

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

@nikomatsakis
Copy link
Contributor

(Though it seems to be related to the same root problem)

@nikomatsakis
Copy link
Contributor

(Ah, this check is only done when debug_assertions are enabled.)

@alexcrichton alexcrichton added this to the Rust 2018 Release milestone Nov 21, 2018
@nikomatsakis
Copy link
Contributor

nikomatsakis commented Nov 21, 2018

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() { }

@nikomatsakis
Copy link
Contributor

OK I see the bug I think

@nikomatsakis
Copy link
Contributor

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:

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:

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.

@nikomatsakis
Copy link
Contributor

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").

@nikomatsakis
Copy link
Contributor

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.

@nikomatsakis
Copy link
Contributor

OK, so, I have a fix but there is one part I do not understand. In particular, I have to remove this line:

*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).

@nikomatsakis
Copy link
Contributor

I'll open my PR and cc the relevant folks.

@nikomatsakis
Copy link
Contributor

@pietroalbini and I have been conversing on Zulip, log here.

@nikomatsakis
Copy link
Contributor

Pending fix in #56143

@petrochenkov petrochenkov removed this from the Rust 2018 Release milestone Nov 22, 2018
@nagisa nagisa added the P-high High priority label Nov 22, 2018
bors added a commit that referenced this issue Nov 22, 2018
…y, r=petrochenkov

Issue 56128 segment id ice nightly

Tentative fix for #56128

From what I can tell, the problem is that if you have `pub(super) use foo::{a, b}`, then when we explode the `a` and `b`, the segment ids from the `super` path were not getting cloned. However, once I fixed *that*, then I ran into a problem that the "visibility" node-ids were not present in the final HIR -- this is because the visibility of the "stem" that is returned in this case was getting reset to inherited. I don't *think* it is a problem to undo that, so that the visibility is returned unmodified.

Fixes #55475
Fixes #56128

cc @nrc @petrochenkov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants