Skip to content

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

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
cjgillot:retype-context-after
Jun 10, 2026
Merged

Change type of async context parameter after state transform.#157166
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
cjgillot:retype-context-after

Conversation

@cjgillot

@cjgillot cjgillot commented May 30, 2026

Copy link
Copy Markdown
Contributor

View all comments

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

rustbot commented May 30, 2026

Copy link
Copy Markdown
Collaborator

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

rustbot commented May 30, 2026

Copy link
Copy Markdown
Collaborator

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

This comment has been minimized.

@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
@rust-bors

This comment has been minimized.

@cjgillot cjgillot force-pushed the retype-context-after branch from 89aaf42 to 93879f5 Compare June 1, 2026 21:36
@rustbot

This comment has been minimized.

@rust-bors

This comment has been minimized.

@cjgillot cjgillot force-pushed the retype-context-after branch from 93879f5 to 323effe Compare June 3, 2026 21:40
@rustbot

This comment has been minimized.

@cjgillot cjgillot force-pushed the retype-context-after branch from 323effe to b7e26ac Compare June 4, 2026 12:12
@rustbot

rustbot commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

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.

Comment on lines +612 to +615
/// HIR uses `get_context` to unwrap a `&mut Context<'_>` from a `ResumeTy`.
/// Both types are just a single pointer, but liveness analysis does not know that and
/// supposes that the operand and the destination are live at the same time.
/// Forcibly inline those calls to avoid this.

@oli-obk oli-obk Jun 9, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preexisting, but: it feels a bit funny to generate a function call in ast lowering only to desugar it here manually. The function body is effectively dead code.

View changes since the review

@oli-obk oli-obk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rust-bors

rust-bors Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

📌 Commit b7e26ac has been approved by oli-obk

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 9, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 9, 2026
…li-obk

Change type of async context parameter after state transform.

`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 rust-lang#156875.
rust-bors Bot pushed a commit that referenced this pull request Jun 9, 2026
Rollup of 18 pull requests

Successful merges:

 - #152852 (Remove driver_lint_caps)
 - #157166 (Change type of async context parameter after state transform.)
 - #157335 (bootstrap: Handle dotted table keys when parsing bootstrap.toml)
 - #157503 (Disable `tests/debuginfo/pretty-std.rs` `OsString` cdb check)
 - #157571 (Remove ProcMacro enum from proc macro ABI)
 - #148183 (rustdoc: Test & document `test_harness` code block attribute)
 - #153847 (Fix marker trait winnowing depending on impl order)
 - #156067 (Fix async drop glue for Box<T>)
 - #156399 (fix improper ctypes in Znext solver)
 - #157338 (Make `Literal::byte_character_value` work with bytes as well)
 - #157410 (Implement rustc_public::CrateDef{,Type} for FieldDef)
 - #157605 (Arg splat experiment - syntax impl)
 - #157630 (Add multibyte JSON diagnostic regression test)
 - #157633 (Reorder `impl` restriction rendering and add bottom margin)
 - #157642 (Report duplicate relaxed bounds during ast lowering)
 - #157652 (fix doc for unicode normalization faq on `casefold` APIs)
 - #157661 (Update to ar_archive_writer v0.5.2)
 - #157668 (Add test for matches in `rustc_must_match_exhaustively`)

Failed merges:

 - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
rust-bors Bot pushed a commit that referenced this pull request Jun 9, 2026
Rollup of 17 pull requests

Successful merges:

 - #157166 (Change type of async context parameter after state transform.)
 - #157335 (bootstrap: Handle dotted table keys when parsing bootstrap.toml)
 - #157503 (Disable `tests/debuginfo/pretty-std.rs` `OsString` cdb check)
 - #157571 (Remove ProcMacro enum from proc macro ABI)
 - #148183 (rustdoc: Test & document `test_harness` code block attribute)
 - #153847 (Fix marker trait winnowing depending on impl order)
 - #156067 (Fix async drop glue for Box<T>)
 - #156399 (fix improper ctypes in Znext solver)
 - #157338 (Make `Literal::byte_character_value` work with bytes as well)
 - #157410 (Implement rustc_public::CrateDef{,Type} for FieldDef)
 - #157605 (Arg splat experiment - syntax impl)
 - #157630 (Add multibyte JSON diagnostic regression test)
 - #157633 (Reorder `impl` restriction rendering and add bottom margin)
 - #157642 (Report duplicate relaxed bounds during ast lowering)
 - #157652 (fix doc for unicode normalization faq on `casefold` APIs)
 - #157661 (Update to ar_archive_writer v0.5.2)
 - #157668 (Add test for matches in `rustc_must_match_exhaustively`)

Failed merges:

 - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
@rust-bors

rust-bors Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

⌛ Testing commit b7e26ac with merge 5103141...

Workflow: https://github.com/rust-lang/rust/actions/runs/27238086714

rust-bors Bot pushed a commit that referenced this pull request Jun 9, 2026
Change type of async context parameter after state transform.

`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.
@jhpratt

