You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the current implementation, gen/async/async gen blocks and closures have type Coroutine(..) and CoroutineClosure(..). Those types implement Iterator, Future or AsyncIterator depending on the initial desugaring.
This creates a lot of complexity:
trait solvers must check which kind of coroutine each time;
MIR StateTransform needs to fixup types depending on the coroutine kind.
I propose to change the desugaring for coroutines to:
gen { .. } becomes CoroutineIterator::from_coroutine(#[coroutine] { .. });
async gen { .. } becomes CoroutineAsyncIterator::from_coroutine(#[coroutine] { .. }).
This way, all coroutines implement std::ops::Coroutine and core is responsible for translating this to user-friendly traits. All the complexity is pushed to error-reporting code, which is not soundness-critical.
Coroutine closures are a little more complex, as we need to keep the CoroutineClosure type for borrow-checking.
Mentors or Reviewers
This involves MIR manipulation and trait solving, so @oli-obk and @lcnr need to know.
Proposal
In the current implementation,
gen/async/async genblocks and closures have typeCoroutine(..)andCoroutineClosure(..). Those types implementIterator,FutureorAsyncIteratordepending on the initial desugaring.This creates a lot of complexity:
I propose to change the desugaring for coroutines to:
gen { .. }becomesCoroutineIterator::from_coroutine(#[coroutine] { .. });async { .. }becomesCoroutineFuture::from_coroutine(#[coroutine] { .. });async gen { .. }becomesCoroutineAsyncIterator::from_coroutine(#[coroutine] { .. }).This way, all coroutines implement
std::ops::Coroutineandcoreis responsible for translating this to user-friendly traits. All the complexity is pushed to error-reporting code, which is not soundness-critical.Coroutine closures are a little more complex, as we need to keep the
CoroutineClosuretype for borrow-checking.Mentors or Reviewers
This involves MIR manipulation and trait solving, so @oli-obk and @lcnr need to know.
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.
Note
Concerns (0 active)
back-to-the-futureresolved in this commentManaged by
@rustbot—see help for details.