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

[Macros] Update the name and argument list for the @Task function body macro. #80187

Merged
merged 1 commit into from
Mar 24, 2025

Conversation

hborla
Copy link
Member

@hborla hborla commented Mar 21, 2025

  • Use @Task for the macro name, because it always expands to a call to Task.init.
  • Add a parameter for specifying a global actor. Applying @Task with no global actor parameter will infer the isolation of the context on the closure. If a global actor is specified, the macro will use it as a global actor attribute on the closure.
  • Add parameters for name and priority, which are copied over to the Task.init call.

For example:

func perform() async { ... }

func acceptClosure(_ closure: @escaping () -> Void) { ... }

func test() {
  acceptClosure { @Task(name: "MyTask") in
    await perform()
  }
}

The macro expands to

func test() {
  acceptClosure {
    Task(name: "MyTask") {
      await perform()
    }
  }
}

that wraps a function or closure body in a new top-level task.
@hborla hborla force-pushed the task-macro-improvements branch from f3a48f2 to bac0a10 Compare March 21, 2025 13:21
@hborla
Copy link
Member Author

hborla commented Mar 21, 2025

@swift-ci please smoke test

@hborla hborla marked this pull request as ready for review March 21, 2025 20:36
@hborla
Copy link
Member Author

hborla commented Mar 21, 2025

@swift-ci please smoke test

1 similar comment
@hborla
Copy link
Member Author

hborla commented Mar 22, 2025

@swift-ci please smoke test

@hborla
Copy link
Member Author

hborla commented Mar 23, 2025

@swift-ci please smoke test macOS

@hborla hborla merged commit 498d7cc into swiftlang:main Mar 24, 2025
3 checks passed
@hborla hborla deleted the task-macro-improvements branch March 24, 2025 15:46
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.

1 participant