Skip to content

[6.2][Concurrency] Fix a false-positive metatype capture diagnostic. #81881

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
May 31, 2025

Conversation

hborla
Copy link
Member

@hborla hborla commented May 30, 2025

  • Explanation: sending closures that are isolated to the same actor as the enclosing context don't execute concurrently with the context. Concurrency checking for local captures accounts for this, but there was a bug in the strict Sendable metatype logic from SE-0470 that diagnosed non-Sendable metatypes in sending closures that did not execute concurrently. This change fixes that so that the following pattern is safe:
protocol P {}

func acceptClosure(_: () -> Void) {}

@MainActor
func f<T: P>(_: T.Type) {
  acceptClosure {
    Task {
      _ = T.self // okay to capture T.Type in this closure.
    }
  }
}

hborla added 2 commits May 30, 2025 16:09
This code is no longer used given that region isolation is always enabled
along with strict concurrency checking.

(cherry picked from commit c283ce1)
isolated to the same actor as the enclosing context.

(cherry picked from commit f0e77c7)
@hborla hborla requested a review from a team as a code owner May 30, 2025 23:13
@hborla
Copy link
Member Author

hborla commented May 30, 2025

@swift-ci please test

@hborla hborla merged commit c6cafd3 into swiftlang:release/6.2 May 31, 2025
5 checks passed
@hborla hborla deleted the 6.2-isolated-capture-fixes branch May 31, 2025 19:44
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