Apple’s Swift 5.8 previews Swift 6 features

Swift 5.8 brings improvements to the developer experience, enhanced Windows support, and the ability to try out features coming in Swift 6.

prediction predict the future crystal ball hand holding crystal ball by arthur ogleznev via unsplash
Arthur Ogleznev / Unsplash (CC0)

Swift 5.8, an update of Apple’s general purpose, multi-paradigm programming language, lays the foundation for Swift 6 with previews of features such as concise magic file names and regex literals. Swift 5.8 highlights also include an improved developer experience and refined Windows support. 

Officially released March 30, Swift 5.8 can be downloaded from The Swift 6 previews are turned off by default, but can be enabled through the compiler flag -enable-upcoming-feature followed by the feature identifiers. These identifiers also can be used in source code.

The Swift 6 evolution proposals included in Swift 5.8:

  • Concise magic file names (ConciseMagicFile), in which #file would evaluate to a human-readable string containing the file name and module name while preserving existing behavior in a new #filePath expression. Presently, #file evaluates to a string literal holding the full path to the current source file. The current mechanism has had drawbacks such as potential revelation of private or sensitive information as well as bloated binaries.
  • Regex literals (BareSlashRegexLiterals), which provide compile-time checks and typed-capture inference.
  • Forward-scan matching for trailing disclosures (ForwardTrailingClosures), which replace backward-scan matching with a forward scan, for simplicity and better API support.
  • Introduce existential any (ExistentialAny), which make the impact of existential types explicit in the language by annotating these types with any. Currently, existential types in Swift have a lightweight spelling. A plain protocol name in type context means an existential type, but this has caused confusion and often requires rewriting code.

Also featured in Swift 5.8 is a conditional attributes capability that promises to reduce maintenance costs of libraries supporting multiple Swift tools versions. Other language and standard library enhancements are offered including unboxing for any arguments to optional parameters and improved debug printing for key paths. The result builder implementation has been reworked to improve compile performance, code completion results, and diagnostics.

In addition, SwiftSyntax has a rewritten parser implemented entirely in Swift instead of relying on the C++ parser to produce a SwiftSyntax tree. The new parser offers benefits in areas such as error recovery. While the Swift compiler still uses the old C++ parser, plans call for eventually replacing this parser entirely. The Swift Package Manager offers enhancements such as targets now specifying the upcoming language features they require, and token authentication when interacting with a package registry.

For Windows, Swift 5.8 offers improvements such as the Windows toolchain reducing dependency on environment variables. Also, initial work to support C++ interop on Windows has been merged and is available in the toolchain. This includes work toward modularizing the Microsoft C++ runtime.

In addition to Swift 6, a Swift 5.9 release also is planned. Swift 5.7 was published last September.

Copyright © 2023 IDG Communications, Inc.