Skip to content

Commit ad0888d

Browse files
karami-mehdiMehdi Karami
andauthored
[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]>
1 parent dc947b8 commit ad0888d

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

proposals/0418-inferring-sendable-for-methods.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ let unapplied: (S) -> (() -> Void) = S.f
3535
```
3636

3737

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.
3939

4040

4141
```swift
@@ -192,7 +192,7 @@ It is important to note that **under the proposed rule all of the declarations t
192192
let name: KeyPath<User, String> = \.name // 🟢 but key path is **non-Sendable**
193193
```
194194

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.
196196

197197
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:
198198

@@ -226,7 +226,7 @@ This proposal includes five changes to `Sendable` behavior.
226226

227227
The first two are what we just discussed regarding partial and unapplied methods.
228228

229-
```
229+
```swift
230230
struct User : Sendable {
231231
var address: String
232232
var password: String
@@ -271,7 +271,7 @@ let name: KeyPath<User, String> = \.name
271271
let otherName: KeyPath<User, String> & Sendable = \.name 🔴
272272
```
273273

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.
275275

276276
```swift
277277
let name: @Sendable (User) -> String = \.name 🟢
@@ -307,7 +307,6 @@ func filter<T: Sendable>(_: @Sendable (User) -> T) {}
307307
filter(name) // 🟢 use of @Sendable applies a sendable key path
308308
```
309309

310-
311310
Next is:
312311

313312
4. The inference of `@Sendable` when referencing non-local functions.
@@ -410,19 +409,14 @@ N/A
410409

411410
## Future Directions
412411

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.
414413

415414
## Alternatives Considered
416415

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.
418417

419418
```swift
420419
/*@Sendable*/ func alwaysSendable() {}
421420
```
422421

423422
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.
424-
425-
426-
427-
428-

0 commit comments

Comments
 (0)