Skip to content

[stdlib] Remove documentation piece that it is not longer true. #23400

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 1 commit into from
Mar 21, 2019

Conversation

drodriguez
Copy link
Contributor

Since a4e9109 (#17396), both the hashes and the equality of numeric
types inside of AnyHashable do not follow the rules that this part of
the comment was talking about.

I couldn't find an easy example that shows the same behaviour, so I
decided to remove the comment completely.

/cc @lorentey

Since a4e9109 (swiftlang#17396), both the hashes and the equality of numeric
types inside of AnyHashable do not follow the rules that this part of
the comment was talking about.

I couldn't find an easy example that shows the same behaviour, so I
decided to remove the comment completely.
@lorentey
Copy link
Member

One way to demonstrate the behavior is to use a custom wrapper struct as one of the types:

struct Wrapper: Hashable {
  let value: Int
}

let x = AnyHashable(Int(42))		
let y = AnyHashable(Wrapper(value: 42))		

print(x == y)		
// Prints "false" because `Int` and `Wrapper` are different types		

print(x == AnyHashable(Int(42)))		
// Prints "true"

@lorentey
Copy link
Member

I'd be fine with either removing the example or updating it -- @natecook1000, what do you think?

@lorentey lorentey requested a review from natecook1000 March 19, 2019 03:30
@drodriguez
Copy link
Contributor Author

I think the interesting part of the previous example was that even if Int(42) == UInt8(42), the type-erased values do not compare the same. With the changes which keep the equality properties of the underlaying values, that little disagreement is not longer true.

In my opinion, the proposed example doesn't work in the same way, since the equality between Wrapper and Int will never be true.

@natecook1000
Copy link
Member

There are a couple funky things intersecting here: (1) we have heterogeneous equality operators defined for integers, and (2) AnyHashable uses NSNumber semantics for comparison, even when Foundation hasn't been imported. You can see this by comparing AnyHash'd integer and floating-point values:

let x = AnyHashable(Int(42))
let y = AnyHashable(Double(42))

x == y // true

Whereas you couldn't compare an Int and Double that weren't wrapped.

All that said, I think it makes sense to take these examples out and note the oddity in the type overview. Thanks for looking at this, @drodriguez!

@natecook1000
Copy link
Member

@swift-ci Please smoke test and merge

@drodriguez
Copy link
Contributor Author

@swift-ci please smoke test and merge

@drodriguez
Copy link
Contributor Author

Trying again if my CI powers have been enabled. In any case, the macOS failure seems to be unrelated to the changes. If my request to CI doesn’t work, would someone start it up for me? Thanks!

@compnerd
Copy link
Member

@swift-ci please test macOS platform

@compnerd compnerd merged commit 65d4199 into swiftlang:master Mar 21, 2019
@drodriguez drodriguez deleted the remove-incorrect-docs branch April 8, 2019 20:31
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