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

Require explicitly marking closures as coroutines #123792

Merged
merged 2 commits into from Apr 24, 2024

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Apr 11, 2024

instead of relying on patching up the closure to be a coroutine if it happens to contain a yield expression.

I only do this in the 2024 edition, as the gen keyword is only available there.

@rustbot

This comment was marked as resolved.

@rustbot rustbot added PG-exploit-mitigations Project group: Exploit mitigations 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 Apr 11, 2024
@rustbot
Copy link
Collaborator

rustbot commented Apr 11, 2024

Some changes occurred in tests/ui/sanitizer

cc @rust-lang/project-exploit-mitigations, @rcvalle

@oli-obk
Copy link
Contributor Author

oli-obk commented Apr 11, 2024

r? @compiler-errors

self.with_new_scopes(ident.span, |this| {
self.with_new_scopes(span, |this| {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to do this change as otherwise the span points to the identifier of functions instead of the fn, so adding gen would have resulted in fn gen foo instead of gen fn foo.

Comment on lines 1525 to 1536
if this.token.uninterpolated_span().at_least_rust_2024()
// check for `gen {}` and `gen move {}`
// or `async gen {}` and `async gen move {}`
&& (this.is_gen_block(kw::Gen, 0)
|| (this.check_keyword(kw::Async) && this.is_gen_block(kw::Gen, 1)))
{
// FIXME: (async) gen closures aren't yet parsed.
this.parse_gen_block()
} else if this.check_keyword(kw::Async) {
if this.check_keyword(kw::Async) {
// FIXME(gen_blocks): Parse `gen async` and suggest swap
if this.is_gen_block(kw::Async, 0) {
if this.is_gen_block(kw::Async, 0) || this.is_gen_block(kw::Gen, 1) {
// Check for `async {` and `async move {`,
this.parse_gen_block()
} else {
this.parse_expr_closure()
}
} else if this.check_keyword(kw::Gen)
&& this.token.uninterpolated_span().at_least_rust_2024()
{
if this.is_gen_block(kw::Gen, 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This deserves further cleanup, but I think it's already an improvement if all the async stuff always goes through the kw::Async arm.

Also we can now gate the edition check on the keyword check, yay

@rustbot
Copy link
Collaborator

rustbot commented Apr 11, 2024

Some changes occurred in tests/ui/sanitizer

cc @rust-lang/project-exploit-mitigations, @rcvalle

@compiler-errors
Copy link
Member

compiler-errors commented Apr 11, 2024

Let's not use gen as the keyword for this. That conflicts with gen closures, which we could have as a parallel to async closures, and is confusing given that gen fns and gen blocks also exist.

@compiler-errors
Copy link
Member

Given that full/general coroutines still are not expected to land anytime soon, I'd rather if we don't add syntax for this at all, and just use an attr tbh

@compiler-errors compiler-errors 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 Apr 11, 2024
@rustbot
Copy link
Collaborator

rustbot commented Apr 12, 2024

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

The Miri subtree was changed

cc @rust-lang/miri

Some changes occurred in coverage tests.

cc @Zalathar

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead.

cc @rust-lang/rust-analyzer

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@compiler-errors
Copy link
Member

compiler-errors commented Apr 12, 2024

Cool -- I appreciate this new approach. I will review it in detail when I find some time soon...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Apr 16, 2024

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

@oli-obk oli-obk removed the PG-exploit-mitigations Project group: Exploit mitigations label Apr 17, 2024
@oli-obk
Copy link
Contributor Author

oli-obk commented Apr 23, 2024

@bors r=compiler-errors rollup=iffy

@bors
Copy link
Contributor

bors commented Apr 23, 2024

📌 Commit 2c39d20 has been approved by compiler-errors

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Apr 23, 2024

⌛ Testing commit 2c39d20 with merge f506f21...

bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 23, 2024
…er-errors

Require explicitly marking closures as coroutines

instead of relying on patching up the closure to be a coroutine if it happens to contain a `yield` expression.

I only do this in the 2024 edition, as the `gen` keyword is only available there.
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Apr 23, 2024

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 23, 2024
@oli-obk
Copy link
Contributor Author

oli-obk commented Apr 23, 2024

msvc -.-

@bors r=compiler-errors rollup=iffy

@bors
Copy link
Contributor

bors commented Apr 23, 2024

📌 Commit bf436b5 has been approved by compiler-errors

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 Apr 23, 2024
@bors
Copy link
Contributor

bors commented Apr 23, 2024

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

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 23, 2024
@oli-obk
Copy link
Contributor Author

oli-obk commented Apr 24, 2024

@bors r=compiler-errors rollup=iffy

@bors
Copy link
Contributor

bors commented Apr 24, 2024

📌 Commit aef0f40 has been approved by compiler-errors

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 24, 2024
@bors
Copy link
Contributor

bors commented Apr 24, 2024

⌛ Testing commit aef0f40 with merge e936289...

@bors
Copy link
Contributor

bors commented Apr 24, 2024

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing e936289 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 24, 2024
@bors bors merged commit e936289 into rust-lang:master Apr 24, 2024
13 checks passed
@rustbot rustbot added this to the 1.79.0 milestone Apr 24, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (e936289): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

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

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.4% [3.4%, 3.4%] 1
Regressions ❌
(secondary)
3.0% [3.0%, 3.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-5.3% [-5.3%, -5.3%] 1
All ❌✅ (primary) 3.4% [3.4%, 3.4%] 1

Cycles

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.5% [2.8%, 4.2%] 3
Regressions ❌
(secondary)
2.4% [2.1%, 2.8%] 7
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.5% [2.8%, 4.2%] 3

Binary size

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

Bootstrap: 673.226s -> 672.79s (-0.06%)
Artifact size: 315.42 MiB -> 315.46 MiB (0.01%)

@oli-obk oli-obk deleted the coroutine_closures branch April 24, 2024 12:22
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. PG-exploit-mitigations Project group: Exploit mitigations 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.

None yet

9 participants