1996 Commits
Author SHA1 Message Date
Karoy Lorentey 3b69cedbaa Merge pull request #747 from lorentey/strict-memory-safety
Enable strict memory safety on Swift 6.4
1.7.2
2026-10-01 14:18:10 -07:00
Karoy Lorentey 017f766cb9 Update package manifest for benchmarks
- Bump required toolchain to 6.4
- Add availability macros for 6.4 and 6.5.
2026-10-01 13:41:06 -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 9e7949017a Tests: add unsafe keywords where needed 2026-10-01 11:44:47 -07:00
Karoy Lorentey d07dc32dfa Sources: Add unsafe keywords where needed 2026-10-01 11:14:29 -07:00
Karoy Lorentey 13f71ad927 Enable strict memory safety 2026-09-30 20:40:09 -07:00
Karoy Lorentey a5b094974f Merge pull request #745 from lorentey/migrate-from-spi-to-package
Stop using `@_spi` attribute and `@testable import`
2026-09-29 18:51:34 -07:00
Karoy Lorentey c991c8543a Update SortedCollections for un-@testable testing 2026-09-29 18:32:58 -07:00
Karoy Lorentey 0ec72a9532 Stop using @_spi attribute and @testable import 2026-09-29 18:32:55 -07:00
Karoy Lorentey afb6141ea0 Merge pull request #744 from lorentey/separate-containers-preview
[Xcode, CMake]: Build ContainersPreview as a standalone module
2026-09-29 16:24:25 -07:00
Karoy Lorentey 77e71ebc78 Update Xcode Project Build job
Build the `ContainersPreview` scheme in addition to `Collections`.
2026-09-29 15:45:04 -07:00
Karoy Lorentey c410b3cd3a Remove obsolete/disabled APIs 2026-09-29 15:41:06 -07:00
Karoy Lorentey 44b674265c Update import statements 2026-09-29 15:41:05 -07:00
Karoy Lorentey 1be474f795 Xcode, CMake: Spin off ContainersPreview into its own target 2026-09-29 15:41:03 -07:00
Karoy Lorentey 98ef3c9860 Merge pull request #740 from lorentey/release-prep
Version 1.7.1 release preparations
1.7.1
2026-09-25 16:44:01 -07:00
Karoy Lorentey a1f0f1411c Update README 2026-09-25 16:01:45 -07:00
Karoy Lorentey 935af54791 [Xcode] Remove obsolete file references 2026-09-25 16:01:42 -07:00
Karoy Lorentey 2ba0f6e59f Merge pull request #739 from lorentey/drop-unused-code
Avoid using `Ref` in Swift 6.4
2026-09-25 15:18:19 -07:00
Karoy Lorentey f57d12f86c Merge pull request #735 from Joseph-Cursio/validate-container-count-guard
validateContainer: report a mis-sized expectation instead of trapping or ignoring it
2026-09-25 15:13:24 -07:00
Karoy Lorentey f1e675acd2 Turn off BorrowingIteratorProtocol.next()
The reference to `Ref` appears to trigger a broken strong linkage to `_swift_initBorrow`, despite the code being only available on macOS/iOS/etc 27.
2026-09-25 15:01:04 -07:00
Karoy Lorentey feef32596a Merge pull request #736 from Denimworld12/fix-bitset-counted-update-count
[BitCollections] Fix BitSet.Counted.update(with:) not maintaining the cached count
2026-09-25 14:07:45 -07:00
Karoy Lorentey 21807d9116 Merge pull request #737 from Denimworld12/fix-union-wrong-level
[HashTreeCollections] Fix union misplacing items pushed into a new child
2026-09-25 14:07:00 -07:00
Karoy Lorentey 99b82a4985 Apply batched suggestions from code review
Co-authored-by: Karoy Lorentey <klorentey@apple.com>
2026-09-25 13:48:39 -07:00
Karoy Lorentey 5448b9cdb1 Delete distracting comments
Co-authored-by: Karoy Lorentey <klorentey@apple.com>
2026-09-25 13:47:08 -07:00
Karoy Lorentey 882169ae00 Merge pull request #738 from apple/ospobot/code-of-conduct
Housekeeping: replace repo-level CODE_OF_CONDUCT
2026-09-25 13:34:09 -07:00
apple-ospo[bot] bb7c1a33d4 Replace repo-level CODE_OF_CONDUCT file with the inherited org-wide Code of Conduct in .github repo. 2026-09-25 17:41:17 +00:00
Nikhil Gupta ab29aa793d [HashTreeCollections] Fix union misplacing items pushed into a new child
`copyNodeAndPushItemIntoNewChild` takes an existing item out of `self` and
pushes it into `newChild`, which is then installed as a child of `self` at
`bucket`. `newChild` therefore sits one level below `self`, but the item was
inserted into it using `self`'s level:

    let r = newChild.inserting(level, item, hash)

Navigating with the parent's level picks the wrong hash digit, so the item —
and the subtree it is merged with — end up filed under a path that doesn't
match their hash.

`TreeSet.union` reaches this when it merges an incoming collision node against
an item already occupying that bucket. The result is a set that still reports
the right `count` and still yields every element when iterated, but whose
misplaced members cannot be found by `contains`, since lookup navigates by
hash:

    let a1 = RawCollider(1, "A")
    let a2 = RawCollider(2, "B")
    let c1 = RawCollider(5, "ACAD")
    let c2 = RawCollider(6, "ACAD")

    let u = TreeSet([a1, a2]).union(TreeSet([c1, c2]))
    u.count          // 4
    Array(u)         // [2#B, 1#A, 5#ACAD, 6#ACAD]
    u.contains(c1)   // false
    u.contains(a1)   // false

Building the same set directly with `TreeSet([a1, a2, c1, c2])` is unaffected;
only the structural merge paths are.

Insert at `level.descend()` instead.

Enumerating every pair of subsets of the shared `testItems` fixture, 171 of
4096 unions contained at least one member that `contains` could not find.
With this change all 4096 are clean.

Also fix the full invariant check, which could not run on any tree containing
a collision node. Collision nodes store their item count in `itemMap` and
`childMap` rather than a set of occupied buckets, so treating those bitmaps as
buckets walks items that aren't there — a node holding 5 items has
`itemMap._value == 5`, whose bits nominate buckets 0 and 2. The bucket loop now
only runs for regular nodes. Before this, `swift test
-Xswiftc -DCOLLECTIONS_INTERNAL_CHECKS` trapped immediately in
HashTreeCollections; that trap was also what kept the invariant check from
reporting the misplaced nodes above.

Add a regression test alongside the existing `test_union_collision_node_ordering`.
2026-09-25 14:11:23 +05:30
Nikhil Gupta 84e65e8b5a [BitCollections] Fix BitSet.Counted.update(with:) not maintaining the cached count
BitSet.Counted caches its size in `_count` so that `count` is O(1).
Every mutating operation is responsible for keeping that cache in sync
with the underlying bit set.

`update(with:)` forwarded straight to `BitSet.update(with:)` without
adjusting `_count`. That method inserts the member when it isn't already
present (it is defined as `insert(newMember).inserted ? nil : newMember`),
so inserting a new member this way left the cached count one too low.

The stale count is observable in a few ways:

- `count` under-reports the number of members.
- `isEmpty` is `_count == 0`, so a set that still contains members can
  report itself as empty.
- The `Collection` conformance promises `count` elements but iteration
  yields more, which breaks the standard library. `Array(set)` traps with
  "Fatal error: invalid Collection: more than 'count' elements in
  collection".

In builds with COLLECTIONS_INTERNAL_CHECKS this also violates
`_checkInvariants()`, which asserts `_count == _bits.count`.

Mirror what `insert(_:)` already does and bump `_count` when a new member
was inserted. `update(with:)` returns nil exactly in that case.

`BitSet` has had a `test_update` for this all along; `BitSet.Counted` did
not, which is how this went unnoticed. Add the matching test, following
the same combinatorial style and using `Set<Int>` as the oracle.
2026-09-25 13:02:10 +05:30
Karoy Lorentey 1a1818df8f Drop unused Optional._borrow, ._mutate and _insert definitions 2026-09-23 15:45:26 -07:00
Joseph CursioandClaude Opus 5 c0c4b3bfad Report a mis-sized expectation instead of trapping or ignoring it
validateContainer checked the container's own count, underestimatedCount
and isEmpty for consistency, but never compared count against the number
of expected contents. Every loop that follows is bounded by the
container's count and indexes expectedContents at the same offset, so the
two failure modes were:

- A short expectation ran off the end. Where the expectation is a prefix
  of the contents it matches its way to the end and then traps with
  "Fatal error: Index out of range", killing the test process instead of
  reporting a validation failure.

- A long expectation was accepted. Offsets past the container's count are
  never looked at, so an expectation of twice the length passed.

The second is the worse of the two: a test can assert far less than it
appears to, and nothing says so.

One guard fixes both, placed after the container's own count consistency
checks so that a container with a broken count still reports that rather
than a size mismatch.

The regression test uses dropLast rather than dropFirst, and the comment
says why: dropFirst shifts every element, so a content mismatch at offset
0 is reported before the out-of-bounds access happens. That masks the
defect by coincidence rather than guarding against it, and a test written
that way would have passed against the unfixed code for the wrong reason.

Watched failing before the fix: the short case trapped with signal 5, the
long case reported "an expectation of 8 items must not validate against a
container of 4". Full suite with --traits UnstableContainersPreview: 893
tests, 0 failures, so none of the six existing checkContainer call sites
was relying on either behaviour.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-23 08:02:40 -05:00
Karoy Lorentey a66de878e8 Merge pull request #731 from lorentey/release-prep
Finalize the 1.7.0 release
1.7.0
2026-09-22 19:44:20 -07:00
Karoy Lorentey 3cd6ca91d5 Drop bad Iterable tests 2026-09-22 19:19:20 -07:00
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 021a54b8cc Update docs 2026-09-22 18:56:47 -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 4e0c3576d5 Merge pull request #730 from Joseph-Cursio/check-set-algebra-twins
Check the mutating form* twins against their non-mutating originals
2026-09-22 11:28:31 -07:00
Karoy Lorentey edcbded708 Fix workflow spec 2026-09-22 11:15:48 -07:00
Karoy Lorentey 12dab234df Fix container validation on some 6.4 nightlies
6.4 branches don’t like the `throws(Never)` declarations that have slipped into the container validator. Get rid of them.
2026-09-22 11:15:46 -07:00
Joseph CursioandClaude Opus 5 de23cb86c8 Check the mutating form* twins against their non-mutating originals
formUnion against union, formIntersection against intersection,
subtract against subtracting, and formSymmetricDifference against
symmetricDifference, in both the Self-taking and Sequence-taking
overloads.

Each runs under withHiddenCopies at both sharing states, because a
mutating operation on a shared value is where copy-on-write bugs
live, and the original is checked afterwards to confirm it was not
mutated through the copy.

This is the highest-value law in the checker. The two implementations
should agree by construction, so a divergence is a real bug rather
than a debatable one — and nothing else here would catch a form*
method that is simply wrong: a formUnion that intersects passes every
law in the preceding commit.

Verified by injecting three defects into a stand-in conformance: a
formUnion that intersects, an isStrictSubset that drops strictness,
and a subtracting that returns a stale count. All three are caught,
and an unmodified control passes. The stale-count case is caught only
because contents and count are asserted separately.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-21 21:14:59 -05:00
Karoy Lorentey 8104faa3af Fix errors uncovered by new workflow configuration 2026-09-21 14:10:43 -07:00
Karoy Lorentey 0685a69944 Update workflows
- Stop testing Swift 6.0 and 6.1
- Run full unstable package trait test on 6.3 and nightly-6.4.x
- Use preconfigured install-cmake action that verifies SHA256 hash of downloaded tarball
2026-09-21 14:10:21 -07:00
Karoy Lorentey 79f41229ef Merge pull request #728 from lorentey/container-updates
`Producer.generate(into:)`: Switch to saturating semantics
2026-09-21 13:35:19 -07:00
Karoy Lorentey 9eb1e96d79 Add rudimentary swift-format configuration 2026-09-21 13:34:42 -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 78bb4bf6b9 Update README 2026-09-21 13:33:58 -07:00
Karoy Lorentey 5d0faff6c7 Update container design document 2026-09-21 13:07:04 -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 c38a7173fc Merge pull request #720 from Joseph-Cursio/container-conformance-deques
Validate the Container conformance of RigidDeque and UniqueDeque
2026-09-21 12:54:59 -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