Skip to content
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

DateComponents, URLRequest, URLComponents: Fix hashing #1656

Merged
merged 5 commits into from
Aug 18, 2018

Conversation

lorentey
Copy link
Member

@lorentey lorentey commented Aug 6, 2018

This PR collects fixes previously submitted separately as #1645, #1646 and #1648, fixing the implementation of hashing for the following Foundation types:

  • DateComponents
  • NSDateComponents
  • URLRequest
  • NSURLRequest
  • URLComponents
  • NSURLComponents

Note that this isn't a full audit of Foundation hashing -- this was the bare minimum necessary for #1649. I suspect there may be more types with issues similar to these.

Resolves:

@lorentey lorentey requested a review from millenomi August 6, 2018 15:58
@lorentey
Copy link
Member Author

lorentey commented Aug 6, 2018

@swift-ci please test


// Check that mutating `object` via the specified key path affects its
// hash value.
func _checkHashableMutations<Source: Hashable, Target: Hashable, S: Sequence>(
Copy link
Contributor

Choose a reason for hiding this comment

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

I know these are a ton of arguments and it's essentially fileprivate, but honestly I'd have a more descriptive set of labels because it is really hard to parse the invocations above at a glance.

e.g.: _checkHashing(of type, matches type, initialValue:, copyHandler:, byMutating keyPaths, throughRange:)

Copy link
Contributor

@millenomi millenomi left a comment

Choose a reason for hiding this comment

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

✅ with the readability comment above. (I assume this passes when run on Darwin Foundation?)

@lorentey
Copy link
Member Author

I assume this passes when run on Darwin Foundation?

That's a good question! I should make a Darwin version of these tests -- I'm adding it to my to do list.

@lorentey
Copy link
Member Author

@swift-ci please test and merge

@lorentey
Copy link
Member Author

Oh, swift-ci can’t merge here!

@swift-ci test

@spevans
Copy link
Contributor

spevans commented Aug 16, 2018

@lorentey There is an Xcode project, DarwinCompatibilityTests in the toplevel that can be used to run the TestFoundation tests against Darwin's native foundation. The tests should show up in the unit test pane, although not all of them currently pass.

@lorentey
Copy link
Member Author

I managed to run these tests on Darwin's Foundation, and filed rdar://problem/43422017 with my findings. While Darwin Foundation (erroneously) neglects to mix some of the properties that affect equality into the hash value, I believe there is no need for swift-corelibs-foundation to emulate this behavior. (Emulating exact hash values would not be a worthy exercise anyway, and given the lack of random seeding, it may even be actively harmful to do so in server contexts.) So I think the definitions can stay as defined here.

@lorentey
Copy link
Member Author

Now if only I could get PR testing to update GitHub status... The tests seem to finish successfully, but the PR stays yellow.

@swift-ci test

@lorentey lorentey merged commit 50b26ff into swiftlang:master Aug 18, 2018
@lorentey lorentey deleted the hashing-improvements branch August 18, 2018 15:09
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.

3 participants