Skip to content

[pigeon] Support @Sendable in Swift code #140439

@yuukiw00w

Description

@yuukiw00w

Use case

I set Strict Concurrency Checking to complete in Xcode 15's Build Settings, and use @MainActor.

Specifically, when implementing a class conforming to a protocol generated by Pigeon, I intend to have a class conforming to @MainActor as a property of that class. I plan to use the functions of that class to perform operations.

Furthermore, in cases where I return a struct defined by Pigeon in a completion handler when implementing functions of the protocol, if the completion handler does not conform to @Sendable, the following warning is issued.

Capture of 'completion' with non-sendable type '(Result<[CustomType], any Error>) -> Void' in a `@Sendable` closure

Proposal

// pigeon generated

// I want to add @Sendable to CustomType
struct CustomType {
  var sample1: String
  var sample2: Int
}

protocol Sample {
  // I want to @Sendable before @escaping
  func fetchSample(completion: @escaping (Result<[CustomType], Error>) -> Void)
}

// implements
final class SampleImpl: Sample, Sendable {
  private let mainActorSample: MainActorSampleClass = .init()

  // I want to @Sendable before @escaping
  func fetchSample(completion: @escaping (Result<[CustomType], Error>) -> Void) {
    Task { @MainActor in
      let customType = mainActorSample.fetchSample()
      completion(customType)
    }
  }
}

In practice, even with the aforementioned modifications, a warning is issued at the reply location due to the absence of @Sendable on reply in setMessageHandler.

While it is desirable to eventually address this warning at the reply location, we will exclude it from the scope of consideration in this issue.

The reason is likely that, given the nature of passing arguments to Flutter, it is assumed that reply is implicitly Sendable, and this warning within the code generated by Pigeon can be temporarily ignored.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: new featureNothing broken; request for a new capabilityhas partial patchThere is a PR awaiting someone to take it across the finish linep: pigeonrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions