Swift 5.7 released

Swift 5.7 is now out , 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 letstatement 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 homogenization requirements, such as homogenization requirements for collections SubSequenceassociated types, and CaseIterablecode that uses the protocol, which defines the Self.Element == Selfrequirements.

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 extended variable lifetimes are now safe without explicit use by the programmer withExtendedLifetime(), which protects you from hard-to-diagnose lifetime bugs that only run in optimized builds. 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.

Code Completion now reports that int and string match the surrounding context if done in the following example +, allowing the editor to rank these results higherarray .

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

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

Code Completion now only prompts for the secondInt parameter label and omits secondString if you complete the missing parameter in the example below .

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

More details can be found on the official blog .

Guess you like

Origin www.oschina.net/news/210073/swift-5-7-released