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

always @preconcurrency import Glibc/Musl/Android/Bionic/WASILibc #1175

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

weissi
Copy link

@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.


This has been used to rewrite the sources:

find Sources/ -name '*.swift' | while read -r line; do sed -r -i '' 's/^( *)(@_exported )?import (Musl|Android|Bionic|Glibc|WASILibc)/\1\2@preconcurrency import \3/g' "$line"; done

@weissi weissi force-pushed the jw-preconcurrency-glibc branch from 7c73fc2 to 662a5f1 Compare February 15, 2025 10:20
@parkera parkera requested a review from al45tair February 19, 2025 23:43
@parkera
Copy link
Contributor

parkera commented Feb 19, 2025

@swift-ci test

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