-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Fix Async Generator ABI #105082
Fix Async Generator ABI #105082
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
|
Can you give a suggestion how to specifically test for the ABI here?
async blocks / fns always went through
I started looking at #104828, searching for all the places that use |
…piler-errors Make sure async constructs do not `impl Generator` Async lowering turns async functions and blocks into generators internally. Though these special kinds of generators should not `impl Generator` themselves. The other way around, normal generators should not `impl Future`. This was discovered in rust-lang#105082 (comment) and is a regression from rust-lang#104321. r? `@compiler-errors`
Make sure async constructs do not `impl Generator` Async lowering turns async functions and blocks into generators internally. Though these special kinds of generators should not `impl Generator` themselves. The other way around, normal generators should not `impl Future`. This was discovered in rust-lang/rust#105082 (comment) and is a regression from rust-lang/rust#104321. r? `@compiler-errors`
Friendly ping. This is blocking a rustup for cg_clif. |
I think this is blocked on figuring out a good way to regression test against this in the future. I would happily do that as a followup though to unblock With #104828 / #105250 I contiously took advantage that the compiler was very lenient and did not verify these things too strictly. This bug here was rather by accident. Ideally both should be covered by tests that avoid similar things in the future. |
I'm hoping to integrate cg_clif's test suite with rust's CI soonish, which should catch any regressions. A regular test would indeed be nice though. Would a MIR dump after the generator transformation for the generator of an async function that uses |
That might indeed be an option, I will experiment with that tomorrow. |
The MIR type is not the problem here, and it should be coming through correctly from the generator transform: rust/compiler/rustc_mir_transform/src/generator.rs Lines 1301 to 1314 in 7632db0
The problem is rather that
I don’t see the |
Hm, is |
Also, what is clif doing differently? Is it checking full type equality? Or does it just do layout for |
I don’t think we are hitting For clif, I believe it is doing full type equality, but @bjorn3 can answer that better I’m sure. |
This change was missed when making async generators implement `Future` directly. It did not cause any problems in codegen so far, as `GeneratorState<(), Output>` happens to have the same ABI as `Poll<Output>`.
Rebased and added a comment. |
Yeah, cg_clif is checking full type equality. It has catched a lot of bugs while working on cg_clif itself. However even when relaxing the check to allow Poll/GeneratorState mismatches I still get a crash as the generated MIR attempts to write to field 0 of the return value which is an i32 for one type and () for the other type. |
@bors r+ |
…iaskrgr Rollup of 10 pull requests Successful merges: - rust-lang#98391 (Reimplement std's thread parker on top of events on SGX) - rust-lang#104019 (Compute generator sizes with `-Zprint_type_sizes`) - rust-lang#104512 (Set `download-ci-llvm = "if-available"` by default when `channel = dev`) - rust-lang#104901 (Implement masking in FileType comparison on Unix) - rust-lang#105082 (Fix Async Generator ABI) - rust-lang#105109 (Add LLVM KCFI support to the Rust compiler) - rust-lang#105505 (Don't warn about unused parens when they are used by yeet expr) - rust-lang#105514 (Introduce `Span::is_visible`) - rust-lang#105516 (Update cargo) - rust-lang#105522 (Remove wrong note for short circuiting operators) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
I can confirm that all issues for cg_clif are fixed with this PR. I will update cg_clif once a nightly with this PR is released. |
Just for reference, this did manifest as a crash on Fedora 36 with LLVM 14: So far, backporting this PR does appear to fix that, thanks! |
Do we have any builders with both LLVM 14 and LLVM assertions enabled? If not I think the crash was due to pointer types being mixed up. LLVM 15 uses opaque pointers and as such there is nothing to mixup. |
I added LLVM 14 in #107044, but that's Ubuntu's normal package. I think we only have CI builds with assertions in the bundled LLVM. |
This change was missed when making async generators implement
Future
directly.It did not cause any problems in codegen so far, as
GeneratorState<(), Output>
happens to have the same ABI as
Poll<Output>
.