jhpratt commented Jun 9, 2026

Copy link
Copy Markdown
Member

yielding to a rollup=never PR

@bors yield

@rust-bors

rust-bors Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Auto build was cancelled. Cancelled workflows:

The next pull request likely to be tested is #129543.

rust-bors Bot pushed a commit that referenced this pull request Jun 10, 2026
Rollup of 17 pull requests

Successful merges:

 - #157166 (Change type of async context parameter after state transform.)
 - #157335 (bootstrap: Handle dotted table keys when parsing bootstrap.toml)
 - #157503 (Disable `tests/debuginfo/pretty-std.rs` `OsString` cdb check)
 - #157571 (Remove ProcMacro enum from proc macro ABI)
 - #148183 (rustdoc: Test & document `test_harness` code block attribute)
 - #153847 (Fix marker trait winnowing depending on impl order)
 - #156067 (Fix async drop glue for Box<T>)
 - #156399 (fix improper ctypes in Znext solver)
 - #157338 (Make `Literal::byte_character_value` work with bytes as well)
 - #157410 (Implement rustc_public::CrateDef{,Type} for FieldDef)
 - #157605 (Arg splat experiment - syntax impl)
 - #157630 (Add multibyte JSON diagnostic regression test)
 - #157633 (Reorder `impl` restriction rendering and add bottom margin)
 - #157642 (Report duplicate relaxed bounds during ast lowering)
 - #157652 (fix doc for unicode normalization faq on `casefold` APIs)
 - #157661 (Update to ar_archive_writer v0.5.2)
 - #157668 (Add test for matches in `rustc_must_match_exhaustively`)

Failed merges:

 - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
@rust-bors

rust-bors Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

⌛ Testing commit b7e26ac with merge 39465ed...

Workflow: https://github.com/rust-lang/rust/actions/runs/27248950736

rust-bors Bot pushed a commit that referenced this pull request Jun 10, 2026
Change type of async context parameter after state transform.

`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.
@jhpratt

jhpratt commented Jun 10, 2026

Copy link
Copy Markdown
Member

same thing

@bors yield

@rust-bors

rust-bors Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Auto build was cancelled. Cancelled workflows:

The next pull request likely to be tested is #157683.

rust-bors Bot pushed a commit that referenced this pull request Jun 10, 2026
Rollup of 17 pull requests

Successful merges:

 - #157166 (Change type of async context parameter after state transform.)
 - #157335 (bootstrap: Handle dotted table keys when parsing bootstrap.toml)
 - #157503 (Disable `tests/debuginfo/pretty-std.rs` `OsString` cdb check)
 - #157571 (Remove ProcMacro enum from proc macro ABI)
 - #148183 (rustdoc: Test & document `test_harness` code block attribute)
 - #153847 (Fix marker trait winnowing depending on impl order)
 - #156067 (Fix async drop glue for Box<T>)
 - #156399 (fix improper ctypes in Znext solver)
 - #157338 (Make `Literal::byte_character_value` work with bytes as well)
 - #157410 (Implement rustc_public::CrateDef{,Type} for FieldDef)
 - #157605 (Arg splat experiment - syntax impl)
 - #157630 (Add multibyte JSON diagnostic regression test)
 - #157633 (Reorder `impl` restriction rendering and add bottom margin)
 - #157642 (Report duplicate relaxed bounds during ast lowering)
 - #157652 (fix doc for unicode normalization faq on `casefold` APIs)
 - #157661 (Update to ar_archive_writer v0.5.2)
 - #157668 (Add test for matches in `rustc_must_match_exhaustively`)

Failed merges:

 - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
@rust-bors

rust-bors Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

⌛ Testing commit b7e26ac with merge e1e4985...

Workflow: https://github.com/rust-lang/rust/actions/runs/27249369474

rust-bors Bot pushed a commit that referenced this pull request Jun 10, 2026
Change type of async context parameter after state transform.

`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.
@jhpratt

