Nim/tests/stdlib
c-blake a0b33f9408
Add hashWangYi1 (#13823)
* Unwind just the "pseudorandom probing" (whole hash-code-keyed variable
stride double hashing) part of recent sets & tables changes (which has
still been causing bugs over a month later (e.g., two days ago
https://github.com/nim-lang/Nim/issues/13794) as well as still having
several "figure this out" implementation question comments in them (see
just diffs of this PR).

This topic has been discussed in many places:
  https://github.com/nim-lang/Nim/issues/13393
  https://github.com/nim-lang/Nim/pull/13418
  https://github.com/nim-lang/Nim/pull/13440
  https://github.com/nim-lang/Nim/issues/13794

Alternative/non-mandatory stronger integer hashes (or vice-versa opt-in
identity hashes) are a better solution that is more general (no illusion
of one hard-coded sequence solving all problems) while retaining the
virtues of linear probing such as cache obliviousness and age-less tables
under delete-heavy workloads (still untested after a month of this change).

The only real solution for truly adversarial keys is a hash keyed off of
data unobservable to attackers.  That all fits better with a few families
of user-pluggable/define-switchable hashes which can be provided in a
separate PR more about `hashes.nim`.

This PR carefully preserves the better (but still hard coded!) probing
of the  `intsets` and other recent fixes like `move` annotations, hash
order invariant tests, `intsets.missingOrExcl` fixing, and the move of
`rightSize` into `hashcommon.nim`.

* Fix `data.len` -> `dataLen` problem.

* This is an alternate resolution to https://github.com/nim-lang/Nim/issues/13393
(which arguably could be resolved outside the stdlib).

Add version1 of Wang Yi's hash specialized to 8 byte integers.  This gives
simple help to users having trouble with overly colliding hash(key)s.  I.e.,
  A) `import hashes; proc hash(x: myInt): Hash = hashWangYi1(int(x))`
      in the instantiation context of a `HashSet` or `Table`
or
  B) more globally, compile with `nim c -d:hashWangYi1`.

No hash can be all things to all use cases, but this one is A) vetted to
scramble well by the SMHasher test suite (a necessarily limited but far
more thorough test than prior proposals here), B) only a few ALU ops on
many common CPUs, and C) possesses an easy via "grade school multi-digit
multiplication" fall back for weaker deployment contexts.

Some people might want to stampede ahead unbridled, but my view is that a
good plan is to
  A) include this in the stdlib for a release or three to let people try it
     on various key sets nim-core could realistically never access/test
     (maybe mentioning it in the changelog so people actually try it out),
  B) have them report problems (if any),
  C) if all seems good, make the stdlib more novice friendly by adding
     `hashIdentity(x)=x` and changing the default `hash() = hashWangYi1`
     with some `when defined` rearranging so users can `-d:hashIdentity`
     if they want the old behavior back.
This plan is compatible with any number of competing integer hashes if
people want to add them.  I would strongly recommend they all *at least*
pass the SMHasher suite since the idea here is to become more friendly to
novices who do not generally understand hashing failure modes.

* Re-organize to work around `when nimvm` limitations; Add some tests; Add
a changelog.md entry.

* Add less than 64-bit CPU when fork.

* Fix decl instead of call typo.

* First attempt at fixing range error on 32-bit platforms; Still do the
arithmetic in doubled up 64-bit, but truncate the hash to the lower
32-bits, but then still return `uint64` to be the same.  So, type
correct but truncated hash value.  Update `thashes.nim` as well.

* A second try at making 32-bit mode CI work.

* Use a more systematic identifier convention than Wang Yi's code.

* Fix test that was wrong for as long as `toHashSet` used `rightSize` (a
very long time, I think).  `$a`/`$b` depend on iteration order which
varies with table range reduced hash order which varies with range for
some `hash()`.  With 3 elements, 3!=6 is small and we've just gotten
lucky with past experimental `hash()` changes.  An alternate fix here
would be to not stringify but use the HashSet operators, but it is not
clear that doesn't alter the "spirit" of the test.

