Skip to content
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

Yield reference in coroutine with GAT #69268

Open
cynecx opened this issue Feb 18, 2020 · 1 comment
Open

Yield reference in coroutine with GAT #69268

cynecx opened this issue Feb 18, 2020 · 1 comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-coroutines Area: Coroutines A-GATs Area: Generic associated types (GATs) C-feature-request Category: A feature request, i.e: not implemented / a PR. F-coroutines `#![feature(coroutines)]` GATs-triaged Issues using the `generic_associated_types` feature that have been triaged T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@cynecx
Copy link
Contributor

cynecx commented Feb 18, 2020

Since #67160 has been merged in December, having a GAT with lifetimes should be possible (See the StreamingIterator example in that PR).

The current trait-defition of a coroutine is the following:

pub trait Coroutine<R = ()> {
    type Yield;
    type Return;
    fn resume(
        self: Pin<&mut Self>, 
        arg: R
    ) -> CoroutineState<Self::Yield, Self::Return>;
}

The issue here is that the Yield can't be parameterized with a lifetime, so yielding a reference from a coroutine is not possible in its current state.

By using a GAT for the Yield AT, it would be possible to return a local reference.

I also don't see why the resume argument type could not have been expressed with a GAT, so at the end we would use the following trait definition for a coroutine:

pub trait Coroutine {
    type Resume<'a>;
    type Yield<'a>;
    type Return;

    fn resume<'a, 'b>(
        self: Pin<&'a mut Self>, 
        arg: Self::Resume<'b>
    ) -> CoroutineState<Self::Yield<'a>, Self::Return>;
}
@jonas-schievink jonas-schievink added A-associated-items Area: Associated items (types, constants & functions) A-coroutines Area: Coroutines C-feature-request Category: A feature request, i.e: not implemented / a PR. F-coroutines `#![feature(coroutines)]` F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Feb 18, 2020
@jackh726
Copy link
Member

GATs issue triage: not blocking. This is a feature use.

@jackh726 jackh726 added the GATs-triaged Issues using the `generic_associated_types` feature that have been triaged label Oct 16, 2021
@oli-obk oli-obk changed the title Yield reference in generator with GAT Yield reference in coroutine with GAT Oct 21, 2023
@fmease fmease added A-GATs Area: Generic associated types (GATs) and removed F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs labels Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-coroutines Area: Coroutines A-GATs Area: Generic associated types (GATs) C-feature-request Category: A feature request, i.e: not implemented / a PR. F-coroutines `#![feature(coroutines)]` GATs-triaged Issues using the `generic_associated_types` feature that have been triaged T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants