Skip to content

[6.0][Concurrency] Check varIsSafeAcrossActors in getActorIsolationForReference. #73289

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
Apr 26, 2024

Conversation

hborla
Copy link
Member

@hborla hborla commented Apr 26, 2024

  • Explanation: A recent change to add a default implementation of mutating func next() on AsyncIteratorProtocol caused code like the following to fail to type check:

    @available(SwiftStdlib 5.1, *)
    actor Iterator: AsyncIteratorProtocol {
      init() {}
      func next() throws -> Int? { nil }
    }
    
    @available(SwiftStdlib 5.1, *)
    actor SafeMutatingCall {
      private let iterator: Iterator
    
      public init() async throws {
        self.iterator = Iterator()
        _ = try await self.iterator.next() // error: cannot call mutating async function 'next()' on actor-isolated property 'iterator'
      }
    }

    This happened because now overload resolution selects the mutating default implementation from AsyncIteratorProtocol, and the actor isolation checker code that diagnoses mutating/inout calls on isolated properties did not consider whether a property is safe to access across actors. This change only treats nonisolated let properties in actors as isolated if access is from outside the module or the property type is not Sendable, following the rules in [Concurrency] nonisolated can only be applied to actor properties with Sendable type. #70909.

  • Scope: Only impacts actor isolated properties that are let constants whose type is Sendable.

  • Risk: Low; treating Sendable actor isolated let properties as nonisolated within the module allows more code to compile.

  • Testing: Updated existing expected diagnostics, and added a new test case for the source compatibility issue.

  • Reviewer: @DougGregor

  • Main branch PR: [Concurrency] Check varIsSafeAcrossActors in getActorIsolationForReference. #73279

…olated

if access is from outside the module or the property type is not 'Sendable'.

(cherry picked from commit 39c7962)
@hborla hborla requested a review from a team as a code owner April 26, 2024 16:14
@hborla
Copy link
Member Author

hborla commented Apr 26, 2024

@swift-ci please test

@hborla hborla merged commit 6eb92fb into swiftlang:release/6.0 Apr 26, 2024
5 checks passed
@hborla hborla deleted the 6.0-actor-nonisolated-let branch April 26, 2024 21:47
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