Commit Graph
158 Commits
Author SHA1 Message Date
David Nadoba 3a07388528 Add TemporaryArray: a stack-seeded, heap-spilling scratch array
TemporaryArray is a ~Copyable and ~Escapable dynamic array whose initial
storage is a borrowed buffer (most usefully a stack allocation vended by
withTemporaryArray(of:capacity:_:)) and which transparently spills over
into freshly allocated heap storage once it outgrows that seed buffer. As
long as the element count stays within a seed buffer that fit on the stack,
the array incurs no heap traffic at all.

Because it can hold a dependency on borrowed (stack) memory, the type is
non-escapable: instances cannot outlive the scope that provides their
initial buffer. Contents are lifted out into an owning container with
take(), which transfers the heap buffer in O(1) if the array has already
spilled, or moves the elements into a fresh UniqueArray otherwise.

The API mirrors UniqueArray (SE-0527), minus the pieces that don't apply
to a non-escapable scratch type (DynamicContainer, MutableContainer, and
RangeReplaceableContainer conformances plus the Drain-based consumer),
plus members unique to its borrow-then-spill design: take(), clone(), and
append(repeating:count:). The seed-buffer initializer is kept internal for
now, with withTemporaryArray as the sole entry point. Equatable/Hashable
and CustomStringConvertible/CustomDebugStringConvertible are implemented
as methods with FIXMEs to add the conformances once those protocols
support ~Copyable/~Escapable types.

The Collection/RangeReplaceable surface and container-protocol conformances
are gated behind the UnstableContainersPreview trait, mirroring UniqueArray;
the core API builds in the default configuration. DocC coverage is added for
the type and the withTemporaryArray entry point.
2026-07-09 15:16:13 -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
Karoy Lorentey 85cdb77d25 Fix build issues 2026-06-17 16:17:36 -07:00
Nate Cook c039a18a0e Switch to using stdlib Ref and UniqueBox 2026-06-17 14:27:29 -07:00
Nate Cook dca015d7e8 Align Iterable with proposal
Adds throwing and ~Escapable elements
2026-06-17 14:27:29 -07:00
Nate Cook 4bda43f4a9 Renaming BorrowingSequence_ to Iterable_ 2026-06-17 14:27:29 -07:00
Karoy Lorentey 28e9d98a7e Fix deprecation warnings 2026-06-17 13:48:54 -07:00
Alejandro Alonso 06423d7329 Fix broken docs 2026-06-17 13:48:54 -07:00
Alejandro AlonsoandKaroy Lorentey 2a39308613 Update Sources/BasicContainers/UniqueArray/UniqueArray.swift
Co-authored-by: Karoy Lorentey <klorentey@apple.com>
2026-06-17 13:48:54 -07:00
Alejandro AlonsoandKaroy Lorentey eb5c24f71a Update Sources/BasicContainers/RigidArray/RigidArray.swift
Co-authored-by: Karoy Lorentey <klorentey@apple.com>
2026-06-17 13:48:54 -07:00
Alejandro AlonsoandKaroy Lorentey c6a1dabfd0 Update Sources/BasicContainers/RigidArray/RigidArray+Deprecated.swift
Co-authored-by: Karoy Lorentey <klorentey@apple.com>
2026-06-17 13:48:53 -07:00
Alejandro Alonso 6da58357a3 Rename reallocate to setCapacity for Rigid and UniqueArray
Update UniqueArray.swift

Update UniqueArray.swift
2026-06-17 13:48:53 -07:00
Karoy Lorentey a731a7fdad [BasicContainers] Don’t define LLDB formatter symbol on Wasm
While we’re here, follow our explicit access control rule when defining the variable.
2026-05-12 15:33:22 -07:00
Karoy Lorentey c38e47d03e [BasicContainers, DequeModule] Avoid using deprecated API 2026-05-07 16:17:20 -07:00
Karoy Lorentey 72ee2bf645 [BasicContainers] Update CMakeLists.txt 2026-05-07 16:16:57 -07:00
Karoy Lorentey 16d6b8e1fe [ContainersPreview] Inout ⟹ MutableRef 2026-05-06 18:28:07 -07:00
Karoy Lorentey a6fd64697a [ContainersPreview] Borrow ⟹ Ref
Also update the type’s public API surface to reflect SE-0519, leaving deprecated aliases for the old names.
2026-05-06 18:00:13 -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 bb7839ae50 Merge pull request #642 from lorentey/doc-fix
[BasicContainers] Fix copypasta in `UniqueArray.edit`’s docs
2026-05-05 17:31:51 -07:00
Karoy Lorentey 50f93dd05f [BasicContainers] Fix copypasta in UniqueArray.edit’s docs 2026-05-05 16:18:11 -07:00
Karoy Lorentey 022795168a [BasicContainers] Enable APIs scheduled to ship in 1.5.0
- `RigidArray.nextMutableSpan(after:maximumCount:)`
- `UniqueArray.nextMutableSpan(after:maximumCount:)`
- `RigidDeque.nextMutableSpan(after:maximumCount:)`
- `UniqueDeque.nextMutableSpan(after:maximumCount:)`
- `UniqueArray.init(minimumCapacity:)` (replacing `.init(capacity:)`)
- `UniqueDeque.init(minimumCapacity:)` (replacing `.init(capacity:)`)
- `RigidDeque.index(before:)`
- `UniqueDeque.index(before:)`
- `RigidDeque.formIndex(before:)`
- `UniqueDeque.formIndex(before:)`
2026-05-05 16:01:31 -07:00
Karoy Lorentey 9364ee33b1 Merge pull request #607 from kastiglione/Debugging-Add-lldb-data-formatter-for-RigidArray
[Debugging] Add lldb data formatter for RigidArray
2026-04-30 17:35:23 -07:00
Karoy Lorentey 215a9ac0a7 Merge pull request #632 from lorentey/assorted-fixes
[BasicContainers, DequeModule]: Assorted fixes
2026-04-30 15:53:21 -07:00
Manoj Mahapatra 6cce7de52e fix: reserveCapacity DocC link in RigidArray 2026-04-29 12:41:08 -07:00
Karoy Lorentey 4b8dc6d951 BasicContainers] RigidDictionary.udateValue(forKey:with:): Fix undefined behavior on removals 2026-04-27 16:42:51 -07:00
Franz Busch 793bcd5d66 Update the count 2026-04-25 17:43:25 +02:00
Karoy Lorentey 5bd8ab095d [BasicContainers] UniqueArray.replace(removing:copying): Fix overallocation issue
`UniqueArray.replace(removing:copying:)` overloads overestimated the amount of memory they need, sometimes leading to unnecessary reallocations. Fix this.
2026-04-22 16:23:15 -07:00
Karoy Lorentey 6ed215dcc2 Merge pull request #629 from lorentey/fix-fancy-rigidarray-replacement
[BasicContainers] RigidArray.replace(removing:consumingWith:addingCount:initializingWith:): Fix correctness issue with partial initialization
2026-04-22 16:10:13 -07:00
Karoy Lorentey d8ace00d14 [BasicContainers] RigidArray.replace(removing:consumingWith:addingCount:initializingWith:): Fix correctness issue with partial initialization
The original code was invoking `_closeGap` with an incorrect size (from `append` rather than `replace`), leading to runtime traps and potential memory safety issues if the `resize` invocation ends up underfilling the container.
2026-04-22 15:32:55 -07:00
Karoy Lorentey b75bd4ef01 [BasicContainers] RigidSet.insert(maximumCount:from:): Fix spurious capacity overflow caused by incorrect accounting 2026-04-22 15:12:55 -07:00
Karoy Lorentey bf8441dc95 [BasicContainers] Fix typos in doc comments 2026-04-08 18:31:11 -07:00
Karoy Lorentey a9b64d4f09 [BasicContainers] RigidArray,UniqueArray: Add Equatable conformance on Swift 6.4
This is currently conditional on the UnstableContainersPreview trait. (Swift 6.4 has not shipped yet, so we cannot unconditionally enable this without risking breakage.)
2026-04-08 18:31:11 -07:00
Karoy Lorentey 917eead3cb [BasicContainers] RigidArray,UniqueArray: Add FIXME for Custom[Debug]StringConvertible conformances 2026-04-08 18:31:11 -07:00
Karoy Lorentey 7f4cebd2c5 BasicContainers] Add UniqueArray.isTriviallyIdentical(to:) 2026-04-08 18:31:10 -07:00
Karoy Lorentey b4bfd6d02e [BasicContainers] RigidArray.isTriviallyIdentical(to:): Don’t require Equatable elements, but do allow noncopyable ones 2026-04-08 18:31:07 -07:00
Karoy Lorentey 35b7d8fba4 Fix lifetime requirements rigidly enforced in the latest nightlies 2026-04-03 17:01:36 -07:00
Dave Lee a2c67046c1 Support single-module mode
When `COLLECTIONS_SINGLE_MODULE` is set, a single `Collections` module is
built. Type names need to match accordingly.
2026-03-31 12:53:53 -07:00
Dave Lee f93d09ec67 Fix copyright dates 2026-03-31 12:53:52 -07:00
Dave Lee 86d184d89c Add generate_formatters.sh script 2026-03-31 09:56:00 -07:00
Dave Lee 7d721cbf7c Add license header 2026-03-31 09:55:49 -07:00
Dave Lee a6cefb8eda Update RigidArray+Formatter.swift 2026-03-30 11:02:31 -07:00
Karoy Lorentey e0ec6b0976 UniqueSet: Fix copypasta 2026-03-27 11:59:41 -07:00
Karoy Lorentey 685ef74751 Fix {Rigid,Unique}{Set,Dictionary} 2026-03-27 11:47:03 -07:00
Karoy Lorentey f83e9b6538 Rename Collection.underestimatedCount_ 2026-03-27 11:47:00 -07:00
Karoy Lorentey 597b7a7dd2 Revert most of the availability constraints from 419e2f and 4c0482 🎉 2026-03-27 11:25:43 -07:00
Nate Cook 61fb6f5d13 Fix errant CMakeList renamings 2026-03-27 11:02:44 -05:00
Nate Cook a99a015934 Disambiguate ContainersPreview and stdlib
Adds trailing underscores to the BorrowingSequence protocols and
requirements, in order to allow both parallel conformances and
the ability to evolve the requirements in this package.
2026-03-27 07:41:32 -05:00
Karoy Lorentey 4c04822689 [ContainersPreview] Exhibit B in the case against prototyping things in the stdlib 😳 2026-03-26 18:13:22 -07:00
Karoy Lorentey d2d3b917ca [BasicContainers, ContainersPreview, DequeModule] More SuppressedAssociatedTypesWithDefaults fixups 2026-03-26 18:12:41 -07:00