# Crowd source: Swift Language Modes in various environments

**URL:** <https://forums.swift.org/t/crowd-source-swift-language-modes-in-various-environments/76102>\
**Category:** Using Swift\
**Tags:** swift5, concurrency, swift6\
**Created:** [November 18, 2024, 7:42pm UTC](https://forums.swift.org/t/crowd-source-swift-language-modes-in-various-environments/76102 "2024-11-18T19:42:29Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![DandyLyons](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dandylyons/32/14417_2.png) [@DandyLyons](https://forums.swift.org/u/DandyLyons)\
**Post date:** [November 18, 2024, 7:42pm UTC](https://forums.swift.org/t/crowd-source-swift-language-modes-in-various-environments/76102/1 "2024-11-18T19:42:29Z")

</div>

There is so much counterintuitive information in the transition from Swift 5 to Swift 6. Many people don't understand the difference between Swift compiler versions and language modes. Swift 6 understandably introduces new compiler errors which are breaking changes. But these compiler errors appear in surprising places as well.

For example, the docs state "_The Swift 6 language mode is opt-in . Existing projects will not switch to this mode without configuration changes._" ([Quote from “Migrating to Swift 6 | Documentation”](https://arc.net/l/quote/rgxzvrfi)) So when I built my SPM project, I did not expect strict concurrency checking to produce non-compilable errors. But it did. If Swift 6 language mode is supposed to be opt-in then why would this result in an error, instead of a warning?

Well it seems that the docs are incorrect because the errors went away after I **opted out** of Swift 6 language mode, and **opted into** Swift 5 language mode.

It seems that Xcode, SPM, and Swift CLI all handle this slightly differently.

For this reason, I'd like to crowd source some info about how Swift behaves differently depending on tools version, language mode, etc.

I would appreciate anyone willing to contribute to this spreadsheet.

> **[Swift 5 to 6 Transition](https://docs.google.com/spreadsheets/d/15CYe85pQNmKMIEM-2jhRPu2lQJAFSorviPm3MintqR8/edit?usp=sharing)**
>
> This Sheet is private

---

<div class="post-metadata">

**Author:** ![xwu](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xwu](https://forums.swift.org/u/xwu)\
**Post date:** [November 18, 2024, 9:01pm UTC](https://forums.swift.org/t/crowd-source-swift-language-modes-in-various-environments/76102/3 "2024-11-18T21:01:31Z")

</div>

> [@DandyLyons](#):
>
> For example, the docs state "_The Swift 6 language mode is opt-in . Existing projects will not switch to this mode without configuration changes._" ([Quote from “Migrating to Swift 6 | Documentation”](https://arc.net/l/quote/rgxzvrfi)) So when I built my SPM project, I did not expect strict concurrency checking to produce non-compilable errors. But it did. If Swift 6 language mode is supposed to be opt-in then why would this result in an error, instead of a warning?
> 
> Well it seems that the docs are incorrect because the errors went away after I **opted out** of Swift 6 language mode, and **opted into** Swift 5 language mode.

This sounds like a bug in how the compiler is emitting diagnostics.  
Can you share a reproducer?

---

<div class="post-metadata">

**Author:** ![DandyLyons](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dandylyons/32/14417_2.png) [@DandyLyons](https://forums.swift.org/u/DandyLyons)\
**Post date:** [November 18, 2024, 9:07pm UTC](https://forums.swift.org/t/crowd-source-swift-language-modes-in-various-environments/76102/4 "2024-11-18T21:07:09Z")

</div>

Thanks. I'll DM you.

---

<div class="post-metadata">

**Author:** ![xwu](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xwu](https://forums.swift.org/u/xwu)\
**Post date:** [November 18, 2024, 9:18pm UTC](https://forums.swift.org/t/crowd-source-swift-language-modes-in-various-environments/76102/5 "2024-11-18T21:18:58Z")

</div>

I don't hack on that part of the compiler much, but I'm happy to take a look. Never wrong to file a GitHub issue or a Feedback though :)

---

<div class="post-metadata">

**Author:** ![xwu](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xwu](https://forums.swift.org/u/xwu)\
**Post date:** [November 18, 2024, 9:40pm UTC](https://forums.swift.org/t/crowd-source-swift-language-modes-in-various-environments/76102/6 "2024-11-18T21:40:49Z")

</div>

Ah, I see what's going on.

Basically, there's more than one way to opt-in to the Swift 6 language mode, and you've done so without knowing it, as detailed in ["Enabling The Swift 6 Language Mode"](https://www.swift.org/migration/documentation/swift-6-concurrency-migration-guide/swift6mode/)—

> A `Package.swift` file that uses `swift-tools-version` of `6.0` will enable the Swift 6 language mode for all targets. You can still set the language mode for the package as a whole using the `swiftLanguageModes` property of `Package`.

This is why you have to opt your target back out of the Swift 6 language mode in your package manifest. You can instead downgrade the minimum tools version.

---

<div class="post-metadata">

**Author:** ![DandyLyons](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dandylyons/32/14417_2.png) [@DandyLyons](https://forums.swift.org/u/DandyLyons)\
**Post date:** [November 18, 2024, 9:42pm UTC](https://forums.swift.org/t/crowd-source-swift-language-modes-in-various-environments/76102/7 "2024-11-18T21:42:34Z")

</div>

Ah. Of course. Thank you. I missed that detail.

---

<div class="post-metadata">

**Author:** ![dima\_kozhinov](https://avatars.discourse-cdn.com/v4/letter/d/258eb7/32.png) [@dima\_kozhinov](https://forums.swift.org/u/dima_kozhinov)\
**Post date:** [November 18, 2024, 10:49pm UTC](https://forums.swift.org/t/crowd-source-swift-language-modes-in-various-environments/76102/8 "2024-11-18T22:49:39Z")

</div>

> [@xwu](#):
>
> there's more than one way to opt-in to the Swift 6 language mode, and you've done so without knowing it

> A `Package.swift` file that uses `swift-tools-version` of `6.0` will enable the Swift 6 language mode for all targets.

It's the `swift package init` command who creates the `// swift-tools-version: 6.0` line in `Package.swift` file, not user. So for Swift Package Manager new projects we have opt-out, not opt-in.

---

<div class="post-metadata">

**Author:** ![DandyLyons](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dandylyons/32/14417_2.png) [@DandyLyons](https://forums.swift.org/u/DandyLyons)\
**Post date:** [November 18, 2024, 10:53pm UTC](https://forums.swift.org/t/crowd-source-swift-language-modes-in-various-environments/76102/9 "2024-11-18T22:53:50Z")

</div>

This is a very good point. I did not add `// swift-tools-version: 6.0` to my `Package.swift`. It was `swift package init` that did. It is very misleading for the docs to say that it is opt-in when it implicitly opts in for me without my knowledge.

---

<div class="post-metadata">

**Author:** ![jlukas](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jlukas/32/317_2.png) [@jlukas](https://forums.swift.org/u/jlukas)\
**Post date:** [November 19, 2024, 1:05am UTC](https://forums.swift.org/t/crowd-source-swift-language-modes-in-various-environments/76102/10 "2024-11-19T01:05:58Z")

</div>

It’s opt-in for existing projects, not new projects.

---

<div class="post-metadata">

**Author:** ![dima\_kozhinov](https://avatars.discourse-cdn.com/v4/letter/d/258eb7/32.png) [@dima\_kozhinov](https://forums.swift.org/u/dima_kozhinov)\
**Post date:** [November 19, 2024, 1:32am UTC](https://forums.swift.org/t/crowd-source-swift-language-modes-in-various-environments/76102/11 "2024-11-19T01:32:24Z")

</div>

What language mode do _new_ Xcode projects have?

Edit: I found the answer here: [Adopting strict concurrency in Swift 6 apps | Apple Developer Documentation](https://developer.apple.com/documentation/swift/adoptingswift6)

> new projects default to the Swift 5 language mode.

Swift Package Manager behaves differently.

---

<div class="post-metadata">

**Author:** ![idrougge](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/idrougge/32/3885_2.png) [@idrougge](https://forums.swift.org/u/idrougge)\
**Post date:** [November 19, 2024, 12:13pm UTC](https://forums.swift.org/t/crowd-source-swift-language-modes-in-various-environments/76102/12 "2024-11-19T12:13:11Z")

</div>

Perhaps `swift package init` should add a comment detailing the effects of different `swift-tools-version` settings.

---

<div class="post-metadata">

**Author:** ![kschlagel](https://avatars.discourse-cdn.com/v4/letter/k/48db29/32.png) [@kschlagel](https://forums.swift.org/u/kschlagel)\
**Post date:** [November 20, 2024, 6:52pm UTC](https://forums.swift.org/t/crowd-source-swift-language-modes-in-various-environments/76102/13 "2024-11-20T18:52:25Z")

</div>

I've always wanted to see `swift-tools-version` renamed to `minimum-swift-tools-version` (or something like that). The word _minimum_ is important here!

---

<div class="post-metadata">

**Author:** ![Jon\_Shier](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jon_shier/32/921_2.png) [@Jon\_Shier](https://forums.swift.org/u/Jon_Shier)\
**Post date:** [November 20, 2024, 7:49pm UTC](https://forums.swift.org/t/crowd-source-swift-language-modes-in-various-environments/76102/14 "2024-11-20T19:49:21Z")

</div>

Except it's not accurate. `swift-tools-version` determines the version SPM uses to parse the manifest exactly, and only newer versions get newer features. This includes things like language mode, but also things like the updated manifest model with the `swiftLanguageMode` label. Newer versions of SPM will happily parse and use packages with much older tools versions, and packages can require language versions newer than the tools version.

---

<div class="post-metadata">

**Author:** ![kschlagel](https://avatars.discourse-cdn.com/v4/letter/k/48db29/32.png) [@kschlagel](https://forums.swift.org/u/kschlagel)\
**Post date:** [November 20, 2024, 8:20pm UTC](https://forums.swift.org/t/crowd-source-swift-language-modes-in-various-environments/76102/15 "2024-11-20T20:20:41Z")

</div>

Would you say the [documentation](https://docs.swift.org/package-manager/PackageDescription/PackageDescription.html#about-the-swift-tools-version) is accurate?

> The Swift tools version declares the version of the `PackageDescription` library, the minimum version of the Swift tools and Swift language compatibility version to process the manifest, and the minimum version of the Swift tools that are needed to use the Swift package.

---

<div class="post-metadata">

**Author:** ![Jon\_Shier](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jon_shier/32/921_2.png) [@Jon\_Shier](https://forums.swift.org/u/Jon_Shier)\
**Post date:** [November 20, 2024, 9:15pm UTC](https://forums.swift.org/t/crowd-source-swift-language-modes-in-various-environments/76102/16 "2024-11-20T21:15:07Z")

</div>

Yes, so I suppose I should've said it's incomplete, rather than inaccurate. It's a minimum in some ways, but in most it determines the _exact_ version of behavior used to interpret the package.

---

<div class="post-metadata">

**Author:** ![NeoNacho](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/neonacho/32/1368_2.png) [@NeoNacho](https://forums.swift.org/u/NeoNacho)\
**Post date:** [November 21, 2024, 12:03am UTC](https://forums.swift.org/t/crowd-source-swift-language-modes-in-various-environments/76102/17 "2024-11-21T00:03:08Z")

</div>

Semi-related to the discussion here, I think it might be a good idea to think more about the tools-version and its relation to language mode, as well as revisit the concept more generally.

It was designed in a somewhat different world where language versions were happening more often and were generally something developers would adopt rather quickly. Similarly, on the package manager side, the version was mostly about additions to the API, rather than actually different behaviors preserved for backwards compatibility.
