You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Drop elaboration emits O(N^2) cleanup for partially-initialized aggregate literals #157463
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-codegenArea: Code generationA-mir-optArea: MIR optimizationsC-bugCategory: This is a bug.I-compiletimeIssue: Problems and improvements with respect to compile times.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
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:
Where it originates: MIR drop elaboration emits an O(N²) cleanup ladder, before LLVM runs.
Counting basic blocks / drop terminators / cleanup blocks in the optimized MIR of build() (rustc 1.94.1 -O --emit=mir):
N
variant
bbs
drops
cleanup bbs
16
baseline (interleaved ?)
321
254
269
16
bind-then-build
82
30
31
32
baseline
1153
1022
1053
32
bind-then-build
162
62
63
64
baseline
4353
4094
4157
64
bind-then-build
322
126
127
For the interleaved-divergence aggregate literal, MIR drop terminators and cleanup blocks are ≈ N² (4094 ≈ 64² at N=64); the bind-then-build form is ≈ 2N. Each construction point gets its own cleanup chain that drops the suffix of already-initialized elements, so the partially-initialized aggregate produces a quadratic cleanup ladder at the MIR level — already present before any LLVM pass runs. The ~O(N³) wall-clock is then the function-opt pipeline (InstCombine/CorrelatedValuePropagation/JumpThreading) running super-linearly on top of that O(N²) CFG.
So this looks like it's rooted in drop elaboration for partially-initialized aggregate literals, with LLVM's super-linearity compounding it. python3 mir_count.py in the repro repo reproduces the counts.
changed the title [-]Super-linear (~cubic) `-O` compile time building an N-element aggregate literal whose initializers can diverge[/-][+]Drop elaboration emits `O(N²)` cleanup for partially-initialized aggregate literals → super-linear `-O` compile time[/+]on Jun 5, 2026
For the last few months we have been receiving an increased amount of LLM generated contributions. Your issue is generated (even if possibly with you in the loop), without a human written concise preamble. This makes it very hard to find the actual information in it.
We are a community of contributors, not just a code repository. We focus on contributors who desire to stay around and put in the work to produce high quality contributions or learn to do so.
We are thus warning you as per our policies (1) and contribution standards (2) to stop generating PRs and comments.
@ashi009: It's my sense that you put in real effort on this. I appreciate that. As you noticed, we're building on this work in #157491. In your place, I'd probably be frustrated.
The reasons why the Rust Project needs to close this issue and issues like it are complicated and are not a judgment on your effort or on you as a person.
The offer that @oli-obk made to join us on Zulip is real. We want you to participate in the Rust Project, and we want to help you do that. Please consider joining us.
For what it's worth, I intended to use LLM to connect the dots in an issue report to make it cheaper for maintainers to act on. I take the point that the issue reads LLM-generated (with all the headers and tables), and I'd happily have rewritten it by hand if asked.
changed the title [-]Drop elaboration emits `O(N²)` cleanup for partially-initialized aggregate literals → super-linear `-O` compile time[/-][+]`evaluate_obligation` re-derives region-independent `Send`/`Sync` once per impl when a `where Self: 'a` bound is in scope [/+]on Jun 9, 2026
changed the title [-]`evaluate_obligation` re-derives region-independent `Send`/`Sync` once per impl when a `where Self: 'a` bound is in scope [/-][+]Drop elaboration emits `O(N²)` cleanup for partially-initialized aggregate literals → super-linear `-O` compile time[/+]on Jun 9, 2026
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-codegenArea: Code generationA-mir-optArea: MIR optimizationsC-bugCategory: This is a bug.I-compiletimeIssue: Problems and improvements with respect to compile times.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
Activity
ashi009 commentedon Jun 5, 2026
Where it originates: MIR drop elaboration emits an
O(N²)cleanup ladder, before LLVM runs.Counting basic blocks /
dropterminators / cleanup blocks in the optimized MIR ofbuild()(rustc 1.94.1 -O --emit=mir):drops?)For the interleaved-divergence aggregate literal, MIR
dropterminators and cleanup blocks are ≈ N² (4094 ≈ 64² at N=64); the bind-then-build form is ≈ 2N. Each construction point gets its own cleanup chain that drops the suffix of already-initialized elements, so the partially-initialized aggregate produces a quadratic cleanup ladder at the MIR level — already present before any LLVM pass runs. The ~O(N³)wall-clock is then the function-opt pipeline (InstCombine/CorrelatedValuePropagation/JumpThreading) running super-linearly on top of thatO(N²)CFG.So this looks like it's rooted in drop elaboration for partially-initialized aggregate literals, with LLVM's super-linearity compounding it.
python3 mir_count.pyin the repro repo reproduces the counts.[-]Super-linear (~cubic) `-O` compile time building an N-element aggregate literal whose initializers can diverge[/-][+]Drop elaboration emits `O(N²)` cleanup for partially-initialized aggregate literals → super-linear `-O` compile time[/+]oli-obk commentedon Jun 9, 2026
Hi,
For the last few months we have been receiving an increased amount of LLM generated contributions. Your issue is generated (even if possibly with you in the loop), without a human written concise preamble. This makes it very hard to find the actual information in it.
We are a community of contributors, not just a code repository. We focus on contributors who desire to stay around and put in the work to produce high quality contributions or learn to do so.
We are thus warning you as per our policies (1) and contribution standards (2) to stop generating PRs and comments.
To make sure you can learn how to contribute, we invite you to join https://rust-lang.zulipchat.com/join/rlfvpemsaacs3pfi6kwqnqjb/ and start a thread asking for a mentor.
Thanks for understanding
Oli in the name of the mod team
ashi009 commentedon Jun 9, 2026
oh great, ignoring real bug, and no wonder rust has soo many bugs.
traviscross commentedon Jun 9, 2026
@ashi009: It's my sense that you put in real effort on this. I appreciate that. As you noticed, we're building on this work in #157491. In your place, I'd probably be frustrated.
The reasons why the Rust Project needs to close this issue and issues like it are complicated and are not a judgment on your effort or on you as a person.
The offer that @oli-obk made to join us on Zulip is real. We want you to participate in the Rust Project, and we want to help you do that. Please consider joining us.
ashi009 commentedon Jun 9, 2026
@traviscross Thanks, and I'm glad to see #157491 builds on it.
For what it's worth, I intended to use LLM to connect the dots in an issue report to make it cheaper for maintainers to act on. I take the point that the issue reads LLM-generated (with all the headers and tables), and I'd happily have rewritten it by hand if asked.
traviscross commentedon Jun 9, 2026
Could you? That'd be valuable, I think, for us to see here. With that resolved, we'll be able to reopen this.
Keeping it short and focusing on the reproduction is probably best.
[-]Drop elaboration emits `O(N²)` cleanup for partially-initialized aggregate literals → super-linear `-O` compile time[/-][+]`evaluate_obligation` re-derives region-independent `Send`/`Sync` once per impl when a `where Self: 'a` bound is in scope [/+][-]`evaluate_obligation` re-derives region-independent `Send`/`Sync` once per impl when a `where Self: 'a` bound is in scope [/-][+]Drop elaboration emits `O(N²)` cleanup for partially-initialized aggregate literals → super-linear `-O` compile time[/+]lnicola commentedon Jun 9, 2026
I think the repro README should just link to the issue and say:
(the comments on top of the files have the wrong file name)
ashi009 commentedon Jun 9, 2026
@traviscross updated. PTAL.
@lnicola indeed, that's how I would put it if I were reporting it manually.
[-]Drop elaboration emits `O(N²)` cleanup for partially-initialized aggregate literals → super-linear `-O` compile time[/-][+]Drop elaboration emits `O(N^2)` cleanup for partially-initialized aggregate literals[/+]traviscross commentedon Jun 9, 2026
Thanks @ashi009.
lnicola commentedon Jun 9, 2026
For the sake of FOSS maintainers, please report issues manually from now on.
Auto merge of #157491 - cjgillot:elaborate-drop-chain, r=saethlin
Auto merge of #157491 - cjgillot:elaborate-drop-chain, r=saethlin
Auto merge of #157491 - cjgillot:elaborate-drop-chain, r=saethlin
Auto merge of #157491 - cjgillot:elaborate-drop-chain, r=saethlin