swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.41k stars 10.34k forks source link

`-vfsoverlay` breaks `-strict-concurrency` checking #73088

Open jszumski opened 5 months ago

jszumski commented 5 months ago

Description

Using a VFS overlay prevents strict concurrency checking from diagnosing valid violations in Swift 5.10.

Reproduction

# prepare the dependency
swiftc \
    -c ModuleMinimal/ExampleMinimal.swift \
    -strict-concurrency=minimal \
    -emit-module \
    -emit-module-path build/ModuleMinimal.swiftmodule \
    -module-name ModuleMinimal \
    -whole-module-optimization \
    -parse-as-library \
    -o build/ModuleMinimal.o

# use the dependency without VFS
#
# correctly outputs:
#   warning: static property 'one' is not concurrency-safe because it is not either conforming to 'Sendable'
#   or isolated to a global actor; this is an error in Swift 6
swiftc \
    -c ModuleComplete/ExampleComplete.swift \
    -strict-concurrency=complete \
    -emit-module \
    -emit-module-path build/ModuleComplete.swiftmodule \
    -module-name ModuleComplete \
    -whole-module-optimization \
    -parse-as-library \
    -I build \
    -o build/ModuleComplete.o \

# use the dependency with VFS
#
# incorrectly shows no output
swiftc \
    -c ModuleComplete/ExampleComplete.swift \
    -strict-concurrency=complete \
    -emit-module \
    -emit-module-path build/ModuleComplete.swiftmodule \
    -module-name ModuleComplete \
    -whole-module-optimization \
    -parse-as-library \
    -Xfrontend -vfsoverlay \
    -Xfrontend vfs-overlay.yaml \
    -I/vfs_swiftmodules \
    -o build/ModuleComplete.o
# ExampleMinimal.swift

import Foundation

public struct ExampleMinimal {
    public let number: Int

    public static let one = ExampleMinimal(number: 1) // a declaration that does not pass `strict-concurrency=complete`
}
# ExampleComplete.swift

import Foundation
import ModuleMinimal

public struct ExampleComplete {
    public let number: Int

    public init() {
        number = ExampleMinimal.one.number // expected to raise an issue here
    }
}
# vfs-overlay.yml

case-sensitive: true
overlay-relative: false
roots:
  - contents:
      - external-contents: build/ModuleMinimal.swiftmodule
        name: ModuleMinimal.swiftmodule
        type: file
    name: /vfs_swiftmodules
    type: directory
use-external-names: false
version: 0

Expected behavior

Compliations with and without VFS should show warning: static property 'one' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor; this is an error in Swift 6.

Environment

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)

Additional information

No response

jszumski commented 5 months ago

Repro: concurrency-vfs.zip