You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _posts/2024-09-17-announcing-swift-6.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ Read on for a deep dive into changes to the language, standard libraries, debugg
19
19
20
20
### Concurrency
21
21
22
-
Swift has long offered memory safety, ensuring that variables are initialized before they’re used, memory isn’t accessed after it’s been deallocated, and array indices are checked for out-of-bounds errors. Swift 6 now includes a new, opt-in language mode that extends Swift’s safety guarantees to prevent data races in concurrent code by diagnosing potential data races in your code as compiler errors.
22
+
Swift has long offered memory safety, ensuring that variables are initialized before they’re used, memory isn’t accessed after it’s been deallocated, and array indices are checked for out-of-bounds errors. Swift 6 now includes a new, opt-in language mode that extends Swift’s safety guarantees to prevent data races in concurrent code by diagnosing potential data races in your code as compiler errors.
23
23
24
24
Data-race safety checks were previously available as warnings in Swift 5.10 through the `-strict-concurrency=complete` compiler flag. Thanks to improved `Sendable` inference and new compiler analysis for transferring mutable state from one actor to another, Swift 6 warnings about data-race safety have fewer false positives. You can find more information about the Swift 6 language mode and how to migrate at [Swift.org/migration](http://swift.org/migration).
25
25
@@ -34,8 +34,8 @@ Swift 6 enables functions to specify the type of error that they throw as part o
34
34
For example:
35
35
36
36
```swift
37
-
funcparseRecord(fromstring: String) throws(ParseError) -> Record {
38
-
// ...
37
+
funcparseRecord(fromstring: String) throws(ParseError) -> Record {
38
+
// ...
39
39
}
40
40
```
41
41
@@ -55,8 +55,8 @@ Typed throws can also be used in generic functions to propagate error types from
@@ -115,19 +115,19 @@ Swift 6 rounds out the set of low-level integer primitives with the addition of
115
115
116
116
### Productivity enhancements
117
117
118
-
Swift 6 introduces a number of productivity enhancements, including [`count(where:)`](<https://developer.apple.com/documentation/swift/sequence/count(where:)>) to streamline counting the number of elements in a sequence that satisfy a predicate, [pack iteration](https://www.swift.org/blog/pack-iteration/) for writing natural `for`-loops over the elements in a value parameter pack, access control for imports to keep implementation details from leaking into your public APIs, `@attached(body)` macros for synthesizing and augmenting function implementations, expression macros as default arguments, and more.
118
+
Swift 6 introduces a number of productivity enhancements, including [`count(where:)`](https://developer.apple.com/documentation/swift/sequence/count(where:)) to streamline counting the number of elements in a sequence that satisfy a predicate, [pack iteration](https://www.swift.org/blog/pack-iteration/) for writing natural `for`-loops over the elements in a value parameter pack, access control for imports to keep implementation details from leaking into your public APIs, `@attached(body)` macros for synthesizing and augmenting function implementations, expression macros as default arguments, and more.
119
119
120
120
You can find a complete list of language proposals that were accepted through the [Swift Evolution](https://github.com/swiftlang/swift-evolution) process and implemented in Swift 6 on the [Swift Evolution dashboard](https://www.swift.org/swift-evolution/#?version=6.0).
121
121
122
122
## Debugging
123
123
124
-
### Custom LLDB summaries with <code>@DebugDescription</code>
124
+
### Custom LLDB summaries with `@DebugDescription`
125
125
126
126
Swift 6 provides a new debugging macro to easily customize how an object is displayed in LLDB when using the `p` command, and in the variables view in Xcode and VSCode, by using a formatting scheme that does not run arbitrary code.
127
127
128
128
Types that conform to `CustomDebugStringConvertible` provide a `debugDescription` property that returns a string describing the object. In LLDB, the `po` command calls this computed property on an object. In contrast, the `p` command uses LLDB’s type summary formatters to directly format the object using its stored property values.
129
129
130
-
[`@DebugDescription`](<https://developer.apple.com/documentation/swift/debugdescription()>) is a new macro in the standard library which lets you specify LLDB type summaries for your own types directly in code. The macro processes the `debugDescription` property, translating simple string interpolations involving stored properties into LLDB type summaries. This allows LLDB to use your custom formatting even when using `p`, and also in Xcode or VSCode’s variable display windows. The macro can use an existing conformance to `CustomDebugStringConvertible`, or you can provide a separate string interpolation only for use in LLDB’s `p` command. Providing a separate LLDB description string is useful if your `CustomDebugStringConvertible` implementation doesn’t meet the requirements of the `@DebugDescription` macro, or if you’re familiar with the [LLDB Summary String syntax](https://lldb.llvm.org/use/variable.html#summary-strings) and you want to use it directly.
130
+
[`@DebugDescription`](https://developer.apple.com/documentation/swift/debugdescription()) is a new macro in the standard library which lets you specify LLDB type summaries for your own types directly in code. The macro processes the `debugDescription` property, translating simple string interpolations involving stored properties into LLDB type summaries. This allows LLDB to use your custom formatting even when using `p`, and also in Xcode or VSCode’s variable display windows. The macro can use an existing conformance to `CustomDebugStringConvertible`, or you can provide a separate string interpolation only for use in LLDB’s `p` command. Providing a separate LLDB description string is useful if your `CustomDebugStringConvertible` implementation doesn’t meet the requirements of the `@DebugDescription` macro, or if you’re familiar with the [LLDB Summary String syntax](https://lldb.llvm.org/use/variable.html#summary-strings) and you want to use it directly.
131
131
132
132
For example, the following code customizes how `po` in LLDB displays the `Organization` type with a conformance to `CustomDebugStringConvertible`, and the `@DebugDescription` macro exposes this custom formatting to the `p` command and the variables view:
Swift Testing takes full advantage of macros. Its `@Test` and `@Suite` attached macros declare test functions and suite types respectively, and they accept arguments (known as traits) to customize various behaviors. The `#expect` and `#require` expression macros validate expected behaviors, and capture rich representation of expressions and their sub-values to produce detailed failure messages.
187
187
188
-
Since Swift Testing is included directly in Swift 6 toolchains, you can `import Testing` without needing to declare a package dependency. This means your tests do not need to build Swift Testing or its dependencies (including swift-syntax), and its macro implementation comes prebuilt. The package manager in Swift 6 automatically builds and runs Swift Testing tests in addition to XCTests (if present), and shows results from both libraries in log output. Swift Testing supports all platforms that Swift officially supports, including all Apple platforms, Linux, and Windows.
188
+
Since Swift Testing is included directly in Swift 6 toolchains, you can `import Testing` without needing to declare a package dependency. This means your tests do not need to build Swift Testing or its dependencies (including swift-syntax), and its macro implementation comes prebuilt. The package manager in Swift 6 automatically builds and runs Swift Testing tests in addition to XCTests (if present), and shows results from both libraries in log output. Swift Testing supports all platforms that Swift officially supports, including all Apple platforms, Linux, and Windows.
189
189
190
190
To learn more about this new open source project, visit the [swift-testing](https://github.com/swiftlang/swift-testing) repository on GitHub, and get involved with its ongoing development [on the forums](https://forums.swift.org/c/related-projects/swift-testing/103).
0 commit comments