Skip to content

Compiler hangs after 'write metadata stage' #37311

Closed
@mglagla

Description

@mglagla

Hello everyone,

while trying to refactor a small toy project (Link), I've hit a bug where the compiler never finishes compiling:

calcium $ cargo rustc -Ztime-passes -Ztime-llvm-passes
   Compiling calcium v0.5.0 (file:///data/Code/calcium)
warning: the option `Z` is unstable and should only be used on the nightly compiler, but it is currently accepted for backwards compatibility; this will soon change, see issue #31847 for more details

time: 0.002; rss: 43MB  parsing
time: 0.000; rss: 43MB  configuration
time: 0.000; rss: 43MB  recursion limit
time: 0.000; rss: 43MB  crate injection
time: 0.000; rss: 43MB  plugin loading
time: 0.000; rss: 43MB  plugin registration
time: 0.038; rss: 82MB  expansion
time: 0.000; rss: 82MB  maybe building test harness
time: 0.001; rss: 82MB  assigning node ids
time: 0.000; rss: 82MB  checking for inline asm in case the target doesn't support it
time: 0.000; rss: 82MB  complete gated feature checking
time: 0.000; rss: 82MB  collecting defs
time: 0.009; rss: 94MB  external crate/lib resolution
time: 0.000; rss: 94MB  early lint checks
time: 0.000; rss: 94MB  AST validation
time: 0.004; rss: 94MB  name resolution
time: 0.001; rss: 94MB  lowering ast -> hir
time: 0.001; rss: 98MB  indexing hir
time: 0.000; rss: 98MB  attribute checking
time: 0.000; rss: 98MB  language item collection
time: 0.000; rss: 98MB  lifetime resolution
time: 0.000; rss: 98MB  looking for entry point
time: 0.000; rss: 98MB  looking for plugin registrar
time: 0.001; rss: 98MB  region resolution
time: 0.000; rss: 98MB  loop checking
time: 0.000; rss: 98MB  static item recursion checking
time: 0.000; rss: 98MB  load_dep_graph
time: 0.008; rss: 98MB  type collecting
time: 0.000; rss: 98MB  variance inference
time: 0.050; rss: 104MB coherence checking
time: 0.012; rss: 104MB wf checking
time: 0.003; rss: 104MB item-types checking
time: 0.112; rss: 106MB item-bodies checking
time: 0.000; rss: 106MB drop-impl checking
time: 0.007; rss: 106MB const checking
time: 0.001; rss: 106MB privacy checking
time: 0.000; rss: 106MB stability index
time: 0.001; rss: 106MB intrinsic checking
time: 0.000; rss: 106MB effect checking
time: 0.002; rss: 106MB match checking
time: 0.001; rss: 106MB liveness checking
time: 0.003; rss: 108MB rvalue checking
time: 0.009; rss: 111MB MIR dump
time: 0.006; rss: 114MB MIR passes
time: 0.009; rss: 114MB borrow checking
time: 0.000; rss: 114MB reachability checking
time: 0.001; rss: 114MB death checking
time: 0.001; rss: 114MB stability checking
time: 0.000; rss: 114MB unused lib feature checking
warning: variant is never used: `MismatchingParens`, #[warn(dead_code)] on by default
  --> src/parse.rs:33:5
   |
33 |     MismatchingParens,
   |     ^^^^^^^^^^^^^^^^^

time: 0.009; rss: 114MB lint checking
time: 0.000; rss: 114MB resolving dependency formats
time: 0.006; rss: 114MB Prepare MIR codegen passes
  time: 0.019; rss: 114MB   write metadata
^C
calcium $ 

I had to stop because even after a minute it did not finish.

This is the offending commit on branch "no-alloc", the previous commit on branch master finished very quickly.

The only difference to master is this code in parse.rs, starting on line 97:

let mut ref_c = 1;
let mut sub_tokens = Vec::new();

while ref_c > 0 {
    let token = if let Some(t) = it.next() {
        t.clone()
    } else { return Err(ParseError::MismatchingParens) };

        match token {
            Token::Operator(Symbol::OpenParen) => {
                ref_c += 1;
            },
            Token::Operator(Symbol::CloseParen) => {
                ref_c -= 1;
            },
            _ => {},
        }

    if ref_c > 0 {
        sub_tokens.push(token);
    }
}

let mut sub_iter = sub_tokens.iter().peekable();
parse_expr(&mut sub_iter, 0)              

has been replaced with this code:

let mut ref_c = 1;
let mut sub_iter = it.filter_map(|t| {
    match *t {
        Token::Operator(Symbol::OpenParen) => {
            ref_c += 1;
        },
        Token::Operator(Symbol::CloseParen) => {
            ref_c -= 1;
        },
        _ => {},
    };

    if ref_c > 0 {
        Some(t)
    } else {
        None
    }
})
.fuse()
.peekable();

parse_expr(&mut sub_iter, 0)

rustc version is 1.12.0 (3191fba 2016-09-23)

Metadata

Metadata

Assignees

Labels

A-type-systemArea: Type systemP-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions