Proposal
Part of project goal Async statemachine optimisation
I want to add a way for users to optimize statemachines by removing panic paths.
Currently all generated futures will panic when it's poisoned or when it has returned Ready before.
This is good and should remain the default.
However, this has a cost. These branches of the statemachines are never hit in code that is bug free. But LLVM does not know this and can't/won't optimize these panics away. The presence of the panics means LLVM needs to be pessimistic with other optimizations.
Removing the panics and replacing them with simply returning Pending reduces the binary size by about 2% (and up to 5%) on async embedded firmware applications.
I've implemented it here on my fork already: rust-lang/rust@main...diondokter:rust:async-panic
I'm submitting this MCP following the guide here: https://forge.rust-lang.org/compiler/proposals-and-stabilization.html?highlight=unstable%20flag#compiler-flags
Returning Pending is legal I think. The reference doesn't say async blocks or async fns are guaranteed to panic and the Future docs only mention that the behavior is unspecified, but must be 'safe'.
The end goal is getting this flag stabilized as a profile option in cargo. (Possibly with panics off by default in release mode, but that can be discussed then)
Maybe there should be some bikeshedding on the name? Alternatives I can think of:
- coroutine-panic
- async-panics
Or maybe it should be an enum?
- async-poll-after-completion = "panic" / "pending"
Mentors or Reviewers
Review of the PR for the flag can likely be done by @dingxiangfei2009
Process
The main points of the Major Change Process are as follows:
You can read more about Major Change Proposals on forge.
Proposal
Part of project goal Async statemachine optimisation
I want to add a way for users to optimize statemachines by removing panic paths.
Currently all generated futures will panic when it's poisoned or when it has returned
Readybefore.This is good and should remain the default.
However, this has a cost. These branches of the statemachines are never hit in code that is bug free. But LLVM does not know this and can't/won't optimize these panics away. The presence of the panics means LLVM needs to be pessimistic with other optimizations.
Removing the panics and replacing them with simply returning
Pendingreduces the binary size by about 2% (and up to 5%) on async embedded firmware applications.I've implemented it here on my fork already: rust-lang/rust@main...diondokter:rust:async-panic
I'm submitting this MCP following the guide here: https://forge.rust-lang.org/compiler/proposals-and-stabilization.html?highlight=unstable%20flag#compiler-flags
Returning
Pendingis legal I think. The reference doesn't say async blocks or async fns are guaranteed to panic and theFuturedocs only mention that the behavior is unspecified, but must be 'safe'.The end goal is getting this flag stabilized as a profile option in cargo. (Possibly with panics off by default in release mode, but that can be discussed then)
Maybe there should be some bikeshedding on the name? Alternatives I can think of:
Or maybe it should be an enum?
Mentors or Reviewers
Review of the PR for the flag can likely be done by @dingxiangfei2009
Process
The main points of the Major Change Process are as follows:
@rustbot secondor kickoff a team FCP with@rfcbot fcp $RESOLUTION.You can read more about Major Change Proposals on forge.