about summary refs log tree commit diff
path: root/src/etc/test-float-parse
diff options
context:
space:
mode:
authorAlex Huszagh <ahuszagh@gmail.com>2021-07-17 00:30:34 -0500
committerAlex Huszagh <ahuszagh@gmail.com>2021-07-17 00:30:34 -0500
commit8752b403695a8830913571f0fd5ebfcf1483db37 (patch)
treefba1ac7613edb617bee5b257b21bd6d10dad0662 /src/etc/test-float-parse
parentd2b04f075c0ce010758c4c8674152ff89d1d73f3 (diff)
downloadrust-8752b403695a8830913571f0fd5ebfcf1483db37.tar.gz
rust-8752b403695a8830913571f0fd5ebfcf1483db37.zip
Changed dec2flt to use the Eisel-Lemire algorithm.
Implementation is based off fast-float-rust, with a few notable changes.

- Some unsafe methods have been removed.
- Safe methods with inherently unsafe functionality have been removed.
- All unsafe functionality is documented and provably safe.
- Extensive documentation has been added for simpler maintenance.
- Inline annotations on internal routines has been removed.
- Fixed Python errors in src/etc/test-float-parse/runtests.py.
- Updated test-float-parse to be a library, to avoid missing rand dependency.
- Added regression tests for #31109 and #31407 in core tests.
- Added regression tests for #31109 and #31407 in ui tests.
- Use the existing slice primitive to simplify shared dec2flt methods
- Remove Miri ignores from dec2flt, due to faster parsing times.

- resolves #85198
- resolves #85214
- resolves #85234
- fixes #31407
- fixes #31109
- fixes #53015
- resolves #68396
- closes https://github.com/aldanor/fast-float-rust/issues/15
Diffstat (limited to 'src/etc/test-float-parse')
-rw-r--r--src/etc/test-float-parse/Cargo.toml13
-rw-r--r--src/etc/test-float-parse/runtests.py37
-rw-r--r--src/etc/test-float-parse/src/bin/few-ones.rs (renamed from src/etc/test-float-parse/few-ones.rs)4
-rw-r--r--src/etc/test-float-parse/src/bin/huge-pow10.rs (renamed from src/etc/test-float-parse/huge-pow10.rs)4
-rw-r--r--src/etc/test-float-parse/src/bin/long-fractions.rs (renamed from src/etc/test-float-parse/long-fractions.rs)4
-rw-r--r--src/etc/test-float-parse/src/bin/many-digits.rs (renamed from src/etc/test-float-parse/many-digits.rs)4
-rw-r--r--src/etc/test-float-parse/src/bin/rand-f64.rs (renamed from src/etc/test-float-parse/rand-f64.rs)4
-rw-r--r--src/etc/test-float-parse/src/bin/short-decimals.rs (renamed from src/etc/test-float-parse/short-decimals.rs)4
-rw-r--r--src/etc/test-float-parse/src/bin/subnorm.rs (renamed from src/etc/test-float-parse/subnorm.rs)4
-rw-r--r--src/etc/test-float-parse/src/bin/tiny-pow10.rs (renamed from src/etc/test-float-parse/tiny-pow10.rs)4
-rw-r--r--src/etc/test-float-parse/src/bin/u32-small.rs (renamed from src/etc/test-float-parse/u32-small.rs)4
-rw-r--r--src/etc/test-float-parse/src/bin/u64-pow2.rs (renamed from src/etc/test-float-parse/u64-pow2.rs)4
-rw-r--r--src/etc/test-float-parse/src/lib.rs (renamed from src/etc/test-float-parse/_common.rs)0
13 files changed, 43 insertions, 47 deletions
diff --git a/src/etc/test-float-parse/Cargo.toml b/src/etc/test-float-parse/Cargo.toml
new file mode 100644
index 00000000000..8226e815c2c
--- /dev/null
+++ b/src/etc/test-float-parse/Cargo.toml
@@ -0,0 +1,13 @@
+[package]
+name = "test-float-parse"
+version = "0.1.0"
+edition = "2018"
+publish = false
+
+[workspace]
+
+[dependencies]
+rand = "0.4"
+
+[lib]
+name = "test_float_parse"
diff --git a/src/etc/test-float-parse/runtests.py b/src/etc/test-float-parse/runtests.py
index 218552a4597..cf7279534dc 100644
--- a/src/etc/test-float-parse/runtests.py
+++ b/src/etc/test-float-parse/runtests.py
@@ -131,22 +131,20 @@ def write_errors():
             exit_status = 101
 
 
-def rustc(test):
-    rs = test + '.rs'
-    exe = test + '.exe'  # hopefully this makes it work on *nix
-    print("compiling", test)
+def cargo():
+    print("compiling tests")
     sys.stdout.flush()
