Swift 5.8 Released!

Image credits: Pixabay - Gerd Altmann

Swift 5.8 is now officially released! ? This release includes major additions to the language and standard library, including hasFeature to support piecemeal adoption of upcoming features, an improved developer experience, improvements to tools in the Swift ecosystem including Swift-DocCSwift Package Manager, and SwiftSyntax, refined Windows support, and more.

Thank you to everyone in the Swift community who made this release possible. Your Swift Forums discussions, bug reports, pull requests, educational content, and other contributions are always appreciated!

For a quick dive into some of what’s new in Swift 5.8, check out this playground put together by Paul Hudson.

The Swift Programming Language book has been updated for Swift 5.8 and is now published with DocC. This is the official Swift guide and a great entry point for those new to Swift. The Swift community also maintains a number of translations.

Language and Standard Library

Swift 5.8 enables you to start incrementally preparing your projects for Swift 6 by using upcoming features. By default, upcoming features are disabled. To enable a feature, pass the compiler flag -enable-upcoming-feature followed by the feature’s identifier.

Feature identifiers can also be used in source code using #if hasFeature(FeatureIdentifier) so that code can still compile with older tools where the upcoming feature is not available.

Swift 5.8 includes upcoming features for the following Swift evolution proposals:

For example, building the following file at /Users/example/Desktop/0274-magic-file.swift in a module called MagicFile with -enable-experimental-feature ConciseMagicFile will opt into the concise format for #file and #filePath described in SE-0274:

fatalError("Something bad happened!")

The above code will produce the following output:

Fatal error: Something bad happened!: file MagicFile/0274-magic-file.swift, line 3

Swift 5.8 also includes conditional attributes to reduce the maintenance cost of libraries that support multiple Swift tools versions. #if checks can now surround attributes on a declaration, and a new hasAttribute(AttributeName) conditional directive can be used to check whether the compiler version has support for the attribute with the name AttributeName in the current language mode:

#if hasAttribute(preconcurrency)
protocol P: Sendable { ... }

Swift 5.8 brings other language and standard library enhancements, including unboxing for any arguments to optional parameterslocal wrapped properties in result buildersimproved debug printing for key paths, and more.

You can find the complete list of Swift Evolution proposals that were implemented in Swift 5.8 in the Swift Evolution Appendix below.

Developer Experience

Improved Result Builder Implementation

The result builder implementation has been reworked in Swift 5.8 to greatly improve compile-time performance, code completion results, and diagnostics. The Swift 5.8 result builder implementation enforces stricter type inference that matches the semantics in SE-0289: Result Builders, which has an impact on some existing code that relied on invalid type inference.

The new implementation takes advantage of the extended multi-statement closure inference introduced in Swift 5.7 and applies the result builder transformation exactly as specified by the result builder proposal – a source-level transformation which is type-checked like a multi-statement closure. Doing so enables the compiler to take advantage of all the benefits of the improved closure inference for result builder-transformed code, including optimized type-checking performance (especially in invalid code) and improved error messages.

For more details, please refer to the Swift Forums post that outlines the improvements and provides more information about invalid inference scenarios.



As announced in February, The Swift Programming Language book has been converted to Swift-DocC and made open source, and with it came some enhancements to Swift-DocC itself in the form of option directives you can use to change the behavior of your generated documentation. Swift-DocC has also added some new directives to create more dynamic documentation pages, including Grid-based layouts and tab navigators.

To take things even further, you can now customize the appearance of your documentation pages with color, font, and icon customizations. Navigation also took a step forward with quick navigation, allowing fuzzy in-project search:

Swift-DocC also now supports documenting extensions to types from other modules. This is an opt-in feature and can be enabled by adding the --include-extended-types flag when using the Swift-DocC plugin.

Swift Package Manager

Following are some highlights from the changes introduced to the Swift Package Manager in Swift 5.8:

  • SE-0362: Targets can now specify the upcoming language features they require. Package.swift manifest syntax has been expanded with an API to include setting enableUpcomingFeature and enableExperimentalFeature flags at the target level.
  • SE-0378: Token authentication when interacting with a package registry is now supported. The swift package-registry command has two new subcommands login and logout for adding/removing registry credentials.
  • Exposing an executable product that consists solely of a binary target that is backed by an artifact bundle is now allowed. This allows vending binary executables as their own separate package, independently of the plugins that are using them.
  • In packages using tools version 5.8 or later, Foundation is no longer implicitly imported into package manifests. If Foundation APIs are used, the module needs to be imported explicitly.

See the Swift Package Manager changelog for the complete list of changes.


With the Swift 5.8-aligned release of SwiftSyntax, SwiftSyntax contains a completely re-written parser that is implemented entirely in Swift instead of relying on the C++ parser to produce a SwiftSyntax tree. While the Swift compiler still uses the old parser implemented in C++, the eventual goal is to replace the old parser entirely. The new parser has a number of advantages:

  • Contributing to or depending on SwiftSyntax is now as easy as any other Swift package. This greatly lowers the barrier of entry for new contributors and adopters.
  • The new parser has been designed with error recovery as a primary goal. It is more tolerant of parsing errors and produces better error messages.
  • SwiftSyntaxBuilder allows generating source code in a declarative way using a mixture of result builders and string interpolation. An example can be found here.

Windows Platform

Swift 5.8 continues the incremental improvements to the Windows toolchain. Some of the important work that has gone into this release cycle includes:

  • The Windows toolchain has reduced some of its dependency on environment variables. DEVELOPER_DIR was previously needed to locate components and this is no longer required. This cleans up the installation and enables us to get closer to per-user installation.
  • ICU has been changed to static linking. This reduces the number of files that need to be distributed and reduces the number of dependencies that a shipping product requires. This was made possible by the removal of the ICU dependency in the Swift standard library.
  • Some of the initial work to support C++ interop on Windows has been merged and is available in the toolchain. This includes the work towards modularising the Microsoft C++ Runtime (msvcprt).
  • The vcruntime module has been renamed to visualc. This better reflects the module and paves the road for future enhancements for bridging the Windows platform libraries.
  • A significant amount of work for improving path handling in the Swift Package Manager has been merged. This should help make Swift Package Manager more robust on Windows and improve interactions with SourceKit-LSP.
  • SourceKit-LSP has benefited from several robustness improvements. Cross-module references are now more reliable and C/C++ references have been improved thanks to the enhanced path handling in SPM which ensures that files are correctly identified.


Official binaries are available for download from Swift.org for Xcode, Windows, and Linux. The Swift 5.8 compiler is also included in Xcode 14.3.

Swift Evolution Appendix

The following language, standard library, and Swift Package Manager proposals were accepted through the Swift Evolution process and implemented in Swift 5.8.

Language and Standard Library

Swift Package Manager

By: Alexander Sandberg
Originally published at Swift Blog

Source: Cyberpogo

For enquiries, product placements, sponsorships, and collaborations, connect with us at hello@firegulaman.com. We'd love to hear from you!