Swift 5.9 released

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.

Read on for a deep dive into changes to the language, standard library, tooling, platform support, and next steps for getting started with Swift 5.9.

Thank you to everyone in the Swift community who made this release possible. Your Swift Forums discussions, bug reports, pull requests, educational content, and other contributions are always appreciated!

48 Likes

First, for backtrace support on macOS, this setting is mentioned: SWIFT_BACKTRACE=enable=yes. This syntax seems odd (two equals?), and it isn't clear where to add it. I assume this is an environment variable?

Second, there's this statement about breakpoint support:

Swift expressions can now refer to generic type parameters. This allows setting a conditional breakpoint in a generic function that only triggers when a type parameter is instantiated with a specific concrete type.

Could we get an example? There is no Swift syntax for a typed version of a generic function, so how does this work?

1 Like

i’m surprised that there is a big bold button directing linux users to install swift through docker:

and yet there are no docker images for 5.9; users following the directions and pulling from swift:latest will receive a 5.8 toolchain instead.

4 Likes

I believe the Docker images should be available soon (see /download), but we should maybe make this more clear in the installation instructions as well.

cc: @mishal_shah

3 Likes

Swift allows using type parameters, e.g. as metatypes, in expressions inside the implementation of a generic type or function. This is referring to enabling the same ability in the LLDB expression evaluator. For example, if you're inside a generic function func test<T>() { ... }, you can set a conditional breakpoint that will hit when T.self == Int.self, or you can p T.self to see the underlying type of T when you're at a breakpoint inside this function.

9 Likes

There's also going to be a follow-up blog post focussing on the debugging enhancements in Swift 5.9 with more concrete examples coming soon.

15 Likes

Looks like there is a mistake in the parameter packs example:

let (int, double, string, bool) = all(optionalInt, optionalDouble, optionalString, optionalBool) {
  print(int, double, string, bool)
}
else {
  print("got a nil")
}

I was confused by this. I was guessing that it was meant to be a conditional binding with if let and the if was just accidentally excluded.

I think there is a regression issue that was fixed in development snapshots:

it looks like the 5.9 docker images are available now!

2 Likes

Not sure if it belongs here but Documentation doesn't contain any mention about Type and Value parameter packs, repeat pattern, generally nothing about variadic generic support?

1 Like

There's a WIP PR to add that documentation here.

5 Likes

func all<each Wrapped>(_ optional: repeat (each Wrapped)?) -> (repeat each Wrapped)?

The ergonomics of this are confusing. Is there a clear definition for newbies to explain why repeat is sometimes there and sometimes not and when it belongs inside parentheses and when it doesn’t?

3 Likes

Variadics support isn't mentioned in Changelog either.

“Variadic generic parameter packs are spelled each T. Whenever you want to use them, you write repeat and then the type or expression containing each T. This shows which part of the code should be repeated for each member of the pack.”