swift
[4.2][stdlib] Make sure _SwiftNewtypeWrapper hashes the same way as its RawValue
#15991
Merged

[4.2][stdlib] Make sure _SwiftNewtypeWrapper hashes the same way as its RawValue #15991

lorentey
lorentey7 years ago

_SwiftNewtypeWrapper forwarded hashValue to its rawValue, but it failed to do the same for _hash(into:), which resulted in the wrapper struct having subtly different hashing than the raw value.

This violated an implicit invariant when dictionaries/sets of such types were bridged to Objective-C through AnyHashable, leading to nondeterministic but frequent crashes.

rdar://problem/39398060

(cherry picked from commit 6c5a6a6)

lorentey [4.2][stdlib] Make sure _SwiftNewtypeWrapper hashes the same way as i…
95695910
lorentey
lorentey7 years ago

@swift-ci please smoke test

lorentey lorentey requested a review from DougGregor DougGregor 7 years ago
lorentey
lorentey7 years ago

@DougGregor could you take a quick look? Note that I had to add the new Self: Hashable constraint on the extension; otherwise the _hash(into:) definition clashed with its default implementation.

lorentey lorentey requested a review from airspeedswift airspeedswift 7 years ago
airspeedswift
airspeedswift approved these changes on 2018-04-17
airspeedswift7 years ago

LGTM. Can you add a test for the issue it resolves?

lorentey
lorentey7 years agošŸ‘ 1

@airspeedswift PR #15939 includes an update to the test suite's checkHashable to also verify hash(into:) equivalency (among other things). This update will extend the scope of an existing test so that it will cover this issue. I expect to land that very soon.

lorentey
lorentey7 years ago

@swift-ci please test and merge

swift-ci swift-ci merged ed1b8f3c into swift-4.2-branch 7 years ago
lorentey lorentey deleted the newtype-vs-anyhashable-4.2 branch 7 years ago

Login to write a write a comment.

Login via GitHub

Assignees
No one assigned
Labels
Milestone