rust-lang / rust-lang/rust

Drop elaboration emits `O(N^2)` cleanup for partially-initialized aggregate literals

Open
#157,463 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-codegen A-LLVM A-mir-opt C-bug I-compiletime T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

An aggregate literal of N droppable elements whose initializers can diverge could emit O(N^2) drop terminators. Which chokes LLVM's CVP pass and cost substantial time in optimized build.

For example, the following code will take over 60s to build with -O:

pub fn build(s: u64) -> Result<Big, ()> {
    Ok(Big { f0: make_one(s ^ 0)?, /* … N fields … */ f127: make_one(s ^ 127)? })
}

See https://github.com/ashi009/cvp-llvm-repro for a runnable example.

Reproducible on 1.96.0 stable (LLVM 22.1.2) and 1.98.0-nightly e7815e522 (LLVM 22.1.6).

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 with the runnable example at ashi009/cvp-llvm-repro and reproduce the optimized build using the aggregate literal with diverging initializers. Trace Rust's drop elaboration and generated drop terminators into LLVM's CVP pass; done means the cleanup is no longer quadratic and the reproduced build avoids the reported optimization cost.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.