171 Commits
Author SHA1 Message Date
Karoy Lorentey 8d0a2dfceb Deque: Make the empty singleton immortal 2026-11-06 16:06:08 -08:00
Karoy Lorentey daeac4ebb8 Stop catering to toolchains older than Swift 6.2 2026-11-05 17:40:50 -08:00
Karoy Lorentey a99833003c Work around optimizer bug in Swift 6.2 (memory leaks due to miscompiled bulk deinitialization) 2026-11-05 17:40:46 -08:00
Tolga Unal 68fd4f2cc8 [DequeModule] Make UniqueDeque Iterable without ContainersPreview
842f125c removed the trait conditions around the Iterable APIs, but
UniqueDeque only got its conformance through Container in ContainersPreview.
RigidDeque had no underestimatedCount, so it was 0 through Iterable.
2026-11-05 09:09:48 -05:00
Daiki Matsudate 16710713be Make UniqueDeque's Sendable conformance checked
UniqueDeque's only stored property is RigidDeque<Element>, which is
already Sendable when Element is, so the compiler can verify the
conformance without @unchecked. This mirrors UniqueArray over RigidArray.
2026-11-02 16:56:23 +09:00
Karoy Lorentey e13f175180 Review RigidDeque/UniqueDeque tests; add better tests for prepends 2026-10-26 18:01:57 -07:00
Awais Rehman d45bd52372 Merge pull request #796 from awaisdev5765/fix-prepend-multi-span
Fix prepend(copying:) dropping items from multi-span sources
2026-10-26 12:40:35 -07:00
Aashish d04fe0cd79 Fix DequeModule doc comments: capacity-overflow example and prepend/append direction wording
The prepend(copying:) examples on RigidDeque build a capacity-10 deque and then insert 11 items, which traps with 'RigidDeque capacity overflow' -- the type never grows and the docs' own fixed-capacity section says a full deque traps. Capacity 11 holds the documented result. Also fix five copy-paste direction errors in prose summaries (append described as going to the front, prepend described as going to the end).
2026-10-23 16:45:05 +05:45
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 24339ad6a3 CMake: Remove obsolete references to source variables 2026-10-12 12:24:03 -07:00
Karoy Lorentey 1b936eda0b Disable strict memory safety on older toolchains
It would take too much effort to try to mitigate stdlib differences.

Fix low-hanging warnings, but turn off `.strictMemorySafety` on older toolchains by splitting the package manifest.
2026-10-01 13:40:27 -07:00
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 a70b97e2bf Merge pull request #721 from hxperl/docc-parameter-name-backticks
Unbacktick parameter names so DocC binds the parameter docs
2026-09-21 12:54:44 -07:00
Karoy Lorentey 45e7f63387 Merge pull request #725 from eliorpom-cmd/fix-typos-20260918
Fix typos in documentation and comments
2026-09-21 12:54:16 -07:00
Karoy Lorentey d392f0cbff MutableContainer: Add tests; resolve issues uncovered 2026-09-21 09:54:29 -07:00
Elior Pommier cabf7390ce Fix typos in documentation and comments
Corrects 25 misspellings across DocC articles, design documentation and doc
comments. Prose only: no identifiers, no public API, no behaviour change.

| Typo | Correction | Count |
|---|---|---|
| `offseting` | `offsetting` | 7 |
| `valud` | `value` | 4 |
| `necessarilly` | `necessarily` | 3 |
| `recommmend` | `recommend` | 2 |
| `Mutablility` | `Mutability` | 1 |
| `childs` | `child's` | 1 |
| `constaints` | `constraints` | 1 |
| `destintion` | `destination` | 1 |
| `explan` | `explain` | 1 |
| `forcuses` | `focuses` | 1 |
| `ot` | `or` | 1 |
| `succcess` | `success` | 1 |
| `unqiue` | `unique` | 1 |

Two of these are worth a second look, since they are not pure spelling:

- `_HTable+Removal.swift:18` reads "without marking it as unoccupied ot
  restoring the hash table's other invariants". Read as `or`, matching the
  sentence, and deliberately not as a prefix of `other` later on the line.
- `_Node.UnsafeHandle+Deletion.swift:369` reads "reuse the left childs node".
  Corrected to the possessive `child's` rather than `children`, which is what
  a plain spellchecker suggests but does not fit the sentence.

`valud` is corrected to `value` to match the wording of the equivalent
parameter documentation on `swapAt(_:_:)`.

One change is outside documentation: `CheckContainer.swift:476` fixes
`succcess` inside a test assertion message. It is a human-readable string, not
an expected value, so no test behaviour changes.

Deliberately left alone:

- `isDisjoint(with:)-54iy6` in `OrderedSet.md` is a DocC disambiguation hash,
  not a misspelling.
- `Peristent` in the 2022 ShareableHashedCollections review document, which is
  an archived record of a past review rather than living documentation.

Found with `typos-cli`, then reviewed by hand; the tool's raw output also
flagged identifiers and symbol hashes, which are not included here.
2026-09-18 14:31:47 +02:00
Karoy Lorentey c031de73d0 MutableContainer: Add some bulk update operations 2026-09-16 19:58:28 -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
hxperl 80216ab026 Unbacktick parameter names so DocC binds the parameter docs
Six `- Parameter` entries in `Deque` and `BitSet` write the parameter
name inside backticks (``- Parameter `i`:``). DocC binds parameter
documentation by bare identifier, so these never attach: no Parameters
section is rendered at all, and the entry instead falls into the
Discussion as a literal "Parameter `i`: ..." bullet, which also swallows
the `- Complexity:` callout that follows it.

Dropping the backticks around the name restores the Parameters section on
all six pages. Backticks inside the description text are left alone.
2026-09-11 14:07:13 +09: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
Alejandro Alonso d6c0fe063e Remove references to ManagedBuffer.capacity and use the given minCapacity
Fix errors

Update Deque._UnsafeHandle.swift
2026-08-12 14:09:05 -07:00
Karoy Lorentey 669eb09cea Use Iterable from the Standard Library, replacing the local definition 2026-07-27 13:32:46 -07:00
Karoy Lorentey 8380ca41da Merge pull request #682 from lorentey/container-updates
[ContainersPreview] Update Container protocols
2026-07-22 13:08:25 -07:00
Karoy Lorentey 232dc7f9ee Add second parameter to Container.makeBorrowingIterator(from:to:) 2026-07-21 15:21:45 -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 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 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 62332dc40a Avoid borrow/mutate accessors before Swift 6.4 2026-07-07 16:52:32 -07:00
Karoy Lorentey b1cba02393 [DequeModule] Disable Equatable/Hashable conformance on pre-6.4 toolchains 2026-07-07 16:47:05 -07:00
Karoy Lorentey fbb8aa1e36 [DequeModule] UniqueDeque: Add isTriviallyIdentical(to:) 2026-07-07 16:42:51 -07:00
Karoy Lorentey 920bc2a81f [DequeModule] RigidDeque: Fix duplicate Equatable conformance 2026-07-07 15:21:26 -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 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
wjdtjq6 62a08e503e docs: fix typos in doc comments and DocC article 2026-07-02 21:17:11 +09:00
Karoy Lorentey e8b09ade25 Add subscript requirements to [Mutable]Container with borrow/mutate accessors 2026-06-22 20:10:22 -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 1f5d0ab343 [BasicContainers, DequeModule] Resolve warnings in 6.4 2026-06-18 13:21:42 -07:00
Karoy Lorentey 73ec3d3416 [BasicContainers, DequeModule] Clean up Equatable/Hashable conformances
Make sure all types conditionally conform to Equatable/Hashable, even if their contents happen to be noncopyable.
2026-06-18 12:56:23 -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 bced34defa Review error handling 2026-06-17 18:24:03 -07:00