-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Cannot define async fn with no_std #56974
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Marking as not blocking stabilization -- obviously we want things to work from core eventually, but it's ok if that doesn't work to start, and I don't believe there are any major design questions at play here (right @cramertj?) |
Yup-- this is an unfortunate restriction, but I think it's not a blocker for an MVP and resolving it requires some more complex investigation into generator arguments + some special-sauce :) |
Could someone indicate how difficult this would be to tackle as a new Rust contributor? I fear like this might be a bit over my head, but I'd love to know. |
It's not easy. There needs to be a way to pass an argument into the generator resume function which can be accessed by any |
There is a way to implement it today using |
For platforms with ELF TLS support, https://github.com/sunriseos/core-futures-tls solves this issue. It could be trivially modified for single-core platforms without ELF TLS, but multi-core ones would be much more difficult. |
See also https://internals.rust-lang.org/t/pre-rfc-generator-resume-args/10011 for a Pre-RFC for generator resume arguments. |
cc @cavedweller |
Now that |
@birktj This is fully supported in the compiler, however functions used internally by async/await are not implemented in libcore due to requiring TLS. core-futures-tls uses the unstable |
@leo60228 so if I understand correctly, all that is required to use |
The underlying implementation is depending on it being thread local, it just happens to be sufficient on a MCU that you can define a how thread_local works as a Cell. (which is what core-futures-tls does) This is currently at least a little off on being able to run on stable, the TLS dependency needs to be removed from the underlying implementation. This won't change the API hence why async/await was stabilizable, it just happens that |
@birktj that will not be interrupt-safe, polling a |
Triage: Highly relevant for embedded folks, tagging rust-lang/rfcs#2781 proposes generator resume arguments, which would solve this issue once implemented (stabilization is not necessary). |
Actually we shouldn't need an RFC at all for this, generators are experimental anyways |
#68524 removes one of the roadblocks for this by implementing generator resume arguments |
…guments, r=Zoxc Generator Resume Arguments cc rust-lang#43122 and rust-lang#56974 Blockers: * [x] Fix miscompilation when resume argument is live across a yield point (rust-lang#68524 (comment)) * [x] Fix 10% compile time regression in `await-call-tree` benchmarks (rust-lang#68524 (comment)) * [x] Fix remaining 1-3% regression (rust-lang#68524 (comment)) - resolved (rust-lang#68524 (comment)) * [x] Make dropck rules account for resume arguments (rust-lang#68524 (comment)) Follow-up work: * Change async/await desugaring to make use of this feature * Rewrite [`box_region.rs`](https://github.com/rust-lang/rust/blob/3d8778d767f0dde6fe2bc9459f21ead8e124d8cb/src/librustc_data_structures/box_region.rs) to use resume arguments (this shows up in profiles too)
I guess what's left is to update the |
@Arnavion yep, I've started to work on that already. Expect a PR next week. |
Opened #69033 with the final fix for this |
So, [currently][1], `async` fns/closures prevent crates from building in a no_std environment. Since the only occurrence is this single `send` method, I've moved it to the rpc crate. [1]: rust-lang/rust#56974
So, [currently][1], `async` fns/closures prevent crates from building in a no_std environment. Since the only occurrence is this single `send` method, I've moved it to the rpc crate. [1]: rust-lang/rust#56974
So, [currently][1], `async` fns/closures prevent crates from building in a no_std environment. Since the only occurrence is this single `send` method, I've moved it to the rpc crate. [1]: rust-lang/rust#56974
…, r=tmandry Use generator resume arguments in the async/await lowering This removes the TLS requirement from async/await and enables it in `#![no_std]` crates. Closes rust-lang#56974 I'm not confident the HIR lowering is completely correct, there seem to be quite a few undocumented invariants in there. The `async-std` and tokio test suites are passing with these changes though.
(playground) currently fails with
This should also work with whatever the syntax for
await
is, currently it fails earlier than this error because ofawait!
only being defined instd
, see #56767.The text was updated successfully, but these errors were encountered: