Skip to content

rustc exhausts all memory on a trivially wrong program (seems to be fixed on nightly?) #122314

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

Closed
Kimundi opened this issue Mar 10, 2024 · 1 comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Kimundi
Copy link
Member

Kimundi commented Mar 10, 2024

I found a case where apparently, trying to construct a struct the wrong way leads to the compiler very quickly exhausting all memory.

I observed it to take up 10G mem +10G of swap in a few seconds on my system.

The issue seems to be fixed on nightly, but I was unsure if I should still open a ticket about it.

Code

This scenario seems to require an external crate, so the minimum reproduction I can manage is a pair of lib.rs and main.rs:

// lib.rs
pub struct QueryCache {}
impl QueryCache {
    pub async fn open() {}
}
// main.rs
use example::QueryCache;
fn main() {
    QueryCache()
}

Alternatively see https://github.com/Kimundi/rustc_bug_2024_quick_oom

To reproduce, run:

cargo build

...and monitor memory consumption.

Meta

rustc --version --verbose:

rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-unknown-linux-gnu
release: 1.76.0
LLVM version: 17.0.6

Error output

I can not reproduce it in the MRE, but sometimes I get this error instead of the endless resource exhaustion:

error[E0391]: cycle detected when getting the resolver for lowering
  |
  = note: ...which requires normalizing `example::QueryCache::open::{opaque#0}`...
  = note: ...which requires looking up limits...
  = note: ...which requires getting the crate HIR...
  = note: ...which again requires getting the resolver for lowering, completing the cycle
  = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information

For more information about this error, try `rustc --explain E0391`.

Fixed on Nightly

The issue seems to be fixed on nightly:

rustc +nightly --version --verbose:

rustc 1.78.0-nightly (2d24fe591 2024-03-09)
binary: rustc
commit-hash: 2d24fe591f30386d6d5fc2bb941c78d7266bf10f
commit-date: 2024-03-09
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0
cargo +nightly build
   Compiling example v0.1.0 (/home/kimundi/projects/ice_repro)
error[E0423]: expected function, tuple struct or tuple variant, found struct `QueryCache`
 --> src/main.rs:4:5
  |
4 |     QueryCache()
  |     ^^^^^^^^^^^^ help: use struct literal syntax instead: `QueryCache {}`
  |
 ::: /home/kimundi/projects/ice_repro/src/lib.rs:1:1
  |
1 | pub struct QueryCache {}
  | --------------------- `QueryCache` defined here

For more information about this error, try `rustc --explain E0423`.
error: could not compile `example` (bin "example") due to 1 previous error
@Kimundi Kimundi added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 10, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 10, 2024
@lukas-code
Copy link
Member

This is a duplicate of #119625 / #122057 and will be fixed in Rust 1.77.

@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 10, 2024
@jieyouxu jieyouxu closed this as not planned Won't fix, can't repro, duplicate, stale Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants