31 Commits
Author SHA1 Message Date
Karoy Lorentey bbdd37ada7 Fix a variety of issues in the nextSpan/previousSpan method family 2026-10-21 19:56:55 -07:00
Swastik TripathiandClaude Opus 5.5 5d4a707373 [UniqueDeque] Fix prepend(from:) reversing batch order when producer needs multiple passes
prepend(from:) looped calling uncheckedPrepend, which each time placed the
new batch at index 0 of the deque. Later batches ended up in front of earlier
ones, producing items in the wrong order.

Fix: use uncheckedInsert(addingCount:at:added) so each new batch is inserted
immediately after the items already prepended in earlier passes. Promote the
overload from internal to package so ContainersPreview can reach it.

Adds a regression test covering single- and multi-batch producers prepending
into empty and non-empty deques. Fixes #763.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 08:35:03 +05:30
Karoy Lorentey d07dc32dfa Sources: Add unsafe keywords where needed 2026-10-01 11:14:29 -07:00
Karoy Lorentey 537bf9cbfb Drop support for Swift 6.0 and 6.1
This allows the use of Span types without `#if compiler` guards.
2026-09-21 13:34:39 -07:00
Karoy Lorentey 5cebba6f29 Refactor DrainableContainer/RangeReplaceableContainer/DynamicContainer
Range replacement operations generally need to invalidate all indices, and that means that we lose our position in the container after each insertion/removal, unless we happen to be using a container with looser index invalidation (such as arrays or deques).

A linked list is an example for a container type where insertions/removals need to invalidate all indices — as we need to track index validation using a single version counter that is stored in the list’s head. However, it would not be acceptable to lose our place whenever we insert a new item to the list; therefore, to mitigate the validation issue, this commit changes all range-replacement operations to return a valid index range to the affected items in the container.

This is a radical break from `RangeReplaceableCollection`. It fixes a long-standing defect with it, but it also makes it tricky to conform the same type to both protocol families, as the two require the “same” methods to return different types (`Void` vs `Range<Index>`).

Given that the LSG has intentionally diverged `UniqueArray.removeAll()` from RangeReplaceableCollection semantics, I expect this isn’t going to be an issue. For example, types with existing collection conformances can expose container views, mitigating such semantic differences.

To allow SubrangeConsumers to work without losing position, add a new protocol, `ContainerDrain` with a consuming `finalize` operation that returns a valid index in the resulting container state.

While we’re here, apply the API tweaks from SE-0527:
- Revert the `replace(removing:…:)` names, rolling back to `replaceSubrange(_:…:)` .
- Similarly, rename `consume(_:)` → `consumeSubrange(_:)`
- Rename `reallocate(capacity:)` → `setCapacity(_:)`.
2026-09-14 20:37:12 -07:00
Karoy Lorentey 842f125c47 Invert dependencies to ContainersPreview, moving all container APIs there
- Move `InputSpan` into its own module, `SpanPreview`. Add dependencies to it.
- Invert dependencies to `ContainersPreview`, so that no production target imports it, but it now depends on its previous dependents.
- Move all generic APIs and conformances using `Producer`/`Drain`/`Container` to the `ContainersPreview` module.
- Remove `UnstableContainersPreview` conditions around `Iterable` APIs

In summary, importing `BasicContainers` and `DequeModule` continue to get us the basic definitions for `RigidArray`, `UniqueSet`, `RigidDeque` etc., without most of their unstable APIs. (With the exception of core APIs that require `InputSpan`.)

To get any API that uses an unstable protocol like `Container` or `Drain`, we’ll now need to import `ContainersPreview` in addition to the type-defining module.

This will provide a slightly less horrible migration path when (if) the container/producer protocol family gets adopted/adapted into the stdlib.
2026-08-25 18:29:58 -07:00
Anton Karpov c2b2092f94 Name the documented arguments the way the declarations name them
Twenty-five doc comments in the shipping modules name an argument that the
declaration below them does not have, so DocC has nothing to bind the
description to and drops it. Nothing warns about this.

Most of them are renames that the comment did not follow, and the file itself
usually holds the proof: RigidDeque.prepend says - maxCount while its own
Complexity line already says newItemCount, and append(copying:) has three
overloads where the oldest still takes newElements and the two newer ones take
items with the older one's wording.

Three entries name an argument that no longer exists at all and are removed
rather than renamed.
2026-08-13 16:29:06 +03: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
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
Karoy Lorentey 6bbed0e1e2 [ContainersPreview] Conform [Unique,Rigid]Array and [Unique,Rigid]Deque to container protocols 2026-03-17 13:13:42 -07:00
Karoy Lorentey 1c69635852 Add SPDX-License-Identifier tags 2026-03-05 19:39:24 -08:00
Karoy Lorentey 6e496a9512 [DequeModule] Review bulk insertion/append/prepend/replace operations 2026-02-27 18:02:06 -08:00
Karoy Lorentey 35e09984f5 [doc] Add missing colon after “Parameters” 2026-02-05 16:48:05 -08:00
Karoy Lorentey 653a60b8e7 replaceSubrange(_:...) → replace(removing:...) 2026-02-05 14:56:51 -08:00
Karoy Lorentey e4a874b67a Rigid & Unique types: Add Equatable, Hashable, Custom[Debug]StringConvertible operations
Currently these are all conditional on copyable elements, and the types cannot conform to the actual protocols yet.
2026-02-04 23:24:08 -08:00
Karoy Lorentey 06f2ec073d Rigid, Unique types: Rework OutputSpan-based append/prepend/insert/replaceSubrange primitives 2026-02-04 17:29:43 -08:00
Karoy Lorentey 9503f8fe57 Improve consistency of precondition failure messages
More uniform message strings should feel better, and they should ever so slightly reduce code size.
2026-02-04 10:27:17 -08:00
Karoy Lorentey 3a1498781a Fix support for older compilers 2026-01-26 11:18:59 -08:00
Karoy Lorentey 76fa120c27 More RigidDeque testing 2026-01-26 11:18:57 -08:00
Karoy Lorentey 29b31e5e0d RigidDeque: Add test coverage; fix issues 2026-01-25 16:42:41 -08:00
Karoy Lorentey 70a36c2c47 RigidDeque: Another iterative design pass on deque operations
- Adopt and embrace Drain and Producer to simplify moving data in and out of deques.
- Fully generalized core range replacement primitive using higher-order functions based around InputSpan and OutputSpan
2026-01-25 16:42:40 -08:00
Karoy Lorentey 7b5221ea24 RigidDeque: Add Container conformance and allow copying from Containers 2026-01-20 10:51:17 -08:00
Karoy Lorentey d1d757e425 [RigidDeque] Implement replacement operations 2026-01-08 17:25:21 -08:00
Karoy Lorentey 5943e6eb5c [RigidDeque] Flesh out insertions 2026-01-07 17:46:25 -08:00
Karoy Lorentey 16aac1913c [RigidDeque] Clean up initializers 2026-01-06 15:49:14 -08:00
Karoy Lorentey 54494e1c98 [RigidDeque] Flesh out prepend methods 2026-01-06 15:14:07 -08:00
Karoy Lorentey 722ed6ae90 [RigidDeque] Flesh out append methods 2026-01-05 18:29:31 -08:00
Nate Cook ec89f90bd0 Expand RigidDeque test coverage 2025-12-15 10:39:46 -06:00
Nate Cook 8320ac8215 Add additional API and tests 2025-11-02 14:59:55 -06:00
Alejandro Alonso 3975774393 wip 2025-10-23 15:05:12 -07:00