-    check_call(['rustc', rs, '-o', exe])
+    check_call(['cargo', 'build', '--release'])
 
 
 def run(test):
     global test_name
     test_name = test
 
-    t0 = time.clock()
+    t0 = time.perf_counter()
     msg("setting up supervisor")
-    exe = test + '.exe'
-    proc = Popen(exe, bufsize=1<<20 , stdin=PIPE, stdout=PIPE, stderr=PIPE)
+    command = ['cargo', 'run', '--bin', test, '--release']
+    proc = Popen(command, bufsize=1<<20 , stdin=PIPE, stdout=PIPE, stderr=PIPE)
     done = multiprocessing.Value(ctypes.c_bool)
     queue = multiprocessing.Queue(maxsize=5)#(maxsize=1024)
     workers = []
@@ -166,7 +164,7 @@ def run(test):
         worker.join()
     msg("python is done")
     assert queue.empty(), "did not validate everything"
-    dt = time.clock() - t0
+    dt = time.perf_counter() - t0
     msg("took", round(dt, 3), "seconds")
 
 
@@ -176,7 +174,7 @@ def interact(proc, queue):
         line = proc.stdout.readline()
         if not line:
             continue
-        assert line.endswith('\n'), "incomplete line: " + repr(line)
+        assert line.endswith(b'\n'), "incomplete line: " + repr(line)
         queue.put(line)
         n += 1
         if n % UPDATE_EVERY_N == 0:
@@ -185,7 +183,7 @@ def interact(proc, queue):
     rest, stderr = proc.communicate()
     if stderr:
         msg("rust stderr output:", stderr)
-    for line in rest.split('\n'):
+    for line in rest.split(b'\n'):
         if not line:
             continue
         queue.put(line)
@@ -193,18 +191,19 @@ def interact(proc, queue):
 
 def main():
     global MAILBOX
-    all_tests = [os.path.splitext(f)[0] for f in glob('*.rs') if not f.startswith('_')]
+    files = glob('src/bin/*.rs')
+    basenames = [os.path.basename(i) for i in files]
+    all_tests = [os.path.splitext(f)[0] for f in basenames if not f.startswith('_')]
     args = sys.argv[1:]
     if args:
         tests = [test for test in all_tests if test in args]
-    else
+    else:
         tests = all_tests
     if not tests:
         print("Error: No tests to run")
         sys.exit(1)
     # Compile first for quicker feedback
-    for test in tests:
-        rustc(test)
+    cargo()
     # Set up mailbox once for all tests
     MAILBOX = multiprocessing.Queue()
     mailman = threading.Thread(target=write_errors)
@@ -251,7 +250,7 @@ def do_work(queue):
             else:
                 continue
         bin64, bin32, text = line.rstrip().split()
-        validate(bin64, bin32, text)
+        validate(bin64, bin32, text.decode('utf-8'))
 
 
 def decode_binary64(x):
@@ -331,7 +330,11 @@ SINGLE_ZERO_CUTOFF = MIN_SUBNORMAL_SINGLE / 2
 SINGLE_INF_CUTOFF = MAX_SINGLE + 2 ** (MAX_ULP_SINGLE - 1)
 
 def validate(bin64, bin32, text):
-    double = decode_binary64(bin64)
+    try:
+        double = decode_binary64(bin64)
+    except AssertionError:
+        print(bin64, bin32, text)
+        raise
     single = decode_binary32(bin32)
     real = Fraction(text)
 
