[swift-evolution] Pitch: Automatically deriving Equatable/Hashable for more value types

Xiaodi Wu xiaodi.wu at gmail.com
Mon May 15 18:08:34 CDT 2017


Oh, and to add, the details of hashing may not need to be fully written
out, but it would be nice to mention that it will follow existing standard
library practice--or, if not, then why, and also any implications related
to hash collision security issues. Moreover, it may be worth mentioning
that the synthesized method involves mixing the _hashes_ of members and not
their memory representation--though it may seem obvious.


On Mon, May 15, 2017 at 17:21 Tony Allevato via swift-evolution <
swift-evolution at swift.org> wrote:

> Yes—the PR of the proposal is here:
> https://github.com/apple/swift-evolution/pull/706
>
> It needs to be updated slightly—I'll remove the references to the
> "multiplicative hash function" recommendation because I ended up using the
> existing _mixInt and xor, which is how the standard library implements its
> Collection hashValues. (The proposal probably really doesn't need to state
> anything about the hash function used, and its entirely an implementation
> detail.)
>
>
> On Mon, May 15, 2017 at 3:18 PM Andrew Bennett <cacoyi at gmail.com> wrote:
>
>> Nice work Tony! Is this proposal up for PR on swift-evolution as well?
>>
>> On Tue, 16 May 2017 at 7:30 am, Tony Allevato <tony.allevato at gmail.com>
>> wrote:
>>
>>> Just to update everyone on the thread—it took a little longer than I'd
>>> hoped to get the kinks out, but I finally have the implementation up as a
>>> PR: https://github.com/apple/swift/pull/9619
>>>
>>> Hopefully there's still enough time to get the proposal reviewed, make
>>> any changes needed, and get this into Swift 4!
>>>
>>>
>>> On Tue, May 9, 2017 at 10:27 PM Brent Royal-Gordon <
>>> brent at architechies.com> wrote:
>>>
>>>> On May 9, 2017, at 3:53 PM, Tony Allevato via swift-evolution <
>>>> swift-evolution at swift.org> wrote:
>>>>
>>>> Likewise, proposing a new public addition to the standard library would
>>>> inspire far more design discussion than I believe we have time for if we
>>>> want this to make Swift 4. :)
>>>>
>>>>
>>>> Agreed. What I would do here is add an `_combineHashes` function (or
>>>> `Hashable` extension method, or whatever is most convenient) to the
>>>> standard library in Swift 4, have your compiler magic feature use it, and
>>>> defer the name-and-interface discussion until Swift 5.
>>>>
>>>> --
>>>> Brent Royal-Gordon
>>>> Architechies
>>>>
>>>> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170515/6715df49/attachment.html>


More information about the swift-evolution mailing list