Skip to content

Commit b8f9aa1

Browse files
committed
[SE-0206][stdlib] De-underscore Hashable.hash(into:)
(cherry picked from commit 0fb3e88)
1 parent c8455b1 commit b8f9aa1

25 files changed

+51
-42
lines changed

stdlib/private/StdlibUnittest/MinimalTypes.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public struct MinimalHashableValue : Equatable, Hashable {
145145
return hasher.finalize()
146146
}
147147

148-
public func _hash(into hasher: inout Hasher) {
148+
public func hash(into hasher: inout Hasher) {
149149
MinimalHashableValue.timesHashIntoWasCalled += 1
150150
MinimalHashableValue.hashIntoImpl.value(value, &hasher)
151151
}
@@ -198,7 +198,7 @@ public class MinimalHashableClass : Equatable, Hashable {
198198
return hasher.finalize()
199199
}
200200

201-
public func _hash(into hasher: inout Hasher) {
201+
public func hash(into hasher: inout Hasher) {
202202
MinimalHashableClass.timesHashIntoWasCalled += 1
203203
MinimalHashableClass.hashIntoImpl.value(value, &hasher)
204204
}
@@ -256,7 +256,7 @@ public struct GenericMinimalHashableValue<Wrapped> : Equatable, Hashable {
256256
return hasher.finalize()
257257
}
258258

259-
public func _hash(into hasher: inout Hasher) {
259+
public func hash(into hasher: inout Hasher) {
260260
GenericMinimalHashableValue_timesHashIntoWasCalled += 1
261261
GenericMinimalHashableValue_hashIntoImpl.value(value, &hasher)
262262
}
@@ -312,7 +312,7 @@ public class GenericMinimalHashableClass<Wrapped> : Equatable, Hashable {
312312
return hasher.finalize()
313313
}
314314

315-
public func _hash(into hasher: inout Hasher) {
315+
public func hash(into hasher: inout Hasher) {
316316
GenericMinimalHashableClass_timesHashIntoWasCalled += 1
317317
GenericMinimalHashableClass_hashIntoImpl.value(value, &hasher)
318318
}

stdlib/private/StdlibUnittest/StdlibUnittest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2497,7 +2497,7 @@ public func checkHashable<Instances: Collection>(
24972497
expectTrue(
24982498
(0..<10).contains { hash(x, seed: $0) != hash(y, seed: $0) },
24992499
"""
2500-
_hash(into:) expected to differ, found to match
2500+
hash(into:) expected to differ, found to match
25012501
lhs (at index \(i)): \(x)
25022502
rhs (at index \(j)): \(y)
25032503
""",

stdlib/public/core/AnyHashable.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ internal protocol _AnyHashableBox {
4848
/// no comparison is possible. Otherwise, contains the result of `==`.
4949
func _isEqual(to: _AnyHashableBox) -> Bool?
5050
var _hashValue: Int { get }
51-
func _hash(_into hasher: inout Hasher)
51+
func _hash(into hasher: inout Hasher)
5252

5353
var _base: Any { get }
5454
func _downCastConditional<T>(into result: UnsafeMutablePointer<T>) -> Bool
@@ -90,8 +90,8 @@ internal struct _ConcreteHashableBox<Base : Hashable> : _AnyHashableBox {
9090
}
9191

9292
@inlinable // FIXME(sil-serialize-all)
93-
func _hash(_into hasher: inout Hasher) {
94-
_baseHashable._hash(into: &hasher)
93+
func _hash(into hasher: inout Hasher) {
94+
_baseHashable.hash(into: &hasher)
9595
}
9696

9797
@inlinable // FIXME(sil-serialize-all)
@@ -293,8 +293,8 @@ extension AnyHashable : Hashable {
293293
}
294294

295295
@inlinable // FIXME(sil-serialize-all)
296-
public func _hash(into hasher: inout Hasher) {
297-
_box._hash(_into: &hasher)
296+
public func hash(into hasher: inout Hasher) {
297+
_box._hash(into: &hasher)
298298
}
299299
}
300300

stdlib/public/core/Arrays.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2269,7 +2269,7 @@ extension ${Self}: Hashable where Element: Hashable {
22692269
}
22702270

22712271
@inlinable // FIXME(sil-serialize-all)
2272-
public func _hash(into hasher: inout Hasher) {
2272+
public func hash(into hasher: inout Hasher) {
22732273
hasher.combine(count) // discriminator
22742274
for element in self {
22752275
hasher.combine(element)

stdlib/public/core/Bool.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ extension Bool : Equatable, Hashable {
158158
}
159159

160160
@inlinable // FIXME(sil-serialize-all)
161-
public func _hash(into hasher: inout Hasher) {
161+
public func hash(into hasher: inout Hasher) {
162162
hasher.combine((self ? 1 : 0) as UInt8)
163163
}
164164

stdlib/public/core/CTypes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ extension OpaquePointer: Hashable {
185185
}
186186

187187
@inlinable // FIXME(sil-serialize-all)
188-
public func _hash(into hasher: inout Hasher) {
188+
public func hash(into hasher: inout Hasher) {
189189
hasher.combine(Int(Builtin.ptrtoint_Word(_rawValue)))
190190
}
191191
}

stdlib/public/core/ClosedRange.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ where Bound: Strideable, Bound.Stride: SignedInteger, Bound: Hashable {
174174
}
175175

176176
@inlinable // FIXME(sil-serialize-all)
177-
public func _hash(into hasher: inout Hasher) {
177+
public func hash(into hasher: inout Hasher) {
178178
switch self {
179179
case .inRange(let value):
180180
hasher.combine(0 as Int8)
@@ -401,7 +401,7 @@ extension ClosedRange: Hashable where Bound: Hashable {
401401
}
402402

403403
@inlinable // FIXME(sil-serialize-all)
404-
public func _hash(into hasher: inout Hasher) {
404+
public func hash(into hasher: inout Hasher) {
405405
hasher.combine(lowerBound)
406406
hasher.combine(upperBound)
407407
}

stdlib/public/core/Dictionary.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ extension Dictionary: Hashable where Value: Hashable {
14551455
}
14561456

14571457
@inlinable // FIXME(sil-serialize-all)
1458-
public func _hash(into hasher: inout Hasher) {
1458+
public func hash(into hasher: inout Hasher) {
14591459
var commutativeHash = 0
14601460
for (k, v) in self {
14611461
var elementHasher = Hasher()

stdlib/public/core/DropWhile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ extension LazyDropWhileCollection.Index: Hashable where Base.Index: Hashable {
189189
}
190190

191191
@inlinable // FIXME(sil-serialize-all)
192-
public func _hash(into hasher: inout Hasher) {
192+
public func hash(into hasher: inout Hasher) {
193193
hasher.combine(base)
194194
}
195195
}

stdlib/public/core/Flatten.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ extension FlattenCollection.Index : Hashable
235235
}
236236

237237
@inlinable // FIXME(sil-serialize-all)
238-
public func _hash(into hasher: inout Hasher) {
238+
public func hash(into hasher: inout Hasher) {
239239
hasher.combine(_outer)
240240
hasher.combine(_inner)
241241
}

stdlib/public/core/FloatingPointTypes.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1531,7 +1531,7 @@ extension ${Self} : Hashable {
15311531
}
15321532

15331533
@inlinable // FIXME(sil-serialize-all)
1534-
public func _hash(into hasher: inout Hasher) {
1534+
public func hash(into hasher: inout Hasher) {
15351535
var v = self
15361536
if isZero {
15371537
// To satisfy the axiom that equality implies hash equality, we need to

stdlib/public/core/Hashable.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,23 @@ public protocol Hashable : Equatable {
109109
/// your program. Do not save hash values to use during a future execution.
110110
var hashValue: Int { get }
111111

112-
/// Feed bits to be hashed into the hash function represented by `hasher`.
113-
func _hash(into hasher: inout Hasher)
112+
/// Hash the essential components of this value into the hash function
113+
/// represented by `hasher`, by feeding them into it using its `combine`
114+
/// methods.
115+
///
116+
/// Essential components are precisely those that are compared in the type's
117+
/// implementation of `Equatable`.
118+
///
119+
/// Note that `hash(into:)` doesn't own the hasher passed into it, so it must
120+
/// not call `finalize()` on it. Doing so may become a compile-time error in
121+
/// the future.
122+
func hash(into hasher: inout Hasher)
114123
}
115124

116125
extension Hashable {
117126
@inlinable
118127
@inline(__always)
119-
public func _hash(into hasher: inout Hasher) {
128+
public func hash(into hasher: inout Hasher) {
120129
hasher.combine(self.hashValue)
121130
}
122131
}

stdlib/public/core/Hasher.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public struct Hasher {
304304
@inlinable
305305
@inline(__always)
306306
public mutating func combine<H: Hashable>(_ value: H) {
307-
value._hash(into: &self)
307+
value.hash(into: &self)
308308
}
309309

310310
@effects(releasenone)

stdlib/public/core/Integers.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3708,7 +3708,7 @@ extension ${Self} : Hashable {
37083708
}
37093709

37103710
@inlinable // FIXME(sil-serialize-all)
3711-
public func _hash(into hasher: inout Hasher) {
3711+
public func hash(into hasher: inout Hasher) {
37123712
// FIXME(hasher): To correctly bridge `Set`s/`Dictionary`s containing
37133713
// `AnyHashable`-boxed integers, all integer values are currently required
37143714
// to hash exactly the same way as the corresponding (U)Int64 value. To fix

stdlib/public/core/KeyPath.swift

Lines changed: 3 additions & 3 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+
public func hash(into hasher: inout Hasher) {
5656
return withBuffer {
5757
var buffer = $0
5858
while true {
@@ -446,7 +446,7 @@ internal struct ComputedPropertyID: Hashable {
446446
}
447447

448448
@inlinable // FIXME(sil-serialize-all)
449-
public func _hash(into hasher: inout Hasher) {
449+
public func hash(into hasher: inout Hasher) {
450450
hasher.combine(value)
451451
hasher.combine(isStoredProperty)
452452
hasher.combine(isTableOffset)
@@ -579,7 +579,7 @@ internal enum KeyPathComponent: Hashable {
579579
}
580580

581581
@inlinable // FIXME(sil-serialize-all)
582-
internal func _hash(into hasher: inout Hasher) {
582+
internal func hash(into hasher: inout Hasher) {
583583
var hasher = hasher
584584
func appendHashFromArgument(
585585
_ argument: KeyPathComponent.ArgumentRef?

stdlib/public/core/NewtypeWrapper.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extension _SwiftNewtypeWrapper where Self: Hashable, Self.RawValue : Hashable {
2222
}
2323

2424
@inlinable // FIXME(sil-serialize-all)
25-
public func _hash(into hasher: inout Hasher) {
25+
public func hash(into hasher: inout Hasher) {
2626
hasher.combine(rawValue)
2727
}
2828
}

stdlib/public/core/Optional.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ extension Optional: Hashable where Wrapped: Hashable {
422422
}
423423

424424
@inlinable // FIXME(sil-serialize-all)
425-
public func _hash(into hasher: inout Hasher) {
425+
public func hash(into hasher: inout Hasher) {
426426
switch self {
427427
case .none:
428428
hasher.combine(0 as UInt8)

stdlib/public/core/PrefixWhile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ extension LazyPrefixWhileCollection.Index: Hashable where Base.Index: Hashable {
208208
}
209209

210210
@inlinable // FIXME(sil-serialize-all)
211-
public func _hash(into hasher: inout Hasher) {
211+
public func hash(into hasher: inout Hasher) {
212212
switch _value {
213213
case .index(let value):
214214
hasher.combine(value)

stdlib/public/core/Range.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ extension Range: Hashable where Bound: Hashable {
411411
}
412412

413413
@inlinable // FIXME(sil-serialize-all)
414-
public func _hash(into hasher: inout Hasher) {
414+
public func hash(into hasher: inout Hasher) {
415415
hasher.combine(lowerBound)
416416
hasher.combine(upperBound)
417417
}

stdlib/public/core/Reverse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ extension ReversedCollection.Index: Hashable where Base.Index: Hashable {
197197
}
198198

199199
@inlinable // FIXME(sil-serialize-all)
200-
public func _hash(into hasher: inout Hasher) {
200+
public func hash(into hasher: inout Hasher) {
201201
hasher.combine(base)
202202
}
203203
}

stdlib/public/core/Set.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ extension Set: Hashable {
497497
}
498498

499499
@inlinable // FIXME(sil-serialize-all)
500-
public func _hash(into hasher: inout Hasher) {
500+
public func hash(into hasher: inout Hasher) {
501501
var hash = 0
502502
for member in self {
503503
hash ^= _hashValue(for: member)

stdlib/public/core/StringHashable.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ extension _SmallUTF8String {
8282
extension _StringGuts {
8383
@effects(releasenone) // FIXME: Is this valid in the opaque case?
8484
@usableFromInline
85-
internal func _hash(into hasher: inout Hasher) {
85+
internal func hash(into hasher: inout Hasher) {
8686
if _isSmall {
8787
_smallUTF8String.hash(into: &hasher)
8888
return
@@ -102,7 +102,7 @@ extension _StringGuts {
102102

103103
@effects(releasenone) // FIXME: Is this valid in the opaque case?
104104
@usableFromInline
105-
internal func _hash(_ range: Range<Int>, into hasher: inout Hasher) {
105+
internal func hash(_ range: Range<Int>, into hasher: inout Hasher) {
106106
if _isSmall {
107107
_smallUTF8String[range].hash(into: &hasher)
108108
return
@@ -132,8 +132,8 @@ extension String : Hashable {
132132
}
133133

134134
@inlinable
135-
public func _hash(into hasher: inout Hasher) {
136-
_guts._hash(into: &hasher)
135+
public func hash(into hasher: inout Hasher) {
136+
_guts.hash(into: &hasher)
137137
}
138138
}
139139

@@ -144,7 +144,7 @@ extension StringProtocol {
144144
}
145145

146146
@inlinable
147-
public func _hash(into hasher: inout Hasher) {
148-
_wholeString._guts._hash(_encodedOffsetRange, into: &hasher)
147+
public func hash(into hasher: inout Hasher) {
148+
_wholeString._guts.hash(_encodedOffsetRange, into: &hasher)
149149
}
150150
}

stdlib/public/core/UnsafePointer.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ extension ${Self}: Hashable {
908908
}
909909

910910
@inlinable // FIXME(sil-serialize-all)
911-
public func _hash(into hasher: inout Hasher) {
911+
public func hash(into hasher: inout Hasher) {
912912
hasher.combine(Int(bitPattern: self))
913913
}
914914
}

test/Prototypes/DoubleWidth.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ extension DoubleWidth : Hashable {
148148
}
149149

150150
@inlinable // FIXME(sil-serialize-all)
151-
public func _hash(into hasher: inout Hasher) {
151+
public func hash(into hasher: inout Hasher) {
152152
hasher.combine(low)
153153
hasher.combine(high)
154154
}

test/SILGen/objc_bridging_any.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,5 +697,5 @@ class SwiftAnyEnjoyer: NSIdLover, NSIdLoving {
697697
// CHECK-LABEL: sil_witness_table shared [serialized] GenericOption: Hashable module objc_generics {
698698
// CHECK-NEXT: base_protocol Equatable: GenericOption: Equatable module objc_generics
699699
// CHECK-NEXT: method #Hashable.hashValue!getter.1: {{.*}} : @$SSo13GenericOptionas8HashableSCsACP9hashValueSivgTW
700-
// CHECK-NEXT: method #Hashable._hash!1: {{.*}} : @$SSo13GenericOptionas8HashableSCsACP5_hash4intoys6HasherVz_tFTW
700+
// CHECK-NEXT: method #Hashable.hash!1: {{.*}} : @$SSo13GenericOptionas8HashableSCsACP4hash4intoys6HasherVz_tFTW
701701
// CHECK-NEXT: }

0 commit comments

Comments
 (0)