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

Import reordering can break programs (using @preconcurrency) #79414

Closed
weissi opened this issue Feb 15, 2025 · 2 comments
Closed

Import reordering can break programs (using @preconcurrency) #79414

weissi opened this issue Feb 15, 2025 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@weissi
Copy link
Contributor

weissi commented Feb 15, 2025

Description

Consider this program

@preconcurrency import Glibc
import Foundation

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

compiles and runs just fine:

$ swiftc -swift-version 6 test.swift && echo OK
OK

But running swift-format (default config) on it, breaks it:

$ 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

This is because it changed the order of the imports.

This is probably a Swift bug but you could argue it's a formatter bug too.

Related issues:

Reproduction

import Foundation
@preconcurrency import Glibc

await Task {
  _ = fputs("hello\n", stderr)
}.value
swiftc -swift-version 6 test.swift && echo OK

Expected behavior

compiles fine in language mode 6.

Environment

Swift version 6.0.2 (swift-6.0.2-RELEASE)
Target: aarch64-unknown-linux-gnu

Additional information

No response

@allevato
Copy link
Member

This is a duplicate of #76842.

@hborla
Copy link
Member

hborla commented Feb 22, 2025

Duplicate of #76842

@hborla hborla marked this as a duplicate of #76842 Feb 22, 2025
@hborla hborla closed this as completed Feb 22, 2025
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. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

3 participants