Default swift language version for a given toolchain version

I think it's also important to note that in the context of SwiftPM package and Xcode projects, explicit
-swift-version flags are already typically passed to the compiler.

I think this flag is always passed for SwiftPM packages.

Xcode project templates currently automatically define a SWIFT_VERSION build setting of 5 which is passed to the compiler. Xcode builds fail if no SWIFT_VERSION is set. (Thank you @NeoNacho Default swift language version for a given toolchain version - #9 by NeoNacho)

So, in many existing developer contexts, the compiler default language mode is already overridden.

I think this ends up being three different decisions about language version/mode:

  • How SwiftPM chooses the default language mode it passes to the compiler
  • The language mode set in Xcode templates
  • The compiler default language mode

SwiftPM

For SwiftPM, I believe that SwiftPM should pass the -swift-version 6 flag by default once a package has been updated to declare // swift-tools-version:6.0.

It is an explicit opt-in for existing packages so swift-tools-version 5.x packages continue to use version 5 by default. (Pitch: [SwiftPM] Swift Language Version Per Target - #12 by James_Dempsey)

Xcode

For Xcode, since it's proprietary, as a community, we don't really have insight into when templates might change to use SWIFT_VERSION 6.

But even then, most existing Xcode projects will continue building with SWIFT_VERSION 5 since that has been part of templates for a long while now.

I could also imagine Xcode checking if a project does not have a SWIFT_VERSION build setting and notifying the user and letting them choose between 5 and 6.

One thing I do hope Apple-internal folks guard against is encouraging SWIFT_VERSION 6 as one of the 'recommended build setting updates' that appear when opening a project with a new Xcode version.

Compiler Default

I don't have any statistics as to how much Swift is compiled via SwiftPM commands vs xcodebuild of Xcode projects vs 'bare' use of calling the compiler using things like makefiles.

But, I would imagine a great deal of compilation is in the context of building SwiftPM packages and Xcode projects, which override the compiler default.

I could see the built-in default going either way.

UPDATE: Updated with information that Xcode builds fail if SWIFT_VERSION build setting is not present.

3 Likes