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
[SE-0418] Refine grammar errors and enhance code clarity (#2265)
* Correct grammar errors for improved clarity
* Enhance code clarity by refactoring to Swift syntax
* Adjust spacing and remove extra characters
---------
Co-authored-by: Mehdi Karami <[email protected]>
Copy file name to clipboardExpand all lines: proposals/0418-inferring-sendable-for-methods.md
+6-12Lines changed: 6 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,7 @@ let unapplied: (S) -> (() -> Void) = S.f
35
35
```
36
36
37
37
38
-
Suppose we want to create a generic method that expects an unapplied function method conforming to Sendable as a parameter. We can create a protocol ``P`` that conforms to the `Sendable` protocol and tell our generic function to expect some generic type that conforms to ``P``. We can also use the `@Sendable` attribute, introduced for closures and functions in [SE-302](https://github.com/kavon/swift-evolution/blob/sendable-functions/proposals/0302-concurrent-value-and-concurrent-closures.md), to annotate the closure parameter.
38
+
Suppose we want to create a generic method that expects an unapplied function method conforming to Sendable as a parameter. We can create a protocol `P` that conforms to the `Sendable` protocol and tell our generic function to expect some generic type that conforms to `P`. We can also use the `@Sendable` attribute, introduced for closures and functions in [SE-302](https://github.com/kavon/swift-evolution/blob/sendable-functions/proposals/0302-concurrent-value-and-concurrent-closures.md), to annotate the closure parameter.
39
39
40
40
41
41
```swift
@@ -192,7 +192,7 @@ It is important to note that **under the proposed rule all of the declarations t
192
192
let name: KeyPath<User, String> = \.name// 🟢 but key path is **non-Sendable**
193
193
```
194
194
195
-
Since Sendable is a marker protocol is should be possible to adjust all declarations where `& Sendable` is desirable without any ABI impact.
195
+
Since Sendable is a marker protocol it should be possible to adjust all declarations where `& Sendable` is desirable without any ABI impact.
196
196
197
197
Existing APIs that use key path in their parameter types or default values can add `Sendable` requirement in a non-ABI breaking way by marking existing declarations as @preconcurrency and adding `& Sendable` at appropriate positions:
198
198
@@ -226,7 +226,7 @@ This proposal includes five changes to `Sendable` behavior.
226
226
227
227
The first two are what we just discussed regarding partial and unapplied methods.
228
228
229
-
```
229
+
```swift
230
230
structUser : Sendable {
231
231
var address: String
232
232
var password: String
@@ -271,7 +271,7 @@ let name: KeyPath<User, String> = \.name
271
271
let otherName: KeyPath<User, String> & Sendable = \.name 🔴
272
272
```
273
273
274
-
The conversion between key path and a `@Sendable` function doesn’t actually require the key path itself to be `Sendable` because the it’s not captured by the closure but wrapped by it.
274
+
The conversion between key path and a `@Sendable` function doesn’t actually require the key path itself to be `Sendable` because it’s not captured by the closure but wrapped by it.
filter(name) // 🟢 use of @Sendable applies a sendable key path
308
308
```
309
309
310
-
311
310
Next is:
312
311
313
312
4. The inference of `@Sendable` when referencing non-local functions.
@@ -410,19 +409,14 @@ N/A
410
409
411
410
## Future Directions
412
411
413
-
Accessors are not currently allowed to participate with the `@Sendable` system in this proposal. It would be straight-forward to allow getters to do so in a future proposal if there was demand for this.
412
+
Accessors are not currently allowed to participate with the `@Sendable` system in this proposal. It would be straightforward to allow getters to do so in a future proposal if there was demand for this.
414
413
415
414
## Alternatives Considered
416
415
417
-
Swift could forbid explicitly marking function declarations with the`@Sendable` attribute, since under this proposal there’s no longer any reason to do this.
416
+
Swift could forbid explicitly marking function declarations with the`@Sendable` attribute, since under this proposal there’s no longer any reason to do this.
418
417
419
418
```swift
420
419
/*@Sendable*/funcalwaysSendable() {}
421
420
```
422
421
423
422
However, since these attributes are allowed today, this would be a source breaking change. Swift 6 could potentially include fix-its to remove `@Sendable` attributes to ease migration, but it’d still be disruptive. The attributes are harmless under this proposal, and they’re still sometimes useful for code that needs to compile with older tools, so we have chosen not to make this change in this proposal. We can consider deprecation at a later time if we find a good reason to do so.
0 commit comments