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 unexpectedly affected by order #64392

Open
stevapple opened this issue Mar 15, 2023 · 1 comment
Open

@preconcurrency import unexpectedly affected by order #64392

stevapple opened this issue Mar 15, 2023 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. concurrency Feature: umbrella label for concurrency language features

Comments

@stevapple
Copy link
Contributor

Description
@preconcurrency import should apply @preconcurreny to what it imports exactly. eg., @preconcurrency import struct Foundation.Date should import exactly Foundation.Date as a @preconcurreny struct.

However, an experiment found that the compiler will emit false diagnostic on @preconcurrency import if there're more than one imports for the same module and the @preconcurrency one is not the first of them.

Steps to reproduce

import struct Foundation.Data
@preconcurrency import struct Foundation.Date

struct DateWrapper: Sendable {
    let date: Date
}

triggers compiler warning

bug.swift:5:9: warning: stored property 'date' of 'Sendable'-conforming struct 'DateWrapper' has non-sendable type 'Date'
    let date: Date
        ^
Foundation.Date:1:15: note: struct 'Date' does not conform to the 'Sendable' protocol
public struct Date : ReferenceConvertible, Comparable, Equatable {
              ^
bug.swift:1:1: remark: add '@preconcurrency' to suppress 'Sendable'-related warnings from module 'Foundation'
import struct Foundation.Data
^
@preconcurrency 
bug.swift:2:17: remark: '@preconcurrency' attribute on module 'Foundation' is unused
@preconcurrency import struct Foundation.Date
~~~~~~~~~~~~~~~~^

Expected behavior
The code should compile without warnings.

Environment
Swift version 5.7.3 (swift-5.7.3-RELEASE)
Target: x86_64-unknown-linux-gnu

Additional context
If we change the order of the two imports in the example code:

@preconcurrency import struct Foundation.Date
import struct Foundation.Data

struct DateWrapper: Sendable {
    let date: Date
}

Then it is warning-free as expected😅

@stevapple stevapple added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Mar 15, 2023
@hborla hborla added concurrency Feature: umbrella label for concurrency language features and removed triage needed This issue needs more specific labels labels Apr 27, 2024
@DougGregor
Copy link
Member

The ordering issue is addressed by #74413, but we're still not modeling the import of specific entities (i.e., an import struct).

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

3 participants