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.
or, if you would like to keep your feedback private, directly to the review manager.
What goes into a review?
The goal of the review process is to improve the proposal under review through constructive criticism and contribute to the direction of Swift. When writing your review, here are some questions you might want to answer in your review:
* What is your evaluation of the proposal?
* Is the problem being addressed significant enough to warrant a change to Swift?
* Does this proposal fit well with the feel and direction of Swift?
* If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
* How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
More information about the Swift evolution process is available at
This proposal looks great to me. I only have one nitpick: it looks like there's a '_Hashable' protocol used in the Dictionary extension to get around the limit on generic subscripts. Swift has managed to remove most (all?) underscored protocols from public APIs, so I would just suggest that the implementation consider an alternate name that isn't underscored. Something like 'HashableBase' would still imply that the protocol is more of an implementation detail than a useful protocol on its own.
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.
Looks great, and quite aside from its use in bridged dictionaries, I'm sure users will happily abuse it for heterogeneous comparisons.
My only comment is this: Is the `base` property following some convention established by other type-erased wrappers? If not, I would suggest either `any`, `value`, or `wrapped`; `base` seems to suggest something like a base class, which is not what's going on here.
···
On Jul 23, 2016, at 3:26 PM, Chris Lattner <clattner@apple.com> wrote:
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.
I’d only +1 this proposal if we can perform an implicit conversion. From SE-0116:
The user model for this type would ideally align with our long-term goal of supporting Hashable existentials directly, so the type deserves some short-term compiler support to help us get there.
I read that as meaning that the interface should look as close as possible to what using a raw “Hashable” would look like, and that some short-term complier magic to achieve that would be acceptable. As far as that goes:
- unwrapping is functionally equivalent (upcasting from Any today, in the future from Hashable, but when upcasting all that matters is the destination type so NFC)
- wrapping is too verbose:
/// let descriptions: [AnyHashable : Any] = [
/// AnyHashable(""): "emoji",
/// AnyHashable(42): "an Int",
/// AnyHashable(Int8(43)): "an Int8",
/// AnyHashable(Set(["a", "b"])): "a set of strings"
/// ]
That would be a big regression in readability, IMO. Previously, you could declare those keys without the “AnyHashable” wrapper, and the bridging magic would turn Int -> NSNumber because that’s the way to make an Int conform to NSObject. It should be possible to teach the compiler how to turn a Hashable in to an AnyHashable implicitly.
But yeah, if we can do an implicit conversion, it’s a from me
Karl
···
On 24 Jul 2016, at 00:26, Chris Lattner via swift-evolution <swift-evolution@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.
or, if you would like to keep your feedback private, directly to the review manager.
What goes into a review?
The goal of the review process is to improve the proposal under review through constructive criticism and contribute to the direction of Swift. When writing your review, here are some questions you might want to answer in your review:
* What is your evaluation of the proposal?
* Is the problem being addressed significant enough to warrant a change to Swift?
* Does this proposal fit well with the feel and direction of Swift?
* If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
* How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
More information about the Swift evolution process is available at
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
···
On Mon, Jul 25, 2016 at 1:34 PM, Pyry Jahkola via swift-evolution <swift-evolution@swift.org> wrote:
On 24 Jul 2016, at 01:26, Chris Lattner via swift-evolution > <swift-evolution@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.
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`).
I don't see a benefit for this. Nobody should be using _Hashable.
Adding it as a non-underscored protocol increases API surface for no
benefit. _Hashable is slated for removal as soon as we get the
necessary compiler features.
Dmitri
···
On Mon, Jul 25, 2016 at 1:12 PM, Nate Cook via swift-evolution <swift-evolution@swift.org> wrote:
This proposal looks great to me. I only have one nitpick: it looks like there's a '_Hashable' protocol used in the Dictionary extension to get around the limit on generic subscripts. Swift has managed to remove most (all?) underscored protocols from public APIs, so I would just suggest that the implementation consider an alternate name that isn't underscored. Something like 'HashableBase' would still imply that the protocol is more of an implementation detail than a useful protocol on its own.
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.)