Skip to content

Use Hashable.hash(into:) over hashValue to silence the deprecation warnings #1820

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

Merged
merged 3 commits into from
Feb 14, 2019

Conversation

ikesyo
Copy link
Member

@ikesyo ikesyo commented Jan 14, 2019

There are some remaining warnings, but this should be a good start.

@ikesyo
Copy link
Member Author

ikesyo commented Jan 14, 2019

@swift-ci Please test

Copy link
Member

@lorentey lorentey left a comment

Choose a reason for hiding this comment

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

I have one major issue with NSObject's hashing, and lots of smaller nitpicks.

The NSObject issue isn't new with this PR, but since we're changing it, we might as well change it to something that's consistent with Apple's Foundation.

@@ -323,8 +323,8 @@ open class NSObject : NSObjectProtocol, Equatable, Hashable {
return self
}

open var hashValue: Int {
return hash
open func hash(into hasher: inout Hasher) {
Copy link
Member

Choose a reason for hiding this comment

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

For compatibility with the Foundation overlay on Cocoa platforms, we should not remove the existing hashValue definition, but we should make it public final instead of open. This also applies tohash(into:) -- it must also be declared public final. (See swiftlang/swift#20129)

The NSObject hashing interface is hash; subclasses must override that instead of hashValue or hash(into:). Sadly, this includes subclasses defined within this module -- I think there might be a couple of subclasses that do currently the wrong thing.

(On Darwin, NSObject.hashValue and hash(into:) are defined public because the enclosing module is small, and doesn't define subclasses. The appropriate qualifier in swift-corelibs-foundation is public final.)

@lorentey
Copy link
Member

Thanks a lot for working on this!

The Foundation overlay on Apple platforms has not been updated yet, but there is no reason corelibs-Foundation can't do the transition first.

@ikesyo
Copy link
Member Author

ikesyo commented Jan 14, 2019

@lorentey Thanks for your review and the suggestions! I'll address those.

@ikesyo
Copy link
Member Author

ikesyo commented Jan 14, 2019

@swift-ci Please test

@parkera
Copy link
Contributor

parkera commented Jan 14, 2019

Thanks a lot for working on this!

The Foundation overlay on Apple platforms has not been updated yet, but there is no reason corelibs-Foundation can't do the transition first.

We're trying to keep these in sync as much as possible.

@ikesyo ikesyo requested a review from lorentey January 15, 2019 14:20
@lorentey
Copy link
Member

I'll submit a PR to update the Foundation overlay soon -- it makes sense to hold this PR until then.

@ikesyo
Copy link
Member Author

ikesyo commented Jan 22, 2019

I'll submit a PR to update the Foundation overlay soon

@lorentey Is there any progress on the overlay? I'd like to merge this if it needs more time.

@lorentey
Copy link
Member

Apologies for the delay. I split out your NSObject.hashValue commit into a separate PR -- #1850. I believe this can land immediately, pending review.

Switching to hash(into:) will need a bit of coordination; my PR for the overlays is still in progress.

@millenomi
Copy link
Contributor

@swift-ci please test and merge

@swift-ci swift-ci merged commit 4b34eb5 into swiftlang:master Feb 14, 2019
@ikesyo ikesyo deleted the use-hash-into branch February 14, 2019 10:28
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.

5 participants