Skip to content

Change type of async context parameter after state transform.#157166

Open
cjgillot wants to merge 2 commits into
rust-lang:mainfrom
cjgillot:retype-context-after
Open

Change type of async context parameter after state transform.#157166
cjgillot wants to merge 2 commits into
rust-lang:mainfrom
cjgillot:retype-context-after

Conversation

@cjgillot
Copy link
Copy Markdown
Contributor

@cjgillot cjgillot commented May 30, 2026

Future::poll expects a &mut std::task::Context<'_>. Meanwhile, async coroutines use std::future::ResumeTy as resume parameter. This is meant to workaround the limitations of borrowck, which cannot prove that coroutines implement for<'a, 'b> CoroutineTrait<&'a mut Context<'b>>.

In the coroutine state transform, we need to change the signature from ResumeTy to the proper &mut Context<'_>. The current code attempts to find locals that have type ResumeTy to change their type. This is needlessly complex and relies on undocumented behaviour of the MIR builder.

Instead, this PR proposes to replace the ResumeTy argument with a new local, with value ResumeTy(transmute(context)).

Based on #156875.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 30, 2026

This PR changes MIR

cc @oli-obk, @RalfJung, @JakobDegen, @vakaras

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 30, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 30, 2026

r? @tiif

rustbot has assigned @tiif.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 17 candidates

@rust-log-analyzer

This comment has been minimized.

@cjgillot cjgillot force-pushed the retype-context-after branch from 8447533 to 8c16d8a Compare May 30, 2026 17:54
@rust-log-analyzer

This comment has been minimized.

@cjgillot cjgillot force-pushed the retype-context-after branch from 8c16d8a to ab5076b Compare May 30, 2026 21:12
@rust-log-analyzer

This comment has been minimized.

@cjgillot cjgillot force-pushed the retype-context-after branch from ab5076b to 769048f Compare May 31, 2026 08:02
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 31, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-log-analyzer

This comment has been minimized.

@cjgillot cjgillot force-pushed the retype-context-after branch from 769048f to 89aaf42 Compare May 31, 2026 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants