The Swift Collections 1.4.0 package tag is now available.
This feature release supports Swift toolchain versions 6.0, 6.1 and 6.2. It includes a variety of bug fixes, and ships the following new features:
New ownership-aware ring buffer and hashed container implementations
In the DequeModule module, we have two new source-stable types that provide ownership-aware ring buffer implementations:
struct UniqueDeque<Element>is a uniquely held, dynamically resizing, noncopyable deque.struct RigidDeque<Element>is a fixed-capacity deque implementation.
RigidDeque/UniqueDeque are to Deque like RigidArray/UniqueArray are to Array -- they provide noncopyable embodiments of the same basic data structure, with many of the same operations.
In the BasicContainers module, this release adds previews of four new types, implementing ownership-aware hashed containers:
struct UniqueSet<Element>is a uniquely held, dynamically resizing set.struct RigidSet<Element>is a fixed-capacity set.struct UniqueDictionary<Key, Value>is a uniquely held, dynamically resizing dictionary.struct RigidDictionary<Key, Value>is a fixed-capacity dictionary.
These are direct analogues of the standard Set and Dictionary types. These types are built on top of the Equatable and Hashable protocol generalizations that were proposed in SE-0499; as that proposal is not yet implemented in any shipping toolchain, these new types are shipping as source-unstable previews, conditional on a new UnstableHashedContainers package trait. The final API of these types will also deeply depend on the struct Borrow and struct Inout proposals (and potentially other language/stdlib improvements) that are currently working their way through the Swift Evolution process. Accordingly, we may need to make source-breaking changes to the interfaces of these types -- they are not ready to be blessed as Public API. However, we encourage intrepid engineers to try them on for size, and report pain points. (Of which we expect there will be many in this first preview.)
We continue the pattern of Rigid- and Unique- naming prefixes with these new types:
- The
Uniquetypes (UniqueArray,UniqueDeque,UniqueSet,UniqueDictionaryetc.) are dynamically self-sizing containers that automatically reallocate their storage as needed to best accommodate their contents; theUniqueprefix was chosen to highlight that these types are always uniquely held, avoiding the complications of mutating shared copies. - The
Rigidtypes remove dynamic sizing, and they operate strictly within an explicitly configured capacity. Dynamic sizing is not always appropriate -- when targeting space- or time-constrained environments (think embedded use cases or real-time work), it is preferable to avoid implicit reallocations, and to instead choose to have explicit control over when (and if) storage is reallocated, and to what size. This is where theRigidtypes come in: their instances are created with a specific capacity and it is a runtime error to exceed that. This makes them quite inflexible (hence the "rigid" qualifier), but in exchange, their operations provide far stricter complexity guarantees: they exhibit no random runtime latency spikes, and they can trivially fit in strict memory budgets.
Early drafts of borrowing sequence, generative iteration and container protocols
This release includes highly experimental but working implementations of new protocols supplying ownership-aware alternatives to the classic Sequence/Collection protocol hierarchy. These protocols and the generic operations built on top of them can be turned on by enabling the UnstableContainersPreview package trait.
protocol BorrowingSequence<Element>models borrowing sequences with ephemeral lifetimes. (This is already progressing through Swift Evolution.)protocol Container<Element>models constructs that physically store their contents, and can expose stable spans over them.protocol Producer<Element, ProducerError>models a generative iterator -- a construct that generates items demand.protocol Drain<Element>refinesProducerto model an in-place consumable elements -- primarily for use around container types.
In this version, the package has developed these protocols just enough to implement basic generic operations for moving data between containers like UniqueArray and RigidDeque. As we gain experience using these, future releases may start adding basic generic algorithms, more protocols (bidirectional, random-access, (per)mutable, range-replaceable containers etc.) convenience adapters, and other features -- or we may end up entirely overhauling or simply discarding some/all of them. Accordingly, the experimental interfaces enabled by UnstableContainersPreview are not source stable, and they are not intended for production use. We expect the eventual production version of these (or whatever designs they evolve into) to ship in the Swift Standard Library. We do highly recommend interested folks to try playing with these, to get a feel for the strange problems of Ownership.
Besides these protocols, the package also defines rudimentary substitutes of some basic primitives that belong in the Standard Library:
struct InputSpan<Element>the dual ofOutputSpan-- whileOutputSpanis primarily for moving items into somebody else's storage,InputSpanenables safely moving items out of storage.struct Borrow<Target>represents a borrowing reference to an item. (This package models this with a pointer, which is an ill-fitting substitute for the real implementation in the stdlib.)struct Inout<Target>represents a mutating reference to an item.
A formal way to access SortedSet and SortedDictionary types
The SortedCollections module contains (preexisting) early drafts of two sorted collection types SortedSet and SortedDictionary, built on top of an in-memory B-tree implementation. This release defines an UnstableSortedCollections package trait that can be used to enable building these types for experimentation without manually modifying the package. Like in previous releases, these implementations remain unfinished in this release, with known API issues; accordingly, these types remain unstable. (Issue #1 remains open.) Future package releases may change their interface in ways that break source compatibility, or they may remove these types altogether.
Minor interface-level changes
-
The
Collectionsmodule no longer uses the unstable@_exported importfeature. Instead, it publishes public typealiases of every type that it previously reexported fromDequeModule,OrderedCollections,BitCollections,HeapModuleandHashTreeCollections. -
We renamed some
RigidArray/UniqueArrayoperations to improve their clarity at the point of use. The old names are still available, but deprecated.Old name New name append(count:initializingWith:)append(addingCount:initializingWith:)insert(count:at:initializingWith:)insert(addingCount:at:initializingWith:)replaceSubrange(_:newCount:initializingWith:)replace(removing:addingCount:initializingWith:)replaceSubrange(_:moving:)replace(removing:moving:)replaceSubrange(_:copying:)replace(removing:copying:)copy()clone()copy(capacity:)clone(capacity:) -
We have now defined a complete set of
OutputSpan/InputSpan-basedappend/insert/replace/consumeprimitives, fully generalized to be implementable by piecewise contiguous containers. These operations pave the way for aContainer-based analogue of the classicRangeReplaceableCollectionprotocol, with most of the user-facing operations becoming standard generic algorithms built on top of these primitives:mutating func append<E: Error>( addingCount newItemCount: Int, initializingWith initializer: (inout OutputSpan<Element>) throws(E) -> Void ) mutating func insert<E: Error>( addingCount newItemCount: Int, at index: Int, initializingWith initializer: (inout OutputSpan<Element>) throws(E) -> Void ) throws(E) mutating func replace<E: Error>( removing subrange: Range<Int>, consumingWith consumer: (inout InputSpan<Element>) -> Void, addingCount newItemCount: Int, initializingWith initializer: (inout OutputSpan<Element>) throws(E) -> Void ) throws(E) mutating func consume( _ subrange: Range<Int>, consumingWith consumer: (inout InputSpan<Element>) -> Void ) -
The package no longer uses the code generation tool
gyb.
What's Changed
- Fix links in GitHub templates by @lorentey in Fix links in GitHub templates by lorentey ยท Pull Request #527 ยท apple/swift-collections ยท GitHub
- Adopt
packageaccess modifier and get rid of gybbing by @lorentey in Adopt `package` access modifier and get rid of gybbing by lorentey ยท Pull Request #526 ยท apple/swift-collections ยท GitHub - [Doc] Fix links in landing page by @Azoy in [Doc] Fix links in landing page by Azoy ยท Pull Request #531 ยท apple/swift-collections ยท GitHub
- [BigString] Refactor _Chunk to be its own managed buffer of UTF8 by @Azoy in [BigString] Refactor _Chunk to be its own managed buffer of UTF8 by Azoy ยท Pull Request #488 ยท apple/swift-collections ยท GitHub
- Add new package trait UnstableSortedCollections by @lorentey in Add new package trait UnstableSortedCollections by lorentey ยท Pull Request #533 ยท apple/swift-collections ยท GitHub
- [RopeModule] Fix warnings by @lorentey in [RopeModule] Fix warnings by lorentey ยท Pull Request #534 ยท apple/swift-collections ยท GitHub
- Fix ability to build & test BigString with Xcode & CMake by @lorentey in Fix ability to build & test BigString with Xcode & CMake by lorentey ยท Pull Request #537 ยท apple/swift-collections ยท GitHub
- [BigString] Bring back Index._isUTF16TrailingSurrogate by @Azoy in [BigString] Bring back Index._isUTF16TrailingSurrogate by Azoy ยท Pull Request #539 ยท apple/swift-collections ยท GitHub
- chore: restrict GitHub workflow permissions - future-proof by @incertum in chore: restrict GitHub workflow permissions - future-proof by incertum ยท Pull Request #540 ยท apple/swift-collections ยท GitHub
- [BitCollections] Add missing imports for InternalCollectionsUtilities by @lorentey in [BitCollections] Add missing imports for InternalCollectionsUtilities by lorentey ยท Pull Request #554 ยท apple/swift-collections ยท GitHub
- Compare self.value to other, not itself by @SiliconA-Z in Compare self.value to other, not itself by SiliconA-Z ยท Pull Request #553 ยท apple/swift-collections ยท GitHub
- Change useFloyd heuristic to match comment by @SiliconA-Z in Change useFloyd heuristic to match comment by SiliconA-Z ยท Pull Request #551 ยท apple/swift-collections ยท GitHub
- Typo: symmetric difference should be the xor, not intersection by @SiliconA-Z in Typo: symmetric difference should be the xor, not intersection by SiliconA-Z ยท Pull Request #550 ยท apple/swift-collections ยท GitHub
- first should get the Initialized elements by @SiliconA-Z in first should get the Initialized elements by SiliconA-Z ยท Pull Request #549 ยท apple/swift-collections ยท GitHub
- Replace Container with a far less powerful (but more universal) Iterable construct by @lorentey in Replace Container with a far less powerful (but more universal) Iterable construct by lorentey ยท Pull Request #543 ยท apple/swift-collections ยท GitHub
- Temporarily stop testing RigidArray & UniqueArray on release/6.3 snapshots on Linux by @lorentey in Temporarily stop testing RigidArray & UniqueArray on release/6.3 snapshots on Linux by lorentey ยท Pull Request #562 ยท apple/swift-collections ยท GitHub
- [RigidArray, HashTrees] Mark deinitializers inlinable by @lorentey in [RigidArray, HashTrees] Mark deinitializers inlinable by lorentey ยท Pull Request #560 ยท apple/swift-collections ยท GitHub
- GHA: Add weekly dependabot by @bkhouri in GHA: Add weekly dependabot by bkhouri ยท Pull Request #563 ยท apple/swift-collections ยท GitHub
- Work around temporary issue with current 6.3 snapshots by @lorentey in Work around temporary issue with current 6.3 snapshots by lorentey ยท Pull Request #565 ยท apple/swift-collections ยท GitHub
- Add
RigidDequeandUniqueDequeby @lorentey in Add `RigidDeque` and `UniqueDeque` by lorentey ยท Pull Request #557 ยท apple/swift-collections ยท GitHub - [Collections module] Stop using
@_exported importby @lorentey in [Collections module] Stop using `@_exported import` by lorentey ยท Pull Request #566 ยท apple/swift-collections ยท GitHub - Delete stray benchmark results files by @lorentey in Delete stray benchmark results files by lorentey ยท Pull Request #567 ยท apple/swift-collections ยท GitHub
- Assorted
RigidArray/UniqueArrayupdates by @lorentey in Assorted `RigidArray`/`UniqueArray` updates by lorentey ยท Pull Request #569 ยท apple/swift-collections ยท GitHub RigidArray/UniqueArray: Add new copying span initializers by @Azoy in `RigidArray`/`UniqueArray`: Add new copying span initializers by Azoy ยท Pull Request #572 ยท apple/swift-collections ยท GitHubRigidDeque/UniqueDeque: Add some top-level documentation by @lorentey in `RigidDeque`/`UniqueDeque`: Add some top-level documentation by lorentey ยท Pull Request #571 ยท apple/swift-collections ยท GitHub- Update docs for Container.nextSpan(after:maximumCount:) by @lorentey in Update docs for Container.nextSpan(after:maximumCount:) by lorentey ยท Pull Request #574 ยท apple/swift-collections ยท GitHub
- Remove workaround for bug in OutputSpan.wUMBP by @lorentey in Remove workaround for bug in OutputSpan.wUMBP by lorentey ยท Pull Request #570 ยท apple/swift-collections ยท GitHub
- [RigidArray, RigidDeque].nextSpan: Validate
maximumCountby @lorentey in [RigidArray, RigidDeque].nextSpan: Validate `maximumCount` by lorentey ยท Pull Request #575 ยท apple/swift-collections ยท GitHub - Bump swiftlang/github-workflows/.github/workflows/soundness.yml from 0.0.6 to 0.0.7 by @dependabot[bot] in Bump swiftlang/github-workflows/.github/workflows/soundness.yml from 0.0.6 to 0.0.7 by dependabot[bot] ยท Pull Request #577 ยท apple/swift-collections ยท GitHub
- give constant folding an opportunity to select a much faster code path for empty dictionary (and set) literals by @tayloraswift in give constant folding an opportunity to select a much faster code path for empty dictionary (and set) literals by tayloraswift ยท Pull Request #578 ยท apple/swift-collections ยท GitHub
- Bump swiftlang/github-workflows/.github/workflows/swift_package_test.yml from 0.0.6 to 0.0.7 by @dependabot[bot] in Bump swiftlang/github-workflows/.github/workflows/swift_package_test.yml from 0.0.6 to 0.0.7 by dependabot[bot] ยท Pull Request #576 ยท apple/swift-collections ยท GitHub
- Ownership-aware Set and Dictionary variants by @lorentey in Ownership-aware Set and Dictionary variants by lorentey ยท Pull Request #573 ยท apple/swift-collections ยท GitHub
- [Prerelease] Check API for consistency, fill holes, patch incoherencies by @lorentey in [Prerelease] Check API for consistency, fill holes, patch incoherencies by lorentey ยท Pull Request #581 ยท apple/swift-collections ยท GitHub
- [BitSet] Amend return value of
update(with:)method by @benrimmington in [BitSet] Amend return value of `update(with:)` method by benrimmington ยท Pull Request #538 ยท apple/swift-collections ยท GitHub - [BasicContainers] Fix spelling of a source file by @lorentey in [BasicContainers] Fix spelling of a source file by lorentey ยท Pull Request #585 ยท apple/swift-collections ยท GitHub
- Include notes about index mutation in
span(after/before:)(+ other doc fixes) by @natecook1000 in Include notes about index mutation in `span(after/before:)` (+ other doc fixes) by natecook1000 ยท Pull Request #541 ยท apple/swift-collections ยท GitHub - [BasicContainers] Finalize requirements for hashed containers by @lorentey in [BasicContainers] Finalize requirements for hashed containers by lorentey ยท Pull Request #586 ยท apple/swift-collections ยท GitHub
- Update README for 1.4.0 by @lorentey in Update README for 1.4.0 by lorentey ยท Pull Request #587 ยท apple/swift-collections ยท GitHub
- Working towards the 1.4.0 tag by @lorentey in Working towards the 1.4.0 tag by lorentey ยท Pull Request #588 ยท apple/swift-collections ยท GitHub
- [BasicContainers] Avoid defining set/dictionary types unless UnstableHashedContainers is enabled by @lorentey in [BasicContainers] Avoid defining set/dictionary types unless UnstableHashedContainers is enabled by lorentey ยท Pull Request #589 ยท apple/swift-collections ยท GitHub
- [BasicContainers] RigidArray: Correct spelling of replacement for deprecated method by @lorentey in [BasicContainers] RigidArray: Correct spelling of replacement for deprecated method by lorentey ยท Pull Request #590 ยท apple/swift-collections ยท GitHub
New Contributors
- @incertum made their first contribution in chore: restrict GitHub workflow permissions - future-proof by incertum ยท Pull Request #540 ยท apple/swift-collections ยท GitHub
- @SiliconA-Z made their first contribution in Compare self.value to other, not itself by SiliconA-Z ยท Pull Request #553 ยท apple/swift-collections ยท GitHub
- @bkhouri made their first contribution in GHA: Add weekly dependabot by bkhouri ยท Pull Request #563 ยท apple/swift-collections ยท GitHub
- @dependabot[bot] made their first contribution in Bump swiftlang/github-workflows/.github/workflows/soundness.yml from 0.0.6 to 0.0.7 by dependabot[bot] ยท Pull Request #577 ยท apple/swift-collections ยท GitHub
- @tayloraswift made their first contribution in give constant folding an opportunity to select a much faster code path for empty dictionary (and set) literals by tayloraswift ยท Pull Request #578 ยท apple/swift-collections ยท GitHub
- @benrimmington made their first contribution in [BitSet] Amend return value of `update(with:)` method by benrimmington ยท Pull Request #538 ยท apple/swift-collections ยท GitHub
Full Changelog: Comparing 1.3.0...1.4.0 ยท apple/swift-collections ยท GitHub