34 Commits
Author SHA1 Message Date
Tolga Unal c211bc56af [BasicContainers] Make the hashed containers Sendable
RigidSet, UniqueSet, RigidDictionary and UniqueDictionary had no
Sendable conformance, while the arrays and deques conform when their
elements are Sendable. Add the same conditional conformances: unchecked
for the rigid containers, which keep their elements behind unsafe
pointers, and checked for the unique ones.
2026-11-16 11:38:37 -05:00
Swastik TripathiandClaude Opus 5.5 b0d9a5ebbb [BasicContainers] Un-deprecate withKeys while keys is miscompiled
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 09:12:34 +05:30
Sandeep Vijayarao 9a699a1952 [BasicContainers] Don't resolve the hole before shrinking in UniqueDictionary
Resolves the FIXME added in #836: when removing an entry through
`updateValue(forKey:with:)` triggers shrinking, there is no need to
restore the hash table's invariants first, since resizing rehashes every
item anyway.

Factor the part of `RigidDictionary._punchHole(at:)` that doesn't touch
the value slot into `_punchHole(withMovedValueAt:)`, and use it on the
shrink path of `UniqueDictionary._removeEntry(withMovedValueAt:)`, which
now mirrors `_removeValue(at:)`.
2026-11-05 18:54:31 -08:00
Karoy Lorentey 3f5e6e427b Merge branch 'main' into fix-unique-dictionary-closure-removal 2026-11-05 18:32:45 -08:00
Karoy Lorentey dbc1c194de Add performance FIXME 2026-11-05 18:29:11 -08:00
Sandeep Vijayarao 1735b98380 [BasicContainers] Fix double destroy in UniqueDictionary.updateValue(forKey:with:)
When the updater closure removes an existing entry (sets the value to
nil), `UniqueDictionary.updateValue(forKey:with:)` called
`_removeValue(at:)`. But the value had already been moved out of its
slot before calling the updater, and `_removeValue(at:)` moves it out
again and discards the result, destroying uninitialized memory. This
leads to crashes or memory corruption.

`RigidDictionary.updateValue(forKey:with:)` already handles this case
correctly, by deinitializing just the key and resolving the hole.

Add `UniqueDictionary._removeEntry(withMovedValueAt:)`, which does the
same and then shrinks storage under the same condition as
`_removeValue(at:)`, and use it for the removal path.
2026-11-05 18:17:48 -08:00
Karoy Lorentey f17980c2c5 Stop using @_addressableForDependencies 2026-11-05 16:29:46 -08:00
Tolga Unal 9927f05e42 [BasicContainers] Make UniqueDictionary Equatable and Hashable with noncopyable contents
73ec3d341 made the other containers conform to Equatable/Hashable with
noncopyable contents, but UniqueDictionary was missed. The Hashable
extensions of RigidDictionary were also missing `Key: ~Copyable`.
2026-11-04 19:29:14 -05:00
Karoy Lorentey d07dc32dfa Sources: Add unsafe keywords where needed 2026-10-01 11:14:29 -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
Alejandro Alonso b2a1f89cc6 Add mutableValue(forKey:) to new dictionary types 2026-08-10 17:48:13 -07:00
Karoy Lorentey 70dc238938 [BasicContainers] RigidDictionary, UniqueDictionary: Add keys property
This replaces `withKeys`, which is now deprecated.
2026-07-07 16:52:33 -07:00
Karoy Lorentey 85cdb77d25 Fix build issues 2026-06-17 16:17:36 -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 685ef74751 Fix {Rigid,Unique}{Set,Dictionary} 2026-03-27 11:47:03 -07:00
Karoy Lorentey fda65e149b [BasicContainers] Hashed containers: Make _checkInvariants() dump the hash table on failure 2026-03-11 00:31:37 -07:00
Karoy Lorentey 634a0ae766 [BasicContainers] Implement _checkInvariants on hashed containers 2026-03-10 23:04:49 -07:00
Karoy Lorentey de436301e5 [BasicContainers] Allow standalone use of the UnstableHashedContainers trait
Oops, I lost a change that allowed enabling the UnstableHashedContainers trait without also opting into UnstableContainersPreview. Reimplement this functionality.
2026-03-09 15:59:38 -07:00
Karoy Lorentey 5605e14682 [BasicContainers] Avoid defining set/dictionary types unless UnstableHashedContainers is enabled 2026-03-06 11:17:39 -08:00
Karoy Lorentey 1c69635852 Add SPDX-License-Identifier tags 2026-03-05 19:39:24 -08:00
Karoy Lorentey 4160bcb98d [BasicContainers] RigidDictionary, UniqueDictionary: Add debugging methods 2026-03-05 15:33:25 -08:00
Karoy Lorentey ffdc48e67e [BasicContainers] Finalize requirements for hashed containers
- UnstableNoncopyableKeys → UnstableHashedContainers
- Delete the GeneralizedEquatable and GeneralizedHashable protocols, replacing them with the standard generalizations in the 6.4 stdlib
- Require Swift 6.4 for {Rigid,Unique}{Set,Dictionary}.
2026-03-03 16:01:45 -08:00
Karoy Lorentey 318ac805ea [BasicContainers] Add Index to hashed containers. Implement dictionary iteration using indices 2026-02-27 12:19:54 -08:00
Karoy Lorentey 087197dc1a [BasicContainers] Add removeAll() to hashed containers 2026-02-26 16:27:56 -08:00
Karoy Lorentey 0538000ffd [BasicContainers] Hashed containers: Add Equatable/Hashable conformances and related methods 2026-02-24 16:40:45 -08:00
Karoy Lorentey 0528dc2600 [BasicContainers] Adjust compilation conditions 2026-02-23 14:05:16 -08:00
Karoy Lorentey 2654a0711e [BasicContainers] Add removal operations to dictionaries 2026-02-23 13:59:36 -08:00
Karoy Lorentey 8624f936ea [BasicContainers] Add a containsKey method to dictionaries 2026-02-23 13:58:56 -08:00
Karoy Lorentey 992bff5b87 [BasicContainers] Implement UniqueDictionary insertions 2026-02-23 13:58:31 -08:00
Karoy Lorentey a14f9eb61c [BasicContainers] Add missing imports of ContainersPreview 2026-02-23 13:56:38 -08:00
Karoy Lorentey f7625351ae [BasicContainers] RigidDictionary, UniqueDictionary: Add API exposing the set of keys 2026-02-23 11:56:48 -08:00
Karoy Lorentey ec1c374ff0 [BasicContainers] Oops, mark dictionary insertions @discardableResult 2026-02-23 11:38:09 -08:00
Karoy Lorentey d318a65867 [BasicContainers] Add UniqueDictionary 2026-02-19 17:57:34 -08:00