Skip to content

Commit a00d4ee

Browse files
authored
[SE-0467] incorporate review feedback (#2737)
* [se0467] extract slicing from future directions * [se0467] clean up element constraints * [se0467] fix another typo * [se0467] fix a typo and parameter name
1 parent b5bf19d commit a00d4ee

File tree

1 file changed

+7
-29
lines changed

1 file changed

+7
-29
lines changed

proposals/0467-MutableSpan.md

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ This lifetime relationship will apply to all the safe `var mutableSpan: MutableS
8484
An important category of use cases for `MutableSpan` and `MutableRawSpan` consists of bulk copying operations. Often times, such bulk operations do not necessarily start at the beginning of the span, thus having a method to select a sub-span is necessary. This means producing an instance derived from the callee instance. We adopt the nomenclature already introduced in [SE-0437][SE-0437], with a family of `extracting()` methods.
8585

8686
```swift
87-
extension MutableSpan where Element: ~Copyable & ~Escapable {
87+
extension MutableSpan where Element: ~Copyable {
8888
@_lifetime(inout self)
8989
public mutating func extracting(_ range: Range<Index>) -> Self
9090
}
@@ -114,20 +114,20 @@ As established in [SE-0437][SE-0437], the instance returned by the `extracting()
114114

115115
````swift
116116
@frozen
117-
public struct MutableSpan<Element: ~Copyable & ~Escapable>: ~Copyable, ~Escapable {
117+
public struct MutableSpan<Element: ~Copyable>: ~Copyable, ~Escapable {
118118
internal var _start: UnsafeMutableRawPointer?
119119
internal var _count: Int
120120
}
121121

122-
extension MutableSpan: @unchecked Sendable where Element: Sendable {}
122+
extension MutableSpan: @unchecked Sendable where Element: Sendable & ~Copyable {}
123123
````
124124

125125
We store a `UnsafeMutableRawPointer` value internally in order to explicitly support reinterpreted views of memory as containing different types of `BitwiseCopyable` elements. Note that the the optionality of the pointer does not affect usage of `MutableSpan`, since accesses are bounds-checked and the pointer is only dereferenced when the `MutableSpan` isn't empty, when the pointer cannot be `nil`.
126126

127127
Initializers, required for library adoption, will be proposed alongside [lifetime annotations][PR-2305]; for details, see "[Initializers](#initializers)" in the [future directions](#Directions) section.
128128

129129
```swift
130-
extension MutableSpan where Element: ~Copyable & ~Escapable {
130+
extension MutableSpan where Element: ~Copyable {
131131
/// The number of initialized elements in this `MutableSpan`.
132132
var count: Int { get }
133133

@@ -172,7 +172,7 @@ We include functions to perform bulk copies of elements into the memory represen
172172

173173
```swift
174174
extension MutableSpan where Element: Copyable {
175-
/// Updates every element of this span's to the given value.
175+
/// Updates every element of this span to the given value.
176176
mutating func update(
177177
repeating repeatedValue: Element
178178
)
@@ -224,7 +224,7 @@ extension MutableSpan where Element: Copyable {
224224
These functions extract sub-spans of the callee. The first two perform strict bounds-checking. The last four return prefixes or suffixes, where the number of elements in the returned sub-span is bounded by the number of elements in the parent `MutableSpan`.
225225

226226
```swift
227-
extension MutableSpan where Element: ~Copable & ~Escapable {
227+
extension MutableSpan where Element: ~Copyable {
228228
/// Returns a span over the items within the supplied range of
229229
/// positions within this span.
230230
@_lifetime(inout self)
@@ -427,7 +427,7 @@ extension MutableRawSpan {
427427

428428
/// Updates the span's bytes with the bytes of the elements from the source
429429
mutating func update<Element: BitwiseCopyable>(
430-
from elements: inout some IteratorProtocol<Element>
430+
from source: inout some IteratorProtocol<Element>
431431
) -> Int
432432

433433
/// Updates the span's bytes with every byte of the source.
@@ -669,28 +669,6 @@ Note: The future directions stated in [SE-0447](https://github.com/swiftlang/swi
669669

670670
These annotations have been [pitched][PR-2305-pitch] and, after revision, are expected to be pitched again soon. `MutableSpan` initializers using lifetime annotations will be proposed alongside the annotations themselves.
671671

672-
#### Functions providing variants of `MutableRawSpan` to `MutableSpan`
673-
674-
`MutableSpan`s representing subsets of consecutive elements could be extracted out of a larger `MutableSpan` with an API similar to the `extracting()` functions recently added to `UnsafeBufferPointer` in support of non-copyable elements:
675-
676-
```swift
677-
extension MutableSpan where Element: ~Copyable {
678-
public mutating func extracting(_ bounds: Range<Index>) -> Self
679-
}
680-
```
681-
682-
These functions would require a lifetime dependency annotation.
683-
684-
Similarly, a `MutableRawSpan` could provide a function to mutate a range of its bytes as a typed `MutableSpan`:
685-
686-
```swift
687-
extension MutableRawSpan {
688-
@unsafe
689-
public mutating func unsafeMutableView<T: BitwiseCopyable>(as type: T.Type) -> MutableSpan<T>
690-
}
691-
```
692-
We are subsetting functions that require lifetime annotations until such annotations are [proposed][PR-2305].
693-
694672
#### Splitting `MutableSpan` instances – `MutableSpan` in divide-and-conquer algorithms
695673

696674
It is desirable to have a way to split a `MutableSpan` in multiple parts, for divide-and-conquer algorithms or other reasons:

0 commit comments

Comments
 (0)