Paul Krill
Editor at Large

Apple’s Swift 5.8 previews Swift 6 features

news
Apr 4, 20233 mins

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

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 swift.org. 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.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author