Commit Graph
149 Commits
Author SHA1 Message Date
Karoy Lorentey 98bc1f9965 Fix some issues on earlier toolchains 2026-07-20 16:54:23 -07:00
Karoy Lorentey ea64e6332f Update RandomAccessContainer
- Require Index to be Comparable
- Add `formIndex(_:offsetBy:limitedBy:)` algorithm
2026-07-20 15:45:32 -07:00
Karoy Lorentey e75f053e46 Update MutableContainer
- Add `nextMutableSpan(after:)` and `nextMutableSpan(after:maxCount:limitedBy)`, replacing `nextMutableSpan(after:maxCount:)` as the core access primitives
- Add `previousMutableSpan` default algorithms on bidirectional mutable containers
2026-07-20 15:44:35 -07:00
Karoy Lorentey ef0fba7f7f Resolve some implementation issues 2026-07-20 15:42:28 -07:00
Karoy Lorentey 95395ad9d2 Add BidirectionalContainer.spanBoundary(before:maxDistance:limitedBy:) and make it the core primitive 2026-07-20 11:51:43 -07:00
Karoy Lorentey e70b4df228 Introduce Container.nextSpan(after:maxCount:limitedBy:) and make it the core Container primitive 2026-07-18 14:14:13 -07:00
Karoy Lorentey 391693a8ba Review and update BidirectionalContainer’s default implementations 2026-07-17 16:58:01 -07:00
Karoy Lorentey a7f6b90c99 Make the limit optional in Container.nextSpan(after:limitedBy:). Review and update default implementations
- Make `nextSpan(after:limitedBy:)` the core iteration interface
- Review default algorithms and update them to use it, speeding them up
- Spin off `Span._nextSpan(after:maxCount)` and `Span._nextSpan(after:limitedBy:)` with copying lifetime semantics. This allows forwarding to these without having to override lifetimes.
2026-07-17 16:57:26 -07:00
Karoy Lorentey 27fe58c42c Beef up ContainerIterator’s provided algorithms 2026-07-17 11:51:20 -07:00
Karoy Lorentey 99ac14d1fa previousSpan(before:maxCount:) ⟹ spanBoundary(before:maxDistance:)
This allows MutableContainers to support mutating iteration backwards without requiring a separate MutableBidirectionalContainer protocol.
2026-07-17 11:50:38 -07:00
Karoy Lorentey ea581e47e1 Add UnfoldProducer 2026-07-15 15:10:58 -07:00
Karoy Lorentey dcaffab0af Update Container
- Require Index to be Hashable
- Add strong complexity expectations. Require `isEmpty`, `count` and `endIndex` to have O(1) complexity. Recommend most index navigation methods to be linear in the distance traveled.
- Remove `index(alignedDown:)` and `index(alignedUp:)`; Collection views are far less relevant in this model, so index rounding is mostly unnecessary. (The need can still pop up when indices are shared between several views of layout-compatible Element types — such as a container of UInt64 than can also be interpreted as a container of UInt8; if that becomes a thing, we may need to bring these requirements back.)
- Add `nextSpan(after:limitedBy:)` as an alternative to `nextSpan(after:maximumCount:)`. This makes it possible to provide fast default implementations for `distance(from:to:)` and `formIndex(_:offsetBy:limitedBy:)`.
2026-07-15 15:10:58 -07:00
Karoy Lorentey 6210abf469 Update Producer/Drain algorithms
- Implement skip(by:) whenever possible
2026-07-14 17:54:03 -07:00
Karoy Lorentey dfd2e34009 Overhaul Producer’s skip(by:) to better align with Iterable
- Don’t allow `skip(by:)` to skip fewer than the requested number of items, unless it hits the end of the sequence or an error. Remove its Boolean return value.
- Introduce a variant of `skip(by:)` that doesn’t take an inout argument, losing the ability to report which item triggered a throw. This is just a standard algorithm; the protocol continues to require proper reporting of partial success.
- Use the stdlib’s `withTemporaryAllocation` method where possible to create temporary buffers.
2026-07-14 17:45:27 -07:00
Karoy Lorentey 62332dc40a Avoid borrow/mutate accessors before Swift 6.4 2026-07-07 16:52:32 -07:00
Karoy Lorentey c6eabe862a Resolve access issues & missing imports 2026-07-07 14:34:41 -07:00
Karoy Lorentey ff695132ed Bump availability of Iterable_ and Container protocols to SwiftStdlib 6.4
This is preparing for switching over to the stdlib’s definition of `protocol Iterable`, assuming it will land with macOS 27/iOS 27 etc availability; `Container` is refining `Iterable`, so it needs matching availability.

