Swift 5.9
Alexander Sandberg and Holly Borla (tweet, Hacker News):
This is a major new release that adds an expressive macro system to the language and introduces support for integrating Swift into C++ codebases through bidirectional interoperability.
It also introduces parameter packs, an improved expression evaluator while debugging, enhanced crash handling, Windows platform improvements, and more.
[…]
The new
consume
operator tells Swift to deinitialize a variable and transfer its contents without copying it. Theconsuming
andborrowing
parameter modifiers provide hints that Swift can use to eliminate unnecessary copying and reference-counting operations when passing a parameter.
I have not been following this closely, but as far as I can tell this is for optimizations in code that you write. It doesn’t help when your code is being called by the standard library. If you try to iterate a Sequence
or sort an Array
of custom objects, I think it’s still going to do lots of unnecessary reference-counting.
Finally, noncopyable structs and enums allow you to create types which, like a class, can’t be meaningfully copied when assigned, but like a struct or enum, do not need to be reference-counted because only one storage location can own the instance at a time.
[…]
- SE-0366:
consume
operator to end the lifetime of a variable binding- SE-0374: Add sleep(for:) to Clock
- SE-0377:
borrowing
andconsuming
parameter ownership modifiers- SE-0380:
if
andswitch
expressions- SE-0381: DiscardingTaskGroups
- SE-0382: Expression Macros
- SE-0384: Importing Forward Declared Objective-C Interfaces and Protocols
- SE-0386: New access modifier:
package
- SE-0388: Convenience Async[Throwing]Stream.makeStream methods
- SE-0389: Attached Macros
- SE-0390: Noncopyable structs and enums
- SE-0392: Custom Actor Executors
- SE-0393: Value and Type Parameter Packs
- SE-0394: Package Manager Support for Custom Macros
- SE-0395: Observation
- SE-0396: Conform
Never
toCodable
- SE-0397: Freestanding Declaration Macros
- SE-0398: Allow Generic Types to Abstract Over Packs
- SE-0399: Tuple of value pack expansion
- SE-0400: Init Accessors
- SE-0401: Remove Actor Isolation Inference caused by Property Wrappers
- SE-0402: Generalize
conformance
macros asextension
macros
Lots of good stuff here. I’m still using Xcode 14, and the Swift compiler frequently crashes or produces incorrect results. I hope this version is better.
See also: Paul Hudson.
Previously:
- Macros in Swift 5.9
- SwiftUI Data Flow 2023
- Swift Proposal: Init Accessors
- SwiftData
- WWDC 2023 Links
- A Vision for Using C++ From Swift
- Xcode 14.3
- Swift 5.8
- Swift Proposal: Value and Type Parameter Packs
- Swift Proposal: Noncopyable Structs and Enums
- A Vision for Variadic Generics in Swift
- Swift Pitch: “borrow” and “take” Parameter Ownership Modifiers
- Porting Graphing Calculator From C++ to Swift
- Roadmap for Improving Swift Performance Predictability