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

For async closures, cap closure kind, get rid of by_mut_body #120717

Merged
merged 3 commits into from
Mar 20, 2024

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Feb 6, 2024

Right now we have three AsyncFn* traits, and three corresponding futures that are returned by the call_* functions for them. This is fine, but it is a bit excessive, since the future returned by AsyncFn and AsyncFnMut are identical. Really, the only distinction we need to make with these bodies is "by ref" and "by move".

This PR removes AsyncFn::CallFuture and renames AsyncFnMut::CallMutFuture to AsyncFnMut::CallRefFuture. This simplifies MIR building for async closures, since we don't need to build an extra "by mut" body, but just a "by move" body which is materially different.

We need to do a bit of delicate handling of the ClosureKind for async closures, since we need to "cap" it to AsyncFnMut in some cases when we only care about what body we're looking for.

This also fixes a bug where <{async closure} as Fn>::call was returning a body that takes the async-closure receiver by move.

This also helps align the AsyncFn traits to the LendingFn traits' eventual designs.

@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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Feb 6, 2024
@rustbot
Copy link
Collaborator

rustbot commented Feb 6, 2024

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@compiler-errors compiler-errors marked this pull request as draft February 6, 2024 18:59
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Feb 10, 2024

☔ The latest upstream changes (presumably #120712) made this pull request unmergeable. Please resolve the merge conflicts.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Feb 21, 2024

☔ The latest upstream changes (presumably #121356) made this pull request unmergeable. Please resolve the merge conflicts.

@bors
Copy link
Contributor

bors commented Feb 29, 2024

☔ The latest upstream changes (presumably #121800) made this pull request unmergeable. Please resolve the merge conflicts.

@compiler-errors compiler-errors marked this pull request as ready for review March 2, 2024 19:48
@compiler-errors
Copy link
Member Author

compiler-errors commented Mar 2, 2024

r? oli-obk

This is almost certainly not commented enough; please let me know where I should go into more detail.

Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

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

idk if it's a good time to start documenting how async closures work in the unstable-book, but may be good to have a single central thing to link to

tests/mir-opt/async_closure_shims.rs Show resolved Hide resolved
compiler/rustc_middle/src/ty/sty.rs Show resolved Hide resolved
compiler/rustc_mir_transform/src/shim.rs Show resolved Hide resolved
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 4, 2024
@bors
Copy link
Contributor

bors commented Mar 9, 2024

☔ The latest upstream changes (presumably #122241) made this pull request unmergeable. Please resolve the merge conflicts.

@compiler-errors compiler-errors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 19, 2024
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@compiler-errors compiler-errors changed the title [WIP] For async closures, cap closure kind, get rid of by_mut_body For async closures, cap closure kind, get rid of by_mut_body Mar 19, 2024
@oli-obk
Copy link
Contributor

oli-obk commented Mar 20, 2024

@bors r+

@bors
Copy link
Contributor

bors commented Mar 20, 2024

📌 Commit 541858e 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 Mar 20, 2024
@bors
Copy link
Contributor

bors commented Mar 20, 2024

⌛ Testing commit 541858e with merge c86f3ac...

@bors
Copy link
Contributor

bors commented Mar 20, 2024

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing c86f3ac to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 20, 2024
@bors bors merged commit c86f3ac into rust-lang:master Mar 20, 2024
12 checks passed
@rustbot rustbot added this to the 1.79.0 milestone Mar 20, 2024
@bors bors mentioned this pull request Mar 20, 2024
16 tasks
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (c86f3ac): comparison URL.

Overall result: ❌✅ regressions and improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.2% [0.1%, 4.3%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.2% [-0.2%, -0.2%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
3.7% [3.7%, 3.7%] 1
Regressions ❌
(secondary)
6.1% [6.1%, 6.1%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.7% [3.7%, 3.7%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 670.215s -> 668.111s (-0.31%)
Artifact size: 312.79 MiB -> 312.74 MiB (-0.02%)

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 25, 2024
…losure, r=bjorn3

Add `async-closures/once.rs` back to cranelift tests

This was fixed afaict by rust-lang#120717

r? `@bjorn3`
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 25, 2024
Rollup merge of rust-lang#123022 - compiler-errors:clif-tests-async-closure, r=bjorn3

Add `async-closures/once.rs` back to cranelift tests

This was fixed afaict by rust-lang#120717

r? `@bjorn3`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants