1251 Commits
Author SHA1 Message Date
Karoy Lorentey e2c040bcaa BorrowingIteratorProtocol.map: Hide map2 and map3 behind underscores
`map2` and `map3` are merely illustrating problems with the throwing Iterable in higher-order functions in Swift 6.4; they aren’t really suitable for exposing as API, even behind a package trait.
2026-09-22 19:04:12 -07:00
Karoy Lorentey 2dcded505e Stop shipping retroactive Iterable conformances on standard types 2026-09-22 19:04:09 -07:00
Karoy Lorentey 9bf8a9763b Merge pull request #729 from lorentey/release-prep
1.7.0 release preparations
2026-09-22 12:42:05 -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 8e4f078441 Producer.generate(into:): Switch to saturating semantics
This noticeable simplifies client code, as clients invariably want to fully populate their buffer (when possible). It also is consistent with the semantics of `Iterable.skip(by:)`.
2026-09-21 13:07:01 -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 561d10ed84 Merge pull request #727 from lorentey/container-updates
Container: Reinstate requirement for Comparable indices
2026-09-21 11:01:37 -07:00
Karoy Lorentey b2424210b4 Container: Reinstate requirement for Comparable indices
I have a linked list prototype that can support comparable indices (and an O(1) `count`); accordingly, reinstate the requirement for index comparability. This eliminates a potential performance footgun for custom containers that define their own Index, as an incomparable index would make `func distance` 2x slower.
2026-09-21 10:41:46 -07:00
Karoy Lorentey f5db7175b3 Merge pull request #724 from lorentey/container-updates
MutableContainer: Add some bulk update operations
2026-09-21 10:10:34 -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 4ea0e4443d MutableContainer: Also add copying variants of bulk updates 2026-09-16 20:44:13 -07:00
Karoy Lorentey c031de73d0 MutableContainer: Add some bulk update operations 2026-09-16 19:58:28 -07:00
Karoy Lorentey 3ceaf1ac39 Merge pull request #723 from lorentey/container-updates
Refactor DrainableContainer/RangeReplaceableContainer/DynamicContainer
2026-09-16 13:40:56 -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 774d6ba631 Merge pull request #718 from dylanpulver/bitset-isequalset-empty-range
[BitSet] Fix isEqualSet(to: Range<Int>) for empty ranges
2026-09-04 10:48:55 -07:00
Karoy Lorentey 396fee354f Merge pull request #717 from Azoy/rigiddictionary-layout-update
[RigidDictionary] Store a sentinel value for values ptr if null
2026-09-02 17:12:29 -07:00
Dylan Pulver 85342a6a49 [BitSet] isEqualSet(to: Range<Int>) is wrong for an empty range
`_toUInt()` returns nil whenever a bound is negative, and the guard maps that
straight to `false`. That is right for a nonempty range -- a bit set can never
hold a negative value -- but an empty range equals the empty set regardless of
where its bounds sit, so `BitSet().isEqualSet(to: -5 ..< -5)` answered false.

Five of the six `Range<Int>` predicates already handle this: isSubset and
isDisjoint clamp, isStrictSubset composes those two, and isSuperset and
isStrictSuperset test `other.isEmpty` before converting. isEqualSet was the
one that did not, which let a bit set be both a subset and a superset of a
range while reporting that it was not equal to it.
2026-09-03 02:59:42 +03:00
Alejandro Alonso b2110d3563 Use single module conditional 2026-09-02 14:52:44 -07:00
Alejandro Alonso e773108091 Make RigidDictionary store a sentinel value for values ptr if null 2026-09-02 14:25:00 -07:00
Karoy Lorentey 08bbdd3def Reinstate exported imports in Collections module 2026-09-01 13:46:05 -07:00
Karoy Lorentey 26f299bd49 Merge pull request #715 from lorentey/no-dynamic-conformance-checks-in-embedded
Disable `_UniqueCollection` fast paths in embedded Swift
2026-09-01 10:50:17 -07:00
Karoy Lorentey e611f62e67 Disable _UniqueCollection fast paths in embedded Swift
As of 2026-09-01, conformance checks are now diagnosed as errors:

```
 70 |     // Fast paths for when we know elements are all unique
 71 |     if elements is _UniqueCollection {
    |                 `- error: cannot perform a dynamic cast to a type involving protocol '_UniqueCollection' in Embedded Swift
```
2026-09-01 10:31:54 -07:00
Karoy Lorentey 225bd07e56 RigidSet, UniqueSet: Add Container conformance 2026-09-01 09:34:05 -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
Karoy Lorentey 1574bed0dc [ContainersPreview] Spin off removal/consumption operations from RangeReplaceableContainer into a new DrainableContainer protocol
We have types that can usefully conform to `DrainableContainer` but not the full `RangeReplaceableContainer`; `OrderedSet` is one obvious example.
2026-08-25 14:10:06 -07:00
Karoy Lorentey 7e2a4bc761 Merge pull request #705 from karpovantonme/doc/sorted-collections
[SortedCollections] Name the documented arguments the way the declarations name them
2026-08-25 14:02:59 -07:00
Karoy Lorentey fcfa3b00cb Merge pull request #703 from inju2403/cleanup/replaceelement-exchange-same-key
[OrderedCollections] Use exchange(_:with:) in replaceElement's equal-key path
2026-08-25 14:02:39 -07:00
Karoy Lorentey 99b8eca1c2 Merge pull request #701 from karpovantonme/doc/parameter-names
Name the documented arguments the way the declarations name them
2026-08-25 13:50:46 -07:00
Karoy Lorentey f425dffd5b Merge pull request #702 from apple/dn/bit-set-count
Improve `BitSet.count` performance by ~3x
2026-08-18 13:54:33 -07:00
Anton Karpov ed41e49a16 [SortedCollections] Name the documented arguments the way the declarations name them
Same species as #701, in the module behind the UnstableSortedCollections
trait. 16 doc comments name an argument the declaration does not have, and
one block documents a function that is no longer there.

The Keys and Values views carry the same four each: - Parameter i where the
argument is index, and - Parameter index on subscript(position:).

In the B-tree internals the descriptions usually name the right thing while
the key does not: - node on toNode(leftChild:) says the argument becomes the
left child, and - newElement on exchangeChild(atSlot:with newChild:) says it
is the new child.

_BTree.swift keeps a doc block for a function that was removed: it documents
an offset parameter and sits above an unrelated declaration.
2026-08-16 21:52:31 +03:00
David Nadoba 962d21d92d Mark _Word.allBits as @inlinable 2026-08-14 16:32:50 -07:00
inju2403 7a67033ee2 [OrderedCollections] Use exchange(_:with:) in replaceElement's equal-key path
#688 factored `replaceElement`'s general case onto `OrderedSet._replaceNew(at:with:in:)` and, per review feedback, switched the value overwrite there to `exchange(_:with:)`. The equal-key path above it was outside that diff, so it still reads the old value into a local and then assigns over it.

Switch it to `exchange(_:with:)` as well, so both paths move the old value out instead of copying it. No behavior change: the returned element, the preconditions, and the expected amortized O(1) complexity are all unchanged.
2026-08-14 09:19:43 +09:00
David Nadoba 8a050cd30d Improve BitSet.count performance 2026-08-13 13:52:01 -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 f3e778f17a Merge pull request #699 from Azoy/eliminate-duplicate-bounds-checks
[Rigid/UniqueArray] Eliminate some duplicate bounds checks for UniqueArray
2026-08-12 15:24:17 -07:00
Alejandro Alonso d44d6a3a26 Update UniqueArray+Append.swift 2026-08-12 15:04:38 -07: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
Alejandro Alonso 1b511f7652 Update UniqueArray+Append.swift 2026-08-12 14:07:15 -07:00
Alejandro Alonso 6c7ebb3cb9 Update UniqueArray+Append.swift 2026-08-12 13:32:38 -07:00
Alejandro Alonso dad98a58ca Replace inlinable with aEIC 2026-08-12 13:31:02 -07:00
Alejandro Alonso 4fd692f00b Apply review suggestions 2026-08-12 13:29:24 -07:00
Alejandro Alonso f2914d4fb4 Eliminate some duplicate bounds checks for UniqueArray 2026-08-12 12:25:12 -07:00
Karoy Lorentey 2dae6db88f Merge pull request #697 from Hashim1999164/fix/sorted-dictionary-keys-values-equality
Fix inverted SortedDictionary Keys/Values/SubSequence equality
2026-08-11 14:25:33 -07:00
Karoy Lorentey 2875152465 Merge pull request #688 from inju2403/cleanup/replaceelement-reuse-replace
[OrderedCollections] Share OrderedSet's replace primitive with OrderedDictionary.replaceElement
2026-08-11 14:11:16 -07:00
Alejandro Alonso b2a1f89cc6 Add mutableValue(forKey:) to new dictionary types 2026-08-10 17:48:13 -07:00
Hashim1999164 01d981c87e Use tuple inequality in SortedDictionary.SubSequence equality.
Match the Keys and Values comparison style after review feedback.
2026-08-02 22:52:49 +05:00
Hashim1999164 1efcb6cabd Fix inverted equality in SortedDictionary Keys, Values, and SubSequence.
Equality comparisons returned false for matching elements and true for mismatches. Correct the comparisons and add coverage for the affected views.
2026-08-02 22:52:49 +05:00