Skip to content

Commit 6e6a16f

Browse files
committed
[stdlib] Describe availability of new conformances and members
This assumes these will land in Swift 4.1; the attributes need to be adjusted if that turns out not to be the case. It seems @available for protocol conformances is not yet functional. I added attributes for those anyway, marked with FIXME(conformance-availability). # Conflicts: # stdlib/public/core/ExistentialCollection.swift.gyb # stdlib/public/core/Mirror.swift
1 parent 8d146e9 commit 6e6a16f

11 files changed

+65
-27
lines changed

stdlib/public/core/Arrays.swift.gyb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2250,14 +2250,16 @@ extension ${Self} : Equatable where Element : Equatable {
22502250
}
22512251
}
22522252

2253-
extension ${Self} : Hashable where Element : Hashable {
2253+
@available(swift, introduced: 4.1) // FIXME(conformance-availability)
2254+
extension ${Self}: Hashable where Element : Hashable {
22542255
/// The hash value for the array.
22552256
///
22562257
/// Two arrays that are equal will always have equal hash values.
22572258
///
22582259
/// Hash values are not guaranteed to be equal across different executions of
22592260
/// your program. Do not save hash values to use during a future execution.
22602261
@_inlineable // FIXME(sil-serialize-all)
2262+
@available(swift, introduced: 4.1)
22612263
public var hashValue: Int {
22622264
// FIXME(ABI)#177: <rdar://problem/18915294> Issue applies to Array too
22632265
var result: Int = 0

stdlib/public/core/ClosedRange.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,10 @@ extension ClosedRange.Index : Comparable {
167167
}
168168
}
169169

170-
extension ClosedRange.Index: Hashable
170+
@available(swift, introduced: 4.1) // FIXME(conformance-availability)
171+
extension ClosedRange.Index: Hashable
171172
where Bound: Strideable, Bound.Stride: SignedInteger, Bound: Hashable {
173+
@available(swift, introduced: 4.1)
172174
public var hashValue: Int {
173175
switch self {
174176
case .inRange(let value):

stdlib/public/core/CollectionOfOne.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,17 @@ extension CollectionOfOne: RandomAccessCollection, MutableCollection {
136136
}
137137
}
138138

139+
@available(swift, introduced: 4.1) // FIXME(conformance-availability)
139140
extension CollectionOfOne : Equatable where Element : Equatable {
140141
/// Returns a Boolean value indicating whether two collections are equal.
141142
@_inlineable // FIXME(sil-serialize-all)
143+
@available(swift, introduced: 4.1)
142144
public static func == (lhs: CollectionOfOne, rhs: CollectionOfOne) -> Bool {
143145
return lhs._element == rhs._element
144146
}
145147
}
146148

149+
@available(swift, introduced: 4.1) // FIXME(conformance-availability)
147150
extension CollectionOfOne : Hashable where Element : Hashable {
148151
/// The hash value for the collection.
149152
///
@@ -152,6 +155,7 @@ extension CollectionOfOne : Hashable where Element : Hashable {
152155
/// Hash values are not guaranteed to be equal across different executions of
153156
/// your program. Do not save hash values to use during a future execution.
154157
@_inlineable // FIXME(sil-serialize-all)
158+
@available(swift, introduced: 4.1)
155159
public var hashValue: Int {
156160
return _element.hashValue
157161
}

stdlib/public/core/EmptyCollection.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,10 @@ extension EmptyCollection : Equatable {
173173
}
174174
}
175175

176+
@available(swift, introduced: 4.1) // FIXME(conformance-availability)
176177
extension EmptyCollection : Hashable {
177178
@_inlineable // FIXME(sil-serialize-all)
179+
@available(swift, introduced: 4.1)
178180
public var hashValue: Int {
179181
return 0
180182
}

stdlib/public/core/ExistentialCollection.swift.gyb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,8 +1244,10 @@ extension ${Self}: _AnyCollectionProtocol {
12441244
}
12451245
% end
12461246
1247+
@available(swift, introduced: 4.1) // FIXME(conformance-availability)
12471248
extension AnyCollection : Equatable where Element : Equatable {
12481249
@_inlineable // FIXME(sil-serialize-all)
1250+
@available(swift, introduced: 4.1)
12491251
public static func == (
12501252
lhs: AnyCollection<Element>, rhs: AnyCollection<Element>
12511253
) -> Bool {
@@ -1256,6 +1258,7 @@ extension AnyCollection : Equatable where Element : Equatable {
12561258
}
12571259
}
12581260
1261+
@available(swift, introduced: 4.1) // FIXME(conformance-availability)
12591262
extension AnyCollection : Hashable where Element : Hashable {
12601263
/// The hash value for the collection.
12611264
///
@@ -1265,6 +1268,7 @@ extension AnyCollection : Hashable where Element : Hashable {
12651268
/// Hash values are not guaranteed to be equal across different executions of
12661269
/// your program. Do not save hash values to use during a future execution.
12671270
@_inlineable // FIXME(sil-serialize-all)
1271+
@available(swift, introduced: 4.1)
12681272
public var hashValue: Int {
12691273
// FIXME(ABI)#177: <rdar://problem/18915294> Issue applies to AnyCollection too
12701274
var result: Int = 0

stdlib/public/core/HashedCollections.swift.gyb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2786,6 +2786,7 @@ extension Dictionary : Equatable where Value : Equatable {
27862786
}
27872787
}
27882788

2789+
@available(swift, introduced: 4.1) // FIXME(conformance-availability)
27892790
extension Dictionary : Hashable where Value : Hashable {
27902791
/// The hash value for the dictionary.
27912792
///
@@ -2794,6 +2795,7 @@ extension Dictionary : Hashable where Value : Hashable {
27942795
/// Hash values are not guaranteed to be equal across different executions of
27952796
/// your program. Do not save hash values to use during a future execution.
27962797
@_inlineable // FIXME(sil-serialize-all)
2798+
@available(swift, introduced: 4.1)
27972799
public var hashValue: Int {
27982800
// FIXME(ABI)#177: <rdar://problem/18915294> Issue applies to Dictionary too
27992801
var result: Int = 0

stdlib/public/core/Mirror.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,8 +905,10 @@ extension DictionaryLiteral : RandomAccessCollection {
905905
}
906906
}
907907

908+
@available(swift, introduced: 4.1) // FIXME(conformance-availability)
908909
extension DictionaryLiteral: Equatable where Key: Equatable, Value: Equatable {
909910
@_inlineable // FIXME(sil-serialize-all)
911+
@available(swift, introduced: 4.1)
910912
public static func == (
911913
lhs: DictionaryLiteral<Key, Value>, rhs: DictionaryLiteral<Key, Value>
912914
) -> Bool {
@@ -917,6 +919,7 @@ extension DictionaryLiteral: Equatable where Key: Equatable, Value: Equatable {
917919
}
918920
}
919921

922+
@available(swift, introduced: 4.1) // FIXME(conformance-availability)
920923
extension DictionaryLiteral: Hashable where Key: Hashable, Value: Hashable {
921924
/// The hash value for the collection.
922925
///
@@ -926,6 +929,7 @@ extension DictionaryLiteral: Hashable where Key: Hashable, Value: Hashable {
926929
/// Hash values are not guaranteed to be equal across different executions of
927930
/// your program. Do not save hash values to use during a future execution.
928931
@_inlineable // FIXME(sil-serialize-all)
932+
@available(swift, introduced: 4.1)
929933
public var hashValue: Int {
930934
// FIXME(ABI)#177: <rdar://problem/18915294> Issue applies to DictionaryLiteral too
931935
var result: Int = 0

stdlib/public/core/Optional.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ extension Optional : Equatable where Wrapped : Equatable {
409409
}
410410
}
411411

412+
@available(swift, introduced: 4.1) // FIXME(conformance-availability)
412413
extension Optional : Hashable where Wrapped : Hashable {
413414
/// The hash value for the optional.
414415
///
@@ -417,6 +418,7 @@ extension Optional : Hashable where Wrapped : Hashable {
417418
/// Hash values are not guaranteed to be equal across different executions of
418419
/// your program. Do not save hash values to use during a future execution.
419420
@_inlineable // FIXME(sil-serialize-all)
421+
@available(swift, introduced: 4.1)
420422
public var hashValue: Int {
421423
var result: Int
422424
switch self {

stdlib/public/core/Range.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ extension Range: Equatable {
358358
}
359359
}
360360

361+
@available(swift, introduced: 4.1) // FIXME(conformance-availability)
361362
extension Range : Hashable where Bound : Hashable {
362363
/// The hash value for the range.
363364
///
@@ -366,6 +367,7 @@ extension Range : Hashable where Bound : Hashable {
366367
/// Hash values are not guaranteed to be equal across different executions of
367368
/// your program. Do not save hash values to use during a future execution.
368369
@_inlineable // FIXME(sil-serialize-all)
370+
@available(swift, introduced: 4.1)
369371
public var hashValue: Int {
370372
return _combineHashValues(lowerBound.hashValue, upperBound.hashValue)
371373
}

validation-test/stdlib/Dictionary.swift

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -83,31 +83,6 @@ DictionaryTestSuite.test("Index.Hashable") {
8383
expectNotNil(e[d.startIndex])
8484
}
8585

86-
DictionaryTestSuite.test("Hashable") {
87-
let d1: Dictionary<Int, String> = [1: "meow", 2: "meow", 3: "meow"]
88-
let d2: Dictionary<Int, String> = [1: "meow", 2: "meow", 3: "mooo"]
89-
let d3: Dictionary<Int, String> = [1: "meow", 2: "meow", 4: "meow"]
90-
let d4: Dictionary<Int, String> = [1: "meow", 2: "meow", 4: "mooo"]
91-
checkHashable([d1, d2, d3, d4], equalityOracle: { $0 == $1 })
92-
93-
let dd1: Dictionary<Int, Dictionary<Int, String>> = [1: [2: "meow"]]
94-
let dd2: Dictionary<Int, Dictionary<Int, String>> = [2: [1: "meow"]]
95-
let dd3: Dictionary<Int, Dictionary<Int, String>> = [2: [2: "meow"]]
96-
let dd4: Dictionary<Int, Dictionary<Int, String>> = [1: [1: "meow"]]
97-
let dd5: Dictionary<Int, Dictionary<Int, String>> = [2: [2: "mooo"]]
98-
let dd6: Dictionary<Int, Dictionary<Int, String>> = [2: [:]]
99-
let dd7: Dictionary<Int, Dictionary<Int, String>> = [:]
100-
checkHashable([dd1, dd2, dd3, dd4, dd5, dd6, dd7], equalityOracle: { $0 == $1 })
101-
102-
// Check that hash is equal even though dictionary is traversed differently
103-
var d5: Dictionary<Int, String> = [1: "meow", 2: "meow", 3: "mooo", 4: "woof", 5: "baah", 6: "mooo"]
104-
let expected = d5.hashValue
105-
for capacity in [4, 8, 16, 32, 64, 128, 256] {
106-
d5.reserveCapacity(capacity)
107-
expectEqual(d5.hashValue, expected)
108-
}
109-
}
110-
11186
DictionaryTestSuite.test("valueDestruction") {
11287
var d1 = Dictionary<Int, TestValueTy>()
11388
for i in 100...110 {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// RUN: rm -rf %t ; mkdir -p %t
2+
// RUN: %target-build-swift %s -o %t/a.out -swift-version 4 && %target-run %t/a.out
3+
4+
// REQUIRES: executable_test
5+
6+
import StdlibUnittest
7+
import StdlibCollectionUnittest
8+
9+
var DictionaryTestSuite = TestSuite("Dictionary4")
10+
11+
DictionaryTestSuite.test("Hashable") {
12+
let d1: Dictionary<Int, String> = [1: "meow", 2: "meow", 3: "meow"]
13+
let d2: Dictionary<Int, String> = [1: "meow", 2: "meow", 3: "mooo"]
14+
let d3: Dictionary<Int, String> = [1: "meow", 2: "meow", 4: "meow"]
15+
let d4: Dictionary<Int, String> = [1: "meow", 2: "meow", 4: "mooo"]
16+
checkHashable([d1, d2, d3, d4], equalityOracle: { $0 == $1 })
17+
18+
let dd1: Dictionary<Int, Dictionary<Int, String>> = [1: [2: "meow"]]
19+
let dd2: Dictionary<Int, Dictionary<Int, String>> = [2: [1: "meow"]]
20+
let dd3: Dictionary<Int, Dictionary<Int, String>> = [2: [2: "meow"]]
21+
let dd4: Dictionary<Int, Dictionary<Int, String>> = [1: [1: "meow"]]
22+
let dd5: Dictionary<Int, Dictionary<Int, String>> = [2: [2: "mooo"]]
23+
let dd6: Dictionary<Int, Dictionary<Int, String>> = [2: [:]]
24+
let dd7: Dictionary<Int, Dictionary<Int, String>> = [:]
25+
checkHashable(
26+
[dd1, dd2, dd3, dd4, dd5, dd6, dd7],
27+
equalityOracle: { $0 == $1 })
28+
29+
// Check that hash is equal even though dictionary is traversed differently
30+
var d5: Dictionary<Int, String> =
31+
[1: "meow", 2: "meow", 3: "mooo", 4: "woof", 5: "baah", 6: "mooo"]
32+
let expected = d5.hashValue
33+
for capacity in [4, 8, 16, 32, 64, 128, 256] {
34+
d5.reserveCapacity(capacity)
35+
expectEqual(d5.hashValue, expected)
36+
}
37+
}
38+
39+
runAllTests()

0 commit comments

Comments
 (0)