[swift-evolution] [Review] SE-0131: Add AnyHashable to the standard library

Dmitri Gribenko gribozavr at gmail.com
Mon Jul 25 23:16:57 CDT 2016


On Mon, Jul 25, 2016 at 1:34 PM, Pyry Jahkola via swift-evolution
<swift-evolution at swift.org> wrote:
>
> On 24 Jul 2016, at 01:26, Chris Lattner via swift-evolution
> <swift-evolution at swift.org> wrote:
>
> Hello Swift community,
>
> The review of "SE-0131: Add AnyHashable to the standard library" begins now
> and runs through July 25.  This proposal is a bit unusual, since it is a
> late additive proposal.  The reason we need to do something here is as a
> critical part of "SE-0116: Import Objective-C id as Swift Any type”,
> enabling importing untyped NSDictionary's and NSSet’s properly.  The core
> team considers this already conceptually approved for Swift 3 as part of
> SE-0116, but would greatly appreciate feedback on the details of the
> proposed design.
>
> The proposal is available here:
>
> https://github.com/apple/swift-evolution/blob/master/proposals/0131-anyhashable.md
>
> * What is your evaluation of the proposal?
>
>
> +1, this is a nice addition, and useful at times.
>
> There's one very obscure gotcha with AnyHashable that subclass instances of
> a Hashable base class should be cast to the base type before wrapping into
> AnyHashable, otherwise such wrapped values may break the equivalence law of
> symmetry (`a == b` iff `b == a`).

The implementation that I have does not suffer from this issue.  (The
initializer of AnyHashable walks the superclass chain and upcasts the
value to the correct type.)

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/


More information about the swift-evolution mailing list