Add merge yields pass - #162429
Open
diondokter wants to merge 10 commits into
Open
Conversation
Collaborator
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
This comment has been minimized.
This comment has been minimized.
… paths that shouldn't be translated
diondokter
force-pushed
the
collapse_yields
branch
from
September 7, 2026 13:28
920b7ec to
ef8a835
Compare
Collaborator
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
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.
Part of Async statemachine optimisation project goal
r? dingxiangfei2009
Added a pass that merges functionally identical yields right before the async StateTransform pass. The StateTransform pass creates a unique state for every yield, so by merging yields we reduce the amount of states in the state machines.
See the module documentation for more information.
As for how much binary size is saved, that's hard to say in general. There's plenty of code that doesn't have identical yields. But when there is, the savings can be huge. In this project it saves 616 bytes. For a customer, when they applied this pass manually, it saved ~2kb in one instance.
It'll also play nice with the next optimization I'm going to work on, where we optimize async functions with a single await.
I think the biggest risk in the PR are the compare functions for the basic blocks and their parts. That's most of the code in the pass and can break if the basic block structures are updated but this code is forgotten. I don't know how to solve/improve that, so I'm curious if anyone can think of something. The threat is that the compare functions say the blocks are identical, but they're not in reality.
Also, the pass is currently always enabled. I don't know what people want there. Does it need an unstable flag? Or depend on the mir opt level?