|
5 | 5 |
|
6 | 6 | ## Swift 6.2 |
7 | 7 |
|
| 8 | +* The Swift compiler no longer diagnoses references to declarations that are |
| 9 | + potentially unavailable because the platform version might not be new enough |
| 10 | + when those references occur inside of contexts that are also unavailable to |
| 11 | + that platform. This addresses a long-standing nuisance for multi-platform |
| 12 | + code. However, there is also a chance that existing source code may become |
| 13 | + ambiguous as a result: |
| 14 | + |
| 15 | + ```swift |
| 16 | + struct A {} |
| 17 | + struct B {} |
| 18 | + |
| 19 | + func potentiallyAmbiguous(_: A) {} |
| 20 | + |
| 21 | + @available(macOS 99, *) |
| 22 | + func potentiallyAmbiguous(_: B) {} |
| 23 | + |
| 24 | + @available(macOS, unavailable) |
| 25 | + func unavailableOnMacOS() { |
| 26 | + potentiallyAmbiguous(.init()) // error: ambiguous use of 'init()' |
| 27 | + } |
| 28 | + ``` |
| 29 | + |
| 30 | + Code that is now ambiguous as a result should likely be restructured since |
| 31 | + disambiguation based on platform introduction alone has never been a reliable |
| 32 | + strategy, given that the code would eventually become ambiguous anyways when |
| 33 | + the deployment target is raised. |
| 34 | + |
| 35 | +* [SE-0470][]: |
| 36 | + A protocol conformance can be isolated to a specific global actor, meaning that the conformance can only be used by code running on that actor. Isolated conformances are expressed by specifying the global actor on the conformance itself: |
| 37 | + |
| 38 | + ```swift |
| 39 | + protocol P { |
| 40 | + func f() |
| 41 | + } |
| 42 | + |
| 43 | + @MainActor |
| 44 | + class MyType: @MainActor P { |
| 45 | + /*@MainActor*/ func f() { |
| 46 | + // must be called on the main actor |
| 47 | + } |
| 48 | + } |
| 49 | + ``` |
| 50 | + |
| 51 | + Swift will produce diagnostics if the conformance is directly accessed in code that isn't guaranteed to execute in the same global actor. For example: |
| 52 | + |
| 53 | + ```swift |
| 54 | + func acceptP<T: P>(_ value: T) { } |
| 55 | + |
| 56 | + /*nonisolated*/ func useIsolatedConformance(myType: MyType) { |
| 57 | + acceptP(myType) // error: main actor-isolated conformance of 'MyType' to 'P' cannot be used in nonisolated context |
| 58 | + } |
| 59 | + ``` |
| 60 | + |
| 61 | + To address such issues, only use an isolated conformance from code that executes on the same global actor. |
| 62 | + |
8 | 63 | * [SE-0419][]: |
9 | 64 | Introduced the new `Runtime` module, which contains a public API that can |
10 | 65 | generate backtraces, presently supported on macOS and Linux. Capturing a |
@@ -10732,6 +10787,7 @@ using the `.dynamicType` member to retrieve the type of an expression should mig |
10732 | 10787 | [SE-0442]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0442-allow-taskgroup-childtaskresult-type-to-be-inferred.md |
10733 | 10788 | [SE-0444]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md |
10734 | 10789 | [SE-0458]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0458-strict-memory-safety.md |
| 10790 | +[SE-0470]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0470-isolated-conformances.md |
10735 | 10791 | [#64927]: <https://github.com/apple/swift/issues/64927> |
10736 | 10792 | [#42697]: <https://github.com/apple/swift/issues/42697> |
10737 | 10793 | [#42728]: <https://github.com/apple/swift/issues/42728> |
|
0 commit comments