* Fix another stringified test depending upon hash order.

* Oops - revert the string-keyed test.

* Fix another stringify test depending on hash order.

* Add a better than always zero `defined(js)` branch.

* It turns out to be easy to just work all in `BigInt` inside JS and thus
guarantee the same low order bits of output hashes (for `isSafeInteger`
input numbers).  Since `hashWangYi1` output bits are equally random in
all their bits, this means that tables will be safely scrambled for table
sizes up to 2**32 or 4 gigaentries which is probably fine, as long as the
integer keys are all < 2**53 (also likely fine).  (I'm unsure why the
infidelity with C/C++ back ends cut off is 32, not 53 bits.)

Since HashSet & Table only use the low order bits, a quick corollary of
this is that `$` on most int-keyed sets/tables will be the same in all
the various back ends which seems a nice-to-have trait.

* These string hash tests fail for me locally.  Maybe this is what causes
the CI hang for testament pcat collections?

* Oops. That failure was from me manually patching string hash in hashes.  Revert.

* Import more test improvements from https://github.com/nim-lang/Nim/pull/13410

* Fix bug where I swapped order when reverting the test.  Ack.

* Oh, just accept either order like more and more hash tests.

* Iterate in the same order.

* `return` inside `emit` made us skip `popFrame` causing weird troubles.

* Oops - do Windows branch also.

* `nimV1hash` -> multiply-mnemonic, type-scoped `nimIntHash1` (mnemonic
resolutions are "1 == identity", 1 for Nim Version 1, 1 for
first/simplest/fastest in a series of possibilities.  Should be very
easy to remember.)

* Re-organize `when nimvm` logic to be a strict `when`-`else`.

* Merge other changes.

* Lift constants to a common area.

* Fall back to identity hash when `BigInt` is unavailable.

