diff --git a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+ElementsEqual.swift b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+ElementsEqual.swift index 23c96129..c38cfe45 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+ElementsEqual.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+ElementsEqual.swift @@ -18,7 +18,11 @@ import InternalCollectionsUtilities #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -extension BorrowingSequence where Self: ~Copyable & ~Escapable, Element: Equatable { +extension BorrowingSequence +where + Self: ~Copyable & ~Escapable, Element: Equatable, + Element: ~Copyable +{ @inlinable package func _elementsEqual< Other: BorrowingSequence & ~Copyable & ~Escapable @@ -32,7 +36,11 @@ extension BorrowingSequence where Self: ~Copyable & ~Escapable, Element: Equatab } @available(SwiftStdlib 5.0, *) -extension BorrowingSequence where Self: ~Copyable & ~Escapable { +extension BorrowingSequence +where + Self: ~Copyable & ~Escapable, + Element: ~Copyable +{ /// Returns a Boolean value indicating whether two borrowing sequences contain /// equivalent elements in the same order, using the given predicate as the /// equivalence test. @@ -72,7 +80,7 @@ extension BorrowingSequence where Self: ~Copyable & ~Escapable { extension BorrowingIteratorProtocol where Self: ~Copyable & ~Escapable, - Element: Equatable + Element: ~Copyable & Equatable { @inlinable package consuming func elementsEqual< @@ -159,7 +167,11 @@ where } @available(SwiftStdlib 5.0, *) -extension BorrowingIteratorProtocol where Self: ~Copyable & ~Escapable { +extension BorrowingIteratorProtocol +where + Self: ~Copyable & ~Escapable, + Element: ~Copyable +{ @inlinable package consuming func elementsEqual< E: Error, diff --git a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Filter.swift b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Filter.swift index 8a3f357b..59a54461 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Filter.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Filter.swift @@ -14,7 +14,11 @@ #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -extension BorrowingIteratorProtocol where Self: ~Copyable & ~Escapable { +extension BorrowingIteratorProtocol +where + Self: ~Copyable & ~Escapable, + Element: ~Copyable +{ @inlinable @_lifetime(copy self) public consuming func filter( @@ -26,8 +30,9 @@ extension BorrowingIteratorProtocol where Self: ~Copyable & ~Escapable { @available(SwiftStdlib 5.0, *) public struct BorrowingFilter< - Base: BorrowingIteratorProtocol & ~Copyable & ~Escapable, ->: ~Copyable, ~Escapable { + Base: BorrowingIteratorProtocol & ~Copyable & ~Escapable +>: ~Copyable, ~Escapable +where Base.Element: ~Copyable { public typealias Element = Base.Element @_alwaysEmitIntoClient @@ -51,7 +56,7 @@ public struct BorrowingFilter< @available(SwiftStdlib 5.0, *) extension BorrowingFilter: BorrowingIteratorProtocol -where Base: ~Copyable & ~Escapable { +where Base: ~Copyable & ~Escapable, Base.Element: ~Copyable { @_lifetime(&self) public mutating func nextSpan(maximumCount: Int) -> Span { // FIXME: This is quite inefficient compared to Container's filter diff --git a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Map.swift b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Map.swift index 93ccb88d..7f45c827 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Map.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Map.swift @@ -14,7 +14,11 @@ #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -extension BorrowingIteratorProtocol where Self: ~Copyable & ~Escapable { +extension BorrowingIteratorProtocol +where + Self: ~Copyable & ~Escapable, + Element: ~Copyable +{ @inlinable @_lifetime(copy self) public consuming func map( diff --git a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Reduce.swift b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Reduce.swift index a3813638..ccf6532f 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Reduce.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Reduce.swift @@ -14,7 +14,11 @@ #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -extension BorrowingIteratorProtocol where Self: ~Copyable & ~Escapable { +extension BorrowingIteratorProtocol +where + Self: ~Copyable & ~Escapable, + Element: ~Copyable +{ @inlinable public consuming func reduce( _ initialResult: consuming Result, diff --git a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+SpanwiseZip.swift b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+SpanwiseZip.swift index d5bb703a..247b36b9 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+SpanwiseZip.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+SpanwiseZip.swift @@ -18,7 +18,11 @@ import InternalCollectionsUtilities #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -extension BorrowingIteratorProtocol where Self: ~Copyable & ~Escapable { +extension BorrowingIteratorProtocol +where + Self: ~Copyable & ~Escapable, + Element: ~Copyable +{ @inlinable internal consuming func _spanwiseZip< Other: BorrowingIteratorProtocol & ~Copyable & ~Escapable, diff --git a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol.swift b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol.swift index ab6fb791..4074a596 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol.swift @@ -96,7 +96,8 @@ public protocol BorrowingIteratorProtocol: ~Copyable, ~Escapable { } @available(SwiftStdlib 5.0, *) -extension BorrowingIteratorProtocol where Self: ~Copyable & ~Escapable, Element: ~Copyable { +extension BorrowingIteratorProtocol +where Self: ~Copyable & ~Escapable, Element: ~Copyable { @_lifetime(&self) @_lifetime(self: copy self) @_transparent @@ -106,7 +107,8 @@ extension BorrowingIteratorProtocol where Self: ~Copyable & ~Escapable, Element: } @available(SwiftStdlib 5.0, *) -extension BorrowingIteratorProtocol where Self: ~Copyable & ~Escapable, Element: ~Copyable { +extension BorrowingIteratorProtocol +where Self: ~Copyable & ~Escapable, Element: ~Copyable { @_lifetime(self: copy self) @inlinable public mutating func skip(by offset: Int) -> Int { diff --git a/Sources/ContainersPreview/Protocols/BorrowingSequence+Algorithms.swift b/Sources/ContainersPreview/Protocols/BorrowingSequence+Algorithms.swift index f072a2b3..11a72ba7 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingSequence+Algorithms.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingSequence+Algorithms.swift @@ -14,7 +14,11 @@ #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -extension BorrowingSequence where Self: ~Copyable & ~Escapable, Element: ~Copyable { +extension BorrowingSequence +where + Self: ~Copyable & ~Escapable, + Element: ~Copyable +{ @inlinable public func reduce( _ initialResult: consuming Result, @@ -45,12 +49,18 @@ extension BorrowingSequence where Self: ~Copyable & ~Escapable, Element: ~Copyab } @available(SwiftStdlib 5.0, *) -extension BorrowingSequence where Self: ~Copyable & ~Escapable, Element: ~Copyable { +extension BorrowingSequence +where + Self: ~Copyable & ~Escapable, + Element: ~Copyable +{ @inlinable public func elementsEqual( _ other: borrowing OtherSequence, by areEquivalent: (borrowing Element, borrowing OtherSequence.Element) throws -> Bool - ) rethrows -> Bool where OtherSequence: ~Copyable & ~Escapable, OtherSequence.Element: ~Copyable { + ) rethrows -> Bool + where OtherSequence: ~Copyable & ~Escapable, OtherSequence.Element: ~Copyable + { var iter1 = makeBorrowingIterator() var iter2 = other.makeBorrowingIterator() while true { @@ -75,7 +85,8 @@ extension BorrowingSequence where Self: ~Copyable & ~Escapable, Element: ~Copyab } @available(SwiftStdlib 5.0, *) -extension BorrowingSequence where Self: ~Copyable & ~Escapable, Element: ~Copyable & Equatable { +extension BorrowingSequence +where Self: ~Copyable & ~Escapable, Element: ~Copyable & Equatable { @inlinable public func elementsEqual>( _ other: borrowing OtherSequence diff --git a/Sources/ContainersPreview/Protocols/BorrowingSequence.swift b/Sources/ContainersPreview/Protocols/BorrowingSequence.swift index fc05504a..31e0e497 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingSequence.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingSequence.swift @@ -29,7 +29,10 @@ public protocol BorrowingSequence: ~Copyable, ~Escapable { } @available(SwiftStdlib 5.0, *) -extension BorrowingSequence where Self: ~Copyable & ~Escapable { +extension BorrowingSequence +where + Self: ~Copyable & ~Escapable, Element: ~Copyable +{ @inlinable public var underestimatedCount: Int { 0 } @@ -48,7 +51,11 @@ extension BorrowingSequence where Self: Sequence { } @available(SwiftStdlib 5.0, *) -extension BorrowingSequence where Self: ~Copyable & ~Escapable { +extension BorrowingSequence +where + Self: ~Copyable & ~Escapable, + Element: ~Copyable +{ /// Implementation demo of what borrowing for-in loops would need to expand into. @inlinable public func _borrowingForEach( diff --git a/Sources/ContainersPreview/Protocols/Container/BidirectionalContainer.swift b/Sources/ContainersPreview/Protocols/Container/BidirectionalContainer.swift index 0f5b5ac2..cbd61361 100644 --- a/Sources/ContainersPreview/Protocols/Container/BidirectionalContainer.swift +++ b/Sources/ContainersPreview/Protocols/Container/BidirectionalContainer.swift @@ -14,7 +14,9 @@ #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -public protocol BidirectionalContainer: Container, ~Copyable, ~Escapable { +public protocol BidirectionalContainer: Container, ~Copyable, ~Escapable +where Element: ~Copyable +{ func index(before i: Index) -> Index func formIndex(before i: inout Index) @@ -24,7 +26,8 @@ public protocol BidirectionalContainer: Container, ~Copyable, ~Escapabl } @available(SwiftStdlib 5.0, *) -extension BidirectionalContainer where Self: ~Copyable & ~Escapable { +extension BidirectionalContainer +where Self: ~Copyable & ~Escapable, Element: ~Copyable { @inlinable public func formIndex(before i: inout Index) { i = self.index(before: i) diff --git a/Sources/ContainersPreview/Protocols/Container/Container+Filter.swift b/Sources/ContainersPreview/Protocols/Container/Container+Filter.swift index d504b164..e7e42afa 100644 --- a/Sources/ContainersPreview/Protocols/Container/Container+Filter.swift +++ b/Sources/ContainersPreview/Protocols/Container/Container+Filter.swift @@ -18,7 +18,7 @@ import InternalCollectionsUtilities #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -extension Container where Self: ~Copyable /*& ~Escapable*/ { +extension Container where Self: ~Copyable /*& ~Escapable*/, Element: ~Copyable { @_lifetime(borrow self) public func _filter( _ isIncluded: @escaping (borrowing Element) -> Bool @@ -28,7 +28,7 @@ extension Container where Self: ~Copyable /*& ~Escapable*/ { } @available(SwiftStdlib 5.0, *) -extension ContainerIterator { +extension ContainerIterator where Base.Element: ~Copyable { @_lifetime(copy self) public func filter( _ isIncluded: @escaping (borrowing Element) -> Bool @@ -40,7 +40,9 @@ extension ContainerIterator { @available(SwiftStdlib 5.0, *) public struct ContainerFilter< Base: Container & ~Copyable/* FIXME & ~Escapable */ ->: ~Copyable, ~Escapable { +>: ~Copyable, ~Escapable +where Base.Element: ~Copyable +{ public typealias Element = Base.Element @_alwaysEmitIntoClient @@ -84,7 +86,7 @@ public struct ContainerFilter< // FIXME: Sendable @available(SwiftStdlib 5.0, *) -extension ContainerFilter: BorrowingIteratorProtocol { +extension ContainerFilter: BorrowingIteratorProtocol where Element: ~Copyable { @_lifetime(copy self) public mutating func nextSpan(maximumCount: Int) -> Span { precondition(maximumCount > 0) diff --git a/Sources/ContainersPreview/Protocols/Container/Container+SpanwiseZip.swift b/Sources/ContainersPreview/Protocols/Container/Container+SpanwiseZip.swift index 86c1c48f..73bb35d1 100644 --- a/Sources/ContainersPreview/Protocols/Container/Container+SpanwiseZip.swift +++ b/Sources/ContainersPreview/Protocols/Container/Container+SpanwiseZip.swift @@ -18,7 +18,7 @@ import InternalCollectionsUtilities #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 6.2, *) -extension Container where Self: ~Copyable & ~Escapable { +extension Container where Self: ~Copyable & ~Escapable, Element: ~Copyable { @_alwaysEmitIntoClient internal func _spanwiseZip( with other: borrowing Other, diff --git a/Sources/ContainersPreview/Protocols/Container/Container.swift b/Sources/ContainersPreview/Protocols/Container/Container.swift index 1e572732..46b4fbd5 100644 --- a/Sources/ContainersPreview/Protocols/Container/Container.swift +++ b/Sources/ContainersPreview/Protocols/Container/Container.swift @@ -14,7 +14,9 @@ #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -public protocol Container: BorrowingSequence, ~Copyable, ~Escapable { +public protocol Container: BorrowingSequence, ~Copyable, ~Escapable +where Element: ~Copyable +{ associatedtype Index: Comparable // FIXME: Ideally Index should also be required to be Hashable. // FIXME: If we discard the separate BorrowingSequence abstraction, then we @@ -168,7 +170,7 @@ public protocol Container: BorrowingSequence, ~Copyable, ~Escapable { } @available(SwiftStdlib 5.0, *) -extension Container where Self: ~Copyable & ~Escapable { +extension Container where Self: ~Copyable & ~Escapable, Element: ~Copyable { /// Return a span over the container's storage that begins with the element at /// the given index, and extends to the end of the contiguous storage chunk /// that contains it. On return, the index is updated to address the next item @@ -224,7 +226,7 @@ extension Container where Self: ~Copyable & ~Escapable { } @available(SwiftStdlib 5.0, *) -extension Container where Self: ~Copyable & ~Escapable { +extension Container where Self: ~Copyable & ~Escapable, Element: ~Copyable { @inlinable public func formIndex(after index: inout Index) { index = self.index(after: index) @@ -256,7 +258,7 @@ extension Container where Self: ~Copyable & ~Escapable { @available(SwiftStdlib 5.0, *) -extension Container where Self: ~Copyable & ~Escapable { +extension Container where Self: ~Copyable & ~Escapable, Element: ~Copyable { @inlinable public func _defaultDistance(from start: Index, to end: Index) -> Int { // FIXME: Use binary search here (with nextSpan(after:maximumCount:)) @@ -386,7 +388,7 @@ extension Container where Self: ~Copyable & ~Escapable { } @available(SwiftStdlib 5.0, *) -extension Container where Self: ~Copyable & ~Escapable { +extension Container where Self: ~Copyable & ~Escapable, Element: ~Copyable { @_transparent public var underestimatedCount: Int { count } } diff --git a/Sources/ContainersPreview/Protocols/Container/ContainerIterator.swift b/Sources/ContainersPreview/Protocols/Container/ContainerIterator.swift index 3a58f568..cfea4e07 100644 --- a/Sources/ContainersPreview/Protocols/Container/ContainerIterator.swift +++ b/Sources/ContainersPreview/Protocols/Container/ContainerIterator.swift @@ -17,6 +17,7 @@ extension Container where Self: ~Copyable /*FIXME: & ~Escapable*/, + Element: ~Copyable, BorrowingIterator == ContainerIterator { @_lifetime(borrow self) @@ -28,7 +29,9 @@ where @available(SwiftStdlib 5.0, *) public struct ContainerIterator< Base: Container & ~Copyable /*FIXME: & ~Escapable*/ ->: ~Copyable, ~Escapable { +>: ~Copyable, ~Escapable +where Base.Element: ~Copyable +{ let _base: Borrow // FIXME: This doesn't support nonescapable Bases var _position: Base.Index @@ -41,7 +44,9 @@ public struct ContainerIterator< @available(SwiftStdlib 5.0, *) extension ContainerIterator: BorrowingIteratorProtocol -where Base: ~Copyable /*FIXME: & ~Escapable*/ +where + Base: ~Copyable /*FIXME: & ~Escapable*/, + Base.Element: ~Copyable { public typealias Element = Base.Element diff --git a/Sources/ContainersPreview/Protocols/Container/DynamicContainer.swift b/Sources/ContainersPreview/Protocols/Container/DynamicContainer.swift index f1e63083..2c091bca 100644 --- a/Sources/ContainersPreview/Protocols/Container/DynamicContainer.swift +++ b/Sources/ContainersPreview/Protocols/Container/DynamicContainer.swift @@ -14,7 +14,9 @@ #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -public protocol DynamicContainer: RangeReplaceableContainer, ~Copyable { +public protocol DynamicContainer: RangeReplaceableContainer, ~Copyable +where Element: ~Copyable +{ init() init(minimumCapacity: Int) @@ -24,7 +26,7 @@ public protocol DynamicContainer: RangeReplaceableContainer, ~Copyable } @available(SwiftStdlib 5.0, *) -extension DynamicContainer where Self: ~Copyable { +extension DynamicContainer where Self: ~Copyable, Element: ~Copyable { @inlinable public init() { self.init(minimumCapacity: 0) diff --git a/Sources/ContainersPreview/Protocols/Container/MutableContainer.swift b/Sources/ContainersPreview/Protocols/Container/MutableContainer.swift index ff2a1f90..92456fb2 100644 --- a/Sources/ContainersPreview/Protocols/Container/MutableContainer.swift +++ b/Sources/ContainersPreview/Protocols/Container/MutableContainer.swift @@ -14,7 +14,11 @@ #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -public protocol MutableContainer: PermutableContainer, ~Copyable, ~Escapable { +public protocol MutableContainer: + PermutableContainer, ~Copyable, ~Escapable +where + Element: ~Copyable +{ // subscript(index: Index) -> Element { borrow mutate } @_lifetime(&self) @@ -27,7 +31,9 @@ public protocol MutableContainer: PermutableContainer, ~Copyable, ~Esca } @available(SwiftStdlib 5.0, *) -extension MutableContainer where Self: ~Copyable & ~Escapable { +extension MutableContainer +where Self: ~Copyable & ~Escapable, Element: ~Copyable +{ @inlinable @_lifetime(&self) mutating func nextMutableSpan( diff --git a/Sources/ContainersPreview/Protocols/Container/PermutableContainer.swift b/Sources/ContainersPreview/Protocols/Container/PermutableContainer.swift index 41fed7df..2aaf5b90 100644 --- a/Sources/ContainersPreview/Protocols/Container/PermutableContainer.swift +++ b/Sources/ContainersPreview/Protocols/Container/PermutableContainer.swift @@ -14,7 +14,9 @@ #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -public protocol PermutableContainer: Container, ~Copyable, ~Escapable { +public protocol PermutableContainer: Container, ~Copyable, ~Escapable +where Element: ~Copyable +{ @_lifetime(self: copy self) mutating func swapAt(_ i: Index, _ j: Index) } diff --git a/Sources/ContainersPreview/Protocols/Container/RandomAccessContainer.swift b/Sources/ContainersPreview/Protocols/Container/RandomAccessContainer.swift index 6a32157a..3eb70735 100644 --- a/Sources/ContainersPreview/Protocols/Container/RandomAccessContainer.swift +++ b/Sources/ContainersPreview/Protocols/Container/RandomAccessContainer.swift @@ -15,7 +15,8 @@ @available(SwiftStdlib 6.2, *) public protocol RandomAccessContainer -: BidirectionalContainer, ~Copyable, ~Escapable {} +: BidirectionalContainer, ~Copyable, ~Escapable +where Element: ~Copyable {} extension RandomAccessCollection { @inlinable diff --git a/Sources/ContainersPreview/Protocols/Container/RangeExpression2.swift b/Sources/ContainersPreview/Protocols/Container/RangeExpression2.swift index c4c238b7..6baf1683 100644 --- a/Sources/ContainersPreview/Protocols/Container/RangeExpression2.swift +++ b/Sources/ContainersPreview/Protocols/Container/RangeExpression2.swift @@ -21,7 +21,7 @@ public protocol RangeExpression2 { func relative( to container: borrowing C - ) -> Range where C.Index == Bound + ) -> Range where C.Index == Bound, C.Element: ~Copyable func contains(_ element: Bound) -> Bool } @@ -31,7 +31,7 @@ extension Range: RangeExpression2 { @inlinable public func relative( to container: borrowing C - ) -> Range where C.Index == Bound { + ) -> Range where C.Index == Bound, C.Element: ~Copyable { self } } @@ -41,7 +41,7 @@ extension ClosedRange: RangeExpression2 { @inlinable public func relative( to container: borrowing C - ) -> Range where C.Index == Bound { + ) -> Range where C.Index == Bound, C.Element: ~Copyable { let end = container.index(after: self.upperBound) return self.lowerBound ..< end } @@ -52,7 +52,7 @@ extension PartialRangeFrom: RangeExpression2 { @inlinable public func relative( to container: borrowing C - ) -> Range where C.Index == Bound { + ) -> Range where C.Index == Bound, C.Element: ~Copyable { self.lowerBound ..< container.endIndex } } @@ -62,7 +62,7 @@ extension PartialRangeUpTo: RangeExpression2 { @inlinable public func relative( to container: borrowing C - ) -> Range where C.Index == Bound { + ) -> Range where C.Index == Bound, C.Element: ~Copyable { return container.startIndex ..< self.upperBound } } @@ -72,7 +72,7 @@ extension PartialRangeThrough: RangeExpression2 { @inlinable public func relative( to container: borrowing C - ) -> Range where C.Index == Bound { + ) -> Range where C.Index == Bound, C.Element: ~Copyable { let end = container.index(after: self.upperBound) return container.startIndex ..< end } diff --git a/Sources/ContainersPreview/Protocols/Container/RangeReplaceableContainer.swift b/Sources/ContainersPreview/Protocols/Container/RangeReplaceableContainer.swift index 25ee34af..838475ce 100644 --- a/Sources/ContainersPreview/Protocols/Container/RangeReplaceableContainer.swift +++ b/Sources/ContainersPreview/Protocols/Container/RangeReplaceableContainer.swift @@ -22,6 +22,7 @@ import InternalCollectionsUtilities @available(SwiftStdlib 5.0, *) public protocol RangeReplaceableContainer : Container, ~Copyable, ~Escapable +where Element: ~Copyable { // Core requirements @@ -64,7 +65,9 @@ public protocol RangeReplaceableContainer //MARK: - Default Implementations @available(SwiftStdlib 5.0, *) -extension RangeReplaceableContainer where Self: ~Copyable & ~Escapable { +extension RangeReplaceableContainer +where Self: ~Copyable & ~Escapable, Element: ~Copyable +{ @inlinable public mutating func remove(at index: Index) -> Element { let range = Range(uncheckedBounds: (index, self.index(after: index))) @@ -135,7 +138,9 @@ extension RangeReplaceableContainer where Self: ~Copyable & ~Escapable { //MARK: - Standard Extensions @available(SwiftStdlib 5.0, *) -extension RangeReplaceableContainer where Self: ~Copyable & ~Escapable { +extension RangeReplaceableContainer +where Self: ~Copyable & ~Escapable, Element: ~Copyable +{ @inlinable public mutating func replace< E: Error, @@ -202,7 +207,8 @@ extension RangeReplaceableContainer where Self: ~Copyable & ~Escapable { } @available(SwiftStdlib 5.0, *) -extension RangeReplaceableContainer where Self: ~Copyable & ~Escapable { +extension RangeReplaceableContainer +where Self: ~Copyable & ~Escapable, Element: ~Copyable { @inlinable public mutating func consume( _ subrange: Range, @@ -256,7 +262,8 @@ extension RangeReplaceableContainer where Self: ~Copyable & ~Escapable { extension RangeReplaceableContainer where Self: BidirectionalContainer, - Self: ~Copyable & ~Escapable + Self: ~Copyable & ~Escapable, + Element: ~Copyable { @inlinable @_lifetime(&self) @@ -272,7 +279,9 @@ where } @available(SwiftStdlib 5.0, *) -extension RangeReplaceableContainer where Self: ~Copyable & ~Escapable { +extension RangeReplaceableContainer +where Self: ~Copyable & ~Escapable, Element: ~Copyable +{ @inlinable public mutating func removeSubrange( _ bounds: some RangeExpression2 @@ -289,7 +298,9 @@ extension RangeReplaceableContainer where Self: ~Copyable & ~Escapable { } @available(SwiftStdlib 5.0, *) -extension RangeReplaceableContainer where Self: ~Copyable & ~Escapable { +extension RangeReplaceableContainer +where Self: ~Copyable & ~Escapable, Element: ~Copyable +{ @inlinable public mutating func insert< E: Error, @@ -324,7 +335,8 @@ extension RangeReplaceableContainer where Self: ~Copyable & ~Escapable { } @available(SwiftStdlib 5.0, *) -extension RangeReplaceableContainer where Self: ~Copyable & ~Escapable { +extension RangeReplaceableContainer +where Self: ~Copyable & ~Escapable, Element: ~Copyable { @inlinable public mutating func append< E: Error, diff --git a/Sources/ContainersPreview/Protocols/Drain+Map.swift b/Sources/ContainersPreview/Protocols/Drain+Map.swift index 728d7d77..3297fe45 100644 --- a/Sources/ContainersPreview/Protocols/Drain+Map.swift +++ b/Sources/ContainersPreview/Protocols/Drain+Map.swift @@ -14,7 +14,7 @@ #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -extension Drain where Self: ~Copyable & ~Escapable { +extension Drain where Self: ~Copyable & ~Escapable, Element: ~Copyable { @inlinable @_lifetime(copy self) public consuming func map( diff --git a/Sources/ContainersPreview/Protocols/Drain+Reduce.swift b/Sources/ContainersPreview/Protocols/Drain+Reduce.swift index 4933fdd7..9c53dff2 100644 --- a/Sources/ContainersPreview/Protocols/Drain+Reduce.swift +++ b/Sources/ContainersPreview/Protocols/Drain+Reduce.swift @@ -14,7 +14,7 @@ #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -extension Drain where Self: ~Copyable & ~Escapable { +extension Drain where Self: ~Copyable & ~Escapable, Element: ~Copyable { @inlinable public consuming func reduce( _ initialResult: consuming Result, diff --git a/Sources/ContainersPreview/Protocols/Drain.swift b/Sources/ContainersPreview/Protocols/Drain.swift index 041f37e9..e075246c 100644 --- a/Sources/ContainersPreview/Protocols/Drain.swift +++ b/Sources/ContainersPreview/Protocols/Drain.swift @@ -23,7 +23,7 @@ /// output spans. @available(SwiftStdlib 5.0, *) public protocol Drain: Producer, ~Copyable, ~Escapable -where ProducerError == Never +where Element: ~Copyable, ProducerError == Never { /// Returns the next span of consumable items in the sequence underlying this /// drain, of at most the specified maximum count. A `maximumCount` of nil @@ -83,7 +83,7 @@ where ProducerError == Never } @available(SwiftStdlib 5.0, *) -extension Drain where Self: ~Copyable & ~Escapable { +extension Drain where Self: ~Copyable & ~Escapable, Element: ~Copyable { /// Returns the next span of consumable items in the sequence underlying this /// drain, of an arbitrarily large count. /// diff --git a/Sources/ContainersPreview/Protocols/Producer+Collect.swift b/Sources/ContainersPreview/Protocols/Producer+Collect.swift index 0204f632..5bb1f05d 100644 --- a/Sources/ContainersPreview/Protocols/Producer+Collect.swift +++ b/Sources/ContainersPreview/Protocols/Producer+Collect.swift @@ -14,7 +14,7 @@ #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -extension Producer where Self: ~Copyable & ~Escapable { +extension Producer where Self: ~Copyable & ~Escapable, Element: ~Copyable { @inlinable public consuming func collect< R: DynamicContainer & ~Copyable diff --git a/Sources/ContainersPreview/Protocols/Producer+Filter.swift b/Sources/ContainersPreview/Protocols/Producer+Filter.swift index 6afc27f2..92e814eb 100644 --- a/Sources/ContainersPreview/Protocols/Producer+Filter.swift +++ b/Sources/ContainersPreview/Protocols/Producer+Filter.swift @@ -14,7 +14,7 @@ #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -extension Producer where Self: ~Copyable & ~Escapable { +extension Producer where Self: ~Copyable & ~Escapable, Element: ~Copyable { @_lifetime(copy self) public consuming func filter( // Note: The predicate is not throwing to avoid difficult exception safety problems @@ -27,7 +27,8 @@ extension Producer where Self: ~Copyable & ~Escapable { @available(SwiftStdlib 5.0, *) public struct ConsumingFilterProducer< Base: Producer & ~Copyable & ~Escapable ->: ~Copyable, ~Escapable { +>: ~Copyable, ~Escapable +where Base.Element: ~Copyable { public typealias Element = Base.Element public typealias ProducerError = Base.ProducerError @@ -55,8 +56,11 @@ where {} @available(SwiftStdlib 5.0, *) -extension ConsumingFilterProducer: Producer where Base: ~Copyable & ~Escapable { - +extension ConsumingFilterProducer: Producer +where + Base: ~Copyable & ~Escapable, + Base.Element: ~Copyable +{ @inlinable public var underestimatedCount: Int { _base.underestimatedCount diff --git a/Sources/ContainersPreview/Protocols/Producer+Map.swift b/Sources/ContainersPreview/Protocols/Producer+Map.swift index e45867e2..45b36bcd 100644 --- a/Sources/ContainersPreview/Protocols/Producer+Map.swift +++ b/Sources/ContainersPreview/Protocols/Producer+Map.swift @@ -14,7 +14,7 @@ #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -extension Producer where Self: ~Copyable & ~Escapable { +extension Producer where Self: ~Copyable & ~Escapable, Element: ~Copyable { @_lifetime(copy self) public consuming func map( _ transform: @escaping (consuming Element) throws(ProducerError) -> T @@ -27,7 +27,9 @@ extension Producer where Self: ~Copyable & ~Escapable { public struct ConsumingMapProducer< Base: Producer & ~Copyable & ~Escapable, Element: ~Copyable, ->: ~Copyable, ~Escapable { +>: ~Copyable, ~Escapable +where Base.Element: ~Copyable +{ public typealias ProducerError = Base.ProducerError @_alwaysEmitIntoClient @@ -51,7 +53,8 @@ extension ConsumingMapProducer: Escapable where Element: ~Copyable, Base: ~Copyable, - Base: Escapable + Base: Escapable, + Base.Element: ~Copyable {} @available(SwiftStdlib 5.0, *) diff --git a/Sources/ContainersPreview/Protocols/Producer+Reduce.swift b/Sources/ContainersPreview/Protocols/Producer+Reduce.swift index d00448b9..51da345f 100644 --- a/Sources/ContainersPreview/Protocols/Producer+Reduce.swift +++ b/Sources/ContainersPreview/Protocols/Producer+Reduce.swift @@ -14,7 +14,7 @@ #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -extension Producer where Self: ~Copyable & ~Escapable { +extension Producer where Self: ~Copyable & ~Escapable, Element: ~Copyable { @inlinable public consuming func reduce( _ initialResult: consuming Result, diff --git a/Sources/ContainersPreview/Protocols/Producer.swift b/Sources/ContainersPreview/Protocols/Producer.swift index 02afb6b5..a835c616 100644 --- a/Sources/ContainersPreview/Protocols/Producer.swift +++ b/Sources/ContainersPreview/Protocols/Producer.swift @@ -164,7 +164,7 @@ public protocol Producer: ~Copyable, ~Escapable { } @available(SwiftStdlib 5.0, *) -extension Producer where Self: ~Copyable & ~Escapable { +extension Producer where Self: ~Copyable & ~Escapable, Element: ~Copyable { /// A value less than or equal to the number of remaining items that this /// producer is able to generate until it reaches its end. /// @@ -261,7 +261,7 @@ extension Producer where Self: ~Copyable & ~Escapable { } @available(SwiftStdlib 5.0, *) -extension Producer where Self: ~Copyable & ~Escapable { +extension Producer where Self: ~Copyable & ~Escapable, Element: ~Copyable { /// Returns true if the producer has no more elements, consuming it in /// the process. This is implemented by checking if it is possible to /// skip one item.