Skip to content

Commit ade8310

Browse files
committed
[test] Modernize hashing throughout the test suite
(cherry picked from commit 666a22f)
1 parent e714edb commit ade8310

File tree

60 files changed

+224
-160
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+224
-160
lines changed

test/ClangImporter/objc_override.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class CallbackSubC : CallbackBase {
110110

111111
//
112112
class MyHashableNSObject: NSObject {
113-
override var hashValue: Int { // expected-warning{{override of 'NSObject.hashValue' is deprecated}}
113+
override var hashValue: Int { // expected-error{{overriding non-open property outside of its defining module}} expected-error{{overriding non-@objc declarations from extensions is not supported}}
114114
return 0
115115
}
116116
}

test/Constraints/bridging-nsnumber-and-nsvalue.swift.gyb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ extension Equatable {
3838
fatalError("hella cray")
3939
}
4040
}
41-
extension Hashable { public var hashValue: Int { fatalError("trill hiphy") } }
41+
extension Hashable {
42+
public func hash(into hasher: inout Hasher) {
43+
fatalError("trill hiphy")
44+
}
45+
}
46+
4247
extension CGSize: Hashable {}
4348
extension CGPoint: Hashable {}
4449
extension CGRect: Hashable {}

test/Constraints/bridging.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extension LazyFilterSequence.Iterator : _ObjectiveCBridgeable { // expected-erro
4343

4444

4545
struct BridgedStruct : Hashable, _ObjectiveCBridgeable {
46-
var hashValue: Int { return 0 }
46+
func hash(into hasher: inout Hasher) {}
4747

4848
func _bridgeToObjectiveC() -> BridgedClass {
4949
return BridgedClass()
@@ -71,14 +71,14 @@ struct BridgedStruct : Hashable, _ObjectiveCBridgeable {
7171

7272
func ==(x: BridgedStruct, y: BridgedStruct) -> Bool { return true }
7373

74-
struct NotBridgedStruct : Hashable {
75-
var hashValue: Int { return 0 }
74+
struct NotBridgedStruct : Hashable {
75+
func hash(into hasher: inout Hasher) {}
7676
}
7777

7878
func ==(x: NotBridgedStruct, y: NotBridgedStruct) -> Bool { return true }
7979

8080
class OtherClass : Hashable {
81-
var hashValue: Int { return 0 }
81+
func hash(into hasher: inout Hasher) {}
8282
}
8383
func ==(x: OtherClass, y: OtherClass) -> Bool { return true }
8484

test/DebugInfo/DumpTypeFromMangledName.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ let _ = main()
5353
public struct tinky : Equatable, Hashable {
5454
internal let _value: Int
5555

56-
public var hashValue: Int {
57-
return 0
58-
}
56+
public func hash(into hasher: inout Hasher) {}
5957
}
6058

6159
public func == (lhs: tinky, rhs: tinky) -> Bool {

test/IRGen/Inputs/ObjectiveC.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public func _convertObjCBoolToBool(_ x: ObjCBool) -> Bool {
4747
}
4848

4949
extension NSObject : Hashable {
50-
@objc open var hashValue: Int { return 0 }
50+
public func hash(into hasher: inout Hasher) {}
5151
}
5252
public func ==(x: NSObject, y: NSObject) -> Bool { return x === y }
5353

test/IRGen/Inputs/usr/include/BridgeTestObjectiveC.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
typedef struct _NSZone NSZone;
44

5+
typedef long NSInteger;
6+
typedef unsigned long NSUInteger;
7+
58
@protocol NSCopying
69
- copyWithZone:(nullable NSZone*)z;
710
@end
@@ -14,6 +17,5 @@ typedef struct _NSZone NSZone;
1417
+ (void) initialize;
1518

1619
@property (readonly, copy) NSString *description;
20+
@property (readonly) NSUInteger hash;
1721
@end
18-
19-
typedef long NSInteger;

test/IRGen/keypaths.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public struct S: Hashable {
1313
public var z: C
1414
public var reabstracted: () -> ()
1515

16-
public var hashValue: Int { get }
16+
public func hash(into hasher: inout Hasher)
1717
public static func ==(_: S, _: S) -> Bool
1818
}
1919
public class C: Hashable {
@@ -24,7 +24,7 @@ public class C: Hashable {
2424

2525
public init()
2626

27-
public var hashValue: Int { get }
27+
public func hash(into hasher: inout Hasher)
2828
public static func ==(_: C, _: C) -> Bool
2929
}
3030

test/IRGen/objc_bridge.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class Bas : NSObject {
191191

192192
deinit { var x = 10 }
193193

194-
override var hashValue: Int { return 0 }
194+
override var hash: Int { return 0 }
195195

196196
@objc func acceptSet(_ set: Set<Bas>) { }
197197
}

test/Inputs/clang-importer-sdk/swift-modules-without-ns/ObjectiveC.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ extension NSObject : Equatable, Hashable {
7777
public var hashValue: Int {
7878
return hash
7979
}
80+
public func hash(into hasher: inout Hasher) {
81+
hasher.combine(hash)
82+
}
8083
}
8184

8285
public func == (lhs: NSObject, rhs: NSObject) -> Bool {

test/Inputs/clang-importer-sdk/swift-modules/ObjectiveC.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public struct Selector : ExpressibleByStringLiteral {
6060
self = sel_registerName(value)
6161
}
6262

63-
public var hashValue: Int {
64-
return ptr.hashValue
63+
public func hash(into hasher: inout Hasher) {
64+
hasher.combine(ptr)
6565
}
6666
}
6767

@@ -88,12 +88,16 @@ public func ~=(x: NSObject, y: NSObject) -> Bool {
8888
}
8989

9090
extension NSObject : Equatable, Hashable {
91-
@objc open var hashValue: Int {
91+
public static func == (lhs: NSObject, rhs: NSObject) -> Bool {
92+
return lhs.isEqual(rhs)
93+
}
94+
95+
public var hashValue: Int {
9296
return hash
9397
}
9498

95-
public static func == (lhs: NSObject, rhs: NSObject) -> Bool {
96-
return lhs.isEqual(rhs)
99+
public func hash(into hasher: inout Hasher) {
100+
hasher.combine(hash)
97101
}
98102
}
99103

0 commit comments

Comments
 (0)