Stop shipping retroactive Iterable conformances on standard types

This commit is contained in:
Karoy Lorentey committed 2026-09-22 19:04:09 -07:00
1 parent 021a54b8cc
commit 2dcded505e
4 files changed
-170

No files matched your search

-3
View File
@@ -25,12 +25,9 @@ else()
endif()
target_sources(${module_name} PRIVATE
"Conformances/Array+Iterable.swift"
"Conformances/ClosedRange+Iterable.swift"
"Conformances/InputSpan+Container.swift"
"Conformances/MutableSpan+Container.swift"
"Conformances/OutputSpan+Container.swift"
"Conformances/Range+Iterable.swift"
"Conformances/RigidArray+Container.swift"
"Conformances/RigidDeque+Container.swift"
"Conformances/RigidSet+Container.swift"
@@ -1,30 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2026 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
// SPDX-License-Identifier: Apache-2.0 WITH Swift-exception
//
//===----------------------------------------------------------------------===//
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 6.4, *)
extension Array: @retroactive Iterable {
public typealias BorrowingIterator = Span<Element>.BorrowingIterator
@inlinable
public var underestimatedCount: Int { count }
@_lifetime(borrow self)
@inlinable
public func makeBorrowingIterator() -> BorrowingIterator {
BorrowingIterator(self.span)
}
}
#endif
@@ -1,69 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2026 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
// SPDX-License-Identifier: Apache-2.0 WITH Swift-exception
//
//===----------------------------------------------------------------------===//
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 6.2, *)
extension ClosedRange: @retroactive Iterable
where Bound: Strideable, Bound.Stride: SignedInteger
{
public typealias Element = Bound
@frozen
public struct BorrowingIterator: BorrowingIteratorProtocol, ~Copyable {
@usableFromInline
internal var _current: InlineArray<1, Bound>
@usableFromInline
internal var _last: Bound
@usableFromInline
internal var _progress: Bool
@inlinable
internal init(_ base: ClosedRange<Bound>) {
self._current = .init(repeating: base.lowerBound)
self._last = base.upperBound
self._progress = false
}
@inlinable
@_lifetime(&self)
public mutating func nextSpan(maxCount: Int) -> Span<Bound> {
if _progress {
_current[0] = _current[0].advanced(by: 1)
}
guard _current[0] <= _last else {
_progress = false
return .init()
}
_progress = true
return _current.span
}
}
@inlinable
public var underestimatedCount: Int {
guard let distance = Int(exactly: lowerBound.distance(to: upperBound))
else { return 0 }
let advanced = distance.addingReportingOverflow(1)
guard !advanced.overflow else { return 0 }
return advanced.partialValue
}
@inlinable
public func makeBorrowingIterator() -> BorrowingIterator {
BorrowingIterator(self)
}
}
#endif
@@ -1,68 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2026 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
// SPDX-License-Identifier: Apache-2.0 WITH Swift-exception
//
//===----------------------------------------------------------------------===//
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 6.4, *)
extension Range: @retroactive Iterable
where Bound: Strideable, Bound.Stride: SignedInteger
{
public typealias Element = Bound
@frozen
public struct BorrowingIterator: BorrowingIteratorProtocol, ~Copyable {
@usableFromInline
internal var _current: InlineArray<1, Bound>
@usableFromInline
internal var _end: Bound
@usableFromInline
internal var _progress: Bool
@inlinable
internal init(_ base: Range<Bound>) {
self._current = .init(repeating: base.lowerBound)
self._end = base.upperBound
self._progress = false
}
@inlinable
@_lifetime(&self)
public mutating func nextSpan(maxCount: Int) -> Span<Bound> {
if _progress {
_current[0] = _current[0].advanced(by: 1)
}
guard _current[0] < _end else {
_progress = false
return .init()
}
_progress = true
return _current.span
}
}
@inlinable
public var underestimatedCount: Int {
guard let count = Int(exactly: lowerBound.distance(to: upperBound)) else {
return 0
}
return count
}
@inlinable
public func makeBorrowingIterator() -> BorrowingIterator {
BorrowingIterator(self)
}
}
#endif