Skip to content

Commit 5f9bf11

Browse files
authored
Merge pull request #16154 from lorentey/hash-into-everywhere
2 parents 3f94809 + bae6f52 commit 5f9bf11

22 files changed

+53
-186
lines changed

stdlib/public/core/Arrays.swift.gyb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,11 +2263,6 @@ extension ${Self} : Equatable where Element : Equatable {
22632263
}
22642264

22652265
extension ${Self}: Hashable where Element: Hashable {
2266-
@inlinable // FIXME(sil-serialize-all)
2267-
public var hashValue: Int {
2268-
return _hashValue(for: self)
2269-
}
2270-
22712266
@inlinable // FIXME(sil-serialize-all)
22722267
public func hash(into hasher: inout Hasher) {
22732268
hasher.combine(count) // discriminator

stdlib/public/core/Bool.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,6 @@ public // COMPILER_INTRINSIC
145145
func _getBool(_ v: Builtin.Int1) -> Bool { return Bool(v) }
146146

147147
extension Bool : Equatable, Hashable {
148-
/// The hash value for the Boolean value.
149-
///
150-
/// Two values that are equal always have equal hash values.
151-
///
152-
/// - Note: The hash value is not guaranteed to be stable across different
153-
/// invocations of the same program. Do not persist the hash value across
154-
/// program runs.
155-
@inlinable // FIXME(sil-serialize-all)
156-
public var hashValue: Int {
157-
return _hashValue(for: self)
158-
}
159-
160148
@inlinable // FIXME(sil-serialize-all)
161149
public func hash(into hasher: inout Hasher) {
162150
hasher.combine((self ? 1 : 0) as UInt8)

stdlib/public/core/CTypes.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,6 @@ extension OpaquePointer: Equatable {
174174
}
175175

176176
extension OpaquePointer: Hashable {
177-
/// The pointer's hash value.
178-
///
179-
/// The hash value is not guaranteed to be stable across different
180-
/// invocations of the same program. Do not persist the hash value across
181-
/// program runs.
182-
@inlinable // FIXME(sil-serialize-all)
183-
public var hashValue: Int {
184-
return _hashValue(for: self)
185-
}
186-
187177
@inlinable // FIXME(sil-serialize-all)
188178
public func hash(into hasher: inout Hasher) {
189179
hasher.combine(Int(Builtin.ptrtoint_Word(_rawValue)))

stdlib/public/core/Character.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -477,14 +477,11 @@ extension Character : Comparable {
477477
}
478478

479479
extension Character: Hashable {
480-
/// The character's hash value.
481-
///
482-
/// Hash values are not guaranteed to be equal across different executions of
483-
/// your program. Do not save hash values to use during a future execution.
484-
@inlinable // FIXME(sil-serialize-all)
485-
public var hashValue: Int {
480+
// not @inlinable (performance)
481+
@effects(releasenone)
482+
public func hash(into hasher: inout Hasher) {
486483
// FIXME(performance): constructing a temporary string is extremely
487484
// wasteful and inefficient.
488-
return String(self).hashValue
485+
hasher.combine(String(self))
489486
}
490487
}

stdlib/public/core/ClosedRange.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,6 @@ extension ClosedRange.Index : Comparable {
168168

169169
extension ClosedRange.Index: Hashable
170170
where Bound: Strideable, Bound.Stride: SignedInteger, Bound: Hashable {
171-
@inlinable // FIXME(sil-serialize-all)
172-
public var hashValue: Int {
173-
return _hashValue(for: self)
174-
}
175-
176171
@inlinable // FIXME(sil-serialize-all)
177172
public func hash(into hasher: inout Hasher) {
178173
switch self {
@@ -395,11 +390,6 @@ extension ClosedRange: Equatable {
395390
}
396391

397392
extension ClosedRange: Hashable where Bound: Hashable {
398-
@inlinable // FIXME(sil-serialize-all)
399-
public var hashValue: Int {
400-
return _hashValue(for: self)
401-
}
402-
403393
@inlinable // FIXME(sil-serialize-all)
404394
public func hash(into hasher: inout Hasher) {
405395
hasher.combine(lowerBound)

stdlib/public/core/Codable.swift.gyb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,11 @@ public struct CodingUserInfoKey : RawRepresentable, Equatable, Hashable {
10941094
public var hashValue: Int {
10951095
return self.rawValue.hashValue
10961096
}
1097+
1098+
@inlinable // FIXME(sil-serialize-all)
1099+
public func hash(into hasher: inout Hasher) {
1100+
hasher.combine(self.rawValue)
1101+
}
10971102
}
10981103

10991104
//===----------------------------------------------------------------------===//

stdlib/public/core/Dictionary.swift

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,11 +1449,6 @@ extension Dictionary: Equatable where Value: Equatable {
14491449
}
14501450

14511451
extension Dictionary: Hashable where Value: Hashable {
1452-
@inlinable // FIXME(sil-serialize-all)
1453-
public var hashValue: Int {
1454-
return _hashValue(for: self)
1455-
}
1456-
14571452
@inlinable // FIXME(sil-serialize-all)
14581453
public func hash(into hasher: inout Hasher) {
14591454
var commutativeHash = 0
@@ -4334,18 +4329,28 @@ extension Dictionary.Index {
43344329

43354330
@inlinable // FIXME(sil-serialize-all)
43364331
public var hashValue: Int {
4332+
return _hashValue(for: self)
4333+
}
4334+
4335+
@inlinable // FIXME(sil-serialize-all)
4336+
public func hash(into hasher: inout Hasher) {
4337+
#if _runtime(_ObjC)
43374338
if _fastPath(_guaranteedNative) {
4338-
return _nativeIndex.offset
4339+
hasher.combine(0 as UInt8)
4340+
hasher.combine(_nativeIndex.offset)
4341+
return
43394342
}
4340-
43414343
switch _value {
43424344
case ._native(let nativeIndex):
4343-
return nativeIndex.offset
4344-
#if _runtime(_ObjC)
4345+
hasher.combine(0 as UInt8)
4346+
hasher.combine(nativeIndex.offset)
43454347
case ._cocoa(let cocoaIndex):
4346-
return cocoaIndex.currentKeyIndex
4347-
#endif
4348+
hasher.combine(1 as UInt8)
4349+
hasher.combine(cocoaIndex.currentKeyIndex)
43484350
}
4351+
#else
4352+
hasher.combine(_nativeIndex.offset)
4353+
#endif
43494354
}
43504355
}
43514356

stdlib/public/core/Flatten.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,6 @@ extension FlattenCollection.Index : Comparable {
229229

230230
extension FlattenCollection.Index : Hashable
231231
where Base.Index : Hashable, Base.Element.Index : Hashable {
232-
@inlinable // FIXME(sil-serialize-all)
233-
public var hashValue: Int {
234-
return _hashValue(for: self)
235-
}
236-
237232
@inlinable // FIXME(sil-serialize-all)
238233
public func hash(into hasher: inout Hasher) {
239234
hasher.combine(_outer)

stdlib/public/core/FloatingPointTypes.swift.gyb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,15 +1521,6 @@ extension ${Self} : _ExpressibleByBuiltinFloatLiteral {
15211521
% end
15221522

15231523
extension ${Self} : Hashable {
1524-
/// The number's hash value.
1525-
///
1526-
/// Hash values are not guaranteed to be equal across different executions of
1527-
/// your program. Do not save hash values to use during a future execution.
1528-
@inlinable // FIXME(sil-serialize-all)
1529-
public var hashValue: Int {
1530-
return _hashValue(for: self)
1531-
}
1532-
15331524
@inlinable // FIXME(sil-serialize-all)
15341525
public func hash(into hasher: inout Hasher) {
15351526
var v = self

stdlib/public/core/Integers.swift.gyb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3694,19 +3694,6 @@ ${assignmentOperatorComment(x.operator, True)}
36943694
%# end of concrete type: ${Self}
36953695

36963696
extension ${Self} : Hashable {
3697-
/// The integer's hash value.
3698-
///
3699-
/// The hash value is not guaranteed to be stable across different
3700-
/// invocations of the same program. Do not persist the hash value across
3701-
/// program runs.
3702-
@inlinable // FIXME(sil-serialize-all)
3703-
public var hashValue: Int {
3704-
@inline(__always)
3705-
get {
3706-
return _hashValue(for: self)
3707-
}
3708-
}
3709-
37103697
@inlinable // FIXME(sil-serialize-all)
37113698
public func hash(into hasher: inout Hasher) {
37123699
// FIXME(hasher): To correctly bridge `Set`s/`Dictionary`s containing

stdlib/public/core/KeyPath.swift

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class AnyKeyPath: Hashable, _AppendKeyPath {
5252
}
5353

5454
@inlinable // FIXME(sil-serialize-all)
55-
public func hash(into hasher: inout Hasher) {
55+
final public func hash(into hasher: inout Hasher) {
5656
return withBuffer {
5757
var buffer = $0
5858
while true {
@@ -441,12 +441,7 @@ internal struct ComputedPropertyID: Hashable {
441441
}
442442

443443
@inlinable // FIXME(sil-serialize-all)
444-
internal var hashValue: Int {
445-
return _hashValue(for: self)
446-
}
447-
448-
@inlinable // FIXME(sil-serialize-all)
449-
public func hash(into hasher: inout Hasher) {
444+
internal func hash(into hasher: inout Hasher) {
450445
hasher.combine(value)
451446
hasher.combine(isStoredProperty)
452447
hasher.combine(isTableOffset)
@@ -573,11 +568,6 @@ internal enum KeyPathComponent: Hashable {
573568
}
574569
}
575570

576-
@inlinable // FIXME(sil-serialize-all)
577-
internal var hashValue: Int {
578-
return _hashValue(for: self)
579-
}
580-
581571
@inlinable // FIXME(sil-serialize-all)
582572
internal func hash(into hasher: inout Hasher) {
583573
var hasher = hasher

stdlib/public/core/ObjectIdentifier.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,9 @@ extension ObjectIdentifier: Comparable {
8484
}
8585

8686
extension ObjectIdentifier: Hashable {
87-
// FIXME: Better hashing algorithm
88-
/// The identifier's hash value.
89-
///
90-
/// The hash value is not guaranteed to be stable across different
91-
/// invocations of the same program. Do not persist the hash value across
92-
/// program runs.
9387
@inlinable // FIXME(sil-serialize-all)
94-
public var hashValue: Int {
95-
return Int(Builtin.ptrtoint_Word(_value))
88+
public func hash(into hasher: inout Hasher) {
89+
hasher.combine(Int(Builtin.ptrtoint_Word(_value)))
9690
}
9791
}
9892

stdlib/public/core/Optional.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -410,17 +410,6 @@ extension Optional : Equatable where Wrapped : Equatable {
410410
}
411411

412412
extension Optional: Hashable where Wrapped: Hashable {
413-
/// The hash value for the optional instance.
414-
///
415-
/// Two optionals that are equal will always have equal hash values.
416-
///
417-
/// Hash values are not guaranteed to be equal across different executions of
418-
/// your program. Do not save hash values to use during a future execution.
419-
@inlinable // FIXME(sil-serialize-all)
420-
public var hashValue: Int {
421-
return _hashValue(for: self)
422-
}
423-
424413
@inlinable // FIXME(sil-serialize-all)
425414
public func hash(into hasher: inout Hasher) {
426415
switch self {

stdlib/public/core/PrefixWhile.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,6 @@ extension LazyPrefixWhileCollection.Index: Comparable {
202202
}
203203

204204
extension LazyPrefixWhileCollection.Index: Hashable where Base.Index: Hashable {
205-
@inlinable // FIXME(sil-serialize-all)
206-
public var hashValue: Int {
207-
return _hashValue(for: self)
208-
}
209-
210205
@inlinable // FIXME(sil-serialize-all)
211206
public func hash(into hasher: inout Hasher) {
212207
switch _value {

stdlib/public/core/Range.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,6 @@ extension Range: Equatable {
405405
}
406406

407407
extension Range: Hashable where Bound: Hashable {
408-
@inlinable // FIXME(sil-serialize-all)
409-
public var hashValue: Int {
410-
return _hashValue(for: self)
411-
}
412-
413408
@inlinable // FIXME(sil-serialize-all)
414409
public func hash(into hasher: inout Hasher) {
415410
hasher.combine(lowerBound)

stdlib/public/core/Reverse.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,6 @@ extension ReversedCollection.Index: Comparable {
191191
}
192192

193193
extension ReversedCollection.Index: Hashable where Base.Index: Hashable {
194-
@inlinable // FIXME(sil-serialize-all)
195-
public var hashValue: Int {
196-
return base.hashValue
197-
}
198-
199194
@inlinable // FIXME(sil-serialize-all)
200195
public func hash(into hasher: inout Hasher) {
201196
hasher.combine(base)

stdlib/public/core/Set.swift

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -484,20 +484,9 @@ extension Set: Equatable {
484484
}
485485

486486
extension Set: Hashable {
487-
/// The hash value for the set.
488-
///
489-
/// Two sets that are equal will always have equal hash values.
490-
///
491-
/// Hash values are not guaranteed to be equal across different executions of
492-
/// your program. Do not save hash values to use during a future execution.
493-
@inlinable // FIXME(sil-serialize-all)
494-
public var hashValue: Int {
495-
// FIXME(ABI)#177: <rdar://problem/18915294> Cache Set<T> hashValue
496-
return _hashValue(for: self)
497-
}
498-
499487
@inlinable // FIXME(sil-serialize-all)
500488
public func hash(into hasher: inout Hasher) {
489+
// FIXME(ABI)#177: <rdar://problem/18915294> Cache Set<T> hashValue
501490
var hash = 0
502491
for member in self {
503492
hash ^= _hashValue(for: member)
@@ -3662,18 +3651,28 @@ extension Set.Index {
36623651

36633652
@inlinable // FIXME(sil-serialize-all)
36643653
public var hashValue: Int {
3654+
return _hashValue(for: self)
3655+
}
3656+
3657+
@inlinable // FIXME(sil-serialize-all)
3658+
public func hash(into hasher: inout Hasher) {
3659+
#if _runtime(_ObjC)
36653660
if _fastPath(_guaranteedNative) {
3666-
return _nativeIndex.offset
3661+
hasher.combine(0 as UInt8)
3662+
hasher.combine(_nativeIndex.offset)
3663+
return
36673664
}
3668-
36693665
switch _value {
36703666
case ._native(let nativeIndex):
3671-
return nativeIndex.offset
3672-
#if _runtime(_ObjC)
3667+
hasher.combine(0 as UInt8)
3668+
hasher.combine(nativeIndex.offset)
36733669
case ._cocoa(let cocoaIndex):
3674-
return cocoaIndex.currentKeyIndex
3675-
#endif
3670+
hasher.combine(1 as UInt8)
3671+
hasher.combine(cocoaIndex.currentKeyIndex)
36763672
}
3673+
#else
3674+
hasher.combine(_nativeIndex.offset)
3675+
#endif
36773676
}
36783677
}
36793678

stdlib/public/core/StringHashable.swift

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,27 +122,13 @@ extension _StringGuts {
122122
}
123123

124124
extension String : Hashable {
125-
/// The string's hash value.
126-
///
127-
/// Hash values are not guaranteed to be equal across different executions of
128-
/// your program. Do not save hash values to use during a future execution.
129-
@inlinable
130-
public var hashValue: Int {
131-
return _hashValue(for: self)
132-
}
133-
134125
@inlinable
135126
public func hash(into hasher: inout Hasher) {
136127
_guts.hash(into: &hasher)
137128
}
138129
}
139130

140131
extension StringProtocol {
141-
@inlinable
142-
public var hashValue : Int {
143-
return _hashValue(for: self)
144-
}
145-
146132
@inlinable
147133
public func hash(into hasher: inout Hasher) {
148134
_wholeString._guts.hash(_encodedOffsetRange, into: &hasher)

0 commit comments

Comments
 (0)