Swift 5.7 is now available, and this release includes major additions to the language and standard library, enhancements to the compiler for a better developer experience, tools in the Swift ecosystem (including SourceKit-LSP and the Swift Package Manager) improvements, improved Windows support, and more.
Languages and Standard Libraries
The Swift 5.7 language and standard library have several improvements:
- New shorthand syntax for common boilerplate code, including
if let
Statement and multi-statement closure type annotations - Unlocking long-standing language constraints to make general-purpose programming more seamless
- Enhanced data race security with new annotations and opt-in diagnostics
- Actor isolation in a distributed environment
- Improved usability of an existing set of pointer APIs
- Brand new language support and string handling API
developer experience
New generic implementation
In addition to the language improvements mentioned above for handling generics, the generic implementation of the type checker was rewritten from the ground up with improvements in both correctness and performance.
The new implementation fixes a number of longstanding bugs, mostly related to handling complex homogenous requirements, such as for collectionsSubSequence
Same-type requirements for associated types, and the use ofCaseIterable
The code for the protocol, which definesSelf.Element == Self
requirements.
The new generic implementation also improves performance. Type checking time was exponential in Swift 5.6 under the configuration of certain protocols and associated types, but is now linear in Swift 5.7.
Automatic reference counting improvements
In Swift 5.7, ARC behavior is more predictable, user-friendly, and enforceable by specifying new rules to shorten the lifetime of variables while allowing optimizations. To enforce these rules, the compiler employs a new internal representation to keep track of the lexical scope of each variable. This involves updating existing optimizations and implementing several new ones.The most common programming patterns that rely on extending the lifetime of variables are now safe without the need for the programmer to explicitly usewithExtendedLifetime()
, which protects you from hard-to-diagnose lifecycle errors that occur only when running in an optimized build. It also allows more powerful optimizations to be introduced without breaking existing resources.
Code Completion
Code Completion for function call parameters, variables, and global functions is now tightly integrated into Swift’s type checker. This allows Code Completion to provide more accurate results in ambiguous or buggy code.
If in the following example the+
When complete, Code Completion now reports that int and string match the surrounding context, allowing the editor to queue these results inhigher thanarray
s position.
func makeIntOrString() -> Int {}
func makeIntOrString() -> String {}
let array = [4, 2]
let int = 42
let string = "Hello World!"
makeIntOrString() +
if completeMissing parameters in the following example,Code Completion Now only the secondInt parameter label is prompted and secondString is omitted.
func add(_ firstInt: Int, secondInt: Int) {}
func add(_ firstString: String, secondString: String) {}
add(1, )
More details can be found on the official blog.
#Swift #Released #News Fast Delivery