Transform async ResumeTy in generator transform#105977
Conversation
|
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
|
I'm probably not the best person to review mir-opt work. r? @rust-lang/wg-mir-opt |
|
☔ The latest upstream changes (presumably #105741) made this pull request unmergeable. Please resolve the merge conflicts. |
959d552 to
238bd05
Compare
Uhh that's a bug I'm pretty sure? I shouldn't be given any reviews (cc @oli-obk). r? @rust-lang/wg-mir-opt |
explicit team assignments will pick anyone from that team, even if they are not on the automatic rotation |
|
r? @rust-lang/wg-mir-opt |
238bd05 to
332a0fc
Compare
There was a problem hiding this comment.
I wonder if we could register this as a special mir opt so we can see its diff in a mir opt test. Seems like a lot of work though, and out of scope for this PR
There was a problem hiding this comment.
That would be interesting, but not sure if its worth it.
I consider this PR just a temporary workaround that I would love to revert as soon as the compiler can handle &mut Context<'_> in generators directly.
332a0fc to
1db48e2
Compare
|
@bors r+ |
Transform async `ResumeTy` in generator transform - Eliminates all the `get_context` calls that async lowering created. - Replace all `Local` `ResumeTy` types with `&mut Context<'_>`. The `Local`s that have their types replaced are: - The `resume` argument itself. - The argument to `get_context`. - The yielded value of a `yield`. The `ResumeTy` hides a `&mut Context<'_>` behind an unsafe raw pointer, and the `get_context` function is being used to convert that back to a `&mut Context<'_>`. Ideally the async lowering would not use the `ResumeTy`/`get_context` indirection, but rather directly use `&mut Context<'_>`, however that would currently lead to higher-kinded lifetime errors. See <rust-lang#105501>. The async lowering step and the type / lifetime inference / checking are still using the `ResumeTy` indirection for the time being, and that indirection is removed here. After this transform, the generator body only knows about `&mut Context<'_>`. --- Fixes https://github.com/bjorn3/rustc_codegen_cranelift/issues/1330 CC `@bjorn3` r? `@compiler-errors`
- Eliminates all the `get_context` calls that async lowering created. - Replace all `Local` `ResumeTy` types with `&mut Context<'_>`. The `Local`s that have their types replaced are: - The `resume` argument itself. - The argument to `get_context`. - The yielded value of a `yield`. The `ResumeTy` hides a `&mut Context<'_>` behind an unsafe raw pointer, and the `get_context` function is being used to convert that back to a `&mut Context<'_>`. Ideally the async lowering would not use the `ResumeTy`/`get_context` indirection, but rather directly use `&mut Context<'_>`, however that would currently lead to higher-kinded lifetime errors. See <rust-lang#105501>. The async lowering step and the type / lifetime inference / checking are still using the `ResumeTy` indirection for the time being, and that indirection is removed here. After this transform, the generator body only knows about `&mut Context<'_>`.
1db48e2 to
96931a7
Compare
|
Rebased, and added |
|
@bors r+ |
…llaumeGomez Rollup of 5 pull requests Successful merges: - rust-lang#105977 (Transform async `ResumeTy` in generator transform) - rust-lang#106927 (make `CastError::NeedsDeref` create a `MachineApplicable` suggestion) - rust-lang#106931 (document + UI test `E0208` and make its output more user-friendly) - rust-lang#107027 (Remove extra removal from test path) - rust-lang#107037 (Fix Dominators::rank_partial_cmp to match documentation) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
|
Updated cg_clif in bjorn3/rustc_codegen_cranelift@6c58be8. Works perfect! |
to overcome an issue with async generators. Updated the codegen_generator to follow the new logic implemented in rust-lang/rust#105977
This changes from the stdlib supported `ResumeTy`, and converting that to a `&mut Context<'_>` to directly use `&mut Context<'_>` in lowering. It pretty much reverts rust-lang#105977 and re-applies an updated version of rust-lang#105250. The PR is currently failing as it depends on `-Zdrop-tracking-mir` becoming the default, so that the compiler does not falsly believe the context is being held across await points,which would make async blocks `!Send` and `!UnwindSafe`. However it also still fails the testcase added in rust-lang#106264 for reasons I don’t understand.
Upgrade our toolchain to `nightly-2023-01-23`. The changes here are related to the following changes: - rust-lang/rust#104986 - rust-lang/rust#105657 - rust-lang/rust#105603 - rust-lang/rust#105613 - rust-lang/rust#105977 - rust-lang/rust#104645
Instead of using the stdlib supported `ResumeTy`, which is being converting to a `&mut Context<'_>` during the Generator MIR pass, this will use `&mut Context<'_>` directly in HIR lowering. It pretty much reverts rust-lang#105977 and re-applies an updated version of rust-lang#105250. This still fails the testcase added in rust-lang#106264 however, for reasons I don’t understand.
Instead of using the stdlib supported `ResumeTy`, which is being converting to a `&mut Context<'_>` during the Generator MIR pass, this will use `&mut Context<'_>` directly in HIR lowering. It pretty much reverts rust-lang#105977 and re-applies an updated version of rust-lang#105250. This still fails the testcase added in rust-lang#106264 however, for reasons I don’t understand.
Instead of using the stdlib supported `ResumeTy`, which is being converting to a `&mut Context<'_>` during the Generator MIR pass, this will use `&mut Context<'_>` directly in HIR lowering. It pretty much reverts rust-lang#105977 and re-applies an updated version of rust-lang#105250. This still fails the testcase added in rust-lang#106264 however, for reasons I don’t understand.
Instead of using the stdlib supported `ResumeTy`, which is being converting to a `&mut Context<'_>` during the Generator MIR pass, this will use `&mut Context<'_>` directly in HIR lowering. It pretty much reverts rust-lang#105977 and re-applies an updated version of rust-lang#105250. This still fails the testcase added in rust-lang#106264 however, for reasons I don’t understand.
Instead of using the stdlib supported `ResumeTy`, which is being converting to a `&mut Context<'_>` during the Generator MIR pass, this will use `&mut Context<'_>` directly in HIR lowering. It pretty much reverts rust-lang#105977 and re-applies an updated version of rust-lang#105250. This still fails the testcase added in rust-lang#106264 however, for reasons I don’t understand.
Instead of using the stdlib supported `ResumeTy`, which is being converting to a `&mut Context<'_>` during the Generator MIR pass, this will use `&mut Context<'_>` directly in HIR lowering. It pretty much reverts rust-lang#105977 and re-applies an updated version of rust-lang#105250. This still fails the testcase added in rust-lang#106264 however, for reasons I don’t understand.
Instead of using the stdlib supported `ResumeTy`, which is being converting to a `&mut Context<'_>` during the Generator MIR pass, this will use `&mut Context<'_>` directly in HIR lowering. It pretty much reverts rust-lang#105977 and re-applies an updated version of rust-lang#105250. This still fails the testcase added in rust-lang#106264 however, for reasons I don’t understand.
Instead of using the stdlib supported `ResumeTy`, which is being converting to a `&mut Context<'_>` during the Generator MIR pass, this will use `&mut Context<'_>` directly in HIR lowering. It pretty much reverts rust-lang#105977 and re-applies an updated version of rust-lang#105250. This still fails the testcase added in rust-lang#106264 however, for reasons I don’t understand.
Instead of using the stdlib supported `ResumeTy`, which is being converting to a `&mut Context<'_>` during the Generator MIR pass, this will use `&mut Context<'_>` directly in HIR lowering. It pretty much reverts rust-lang#105977 and re-applies an updated version of rust-lang#105250. This still fails the testcase added in rust-lang#106264 however, for reasons I don’t understand.
get_contextcalls that async lowering created.LocalResumeTytypes with&mut Context<'_>.The
Locals that have their types replaced are:resumeargument itself.get_context.yield.The
ResumeTyhides a&mut Context<'_>behind an unsafe raw pointer, and theget_contextfunction is being used to convert that back to a&mut Context<'_>.Ideally the async lowering would not use the
ResumeTy/get_contextindirection, but rather directly use&mut Context<'_>, however that would currently lead to higher-kinded lifetime errors.See #105501.
The async lowering step and the type / lifetime inference / checking are still using the
ResumeTyindirection for the time being, and that indirection is removed here. After this transform, the generator body only knows about&mut Context<'_>.Fixes https://github.com/bjorn3/rustc_codegen_cranelift/issues/1330 CC @bjorn3
r? @compiler-errors