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

Alternate to https://github.com/nim-lang/Nim/pull/15915 #15937

Merged
merged 2 commits into from
Nov 13, 2020

Conversation

c-blake
Copy link
Contributor

@c-blake c-blake commented Nov 12, 2020

JS VM and JS runtime hashes now match (and result is used) fixing the issue and the problem mentioned in the referred to PR.

resolve the problem mentioned there (`hash() == 0`) as well as
to close nim-lang#15624
@bung87
Copy link
Collaborator

bung87 commented Nov 12, 2020

when this merged also merge #15933 for testing against c, cpp , js backend.

@@ -114,7 +114,11 @@ proc hashWangYi1*(x: int64|uint64|Hash): Hash {.inline.} =
const P1 = 0xe7037ed1a0b428db'u64
const P58 = 0xeb44accab455d165'u64 xor 8'u64
when nimvm:
cast[Hash](hiXorLo(hiXorLo(P0, uint64(x) xor P1), P58))
when defined(js): # NOTE: Nim int64<->Number => JS has limited 32-bit hash.
result = cast[Hash](hiXorLo(hiXorLo(P0, uint64(x) xor P1), P58)) and
Copy link
Member

Choose a reason for hiding this comment

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

subexpression cast[Hash](hiXorLo(hiXorLo(P0, uint64(x) xor P1), P58)) repeated 3 times; factor it using some auxiliary template

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. I kept the cast[Hash]() part open coded since it is short and there is one spot where it seems more clear to say cast[Hash](a) and cast[Hash](b) and have the type matching for the binary operator be obvious.

@ringabout
Copy link
Member

It's better to have some tests in this branch.

bung87 added a commit to bung87/Nim that referenced this pull request Nov 13, 2020
no need mention PR nim-lang#15915, fixed in nim-lang#15937
@bung87
Copy link
Collaborator

bung87 commented Nov 13, 2020

test already there , old test just not test agains to js , added in my PR.

@ringabout
Copy link
Member

test already there , old test just not test agains to js , added in my PR.

At least these tests should be tested locally before merging this PR.

{ though this was only a move from 2 copies to 3 copies. ;-) }
@c-blake
Copy link
Contributor Author

c-blake commented Nov 13, 2020

@xflywind - I had already run locally run the tests/stdlib/thashes.nim (which already tests the exact VM-runtime mismatch problem here) under the C,C++,JS targets as per the change in @bung87 's PR. It ran fine under node-14.15, but the BigInt stuff should all be the same back to node-10.

While I can, of course, fold in that +targets: change here, since @bung87 had already closed his original PR and asked that we just merge his test change one later, I thought that the way to go. I don't really care. It's a 1-line change, really.

{ Also, if anyone cares about the limited 32-bit range, I think we can just add 5 more 'F's to the mask to make it a 52-bit hash on the JS backend, but I think everyone agrees that, long-term, Nim 64-bit integers should be backed by JS BigInt not JS Number. At that point it can be the full 64-bits. }

@Araq Araq merged commit a9bd4c4 into nim-lang:devel Nov 13, 2020
@c-blake c-blake deleted the matchJSvmHashRThash branch November 13, 2020 13:06
bung87 added a commit to bung87/Nim that referenced this pull request Nov 13, 2020
no need mention PR nim-lang#15915, fixed in nim-lang#15937
@c-blake
Copy link
Contributor Author

c-blake commented Nov 13, 2020

As a minor follow up to my {} paragraph above, if anyone does read that and expand the hash range, the tests/stdlib/thashes.nim will need to be smarter about not switching off of just Hash.sizeof < 8 since there will become 3 correct outputs, 32-bit, 52-bit and 64-bit.

@timotheecour
Copy link
Member

@c-blake maybe instead add a comment in the code, otherwise this will be forgotten

@c-blake
Copy link
Contributor Author

c-blake commented Nov 13, 2020

Well, I personally hope that u*int64 becomes backed by BigInt before anyone needs to expand the JS hash range. :-) It would probably only save someone one CI run anyway. Maybe I should never have posted the comment.

ringabout added a commit that referenced this pull request Dec 13, 2020
* test for issue #15624 and PR #15915 for patch #13823

* Update thashes.nim

no need mention PR #15915, fixed in #15937

* rebase to devel(issue maybe fixed), ignore ouputs

* Apply suggestions from code review

Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com>
PMunch pushed a commit to PMunch/Nim that referenced this pull request Jan 6, 2021
* Alternate PR to nim-lang#15915 to
resolve the problem mentioned there (`hash() == 0`) as well as
to close nim-lang#15624

* Address nim-lang#15937 (comment)
{ though this was only a move from 2 copies to 3 copies. ;-) }
mildred pushed a commit to mildred/Nim that referenced this pull request Jan 11, 2021
* Alternate PR to nim-lang#15915 to
resolve the problem mentioned there (`hash() == 0`) as well as
to close nim-lang#15624

* Address nim-lang#15937 (comment)
{ though this was only a move from 2 copies to 3 copies. ;-) }
mildred pushed a commit to mildred/Nim that referenced this pull request Jan 11, 2021
* test for issue nim-lang#15624 and PR nim-lang#15915 for patch nim-lang#13823

* Update thashes.nim

no need mention PR nim-lang#15915, fixed in nim-lang#15937

* rebase to devel(issue maybe fixed), ignore ouputs

* Apply suggestions from code review

Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com>
irdassis pushed a commit to irdassis/Nim that referenced this pull request Mar 16, 2021
* Alternate PR to nim-lang#15915 to
resolve the problem mentioned there (`hash() == 0`) as well as
to close nim-lang#15624

* Address nim-lang#15937 (comment)
{ though this was only a move from 2 copies to 3 copies. ;-) }
ardek66 pushed a commit to ardek66/Nim that referenced this pull request Mar 26, 2021
* Alternate PR to nim-lang#15915 to
resolve the problem mentioned there (`hash() == 0`) as well as
to close nim-lang#15624

* Address nim-lang#15937 (comment)
{ though this was only a move from 2 copies to 3 copies. ;-) }
ardek66 pushed a commit to ardek66/Nim that referenced this pull request Mar 26, 2021
* test for issue nim-lang#15624 and PR nim-lang#15915 for patch nim-lang#13823

* Update thashes.nim

no need mention PR nim-lang#15915, fixed in nim-lang#15937

* rebase to devel(issue maybe fixed), ignore ouputs

* Apply suggestions from code review

Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com>
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