* Increase timeout slightly (probably just real-time perturbation of CI
system performance).
2020-04-15 20:11:18 +02:00
..
nre Rework nil/option for nre in light of ""==nil 2018-12-11 22:15:57 +00:00
genericstrformat.nim Strformat symbol binding (#10927) 2019-04-05 15:27:04 +02:00
mjsonexternproc.nim Reorder json add and %, fixes #6385 (#6388) 2017-09-16 19:09:44 +01:00
mstackframes.nim stacktraces can now show custom runtime msgs per frame (#13351) 2020-03-30 13:45:32 +02:00
osproctest.nim Add workingDir parameter to execProcess and test (#9549) 2018-11-26 10:28:44 +01:00
somesql.sql Parse the usage of the SQL in operator properly (#9527) 2018-10-28 13:34:57 +01:00
t8925.nim require errormsg to be specified before file. 2018-12-11 21:23:21 +01:00
t10231.nim fixes #10273 execShellCmd now returns nonzero when child killed with signal + other fixes (#10274) 2019-01-13 09:00:39 +01:00
tasynchttpserver.nim Add barebones asynchttpserver tests (#13883) 2020-04-05 21:16:13 +02:00
tbase64.nim fixes #13722 (#13729) 2020-03-23 15:47:10 +01:00
tbitops.nim faster CIs (#13803) 2020-03-30 13:18:12 +02:00
tbitops.nim.cfg add bitops module for optimized bit manipulation. (#5201) 2017-03-14 21:32:54 +01:00
tcgi.nim require errormsg to be specified before file. 2018-12-11 21:23:21 +01:00
tdecls.nim std/byaddr => std/decls (#13847) 2020-04-03 09:03:13 +02:00
tfrexp1.nim faster CIs (#13803) 2020-03-30 13:18:12 +02:00
tgetaddrinfo.nim #12103 - CI for FreeBSD (#12179) 2019-11-29 21:00:54 +01:00
tgetfileinfo.nim Fix spellings (#12277) [backport] 2019-09-27 07:02:54 +02:00
thashes.nim Add hashWangYi1 (#13823) 2020-04-15 20:11:18 +02:00
thtmlparser.nim fixes #11713, fixes #1034 2019-09-04 11:20:30 +02:00
thttpclient.nim fix deprecations and other warnings (#13748) 2020-03-25 19:15:34 +01:00
thttpclient_ssl.nim SSL certificate verify GitHub action (#13697) 2020-03-20 17:11:39 +01:00
thttpclient_ssl_cert.pem SSL certificate verify GitHub action (#13697) 2020-03-20 17:11:39 +01:00
thttpclient_ssl_key.pem SSL certificate verify GitHub action (#13697) 2020-03-20 17:11:39 +01:00
thttpcore.nim Fix #13573 and #13574 (#13575) 2020-03-06 18:38:56 +00:00
tintsets.nim tables/sharedtables/intsets/etc: fix #13496, #13504, #13505; add lots of tests (#13498) [backport] 2020-02-26 22:07:09 +01:00
tjson_unmarshall.nim fix #13531 by adding a test (#13581) 2020-03-04 10:25:59 +01:00
tjsonexternproc.nim updated tests to be executed 2018-11-23 11:58:28 +01:00
tjsonmacro.nim Extent json.to testing to VM, add workrounds for VM bugs. (#12493) 2019-10-28 10:06:16 +01:00
tjsonmacro_reject.nim require errormsg to be specified before file. 2018-12-11 21:23:21 +01:00
tjsontestsuite.nim updated tests to be executed 2018-11-23 11:58:28 +01:00
tlists.nim add SinglyLinkedList.append procs 2018-11-27 10:34:34 +01:00
tlocks.nim fixes #6049 add mixin release, acquire to withLock (#6113) 2017-07-16 16:54:09 +02:00
tmarshal.nim fixes #8916 by fixing typeinfo and marshal. (#9341) 2018-10-13 08:47:58 +02:00
tmath.nim fix deprecations and other warnings (#13748) 2020-03-25 19:15:34 +01:00
tmemfiles1.nim require errormsg to be specified before file. 2018-12-11 21:23:21 +01:00
tmemfiles2.nim Merge branch 'araq-devel' of github.com:nim-lang/Nim into araq-devel 2018-07-06 17:27:02 +02:00
tmemlines.nim activated more tests, allow input in test spec 2018-11-23 11:58:28 +01:00
tmemlinesBuf.nim eyewash 2018-11-23 11:58:31 +01:00
tmemmapstreams.nim require errormsg to be specified before file. 2018-12-11 21:23:21 +01:00
tmemslices.nim activated more tests, allow input in test spec 2018-11-23 11:58:28 +01:00
tmget.nim fix deprecations and other warnings (#13748) 2020-03-25 19:15:34 +01:00
tmitems.nim Added deques module, deprecating queues 2016-11-24 19:11:51 +07:00
tnet.nim activated more tests, allow input in test spec 2018-11-23 11:58:28 +01:00
tnet_ll.nim Fixed tests to expect [Suite] output from unittest 2016-08-24 22:32:29 +02:00
tnetbind.nim Handle IPv6 in bindAddr #7633 2019-02-23 13:06:26 +00:00
tnetdial.nim fix deprecations and other warnings (#13748) 2020-03-25 19:15:34 +01:00
tnre.nim Testament pre parallel (#9137) 2018-10-12 17:27:47 +02:00
tos.nim [RFC] 'walkDir' now has a new 'checkDir' flag, to mimic behaviour of other languages (#13642) 2020-03-20 16:39:55 +01:00
tos_unc.nim fixes #10952, UNC paths (#11260) 2019-05-16 21:06:04 +02:00
tosproc.nim fix deprecations and other warnings (#13748) 2020-03-25 19:15:34 +01:00
tosprocterminate.nim osproc: added a better version of waitForExit for Haiku (#13938) 2020-04-10 09:34:52 +02:00
tparscfg.nim parsecfg: handle streams and strings when saving or loading configuration (#5554) 2017-04-06 08:10:08 +02:00
tparsecfg.nim fixes #6046 parsecfg failed to parse negative int (#6097) 2017-07-14 16:28:39 +02:00
tparseipv6.nim added IP v6 parsing tests 2017-05-04 22:25:29 +02:00
tparsesql.nim require errormsg to be specified before file. 2018-12-11 21:23:21 +01:00
tparseuints.nim Fixed tests to expect [Suite] output from unittest 2016-08-24 22:32:29 +02:00
tparsopt.nim more tests fixed 2018-11-23 11:58:29 +01:00
tpegs.nim Add interpreting event parser proc to pegs module. (#8075) 2018-08-24 20:13:37 +02:00
tposix.nim activated more tests, allow input in test spec 2018-11-23 11:58:28 +01:00
tquit.nim testament: joinable is now an explicit concept of a test spec 2018-12-11 21:23:24 +01:00
tregex.nim require errormsg to be specified before file. 2018-12-11 21:23:21 +01:00
trepr.nim fixes #7878 2019-01-14 12:36:34 +01:00
trst.nim Rst parser respect :start-after: and :end-before: in include directive (#12972) 2020-01-05 10:01:21 +01:00
trstgen.nim rst: parse brackets individually, fixes #10475 (#10997) 2019-04-10 15:55:57 +02:00
tsharedtable.nim tables/sharedtables/intsets/etc: fix #13496, #13504, #13505; add lots of tests (#13498) [backport] 2020-02-26 22:07:09 +01:00
tsortcall.nim activated more tests, allow input in test spec 2018-11-23 11:58:28 +01:00
tsqlparser.nim megatest can be executed 2018-12-11 21:23:21 +01:00
tstackframes.nim stacktraces can now show custom runtime msgs per frame (#13351) 2020-03-30 13:45:32 +02:00
tstdlib_issues.nim More descriptive names of test files (#9531) 2018-10-29 17:07:27 +01:00
tstdlib_various.nim megatest can be executed 2018-12-11 21:23:21 +01:00
tstreams.nim faster CIs (#13803) 2020-03-30 13:18:12 +02:00
tstrformat.nim fixes #12612 [backport] (#12681) 2019-11-19 12:09:36 +01:00
tstring.nim distinctBase type trait for distinct types (#13031) 2020-01-08 00:36:57 +01:00
tstrscans.nim Fix strscans.scanp (#9518) 2018-10-28 13:35:30 +01:00
tstrset.nim the parser finally parses 'echo {1,2}' as it should 2017-09-30 21:35:30 +02:00
tstrtabs.nim add a StringTable.clear that requires no mode specification (#12853) 2019-12-09 06:58:36 +01:00
tstrutil.nim Version of trimZeros without temp strings (#12633) 2019-11-11 12:54:17 +01:00
ttimes.nim faster CIs (#13803) 2020-03-30 13:18:12 +02:00
tunidecode.nim further adaptations 2014-08-29 09:12:12 +02:00
tunittest.nim make tests more robust; tests should be deterministic, no randomize() calls in tests 2019-01-13 13:54:44 +01:00
tunittestexceptiontype.nim Added: type name output when exception raised from unittest (#7869) 2018-05-28 05:24:04 +03:00
tunittesttemplate.nim fix several bugs with repr (#13386) 2020-02-11 21:33:06 +01:00
tvarints.nim Make unused code into actual test, replace echo with doassert (#13952) 2020-04-11 22:16:26 +02:00
twchartoutf8.nim make more tests green 2018-04-30 11:16:56 +02:00
twrapnils.nim maybe: allows optional chaining of field access and indexing when LHS i snil (#13023) 2020-01-18 12:24:56 +01:00
uselocks.nim fixes #6049 add mixin release, acquire to withLock (#6113) 2017-07-16 16:54:09 +02:00