Default implementation of Hashable in Swift 4.0

In Swift 4.0 structs whose stored properties are all

Hashable
compiler provides the synthesized implementation of `hashValue`. How does it implemented? What hash function it uses? Where can I find this information by myself (I know that Swift is open-source)?
Answered by kelin in 330044022

Ok, so the answer I got there (https://forums.swift.org/t/how-is-synthesized-hashable-implemented/15960?u=kelin) is: SipHash-1-3 for Swift 4.2. I asked this question becasue I wanted to make my own hash implementation and I think using the same function as the default one would be a good solution.

I think you're referring to the implementation of this proposal:


github.com/apple/swift-evolution/blob/master/proposals/0185-synthesize-equatable-hashable.md


which says it was implemented in 4.1.

Oh, yes, sure. Didn't notice how Xcode was updated to Swift 4.1.

Note that Hashable conformance synthesis changed dramatically in Swift 4.2:


github.com/apple/swift-evolution/blob/master/proposals/0206-hashable-enhancements.md


I see that you asked about the implementation over on forums.swift.org. That's good, but remember that you likely won't get an answer about the 4.1 implementation, if that's what you were looking for specifically. (The old "hashValue" requirement is deprecated in 4.2.)

Accepted Answer

Ok, so the answer I got there (https://forums.swift.org/t/how-is-synthesized-hashable-implemented/15960?u=kelin) is: SipHash-1-3 for Swift 4.2. I asked this question becasue I wanted to make my own hash implementation and I think using the same function as the default one would be a good solution.

Default implementation of Hashable in Swift 4.0
 
 
Q