If `Iterable` won’t ship in Swift 6.4, then we’ll need to bump this again.
2026-07-07 14:22:45 -07:00
Karoy Lorentey a80c9d1257 Container: Add makeBorrowingIterator(from:) and currentIndex(of:) requirements 2026-07-07 14:21:54 -07:00
Karoy Lorentey 721b5bce41 Iterable_: Define an ambiguity resolver for the default underEstimatedCount 2026-07-07 14:21:54 -07:00
Karoy Lorentey d0b4c4c215 IterableIterator_ → BorrowingIterator_ 2026-07-07 14:21:53 -07:00
Karoy Lorentey bb0dc189ef maximumCount → maxCount
While we’re here, adjust `RigidSet.insert(maximumCount:initializingWith:)` and similar APIs to be consistent with RangeReplaceableContainer’s methods.
2026-07-07 14:21:53 -07:00
Karoy Lorentey 72c0dd258d IterableIteratorProtocol_ → BorrowingIteratorProtocol_ 2026-07-07 14:20:26 -07:00
Karoy Lorentey 3ba8d70ec3 Review and update container protocols and conformances
- @inlinable → @_alwaysEmitIntoClient for now, to avoid temporary ABI issues
- Review RangeReplaceableContainer algorithms; add missing ones:
    - New requirements: `removeFirst()`, `removeFirst(_:)`, `_customRemoveLast()`, `_customRemoveLast(_:) (with default implementations)
    - `func removeAll()`
    - `func removeLast()`, `func removeLast(_:)`, `func popLast()` when self is also bidirectional
- Review RigidArray, UniqueArray algorithms; remove ones needlessly duplicating functionality already provided by RRC. Try not to break source compatibility.
2026-07-07 14:18:09 -07:00
Karoy Lorentey 204e94cb63 [ContainersPreview] Conform span types to some of the container protocols
This is currently limited to `Container`, `BidirectionalContainer`, `RandomAccessContainer` and `MutableContainer`. `OutputSpan` and `InputSpan` should also be `RangeReplaceableContainer`s, but that is proving tricky to express in current Swift.
2026-07-07 14:18:09 -07:00
Karoy Lorentey 8a1438c2b2 [ContainersPreview] Update/fix RangeReplaceableContainer
- Introduce easy-to-use `replace(removing:addingFrom:)`, `insert(from:at:)`, and `append(from:)` algorithms that take `CountedProducer` instances, avoiding having to pass explicit counts separately
- Avoid RangeExpression2 helpers from satisfying core protocol requirements, leading to broken conformances
- Add `replace(removing:moving:)`, `replace(removing:consuming:)`, `insert(moving:at:)`, `insert(consuming:at:)`, `append(moving:)`, `append(consuming:)` operations that take range-replaceable containers.
- Reorder some parameters for consistency/readability:
    - `insert(addingCount:at:from:)` → `insert(addingCount:from:at:)`
    - `insert(at:moving:from:)` → `insert(moving:from:at:)`
2026-06-23 17:30:24 -07:00
Karoy Lorentey b2c1669aa7 [ContainersPreview] RandomAccessContainer: Add a separate set of default implementations for Index == Int
This avoids going through Strideable, likely assisting the inliner.

Also mark default implementations @_aeic, to avoid ABI headaches
2026-06-23 17:07:25 -07:00
Karoy Lorentey 250af87308 [ContainersPreview] Redeclare Container requirements in refining protocols
Use `override`/`@_nonoverride` to help associated type inference and to allow diverging implementations of select requirements in BidirectionalContainer, RandomAccessContainer, and MutableContainer.
2026-06-23 16:55:53 -07:00
Karoy Lorentey e8b09ade25 Add subscript requirements to [Mutable]Container with borrow/mutate accessors 2026-06-22 20:10:22 -07:00
Karoy Lorentey 22a94a9756 [ContainersPreview] Have RangeExpression2 refine RangeExpression 2026-06-18 15:31:37 -07:00
Karoy Lorentey 130d235b28 Resolve issues after rebase 2026-06-18 13:29:52 -07:00
Karoy Lorentey 12b1cf8020 [ContainersPreview] Make Drain refine CountedProducer
This lets us avoid having to pass an explicit count when using a drain to populate a container.
2026-06-18 13:22:16 -07:00
Karoy Lorentey eabf5141d1 [ContainersPreview] Add CountedProducer protocol 2026-06-18 13:22:16 -07:00
Karoy Lorentey de3b9b67be [ContainersPreview] Move helpers to InternalCollectionsUtilities 2026-06-18 13:20:38 -07:00
Karoy Lorentey 3d68fc1107 Clean up the UniqueBox/Ref/MutableRef situation
- UniqueBox is public API, so we cannot remove it in favor of the stdlib’s
- Remove Ref and MutableRef. Keep an internal _MutableRef to work around stdlib limitations.
2026-06-17 18:29:41 -07:00
Karoy Lorentey 51c9e4ead8 Fix IterableIteratorProtocol.map; add map2 and map3 with different throwing behavior 2026-06-17 18:24:03 -07:00
Karoy Lorentey 7c853751c6 Add IterableIteratorProtocol.mapError 2026-06-17 18:24:03 -07:00
Karoy Lorentey bced34defa Review error handling 2026-06-17 18:24:03 -07:00
Karoy Lorentey 85cdb77d25 Fix build issues 2026-06-17 16:17:36 -07:00
Karoy Lorentey 816b887369 Update CMake and Xcode build configurations 2026-06-17 14:40:07 -07:00
Nate Cook c039a18a0e Switch to using stdlib Ref and UniqueBox 2026-06-17 14:27:29 -07:00
Nate Cook dca015d7e8 Align Iterable with proposal
Adds throwing and ~Escapable elements
2026-06-17 14:27:29 -07:00
Nate Cook 4bda43f4a9 Renaming BorrowingSequence_ to Iterable_ 2026-06-17 14:27:29 -07:00
Karoy Lorentey e31c04143e Update CMake & Xcode build configurations 2026-06-05 18:45:56 -07:00
Guoye Zhang 8cacd3c125 Add missing availability to Borrow 2026-05-18 17:50:20 -07:00
Franz Busch f674e13c3d Guard UniqueBox.borrow correctly
Correctly guard the `borrow` method behind the compiler version
2026-05-11 14:43:54 +02:00
Karoy Lorentey 16d6b8e1fe [ContainersPreview] Inout ⟹ MutableRef 2026-05-06 18:28:07 -07:00
Karoy Lorentey 1fd366764d [ContainersPreview] Ref: Fix fallback implementation; make sure we have deprecated aliases for old names 2026-05-06 18:00:13 -07:00
Karoy Lorentey 18c58bcca4 [ContainersPreview] Ref: Disable Builtin.Borrow for now 2026-05-06 18:00:13 -07:00
Karoy Lorentey a6fd64697a [ContainersPreview] Borrow ⟹ Ref
Also update the type’s public API surface to reflect SE-0519, leaving deprecated aliases for the old names.
2026-05-06 18:00:13 -07:00
Franz Busch 3c373b900c Use the defines from traits directly
Package traits already pass defines with their trait name when building. Instead of adding our own conditional defines based on the traits we can use the trait provided defines directly. I observed that various tooling behaves better with the trait provided defines.
2026-05-06 07:41:02 -07:00