jhpratt commented Jun 10, 2026

Copy link
Copy Markdown
Member

repeated network failures; I've closed the tree elsewhere

@bors yield

@rust-bors

rust-bors Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Auto build was cancelled. Cancelled workflows:

The next pull request likely to be tested is #157683.

rust-bors Bot pushed a commit that referenced this pull request Jun 10, 2026
Rollup of 17 pull requests

Successful merges:

 - #157166 (Change type of async context parameter after state transform.)
 - #157335 (bootstrap: Handle dotted table keys when parsing bootstrap.toml)
 - #157503 (Disable `tests/debuginfo/pretty-std.rs` `OsString` cdb check)
 - #157571 (Remove ProcMacro enum from proc macro ABI)
 - #148183 (rustdoc: Test & document `test_harness` code block attribute)
 - #153847 (Fix marker trait winnowing depending on impl order)
 - #156067 (Fix async drop glue for Box<T>)
 - #156399 (fix improper ctypes in Znext solver)
 - #157338 (Make `Literal::byte_character_value` work with bytes as well)
 - #157410 (Implement rustc_public::CrateDef{,Type} for FieldDef)
 - #157605 (Arg splat experiment - syntax impl)
 - #157630 (Add multibyte JSON diagnostic regression test)
 - #157633 (Reorder `impl` restriction rendering and add bottom margin)
 - #157642 (Report duplicate relaxed bounds during ast lowering)
 - #157652 (fix doc for unicode normalization faq on `casefold` APIs)
 - #157661 (Update to ar_archive_writer v0.5.2)
 - #157668 (Add test for matches in `rustc_must_match_exhaustively`)

Failed merges:

 - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
rust-bors Bot pushed a commit that referenced this pull request Jun 10, 2026
Rollup of 17 pull requests

Successful merges:

 - #157166 (Change type of async context parameter after state transform.)
 - #157335 (bootstrap: Handle dotted table keys when parsing bootstrap.toml)
 - #157503 (Disable `tests/debuginfo/pretty-std.rs` `OsString` cdb check)
 - #157571 (Remove ProcMacro enum from proc macro ABI)
 - #148183 (rustdoc: Test & document `test_harness` code block attribute)
 - #153847 (Fix marker trait winnowing depending on impl order)
 - #156067 (Fix async drop glue for Box<T>)
 - #156399 (fix improper ctypes in Znext solver)
 - #157338 (Make `Literal::byte_character_value` work with bytes as well)
 - #157410 (Implement rustc_public::CrateDef{,Type} for FieldDef)
 - #157605 (Arg splat experiment - syntax impl)
 - #157630 (Add multibyte JSON diagnostic regression test)
 - #157633 (Reorder `impl` restriction rendering and add bottom margin)
 - #157642 (Report duplicate relaxed bounds during ast lowering)
 - #157652 (fix doc for unicode normalization faq on `casefold` APIs)
 - #157661 (Update to ar_archive_writer v0.5.2)
 - #157668 (Add test for matches in `rustc_must_match_exhaustively`)

Failed merges:

 - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
rust-bors Bot pushed a commit that referenced this pull request Jun 10, 2026
Rollup of 17 pull requests



