Skip to content

[Concurrency] Add an experimental macro for wrapping a function body in a new task. #79729

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 1 commit into from
Mar 4, 2025

Conversation

hborla
Copy link
Member

@hborla hborla commented Mar 2, 2025

It's very common to wrap an entire function body in a new task, e.g. in a synchronous event handler that needs to kick off async work. This change adds an experimental function body macro that wraps an entire function body in a task.

This macro is a much simpler version of the @asyncHandler attribute, which was proposed in an early pitch of SE-0297: Concurrency Interoperability with Objective-C, and subsetted out because many event handlers need to start work synchronously. This macro currently uses Task.init, but could be updated to use the pitched Task.startSynchronously API.

This macro is gated behind the ConcurrencySyntaxSugar experimental feature. I'll write up a pitch for this soon to discuss the design. Please save any design feedback for the forthcoming forum thread.

I'm currently working on lifting the limitation that function body macros cannot be applied to closures, so this macro can be used with closures too. There are quite a few places that assume an attached macro can only be applied to a declaration :)

@hborla
Copy link
Member Author

hborla commented Mar 4, 2025

@swift-ci please smoke test

@ktoso
Copy link
Contributor

ktoso commented Mar 4, 2025

Naming bikeshed aside I think we'd probably want to adopt the name: (once #79600 is merged) and maybe priority: parameters on this as well 🤔

@hborla hborla force-pushed the concurrency-sugar branch from 8f12128 to 8be41ed Compare March 4, 2025 04:51
@hborla
Copy link
Member Author

hborla commented Mar 4, 2025

@swift-ci please smoke test

@hborla
Copy link
Member Author

hborla commented Mar 4, 2025

@ktoso ah yeah good idea! I'll wait for #79600 so I can add the parameters together.

@hborla hborla marked this pull request as ready for review March 4, 2025 04:52
@hborla hborla merged commit f0446d0 into swiftlang:main Mar 4, 2025
3 checks passed
@hborla hborla deleted the concurrency-sugar branch March 4, 2025 14:14
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