Issue #183 22 Apr 2021
Written by: Kristaps Grinbergs
We finally have the Xcode 12.5 RC, and it has some notable Swift language fixes and improvements.
In the last two weeks it seems like the Swift core team have woken up after a winter slumber. Dozens of proposals are now in review and many have been returned.
Now let’s go to the news!
Imagine you could undo mistakes in Git with a simple keyboard shortcut, use Interactive Rebase via drag and drop or clone a repository from GitHub with a single click. Tower lets you do exactly that and so much more. Finally take advantage of Git’s powerful feature set - in a beautiful GUI that will make you more productive every single day. Try it free for 30 days.
News and community
Xcode 12.5 RC is out and has a lot of new Swift features, improvements, and fixes.
Commits and pull requests
The feedback to the idea of extending SwiftPM to support new kind of binary targets, in conjunction with the plugin system proposed in SE-0303 was positive. However, given SE-0303 was returned to review, as well as feedback from reviewers requesting additional details on the structure suggested on SE-0305, the core team decided to ask that SE-0305 is refined alongside SE-0303.
Proposals in review
The core team sees two competing draws for consistency here—first, as Chris notes, in other places where Swift models API design,
letis externally treated equivalently with a get-only
var, and by that principle, actors should follow suit and not expose
lets as implicitly
nonisolatedoutside of the actor even if they are immutable. That would reserve for the actor the ability to evolve the interface into an internally-mutable variable, or get-only computed property, without breaking API or ABI. It would also result in a consistent rule for how
nonisolatedapply to actor members; instead of
lets being a special case, any actor declaration would require
nonisolatedto be explicitly annotated to declare it as safe to access from outside the actor without isolation.
On the other hand, “
lets are immutable and safe to share across threads” has also been a common message through Swift’s history, and it could seem boilerplatey to require an explicit annotation on top of
letto say that, yes, this immutable value is actually immutable. If actors in practice end up carrying a lot of immutable state, the annotation burden could be onerous. The core team would like to hear from the community, particularly adopters who have experimented with actors, to get more signal about how much burden treating the isolation
lets equivalently with other declarations will be in practice.
Nominal types such as classes, structs, and enums in Swift support computed properties and subscripts, which are members of the type that invoke programmer-specified computations when getting or setting them. The recently accepted proposal SE-0296 introduced asynchronous functions via
async, in conjunction with
await, but did not specify that computed properties or subscripts can support effects like asynchrony. Furthermore, to take full advantage of
asyncproperties, the ability to specify that a property
throwsis also important.
The Swift Package Manager’s binaryTarget type lets packages vend libraries that either cannot be built in Swift Package Manager for technical reasons, or for which the source code cannot be published for legal or other reasons.
In the current version of SwiftPM, binary targets only support libraries in an Xcode-oriented format called XCFramework, and only for Apple platforms.
This is a proposal for extensible build tools support in Swift Package Manager. The initial set of functionality is intentionally basic, and focuses on a general way of allowing build tool plugins to add commands to the build graph. The approach is to:
- provide a scalable way for packages to define plugins that can provide build-related capabilities
- support a narrowly scoped initial set of possible capabilities that plugins can provide
The set of possible capabilities can then be extended in future SwiftPM versions. The goal is to provide short-term support for common tasks such as source code generation, with a design that can scale to more complex tasks in the future.
This proposal depends on improvements to the existing Binary Target type in SwiftPM — those details are the subject of the separate proposal SE-0305.
This proposal is part of the larger concurrency feature. There have been quite a lot of these reviews, and there are a quite a few more coming, I’m afraid; still, we seem to have got through most of the more difficult ones. Thank you for your patience with all this.
Swift allows one to use a protocol as a type when its requirements meet a rather unintuitive list of criteria, among which is the absence of associated type requirements, and emits the following error otherwise:
Protocol can only be used as a generic constraint because it has 'Self' or associated type requirements. Our objective is to alleviate this limitation to impact only the ability to access certain members (instead of preemptively sealing off the entire protocol interface), and adjust the specified criteria to further reduce the scope of the restriction.
This proposal is a preamble to a series of changes aimed at generalizing value-level abstraction (existentials) and improving its interaction with type-level abstraction (generics). For an in-depth exploration of the relationships among different built-in abstractions models, we recommend reading the design document for improving the UI of the generics model.
This proposal aims to fix the lack of
Collectionconformance of the sequences returned by
enumerated(), preventing them from being used in a context that requires a
Collection. Also included is the addition of the
Collectionas a more ergonomic, efficient, and correct alternative to
There is an undocumented convention in Swift, of appending an underscore “_” to a public symbol or attribute to communicate some special meaning.
However, you will not find any mention of this practice within Swift’s own documentation on swift.org, nor any explanation of the often subtle differences in meaning of “_”. (Please correct me if I’m wrong. I did several searches and came up with nothing, and several read-throughs.)
Dictionarytype exposes a non-nil subscript
[position:]which takes a
Dictionary.Index. I always wondered why this subscript is
get-only, since I often find myself wanting to check if a key-value pair is present in the dictionary, and then mutate the value only if it exists.
Swift on the Server Workgroup meeting notes: