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

Pattern that the region based isolation checker does not understand how to check #76205

Open
dehesa opened this issue Sep 1, 2024 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@dehesa
Copy link

dehesa commented Sep 1, 2024

Description

I get the message

Pattern that the region based isolation checker does not understand how to check. Please file a bug.

when compiling the code printed below. It is 100% reproducible.

Reproduction

func withTaskProgression<Success: Sendable, Failure: Error>(
  operation: () async throws(Failure) -> sending Success,
  progression: @Sendable (TaskProgress) -> Void,
  isolation: isolated (any Actor)? = #isolation
) async throws(Failure) -> Success {
  try await withoutActuallyEscaping(progression) { (progression) async throws(Failure) -> Success in
    let progress = UnsafeTaskProgress(handler: progression)

    let result: Success
    do {
      result = try await Task.$progress.withValue(progress) {
        try await operation()
      }
    } catch let error as Failure {
      progress.failed(with: error)
      throw error
    } catch { fatalError() } // TODO: Remove when concrete thrown errors are better supported

    progress.finished()
    return result
  }
}

extension Task where Success == Never, Failure == Never {
  @TaskLocal static var progress: UnsafeTaskProgress?
}

final class UnsafeTaskProgress: Sendable {
  private let handler: Handler

  init(handler: @escaping Handler) {
    self.handler = handler
  }

  typealias Handler = @Sendable (TaskProgress) -> Void
  func failed(with error: some Swift.Error) {}
  func finished() {}
}

struct TaskProgress: Sendable {}

Expected behavior

I expect to be able to return Success without issues. In any case, the messages recommended to file a bug and that is what I am doing.

Environment

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx15.0

Additional information

I am running macOS 15.0 (Sequoia Beta 24A5331b) with Xcode 16.0 Beta 6 (16A5230g).

A bit outside the scope of the bug, but I am trying to create a Swift Concurrency progression report (as talked about in the Swift Forums).

@dehesa dehesa added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant