bazelbuild / rules_swift

Bazel rules to build Swift on Apple and Linux platforms
Apache License 2.0
309 stars 133 forks source link

`swift.vfsoverlay` breaks `-strict-concurrency` checking #1196

Closed jszumski closed 4 months ago

jszumski commented 4 months ago

The swift.vfsoverlay feature breaks module concurrency checking when enabled with Xcode 15.3. This tiny example has a strict-concurrency=complete module that depends on a strict-concurrency=minimal module:

# BUILD

swift_library(
    name = "ModuleMinimal",
    srcs = ["ModuleMinimal/ExampleMinimal.swift"],
)

swift_library(
    name = "ModuleComplete",
    srcs = ["ModuleComplete/ExampleComplete.swift"],
    copts = [
        "-strict-concurrency=complete",
        "-warnings-as-errors",
    ],
    deps = [
        ":ModuleMinimal",
    ],
    features = ["swift.vfsoverlay"],
)
# 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
    }
}

brentleyjones commented 4 months ago

Does swift.use_explicit_swift_module_map work (which should generally be used instead of swift.vfsoverlay)?

jszumski commented 4 months ago

Nope, it also unexpectedly succeeds:

swift_library(
    name = "ModuleComplete",
    srcs = ["ModuleComplete/ExampleComplete.swift"],
    copts = [
        "-strict-concurrency=complete",
        "-warnings-as-errors",
    ],
    deps = [
        ":ModuleMinimal",
    ],
    features = ["swift.use_explicit_swift_module_map"],
)

result:

INFO: Elapsed time: 5.497s, Critical Path: 3.03s
INFO: 34 processes: 13 internal, 19 darwin-sandbox, 2 worker.
INFO: Build completed successfully, 34 total actions
brentleyjones commented 4 months ago

I would extract this into a swiftc based repro, and file it against the swift GitHub repo, because this is a swift compiler bug then. (use the vfs versions since they have issues with us using the explicit module map the way we do)

jszumski commented 4 months ago

Filed upstream: https://github.com/apple/swift/issues/73088