Merge pull request #586 from lorentey/unstable-hashed-containers

[BasicContainers] Finalize requirements for hashed containers
This commit is contained in:
Karoy Lorentey authored and GitHub committed 2026-03-04 09:41:15 -08:00
commit ae4e6f850e
58 files changed
+137 -207

No files matched your search

+4 -4
View File
@@ -35,7 +35,7 @@ let _traits: Set<Trait> = [
types before they ship.
"""),
.trait(
name: "UnstableNoncopyableKeys",
name: "UnstableHashedContainers",
description: """
Enables support for noncopyable set members and dictionary keys in
`BasicContainers`. This requires a Standard Library with generalized
@@ -57,8 +57,8 @@ var defines: [SwiftSetting] = [
"COLLECTIONS_UNSTABLE_SORTED_COLLECTIONS",
.when(traits: ["UnstableSortedCollections"])),
.define(
"COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS",
.when(traits: ["UnstableNoncopyableKeys"])),
"COLLECTIONS_UNSTABLE_HASHED_CONTAINERS",
.when(traits: ["UnstableHashedContainers"])),
// Enables internal consistency checks at the end of initializers and
// mutating operations. This can have very significant overhead, so enabling
@@ -113,8 +113,8 @@ let availabilityMacros: KeyValuePairs<String, String> = [
]
let extraSettings: [SwiftSetting] = [
// .strictMemorySafety(),
.enableUpcomingFeature("MemberImportVisibility"),
// .strictMemorySafety(),
.enableExperimentalFeature("BuiltinModule"),
.enableExperimentalFeature("Lifetimes"),
.enableExperimentalFeature("InoutLifetimeDependence"),
-1
View File
@@ -49,7 +49,6 @@ target_sources(${module_name} PRIVATE
"UniqueArray/UniqueArray+Insertions.swift"
"UniqueArray/UniqueArray+Removals.swift"
"UniqueArray/UniqueArray+Replacements.swift"
"HashTable/ProtocolGeneralizations.swift"
"HashTable/_HTable.swift"
"HashTable/_HTable+Bitmap.swift"
"HashTable/_HTable+Bucket.swift"
@@ -1,117 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2026 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
/// This is a stand-in for the generalization of Equatable as described in SE-0499.
/// This is a temporary protocol that will be deprecated and later removed
/// when the official generalization becomes widely available.
public protocol GeneralizedEquatable: ~Copyable, ~Escapable {
/// Returns a Boolean value indicating whether two values are equal.
///
/// Equality is the inverse of inequality. For any values `a` and `b`,
/// `a == b` implies that `a != b` is `false`.
///
/// - Parameters:
/// - lhs: A value to compare.
/// - rhs: Another value to compare.
static func == (lhs: borrowing Self, rhs: borrowing Self) -> Bool
}
/// This is a stand-in for the generalization of Hashable as described in SE-0499.
/// This is a temporary protocol that will be deprecated and later removed
/// when the official generalization becomes widely available.
public protocol GeneralizedHashable: GeneralizedEquatable, ~Copyable, ~Escapable {
/// Hashes the essential components of this value by feeding them into the
/// given hasher.
///
/// Implement this method to conform to the `Hashable` protocol. The
/// components used for hashing must be the same as the components compared
/// in your type's `==` operator implementation. Call `hasher.combine(_:)`
/// with each of these components.
///
/// - Important: In your implementation of `hash(into:)`,
/// don't call `finalize()` on the `hasher` instance provided,
/// or replace it with a different instance.
/// Doing so may become a compile-time error in the future.
///
/// - Parameter hasher: The hasher to use when combining the components
/// of this instance.
func hash(into hasher: inout Hasher)
/// The temporary substitute to `Hashable._rawHashValue(seed:)`, the raw
/// top-level hashing interface. Some standard library types (mostly
/// primitives) specialize this to eliminate small resiliency overheads. (This
/// only matters for tiny keys.)
///
/// We avoid using the stdlib name as the stdlib's default implementation is
/// overwhelmingly preferable but it isn't (easily) reimplementable outside
/// of the stdlib.
///
/// This will be replaced by the actual `Hashable` method when its
/// generalization ships.
func _rawHashValue_temp(seed: Int) -> Int
}
extension GeneralizedHashable where Self: ~Copyable & ~Escapable {
@inlinable
public func _rawHashValue_temp(seed: Int) -> Int {
var hasher = Hasher()
hasher.combine(seed)
self.hash(into: &hasher)
return hasher.finalize()
}
}
extension GeneralizedHashable where Self: Hashable {
@inlinable
public func _rawHashValue_temp(seed: Int) -> Int {
_rawHashValue(seed: seed)
}
}
extension GeneralizedHashable where Self: ~Copyable & ~Escapable {
/// The hash value.
///
/// Hash values are not guaranteed to be equal across different executions of
/// your program. Do not save hash values to use during a future execution.
@_alwaysEmitIntoClient
@inline(__always)
public var hashValue: Int {
_rawHashValue_temp(seed: 0)
}
}
extension Int: GeneralizedHashable {}
extension Int8: GeneralizedHashable {}
extension Int16: GeneralizedHashable {}
extension Int32: GeneralizedHashable {}
extension Int64: GeneralizedHashable {}
@available(SwiftStdlib 6.0, *)
extension Int128: GeneralizedHashable {}
extension UInt: GeneralizedHashable {}
extension UInt8: GeneralizedHashable {}
extension UInt16: GeneralizedHashable {}
extension UInt32: GeneralizedHashable {}
extension UInt64: GeneralizedHashable {}
@available(SwiftStdlib 6.0, *)
extension UInt128: GeneralizedHashable {}
extension Float: GeneralizedHashable {}
extension Double: GeneralizedHashable {}
@available(SwiftStdlib 5.7, *)
extension Duration: GeneralizedHashable {}
extension String: GeneralizedHashable {}
extension Substring: GeneralizedHashable {}
extension Character: GeneralizedHashable {}
extension Bool: GeneralizedHashable {}
extension UnsafePointer: GeneralizedHashable {}
extension UnsafeMutablePointer: GeneralizedHashable {}
#endif
@@ -13,7 +13,7 @@
import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension RigidDictionary where Key: ~Copyable, Value: ~Copyable {
@@ -15,7 +15,7 @@ import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension RigidDictionary {
@@ -55,7 +55,7 @@ extension RigidDictionary {
}
@available(SwiftStdlib 5.0, *)
extension RigidDictionary: GeneralizedEquatable where Value: GeneralizedEquatable { // Should be Equatable
extension RigidDictionary: Equatable where Value: Equatable {
@inlinable
public static func ==(left: borrowing Self, right: borrowing Self) -> Bool {
left.isEqual(to: right, by: ==)
@@ -14,10 +14,10 @@ import InternalCollectionsUtilities
import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension RigidDictionary: GeneralizedHashable where Value: GeneralizedHashable { // Should be Hashable
extension RigidDictionary: Hashable where Value: Hashable { // Should be Hashable
@inlinable
public func hash(into hasher: inout Hasher) {
var commutativeHash = 0
@@ -13,7 +13,7 @@
import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension RigidDictionary where Key: ~Copyable, Value: ~Copyable {
@@ -13,7 +13,7 @@
import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension RigidDictionary where Key: ~Copyable, Value: ~Copyable {
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension RigidDictionary where Key: ~Copyable, Value: ~Copyable {
@@ -13,7 +13,7 @@
import ContainersPreview
#endif
#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension RigidDictionary where Key: ~Copyable, Value: ~Copyable {
@@ -54,7 +54,7 @@ extension RigidDictionary where Key: ~Copyable, Value: ~Copyable {
let bucket = self._keys._table.insertNew_Large(
hashValue: hashValue,
hashGenerator: {
keys[$0]._rawHashValue_temp(seed: seed)
keys[$0]._rawHashValue(seed: seed)
},
swapper: { bucket in
swap(&key, &keys[bucket])
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension RigidDictionary where Key: ~Copyable, Value: ~Copyable {
@@ -13,7 +13,7 @@
import ContainersPreview
#endif
#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension RigidDictionary where Key: ~Copyable, Value: ~Copyable {
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension RigidDictionary where Key: ~Copyable, Value: ~Copyable {
@@ -32,7 +32,7 @@ extension RigidDictionary where Key: ~Copyable, Value: ~Copyable {
self._keys._table.resolveHole(
at: bucket,
hashGenerator: {
keys[$0.offset]._rawHashValue_temp(seed: seed)
keys[$0.offset]._rawHashValue(seed: seed)
},
mover: {
(keys + $1.offset).initialize(to: (keys + $0.offset).move())
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension RigidDictionary where Key: ~Copyable, Value: ~Copyable {
@@ -67,10 +67,10 @@ extension RigidDictionary where Key: ~Copyable, Value: ~Copyable {
selector: {
srcKey = sourceKeys + $0.offset
srcValue = sourceValues + $0.offset
return srcKey.pointee._rawHashValue_temp(seed: seed)
return srcKey.pointee._rawHashValue(seed: seed)
},
hashGenerator: {
targetKeys[$0.offset]._rawHashValue_temp(seed: seed)
targetKeys[$0.offset]._rawHashValue(seed: seed)
},
swapper: {
swap(&srcKey.pointee, &targetKeys[$0.offset])
@@ -14,12 +14,23 @@ import InternalCollectionsUtilities
import ContainersPreview
#endif
#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(<6.4) || !COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(*, unavailable, message: "RigidSet requires a Swift 6.4 toolchain")
@frozen
public struct RigidDictionary<
Key: Hashable,
Value: ~Copyable
>: ~Copyable {
package init() {
fatalError()
}
}
#else
@available(SwiftStdlib 5.0, *)
@frozen
@_addressableForDependencies
public struct RigidDictionary<
Key: GeneralizedHashable & ~Copyable,
Key: Hashable & ~Copyable,
Value: ~Copyable
>: ~Copyable {
@usableFromInline
@@ -13,7 +13,7 @@
import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
@available(SwiftStdlib 5.0, *)
extension RigidSet: BorrowingSequence where Element: ~Copyable {
@@ -13,7 +13,7 @@
import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension RigidSet where Element: ~Copyable {
@@ -13,7 +13,7 @@
import InternalCollectionsUtilities
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension RigidSet where Element: ~Copyable {
@@ -15,7 +15,7 @@ import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension RigidSet {
@@ -27,7 +27,7 @@ extension RigidSet {
}
@available(SwiftStdlib 5.0, *)
extension RigidSet: GeneralizedEquatable { // Should be Equatable
extension RigidSet: Equatable {
@inlinable
public static func ==(left: borrowing Self, right: borrowing Self) -> Bool {
if left.isTriviallyIdentical(to: right) { return true }
@@ -14,10 +14,10 @@ import InternalCollectionsUtilities
import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension RigidSet: GeneralizedHashable { // Should be Hashable
extension RigidSet: Hashable {
@inlinable
public func hash(into hasher: inout Hasher) {
// Generate a seed from a snapshot of the hasher. This makes members' hash
@@ -36,7 +36,7 @@ extension RigidSet: GeneralizedHashable { // Should be Hashable
let next = it.nextSpan()
var i = 0
while i < next.count {
hash ^= next[i]._rawHashValue_temp(seed: seed)
hash ^= next[i]._rawHashValue(seed: seed)
i &+= 1
}
}
@@ -13,7 +13,7 @@
import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension RigidSet where Element: ~Copyable {
@@ -13,7 +13,7 @@
import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension RigidSet where Element: ~Copyable {
@@ -13,7 +13,7 @@
import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension RigidSet where Element: ~Copyable {
@@ -69,7 +69,7 @@ extension RigidSet where Element: ~Copyable {
let bucket = _table.insertNew_Large(
hashValue: hashValue,
hashGenerator: {
storage[$0]._rawHashValue_temp(seed: seed)
storage[$0]._rawHashValue(seed: seed)
},
swapper: {
swap(&item, &storage[$0])
@@ -13,7 +13,7 @@
import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension RigidSet where Element: ~Copyable {
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension RigidSet where Element: ~Copyable {
@@ -49,7 +49,7 @@ extension RigidSet where Element: ~Copyable {
_table.resolveHole(
at: bucket,
hashGenerator: {
members[$0.offset]._rawHashValue_temp(seed: seed)
members[$0.offset]._rawHashValue(seed: seed)
},
mover: {
(members + $1.offset).initialize(to: (members + $0.offset).move())
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension RigidSet where Element: ~Copyable {
@@ -64,10 +64,10 @@ extension RigidSet where Element: ~Copyable {
from: &old._table,
selector: {
src = source + $0.offset
return src.pointee._rawHashValue_temp(seed: seed)
return src.pointee._rawHashValue(seed: seed)
},
hashGenerator: {
target[$0.offset]._rawHashValue_temp(seed: seed)
target[$0.offset]._rawHashValue(seed: seed)
},
swapper: {
swap(&src.pointee, &target[$0.offset])
@@ -15,12 +15,21 @@ import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(<6.4) || !COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
/// A fixed-capacity, noncopyable, unordered hashed container of unique
/// elements.
@available(*, unavailable, message: "RigidSet requires a Swift 6.4 toolchain")
public struct RigidSet<Element: Hashable>: ~Copyable {
package init() {
fatalError()
}
}
#else
/// A fixed-capacity, noncopyable, unordered hashed container of unique
/// elements.
@available(SwiftStdlib 5.0, *)
@frozen
public struct RigidSet<Element: GeneralizedHashable & ~Copyable>: ~Copyable {
public struct RigidSet<Element: Hashable & ~Copyable>: ~Copyable {
@usableFromInline
package typealias _Bucket = _HTable.Bucket
@@ -150,7 +159,7 @@ extension RigidSet where Element: ~Copyable {
internal borrowing func _hashValue(
for item: borrowing Element
) -> Int {
item._rawHashValue_temp(seed: _seed)
item._rawHashValue(seed: _seed)
}
}
@@ -13,7 +13,7 @@
import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension UniqueDictionary where Key: ~Copyable, Value: ~Copyable {
@@ -15,7 +15,7 @@ import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension UniqueDictionary {
@@ -39,7 +39,7 @@ extension UniqueDictionary {
}
@available(SwiftStdlib 5.0, *)
extension UniqueDictionary: GeneralizedEquatable where Value: GeneralizedEquatable { // Should be Equatable
extension UniqueDictionary: Equatable where Value: Equatable {
@inlinable
@inline(__always)
public static func ==(left: borrowing Self, right: borrowing Self) -> Bool {
@@ -14,10 +14,10 @@ import InternalCollectionsUtilities
import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension UniqueDictionary: GeneralizedHashable where Value: GeneralizedHashable { // Should be Hashable
extension UniqueDictionary: Hashable where Value: Hashable {
@inlinable
@inline(__always)
public func hash(into hasher: inout Hasher) {
@@ -13,7 +13,7 @@
import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension UniqueDictionary where Key: ~Copyable, Value: ~Copyable {
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension UniqueDictionary where Key: ~Copyable, Value: ~Copyable {
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension UniqueDictionary where Key: ~Copyable, Value: ~Copyable {
@@ -13,7 +13,7 @@
import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension UniqueDictionary where Key: ~Copyable, Value: ~Copyable {
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension UniqueDictionary where Key: ~Copyable, Value: ~Copyable {
@@ -13,7 +13,7 @@
import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension UniqueDictionary where Key: ~Copyable, Value: ~Copyable {
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension UniqueDictionary where Key: ~Copyable, Value: ~Copyable {
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension UniqueDictionary where Key: ~Copyable, Value: ~Copyable {
@@ -9,13 +9,22 @@
//
//===----------------------------------------------------------------------===//
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(<6.4) || !COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(*, unavailable, message: "RigidSet requires a Swift 6.4 toolchain")
public struct UniqueDictionary<
Key: Hashable,
Value: ~Copyable
>: ~Copyable {
package init() {
fatalError()
}
}
#else
@available(SwiftStdlib 5.0, *)
@frozen
@_addressableForDependencies
public struct UniqueDictionary<
Key: GeneralizedHashable & ~Copyable,
Key: Hashable & ~Copyable,
Value: ~Copyable
>: ~Copyable {
@usableFromInline
@@ -14,7 +14,7 @@ import InternalCollectionsUtilities
import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
@available(SwiftStdlib 5.0, *)
extension UniqueSet: BorrowingSequence where Element: ~Copyable {
@@ -13,7 +13,7 @@
import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
@available(SwiftStdlib 5.0, *)
extension UniqueSet where Element: ~Copyable {
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension UniqueSet where Element: ~Copyable {
@@ -15,7 +15,7 @@ import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension UniqueSet {
@@ -27,7 +27,7 @@ extension UniqueSet {
}
@available(SwiftStdlib 5.0, *)
extension UniqueSet: GeneralizedEquatable { // Should be Equatable
extension UniqueSet: Equatable {
@inlinable
@inline(__always)
public static func ==(left: borrowing Self, right: borrowing Self) -> Bool {
@@ -14,10 +14,10 @@ import InternalCollectionsUtilities
import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension UniqueSet: GeneralizedHashable { // Should be Hashable
extension UniqueSet: Hashable {
@inlinable
public func hash(into hasher: inout Hasher) {
_storage.hash(into: &hasher)
@@ -13,7 +13,7 @@
import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension UniqueSet where Element: ~Copyable {
@@ -13,7 +13,7 @@
import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension UniqueSet where Element: ~Copyable {
@@ -13,7 +13,7 @@
import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension UniqueSet where Element: ~Copyable {
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension UniqueSet where Element: ~Copyable {
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension UniqueSet where Element: ~Copyable {
@@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(SwiftStdlib 5.0, *)
extension UniqueSet where Element: ~Copyable {
@@ -14,11 +14,17 @@ import InternalCollectionsUtilities
import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(<6.4) || !COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
@available(*, unavailable, message: "RigidSet requires a Swift 6.4 toolchain")
public struct UniqueSet<Element: Hashable>: ~Copyable {
package init() {
fatalError()
}
}
#else
@available(SwiftStdlib 5.0, *)
@frozen
public struct UniqueSet<Element: GeneralizedHashable & ~Copyable>: ~Copyable {
public struct UniqueSet<Element: Hashable & ~Copyable>: ~Copyable {
@usableFromInline
package typealias _Bucket = _HTable.Bucket
@@ -18,7 +18,7 @@ import BasicContainers
import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
class RigidDictionaryTests: CollectionTestCase {
func test_empty() {
@@ -17,7 +17,7 @@ import _CollectionsTestSupport
import BasicContainers
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
class RigidSetTests: CollectionTestCase {
func test_empty() {
@@ -18,7 +18,7 @@ import BasicContainers
import ContainersPreview
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
class UniqueDictionaryTests: CollectionTestCase {
func test_empty() {
@@ -17,7 +17,7 @@ import _CollectionsTestSupport
import BasicContainers
#endif
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
class UniqueSetTests: CollectionTestCase {
func test_empty() {
let s = UniqueSet<Int>()
@@ -78,11 +78,6 @@ extension LifetimeTracked: Hashable where Payload: Hashable {
}
}
#if compiler(>=6.3) && COLLECTIONS_UNSTABLE_NONCOPYABLE_KEYS
extension LifetimeTracked: GeneralizedEquatable where Payload: Equatable {}
extension LifetimeTracked: GeneralizedHashable where Payload: Hashable {}
#endif
extension LifetimeTracked: Comparable where Payload: Comparable {
public static func < (left: LifetimeTracked, right: LifetimeTracked) -> Bool {
return left.payload < right.payload
@@ -68,6 +68,27 @@ extension LifetimeTrackedStruct: TestPrintable where Payload: TestPrintable & ~C
}
#endif
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS
extension LifetimeTrackedStruct: Equatable where Payload: Equatable & ~Copyable {
public static func == (left: borrowing Self, right: borrowing Self) -> Bool {
return left.payload == right.payload
}
}
extension LifetimeTrackedStruct: Hashable where Payload: Hashable & ~Copyable {
public func _rawHashValue(seed: Int) -> Int {
payload._rawHashValue(seed: seed)
}
public func hash(into hasher: inout Hasher) {
hasher.combine(payload)
}
public var hashValue: Int {
payload.hashValue
}
}
#else
extension LifetimeTrackedStruct/*: Equatable*/ where Payload: Equatable /*& ~Copyable*/ {
public static func == (left: borrowing Self, right: borrowing Self) -> Bool {
return left.payload == right.payload
@@ -87,6 +108,7 @@ extension LifetimeTrackedStruct/*: Hashable*/ where Payload: Hashable /*& ~Copya
payload.hashValue
}
}
#endif
extension LifetimeTrackedStruct/*: Comparable*/ where Payload: Comparable /*& ~Copyable*/ {
public static func < (left: borrowing Self, right: borrowing Self) -> Bool {
@@ -65,7 +65,6 @@
7D2A779C2F27F2BF005780C7 /* Deque+ExpressibleByArrayLiteral.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A775C2F27F2BF005780C7 /* Deque+ExpressibleByArrayLiteral.swift */; };
7D2A779F2F27F367005780C7 /* InoutTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A779E2F27F367005780C7 /* InoutTests.swift */; };
7D2A77A02F27F367005780C7 /* BorrowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A779D2F27F367005780C7 /* BorrowTests.swift */; };
7D3D2DC92F3E5D110055E70B /* ProtocolGeneralizations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D3D2DC82F3E5D0E0055E70B /* ProtocolGeneralizations.swift */; };
7D479CB02F450E4600A8CB59 /* RigidSet+BorrowingSequence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D479CAF2F450E3F00A8CB59 /* RigidSet+BorrowingSequence.swift */; };
7D479CB32F45296A00A8CB59 /* UniqueSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D479CB12F45296000A8CB59 /* UniqueSet.swift */; };
7D479CB52F452D6900A8CB59 /* UniqueSetTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D479CB42F452D6700A8CB59 /* UniqueSetTests.swift */; };
@@ -632,7 +631,6 @@
7D2A77762F27F2BF005780C7 /* UniqueDeque+Replacements.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueDeque+Replacements.swift"; sourceTree = "<group>"; };
7D2A779D2F27F367005780C7 /* BorrowTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BorrowTests.swift; sourceTree = "<group>"; };
7D2A779E2F27F367005780C7 /* InoutTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InoutTests.swift; sourceTree = "<group>"; };
7D3D2DC82F3E5D0E0055E70B /* ProtocolGeneralizations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProtocolGeneralizations.swift; sourceTree = "<group>"; };
7D479CAF2F450E3F00A8CB59 /* RigidSet+BorrowingSequence.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidSet+BorrowingSequence.swift"; sourceTree = "<group>"; };
7D479CB12F45296000A8CB59 /* UniqueSet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UniqueSet.swift; sourceTree = "<group>"; };
7D479CB42F452D6700A8CB59 /* UniqueSetTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UniqueSetTests.swift; sourceTree = "<group>"; };
@@ -1363,7 +1361,6 @@
7D479CF22F47FB3D00A8CB59 /* _HTable+Removal.swift */,
7D479CE82F47DE1C00A8CB59 /* _HTable+Resizing.swift */,
7D72467D2F3D9DDB00112FD0 /* _HTable+Sizing.swift */,
7D3D2DC82F3E5D0E0055E70B /* ProtocolGeneralizations.swift */,
);
path = HashTable;
sourceTree = "<group>";
@@ -2502,7 +2499,6 @@
7D2A778C2F27F2BF005780C7 /* UniqueDeque+Prepend.swift in Sources */,
7D2A778D2F27F2BF005780C7 /* UniqueDeque.swift in Sources */,
7D2A778E2F27F2BF005780C7 /* RigidDeque.swift in Sources */,
7D3D2DC92F3E5D110055E70B /* ProtocolGeneralizations.swift in Sources */,
7D2A778F2F27F2BF005780C7 /* Deque+CustomReflectable.swift in Sources */,
7D2A77902F27F2BF005780C7 /* RigidDeque+Insertions.swift in Sources */,
7D2A77912F27F2BF005780C7 /* RigidDeque+Removals.swift in Sources */,