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

Remove need for ResumeTy / get_context in async generators #104828

Closed
Swatinem opened this issue Nov 24, 2022 · 0 comments · Fixed by #105250
Closed

Remove need for ResumeTy / get_context in async generators #104828

Swatinem opened this issue Nov 24, 2022 · 0 comments · Fixed by #105250

Comments

@Swatinem
Copy link
Contributor

#104321 changed async blocks/functions to not go through from_generator / GenFuture, but made those generators implement Future directly.

Though inside those special generators, it is still necessary to hide the &Context<'_> poll argument behind an unsafe ResumeTy wrapper which removes any lifetime constraints.

It should be possible to remove that type, and the unsafe get_context function which turns it back into a &Context<'_> to poll child futures.

With #104321 the compiler already "cheats" and magically turns the &Context<'_> of the Future::poll call into an internal Generator::resume(ResumeTy).

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 5, 2022
Replace usage of `ResumeTy` in async lowering with `Context`

Replaces using `ResumeTy` / `get_context` in favor of using `&'static mut Context<'_>`.

Usage of the `'static` lifetime here is technically "cheating", and replaces the raw pointer in `ResumeTy` and the `get_context` fn that pulls the correct lifetimes out of thin air.

fixes rust-lang#104828 and rust-lang#104321 (comment)

r? `@oli-obk`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 5, 2022
Replace usage of `ResumeTy` in async lowering with `Context`

Replaces using `ResumeTy` / `get_context` in favor of using `&'static mut Context<'_>`.

Usage of the `'static` lifetime here is technically "cheating", and replaces the raw pointer in `ResumeTy` and the `get_context` fn that pulls the correct lifetimes out of thin air.

fixes rust-lang#104828 and rust-lang#104321 (comment)

r? ``@oli-obk``
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 5, 2022
Replace usage of `ResumeTy` in async lowering with `Context`

Replaces using `ResumeTy` / `get_context` in favor of using `&'static mut Context<'_>`.

Usage of the `'static` lifetime here is technically "cheating", and replaces the raw pointer in `ResumeTy` and the `get_context` fn that pulls the correct lifetimes out of thin air.

fixes rust-lang#104828 and rust-lang#104321 (comment)

r? ```@oli-obk```
@bors bors closed this as completed in 967085e Dec 6, 2022
thomcc pushed a commit to tcdi/postgrestd that referenced this issue Feb 10, 2023
Replace usage of `ResumeTy` in async lowering with `Context`

Replaces using `ResumeTy` / `get_context` in favor of using `&'static mut Context<'_>`.

Usage of the `'static` lifetime here is technically "cheating", and replaces the raw pointer in `ResumeTy` and the `get_context` fn that pulls the correct lifetimes out of thin air.

fixes rust-lang/rust#104828 and rust-lang/rust#104321 (comment)

r? `@oli-obk`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant