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

Runtime data race checker triggered for function-wrapper around withCheckedContinuation #62223

Open
mstyura opened this issue Nov 22, 2022 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself concurrency Feature: umbrella label for concurrency language features

Comments

@mstyura
Copy link

mstyura commented Nov 22, 2022

Description
Compile following snipped of code:

`
import Foundation

func withCheckedVoidContinuationBad(function: String = #function, _ body: (CheckedContinuation<Void, Never>) -> Void) async {
  await withCheckedContinuation(body)
}

func withCheckedVoidContinuationGood(function: String = #function, _ body: (CheckedContinuation<Void, Never>) -> Void) async {
  await withCheckedContinuation(function: function, body)
}

actor MyActor {
  var state = 1

  func runBuiltIn() async {
    await withCheckedContinuation { cont in
      state = 2
      print("runBuiltIn")
      cont.resume()
    }
  }
  
  func runBad() async {
    await withCheckedVoidContinuationBad { cont in
      state = 3
      print("runBad")
      cont.resume()
    }
  }
  
  func runGood() async {
    await withCheckedVoidContinuationGood { cont in
      state = 4
      print("runGood")
      cont.resume()
    }
  }
}

let a = MyActor()
await a.runBuiltIn()
await a.runGood()
await a.runBad()

print("Done!")

Steps to reproduce
Compile snipped of code with compiler flargs -Xfrontend -enable-actor-data-race-checks -warn-concurrency

Expected behavior
Both withCheckedVoidContinuationBad and withCheckedVoidContinuationGood either compiled or rejected to compile.

Actual behavior
Runtime data race checker reports an error:

warning: data race detected: actor-isolated function at ActorWithCheckedContinuation/main.swift:30 was not called on the same actor

Environment

  • Swift compiler version info swift-DEVELOPMENT-SNAPSHOT-2022-11-19-a.xctoolchain
  • Xcode version info
  • Deployment target: MacOS 12.5
@mstyura mstyura added the bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. label Nov 22, 2022
@LucianoPAlmeida LucianoPAlmeida added concurrency Feature: umbrella label for concurrency language features runtime The Swift Runtime labels Nov 24, 2022
@AnthonyLatsis AnthonyLatsis added compiler The Swift compiler in itself and removed runtime The Swift Runtime labels Nov 28, 2022
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. compiler The Swift compiler in itself concurrency Feature: umbrella label for concurrency language features
Projects
None yet
Development

No branches or pull requests

3 participants