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

@preconcurrency import doesn't suppress warning on use of imported global variable #72187

Open
hborla opened this issue Mar 8, 2024 · 5 comments
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 Mar 8, 2024

Description

A @preconcurrency import does not suppress the use of an imported global variable.

Reproduction

@preconcurrency import struct UIKit.UIAccessibility.Notification

@MainActor func f() {
     _ = UIAccessibility.Notification.screenChanged // Reference to static property 'screenChanged' is not concurrency-safe because it involves shared mutable state; this is an error in Swift 6
}

Expected behavior

The warning is suppressed.

Environment

Swift 5.10

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 concurrency Feature: umbrella label for concurrency language features and removed triage needed This issue needs more specific labels labels Mar 8, 2024
@rnapier
Copy link

rnapier commented Mar 8, 2024

I've discovered an important detail and this may not be a bug.

The full code I was using included:

import SwiftUI
@preconcurrency import ... // whatever out of UIKit

Since SwiftUI imports UIKit (I assume), this doesn't work as expected. Rearranging fixes it:

@preconcurrency import UKit
import SwiftUI

This is a bit of a papercut for devs, but I don't think it's a bug.

@mattmassicotte
Copy link
Contributor

Here is an issue specifically capturing the ordering of imports being significant: #64392

@mattmassicotte
Copy link
Contributor

With Swift 6 this does suppress the warning, but now incorrectly produces a diagnotic saying that the @preconcurrency attribute has no effect.

swift-driver version: 1.109.2 Apple Swift version 6.0 (swiftlang-6.0.0.3.300 clang-1600.0.20.10)
Target: arm64-apple-macosx14.0

@DougGregor
Copy link
Member

The ordering issue is addressed by #74413, but we're not modeling the submodule import (of UIKit.UIAccessibility) completely.

@mattmassicotte
Copy link
Contributor

I both really appreciate the fix and also the follow up explaining the scope of when it currently will/won't apply.

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

4 participants