make dragonbox opt-in via -d:nimFpRoundtrips (#18504)

* make dragonbox opt-in via -d:nimFpRoundtrips

* make tests green again

* make tests green again
This commit is contained in:
Andreas Rumpf 2021-07-16 18:29:49 +02:00 • committed by GitHub
commit 25efb53862
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 35 additions and 27 deletions

View file

@ -76,9 +76,6 @@
- `json` and `jsonutils` now serialize NaN, Inf, -Inf as strings, so that - `json` and `jsonutils` now serialize NaN, Inf, -Inf as strings, so that
`%[NaN, -Inf]` is the string `["nan","-inf"]` instead of `[nan,-inf]` which was invalid json. `%[NaN, -Inf]` is the string `["nan","-inf"]` instead of `[nan,-inf]` which was invalid json.
- `system.addFloat` now uses the "Dragonbox" algorithm, which ensures correct roundtrips of floating point
numbers, that the minimum length representation of a floating point number is used and correct rounding.
Use `-d:nimLegacyAddFloat` for a transition period.
- `strformat` is now part of `include std/prelude`. - `strformat` is now part of `include std/prelude`.
@ -102,6 +99,12 @@
added support for parenthesized expressions. added support for parenthesized expressions.
added support for const string's instead of just string literals added support for const string's instead of just string literals
- `system.addFloat` and `system.$` now can produce string representations of floating point numbers
that are minimal in size and that "roundtrip" (via the "Dragonbox" algorithm). This currently has
to be enabled via `-d:nimFpRoundtrips`. It is expected that this behavior becomes the new default
in upcoming versions.
- Fixed buffer overflow bugs in `net` - Fixed buffer overflow bugs in `net`
- Exported `sslHandle` from `net` and `asyncnet`. - Exported `sslHandle` from `net` and `asyncnet`.
@ -116,8 +119,6 @@
the OpenSSL DLLs (e.g. libssl-1_1-x64.dll, libcrypto-1_1-x64.dll) you the OpenSSL DLLs (e.g. libssl-1_1-x64.dll, libcrypto-1_1-x64.dll) you
now also need to ship `cacert.pem` with your `.exe` file. now also need to ship `cacert.pem` with your `.exe` file.
- Make `{.requiresInit.}` pragma to work for `distinct` types.
- `typetraits`: - `typetraits`:
`distinctBase` now is identity instead of error for non distinct types. `distinctBase` now is identity instead of error for non distinct types.
Added `enumLen` to return the number of elements in an enum. Added `enumLen` to return the number of elements in an enum.
@ -468,7 +469,6 @@
with `--styleCheck:error` or `--styleCheck:hint`. with `--styleCheck:error` or `--styleCheck:hint`.
## Tool changes ## Tool changes
- Latex doc generation is revised: output `.tex` files should be compiled - Latex doc generation is revised: output `.tex` files should be compiled

View file

@ -7,7 +7,7 @@
# distribution, for details about the copyright. # distribution, for details about the copyright.
# #
when not defined(nimLegacyAddFloat) and not defined(nimscript) and when defined(nimFpRoundtrips) and not defined(nimscript) and
not defined(js) and defined(nimHasDragonBox): not defined(js) and defined(nimHasDragonBox):
import dragonbox import dragonbox

View file

@ -97,7 +97,7 @@ proc nimFloatToStr(f: float): string {.compilerproc.} =
result = newStringOfCap(8) result = newStringOfCap(8)
result.addFloat f result.addFloat f
when not defined(nimLegacyAddFloat) and not defined(nimscript) and when defined(nimFpRoundtrips) and not defined(nimscript) and
not defined(js) and defined(nimHasDragonBox): not defined(js) and defined(nimHasDragonBox):
import schubfach import schubfach

View file

@ -13,12 +13,12 @@ treportunused.nim(30, 5) Hint: 's8' is declared but not used [XDeclaredButNotUse
treportunused.nim(31, 5) Hint: 's9' is declared but not used [XDeclaredButNotUsed] treportunused.nim(31, 5) Hint: 's9' is declared but not used [XDeclaredButNotUsed]
treportunused.nim(32, 6) Hint: 's10' is declared but not used [XDeclaredButNotUsed] treportunused.nim(32, 6) Hint: 's10' is declared but not used [XDeclaredButNotUsed]
treportunused.nim(33, 6) Hint: 's11' is declared but not used [XDeclaredButNotUsed] treportunused.nim(33, 6) Hint: 's11' is declared but not used [XDeclaredButNotUsed]
treportunused.nim(37, 3) Hint: 'v0.99' is declared but not used [XDeclaredButNotUsed]
treportunused.nim(38, 3) Hint: 'v0.99.99' is declared but not used [XDeclaredButNotUsed]
''' '''
action: compile action: compile
""" """
#treportunused.nim(37, 3) Hint: 'v0.99' is declared but not used [XDeclaredButNotUsed]
#treportunused.nim(38, 3) Hint: 'v0.99.99' is declared but not used [XDeclaredButNotUsed]
# bug #9764 # bug #9764
iterator s1(a:string): int = discard iterator s1(a:string): int = discard
iterator s2(): int = discard iterator s2(): int = discard
@ -32,7 +32,9 @@ var s9: int
type s10 = object type s10 = object
type s11 = type(1.2) type s11 = type(1.2)
# https://github.com/nim-lang/Nim/issues/14407 when false:
let # enabled again when Nim bootstraps with -d:nimFpRoundtrips
`v0.99` = "0.99" # https://github.com/nim-lang/Nim/issues/14407
`v0.99.99` = "0.99.99" let
`v0.99` = "0.99"
`v0.99.99` = "0.99.99"

1
tests/float/nim.cfg Normal file
View file

@ -0,0 +1 @@
-d:nimFpRoundtrips

View file

@ -66,6 +66,8 @@ template main =
var a = 1.1'f32 var a = 1.1'f32
doAssert $a == "1.1", $a # was failing doAssert $a == "1.1", $a # was failing
proc runtimeOnlyTests =
# enable for 'static' once -d:nimFpRoundtrips became the default
block: # bug #7717 block: # bug #7717
proc test(f: float) = proc test(f: float) =
let f2 = $f let f2 = $f
@ -82,3 +84,5 @@ template main =
static: main() static: main()
main() main()
runtimeOnlyTests()

View file

@ -303,7 +303,7 @@ let jsonNode = %*mynode
doAssert $jsonNode == """{"kind":"P","pChildren":[{"kind":"Text","textStr":"mychild"},{"kind":"Br"}]}""" doAssert $jsonNode == """{"kind":"P","pChildren":[{"kind":"Text","textStr":"mychild"},{"kind":"Br"}]}"""
doAssert $jsonNode.to(ContentNode) == """(kind: P, pChildren: @[(kind: Text, textStr: "mychild"), (kind: Br)])""" doAssert $jsonNode.to(ContentNode) == """(kind: P, pChildren: @[(kind: Text, textStr: "mychild"), (kind: Br)])"""
block: # bug #17383 when defined(nimFpRoundtrips): # bug #17383
testRoundtrip(int32.high): "2147483647" testRoundtrip(int32.high): "2147483647"
testRoundtrip(uint32.high): "4294967295" testRoundtrip(uint32.high): "4294967295"
when int.sizeof == 4: when int.sizeof == 4:
@ -316,7 +316,7 @@ block: # bug #17383
testRoundtrip(int64.high): "9223372036854775807" testRoundtrip(int64.high): "9223372036854775807"
testRoundtrip(uint64.high): "18446744073709551615" testRoundtrip(uint64.high): "18446744073709551615"
block: # bug #18007 when defined(nimFpRoundtrips): # bug #18007
testRoundtrip([NaN, Inf, -Inf, 0.0, -0.0, 1.0]): """["nan","inf","-inf",0.0,-0.0,1.0]""" testRoundtrip([NaN, Inf, -Inf, 0.0, -0.0, 1.0]): """["nan","inf","-inf",0.0,-0.0,1.0]"""
# pending https://github.com/nim-lang/Nim/issues/18025 use: # pending https://github.com/nim-lang/Nim/issues/18025 use:
# testRoundtrip([float32(NaN), Inf, -Inf, 0.0, -0.0, 1.0]) # testRoundtrip([float32(NaN), Inf, -Inf, 0.0, -0.0, 1.0])
@ -332,7 +332,7 @@ block: # bug #18007
testRoundtripVal(0.0): "0.0" testRoundtripVal(0.0): "0.0"
testRoundtripVal(-0.0): "-0.0" testRoundtripVal(-0.0): "-0.0"
block: # bug #15397, bug #13196 when defined(nimFpRoundtrips): # bug #15397, bug #13196
testRoundtripVal(1.0 + epsilon(float64)): "1.0000000000000002" testRoundtripVal(1.0 + epsilon(float64)): "1.0000000000000002"
testRoundtripVal(0.12345678901234567890123456789): "0.12345678901234568" testRoundtripVal(0.12345678901234567890123456789): "0.12345678901234568"

View file

@ -44,7 +44,7 @@ proc `$`(a: MyEnum): string =
if a == me2: "me2Modif" if a == me2: "me2Modif"
else: system.`$`(a) else: system.`$`(a)
template fn() = template fn() =
block: # toJson, jsonTo block: # toJson, jsonTo
type Foo = distinct float type Foo = distinct float
testRoundtrip('x', """120""") testRoundtrip('x', """120""")
@ -161,15 +161,16 @@ template fn() =
doAssert b[2].signbit doAssert b[2].signbit
doAssert not b[3].signbit doAssert not b[3].signbit
block: # bug #15397, bug #13196 when defined(nimFpRoundtrips):
let a = 0.1 block: # bug #15397, bug #13196
let x = 0.12345678901234567890123456789 let a = 0.1
let b = (a + 0.2, 0.3, x) let x = 0.12345678901234567890123456789
testRoundtripVal(b): "[0.30000000000000004,0.3,0.12345678901234568]" let b = (a + 0.2, 0.3, x)
testRoundtripVal(b): "[0.30000000000000004,0.3,0.12345678901234568]"
testRoundtripVal(0.12345678901234567890123456789): "0.12345678901234568" testRoundtripVal(0.12345678901234567890123456789): "0.12345678901234568"
testRoundtripVal(epsilon(float64)): "2.220446049250313e-16" testRoundtripVal(epsilon(float64)): "2.220446049250313e-16"
testRoundtripVal(1.0 + epsilon(float64)): "1.0000000000000002" testRoundtripVal(1.0 + epsilon(float64)): "1.0000000000000002"
block: # case object block: # case object
type Foo = object type Foo = object
@ -433,7 +434,7 @@ template fn() =
"""{"b": true, "bt": false, "btf": "test"}""" """{"b": true, "bt": false, "btf": "test"}"""
testRoundtrip(Variant(b: true, bt: true, btt: 'c')): testRoundtrip(Variant(b: true, bt: true, btt: 'c')):
"""{"b": true, "bt": true, "btt": "c"}""" """{"b": true, "bt": true, "btt": "c"}"""
# TODO: Add additional tests with missing and extra JSON keys, both when # TODO: Add additional tests with missing and extra JSON keys, both when
# allowed and forbidden analogous to the tests for the not nested # allowed and forbidden analogous to the tests for the not nested
# variant objects. # variant objects.