Skip to content

Commit b2ef455

Browse files
committed
[test] Update tests for _rawHashValue(seed:) changes
1 parent 6d81663 commit b2ef455

File tree

9 files changed

+72
-73
lines changed

9 files changed

+72
-73
lines changed

stdlib/private/StdlibUnittest/StdlibUnittest.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2378,7 +2378,7 @@ public func checkHashable<Instances: Collection>(
23782378
""",
23792379
stackTrace: stackTrace.pushIf(showFrame, file: file, line: line))
23802380
expectEqual(
2381-
x._rawHashValue(seed: (0, 0)), y._rawHashValue(seed: (0, 0)),
2381+
x._rawHashValue(seed: 0), y._rawHashValue(seed: 0),
23822382
"""
23832383
_rawHashValue expected to match, found to differ
23842384
lhs (at index \(i)): \(x)
@@ -2399,8 +2399,8 @@ public func checkHashable<Instances: Collection>(
23992399
""",
24002400
stackTrace: stackTrace.pushIf(showFrame, file: file, line: line))
24012401
expectTrue(
2402-
(0..<10 as Range<UInt64>).contains { i in
2403-
x._rawHashValue(seed: (0, i)) != y._rawHashValue(seed: (0, i))
2402+
(0..<10).contains { i in
2403+
x._rawHashValue(seed: i) != y._rawHashValue(seed: i)
24042404
},
24052405
"""
24062406
_rawHashValue(seed:) expected to differ, found to match

test/IRGen/enum_derived.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ enum E {
2727

2828
// CHECK-NORMAL-LABEL:define hidden swiftcc i{{.*}} @"$s12enum_derived1EO9hashValueSivg"(i8)
2929
// CHECK-TESTABLE-LABEL:define{{( dllexport)?}}{{( protected)?}} swiftcc i{{.*}} @"$s12enum_derived1EO9hashValueSivg"(i8)
30-
// CHECK: call swiftcc void @"$ss6HasherV5_seedABs6UInt64V_AEt_tcfC"(%Ts6HasherV* {{.*}})
30+
// CHECK: call swiftcc void @"$ss6HasherV5_seedABSi_tcfC"(%Ts6HasherV* {{.*}})
3131
// CHECK: call swiftcc i{{[0-9]+}} @"$ss6HasherV9_finalizeSiyF"(%Ts6HasherV* {{.*}})
3232
// CHECK: ret i{{[0-9]+}} %{{[0-9]+}}
3333

test/SILGen/objc_bridging_any.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,5 +698,5 @@ class SwiftAnyEnjoyer: NSIdLover, NSIdLoving {
698698
// CHECK-NEXT: base_protocol Equatable: GenericOption: Equatable module objc_generics
699699
// CHECK-NEXT: method #Hashable.hashValue!getter.1: {{.*}} : @$sSo13GenericOptionaSHSCSH9hashValueSivgTW
700700
// CHECK-NEXT: method #Hashable.hash!1: {{.*}} : @$sSo13GenericOptionaSHSCSH4hash4intoys6HasherVz_tFTW
701-
// CHECK-NEXT: method #Hashable._rawHashValue!1: {{.*}} : @$sSo13GenericOptionaSHSCSH13_rawHashValue4seedSis6UInt64V_AFt_tFTW
701+
// CHECK-NEXT: method #Hashable._rawHashValue!1: {{.*}} : @$sSo13GenericOptionaSHSCSH13_rawHashValue4seedS2i_tFTW
702702
// CHECK-NEXT: }

test/SILGen/synthesized_conformance_enum.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ extension NoValues: CaseIterable {}
6363
// CHECK-NEXT: base_protocol Equatable: <T where T : Equatable> Enum<T>: Equatable module synthesized_conformance_enum
6464
// CHECK-NEXT: method #Hashable.hashValue!getter.1: <Self where Self : Hashable> (Self) -> () -> Int : @$s28synthesized_conformance_enum4EnumOyxGSHAASHRzlSH9hashValueSivgTW // protocol witness for Hashable.hashValue.getter in conformance <A> Enum<A>
6565
// CHECK-NEXT: method #Hashable.hash!1: <Self where Self : Hashable> (Self) -> (inout Hasher) -> () : @$s28synthesized_conformance_enum4EnumOyxGSHAASHRzlSH4hash4intoys6HasherVz_tFTW // protocol witness for Hashable.hash(into:) in conformance <A> Enum<A>
66-
// CHECK-NEXT: method #Hashable._rawHashValue!1: <Self where Self : Hashable> (Self) -> ((UInt64, UInt64)) -> Int : @$s28synthesized_conformance_enum4EnumOyxGSHAASHRzlSH13_rawHashValue4seedSis6UInt64V_AHt_tFTW // protocol witness for Hashable._rawHashValue(seed:) in conformance <A> Enum<A>
66+
// CHECK-NEXT: method #Hashable._rawHashValue!1: <Self where Self : Hashable> (Self) -> (Int) -> Int : @$s28synthesized_conformance_enum4EnumOyxGSHAASHRzlSH13_rawHashValue4seedS2i_tFTW // protocol witness for Hashable._rawHashValue(seed:) in conformance <A> Enum<A>
6767
// CHECK-NEXT: conditional_conformance (T: Hashable): dependent
6868
// CHECK-NEXT: }
6969

test/SILGen/synthesized_conformance_struct.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ extension Struct: Codable where T: Codable {}
6565
// CHECK-NEXT: base_protocol Equatable: <T where T : Equatable> Struct<T>: Equatable module synthesized_conformance_struct
6666
// CHECK-NEXT: method #Hashable.hashValue!getter.1: <Self where Self : Hashable> (Self) -> () -> Int : @$s30synthesized_conformance_struct6StructVyxGSHAASHRzlSH9hashValueSivgTW // protocol witness for Hashable.hashValue.getter in conformance <A> Struct<A>
6767
// CHECK-NEXT: method #Hashable.hash!1: <Self where Self : Hashable> (Self) -> (inout Hasher) -> () : @$s30synthesized_conformance_struct6StructVyxGSHAASHRzlSH4hash4intoys6HasherVz_tFTW // protocol witness for Hashable.hash(into:) in conformance <A> Struct<A>
68-
// CHECK-NEXT: method #Hashable._rawHashValue!1: <Self where Self : Hashable> (Self) -> ((UInt64, UInt64)) -> Int : @$s30synthesized_conformance_struct6StructVyxGSHAASHRzlSH13_rawHashValue4seedSis6UInt64V_AHt_tFTW // protocol witness for Hashable._rawHashValue(seed:) in conformance <A> Struct<A>
68+
// CHECK-NEXT: method #Hashable._rawHashValue!1: <Self where Self : Hashable> (Self) -> (Int) -> Int : @$s30synthesized_conformance_struct6StructVyxGSHAASHRzlSH13_rawHashValue4seedS2i_tFTW // protocol witness for Hashable._rawHashValue(seed:) in conformance <A> Struct<A>
6969
// CHECK-NEXT: conditional_conformance (T: Hashable): dependent
7070
// CHECK-NEXT: }
7171

validation-test/stdlib/FixedPoint.swift.gyb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,9 @@ FixedPoint.test("${Self}.hash(into:)") {
246246

247247
% reference = prepare_bit_pattern(bit_pattern, self_ty.bits, False)
248248
% if self_ty.bits == 64:
249-
let expected = Hasher._hash(seed: Hasher._seed, ${reference} as UInt64)
249+
let expected = Hasher._hash(seed: 0, ${reference} as UInt64)
250250
% else:
251-
let expected = Hasher._hash(
252-
seed: Hasher._seed,
253-
bytes: ${reference},
254-
count: ${self_ty.bits / 8})
251+
let expected = Hasher._hash(seed: 0, bytes: ${reference}, count: ${self_ty.bits / 8})
255252
% end
256253
expectEqual(expected, output, "input: \(input)")
257254
}

validation-test/stdlib/Hashing.swift

Lines changed: 57 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ var HashingTestSuite = TestSuite("Hashing")
1010

1111
func checkHash(
1212
for value: UInt64,
13-
withSeed seed: (UInt64, UInt64),
13+
withSeed seed: UInt,
1414
expected: UInt64,
1515
file: String = #file, line: UInt = #line
1616
) {
17-
var hasher = Hasher(_seed: seed)
17+
var hasher = Hasher(_seed: Int(bitPattern: seed))
1818
hasher._combine(value)
1919
let hash = hasher.finalize()
2020
expectEqual(
@@ -23,50 +23,52 @@ func checkHash(
2323
}
2424

2525
HashingTestSuite.test("Hasher/CustomKeys") {
26-
// This assumes Hasher implements SipHash-1-3.
27-
checkHash(for: 0, withSeed: (0, 0), expected: 0xbd60acb658c79e45)
28-
checkHash(for: 0, withSeed: (0, 1), expected: 0x1ce32b0b44e61175)
29-
checkHash(for: 0, withSeed: (1, 0), expected: 0x9c44b7c8df2ca74b)
30-
checkHash(for: 0, withSeed: (1, 1), expected: 0x9653ca0a3b455506)
31-
checkHash(for: 0, withSeed: (.max, .max), expected: 0x3ab336a4895e4d36)
32-
33-
checkHash(for: 1, withSeed: (0, 0), expected: 0x1e9f734161d62dd9)
34-
checkHash(for: 1, withSeed: (0, 1), expected: 0xb6fcf32d09f76cba)
35-
checkHash(for: 1, withSeed: (1, 0), expected: 0xacb556b13007504a)
36-
checkHash(for: 1, withSeed: (1, 1), expected: 0x7defec680db51d24)
37-
checkHash(for: 1, withSeed: (.max, .max), expected: 0x212798441870ef6b)
38-
39-
checkHash(for: .max, withSeed: (0, 0), expected: 0x2f205be2fec8e38d)
40-
checkHash(for: .max, withSeed: (0, 1), expected: 0x3ff7fa33381ecf7b)
41-
checkHash(for: .max, withSeed: (1, 0), expected: 0x404afd8eb2c4b22a)
42-
checkHash(for: .max, withSeed: (1, 1), expected: 0x855642d657c1bd46)
43-
checkHash(for: .max, withSeed: (.max, .max), expected: 0x5b16b7a8181980c2)
26+
// This assumes Hasher implements SipHash-1-3 and hashing is deterministic.
27+
expectTrue(Hasher._isDeterministic)
28+
29+
checkHash(for: 0, withSeed: 0, expected: 0xbd60acb658c79e45)
30+
checkHash(for: 1, withSeed: 0, expected: 0x1e9f734161d62dd9)
31+
checkHash(for: .max, withSeed: 0, expected: 0x2f205be2fec8e38d)
32+
33+
checkHash(for: 0, withSeed: 1, expected: 0x9c44b7c8df2ca74b)
34+
checkHash(for: 1, withSeed: 1, expected: 0xacb556b13007504a)
35+
checkHash(for: .max, withSeed: 1, expected: 0x404afd8eb2c4b22a)
36+
37+
checkHash(for: 0, withSeed: 0xFFFFFFFF, expected: 0x47329159fe988221)
38+
checkHash(for: 1, withSeed: 0xFFFFFFFF, expected: 0xd7da861471fc35dc)
39+
checkHash(for: .max, withSeed: 0xFFFFFFFF, expected: 0xf6e3047fc114dbc0)
40+
41+
#if !(arch(i386) || arch(arm))
42+
checkHash(for: 0, withSeed: 0xFFFFFFFF_FFFFFFFF, expected: 0x8d0ea5ad8d6a55c7)
43+
checkHash(for: 1, withSeed: 0xFFFFFFFF_FFFFFFFF, expected: 0x2899f60d6b5bc847)
44+
checkHash(for: .max, withSeed: 0xFFFFFFFF_FFFFFFFF, expected: 0xc4d7726fff5e65a0)
45+
#endif
4446
}
4547

4648
HashingTestSuite.test("Hasher/DefaultKey") {
4749
let value: UInt64 = 0x0102030405060708
4850

4951
let defaultHash = _hashValue(for: value)
5052

51-
let rawHash = value._rawHashValue(seed: Hasher._seed)
53+
let rawHash = value._rawHashValue(seed: 0)
5254
expectEqual(rawHash, defaultHash)
5355

54-
let oneShotHash = Hasher._hash(seed: Hasher._seed, value)
56+
let oneShotHash = Hasher._hash(seed: 0, value)
5557
expectEqual(oneShotHash, defaultHash)
5658

5759
var defaultHasher = Hasher()
5860
defaultHasher._combine(value)
5961
expectEqual(defaultHasher.finalize(), defaultHash)
6062

61-
var customHasher = Hasher(_seed: Hasher._seed)
63+
var customHasher = Hasher(_seed: 0)
6264
customHasher._combine(value)
6365
expectEqual(customHasher.finalize(), defaultHash)
6466
}
6567

6668
HashingTestSuite.test("Hashing/TopLevelHashing/UInt64") {
6769
func checkTopLevelHash(
6870
for value: UInt64,
69-
seed: (UInt64, UInt64),
71+
seed: Int,
7072
file: String = #file,
7173
line: UInt = #line) {
7274
var hasher = Hasher(_seed: seed)
@@ -75,22 +77,20 @@ HashingTestSuite.test("Hashing/TopLevelHashing/UInt64") {
7577
let actual = Hasher._hash(seed: seed, value)
7678
expectEqual(actual, expected, file: file, line: line)
7779
}
78-
checkTopLevelHash(for: 0, seed: (0, 0))
79-
checkTopLevelHash(for: 1, seed: (0, 0))
80-
checkTopLevelHash(for: 1, seed: (1, 0))
81-
checkTopLevelHash(for: 1, seed: (1, 1))
82-
checkTopLevelHash(for: 0x0102030405060708, seed: (1, 1))
83-
checkTopLevelHash(
84-
for: 0x0102030405060708,
85-
seed: (0x0807060504030201, 0x090a0b0c0d0e0f))
86-
checkTopLevelHash(for: UInt64.max, seed: (1, 1))
87-
checkTopLevelHash(for: UInt64.max, seed: (UInt64.max, UInt64.max))
80+
checkTopLevelHash(for: 0, seed: 0)
81+
checkTopLevelHash(for: 1, seed: 0)
82+
checkTopLevelHash(for: 0, seed: 1)
83+
checkTopLevelHash(for: 1, seed: 1)
84+
checkTopLevelHash(for: 0x0102030405060708, seed: 1)
85+
checkTopLevelHash(for: 0x0102030405060708, seed: Int.max)
86+
checkTopLevelHash(for: UInt64.max, seed: 1)
87+
checkTopLevelHash(for: UInt64.max, seed: Int.max)
8888
}
8989

9090
HashingTestSuite.test("Hashing/TopLevelHashing/UInt") {
9191
func checkTopLevelHash(
9292
for value: UInt,
93-
seed: (UInt64, UInt64),
93+
seed: Int,
9494
file: String = #file,
9595
line: UInt = #line) {
9696
var hasher = Hasher(_seed: seed)
@@ -99,25 +99,25 @@ HashingTestSuite.test("Hashing/TopLevelHashing/UInt") {
9999
let actual = Hasher._hash(seed: seed, value)
100100
expectEqual(actual, expected, file: file, line: line)
101101
}
102-
checkTopLevelHash(for: 0, seed: (0, 0))
103-
checkTopLevelHash(for: 1, seed: (0, 0))
104-
checkTopLevelHash(for: 1, seed: (1, 0))
105-
checkTopLevelHash(for: 1, seed: (1, 1))
102+
checkTopLevelHash(for: 0, seed: 0)
103+
checkTopLevelHash(for: 1, seed: 0)
104+
checkTopLevelHash(for: 0, seed: 1)
105+
checkTopLevelHash(for: 1, seed: 1)
106106
checkTopLevelHash(
107107
for: UInt(truncatingIfNeeded: 0x0102030405060708 as UInt64),
108-
seed: (1, 1))
108+
seed: 1)
109109
checkTopLevelHash(
110110
for: UInt(truncatingIfNeeded: 0x0102030405060708 as UInt64),
111-
seed: (0x8877665544332211, 0x1122334455667788))
112-
checkTopLevelHash(for: UInt.max, seed: (1, 1))
113-
checkTopLevelHash(for: UInt.max, seed: (UInt64.max, UInt64.max))
111+
seed: Int(truncatingIfNeeded: 0x8877665544332211 as UInt64))
112+
checkTopLevelHash(for: UInt.max, seed: 1)
113+
checkTopLevelHash(for: UInt.max, seed: Int.max)
114114
}
115115

116116
HashingTestSuite.test("Hashing/TopLevelHashing/PartialUInt64") {
117117
func checkTopLevelHash(
118118
for value: UInt64,
119119
count: Int,
120-
seed: (UInt64, UInt64),
120+
seed: Int,
121121
file: String = #file,
122122
line: UInt = #line) {
123123
var hasher = Hasher(_seed: seed)
@@ -131,11 +131,12 @@ HashingTestSuite.test("Hashing/TopLevelHashing/PartialUInt64") {
131131
file: file,
132132
line: line)
133133
}
134-
for seed: (UInt64, UInt64) in [
135-
(0, 0),
136-
(1, 0),
137-
(1, 1),
138-
(0x1827364554637281, 0xf9e8d7c6b5a49382)
134+
for seed: Int in [
135+
0,
136+
1,
137+
2,
138+
Int(truncatingIfNeeded: 0x1827364554637281 as UInt64),
139+
Int(truncatingIfNeeded: 0xf9e8d7c6b5a49382 as UInt64)
139140
] {
140141
for count in 1 ..< 8 {
141142
checkTopLevelHash(for: 0, count: count, seed: seed)
@@ -153,7 +154,7 @@ HashingTestSuite.test("Hashing/TopLevelHashing/PartialUInt64") {
153154
HashingTestSuite.test("Hashing/TopLevelHashing/UnsafeRawBufferPointer") {
154155
func checkTopLevelHash(
155156
for buffer: [UInt8],
156-
seed: (UInt64, UInt64),
157+
seed: Int,
157158
file: String = #file,
158159
line: UInt = #line) {
159160
var hasher = Hasher(_seed: seed)
@@ -171,11 +172,12 @@ HashingTestSuite.test("Hashing/TopLevelHashing/UnsafeRawBufferPointer") {
171172
file: file,
172173
line: line)
173174
}
174-
for seed: (UInt64, UInt64) in [
175-
(0, 0),
176-
(1, 0),
177-
(1, 1),
178-
(0x1827364554637281, 0xf9e8d7c6b5a49382)
175+
for seed: Int in [
176+
0,
177+
1,
178+
2,
179+
Int(truncatingIfNeeded: 0x1827364554637281 as UInt64),
180+
Int(truncatingIfNeeded: 0xf9e8d7c6b5a49382 as UInt64)
179181
] {
180182
var zeros: [UInt8] = []
181183
var integers: [UInt8] = []

validation-test/stdlib/HashingRandomization.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// environment variable is set.
1212

1313
print("Deterministic: \(Hasher._isDeterministic)")
14-
print("Seed: \(Hasher._seed)")
14+
print("Seed: \(Hasher._executionSeed)")
1515
print("Hash values: <\(0.hashValue), \(1.hashValue)>")
1616

1717
// With randomized hashing, we get a new seed and a new set of hash values on

validation-test/stdlib/SipHash.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ struct Loop<C: Collection>: Sequence, IteratorProtocol {
245245

246246
SipHashTests.test("${Self}/combine(UnsafeRawBufferPointer)")
247247
.forEach(in: ${tests}) { test in
248-
var hasher = ${Self}(_seed: test.seed)
248+
var hasher = ${Self}(_rawSeed: test.seed)
249249
test.input.withUnsafeBytes { hasher.combine(bytes: $0) }
250250
let hash = hasher.finalize()
251251
expectEqual(${Self}.HashValue(truncatingIfNeeded: test.output), hash)
@@ -255,7 +255,7 @@ SipHashTests.test("${Self}/combine(UnsafeRawBufferPointer)/pattern")
255255
.forEach(in: cartesianProduct(${tests}, incrementalPatterns)) { test_ in
256256
let (test, pattern) = test_
257257

258-
var hasher = ${Self}(_seed: test.seed)
258+
var hasher = ${Self}(_rawSeed: test.seed)
259259
var chunkSizes = Loop(pattern).makeIterator()
260260
var startIndex = 0
261261
while startIndex != test.input.endIndex {
@@ -274,7 +274,7 @@ SipHashTests.test("${Self}/combine(UnsafeRawBufferPointer)/pattern")
274274
SipHashTests.test("${Self}._combine(${data_type})")
275275
.forEach(in: ${tests}) { test in
276276

277-
var hasher = ${Self}(_seed: test.seed)
277+
var hasher = ${Self}(_rawSeed: test.seed)
278278

279279
// Load little-endian chunks and combine them into the hasher.
280280
let bitWidth = ${data_type}.bitWidth
@@ -303,7 +303,7 @@ SipHashTests.test("${Self}._combine(${data_type})")
303303

304304
SipHashTests.test("${Self}/OperationsAfterFinalize") {
305305
// Verify that finalize is nonmutating.
306-
var hasher1 = ${Self}(_seed: (0, 0))
306+
var hasher1 = ${Self}(_rawSeed: (0, 0))
307307
hasher1._combine(1 as UInt8)
308308
_ = hasher1.finalize()
309309
// Hasher is now consumed. The operations below are illegal, but this isn't
@@ -314,7 +314,7 @@ SipHashTests.test("${Self}/OperationsAfterFinalize") {
314314
let hash1b = hasher1.finalize()
315315
expectEqual(hash1a, hash1b)
316316

317-
var hasher2 = ${Self}(_seed: (0, 0))
317+
var hasher2 = ${Self}(_rawSeed: (0, 0))
318318
hasher2._combine(1 as UInt8)
319319
hasher2._combine(2 as UInt16)
320320
let hash2 = hasher2.finalize()

0 commit comments

Comments
 (0)