-
Notifications
You must be signed in to change notification settings - Fork 255
Swift 5.9 release blog post #372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
113c1bf
add first blog post draft
alexandersandberg 2f8aa20
include SE-0386 in evolutions appendix
alexandersandberg 1f9e12f
add c++ interoperability section
alexandersandberg 40d1057
Update 2023-08-29-swift-5.9-released.md (#374)
tomerd cf20b9a
update debugging section
alexandersandberg 7518f22
update swift syntax section
alexandersandberg e1bc48b
add language and standard library section
alexandersandberg 9bf6871
fix casing of section title
alexandersandberg d147e4a
Add a Crash Handling subsection. (#376)
al45tair 1171ead
remove completed TODOs
alexandersandberg dd2d3a1
add details element to hide code snippet
alexandersandberg 8e492da
add SE-0395 to evolutions list
alexandersandberg 0fa3a86
Remove promise of a future blog post. (#381)
al45tair 79798f7
Update _posts/2023-08-29-swift-5.9-released.md
tomerd 06e45f4
Updates to the 5.9 blog post draft. (#398)
hborla c2af136
Editorial pass for more consistent language and section structure.
hborla 9fe1cc8
Update _posts/2023-08-29-swift-5.9-released.md
tomerd a183a95
Update _posts/2023-08-29-swift-5.9-released.md
tomerd 019cfc3
Update _posts/2023-08-29-swift-5.9-released.md
tomerd 0121079
use smart quotes
alexandersandberg da1c493
address PR feedback
alexandersandberg 475a1d7
Improvements to the release blog post introduction.
hborla 2d316a2
Improve the framing of the language introduction, and flip the order of
hborla 3e08eb3
Minor editorial changes in the debugging section.
hborla 2eb95ab
Minor editorial changes in the Swift Syntax section.
hborla 902fa61
Editorial changes for the Swift Package Manager section.
hborla 03ae353
Re-combine the bullet point about SE-0391 and signed packages. Signed
hborla 4bb86ae
Lift up C++ interop to the top of the Ecosystem section.
hborla b038546
Update _posts/2023-08-29-swift-5.9-released.md
hborla dc5f3f2
Update _posts/2023-08-29-swift-5.9-released.md
hborla 7d2f70a
Add a code example of Swift-C++ interop.
hborla 667bbf1
Show an API before and after parameter packs to demonstrate reducing …
hborla 5f81630
Editorial changes to the Windows section.
hborla 4f13f19
More editorial changes for the language section.
hborla ccc6457
Add subheaders to the Language section
cthielen d894100
Add macro examples
cthielen 5838920
Minor tweaks to the C++ example flow
cthielen 6ef669d
Use consistent formatting for code examples.
hborla 57a95c8
Add a Next Steps section at the end of the post.
hborla 2aa7d5d
Address the outstanding review feedback.
hborla 5d9300e
add @hborla to list of authors
alexandersandberg b7d6c50
Minor tweaks to Language and Standard Library
cthielen a7ec23f
Minor edits to the remaining sections
cthielen 52a6395
Clarify macro composition refers to developers writing macros, not co…
cthielen ff49b01
Add example of a parameter pack call-site
cthielen 4eb287a
Add macro examples
cthielen acd33bb
Update the download section
shahmishal e709a82
remove TODO
alexandersandberg 210665e
Minor tweaks for readability
cthielen a9e7450
Add a note about which platforms support macros.
hborla ad1dbda
Update post date and time
cthielen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| --- | ||
| layout: post | ||
| published: true | ||
| date: 2023-08-29 15:00:00 | ||
| title: Swift 5.9 Released! | ||
| author: [alexandersandberg] | ||
| --- | ||
|
|
||
| Swift 5.9 is now officially released! 🎉 <!-- TODO: Summary of what's included in the release --> | ||
|
|
||
| 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! | ||
|
|
||
| <!-- TODO: Link to Swift 5.9 showcase resource --> | ||
|
|
||
| [The Swift Programming Language](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/) book has been updated for Swift 5.9 and is now published with DocC. This is the official Swift guide and a great entry point for those new to Swift. The Swift community also maintains a number of [translations](/documentation/#translations). | ||
hborla marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| If you’re new to Swift, [The Swift Programming Language](https://docs.swift.org/swift-book/) is the official Swift guide and has been updated for version 5.9. The Swift community maintains a number of [translations](https://www.swift.org/documentation/#translations). | ||
hborla marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Language and Standard Library | ||
|
|
||
| Swift 5.9 tackles three long-desired features that allow you to express things you couldn't easily do before. | ||
alexandersandberg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Swift now supports [macros](https://github.com/apple/swift-evolution/blob/main/visions/macros.md), which allow developers to reduce repetitive boilerplate and create new language features that can be distributed as a Swift package. Using a macro is easy and natural; macros can either be called with the function-like freestanding `#macroName` syntax or attached to declarations with an `@MacroName` attribute, so they work just like built-in language features but can't be mistaken for normal code. Implementing a macro uses a powerful and flexible approach: Macros are implemented by writing Swift functions that use the SwiftSyntax library to generate code to insert into the source file. Macros make it easy for your library's users to adopt powerful capabilities that adapt to the code they're used in, like [the new `Observation` module](https://github.com/apple/swift-evolution/blob/main/proposals/0395-observability.md), which allows Swift classes to automatically notify other code when their properties change. | ||
alexandersandberg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
beccadax marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Swift also has new features to help developers fine-tune memory management behavior in performance-critical code. The [`consume` operator](https://github.com/apple/swift-evolution/blob/main/proposals/0366-move-function.md) tells Swift to de-initialize a variable and transfer its contents without copying it. The [`consuming` and `borrowing` parameter modifiers](https://github.com/apple/swift-evolution/blob/main/proposals/0377-parameter-ownership-modifiers.md) provide hints that Swift can use to eliminate unnecessary copying and reference-counting operations when passing a parameter. And [noncopyable structs and enums](https://github.com/apple/swift-evolution/blob/main/proposals/0390-noncopyable-structs-and-enums.md) allow you to create types which, like a class, represent a specific resource that can't be meaningfully copied when it's 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. | ||
alexandersandberg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
alexandersandberg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| The last of these major features is [parameter packs](https://github.com/apple/swift-evolution/blob/main/proposals/0393-parameter-packs.md). These let you write generic types and functions which work over not just any type, but any _number_ of types. For example, this `all(_:)` function lets you check whether any number of `Optional` values are `nil`, even if the `Optional`s wrap different types: | ||
alexandersandberg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```swift | ||
| /// Takes any number of `Optional` arguments and returns `nil` if any of them | ||
| /// are `nil`, or a tuple of their values if all of them are non-`nil`. | ||
| func all<each Wrapped>(_ optional: repeat (each Wrapped)?) -> (repeat each Wrapped)? { | ||
| /// Accumulates the results from the `checkNilness(of:)` helper function. | ||
| var anyAreNil = false | ||
|
|
||
| // Check if any of the arguments in `each optional` is nil by running this | ||
| // `checkNilness(of:)` function on each argument. | ||
| func checkNilness<OneWrapped>(of oneOptional: OneWrapped?) { | ||
| if oneOptional == nil { | ||
| anyAreNil = true | ||
| } | ||
| } | ||
| repeat checkNilness(of: each optional) | ||
|
|
||
| // Did `checkNilness(of:)` find any nils? If so, return nil early. | ||
| if anyAreNil { | ||
| return nil | ||
| } | ||
|
|
||
| // Otherwise, we can safely force-unwrap all of the arguments and form a tuple | ||
| // from the unwrapped values. | ||
| return (repeat (each optional)!) | ||
alexandersandberg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| let optionalInt: Int? = 1 | ||
| let optionalDouble: Double? = 2.5 | ||
| let optionalString: String? = nil | ||
|
|
||
| if let (int, double, string) = all(optionalInt, optionalDouble, optionalString) { | ||
| print(int, double, string) | ||
| } | ||
| else { | ||
| print("got a nil") | ||
| } | ||
| ``` | ||
|
|
||
| What's more, these features are all usable today in Swift 5.9, but they are not finished growing. Each one is too large to fully implement in a single release; we're excited about what you can already do with them in Swift 5.9, but we're even more excited to have laid the foundations for better things to come. | ||
alexandersandberg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| In addition to these major features, Swift 5.9 also includes lots of smaller refinements to the language. The one developers will probably use most often is [`if` and `switch` expressions](https://github.com/apple/swift-evolution/blob/main/proposals/0380-if-switch-expressions.md), which lets you assign the result of a single-expression `if` or `switch` statement to a variable: | ||
hborla marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```swift | ||
| statusBar.text = if !hasConnection { "Disconnected" } | ||
| else if let error = lastError { error.localizedDescription } | ||
| else { "Ready" } | ||
| ``` | ||
|
|
||
| Swift 5.9 also adds a [new `package` access level](https://github.com/apple/swift-evolution/blob/main/proposals/0386-package-access-modifier.md) that lets other modules in the same package access APIs, but hides them from code outside the package; it's great for splitting up large modules into several smaller ones without exposing internals to the package's clients. Developers using Swift Concurrency may appreciate the [more convenient `DiscardingTaskGroup` types](https://github.com/apple/swift-evolution/blob/main/proposals/0381-task-group-discard-results.md) for task groups that don't generate results and the advanced [custom actor executors](https://github.com/apple/swift-evolution/blob/main/proposals/0392-custom-actor-executors.md) feature for controlling the exact environment that an actor is run in. | ||
hborla marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
alexandersandberg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| A full list of Swift 5.9's Evolution proposals can be found at the end of this post. | ||
alexandersandberg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Developer Experience | ||
|
|
||
| <!-- TODO: Add more sections with content? --> | ||
|
|
||
| ### Debugging | ||
alexandersandberg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| In Swift 5.9, we introduced a couple of new features to [LLDB](https://lldb.llvm.org/) and the Swift compiler aimed at making Swift debugging faster and more reliable. | ||
|
|
||
| The `p` and `po` commands will now bypass the Swift compiler when evaluating simple expressions, which will make printing local and member variables as fast as using the `frame variable` or `v` command. | ||
hborla marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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. | ||
|
|
||
| Finally, the debug info produced by the Swift compiler is now more precise when it comes to scoping of local variables. | ||
hborla marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| For a more detailed discussion and examples of how to use these new features we will be publishing a separate blog focussing on debugging Swift 5.9 next week! | ||
alexandersandberg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Ecosystem | ||
|
|
||
| <!-- TODO: Add more sections with content? --> | ||
|
|
||
| ### Swift Package Manager | ||
alexandersandberg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Following are some highlights from the changes introduced to the [Swift Package Manager](https://github.com/apple/swift-package-manager) in Swift 5.9: | ||
alexandersandberg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - SwiftPM packages can now use `package` as a new access modifier, allowing accessing symbols in another target / module within the same package without making it public. | ||
tomerd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
tomerd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - Introducing `CompilerPluginSupport` module for defining macro targets. Macro targets allow authoring and distribution of custom Swift macros such as [expression macros](https://github.com/apple/swift-evolution/blob/main/proposals/0382-expression-macros.md). | ||
|
|
||
| - Introducing new `.embedInCode` resource rule for embedding the contents of the resource into the executable by generating a byte array, e.g. | ||
|
|
||
| ``` | ||
| struct PackageResources { | ||
| static let my_resource: [UInt8] = [104,101,108,108,111,32,119,111,114,108,100,10] | ||
| } | ||
| ``` | ||
|
|
||
| - `allowNetworkConnections(scope:reason:)` setting giving a command plugin permissions to access the network. Permissions can be scoped to Unix domain sockets in general or specifically for Docker, as well as local or remote IP connections which can be limited by port. For non-interactive use cases, there is also a `--allow-network-connections` commandline flag to allow network connections for a particular scope. | ||
|
|
||
| - SwiftPM can now publish to a registry following the publishing spec as defined in [SE-0391](https://github.com/apple/swift-evolution/blob/main/proposals/0391-package-registry-publish.md). SwiftPM also gains support for signed packages. Trust-on-first-use (TOFU) check which includes only fingerprints (e.g., checksums) previously has been extended to include signing identities, and it is enforced for source archives as well as package manifests. | ||
tomerd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
tomerd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - New `swift experimental-sdk` experimental command is now available for managing Swift SDK bundles that follow the format described in [SE-0387](https://github.com/apple/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md). | ||
|
|
||
| See the [Swift Package Manager changelog](https://github.com/apple/swift-package-manager/blob/main/CHANGELOG.md#swift-59) for the complete list of changes. | ||
|
|
||
| ### Swift Syntax | ||
|
|
||
| [swift-syntax](https://github.com/apple/swift-syntax) has become an essential tool to create macros in Swift 5.9. In addition to the introduction of the modules that allow the creation of macros, swift-syntax has received huge focus on quality: | ||
alexandersandberg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - The documentation of swift-syntax has been greatly expanded and can be viewed at [swiftpackageindex.com](https://swiftpackageindex.com/apple/swift-syntax) | ||
alexandersandberg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - The names of all syntax nodes and their children have been audited to be more consistent and accurately reflect the Swift language. | ||
hborla marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - The error messages produced by the new SwiftParser have been greatly improved and it now produces better errors than the C++ parser in almost all cases. | ||
hborla marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - As part of the Google Summer of Code project, incremental parsing has been introduced to swift-syntax, allowing e.g. an editor to only reparse those parts of a syntax tree that have changed. | ||
hborla marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Over the last year, swift-syntax has been a huge success as an open source project. Since the release of Swift 5.8, more than 30 distinct open source contributors have contributed to the package accounting for more than 30% of the commits. And community tools like [swift-ast-explorer.com](https://swift-ast-explorer.com) are an invaluable tool to explore and understand the SwiftSyntax tree. Thanks to everyone who contributed! | ||
alexandersandberg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### C++ Interoperability | ||
hborla marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Swift 5.9 supports bidirectional interoperability with C++ and Objective-C++. You can now use a subset of C++ APIs in Swift and Swift APIs from C++. For information on enabling C++ interoperability and the supported language subset, please refer to the [documentation](/documentation/cxx-interop/). | ||
hborla marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| C++ interoperability is an actively evolving feature of Swift and developed by the focused [C++ Interoperability Workgroup](/cxx-interop-workgroup/). Certain aspects of the design and functionality might change in future releases of Swift, as the Swift community gathers feedback from real world adoption in mixed Swift and C++ codebases. | ||
|
|
||
| Join the Swift community and the C++ Interoperability Workgroup to provide feedback and help shape the evolution of the feature. | ||
|
|
||
tomerd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ### Windows Platform | ||
|
|
||
| <!-- TODO: Add section content --> | ||
|
|
||
| ## Downloads | ||
|
|
||
| <!-- TODO: Add section content --> | ||
|
|
||
| ## Swift Evolution Appendix | ||
|
|
||
| The following language, standard library, and Swift Package Manager proposals were accepted through the [Swift Evolution](https://github.com/apple/swift-evolution) process and [implemented in Swift 5.9](https://apple.github.io/swift-evolution/#?version=5.9). | ||
|
|
||
| - SE-0366: [`consume` operator to end the lifetime of a variable binding](https://github.com/apple/swift-evolution/blob/main/proposals/0366-move-function.md) | ||
| - SE-0374: [Add sleep(for:) to Clock](https://github.com/apple/swift-evolution/blob/main/proposals/0374-clock-sleep-for.md) | ||
| - SE-0377: [`borrowing` and `consuming` parameter ownership modifiers](https://github.com/apple/swift-evolution/blob/main/proposals/0377-parameter-ownership-modifiers.md) | ||
| - SE-0380: [`if` and `switch` expressions](https://github.com/apple/swift-evolution/blob/main/proposals/0380-if-switch-expressions.md) | ||
| - SE-0381: [DiscardingTaskGroups](https://github.com/apple/swift-evolution/blob/main/proposals/0381-task-group-discard-results.md) | ||
| - SE-0382: [Expression Macros](https://github.com/apple/swift-evolution/blob/main/proposals/0382-expression-macros.md) | ||
| - SE-0384: [Importing Forward Declared Objective-C Interfaces and Protocols](https://github.com/apple/swift-evolution/blob/main/proposals/0384-importing-forward-declared-objc-interfaces-and-protocols.md) | ||
| - SE-0386: [New access modifier: `package`](https://github.com/apple/swift-evolution/blob/main/proposals/0386-package-access-modifier.md) | ||
| - SE-0388: [Convenience Async[Throwing]Stream.makeStream methods](https://github.com/apple/swift-evolution/blob/main/proposals/0388-async-stream-factory.md) | ||
| - SE-0389: [Attached Macros](https://github.com/apple/swift-evolution/blob/main/proposals/0389-attached-macros.md) | ||
| - SE-0390: [Noncopyable structs and enums](https://github.com/apple/swift-evolution/blob/main/proposals/0390-noncopyable-structs-and-enums.md) | ||
| - SE-0392: [Custom Actor Executors](https://github.com/apple/swift-evolution/blob/main/proposals/0392-custom-actor-executors.md) | ||
| - SE-0393: [Value and Type Parameter Packs](https://github.com/apple/swift-evolution/blob/main/proposals/0393-parameter-packs.md) | ||
| - SE-0394: [Package Manager Support for Custom Macros](https://github.com/apple/swift-evolution/blob/main/proposals/0394-swiftpm-expression-macros.md) | ||
| - SE-0396: [Conform `Never` to `Codable`](https://github.com/apple/swift-evolution/blob/main/proposals/0396-never-codable.md) | ||
| - SE-0397: [Freestanding Declaration Macros](https://github.com/apple/swift-evolution/blob/main/proposals/0397-freestanding-declaration-macros.md) | ||
| - SE-0398: [Allow Generic Types to Abstract Over Packs](https://github.com/apple/swift-evolution/blob/main/proposals/0398-variadic-types.md) | ||
| - SE-0399: [Tuple of value pack expansion](https://github.com/apple/swift-evolution/blob/main/proposals/0399-tuple-of-value-pack-expansion.md) | ||
| - SE-0400: [Init Accessors](https://github.com/apple/swift-evolution/blob/main/proposals/0400-init-accessors.md) | ||
| - SE-0401: [Remove Actor Isolation Inference caused by Property Wrappers](https://github.com/apple/swift-evolution/blob/main/proposals/0401-remove-property-wrapper-isolation.md) | ||
| - SE-0402: [Generalize `conformance` macros as `extension` macros](https://github.com/apple/swift-evolution/blob/main/proposals/0402-extension-macros.md) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.