swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.58k stars 10.36k forks source link

stderr is not marked as Sendable on Linux #75601

Open ahoppen opened 3 months ago

ahoppen commented 3 months ago

Using stderr on Linux in Swift 6 mode fails.

$ cat /tmp/a.swift 
import Foundation

fputs("Hello worlds\n", stderr)
root@jammy-latest:/tmp# swift -swift-version 6 a.swift 
a.swift:3:25: error: reference to var 'stderr' is not concurrency-safe because it involves shared mutable state
1 │ import Foundation
2 │ 
3 │ fputs("Hello worlds\n", stderr)
  │                         ╰─ error: reference to var 'stderr' is not concurrency-safe because it involves shared mutable state
4 │ 

SwiftGlibc.stderr:1:12: note: var declared here
1 │ public var stderr: UnsafeMutablePointer<FILE>!
  │            ╰─ note: var declared here

rdar://125578486

grynspan commented 3 months ago

The Glibc thin overlay needs to mark it as nonisolated(unsafe) really. Its mutability is a side effect of how it's declared in Glibc but in practice it's a constant.

weissi commented 3 days ago

Still unfixed in Swift 6.0.1