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

Region isolation diagnoses async iterator transfer despite nonisolated(unsafe) #72942

Open
hborla opened this issue Apr 10, 2024 · 1 comment
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. concurrency Feature: umbrella label for concurrency language features

Comments

@hborla
Copy link
Member

hborla commented Apr 10, 2024

Description

No response

Reproduction

@MainActor
func iterate(over stream: AsyncStream<Int>) async {
  for await ns in stream {
    print(ns)
  }
}

Building this code with -strict-concurrency=complete results in

warning: transferring '$ns$generator' may cause a race; this is an error in the Swift 6 language mode
  4 | @MainActor
  5 | func iterate(over stream: AsyncStream<Int>) async {
  6 |   for await ns in stream {
    |   |- warning: transferring '$ns$generator' may cause a race; this is an error in the Swift 6 language mode
    |   |- note: transferring disconnected '$ns$generator' to nonisolated callee could cause races in between callee nonisolated and local main actor-isolated uses
    |   `- note: use here could race
  7 |     print(ns)
  8 |   }

Expected behavior

No warning. The constraint system inserts nonisolated(unsafe) on the iterator variable to suppress this issue per #70697.

Environment

Swift version 6.0-dev (LLVM 401f5becfe44b89, Swift 129a021e790bc26)

Additional information

No response

@hborla hborla added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Apr 10, 2024
@hborla hborla added concurrency Feature: umbrella label for concurrency language features and removed triage needed This issue needs more specific labels labels Apr 10, 2024
@gottesmm
Copy link
Member

So I looked at this. I basically need to smuggle a bit.

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. concurrency Feature: umbrella label for concurrency language features
Projects
None yet
Development

No branches or pull requests

2 participants