Repository navigation
[rustc] Recompute required constants for coroutine drop shim - #165972
Draft
jayanth260 wants to merge 1 commit into
Draft
jayanth260 wants to merge 1 commit into
jayanth260 wants to merge 1 commit into
Conversation
Collaborator
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
Collaborator
|
Thanks for the pull request, and welcome! The Rust Project has assigned @mejrs (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks. Please see the contribution instructions and our LLM policy for more information. Why was this reviewer chosen?The reviewer was selected based on:
|
jayanth260
force-pushed
the
fix-coroutine-required-consts
branch
from
November 14, 2026 19:57
89ec53c to
82eeaa1
Compare
Member
|
Hi,
This violates our LLM Policy because LLM-generated tests count as LLM-created code, you need to find an LLM reviewer to review your PR, you can do so in #llm-reviews Zulip channel. I'm going to move this to draft until so. |
Kivooeo
marked this pull request as draft
November 15, 2026 07:10
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #148335
Summary
When generating coroutine drop shims, rustc clones the original coroutine MIR body and transforms it into a new body.
However, cloning the body also copies its
required_constsmetadata. Since the generated drop shim can have a different set of required constants from the original coroutine, this metadata may become stale.The monomorphization collector evaluates all constants listed in
required_consts. As a result, constants required only by the original coroutine can be unnecessarily evaluated again when the generated drop shim is instantiated in a downstream crate. This is particularly noticeable with expensive constants in public async functions used across crate boundaries.Recompute
required_constsafter transforming each generated drop-shim body, so that the metadata reflects the resulting MIR rather than the original coroutine body. This recomputation is applied in all three coroutine drop-shim construction paths.Effect
In the example from #148335, the original compilation produced four warning diagnostics: two in the source crate and two in the downstream crate. However, these corresponded to only two CTFE executions—one in each crate.
With this fix, the constant is evaluated only once, in the source crate. The unnecessary CTFE execution in the downstream crate is eliminated.
LLM Usage: Used Chat-GPT for writing tests.