-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
A MIR pass simplifying trivial enum uses, and other temporary locals #138739
Conversation
r? @fee1-dead rustbot has assigned @fee1-dead. Use |
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
This comment has been minimized.
This comment has been minimized.
r? mir-opt |
That is a bit odd - the PR builds and passes all tests locally. I guess this assertion is only enabled in debug builds - I'll see if I can reproduce & fix the build faliure. |
This comment has been minimized.
This comment has been minimized.
Some changes occurred in src/tools/cargo cc @ehuss |
The job Click to see the possible cause of the failure (guessed by this bot)
|
I am closing this PR, since the build failures look like a miscompilation. I'll see if I can make a fully sound version of this PR. |
Motivation
Fixes:#138544
Currently, MIR optimizations are unable to remove(due to pass ordering) simple option uses in loops:
This pass removes such temporary enums(and a few other uneded temporaries).
It works by walking statements one by one, collecting rvalues assigned directly to locals.
Then, knowing what rvalue is assigned to what local, it replaces places in the following statements, like this:
Ensuring soundness
This pass has several deliberate limitations. It will not:
Still, despite those limitations, the pass is able to simplify most if not all simple uses of enums(and clean up some temporaries).
This pass is designed to be extendable, and I have a few ideas for simplifying other pieces of MIR using it.Still, I decided to make a PR for this simpler, easier to review version of this pass, and extend the pass later.