Tuesday, September 19, 2023

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. The consuming and borrowing 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.


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.


Comments RSS · Twitter · Mastodon

Leave a Comment