diff --git a/src/etc/test-float-parse/few-ones.rs b/src/etc/test-float-parse/src/bin/few-ones.rs
index 2d82918aabb..6bb406a5947 100644
--- a/src/etc/test-float-parse/few-ones.rs
+++ b/src/etc/test-float-parse/src/bin/few-ones.rs
@@ -1,6 +1,4 @@
-mod _common;
-
-use _common::validate;
+use test_float_parse::validate;
 
 fn main() {
     let mut pow = vec![];
diff --git a/src/etc/test-float-parse/huge-pow10.rs b/src/etc/test-float-parse/src/bin/huge-pow10.rs
index 9a16d9c6028..722a24ffcd8 100644
--- a/src/etc/test-float-parse/huge-pow10.rs
+++ b/src/etc/test-float-parse/src/bin/huge-pow10.rs
@@ -1,6 +1,4 @@
-mod _common;
-
-use _common::validate;
+use test_float_parse::validate;
 
 fn main() {
     for e in 300..310 {
diff --git a/src/etc/test-float-parse/long-fractions.rs b/src/etc/test-float-parse/src/bin/long-fractions.rs
index 60cf85c4a60..c715bc1ac2b 100644
--- a/src/etc/test-float-parse/long-fractions.rs
+++ b/src/etc/test-float-parse/src/bin/long-fractions.rs
@@ -1,7 +1,5 @@
-mod _common;
-
-use _common::validate;
 use std::char;
+use test_float_parse::validate;
 
 fn main() {
     for n in 0..10 {
diff --git a/src/etc/test-float-parse/many-digits.rs b/src/etc/test-float-parse/src/bin/many-digits.rs
index 599986e20dd..ba166fd5607 100644
--- a/src/etc/test-float-parse/many-digits.rs
+++ b/src/etc/test-float-parse/src/bin/many-digits.rs
@@ -1,11 +1,9 @@
 extern crate rand;
 
-mod _common;
-
-use _common::{validate, SEED};
 use rand::distributions::{Range, Sample};
 use rand::{IsaacRng, Rng, SeedableRng};
 use std::char;
+use test_float_parse::{validate, SEED};
 
 fn main() {
     let mut rnd = IsaacRng::from_seed(&SEED);
diff --git a/src/etc/test-float-parse/rand-f64.rs b/src/etc/test-float-parse/src/bin/rand-f64.rs
index 39ad63945cd..6991e8be15e 100644
--- a/src/etc/test-float-parse/rand-f64.rs
+++ b/src/etc/test-float-parse/src/bin/rand-f64.rs
@@ -1,10 +1,8 @@
 extern crate rand;
 
-mod _common;
-
-use _common::{validate, SEED};
 use rand::{IsaacRng, Rng, SeedableRng};
 use std::mem::transmute;
+use test_float_parse::{validate, SEED};
 
 fn main() {
     let mut rnd = IsaacRng::from_seed(&SEED);
diff --git a/src/etc/test-float-parse/short-decimals.rs b/src/etc/test-float-parse/src/bin/short-decimals.rs
index 8b9b6f78ae3..49084eb35e8 100644
--- a/src/etc/test-float-parse/short-decimals.rs
+++ b/src/etc/test-float-parse/src/bin/short-decimals.rs
@@ -1,6 +1,4 @@
-mod _common;
-
-use _common::validate;
+use test_float_parse::validate;
 
 fn main() {
     // Skip e = 0 because small-u32 already does those.
diff --git a/src/etc/test-float-parse/subnorm.rs b/src/etc/test-float-parse/src/bin/subnorm.rs
index ba68d31e4ed..ac88747eacd 100644
--- a/src/etc/test-float-parse/subnorm.rs
+++ b/src/etc/test-float-parse/src/bin/subnorm.rs
@@ -1,7 +1,5 @@
-mod _common;
-
-use _common::validate;
 use std::mem::transmute;
+use test_float_parse::validate;
 
 fn main() {
     for bits in 0u32..(1 << 21) {
diff --git a/src/etc/test-float-parse/tiny-pow10.rs b/src/etc/test-float-parse/src/bin/tiny-pow10.rs
index 43fad5b49ee..fb6ba166380 100644
--- a/src/etc/test-float-parse/tiny-pow10.rs
+++ b/src/etc/test-float-parse/src/bin/tiny-pow10.rs
@@ -1,6 +1,4 @@
-mod _common;
-
-use _common::validate;
+use test_float_parse::validate;
 
 fn main() {
     for e in 301..327 {
diff --git a/src/etc/test-float-parse/u32-small.rs b/src/etc/test-float-parse/src/bin/u32-small.rs
index 3ae62425adf..5ec9d1eea5f 100644
--- a/src/etc/test-float-parse/u32-small.rs
+++ b/src/etc/test-float-parse/src/bin/u32-small.rs
@@ -1,6 +1,4 @@
-mod _common;
-
-use _common::validate;
+use test_float_parse::validate;
 
 fn main() {
     for i in 0..(1 << 19) {
diff --git a/src/etc/test-float-parse/u64-pow2.rs b/src/etc/test-float-parse/src/bin/u64-pow2.rs
index 7e67e2b1246..984e49200cd 100644
--- a/src/etc/test-float-parse/u64-pow2.rs
+++ b/src/etc/test-float-parse/src/bin/u64-pow2.rs
@@ -1,6 +1,4 @@
-mod _common;
-
-use _common::validate;
+use test_float_parse::validate;
 
 fn main() {
     for exp in 19..64 {
diff --git a/src/etc/test-float-parse/_common.rs b/src/etc/test-float-parse/src/lib.rs
index 9cbad5486b4..9cbad5486b4 100644
--- a/src/etc/test-float-parse/_common.rs
+++ b/src/etc/test-float-parse/src/lib.rs