Skip to content

Fix for async drop inside async gen fn #141932

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

Merged

Conversation

azhogin
Copy link
Contributor

@azhogin azhogin commented Jun 2, 2025

Return value (for yield) is corrected for async drop inside async gen function.
In CFG, when internal async drop future is polled and returned Poll<()>::Pending, then async gen resume function returns Poll<(OptRet)>::Pending.

Fixes #140530

@rustbot
Copy link
Collaborator

rustbot commented Jun 2, 2025

r? @BoxyUwU

rustbot has assigned @BoxyUwU.
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

@rustbot
Copy link
Collaborator

rustbot commented Jun 2, 2025

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 Jun 2, 2025
@azhogin
Copy link
Contributor Author

azhogin commented Jun 2, 2025

r? oli-obk

@rust-log-analyzer

This comment has been minimized.

@azhogin azhogin force-pushed the azhogin/async-drop-inside-asyncgen-fix branch from 8e0c3d0 to 8e20c56 Compare June 2, 2025 21:08
Comment on lines 327 to 328
// yield (const false) is used for async drop yields inside AsyncGen
// We need to convert value to Poll<OptRet>::Pending
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we directly generate the right yield in the async drop logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TerminatorKind::Yield value is Operand, but we need Rvalue::Aggregate (make_aggregate_adt).

As far as I understand, we can do Operand with an additional local variable.
So, instead of 'return Poll::Pending;', the generated code will be 'x = Poll::Pending; return x;'

Value for Yield is generated here:

let value = Operand::Constant(Box::new(ConstOperand {
.

Does it cost additional temporary local?

Copy link
Contributor

Choose a reason for hiding this comment

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

We can generate a const operand directly for a value of Poll::Pending(()), so that would not be the issue.

@azhogin azhogin force-pushed the azhogin/async-drop-inside-asyncgen-fix branch from 8e20c56 to d5a9a00 Compare June 4, 2025 11:45
@oli-obk
Copy link
Contributor

oli-obk commented Jun 4, 2025

Oh heh that works, nice

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jun 4, 2025

📌 Commit d5a9a00 has been approved by oli-obk

It is now in the queue for this repository.

@bors bors 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 4, 2025
bors added a commit that referenced this pull request Jun 5, 2025
Rollup of 11 pull requests

Successful merges:

 - #141890 (Add link to correct documentation in htmldocck.py)
 - #141932 (Fix for async drop inside async gen fn)
 - #141960 (Use non-2015 edition paths in tests that do not test for their resolution)
 - #141968 (Run wfcheck in one big loop instead of per module)
 - #141969 (Triagebot: Remove `assign.users_on_vacation`)
 - #141985 (Ensure query keys are printed with reduced queries)
 - #141999 (Visit the ident in `PreciseCapturingNonLifetimeArg`.)
 - #142005 (Change `tag_field` to `FieldIdx` in `Variants::Multiple`)
 - #142017 (Fix incorrect use of "recommend" over "recommended")
 - #142024 (Don't refer to 'this tail expression' in expansion.)
 - #142025 (Don't refer to 'local binding' in extern macro.)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 9ec41bc into rust-lang:master Jun 5, 2025
10 checks passed
@rustbot rustbot added this to the 1.89.0 milestone Jun 5, 2025
rust-timer added a commit that referenced this pull request Jun 5, 2025
Rollup merge of #141932 - azhogin:azhogin/async-drop-inside-asyncgen-fix, r=oli-obk

Fix for async drop inside async gen fn

Return value (for yield) is corrected for async drop inside async gen function.
In CFG, when internal async drop future is polled and returned `Poll<()>::Pending`, then async gen resume function returns `Poll<(OptRet)>::Pending`.

Fixes #140530
@petrochenkov petrochenkov added the F-async_drop `#![feature(async_drop)]` label Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-async_drop `#![feature(async_drop)]` 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
7 participants