Skip to content

Support Swift 4.2 Hashable #2115

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

Closed
wants to merge 1 commit into from
Closed

Conversation

colemancda
Copy link
Contributor

Updates implementation of Hashable in Foundation types to properly support Swift 4.2 and 5.

@colemancda
Copy link
Contributor Author

@spevans Can you test this please?

@@ -137,9 +137,15 @@ public struct Date : ReferenceConvertible, Comparable, Equatable {
*/
public static let distantPast = Date(timeIntervalSinceReferenceDate: -63114076800.0)

#if swift(>=4.2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The swift version check should not be needed as there is a branch per version.

public func hash(into hasher: inout Hasher) {
unit.hash(into: &hasher)
value.hash(into: &hasher)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont see this method on Darwin's Foundation (unless its in the latest beta?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't implement func hash(into hasher: inout Hasher) it uses hashValue as a fallback implementation, which on Darwin is just the NSObject hash.

@spevans
Copy link
Contributor

spevans commented Apr 15, 2019

Could you add a testcase just calling the method for each of the types are modifying please

@millenomi
Copy link
Contributor

cc @lorentey who was already working on this, or similar.

@lorentey
Copy link
Member

I suggest to hold this; this is somewhat trickier than it looks, and it has to be synced with the Foundation overlay. In swiftlang/swift#23832, I submitted a draft PR for the overlay parts; I'm preparing a similar PR for corelibs-foundation, too.

@lorentey
Copy link
Member

Update: My corelibs-foundation PR is up at #2118.

@millenomi
Copy link
Contributor

@colemancda thank you for the contribution — I'm gonna close this because it has been superseded by #2118.

@millenomi millenomi closed this Apr 17, 2019
@colemancda
Copy link
Contributor Author

Ok, if this is done better somewhere else, that's great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants