Skip to content

Add support for @Concurrent attribute on closures. #36012

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
merged 2 commits into from
Feb 18, 2021

Conversation

DougGregor
Copy link
Member

This allows one to specify @concurrent on closures, e.g.,

let fn = { @concurrent in ... }

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@@ -118,3 +118,10 @@ func testCaseNonTrivialValue() {

j = 17
}

func testExplicitConcurrentClosure() {
let fn = { @concurrent in
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also add some tests that combine @concurrent with parameter names, throws, async, and/or a return type?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, will do.

Copy link
Member Author

Choose a reason for hiding this comment

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

(It'll be a follow-up PR)


void visitConcurrentAttr(ConcurrentAttr *attr) {
// Nothing else to check.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we also need to check if the parameter types and result type are ConcurrentValue, or is that not implemented for functions yet either?

Copy link
Member Author

Choose a reason for hiding this comment

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

We've determined that we don't need that checking, because the act of calling a@concurrent function doesn't necessarily make it share its arguments or result value across different concurrency domains. It's the actual capture of non-concurrent values that is the problem.

@DougGregor DougGregor merged commit 077d96c into swiftlang:main Feb 18, 2021
@DougGregor DougGregor deleted the explicit-concurrent-closure branch February 18, 2021 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants