Skip to content

Beta ICE: ItemLocalIds not assigned densely  #56128

Description

@matklad

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:

Details
   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

Activity

  1. oli-obk commented on Nov 21, 2018

    @oli-obk
    Contributor

    probably a backport of whatever is causing #55475

  2. added
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Nov 21, 2018
  3. added a commit that references this issue on Nov 21, 2018
  4. petrochenkov commented on Nov 21, 2018

    @petrochenkov
    Contributor

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

  5. matklad commented on Nov 21, 2018

    @matklad
    ContributorAuthor

    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 😆

  6. nikomatsakis commented on Nov 21, 2018

    @nikomatsakis
    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
    
  7. nikomatsakis commented on Nov 21, 2018

    @nikomatsakis
    Contributor

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

  8. nikomatsakis commented on Nov 21, 2018

    @nikomatsakis
    Contributor

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

  9. nikomatsakis commented on Nov 21, 2018

    @nikomatsakis
    Contributor

    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() { }
  10. nikomatsakis commented on Nov 21, 2018

    @nikomatsakis
    Contributor

    OK I see the bug I think

  11. nikomatsakis commented on Nov 21, 2018

    @nikomatsakis
    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.

  12. nikomatsakis commented on Nov 21, 2018

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

  13. nikomatsakis commented on Nov 21, 2018

    @nikomatsakis
    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.

  14. nikomatsakis commented on Nov 21, 2018

    @nikomatsakis
    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).

  15. nikomatsakis commented on Nov 21, 2018

    @nikomatsakis
    Contributor

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

  16. nikomatsakis commented on Nov 21, 2018

    @nikomatsakis
    Contributor

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

  17. nikomatsakis commented on Nov 21, 2018

    @nikomatsakis
    Contributor

    Pending fix in #56143

  18. removed this from the Rust 2018 Release milestone on Nov 22, 2018
  19. added a commit that references this issue on Nov 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions