Skip to content

Commit 21dae8e

Browse files
committed
Generalize Sequence: ~Copyable & ~Escapable
1 parent 464e074 commit 21dae8e

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

benchmark/single-source/DataBenchmarks.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,14 +327,20 @@ let large = sampleData(.large)
327327
let array809 = byteArray(size: 809)
328328

329329
struct Count0<S: Sequence> : Sequence {
330+
@available(macOS 9999, *)
331+
public typealias BorrowingIterator = BorrowingIteratorAdapter<S.Iterator>
332+
330333
let base: S
331334
init (_ base:S) { self.base = base }
332335
func makeIterator() -> S.Iterator { return base.makeIterator() }
333336
var underestimatedCount: Int { return 0 }
334337
}
335338

336339
struct Bytes: Sequence, IteratorProtocol {
337-
let count: Int
340+
@available(macOS 9999, *)
341+
public typealias BorrowingIterator = BorrowingIteratorAdapter<Self>
342+
343+
let count: Int
338344
let exact: Bool
339345
var i: Int = 0
340346
init(count: Int, exact: Bool) {

stdlib/private/SwiftReflectionTest/SwiftReflectionTest.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ internal struct Section {
227227
/// Holds the addresses and sizes of sections related to reflection.
228228
internal struct ReflectionInfo : Sequence {
229229
internal typealias Element = Section?
230+
@available(macOS 9999, *)
231+
internal typealias BorrowingIterator = BorrowingIteratorAdapter<AnyIterator<Section?>>
230232

231233
/// The name of the loaded image.
232234
internal let imageName: String

stdlib/public/Concurrency/Deque/Deque+Collection.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ extension _Deque: Sequence {
1919
// This custom implementation performs direct storage access to eliminate any
2020
// and all index validation overhead. It also optimizes away repeated
2121
// conversions from indices to storage slots.
22+
@available(macOS 9999, *)
23+
internal typealias BorrowingIterator = BorrowingIteratorAdapter<Iterator>
2224

2325
/// An iterator over the members of a deque.
2426
struct Iterator: IteratorProtocol {

stdlib/public/RuntimeModule/Base64.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ public struct Base64Encoder<S: Sequence>: Sequence
217217
public struct Base64Decoder<S: Sequence>: Sequence
218218
where S.Element == UTF8.CodeUnit
219219
{
220+
@available(macOS 9999, *)
221+
public typealias BorrowingIterator = BorrowingIteratorAdapter<Iterator>
220222
public typealias Element = UInt8
221223

222224
var source: S

stdlib/public/core/Sequence.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ public protocol IteratorProtocol<Element> {
322322
/// makes no other requirements about element access, so routines that
323323
/// traverse a sequence should be considered O(*n*) unless documented
324324
/// otherwise.
325-
public protocol Sequence<Element> /* : ~Copyable, ~Escapable */ {
325+
public protocol Sequence<Element>: ~Copyable, ~Escapable {
326326
/// A type representing the sequence's elements.
327327
associatedtype Element
328328

@@ -331,7 +331,7 @@ public protocol Sequence<Element> /* : ~Copyable, ~Escapable */ {
331331
associatedtype Iterator: IteratorProtocol<Element>
332332

333333
@available(SwiftStdlib 6.3, *)
334-
associatedtype BorrowingIterator: BorrowingIteratorProtocol<Element> & ~Copyable & ~Escapable = BorrowingIteratorAdapter<Self>
334+
associatedtype BorrowingIterator: BorrowingIteratorProtocol<Element> & ~Copyable & ~Escapable = BorrowingIteratorAdapter<Iterator>
335335

336336
// FIXME: <rdar://problem/34142121>
337337
// This typealias should be removed as it predates the source compatibility
@@ -459,16 +459,16 @@ public protocol Sequence<Element> /* : ~Copyable, ~Escapable */ {
459459
}
460460

461461
@available(SwiftStdlib 6.3, *)
462-
public struct BorrowingIteratorAdapter<S: Sequence>: /* & ~Copyable & ~Escapable */
463-
BorrowingIteratorProtocol where S.Element: Copyable
462+
public struct BorrowingIteratorAdapter<Iterator: IteratorProtocol>: /* & ~Copyable & ~Escapable */
463+
BorrowingIteratorProtocol where Iterator.Element: Copyable
464464
{
465-
var iterator: S.Iterator
466-
var curValue: S.Element?
465+
var iterator: Iterator
466+
var curValue: Iterator.Element?
467467

468-
public typealias Element = S.Element
468+
public typealias Element = Iterator.Element
469469

470470
@lifetime(&self)
471-
public mutating func nextSpan(maximumCount: Int) -> Span<S.Element> {
471+
public mutating func nextSpan(maximumCount: Int) -> Span<Iterator.Element> {
472472
curValue = iterator.next()
473473
return curValue._span
474474
}
@@ -486,7 +486,7 @@ extension NeverIterator: IteratorProtocol { /* where Element: ~Copyable */
486486
}
487487

488488
@available(SwiftStdlib 6.3, *)
489-
extension Sequence where BorrowingIterator == BorrowingIteratorAdapter<Self> {
489+
extension Sequence where BorrowingIterator == BorrowingIteratorAdapter<Iterator> {
490490
public func makeBorrowingIterator() -> BorrowingIterator {
491491
BorrowingIteratorAdapter(iterator: makeIterator())
492492
}

0 commit comments

Comments
 (0)