rust-lang / rust-lang/rust

Rust compiler hangs when pretty-printing MIR for a constant

Open
#132,122 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-const-eval A-MIR C-bug I-hang T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

// compiler-flags: --emit mir
fn main() {
    let _dummy = [(); usize::MAX];
}

I expected to see this happen: Compilation should succeed and generate a MIR file

Instead, this happened: Compiler hangs

Meta

rustc --version --verbose:

rustc 1.82.0 (f6e511eec 2024-10-15)
binary: rustc
commit-hash: f6e511eec7342f59a25f7c0534f1dbea00d01b14
commit-date: 2024-10-15
host: x86_64-unknown-linux-gnu
release: 1.82.0
LLVM version: 19.1.1
I tried the same example in the playground, and it reported that the program was killed.

 Compiling playground v0.0.1 (/playground)
error: could not compile `playground` (bin "playground")

Caused by:
  process didn't exit successfully: `/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc --crate-name playground --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --emit mir=compilation --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=78b40b1b4b7fab71 -C extra-filename=-78b40b1b4b7fab71 --out-dir /playground/target/debug/deps -L dependency=/playground/target/debug/deps -L native=/playground/target/debug/build/libsqlite3-sys-6cf5b51c5e7b32e1/out -L native=/playground/target/debug/build/ring-5cfcc6da0313868c/out -L native=/playground/.cargo/registry/src/index.crates.io-6f17d22bba15001f/windows_x86_64_msvc-0.52.6/lib` (signal: 9, SIGKILL: kill)

FYI, the same issue happens in StableMIR pretty print. I believe the compiler is hanging inside rustc_middle::mir::pretty::pretty_print_const_value.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the reported Rust example with --emit mir and then inspect rustc_middle::mir::pretty::pretty_print_const_value, where the issue reports the hang occurs. Check the same path for StableMIR pretty printing. Done means the reproducer terminates successfully and generates its MIR output without hanging or being killed.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.