# Swift 6 language mode being passed to dependencies

**URL:** <https://forums.swift.org/t/swift-6-language-mode-being-passed-to-dependencies/72622>\
**Category:** Using Swift\
**Tags:** concurrency, sendable\
**Created:** [June 20, 2024, 10:51am UTC](https://forums.swift.org/t/swift-6-language-mode-being-passed-to-dependencies/72622 "2024-06-20T10:51:22Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![0xTim](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/0xtim/32/27968_2.png) [@0xTim](https://forums.swift.org/u/0xTim)\
**Post date:** [June 20, 2024, 10:51am UTC](https://forums.swift.org/t/swift-6-language-mode-being-passed-to-dependencies/72622/1 "2024-06-20T10:51:23Z")

</div>

Hi all,

We're seeing an issue in Vapor when compiling it with the tools version set to 6.0 and the language mode set to `.v6` in that it's failing to compile because of a Sendable warning in a dependency (Swift Metrics). This dependency is currently on 5.6 so should be built in Swift 5 language mode correct?

I think this is a compiler/SwiftPM bug but let me know what the best steps to report are. This is happening on the current Xcode 16 beta. You can reproduce it with the `swift-6-check` branch on [GitHub - vapor/vapor: 💧 A server-side Swift HTTP web framework.](https://github.com/vapor/vapor)

---

<div class="post-metadata">

**Author:** ![mattie](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mattie/32/13267_2.png) [@mattie](https://forums.swift.org/u/mattie)\
**Post date:** [June 20, 2024, 2:39pm UTC](https://forums.swift.org/t/swift-6-language-mode-being-passed-to-dependencies/72622/2 "2024-06-20T14:39:22Z")

</div>

It may be worth trying to reproduce this problem with a command line only build without Xcode or `xcodebuild` involved.

Xcode 16 beta 1's behavior currently differs from `swift` in how default languge mode is set. I don't immediately see how that would cause the problem you are seeing happen. But, it at least does sound like it could be related.

---

<div class="post-metadata">

**Author:** ![0xTim](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/0xtim/32/27968_2.png) [@0xTim](https://forums.swift.org/u/0xTim)\
**Post date:** [June 20, 2024, 2:59pm UTC](https://forums.swift.org/t/swift-6-language-mode-being-passed-to-dependencies/72622/3 "2024-06-20T14:59:45Z")

</div>

Same issue with `swift build`:

```swift
 377 | public struct TimeUnit: Equatable {
     | `- note: consider making struct 'TimeUnit' conform to the 'Sendable' protocol
 378 | private enum Code: Equatable {
 379 | case nanoseconds
     :
 399 | public static let microseconds = TimeUnit(code: .microseconds, scaleFromNanoseconds: 1000)
 400 | public static let milliseconds = TimeUnit(code: .milliseconds, scaleFromNanoseconds: 1000 * TimeUnit.microseconds.scaleFromNanoseconds)
 401 | public static let seconds = TimeUnit(code: .seconds, scaleFromNanoseconds: 1000 * TimeUnit.milliseconds.scaleFromNanoseconds)
     | |- error: static property 'seconds' is not concurrency-safe because non-'Sendable' type 'TimeUnit' may have shared mutable state
     | |- note: annotate 'seconds' with '@MainActor' if property should only be accessed from the main actor
     | `- note: disable concurrency-safety checks if accesses are protected by an external synchronization mechanism
 402 | public static let minutes = TimeUnit(code: .minutes, scaleFromNanoseconds: 60 * TimeUnit.seconds.scaleFromNanoseconds)
 403 | public static let hours = TimeUnit(code: .hours, scaleFromNanoseconds: 60 * TimeUnit.minutes.scaleFromNanoseconds)
/Users/timc/Developer/Vapor/vapor/.build/checkouts/swift-metrics/Sources/CoreMetrics/Metrics.swift:401:23: error: static property 'seconds' is not concurrency-safe because non-'Sendable' type 'TimeUnit' may have shared mutable state

```

Note that the type and declaration producing the error are in a dependency

---

<div class="post-metadata">

**Author:** ![xedin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/xedin/32/309_2.png) [@xedin](https://forums.swift.org/u/xedin)\
**Post date:** [June 20, 2024, 7:09pm UTC](https://forums.swift.org/t/swift-6-language-mode-being-passed-to-dependencies/72622/4 "2024-06-20T19:09:00Z")

</div>

I spent some time investigating this and turns out this is not a SwiftPM issue but a compiler one. The diagnostic points to the declaration of the `seconds` but it should actually be pointing to the point-of-use in this case. I'll working on a fix for this and will update this thread once that's done.

---

<div class="post-metadata">

**Author:** ![FranzBusch](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/franzbusch/32/19447_2.png) [@FranzBusch](https://forums.swift.org/u/FranzBusch)\
**Post date:** [June 20, 2024, 7:51pm UTC](https://forums.swift.org/t/swift-6-language-mode-being-passed-to-dependencies/72622/5 "2024-06-20T19:51:56Z")

</div>

Fix for adding the missing `Sendable` annotations is [here](https://github.com/apple/swift-metrics/pull/148)

---

<div class="post-metadata">

**Author:** ![finestructure](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/finestructure/32/34879_2.png) [@finestructure](https://forums.swift.org/u/finestructure)\
**Post date:** [June 21, 2024, 6:39am UTC](https://forums.swift.org/t/swift-6-language-mode-being-passed-to-dependencies/72622/6 "2024-06-21T06:39:18Z")

</div>

This might explain why we’ve seen an increase in error counts in our [“Ready for Swift 6” graph](https://swiftpackageindex.com/ready-for-swift-6) for the Xcode 16b1 build. We’d be counting root dependencies’ errors multiple times.

---

<div class="post-metadata">

**Author:** ![xedin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/xedin/32/309_2.png) [@xedin](https://forums.swift.org/u/xedin)\
**Post date:** [June 21, 2024, 7:31am UTC](https://forums.swift.org/t/swift-6-language-mode-being-passed-to-dependencies/72622/7 "2024-06-21T07:31:01Z")

</div>

PR [[Concurrency] Don't attempt to diagnose `GlobalConcurrency` issues wi… by xedin · Pull Request #74614 · swiftlang/swift · GitHub](https://github.com/swiftlang/swift/pull/74614) addresses this issue.

---

<div class="post-metadata">

**Author:** ![0xTim](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/0xtim/32/27968_2.png) [@0xTim](https://forums.swift.org/u/0xTim)\
**Post date:** [June 21, 2024, 8:26am UTC](https://forums.swift.org/t/swift-6-language-mode-being-passed-to-dependencies/72622/8 "2024-06-21T08:26:06Z")

</div>

Wonderful thank you!

---

<div class="post-metadata">

**Author:** ![0xTim](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/0xtim/32/27968_2.png) [@0xTim](https://forums.swift.org/u/0xTim)\
**Post date:** [June 21, 2024, 8:28am UTC](https://forums.swift.org/t/swift-6-language-mode-being-passed-to-dependencies/72622/9 "2024-06-21T08:28:33Z")

</div>

Just to follow up on this if it's helpful, using `@preconcurrency import` on the offending library doesn't appear to help

---

<div class="post-metadata">

**Author:** ![0xTim](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/0xtim/32/27968_2.png) [@0xTim](https://forums.swift.org/u/0xTim)\
**Post date:** [June 21, 2024, 8:30am UTC](https://forums.swift.org/t/swift-6-language-mode-being-passed-to-dependencies/72622/10 "2024-06-21T08:30:02Z")

</div>

Final one - without meaning to highjack the thread - is `InferSendableFromCaptures` implemented in the current Swift 6 toolchain? We're seeing an error with code like

```swift
    private static let prefix: [String: WritableKeyPath<Self, Int?>] = [
            "max-age": \.maxAge,
            "s-maxage": \.sMaxAge,
            "min-fresh": \.minFresh,
            "stale-while-revalidate": \.staleWhileRevalidate,
            "stale-if-error": \.staleIfError
        ]

```

I believe this should be fine in Swift 6 with SE-0418 but it doesn't appear to being picked up

---

<div class="post-metadata">

**Author:** ![xedin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/xedin/32/309_2.png) [@xedin](https://forums.swift.org/u/xedin)\
**Post date:** [June 21, 2024, 4:18pm UTC](https://forums.swift.org/t/swift-6-language-mode-being-passed-to-dependencies/72622/11 "2024-06-21T16:18:06Z")

</div>

I'm not sure what you mean here, the contextual type here is not parked as Sendable which overrides any inference we apply to the literal because that's the type we covert to.

---

<div class="post-metadata">

**Author:** ![dnadoba](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dnadoba/32/11438_2.png) [@dnadoba](https://forums.swift.org/u/dnadoba)\
**Post date:** [June 21, 2024, 5:14pm UTC](https://forums.swift.org/t/swift-6-language-mode-being-passed-to-dependencies/72622/12 "2024-06-21T17:14:13Z")

</div>

The type of `prefix` should be ` [String: WritableKeyPath<Self, Int?> & Sendable]`.

---

<div class="post-metadata">

**Author:** ![0xTim](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/0xtim/32/27968_2.png) [@0xTim](https://forums.swift.org/u/0xTim)\
**Post date:** [June 21, 2024, 11:58pm UTC](https://forums.swift.org/t/swift-6-language-mode-being-passed-to-dependencies/72622/13 "2024-06-21T23:58:38Z")

</div>

Ahhh thank you!
