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
[SR-4858] IndexPath.hashValue broken on Linux #3861
Comments
The most recent Darwin version of IndexPath has a better hashValue implementation |
Does it fix the overflow problem mentioned in that thread? |
the listed bug was that it was calling object conversion not overflows, any case of numeric calculation there was ripped directly from the C implementation (which is considerably faster than bridging an entire object) |
print(IndexPath.init(indexes: [1, 2, 3]).hashValue) works just fine: it does not crash from any overflow cases: 206158430467 |
A later comment in that thread: > And that new impl of hashValue doesn't use the overflow operators, so it will choke on large values Integer addition in C does not trap on overflow as it does in Swift, so you have to be very careful copying code. In this case, I think you get a crash for [Int.max >> 8, Int.max >> 36]: ``` print(hashIndexes(first: Int.max >> 8, last: Int.max >> 36, count: 2)) // EXC_BAD_INSTRUCTION |
hmm that it does. That is a separate bug and can easily be fixed, it would be nice if swift was actually consistent about the story on numeric values (float/double follow C rules whereas Int seems to not) |
it is worth noting that if you have IndexPaths with values like Int.max>> 8 something very fishy is going on to begin with (it is not a common use case) |
Here is a pr for the Darwin version (including a test to verify) |
Comment by Matt Rajca (JIRA) This was fixed in June: #1067 |
Additional Detail from JIRA
md5: 3cdcfaf07c165283d1906f11248eb5f9
Issue Description:
In trying to use IndexPaths as dictionary keys, we found that the hashValue implementation is entirely broken on Linux.
More details are at:
apple/swift-protobuf#513
The text was updated successfully, but these errors were encountered: