Skip to content

Conversation

weissi
Copy link
Contributor

@weissi weissi commented Feb 15, 2025

Related issues:

I've got a working program

@preconcurrency import Glibc
import Foundation

await Task {
  _ = fputs("hello\n", stderr)
}.value

but alas, if swift-format reformats it, it makes it (note that the two imports are reordered)

import Foundation
@preconcurrency import Glibc

await Task {
  _ = fputs("hello\n", stderr)
}.value

which unfortunately doesn't compile

$ swift format --in-place test.swift && swiftc -swift-version 6 test.swift && echo OK
test.swift:5:24: error: reference to var 'stderr' is not concurrency-safe because it involves shared mutable state
3 | 
4 | await Task {
5 |   _ = fputs("hello\n", stderr)
  |                        `- error: reference to var 'stderr' is not concurrency-safe because it involves shared mutable state
6 | }.value
7 | 

SwiftGlibc.stderr:1:12: note: var declared here
1 | public var stderr: UnsafeMutablePointer<FILE>!
  |            `- note: var declared here

the problem is that Foundation imports Glibc/Musl but doesn't mark them @preconcurrency.

@weissi weissi changed the title always @preconcurrency import Glibc/Musl always @preconcurrency import Glibc/Musl/Bionic/Android/WASILibc Feb 15, 2025
@weissi
Copy link
Contributor Author

weissi commented Feb 15, 2025

/ci test

@parkera
Copy link
Contributor

parkera commented Feb 19, 2025

@swift-ci test

@weissi
Copy link
Contributor Author

weissi commented Feb 26, 2025

@parkera this passed, can I merge it?

@parkera parkera merged commit 9dd8777 into swiftlang:main Feb 26, 2025
2 checks passed
@parkera
Copy link
Contributor

parkera commented Feb 26, 2025

@weissi do you want to cherry pick for 6.1?

@weissi
Copy link
Contributor Author

weissi commented Feb 26, 2025

@weissi do you want to cherry pick for 6.1?

Great idea: #5177

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants