Skip to content

Commit 71d8e4d

Browse files
authored
Merge pull request swiftlang#1924 from hartbit/hash-value-warnings
Resolve Hashable related warnings
2 parents 09cb208 + ddadb05 commit 71d8e4d

File tree

6 files changed

+14
-44
lines changed

6 files changed

+14
-44
lines changed

Sources/Basic/KeyedPair.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public struct KeyedPair<T, K: Hashable>: Hashable {
4242
self.key = key
4343
}
4444

45-
public var hashValue: Int {
46-
return key.hashValue
45+
public func hash(into hasher: inout Hasher) {
46+
hasher.combine(key)
4747
}
4848
}
4949
public func ==<T, K>(lhs: KeyedPair<T, K>, rhs: KeyedPair<T, K>) -> Bool {

Sources/Basic/ObjectIdentifierProtocol.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
public protocol ObjectIdentifierProtocol: class, Hashable {}
1515

1616
extension ObjectIdentifierProtocol {
17-
public var hashValue: Int {
18-
return ObjectIdentifier(self).hashValue
17+
public func hash(into hasher: inout Hasher) {
18+
hasher.combine(ObjectIdentifier(self))
1919
}
2020

2121
public static func == (lhs: Self, rhs: Self) -> Bool {

Sources/PackageGraph/DependencyResolver.swift

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,6 @@ public enum VersionSetSpecifier: Hashable, CustomStringConvertible {
109109
}
110110
}
111111

112-
//FIXME: Remove in 4.2
113-
public var hashValue: Int {
114-
switch (self) {
115-
case .any:
116-
return 0xB58D
117-
118-
case .empty:
119-
return 0x7121
120-
121-
case .range(let range):
122-
return 0x4CF3 ^ (range.lowerBound.hashValue &* 31) ^ range.upperBound.hashValue
123-
124-
case .exact(let version):
125-
return 0xD04F ^ version.hashValue
126-
}
127-
}
128-
129112
/// Check if the set contains a version.
130113
public func contains(_ version: Version) -> Bool {
131114
switch self {
@@ -417,15 +400,6 @@ public struct PackageContainerConstraintSet<C: PackageContainer>: Collection, Ha
417400
return constraints[identifier] ?? .versionSet(.any)
418401
}
419402

420-
//FIXME: Remove in 4.2? Perhaps?
421-
public var hashValue: Int {
422-
var result = 0
423-
for c in self.constraints {
424-
result ^= c.key.hashValue &* 0x62F ^ c.value.hashValue
425-
}
426-
return result
427-
}
428-
429403
/// Create a constraint set by merging the `requirement` for container `identifier`.
430404
///
431405
/// - Returns: The new set, or nil the resulting set is unsatisfiable.
@@ -839,8 +813,9 @@ public class DependencyResolver<
839813
let container: Container
840814
let allConstraints: ConstraintSet
841815

842-
var hashValue: Int {
843-
return container.identifier.hashValue ^ allConstraints.hashValue
816+
func hash(into hasher: inout Hasher) {
817+
hasher.combine(container.identifier)
818+
hasher.combine(allConstraints)
844819
}
845820

846821
static func ==(lhs: ResolveSubtreeCacheKey, rhs: ResolveSubtreeCacheKey) -> Bool {

Sources/PackageModel/Package.swift

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,7 @@ extension Package: CustomStringConvertible {
109109
}
110110
}
111111

112-
extension Package: Hashable, Equatable {
113-
public var hashValue: Int { return ObjectIdentifier(self).hashValue }
114-
115-
public static func == (lhs: Package, rhs: Package) -> Bool {
116-
return ObjectIdentifier(lhs) == ObjectIdentifier(rhs)
117-
}
112+
extension Package: ObjectIdentifierProtocol {
118113
}
119114

120115
/// A package reference.
@@ -163,8 +158,8 @@ public struct PackageReference: JSONMappable, JSONSerializable, CustomStringConv
163158
return lhs.identity == rhs.identity
164159
}
165160

166-
public var hashValue: Int {
167-
return identity.hashValue
161+
public func hash(into hasher: inout Hasher) {
162+
hasher.combine(identity)
168163
}
169164

170165
public init(json: JSON) throws {

Sources/Utility/ArgumentParser.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ protocol ArgumentProtocol: Hashable {
290290
extension ArgumentProtocol {
291291
// MARK: - Conformance for Hashable
292292

293-
public var hashValue: Int {
294-
return name.hashValue
293+
public func hash(into hasher: inout Hasher) {
294+
return hasher.combine(name)
295295
}
296296

297297
public static func == (_ lhs: Self, _ rhs: Self) -> Bool {

Sources/Xcodeproj/XcodeProjectModelSerialization.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,8 @@ fileprivate class PropertyListSerializer {
466466
self.object = object
467467
}
468468

469-
var hashValue: Int {
470-
return ObjectIdentifier(object).hashValue
469+
func hash(into hasher: inout Hasher) {
470+
hasher.combine(ObjectIdentifier(object))
471471
}
472472

473473
static func == (lhs: SerializedObjectRef, rhs: SerializedObjectRef) -> Bool {

0 commit comments

Comments
 (0)