Swift 5.7 Released!

Swift 5.7 is now officially released! Swift 5.7 includes major additions to the language and standard library, enhancements to the compiler for a better developer experience, improvements to tools in the Swift ecosystem including SourceKit-LSP and the Swift Package Manager, refined Windows support, and more.

Swift 5.7 is the culmination of countless contributions from members across the Swift community. Thank you to everyone in the community for your Swift Forum discussions, bug reports, pull requests, educational content, and much more!

If you’re new to Swift, The Swift Programming Language is the official Swift guide and has been updated for version 5.7. The Swift community maintains a number of translations. It is also available for free on the Apple Books store.

Language and Standard Library

The Swift 5.7 language and standard library feature a number of improvements:

Most of these features were discussed at WWDC22 and were covered in a previous blog post, Swift language announcements from WWDC22. You can also find a complete list of language and standard library Swift Evolution proposals in the Swift Evolution Appendix.

Developer Experience

New Generics Implementation

In addition to the above language improvements for working with generics, the type checker’s generics implementation has been rewritten from scratch with improvements to correctness and performance.

The new implementation fixes many long-standing bugs, mostly related to the handling of complex same-type requirements, such as same-type requirements on a collection’s SubSequence associated type, and code making use of the CaseIterable protocol which defines the requirement Self.Element == Self.

The new generics implementation also improves performance. With certain configurations of protocols and associated types, type checking time would scale exponentially in Swift 5.6, but is now linear in Swift 5.7.

Automatic Reference Counting Improvements

In Swift 5.7, ARC behavior is more predictable, user-friendly, and performant by specifying new rules to shorten the lifetime of variables when optimization is allowed. To enforce the rules, the compiler adopted a new internal representation that tracks the lexical scope of each variable. This involved updating existing optimizations and implementing several new optimizations. Now, the most common programming patterns that depend on extended variable lifetimes are safe without requiring programmers to explicitly use withExtendedLifetime(). This protects you from difficult-to-diagnose lifetime bugs that only appear at runtime in optimized builds. It also allows the introduction of more powerful optimization without breaking existing source.

Code Completion

Code completion of function call arguments, variables, and global functions is now tightly integrated into Swift’s type checker. This allows code completion to provide more accurate results inside ambiguous code or code with errors.

If completing after the + in the following example, code completion now reports int and string as matching the surrounding context, allowing editors to rank these results higher than array.

func makeIntOrString() -> Int {}
func makeIntOrString() -> String {}

let array = [4, 2]
let int = 42
let string = "Hello World!"
makeIntOrString() +

If completing the missing argument in the following example, code completion now only suggests the secondInt argument label and omits secondString.

func add(_ firstInt: Int, secondInt: Int) {}
func add(_ firstString: String, secondString: String) {}
add(1, )

Ecosystem

SourceKit-LSP

SourceKit-LSP received several improvements to support the release of the Swift for Visual Studio Code extension.

Compiler arguments are now recomputed after changes to Package.swift, compile_commands.json, or compile_flags.txt. This ensures that semantic functionality, such as code completion or live issues, continues to work correctly after these changes.

If multiple SwiftPM projects are opened in the same Visual Studio Code workspace, SourceKit-LSP can manage them in a single server instance. The language server no longer needs to be restarted when switching between files from different SwiftPM projects, which reduces the delay until semantic functionality becomes available for a file.

Swift Package Manager

The following Swift Evolution proposals for SwiftPM were accepted and implemented in Swift 5.7:

Distributed Actor Library

Based on SE-0336: Distributed Actor Isolation, a server library for building distributed systems in Swift has been made open source. The library provides a peer-to-peer cluster actor system implementation, including cluster management, failure detection, and integration with service discovery.

Windows Platform

Swift 5.7 comes with the following refinements to Windows support:

Downloads

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

You can also install RPMs for Amazon Linux 2 and CentOS 7 for experimental use only. Please provide your feedback. Use the instructions below for RPM installation:

Amazon Linux 2

$ curl https://download.swift.org/experimental-use-only/repo/amazonlinux/releases/2/swiftlang.repo > /etc/yum.repos.d/swiftlang.repo
$ amazon-linux-extras install epel
$ yum install swiftlang

CentOS 7

$ curl https://download.swift.org/experimental-use-only/repo/centos/releases/7/swiftlang.repo > /etc/yum.repos.d/swiftlang.repo
$ yum install epel-release
$ yum install swiftlang

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

Concurrency

Type System Enhancements

String Processing

Pointer Usability

Swift Package Manager