-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Synthesize ==/hashValue for tuple fields/payloads #12598
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
Open question: Attempting to do this recursively (to allow synthesis in the presence of fields, say, of types But, there may be some value in extending this to handle Thoughts? |
Once we have conditional conformance this can just be driven by Equatable conformance (except for tuples). And that should be pretty close based on @huonw’s recent commits. So probably better to hold off for now. |
@airspeedswift That's great—I didn't realize they were that close. Making It sounds like I should remove the |
Yeah, I'd prefer to remove |
3cdd859
to
c78a3c1
Compare
c78a3c1
to
bdd8be7
Compare
Sounds good to me! I've updated the PR to cover tuples only. |
Question: tuples have |
@xwu I looked into it a little bit, but it seems that having non-nominal types conform to protocols is a much deeper change. Unfortunately I'm less familiar with where to go about getting started on that. Since I don't know how much work it is, I'm not sure if it would make it by the Swift 4.1 deadline. If that change isn't possible in that timeframe, I'd like to not have the existing synthesis crippled because of that missing feature. The tuple-specific changes in this PR can be easily removed in the future once tuples have that capability. |
Even aside from the non-nominal types issue, this also requires conditional conformances. It requires synthesizing something like |
It's also less clear how tuples and What does it mean to attach a property to a tuple? What if my tuple is |
This is one reason (I think) why the design of the derived If it isn't already, the synthesized |
@allevato It's been a few years. If you want to pursue this further, could you please pitch this to evolution so we can get the community's updated thoughts on the idea? Sorry we weren't able to resolve this at the time. |
The original PR (#9619) implementing
Equatable
/Hashable
only covered types that directly conformed to those protocols. This is a bit restrictive for real-world usage—for example, astruct
with anInt?
field won't be able to synthesize, so this PR fills in some gaps for the sake of usability: synthesis for fields/associated values that aretuples where all fields areOptional<T> where T: Equatable/Hashable
and forEquatable
/Hashable
.~In each case, ~future language improvements will eventually allow the special cases to go away.
ForFor tuples, we need the ability to conform non-nominal types to protocols (and variadic generics).Optional
, we need conditional conformances.Update: As discussed below, the support for
Optional
has been removed because it will be covered better by conditional conformances. Exciting!