-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[ObjectiveC] Selector: Synthesize Equatable and Hashable #20872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@swift-ci please test |
Build failed |
Faster because it's inlinable, or faster because the compiler-synthesized definition is going to do extra work? Because if we're just concerned about the latter, we could reasonably special-case single-element structs. |
@jrose-apple The compiler-synthesized The compiler can't really do a better job at synthesizing (I'm much more concerned about moving the remaining parts of stdlib away from |
If we could still make ABI-breaking changes, removing |
Update: Ah, I see what you mean! We could safely remove the |
The difference is that it won't be inlinable, though. |
Luckily, the current definition isn't inlinable either. (This is probably fine -- it's a non-generic struct.) |
Oh, I'm getting your PRs mixed up. :-) All right, great! |
dc44cc7
to
33bfa77
Compare
Done! @swift-ci smoke test |
…and then the next step is that you don't need |
Hah, you're right! It's so rare we can use Hashable synthesis in the stdlib, my poor brain can't handle it. :-) |
Hm, removing the The equality operator currently calls |
It looks like |
OK, I'll take a deep breath and remove both explicit implementations then. |
…zed versions `Selector.==` currently calls `sel_isEqual`, which is documented to be the same as == on the direct pointer values. We can safely replace the explicit implementation with the compiler-generated one. `Selector.hashValue` is deprecated as a Hashable requirement, and the preferred method to implement is `hash(into:)`. Implementing the proper function improves hashing performance by eliminating nested Hasher sessions. By removing the previous definition of `hashValue`, we allow the compiler to synthesize the correct `hash(into:)` (and `hashValue`) implementations.
33bfa77
to
4e2dfb7
Compare
Third time's the charm! @swift-ci smoke-test |
@swift-ci smoke-test |
@swift-ci please smoke test |
(This PR was originally part of #20685.)
SE-0206 deprecated
hashValue
as aHashable
requirement, replacing it withhash(into:)
.This PR removes the explicit
Selector.hashValue
implementation, allowing the compiler to provide a (faster) synthesized Hashable implementation, based onhash(into:)
. For symmetry, it also removes the explicit definition of==
. (The compiler-synthesized pointer comparison is documented to have the same semantics assel_isEqual
.)