@@ -24,6 +24,86 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
2424 }
2525 ```
2626
27+ * [ SE-0309] [ ] :
28+
29+ Protocols with associated types and ` Self ` requirements can now be used as the
30+ types of values with the ` any ` keyword.
31+
32+ Protocol methods that return associated types can be called on an ` any ` type;
33+ the result is type-erased to the associated type's upper bound, which is another
34+ ` any ` type having the same constraints as the associated type. For example:
35+
36+ ``` swift
37+ protocol Surface {... }
38+
39+ protocol Solid {
40+ associatedtype SurfaceType : Surface
41+ func boundary () -> SurfaceType
42+ }
43+
44+ let solid: any Solid = ...
45+
46+ // Type of 'boundary' is 'any Surface'
47+ let boundary = solid.boundary ()
48+ ```
49+
50+ Protocol methods that take an associated type or ` Self ` cannot be used with ` any ` ,
51+ however in conjunction with [ SE-0352] [ ] , you can pass the ` any ` type to a function
52+ taking a generic parameter constrained to the protocol. Within the generic context,
53+ type relationships are explicit and all protocol methods can be used.
54+
55+ * [ SE-0346] [ ] :
56+
57+ Protocols can now declare a list of one or more primary associated types:
58+
59+ ``` swift
60+ protocol Graph <Vertex, Edge> {
61+ associatedtype Vertex
62+ associatedtype Edge
63+ }
64+ ```
65+
66+ A protocol-constrained type like ` Graph<Int> ` can now be written anywhere that
67+ expects the right-hand side of a protocol conformance requirement:
68+
69+ ``` swift
70+ func shortestPath <V , E >(_ : some Graph<V>, from : V, to : V) -> [E]
71+
72+ extension Graph<Int > {... }
73+
74+ func build () -> some Graph<String > {}
75+ ```
76+
77+ A protocol-constrained type is equivalent to a conformance requirement to the protocol
78+ itself together with a same-type requirement constraining the primary associated type.
79+ The first two examples above are equivalent to the following:
80+
81+ ``` swift
82+ func shortestPath <V , E , G >(_ : G, from : V, to : V) -> [E]
83+ where G: Graph, G.Vertex == V, G.Edge == V
84+
85+ extension Graph where Vertex == Int {... }
86+ ```
87+
88+ The ` build() ` function returning ` some Graph<String> ` cannot be written using a ` where `
89+ clause; this is an example of a constrained opaque result type, which could not be written
90+ before.
91+
92+ * [ SE-0353] [ ] :
93+
94+ Further generalizing the above, protocol-constrained types can also be used with ` any ` :
95+
96+ ``` swift
97+ func findBestGraph (_ : [any Graph<Int >]) -> any Graph<Int > {... }
98+ ```
99+
100+ * [ SE-0358] [ ] :
101+
102+ Various protocols in the standard library now declare primary associated types, for
103+ example ` Sequence ` and ` Collection ` declare a single primary associated type ` Element ` .
104+ For example, this allows writing down the types ` some Collection<Int> ` and
105+ ` any Collection<Int> ` .
106+
27107* References to ` optional ` methods on a protocol metatype, as well as references to dynamically looked up methods on the ` AnyObject ` metatype are now supported. These references always have the type of a function that accepts a single argument and returns an optional value of function type:
28108
29109 ``` swift
@@ -112,7 +192,7 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
112192 in places that would previously fail because `any` types do not conform
113193 to their protocols. For example:
114194
115- ```
195+ ```swift
116196 protocol P {
117197 associatedtype A
118198 func getA () -> A
@@ -349,7 +429,7 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
349429
350430* [ SE-0328] [ ] :
351431
352- Opaque types (expressed with ' some' ) can now be used in structural positions
432+ Opaque types (expressed with ` some ` ) can now be used in structural positions
353433 within a result type, including having multiple opaque types in the same
354434 result. For example:
355435
@@ -832,7 +912,7 @@ Swift 5.5
832912 }
833913
834914
835- func hadWithdrawlOn (_ day : Date, from acct : BankAccount) async -> Bool {
915+ func hadWithdrawalOn (_ day : Date, from acct : BankAccount) async -> Bool {
836916 return await ! acct[day].allSatisfy { $0 .amount >= Amount.zero }
837917 // ^~~~~~~~~ this access is async
838918 }
@@ -961,7 +1041,7 @@ Swift 5.5
9611041 }
9621042 ```
9631043
964- * The ' lazy' keyword now works in local contexts, making the following valid:
1044+ * The ` lazy ` keyword now works in local contexts, making the following valid:
9651045
9661046 ``` swift
9671047 func test (useIt : Bool ) {
@@ -2807,7 +2887,7 @@ Swift 3.1
28072887 result in a compilation error.
28082888
28092889 Examples of functions that " return twice" include `vfork` and `setjmp`.
2810- These functions change the control flow of a program in ways that that Swift
2890+ These functions change the control flow of a program in ways that Swift
28112891 has never supported. For example, definitive initialization of variables,
28122892 a core Swift language feature, could not be guaranteed when these functions
28132893 were used.
@@ -2920,7 +3000,7 @@ Swift 3.0
29203000
29213001* [SE- 0101 ][]:
29223002
2923- The functions `sizeof ()`, `strideof ()`, and `alignof ()` have been removed.
3003+ The functions `sizeof ()`, `strideof ()`, and `alignof ()` have been removed.
29243004 Memory layout properties for a type `T` are now spelled
29253005 `MemoryLayout < T> .size `, `MemoryLayout < T> .stride `, and
29263006 `MemoryLayout < T> .alignment `, respectively.
@@ -2962,7 +3042,7 @@ Swift 3.0
29623042
29633043* [SE- 0124 ][]:
29643044
2965- Initializers on `Int ` and `UInt ` that accept an `ObjectIdentifier ` must now use an explicit `bitPattern` label.
3045+ Initializers on `Int ` and `UInt ` that accept an `ObjectIdentifier ` must now use an explicit `bitPattern` label.
29663046
29673047 ```swift
29683048 let x: ObjectIdentifier = ...
@@ -3218,7 +3298,7 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
32183298 didFailToRegisterForRemoteNotificationsWithError error: NSError)
32193299 ```
32203300
3221- Now it accepts an `Error ` argument:
3301+ Now it accepts an `Error ` argument:
32223302
32233303 ```swift
32243304 optional func application (_ application: UIApplication,
@@ -3441,7 +3521,7 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
34413521 foo/* comment */ ! // no longer works
34423522 ```
34433523
3444- Parse errors resulting from this change can be resolved by moving the comment outside the expression.
3524+ Parse errors resulting from this change can be resolved by moving the comment outside the expression.
34453525
34463526* [SE- 0031 ][]:
34473527
@@ -3502,7 +3582,7 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
35023582 Attributes change from using `= ` in parameters lists
35033583 to using `: `, aligning with function call syntax.
35043584
3505- ```
3585+ ```swift
35063586 // before
35073587 @available (* , unavailable , renamed="MyRenamedProtocol")
35083588
@@ -3543,13 +3623,13 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
35433623
35443624 Curried function syntax (with successive parenthesized groups of arguments) is removed, and now produces a compile- time error. Use chained functional return types instead.
35453625
3546- ```
3547- // Before
3548- public func project (function f: FunctionType)(p0 : CGPoint, p1 : CGPoint)(x : CGFloat) -> CGPoint
3626+ ```swift
3627+ // Before
3628+ public func project (function f: FunctionType)(p0 : CGPoint, p1 : CGPoint)(x : CGFloat) -> CGPoint
35493629
3550- // After
3551- public func project (function f: FunctionType) -> (p0 : CGPoint, p1 : CGPoint) -> (x : CGFloat) -> CGPoint
3552- ```
3630+ // After
3631+ public func project (function f: FunctionType) -> (p0 : CGPoint, p1 : CGPoint) -> (x : CGFloat) -> CGPoint
3632+ ```
35533633
35543634* Generic signatures can now contain superclass requirements with generic parameter types, for example:
35553635
@@ -4896,11 +4976,15 @@ Swift 1.2
48964976* The `@autoclosure ` attribute is now an attribute on a parameter, not an
48974977 attribute on the parameter's type.
48984978
4899- Where before you might have used:
4979+ Where before you might have used
49004980
49014981 ```swift
49024982 func assert (predicate : @autoclosure () -> Bool ) {... }
4903- you now write this as :
4983+ ```
4984+
4985+ you now write this as
4986+
4987+ ```swift
49044988 func assert (@autoclosure predicate : () -> Bool ) {... }
49054989 ```
49064990
@@ -4942,7 +5026,11 @@ Swift 1.2
49425026 // redeclares Objective-C method
49435027 // 'setProperty:'
49445028 }
5029+ ```
5030+
49455031 Similar checking applies to accidental overrides in the Objective- C runtime:
5032+
5033+ ```swift
49465034 class B : NSObject {
49475035 func method (arg : String ) { } // note: overridden declaration
49485036 // here has type '(String) -> ()'
@@ -4953,7 +5041,11 @@ Swift 1.2
49535041 // selector 'method:' has incompatible
49545042 // type '([String]) -> ()'
49555043 }
5044+ ```
5045+
49565046 as well as protocol conformances:
5047+
5048+ ```swift
49575049 class MyDelegate : NSObject, NSURLSessionDelegate {
49585050 func URLSession (session : NSURLSession, didBecomeInvalidWithError :
49595051 Bool ){ } // error: Objective-C method 'URLSession:didBecomeInvalidWithError:'
@@ -5041,13 +5133,17 @@ Swift 1.2
50415133 that used `unsafeBitCast` as a workaround for this issue can be written to
50425134 use the raw value initializer.
50435135
5044- For example:
5136+ For example,
50455137
50465138 ```swift
50475139 let animationCurve =
50485140 unsafeBitCast (userInfo[UIKeyboardAnimationCurveUserInfoKey].integerValue ,
50495141 UIViewAnimationCurve.self )
5050- can now be written instead as :
5142+ ```
5143+
5144+ can now be written instead as
5145+
5146+ ```swift
50515147 let animationCurve = UIViewAnimationCurve (rawValue :
50525148 userInfo[UIKeyboardAnimationCurveUserInfoKey].integerValue )!
50535149 ```
@@ -9117,7 +9213,7 @@ Swift 1.0
91179213[SE- 0107 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0107-unsaferawpointer.md>
91189214[SE- 0108 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0108-remove-assoctype-inference.md>
91199215[SE- 0109 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0109-remove-boolean.md>
9120- [SE- 0110 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0110-distingish -single-tuple-arg.md>
9216+ [SE- 0110 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0110-distinguish -single-tuple-arg.md>
91219217[SE- 0111 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0111-remove-arg-label-type-significance.md>
91229218[SE- 0112 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0112-nserror-bridging.md>
91239219[SE- 0113 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0113-rounding-functions-on-floatingpoint.md>
@@ -9264,6 +9360,7 @@ Swift 1.0
92649360[SE- 0300 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0300-continuation.md>
92659361[SE- 0302 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0302-concurrent-value-and-concurrent-closures.md>
92669362[SE- 0306 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0306-actors.md>
9363+ [SE- 0309 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0309-unlock-existential-types-for-all-protocols.md>
92679364[SE- 0310 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0310-effectful-readonly-properties.md>
92689365[SE- 0311 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0311-task-locals.md>
92699366[SE- 0313 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0313-actor-isolation-control.md>
@@ -9287,9 +9384,12 @@ Swift 1.0
92879384[SE- 0341 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0341-opaque-parameters.md>
92889385[SE- 0343 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0343-top-level-concurrency.md>
92899386[SE- 0345 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0345-if-let-shorthand.md>
9387+ [SE- 0346 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0346-light-weight-same-type-syntax.md>
92909388[SE- 0347 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0347-type-inference-from-default-exprs.md>
92919389[SE- 0349 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0349-unaligned-loads-and-stores.md>
92929390[SE- 0352 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0352-implicit-open-existentials.md>
9391+ [SE- 0353 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0353-constrained-existential-types.md>
9392+ [SE- 0358 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0358-primary-associated-types-in-stdlib.md>
92939393
92949394[SR- 75 ]: < https: // bugs.swift.org/browse/SR-75>
92959395[SR- 106 ]: < https: // bugs.swift.org/browse/SR-106>
0 commit comments