From 4df1e3dd56e99c2f3285d2a4d2875995151260ed Mon Sep 17 00:00:00 2001 From: stevapple Date: Thu, 17 Mar 2022 11:30:29 +0800 Subject: [PATCH 1/6] [ChangeLog] Add an entry for SE-0326 --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fcc01bb173ec0..a7b938560ef8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ _**Note:** This is in reverse chronological order, so newer entries are added to ## Swift 5.7 +* [SE-0326][]: + +Parameter and result types can now be inferred from from the body of multi-statement closures. + +Use of multi-statement closures (or simply closures) becomes less cumbersome by removing the need to constantly specify explicit closure types which sometimes could be pretty large e.g. when there are multiple parameters or a complex tuple result type. + * [SE-0343][]: Top-level scripts support asynchronous calls. @@ -9075,6 +9081,7 @@ Swift 1.0 [SE-0322]: [SE-0324]: [SE-0323]: +[SE-0326]: [SE-0327]: [SE-0328]: [SE-0331]: From 1f56e62a7829255422f2b2e45115432213f68821 Mon Sep 17 00:00:00 2001 From: YR Chen Date: Sat, 19 Mar 2022 00:43:44 +0800 Subject: [PATCH 2/6] Update CHANGELOG.md Co-authored-by: Ben Rimmington --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7b938560ef8b..4f9b2ca0f1fa2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ _**Note:** This is in reverse chronological order, so newer entries are added to * [SE-0326][]: -Parameter and result types can now be inferred from from the body of multi-statement closures. +Parameter and result types can now be inferred from the body of multi-statement closures. Use of multi-statement closures (or simply closures) becomes less cumbersome by removing the need to constantly specify explicit closure types which sometimes could be pretty large e.g. when there are multiple parameters or a complex tuple result type. From 945b3275c47e3c3ab726d87cd288231a08a39265 Mon Sep 17 00:00:00 2001 From: stevapple Date: Sat, 19 Mar 2022 00:52:05 +0800 Subject: [PATCH 3/6] [ChangeLog] Fix indentation --- CHANGELOG.md | 223 +++++++++++++++++++++++++-------------------------- 1 file changed, 111 insertions(+), 112 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f9b2ca0f1fa2..a41e97f1bcf1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,60 +7,60 @@ _**Note:** This is in reverse chronological order, so newer entries are added to * [SE-0326][]: -Parameter and result types can now be inferred from the body of multi-statement closures. + Parameter and result types can now be inferred from the body of multi-statement closures. -Use of multi-statement closures (or simply closures) becomes less cumbersome by removing the need to constantly specify explicit closure types which sometimes could be pretty large e.g. when there are multiple parameters or a complex tuple result type. + Use of multi-statement closures (or simply closures) becomes less cumbersome by removing the need to constantly specify explicit closure types which sometimes could be pretty large e.g. when there are multiple parameters or a complex tuple result type. * [SE-0343][]: -Top-level scripts support asynchronous calls. + Top-level scripts support asynchronous calls. -Using an `await` by calling an asynchronous function or accessing an isolated -variable transitions the top-level to an asynchronous context. As an -asynchronous context, top-level variables are `@MainActor`-isolated and the -top-level is run on the `@MainActor`. + Using an `await` by calling an asynchronous function or accessing an isolated + variable transitions the top-level to an asynchronous context. As an + asynchronous context, top-level variables are `@MainActor`-isolated and the + top-level is run on the `@MainActor`. -Note that the transition affects function overload resolution and starts an -implicit run loop to drive the concurrency machinery. + Note that the transition affects function overload resolution and starts an + implicit run loop to drive the concurrency machinery. -Unmodified scripts are not affected by this change unless `-warn-concurrency` is -passed to the compiler invocation. With `-warn-concurrency`, variables in the -top-level are isolated to the main actor and the top-level context is isolated -to the main actor, but is not an asynchronous context. + Unmodified scripts are not affected by this change unless `-warn-concurrency` is + passed to the compiler invocation. With `-warn-concurrency`, variables in the + top-level are isolated to the main actor and the top-level context is isolated + to the main actor, but is not an asynchronous context. * [SE-0336][]: -It is now possible to declare `distributed actor` and `distributed func`s inside of them. + It is now possible to declare `distributed actor` and `distributed func`s inside of them. -Distributed actors provide stronger isolation guarantees than "local" actors, and enable additional checks to be made on return types and parameters of distributed methods, e.g. checking if they conform to `Codable`. Distributed methods can be called on "remote" references of distributed actors, turning those invocations into remote procedure calls, by means of pluggable and user extensible distributed actor system implementations. + Distributed actors provide stronger isolation guarantees than "local" actors, and enable additional checks to be made on return types and parameters of distributed methods, e.g. checking if they conform to `Codable`. Distributed methods can be called on "remote" references of distributed actors, turning those invocations into remote procedure calls, by means of pluggable and user extensible distributed actor system implementations. -Swift does not provide any specific distributed actor system by itself, however, packages in the ecosystem fulfil the role of providing those implementations. + Swift does not provide any specific distributed actor system by itself, however, packages in the ecosystem fulfil the role of providing those implementations. -```swift -distributed actor Greeter { - var greetingsSent = 0 - - distributed func greet(name: String) -> String { - greetingsSent += 1 - return "Hello, \(name)!" + ```swift + distributed actor Greeter { + var greetingsSent = 0 + + distributed func greet(name: String) -> String { + greetingsSent += 1 + return "Hello, \(name)!" + } } -} -func talkTo(greeter: Greeter) async throws { - // isolation of distributed actors is stronger, it is impossible to refer to - // any stored properties of distributed actors from outside of them: - greeter.greetingsSent // distributed actor-isolated property 'name' can not be accessed from a non-isolated context - - // remote calls are implicitly throwing and async, - // to account for the potential networking involved: - let greeting = try await greeter.greet(name: "Alice") - print(greeting) // Hello, Alice! -} -``` + func talkTo(greeter: Greeter) async throws { + // isolation of distributed actors is stronger, it is impossible to refer to + // any stored properties of distributed actors from outside of them: + greeter.greetingsSent // distributed actor-isolated property 'name' can not be accessed from a non-isolated context + + // remote calls are implicitly throwing and async, + // to account for the potential networking involved: + let greeting = try await greeter.greet(name: "Alice") + print(greeting) // Hello, Alice! + } + ``` * The compiler now emits a warning when a non-final class conforms to a protocol that imposes a same-type requirement between `Self` and an associated type. This is because such a requirement makes the conformance unsound for subclasses. -For example, Swift 5.6 would allow the following code, which at runtime would construct an instanec of `C` and not `SubC` as expected: + For example, Swift 5.6 would allow the following code, which at runtime would construct an instanec of `C` and not `SubC` as expected: ```swift protocol P { @@ -168,24 +168,24 @@ Swift 5.6 * [SE-0327][]: -In Swift 5 mode, a warning is now emitted if the default-value expression of an -instance-member property requires global-actor isolation. For example: + In Swift 5 mode, a warning is now emitted if the default-value expression of an + instance-member property requires global-actor isolation. For example: -```swift -@MainActor -func partyGenerator() -> [PartyMember] { fatalError("todo") } + ```swift + @MainActor + func partyGenerator() -> [PartyMember] { fatalError("todo") } -class Party { - @MainActor var members: [PartyMember] = partyGenerator() - // ^~~~~~~~~~~~~~~~ - // warning: expression requiring global actor 'MainActor' cannot - // appear in default-value expression of property 'members' -} -``` + class Party { + @MainActor var members: [PartyMember] = partyGenerator() + // ^~~~~~~~~~~~~~~~ + // warning: expression requiring global actor 'MainActor' cannot + // appear in default-value expression of property 'members' + } + ``` -Previously, the isolation granted by the type checker matched the isolation of -the property itself, but at runtime that is not guaranteed. In Swift 6, -such default-value expressions will become an error if they require isolation. + Previously, the isolation granted by the type checker matched the isolation of + the property itself, but at runtime that is not guaranteed. In Swift 6, + such default-value expressions will become an error if they require isolation. * Actor isolation checking now understands that `defer` bodies share the isolation of their enclosing function. @@ -2010,7 +2010,6 @@ Swift 4.2 needs to have any `init`s from protocols be `required`, which means they need to be in the class definition. - * [SE-0054][] `ImplicitlyUnwrappedOptional` is now an unavailable typealias of `Optional`. @@ -2024,71 +2023,71 @@ Swift 4.2 * [SE-0206][] - The standard library now uses a high-quality, randomly seeded, universal - hash function, represented by the new public `Hasher` struct. - - “Random seeding” varies the result of `hashValue` on each execution of a - Swift program, improving the reliability of the standard library's hashed - collections such as `Set` and `Dictionary`. In particular, random seeding - enables better protection against (accidental or deliberate) hash-flooding - attacks. - - This change fulfills a long-standing prophecy in Hashable's documentation: + The standard library now uses a high-quality, randomly seeded, universal + hash function, represented by the new public `Hasher` struct. - > Hash values are not guaranteed to be equal across different executions of - > your program. Do not save hash values to use during a future execution. - - As a consequence of random seeding, the elements in `Set` and `Dictionary` - values may have a different order on each execution. This may expose some - bugs in existing code that accidentally relies on repeatable ordering. - - Additionally, the `Hashable` protocol now includes an extra function - requirement, `hash(into:)`. The new requirement is designed to be much - easier to implement than the old `hashValue` property, and it generally - provides better hashing. To implement `hash(into:)`, simply feed the exact - same components of your type that you compare in `Equatable`'s `==` - implementation to the supplied `Hasher`: + “Random seeding” varies the result of `hashValue` on each execution of a + Swift program, improving the reliability of the standard library's hashed + collections such as `Set` and `Dictionary`. In particular, random seeding + enables better protection against (accidental or deliberate) hash-flooding + attacks. + + This change fulfills a long-standing prophecy in Hashable's documentation: + + > Hash values are not guaranteed to be equal across different executions of + > your program. Do not save hash values to use during a future execution. + + As a consequence of random seeding, the elements in `Set` and `Dictionary` + values may have a different order on each execution. This may expose some + bugs in existing code that accidentally relies on repeatable ordering. + + Additionally, the `Hashable` protocol now includes an extra function + requirement, `hash(into:)`. The new requirement is designed to be much + easier to implement than the old `hashValue` property, and it generally + provides better hashing. To implement `hash(into:)`, simply feed the exact + same components of your type that you compare in `Equatable`'s `==` + implementation to the supplied `Hasher`: + + ```swift + struct Foo: Hashable { + var a: String? + var b: [Int] + var c: [String: Int] - ```swift - struct Foo: Hashable { - var a: String? - var b: [Int] - var c: [String: Int] - - static func ==(lhs: Foo, rhs: Foo) -> Bool { - return lhs.a == rhs.a && lhs.b == rhs.b && lhs.c == rhs.c - } - - func hash(into hasher: inout Hasher) { - hasher.combine(a) - hasher.combine(b) - hasher.combine(c) - } + static func ==(lhs: Foo, rhs: Foo) -> Bool { + return lhs.a == rhs.a && lhs.b == rhs.b && lhs.c == rhs.c } - ``` - - Automatic synthesis for `Hashable` ([SE-0185]) has been updated to generate - `hash(into:)` implementations. For example, the `==` and `hash(into:)` - implementations above are equivalent to the ones synthesized by the - compiler, and can be removed without changing the meaning of the code. - - Synthesis has also been extended to support deriving `hashValue` from - `hash(into:)`, and vice versa. Therefore, code that only implements - `hashValue` continues to work in Swift 4.2. This new compiler functionality - works for all types that can implement `Hashable`, including classes. - Note that these changes don't affect Foundation's hashing interface. Classes - that subclass `NSObject` should override the `hash` property, like before. - - In certain controlled environments, such as while running particular tests, - it may be helpful to selectively disable hash seed randomization, so that - hash values and the order of elements in `Set`/`Dictionary` values remain - consistent across executions. You can disable hash seed randomization by - defining the environment variable `SWIFT_DETERMINISTIC_HASHING` with the - value of `1`. The Swift runtime looks at this variable during process - startup and, if it is defined, replaces the random seed with a constant - value. + func hash(into hasher: inout Hasher) { + hasher.combine(a) + hasher.combine(b) + hasher.combine(c) + } + } + ``` + + Automatic synthesis for `Hashable` ([SE-0185]) has been updated to generate + `hash(into:)` implementations. For example, the `==` and `hash(into:)` + implementations above are equivalent to the ones synthesized by the + compiler, and can be removed without changing the meaning of the code. + Synthesis has also been extended to support deriving `hashValue` from + `hash(into:)`, and vice versa. Therefore, code that only implements + `hashValue` continues to work in Swift 4.2. This new compiler functionality + works for all types that can implement `Hashable`, including classes. + + Note that these changes don't affect Foundation's hashing interface. Classes + that subclass `NSObject` should override the `hash` property, like before. + + In certain controlled environments, such as while running particular tests, + it may be helpful to selectively disable hash seed randomization, so that + hash values and the order of elements in `Set`/`Dictionary` values remain + consistent across executions. You can disable hash seed randomization by + defining the environment variable `SWIFT_DETERMINISTIC_HASHING` with the + value of `1`. The Swift runtime looks at this variable during process + startup and, if it is defined, replaces the random seed with a constant + value. + * [SR-106][] The behavior of `.description` and `.debugDescription` for floating-point From 7680c18faacad9d57fc2aafbb66b94d2e4c6c9dd Mon Sep 17 00:00:00 2001 From: stevapple Date: Sat, 19 Mar 2022 00:56:41 +0800 Subject: [PATCH 4/6] [ChangeLog] Update "Add new entries" notice --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a41e97f1bcf1b..99d8d4c881179 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -163,6 +163,9 @@ _**Note:** This is in reverse chronological order, so newer entries are added to return [ 1: "One", 2: "Two" ] } ``` + +**Add new entries to the top of this section, not here!** + Swift 5.6 --------- @@ -394,7 +397,6 @@ Swift 5.6 } ``` -**Add new entries to the top of this section, not here!** Swift 5.5 --------- @@ -814,7 +816,6 @@ Swift 5.5 Asynchronous for loops use asynchronous sequences, defined by the protocol `AsyncSequence` and its corresponding `AsyncIterator`. -**Add new entries to the top of this section, not here!** Swift 5.4 --------- @@ -982,7 +983,6 @@ Swift 5.4 let _: Foo? = .bar.anotherFoo.getFoo().optionalFoo?.optionalFoo![] ``` -**Add new entries to the top of this section, not here!** Swift 5.3 --------- From 293c2c1c63dee3f3a6a7fae7536d8ba89b1e29ef Mon Sep 17 00:00:00 2001 From: stevapple Date: Sat, 19 Mar 2022 00:57:53 +0800 Subject: [PATCH 5/6] [ChangeLog] Trim trailing whitespaces --- CHANGELOG.md | 252 +++++++++++++++++++++++++-------------------------- 1 file changed, 126 insertions(+), 126 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99d8d4c881179..05d344e0683f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,14 +32,14 @@ _**Note:** This is in reverse chronological order, so newer entries are added to It is now possible to declare `distributed actor` and `distributed func`s inside of them. - Distributed actors provide stronger isolation guarantees than "local" actors, and enable additional checks to be made on return types and parameters of distributed methods, e.g. checking if they conform to `Codable`. Distributed methods can be called on "remote" references of distributed actors, turning those invocations into remote procedure calls, by means of pluggable and user extensible distributed actor system implementations. + Distributed actors provide stronger isolation guarantees than "local" actors, and enable additional checks to be made on return types and parameters of distributed methods, e.g. checking if they conform to `Codable`. Distributed methods can be called on "remote" references of distributed actors, turning those invocations into remote procedure calls, by means of pluggable and user extensible distributed actor system implementations. Swift does not provide any specific distributed actor system by itself, however, packages in the ecosystem fulfil the role of providing those implementations. ```swift - distributed actor Greeter { + distributed actor Greeter { var greetingsSent = 0 - + distributed func greet(name: String) -> String { greetingsSent += 1 return "Hello, \(name)!" @@ -50,8 +50,8 @@ _**Note:** This is in reverse chronological order, so newer entries are added to // isolation of distributed actors is stronger, it is impossible to refer to // any stored properties of distributed actors from outside of them: greeter.greetingsSent // distributed actor-isolated property 'name' can not be accessed from a non-isolated context - - // remote calls are implicitly throwing and async, + + // remote calls are implicitly throwing and async, // to account for the potential networking involved: let greeting = try await greeter.greet(name: "Alice") print(greeting) // Hello, Alice! @@ -66,23 +66,23 @@ _**Note:** This is in reverse chronological order, so newer entries are added to protocol P { associatedtype A : Q where Self == Self.A.B } - + protocol Q { associatedtype B - + static func getB() -> B } - + class C : P { typealias A = D } - + class D : Q { typealias B = C - + static func getB() -> C { return C() } } - + extension P { static func getAB() -> Self { // This is well-typed, because `Self.A.getB()` returns @@ -90,9 +90,9 @@ _**Note:** This is in reverse chronological order, so newer entries are added to return Self.A.getB() } } - + class SubC : C {} - + // P.getAB() declares a return type of `Self`, so it should // return `SubC`, but it actually returns a `C`. print(SubC.getAB()) @@ -187,7 +187,7 @@ Swift 5.6 ``` Previously, the isolation granted by the type checker matched the isolation of - the property itself, but at runtime that is not guaranteed. In Swift 6, + the property itself, but at runtime that is not guaranteed. In Swift 6, such default-value expressions will become an error if they require isolation. * Actor isolation checking now understands that `defer` bodies share the isolation of their enclosing function. @@ -379,7 +379,7 @@ Swift 5.6 directs the compiler to fill in that portion of the type according to the usual type inference rules. Type placeholders are spelled as an underscore ("`_`") in a type name. For instance: - + ```swift // This is OK--the compiler can infer the key type as `Int`. let dict: [_: String] = [0: "zero", 1: "one", 2: "two"] @@ -393,7 +393,7 @@ Swift 5.6 if #unavailable(iOS 15.0) { // Old functionality } else { - // iOS 15 functionality + // iOS 15 functionality } ``` @@ -486,13 +486,13 @@ Swift 5.5 Task local values can be defined using the new `@TaskLocal` property wrapper. Such values are carried implicitly by the task in which the binding was made, as well as any child-tasks, and unstructured task created from the tasks context. - + ```swift - struct TraceID { + struct TraceID { @TaskLocal - static var current: TraceID? + static var current: TraceID? } - + func printTraceID() { if let traceID = TraceID.current { print("\(traceID)") @@ -500,16 +500,16 @@ Swift 5.5 print("nil") } } - - func run() async { + + func run() async { printTraceID() // prints: nil - TraceID.$current.withValue("1234-5678") { + TraceID.$current.withValue("1234-5678") { printTraceID() // prints: 1234-5678 inner() // prints: 1234-5678 } printTraceID() // prints: nil } - + func inner() { // if called from a context in which the task-local value // was bound, it will print it (or 'nil' otherwise) @@ -519,13 +519,13 @@ Swift 5.5 * [SE-0316][]: - A type can be defined as a global actor. Global actors extend the notion - of actor isolation outside of a single actor type, so that global state - (and the functions that access it) can benefit from actor isolation, - even if the state and functions are scattered across many different - types, functions and modules. Global actors make it possible to safely - work with global variables in a concurrent program, as well as modeling - other global program constraints such as code that must only execute on + A type can be defined as a global actor. Global actors extend the notion + of actor isolation outside of a single actor type, so that global state + (and the functions that access it) can benefit from actor isolation, + even if the state and functions are scattered across many different + types, functions and modules. Global actors make it possible to safely + work with global variables in a concurrent program, as well as modeling + other global program constraints such as code that must only execute on the "main thread" or "UI thread". A new global actor can be defined with the `globalActor` attribute: @@ -602,7 +602,7 @@ Swift 5.5 to reference its metatype, so correct syntax would be to use `obj[MyValue.self]`. * [SE-0310][]: - + Read-only computed properties and subscripts can now define their `get` accessor to be `async` and/or `throws`, by writing one or both of those keywords between the `get` and `{`. Thus, these members can now make asynchronous calls or throw errors in the process of producing a value: ```swift class BankAccount: FinancialAccount { @@ -634,10 +634,10 @@ Swift 5.5 func meetsTransactionLimit(_ limit: Amount) async -> Bool { return try! await self.lastTransaction.amount < limit // ^~~~~~~~~~~~~~~~ this access is async & throws - } + } } - + func hadWithdrawlOn(_ day: Date, from acct: BankAccount) async -> Bool { return await !acct[day].allSatisfy { $0.amount >= Amount.zero } // ^~~~~~~~~ this access is async @@ -948,34 +948,34 @@ Swift 5.4 * [SE-0287][]: Implicit member expressions now support chains of member accesses, making the following valid: - + ```swift let milky: UIColor = .white.withAlphaComponent(0.5) let milky2: UIColor = .init(named: "white")!.withAlphaComponent(0.5) let milkyChance: UIColor? = .init(named: "white")?.withAlphaComponent(0.5) ``` - + As is the case with the existing implicit member expression syntax, the resulting type of the chain must be the same as the (implicit) base, so it is not well-formed to write: - + ```swift let cgMilky: CGColor = .white.withAlphaComponent(0.5).cgColor ``` - + (Unless, of course, appropriate `white` and `withAlphaComponent` members were defined on `CGColor`.) - + Members of a "chain" can be properties, method calls, subscript accesses, force unwraps, or optional chaining question marks. Furthermore, the type of each member along the chain is permitted to differ (again, as long as the base of the chain matches the resulting type) meaning the following successfully typechecks: - + ```swift struct Foo { static var foo = Foo() static var bar = Bar() - + var anotherFoo: Foo { Foo() } func getFoo() -> Foo { Foo() } var optionalFoo: Foo? { Foo() } subscript() -> Foo { Foo() } } - + struct Bar { var anotherFoo = Foo() } @@ -992,7 +992,7 @@ Swift 5.3 * [SE-0279][] & [SE-0286][]: Trailing closure syntax has been extended to allow additional labeled closures to follow the initial unlabeled closure: - + ```swift // Single trailing closure argument UIView.animate(withDuration: 0.3) { @@ -1005,17 +1005,17 @@ Swift 5.3 self.view.removeFromSuperview() } ``` - + Additionally, trailing closure arguments now match the appropriate parameter according to a forward-scan rule (as opposed to the previous backward-scan rule): - + ```swift func takesClosures(first: () -> Void, second: (Int) -> Void = { _ in }) {} - + takesClosures { print("First") } ``` - + In the above example, the trailing closure argument matches parameter `first`, whereas pre-Swift-5.3 it would have matched `second`. In order to ease the transition to this new rule, cases in which the forward-scan and backward-scan match a single trailing closure to different parameters, the backward-scan result is preferred and a warning is emitted. This is expected to be upgraded to an error in the next major version of Swift. * [SR-7083][]: @@ -1032,7 +1032,7 @@ Swift 5.3 ``` Note that the initial value of the property will be forced and made available as the `oldValue` for the `didSet` observer, if the property hasn't been accessed yet. - + ```swift class C { lazy var property: Int = 0 { @@ -1087,16 +1087,16 @@ Swift 5.3 ``` * [SE-0268][]: - + A `didSet` observer which does not refer to the `oldValue` in its body or does not explicitly request it by placing it in the parameter list (i.e. `didSet(oldValue)`) will no longer trigger a call to the property getter to fetch the `oldValue`. - + ```swift class C { var value: Int = 0 { didSet { print("didSet called!") } } } - + let c = C() // This does not trigger a call to the getter for 'value' // because the 'didSet' observer on 'value' does not @@ -1104,7 +1104,7 @@ Swift 5.3 // the 'oldValue' does not need to be fetched. c.value = 1 ``` - + * [SE-0276][]: Catch clauses in a `do`-`catch` statement can now include multiple patterns in a comma-separated list. The body of a `catch` clause will be executed if a thrown error matches any of its patterns. @@ -1119,15 +1119,15 @@ Swift 5.3 ``` * [SE-0280][]: - + Enum cases can now satisfy static protocol requirements. A static get-only property of type `Self` can be witnessed by an enum case with no associated values and a static function with arguments and returning `Self` can be witnessed by an enum case with associated values. - + ```swift protocol P { static var foo: Self { get } static func bar(value: Int) -> Self } - + enum E: P { case foo // matches 'static var foo' case bar(value: Int) // matches 'static func bar(value:)' @@ -1135,7 +1135,7 @@ Swift 5.3 ``` * [SE-0267][]: - + Non-generic members that support a generic parameter list, including nested type declarations, are now allowed to carry a contextual `where` clause against outer generic parameters. Previously, such declarations could only be expressed by placing the member inside a dedicated constrained extension. ```swift @@ -1144,15 +1144,15 @@ Swift 5.3 } ``` Since contextual `where` clauses are effectively visibility constraints, overrides adopting this feature must be at least as visible as the overridden method. In practice, this implies any instance of `Derived` that can access `Base.foo` must also be able to access `Derived.foo`. - + ```swift class Base { func foo() where T == Int { ... } } - + class Derived: Base { // OK, has broader visibility than - override func foo() where U: Equatable { ... } + override func foo() where U: Equatable { ... } } * [SR-75][]: @@ -1170,14 +1170,14 @@ Swift 5.3 ``` * [SE-0266][]: - + Enumerations with no associated values, or only `Comparable` associated values, can opt-in to synthesized `Comparable` conformance by declaring conformance to the `Comparable` protocol. The synthesized implementation orders the cases first by case-declaration order, and then by lexicographic order of the associated values (if any). - + ```swift enum Foo: Comparable { case a(Int), b(Int), c } - + // .a(0) < .a(1) < .b(0) < .b(1) < .c ``` @@ -1186,10 +1186,10 @@ Swift 5.3 When an escaping closure explicitly captures `self` in its capture list, the use of implicit `self` is enabled within that closure. This means that the following code is now valid: - + ```swift func doStuff(_ stuff: @escaping () -> Void) {} - + class C { var x = 0 @@ -1200,7 +1200,7 @@ Swift 5.3 } } ``` - + This proposal also introduces new diagnostics for inserting `self` into the closure's capture list in addition to the existing 'use `self.` explicitly' fix-it. @@ -1214,7 +1214,7 @@ Swift 5.2 When chaining calls to `filter(_:)` on a lazy sequence or collection, the filtering predicates will now be called in the same order as eager filters. - + ```swift let evens = (1...10).lazy .filter { $0.isMultiple(of: 2) } @@ -1222,14 +1222,14 @@ Swift 5.2 _ = evens.count // Prints 2, 4, 6, 8, and 10 on separate lines ``` - + Previously, the predicates were called in reverse order. - + * [SR-2790][]: The compiler will now emit a warning when attempting to pass a temporary pointer argument produced from an array, string, or inout argument to a - parameter which is known to escape it. This includes the various initializers + parameter which is known to escape it. This includes the various initializers for the `UnsafePointer`/`UnsafeBufferPointer` family of types, as well as memberwise initializers. @@ -1241,13 +1241,13 @@ Swift 5.2 func foo() { var i: Int8 = 0 let ptr = UnsafePointer(&i) - // warning: initialization of 'UnsafePointer' results in a + // warning: initialization of 'UnsafePointer' results in a // dangling pointer - - let s1 = S(ptr: [1, 2, 3]) + + let s1 = S(ptr: [1, 2, 3]) // warning: passing '[Int8]' to parameter, but argument 'ptr' should be a // pointer that outlives the call to 'init(ptr:)' - + let s2 = S(ptr: "hello") // warning: passing 'String' to parameter, but argument 'ptr' should be a // pointer that outlives the call to 'init(ptr:)' @@ -1277,30 +1277,30 @@ Swift 5.2 The compiler will now correctly strip argument labels from function references used with the `as` operator in a function call. As a result, the `as` operator - can now be used to disambiguate a call to a function with argument labels. - + can now be used to disambiguate a call to a function with argument labels. + ```swift func foo(x: Int) {} func foo(x: UInt) {} - + (foo as (Int) -> Void)(5) // Calls foo(x: Int) (foo as (UInt) -> Void)(5) // Calls foo(x: UInt) ``` - + Previously this was only possible for functions without argument labels. - + This change also means that a generic type alias can no longer be used to preserve the argument labels of a function reference through the `as` operator. The following is now rejected: - + ```swift typealias Magic = T func foo(x: Int) {} (foo as Magic)(x: 5) // error: Extraneous argument label 'x:' in call ``` - + The function value must instead be called without argument labels: - + ```swift (foo as Magic)(5) ``` @@ -1350,21 +1350,21 @@ Swift 5.2 * `mutating func callAsFunction` is supported. * `func callAsFunction` works with `throws` and `rethrows`. * `func callAsFunction` works with trailing closures. - + * [SE-0249][]: - A `\Root.value` key path expression is now allowed wherever a `(Root) -> Value` - function is allowed. Such an expression is implicitly converted to a key path + A `\Root.value` key path expression is now allowed wherever a `(Root) -> Value` + function is allowed. Such an expression is implicitly converted to a key path application of `{ $0[keyPath: \Root.value] }`. - + For example: - + ```swift struct User { let email: String let isAdmin: Bool } - + users.map(\.email) // this is equivalent to: users.map { $0[keyPath: \User.email] } ``` @@ -1375,11 +1375,11 @@ Swift 5.2 ```swift protocol P {} - + class Base { func foo(arg: T) {} } - + class Derived: Base { override func foo(arg: T) {} } @@ -1419,7 +1419,7 @@ Swift 5.1 let f: Foo = .bar(x: 0, x: 1) ``` - will now be diagnosed as an error. + will now be diagnosed as an error. Note: You can still use duplicate argument labels when declaring functions and subscripts, as long as the internal parameter names are different. For example: @@ -1482,7 +1482,7 @@ Swift 5.1 While most code should not be affected, there are edge cases where the Swift 5.0 compiler would accept code violating these restrictions. This could result in runtime crashes or silent data corruption. - + An example of invalid code which was incorrectly accepted by the Swift 5.0 compiler is an `@escaping` closure calling a local function which references an `inout` parameter from an outer scope: @@ -1549,7 +1549,7 @@ Swift 5.1 It is now possible to use `Self` to refer to the innermost nominal type inside struct, enum and class declarations. For example, the two method declarations inside this struct are equivalent: - + ```swift struct Box { func transform1() -> Self { return self } @@ -1650,20 +1650,20 @@ Swift 5.0 * [SE-0235][]: The standard library now contains a `Result` type for manually propagating errors. - + ```swift enum Result { case success(Success) case failure(Failure) } ``` - - This type serves a complementary role to that of throwing functions and initializers. - Use `Result` in situations where automatic error propagation or `try`-`catch` - blocks are undesirable, such as in asynchronous code or when accumulating the + + This type serves a complementary role to that of throwing functions and initializers. + Use `Result` in situations where automatic error propagation or `try`-`catch` + blocks are undesirable, such as in asynchronous code or when accumulating the results of successive error-producing operations. - -* `Error` now conforms to itself. This allows for the use of `Error` itself as + +* `Error` now conforms to itself. This allows for the use of `Error` itself as the argument for a generic parameter constrained to `Error`. * Swift 3 mode has been removed. Supported values for the `-swift-version` @@ -1678,7 +1678,7 @@ Swift 5.0 removed; any code making use of this protocol will need to be updated for the new design. An `#if compiler` block can be used to conditionalize code between 4.2 and 5.0, for example: - + ```swift #if compiler(<5.0) extension MyType : _ExpressibleByStringInterpolation { ... } @@ -1807,13 +1807,13 @@ Swift 5.0 In Swift 5 mode, attempting to declare a static property with the same name as a nested type is now always correctly rejected. Previously, it was possible to perform such a redeclaration in an extension of a generic type. - + For example: ```swift struct Foo {} extension Foo { struct i {} - + // compiler error: Invalid redeclaration of 'i' // (prior to Swift 5, this did not produce an error) static var i: Int { return 0 } @@ -1823,10 +1823,10 @@ Swift 5.0 * [SR-4248][]: In Swift 5 mode, when casting an optional value to a generic placeholder type, - the compiler will be more conservative with the unwrapping of the value. The + the compiler will be more conservative with the unwrapping of the value. The result of such a cast now more closely matches the result you would get in a non-generic context. - + For example: ```swift func forceCast(_ value: Any?, to type: U.Type) -> U { @@ -1834,11 +1834,11 @@ Swift 5.0 } let value: Any? = 42 - print(forceCast(value, to: Any.self)) + print(forceCast(value, to: Any.self)) // prints: Optional(42) // (prior to Swift 5, this would print: 42) - - print(value as! Any) + + print(value as! Any) // prints: Optional(42) ``` @@ -1917,16 +1917,16 @@ Swift 4.2 The standard library now provides a unified set of randomization functionality. Integer types, floating point types, and Bool all introduce a new static method that creates a random value. - + ```swift let diceRoll = Int.random(in: 1 ... 6) let randomUnit = Double.random(in: 0 ..< 1) let randomBool = Bool.random() ``` - + There are also additions to select a random element from a collection or shuffle its contents. - + ```swift let greetings = ["hey", "hello", "hi", "hola"] let randomGreeting = greetings.randomElement()! // This returns an Optional @@ -1939,14 +1939,14 @@ Swift 4.2 thread-safe random number generator on each platform. All the randomization functions have a `using:` parameter that take a `RandomNumberGenerator` that users can pass in their own random number generator. - + ```swift struct MersenneTwister: RandomNumberGenerator { func next() -> UInt64 { // implementation } } - + var mt = MersenneTwister() let diceRoll = Int.random(in: 1 ... 6, using: &mt) ``` @@ -2036,7 +2036,7 @@ Swift 4.2 > Hash values are not guaranteed to be equal across different executions of > your program. Do not save hash values to use during a future execution. - + As a consequence of random seeding, the elements in `Set` and `Dictionary` values may have a different order on each execution. This may expose some bugs in existing code that accidentally relies on repeatable ordering. @@ -2047,17 +2047,17 @@ Swift 4.2 provides better hashing. To implement `hash(into:)`, simply feed the exact same components of your type that you compare in `Equatable`'s `==` implementation to the supplied `Hasher`: - + ```swift struct Foo: Hashable { var a: String? var b: [Int] var c: [String: Int] - + static func ==(lhs: Foo, rhs: Foo) -> Bool { return lhs.a == rhs.a && lhs.b == rhs.b && lhs.c == rhs.c } - + func hash(into hasher: inout Hasher) { hasher.combine(a) hasher.combine(b) @@ -2065,17 +2065,17 @@ Swift 4.2 } } ``` - + Automatic synthesis for `Hashable` ([SE-0185]) has been updated to generate `hash(into:)` implementations. For example, the `==` and `hash(into:)` implementations above are equivalent to the ones synthesized by the compiler, and can be removed without changing the meaning of the code. - + Synthesis has also been extended to support deriving `hashValue` from `hash(into:)`, and vice versa. Therefore, code that only implements `hashValue` continues to work in Swift 4.2. This new compiler functionality works for all types that can implement `Hashable`, including classes. - + Note that these changes don't affect Foundation's hashing interface. Classes that subclass `NSObject` should override the `hash` property, like before. @@ -2124,7 +2124,7 @@ Swift 4.2 available for types that include stored properties of these types. * [SE-0196][] - + Custom compile-time warnings or error messages can be emitted using the `#warning(_:)` and `#error(_:)` directives. @@ -2164,8 +2164,8 @@ Swift 4.1 Compile-time testing for the existence and importability of modules is now implemented as a build configuration test. The `canImport` test allows - the development of features that require a possibly-failing import - declaration across multiple platforms. + the development of features that require a possibly-failing import + declaration across multiple platforms. ```swift #if canImport(UIKit) @@ -2203,11 +2203,11 @@ Swift 4.1 conditional conformances, available only when their type parameters conform to `Encodable` or `Decodable`, respectively. -* [SE-0188][] - - Index types for most standard library collections now conform to `Hashable`. +* [SE-0188][] + + Index types for most standard library collections now conform to `Hashable`. These indices can now be used in key-path subscripts and hashed collections: - + ```swift let s = "Hashable" let p = \String.[s.startIndex] From a7f49cb085f93d68c8cef3995e1470ccebe5d62c Mon Sep 17 00:00:00 2001 From: stevapple Date: Sat, 19 Mar 2022 01:03:48 +0800 Subject: [PATCH 6/6] [ChangeLog] Add missing colons --- CHANGELOG.md | 62 ++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05d344e0683f7..e7e58b372d00e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1861,7 +1861,7 @@ Swift 5.0 The `DictionaryLiteral` type has been renamed to `KeyValuePairs`. A typealias preserves the old name for compatibility. -* [SR-2608][] +* [SR-2608][]: Default arguments are now printed in SourceKit-generated interfaces for Swift modules, instead of just using a placeholder `default`. @@ -1877,7 +1877,7 @@ Swift 5.0 * Complex recursive type definitions involving classes and generics that would previously cause deadlocks at run time are now fully supported. -* [SR-419][] +* [SR-419][]: In Swift 5 mode, when setting a property from within its own `didSet` or `willSet` observer, the observer will now only avoid being recursively called @@ -1912,7 +1912,7 @@ Swift 4.2 ### 2018-09-17 (Xcode 10.0) -* [SE-0202][] +* [SE-0202][]: The standard library now provides a unified set of randomization functionality. Integer types, floating point types, and Bool all introduce a new static @@ -1951,7 +1951,7 @@ Swift 4.2 let diceRoll = Int.random(in: 1 ... 6, using: &mt) ``` -* [SE-0194][] +* [SE-0194][]: The new CaseIterable protocol describes types which have a static “allCases” property that is used to describe all of the cases of the @@ -1969,7 +1969,7 @@ Swift 4.2 print(Suit.allCases) // prints [Suit.heart, Suit.club, Suit.diamond, Suit.spade] ``` -* [SE-0185][] +* [SE-0185][]: Protocol conformances are now able to be synthesized in extensions in the same file as the type definition, allowing automatic synthesis of conditional @@ -2010,7 +2010,7 @@ Swift 4.2 needs to have any `init`s from protocols be `required`, which means they need to be in the class definition. -* [SE-0054][] +* [SE-0054][]: `ImplicitlyUnwrappedOptional` is now an unavailable typealias of `Optional`. Declarations annotated with `!` have the type `Optional`. If an @@ -2021,7 +2021,7 @@ Swift 4.2 need to be adjusted. Please see [this blog post](https://swift.org/blog/iuo/) for more information. -* [SE-0206][] +* [SE-0206][]: The standard library now uses a high-quality, randomly seeded, universal hash function, represented by the new public `Hasher` struct. @@ -2088,7 +2088,7 @@ Swift 4.2 startup and, if it is defined, replaces the random seed with a constant value. -* [SR-106][] +* [SR-106][]: The behavior of `.description` and `.debugDescription` for floating-point numbers has been changed. Previously these unconditionally printed a fixed @@ -2097,7 +2097,7 @@ Swift 4.2 convert back to the original source value, and no more. For more details, see the original bug report and the linked pull request. -* [SE-0193][] +* [SE-0193][]: Various function-like declarations can now be marked as `@inlinable`, making their bodies available for optimizations from other modules. @@ -2115,7 +2115,7 @@ Swift 4.2 functions have been made generic over `[Binary]FloatingPoint` so that they will automatically be available for any conforming type. -* [SE-0143][] +* [SE-0143][]: The standard library types `Optional`, `Array`, `ArraySlice`, `ContiguousArray`, `Dictionary`, `Range`, and `ClosedRange` now conform to the @@ -2123,7 +2123,7 @@ Swift 4.2 conform to `Hashable`. This makes synthesized `Hashable` implementations available for types that include stored properties of these types. -* [SE-0196][] +* [SE-0196][]: Custom compile-time warnings or error messages can be emitted using the `#warning(_:)` and `#error(_:)` directives. @@ -2148,7 +2148,7 @@ Swift 4.2 circumstances with very simple values, so this is unlikely to affect real-world code.) -* [SE-0143][] +* [SE-0143][]: Runtime query of conditional conformances is now implemented. Therefore, a dynamic cast such as `value as? P`, where the dynamic type of `value` @@ -2160,7 +2160,7 @@ Swift 4.1 ### 2018-03-29 (Xcode 9.3) -* [SE-0075][] +* [SE-0075][]: Compile-time testing for the existence and importability of modules is now implemented as a build configuration test. The `canImport` test allows @@ -2179,7 +2179,7 @@ Swift 4.1 #endif ``` -* [SE-0189][] +* [SE-0189][]: If an initializer is declared in a different module from a struct, it must use `self.init(…)` or `self = …` before returning or accessing `self`. @@ -2196,14 +2196,14 @@ Swift 4.1 per-member basis should explicitly declare a public memberwise initializer for clients in other modules to use. -* [SE-0166][] / [SE-0143][] +* [SE-0166][] / [SE-0143][]: The standard library now defines the conformances of `Optional`, `Array`, `Dictionary`, and `Set` to `Encodable` and `Decodable` as conditional conformances, available only when their type parameters conform to `Encodable` or `Decodable`, respectively. -* [SE-0188][] +* [SE-0188][]: Index types for most standard library collections now conform to `Hashable`. These indices can now be used in key-path subscripts and hashed collections: @@ -2255,7 +2255,7 @@ Swift 4.1 * [SE-0161][] is fully implemented. KeyPaths now support subscript, optional chaining, and optional force-unwrapping components. -* [SE-0186][] +* [SE-0186][]: It is no longer valid to use the ownership keywords `weak` and `unowned` for property declarations in protocols. These keywords are meaningless and misleading when used in a protocol as they don't have any effect. @@ -2270,7 +2270,7 @@ Swift 4.1 } ``` -* [SE-0185][] +* [SE-0185][]: Structs and enums that declare a conformance to `Equatable`/`Hashable` now get an automatically synthesized implementation of `==`/`hashValue`. For structs, all stored properties must be `Equatable`/`Hashable`. For enums, all enum cases with associated values must be `Equatable`/`Hashable`. @@ -2307,7 +2307,7 @@ Swift 4.0 ### 2017-09-19 (Xcode 9.0) -* [SE-0165][] and [SE-0154][] +* [SE-0165][] and [SE-0154][]: The standard library's `Dictionary` and `Set` types have some new features. You can now create a new dictionary from a sequence of keys and values, and merge keys and values into an existing dictionary. @@ -2377,7 +2377,7 @@ Swift 4.0 `#if swift(>=3.2)` to restrict the extension to Swift 3.1 and below. ([SR-2388][]) -* [SE-0156][] +* [SE-0156][]: Protocol composition types can now contain one or more class type terms, forming a class-constrained protocol composition. @@ -2441,7 +2441,7 @@ Swift 4.0 These missing aspects of the proposal can be introduced in a future release without breaking source compatibility with existing code. -* [SE-0142][] +* [SE-0142][]: Protocols and associated types can now contain `where` clauses that provide additional restrictions on associated types. For example: @@ -2456,7 +2456,7 @@ Swift 4.0 } ``` -* [SE-0160][] +* [SE-0160][]: In Swift 4 mode, a declaration is inferred to be `@objc` where it is required for semantic consistency of the programming model. Specifically, it is inferred when: @@ -2607,7 +2607,7 @@ Swift 3.1 side effects, leading to bugs when Swift code attempted to override `initialize`. -* [SR-2394][] +* [SR-2394][]: C functions that "return twice" are no longer imported into Swift. Instead, they are explicitly made unavailable, so attempting to reference them will @@ -2684,7 +2684,7 @@ Swift 3.1 is not guaranteed to work in future versions of Swift, and will now raise a warning. -* [SR-1446][] +* [SR-1446][]: Nested types may now appear inside generic types, and nested types may have their own generic parameters: @@ -3289,11 +3289,11 @@ using the `.dynamicType` member to retrieve the type of an expression should mig * The "none" members of imported NS_OPTIONS option sets are marked as unavailable when they are imported. Use `[]` to make an empty option set, instead of a None member. -* [SE-0043][] +* [SE-0043][]: Adds the ability to declare variables in multiple patterns in cases. -* [SE-0005][] +* [SE-0005][]: Allows the Clang importer to import ObjC symbols using substantially different Swift-like naming paradigms: @@ -3304,7 +3304,7 @@ using the `.dynamicType` member to retrieve the type of an expression should mig * Non-type values, including enumerators, are lowercased. * Classes that implement `compare(_:) -> NSComparisonResult` automatically import as `Comparable`. -* [SE-0040][] +* [SE-0040][]: Attributes change from using `=` in parameters lists to using `:`, aligning with function call syntax. @@ -3317,7 +3317,7 @@ using the `.dynamicType` member to retrieve the type of an expression should mig @available(*, unavailable, renamed: "MyRenamedProtocol") ``` -* [SE-0048][] +* [SE-0048][]: Generic typealiases are now supported. For example: @@ -3330,7 +3330,7 @@ using the `.dynamicType` member to retrieve the type of an expression should mig etc. -* [SE-0049][] +* [SE-0049][]: The `@noescape` attribute is extended to be a more general type attribute. You can now declare values of `@noescape` function type, e.g. in manually curried function signatures. You can now also declare local variables of `@noescape` type, and use `@noescape` in `typealiases`. For example, this is now valid code: @@ -3341,12 +3341,12 @@ using the `.dynamicType` member to retrieve the type of an expression should mig } ``` -* [SE-0034][] +* [SE-0034][]: The `#line` directive (which resets the logical source location for diagnostics and debug information) is renamed to `#sourceLocation`. -* [SE-0002][] +* [SE-0002][]: Curried function syntax (with successive parenthesized groups of arguments) is removed, and now produces a compile-time error. Use chained functional return types instead.