Successful merges:

 - #157166 (Change type of async context parameter after state transform.)
 - #157335 (bootstrap: Handle dotted table keys when parsing bootstrap.toml)
 - #157503 (Disable `tests/debuginfo/pretty-std.rs` `OsString` cdb check)
 - #157571 (Remove ProcMacro enum from proc macro ABI)
 - #148183 (rustdoc: Test & document `test_harness` code block attribute)
 - #153847 (Fix marker trait winnowing depending on impl order)
 - #156067 (Fix async drop glue for Box<T>)
 - #156399 (fix improper ctypes in Znext solver)
 - #157338 (Make `Literal::byte_character_value` work with bytes as well)
 - #157410 (Implement rustc_public::CrateDef{,Type} for FieldDef)
 - #157605 (Arg splat experiment - syntax impl)
 - #157630 (Add multibyte JSON diagnostic regression test)
 - #157633 (Reorder `impl` restriction rendering and add bottom margin)
 - #157642 (Report duplicate relaxed bounds during ast lowering)
 - #157652 (fix doc for unicode normalization faq on `casefold` APIs)
 - #157661 (Update to ar_archive_writer v0.5.2)
 - #157668 (Add test for matches in `rustc_must_match_exhaustively`)

Failed merges:

 - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
rust-bors Bot pushed a commit that referenced this pull request Jun 10, 2026
Rollup of 17 pull requests



Successful merges:

 - #157166 (Change type of async context parameter after state transform.)
 - #157335 (bootstrap: Handle dotted table keys when parsing bootstrap.toml)
 - #157503 (Disable `tests/debuginfo/pretty-std.rs` `OsString` cdb check)
 - #157571 (Remove ProcMacro enum from proc macro ABI)
 - #148183 (rustdoc: Test & document `test_harness` code block attribute)
 - #153847 (Fix marker trait winnowing depending on impl order)
 - #156067 (Fix async drop glue for Box<T>)
 - #156399 (fix improper ctypes in Znext solver)
 - #157338 (Make `Literal::byte_character_value` work with bytes as well)
 - #157410 (Implement rustc_public::CrateDef{,Type} for FieldDef)
 - #157605 (Arg splat experiment - syntax impl)
 - #157630 (Add multibyte JSON diagnostic regression test)
 - #157633 (Reorder `impl` restriction rendering and add bottom margin)
 - #157642 (Report duplicate relaxed bounds during ast lowering)
 - #157652 (fix doc for unicode normalization faq on `casefold` APIs)
 - #157661 (Update to ar_archive_writer v0.5.2)
 - #157668 (Add test for matches in `rustc_must_match_exhaustively`)

Failed merges:

 - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
rust-bors Bot pushed a commit that referenced this pull request Jun 10, 2026
Rollup of 17 pull requests



Successful merges:

 - #157166 (Change type of async context parameter after state transform.)
 - #157335 (bootstrap: Handle dotted table keys when parsing bootstrap.toml)
 - #157503 (Disable `tests/debuginfo/pretty-std.rs` `OsString` cdb check)
 - #157571 (Remove ProcMacro enum from proc macro ABI)
 - #148183 (rustdoc: Test & document `test_harness` code block attribute)
 - #153847 (Fix marker trait winnowing depending on impl order)
 - #156067 (Fix async drop glue for Box<T>)
 - #156399 (fix improper ctypes in Znext solver)
 - #157338 (Make `Literal::byte_character_value` work with bytes as well)
 - #157410 (Implement rustc_public::CrateDef{,Type} for FieldDef)
 - #157605 (Arg splat experiment - syntax impl)
 - #157630 (Add multibyte JSON diagnostic regression test)
 - #157633 (Reorder `impl` restriction rendering and add bottom margin)
 - #157642 (Report duplicate relaxed bounds during ast lowering)
 - #157652 (fix doc for unicode normalization faq on `casefold` APIs)
 - #157661 (Update to ar_archive_writer v0.5.2)
 - #157668 (Add test for matches in `rustc_must_match_exhaustively`)

Failed merges:

 - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
@rust-bors rust-bors Bot merged commit e295994 into rust-lang:main Jun 10, 2026
12 of 13 checks passed
@rustbot rustbot added this to the 1.98.0 milestone Jun 10, 2026
rust-timer added a commit that referenced this pull request Jun 10, 2026
Rollup merge of #157166 - cjgillot:retype-context-after, r=oli-obk

Change type of async context parameter after state transform.

`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.
@cjgillot cjgillot deleted the retype-context-after branch June 10, 2026 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

6 participants