Ted Kremenek is a member of the Swift Core Team and manages the Languages and Runtimes group at Apple.
Swift 5.1 is now officially released!
Swift 5.1 builds on the strengths of Swift 5 by extending the stable features of the language to compile time with the introduction of module stability. With module stability it’s now possible to create and share binary frameworks that will work with future releases of Swift. Swift 5.1 also extends the capabilities of the language and the standard library with new features such as property wrappers, opaque result types, key path member lookup, diffing for appropriate collection types, and new APIs for String. Altogether the new features of Swift 5.1 make it easier to design better APIs and reduce the amount of common boilerplate code.
You can learn more about the design considerations for the 5.1 release in episode 79 of the Swift Unwrapped podcast with Doug Gregor. You can also try out some of the new features in this playground put together by Paul Hudson.
Table of Contents
Module Stability
Swift 5.1 enables the creation of binary frameworks that can be shared with others leveraging the language’s added support for module stability. Module stability defines a new text-based module interface file that describes the API of a binary framework, allowing it to be compiled with code using different versions of the compiler.
The release also includes features to support library evolution. For more information about this addition to the language, please refer to the Swift Evolution proposal for Library Evolution.
The following blog posts and videos provide more details about the work involving ABI stability, module stability, and library evolution:
Standard Library Updates
The standard library in Swift 5.1 includes the following new features:
- Support for handling and updating diffs on collections of appropriate types
- Increased flexibility for initializing an array
- Additional APIs for making it easier to work with Strings, including creating and handling contiguous strings, helpers for working with Unicode text, and generic initializers for String.Index and Range
- A variety of incremental API improvements for working with SIMD types, including support for extending vectors, reductions, and vector swizzles
- Identifiable protocol for supporting entities that require unique identifiers
Swift 5.1 implements the following Standard Library proposals from the Swift Evolution process:
Additional Language and Compiler Updates
Swift 5.1 includes the following new language features:
- Property wrappers introduce a consistent and general purpose syntax for defining custom access patterns for property values, including (and not limited to) delayed initializers, atomic operations, thread-specific storage, and copy-on-write behavior
- Opaque result types allow the use of a generic type to support different types conforming to the same protocol or to hide implementation details in APIs
- The
return
keyword is not necessary for single expression functions or getters Self
can now be used for classes and value types- The compiler now synthesizes default values for properties with default initializers
Swift 5.1 implements the following language proposals from the Swift Evolution process:
SwiftSyntax Updates
SwiftSyntax has been re-architected with a focus on significantly improving its performance by directly using the parser from the Swift compiler. Further, the performance of syntax tree visitation and related operations has been improved by re-architecting the internal data structures to make them more efficient.
Language Server Protocol
The Swift 5.1 OSS toolchain packages for macOS and Ubuntu include the binaries for SourceKit-LSP, an implementation of the Language Server Protocol (LSP) for Swift and C-based languages.
Migrating to Swift 5.1
Swift 5.1 is source-compatible with Swift 5 and supports compatibility modes for Swift 4.2 and Swift 4/4.1.
To help with moving to the Swift 5 language mode from Swift 4/4.2, Apple’s Xcode 11 contains a code migrator that can automatically handle many of the needed source changes. There is also a migration guide available to guide you through many of the changes — especially through the ones that are less mechanical and require more direct scrutiny.
Documentation
An updated version of The Swift Programming Language for Swift 5.1 is now available on Swift.org. It is also available for free on the Apple Books store.
Platforms
Linux
Official binaries for Ubuntu 18.04, Ubuntu 16.04 and Ubuntu 14.04 are available for download.
Apple (Xcode)
For development on Apple’s platforms, Swift 5.1 ships as part of Xcode 11.
A toolchain is also available for download from Swift.org.
Sources
Development on Swift 5.1 was tracked in the swift-5.1-branch on the following repositories on GitHub:
The tag swift-5.1-RELEASE
designates the specific revisions in those repositories that make up the final version of Swift 5.1.
The swift-5.1-branch
will remain open, but under the same release management process, to accumulate changes for the next release.
Leave a Reply