From 3238b9b575a0ca9d9eb7e0fff92d0b02cbcf95ea Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Wed, 5 Oct 2022 11:46:43 -0700 Subject: [PATCH] [PersistentDictionary] PersistentDictionary, .Iterator, .Index, .Keys, .Keys.Iterator, .Values, .Values.Iterator: Explicitly conform to Sendable when Key and Value are both Sendable --- .../PersistentDictionary+Collection.swift | 5 +++++ .../PersistentDictionary+Keys.swift | 9 +++++++++ .../PersistentDictionary+Sendable.swift | 15 +++++++++++++++ .../PersistentDictionary+Sequence.swift | 5 +++++ .../PersistentDictionary+Values.swift | 10 ++++++++++ 5 files changed, 44 insertions(+) create mode 100644 Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Sendable.swift diff --git a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Collection.swift b/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Collection.swift index 42813f5c..3827832d 100644 --- a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Collection.swift +++ b/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Collection.swift @@ -32,6 +32,11 @@ extension PersistentDictionary { } } +#if swift(>=5.5) +extension PersistentDictionary.Index: @unchecked Sendable +where Key: Sendable, Value: Sendable {} +#endif + extension PersistentDictionary.Index: Equatable { @inlinable public static func ==(left: Self, right: Self) -> Bool { diff --git a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Keys.swift b/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Keys.swift index 3c1e2029..7928893c 100644 --- a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Keys.swift +++ b/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Keys.swift @@ -34,6 +34,10 @@ extension PersistentDictionary { } } +#if swift(>=5.5) +extension PersistentDictionary.Keys: Sendable +where Key: Sendable, Value: Sendable {} +#endif extension PersistentDictionary.Keys: Sequence { public typealias Element = Key @@ -74,6 +78,11 @@ extension PersistentDictionary.Keys: Sequence { } } +#if swift(>=5.5) +extension PersistentDictionary.Keys.Iterator: Sendable +where Key: Sendable, Value: Sendable {} +#endif + extension PersistentDictionary.Keys: BidirectionalCollection { public typealias Index = PersistentDictionary.Index diff --git a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Sendable.swift b/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Sendable.swift new file mode 100644 index 00000000..b53df23b --- /dev/null +++ b/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Sendable.swift @@ -0,0 +1,15 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2022 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 swift(>=5.5) +extension PersistentDictionary: @unchecked Sendable +where Key: Sendable, Value: Sendable {} +#endif diff --git a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Sequence.swift b/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Sequence.swift index 1ab3cbe6..5591067c 100644 --- a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Sequence.swift +++ b/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Sequence.swift @@ -41,6 +41,11 @@ extension PersistentDictionary: Sequence { } } +#if swift(>=5.5) +extension PersistentDictionary.Iterator: @unchecked Sendable +where Key: Sendable, Value: Sendable {} +#endif + extension PersistentDictionary.Iterator: IteratorProtocol { public typealias Element = (key: Key, value: Value) diff --git a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Values.swift b/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Values.swift index 27d7d2d7..dc8bdb6a 100644 --- a/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Values.swift +++ b/Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Values.swift @@ -45,6 +45,11 @@ extension PersistentDictionary { } } +#if swift(>=5.5) +extension PersistentDictionary.Values: Sendable +where Key: Sendable, Value: Sendable {} +#endif + extension PersistentDictionary.Values: Sequence { public typealias Element = Value @@ -72,6 +77,11 @@ extension PersistentDictionary.Values: Sequence { } } +#if swift(>=5.5) +extension PersistentDictionary.Values.Iterator: Sendable +where Key: Sendable, Value: Sendable {} +#endif + // Note: This cannot be a MutableCollection because its subscript setter // needs to invalidate indices. extension PersistentDictionary.Values: BidirectionalCollection {