Skip to content

Commit b03f79d

Browse files
glessarditingliu
andauthored
Apply suggestions from code review
Co-authored-by: Tina L <49205802+itingliu@users.noreply.github.com>
1 parent 1db8e6e commit b03f79d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Proposals/nnnn-generalize-closure-based-functions-in-Data.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Status: **Awaiting implementation** or **Awaiting review**
77
* Bug: *if applicable* [swiftlang/swift-foundation#1638](https://github.com/swiftlang/swift-foundation/issues/1638)
88

9-
Implementation: [swiftlang/swift-foundation#1622](https://github.com/swiftlang/swift-foundation/pull/1622)
9+
* Implementation: [swiftlang/swift-foundation#1622](https://github.com/swiftlang/swift-foundation/pull/1622)
1010

1111
* Review: ([pitch](https://forums.swift.org/...))
1212

@@ -16,9 +16,9 @@ We propose to generalize the closure-taking API of `Data` for typed throws and f
1616

1717
## Motivation
1818

19-
Since [SE-0427], noncopyable types can participate in Swift generics, but `Data` has not been adapted to allow working with noncopyable values. [SE-0437] paved the way by generalizing low-level constructs such as `UnsafeBufferPointer<T>`, and as a result the community of Swift systems programmers now expects that generic functions such as `withUnsafeBytes()` can return noncopyable values.
19+
Since [SE-0427](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0427-noncopyable-generics.md), noncopyable types can participate in Swift generics, but `Data` has not been adapted to allow working with noncopyable values. [SE-0437](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0437-noncopyable-stdlib-primitives.md) paved the way by generalizing low-level constructs such as `UnsafeBufferPointer<T>`, and as a result the community of Swift systems programmers now expects that generic functions such as `withUnsafeBytes()` can return noncopyable values.
2020

21-
In [SE-0413], we also added the ability for functions to throw typed errors. This ability is important in high-performance contexts such as embedded Swift, and functions such as `withUnsafeBytes()` should support closures with typed errors.
21+
In [SE-0413](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0413-typed-throws.md), we also added the ability for functions to throw typed errors. This ability is important in high-performance contexts such as embedded Swift, and functions such as `withUnsafeBytes()` should support closures with typed errors.
2222

2323
`Data`'s current closure-based functions such as `withUnsafeBytes()` cannot take advantage of either of these newer features:
2424

@@ -42,14 +42,17 @@ The signatures of `Data`'s three closure-based functions will become:
4242

4343
```swift
4444
extension Data {
45+
@_alwaysEmitIntoClient
4546
public func withUnsafeBytes<E: Error, ResultType: ~Copyable>(
4647
_ apply: (UnsafeRawBufferPointer) throws(E) -> ResultType
4748
) throws(E) -> ResultType
4849

50+
@_alwaysEmitIntoClient
4951
public func withContiguousStorageIfAvailable<E: Error, ResultType: ~Copyable>(
5052
_ body: (_ buffer: UnsafeBufferPointer<UInt8>) throws(E) -> ResultType
5153
) throws(E) -> ResultType?
5254

55+
@_alwaysEmitIntoClient
5356
public mutating func withUnsafeMutableBytes<E: Error, ResultType: ~Copyable>(
5457
_ body: (UnsafeMutableRawBufferPointer) throws(E) -> ResultType
5558
) throws(E) -> ResultType

0 commit comments

Comments
 (0)