Skip to content

Avoid dynamic executor checks when calling synchronous non-escaping closures #82795

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

harlanhaskins
Copy link
Contributor

@harlanhaskins harlanhaskins commented Jul 4, 2025

The following code:

// In Module A
public func takesNonEscapingSyncClosure(_: () -> Void) { ... }

// In Module B

@MainActor
func mainActorFunc() {}

@MainActor
func passesNonEscapingSyncClosure() {
    takesNonEscapingSyncClosure { mainActorFunc() }
}

Would result in a call to _checkTaskExecutor in the closure argument's prologue to ensure takesNonEscapingSyncClosure doesn't dispatch the execution onto another actor.

My assumption here is that because the parameter is:

  • Not isolated
  • Synchronous
  • Non-escaping

we know it will be executed synchronously on the caller's actor and will statically not be executed on another actor. As such, we can avoid inserting the task executor check.

Resolves #82733

@harlanhaskins
Copy link
Contributor Author

@swift-ci please smoke test

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