Skip to content

Commit 75740fb

Browse files
committed
Revert "Merge pull request #13741 from xokdvium/toml-timestamps"
This reverts commit 53ac49f, reversing changes made to 8e5ca78. This broke nixpkgs eval test that was depending overflowing integers...
1 parent 5d3197b commit 75740fb

5 files changed

Lines changed: 25 additions & 158 deletions

File tree

packaging/dependencies.nix

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,6 @@ scope: {
6464
NIX_CFLAGS_COMPILE = "-DINITIAL_MARK_STACK_SIZE=1048576";
6565
});
6666

67-
toml11 = pkgs.toml11.overrideAttrs rec {
68-
version = "4.4.0";
69-
src = pkgs.fetchFromGitHub {
70-
owner = "ToruNiina";
71-
repo = "toml11";
72-
tag = "v${version}";
73-
hash = "sha256-sgWKYxNT22nw376ttGsTdg0AMzOwp8QH3E8mx0BZJTQ=";
74-
};
75-
};
76-
7767
# TODO Hack until https://github.com/NixOS/nixpkgs/issues/45462 is fixed.
7868
boost =
7969
(pkgs.boost.override {

src/libexpr/meson.build

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,6 @@ toml11 = dependency(
7171
method : 'cmake',
7272
include_type : 'system',
7373
)
74-
75-
configdata_priv.set(
76-
'HAVE_TOML11_4',
77-
toml11.version().version_compare('>= 4.0.0').to_int(),
78-
)
79-
8074
deps_other += toml11
8175

8276
config_priv_h = configure_file(

src/libexpr/primops/fromTOML.cc

Lines changed: 22 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,140 +1,73 @@
11
#include "nix/expr/primops.hh"
22
#include "nix/expr/eval-inline.hh"
33

4-
#include "expr-config-private.hh"
5-
64
#include <sstream>
75

86
#include <toml.hpp>
97

108
namespace nix {
119

12-
#if HAVE_TOML11_4
13-
14-
/**
15-
* This is what toml11 < 4.0 did when choosing the subsecond precision.
16-
* TOML 1.0.0 spec doesn't define how sub-millisecond ranges should be handled and calls it
17-
* implementation defined behavior. For a lack of a better choice we stick with what older versions
18-
* of toml11 did [1].
19-
*
20-
* [1]: https://github.com/ToruNiina/toml11/blob/dcfe39a783a94e8d52c885e5883a6fbb21529019/toml/datetime.hpp#L282
21-
*/
22-
static size_t normalizeSubsecondPrecision(toml::local_time lt)
23-
{
24-
auto millis = lt.millisecond;
25-
auto micros = lt.microsecond;
26-
auto nanos = lt.nanosecond;
27-
if (millis != 0 || micros != 0 || nanos != 0) {
28-
if (micros != 0 || nanos != 0) {
29-
if (nanos != 0)
30-
return 9;
31-
return 6;
32-
}
33-
return 3;
34-
}
35-
return 0;
36-
}
37-
38-
/**
39-
* Normalize date/time formats to serialize to the same strings as versions prior to toml11 4.0.
40-
*
41-
* Several things to consider:
42-
*
43-
* 1. Sub-millisecond range is represented the same way as in toml11 versions prior to 4.0. Precisioun is rounded
44-
* towards the next multiple of 3 or capped at 9 digits.
45-
* 2. Seconds must be specified. This may become optional in (yet unreleased) TOML 1.1.0, but 1.0.0 defined local time
46-
* in terms of RFC3339 [1].
47-
* 3. date-time separator (`t`, `T` or space ` `) is canonicalized to an upper T. This is compliant with RFC3339
48-
* [1] 5.6:
49-
* > Applications that generate this format SHOULD use upper case letters.
50-
*
51-
* [1]: https://datatracker.ietf.org/doc/html/rfc3339#section-5.6
52-
*/
53-
static void normalizeDatetimeFormat(toml::value & t)
54-
{
55-
if (t.is_local_datetime()) {
56-
auto & ldt = t.as_local_datetime();
57-
t.as_local_datetime_fmt() = {
58-
.delimiter = toml::datetime_delimiter_kind::upper_T,
59-
// https://datatracker.ietf.org/doc/html/rfc3339#section-5.6
60-
.has_seconds = true, // Mandated by TOML 1.0.0
61-
.subsecond_precision = normalizeSubsecondPrecision(ldt.time),
62-
};
63-
return;
64-
}
65-
66-
if (t.is_offset_datetime()) {
67-
auto & odt = t.as_offset_datetime();
68-
t.as_offset_datetime_fmt() = {
69-
.delimiter = toml::datetime_delimiter_kind::upper_T,
70-
// https://datatracker.ietf.org/doc/html/rfc3339#section-5.6
71-
.has_seconds = true, // Mandated by TOML 1.0.0
72-
.subsecond_precision = normalizeSubsecondPrecision(odt.time),
73-
};
74-
return;
75-
}
76-
77-
if (t.is_local_time()) {
78-
auto & lt = t.as_local_time();
79-
t.as_local_time_fmt() = {
80-
.has_seconds = true, // Mandated by TOML 1.0.0
81-
.subsecond_precision = normalizeSubsecondPrecision(lt),
82-
};
83-
return;
84-
}
85-
}
86-
87-
#endif
88-
8910
static void prim_fromTOML(EvalState & state, const PosIdx pos, Value ** args, Value & val)
9011
{
9112
auto toml = state.forceStringNoCtx(*args[0], pos, "while evaluating the argument passed to builtins.fromTOML");
9213

9314
std::istringstream tomlStream(std::string{toml});
9415

95-
auto visit = [&](auto & self, Value & v, toml::value t) -> void {
16+
std::function<void(Value &, toml::value)> visit;
17+
18+
visit = [&](Value & v, toml::value t) {
9619
switch (t.type()) {
9720
case toml::value_t::table: {
9821
auto table = toml::get<toml::table>(t);
99-
auto attrs = state.buildBindings(table.size());
22+
23+
size_t size = 0;
24+
for (auto & i : table) {
25+
(void) i;
26+
size++;
27+
}
28+
29+
auto attrs = state.buildBindings(size);
10030

10131
for (auto & elem : table) {
10232
forceNoNullByte(elem.first);
103-
self(self, attrs.alloc(elem.first), elem.second);
33+
visit(attrs.alloc(elem.first), elem.second);
10434
}
10535

10636
v.mkAttrs(attrs);
10737
} break;
38+
;
10839
case toml::value_t::array: {
10940
auto array = toml::get<std::vector<toml::value>>(t);
11041

11142
auto list = state.buildList(array.size());
11243
for (const auto & [n, v] : enumerate(list))
113-
self(self, *(v = state.allocValue()), array[n]);
44+
visit(*(v = state.allocValue()), array[n]);
11445
v.mkList(list);
11546
} break;
47+
;
11648
case toml::value_t::boolean:
11749
v.mkBool(toml::get<bool>(t));
11850
break;
51+
;
11952
case toml::value_t::integer:
12053
v.mkInt(toml::get<int64_t>(t));
12154
break;
55+
;
12256
case toml::value_t::floating:
12357
v.mkFloat(toml::get<NixFloat>(t));
12458
break;
59+
;
12560
case toml::value_t::string: {
12661
auto s = toml::get<std::string_view>(t);
12762
forceNoNullByte(s);
12863
v.mkString(s);
12964
} break;
65+
;
13066
case toml::value_t::local_datetime:
13167
case toml::value_t::offset_datetime:
13268
case toml::value_t::local_date:
13369
case toml::value_t::local_time: {
13470
if (experimentalFeatureSettings.isEnabled(Xp::ParseTomlTimestamps)) {
135-
#if HAVE_TOML11_4
136-
normalizeDatetimeFormat(t);
137-
#endif
13871
auto attrs = state.buildBindings(2);
13972
attrs.alloc("_type").mkString("timestamp");
14073
std::ostringstream s;
@@ -147,24 +80,16 @@ static void prim_fromTOML(EvalState & state, const PosIdx pos, Value ** args, Va
14780
throw std::runtime_error("Dates and times are not supported");
14881
}
14982
} break;
83+
;
15084
case toml::value_t::empty:
15185
v.mkNull();
15286
break;
87+
;
15388
}
15489
};
15590

15691
try {
157-
visit(
158-
visit,
159-
val,
160-
toml::parse(
161-
tomlStream,
162-
"fromTOML" /* the "filename" */
163-
#if HAVE_TOML11_4
164-
,
165-
toml::spec::v(1, 0, 0) // Be explicit that we are parsing TOML 1.0.0 without extensions
166-
#endif
167-
));
92+
visit(val, toml::parse(tomlStream, "fromTOML" /* the "filename" */));
16893
} catch (std::exception & e) { // TODO: toml::syntax_error
16994
state.error<EvalError>("while parsing TOML: %s", e.what()).atPos(pos).debugThrow();
17095
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "1234" = "value"; "127.0.0.1" = "value"; a = { b = { c = { }; }; }; arr1 = [ 1 2 3 ]; arr2 = [ "red" "yellow" "green" ]; arr3 = [ [ 1 2 ] [ 3 4 5 ] ]; arr4 = [ "all" "strings" "are the same" "type" ]; arr5 = [ [ 1 2 ] [ "a" "b" "c" ] ]; arr7 = [ 1 2 3 ]; arr8 = [ 1 2 ]; bare-key = "value"; bare_key = "value"; bin1 = 214; bool1 = true; bool2 = false; "character encoding" = "value"; d = { e = { f = { }; }; }; dog = { "tater.man" = { type = { name = "pug"; }; }; }; flt1 = 1; flt2 = 3.1415; flt3 = -0.01; flt4 = 5e+22; flt5 = 1e+06; flt6 = -0.02; flt7 = 6.626e-34; flt8 = 9.22462e+06; fruit = [ { name = "apple"; physical = { color = "red"; shape = "round"; }; variety = [ { name = "red delicious"; } { name = "granny smith"; } ]; } { name = "banana"; variety = [ { name = "plantain"; } ]; } ]; g = { h = { i = { }; }; }; hex1 = 3735928559; hex2 = 3735928559; hex3 = 3735928559; int1 = 99; int2 = 42; int3 = 0; int4 = -17; int5 = 1000; int6 = 5349221; int7 = 12345; j = { "ʞ" = { l = { }; }; }; key = "value"; key2 = "value"; ld1 = { _type = "timestamp"; value = "1979-05-27"; }; ldt1 = { _type = "timestamp"; value = "1979-05-27T07:32:00"; }; ldt10 = { _type = "timestamp"; value = "1979-05-27T00:32:00.123456789"; }; ldt11 = { _type = "timestamp"; value = "1979-05-27T00:32:00.123456789"; }; ldt2 = { _type = "timestamp"; value = "1979-05-27T07:32:00.100"; }; ldt3 = { _type = "timestamp"; value = "1979-05-27T07:32:00.120"; }; ldt4 = { _type = "timestamp"; value = "1979-05-27T07:32:00.123"; }; ldt5 = { _type = "timestamp"; value = "1979-05-27T00:32:00.123400"; }; ldt6 = { _type = "timestamp"; value = "1979-05-27T00:32:00.123450"; }; ldt7 = { _type = "timestamp"; value = "1979-05-27T00:32:00.123456"; }; ldt8 = { _type = "timestamp"; value = "1979-05-27T00:32:00.123456700"; }; ldt9 = { _type = "timestamp"; value = "1979-05-27T00:32:00.123456780"; }; lt1 = { _type = "timestamp"; value = "07:32:00"; }; lt10 = { _type = "timestamp"; value = "00:32:00.123456789"; }; lt11 = { _type = "timestamp"; value = "00:32:00.123456789"; }; lt2 = { _type = "timestamp"; value = "00:32:00.100"; }; lt3 = { _type = "timestamp"; value = "00:32:00.120"; }; lt4 = { _type = "timestamp"; value = "00:32:00.123"; }; lt5 = { _type = "timestamp"; value = "00:32:00.123400"; }; lt6 = { _type = "timestamp"; value = "00:32:00.123450"; }; lt7 = { _type = "timestamp"; value = "00:32:00.123456"; }; lt8 = { _type = "timestamp"; value = "00:32:00.123456700"; }; lt9 = { _type = "timestamp"; value = "00:32:00.123456780"; }; name = "Orange"; oct1 = 342391; oct2 = 493; odt1 = { _type = "timestamp"; value = "1979-05-27T07:32:00Z"; }; odt10 = { _type = "timestamp"; value = "1979-05-27T07:32:00.123456Z"; }; odt11 = { _type = "timestamp"; value = "1979-05-27T07:32:00.123456700Z"; }; odt12 = { _type = "timestamp"; value = "1979-05-27T07:32:00.123456780Z"; }; odt13 = { _type = "timestamp"; value = "1979-05-27T07:32:00.123456789Z"; }; odt14 = { _type = "timestamp"; value = "1979-05-27T07:32:00.123456789Z"; }; odt2 = { _type = "timestamp"; value = "1979-05-27T00:32:00-07:00"; }; odt3 = { _type = "timestamp"; value = "1979-05-27T00:32:00.999999-07:00"; }; odt4 = { _type = "timestamp"; value = "1979-05-27T07:32:00Z"; }; odt5 = { _type = "timestamp"; value = "1979-05-27T07:32:00.100Z"; }; odt6 = { _type = "timestamp"; value = "1979-05-27T07:32:00.120Z"; }; odt7 = { _type = "timestamp"; value = "1979-05-27T07:32:00.123Z"; }; odt8 = { _type = "timestamp"; value = "1979-05-27T07:32:00.123400Z"; }; odt9 = { _type = "timestamp"; value = "1979-05-27T07:32:00.123450Z"; }; physical = { color = "orange"; shape = "round"; }; products = [ { name = "Hammer"; sku = 738594937; } { } { color = "gray"; name = "Nail"; sku = 284758393; } ]; "quoted \"value\"" = "value"; site = { "google.com" = true; }; str = "I'm a string. \"You can quote me\". Name\tJosé\nLocation\tSF."; table-1 = { key1 = "some string"; key2 = 123; }; table-2 = { key1 = "another string"; key2 = 456; }; x = { y = { z = { w = { animal = { type = { name = "pug"; }; }; name = { first = "Tom"; last = "Preston-Werner"; }; point = { x = 1; y = 2; }; }; }; }; }; "ʎǝʞ" = "value"; }
1+
{ "1234" = "value"; "127.0.0.1" = "value"; a = { b = { c = { }; }; }; arr1 = [ 1 2 3 ]; arr2 = [ "red" "yellow" "green" ]; arr3 = [ [ 1 2 ] [ 3 4 5 ] ]; arr4 = [ "all" "strings" "are the same" "type" ]; arr5 = [ [ 1 2 ] [ "a" "b" "c" ] ]; arr7 = [ 1 2 3 ]; arr8 = [ 1 2 ]; bare-key = "value"; bare_key = "value"; bin1 = 214; bool1 = true; bool2 = false; "character encoding" = "value"; d = { e = { f = { }; }; }; dog = { "tater.man" = { type = { name = "pug"; }; }; }; flt1 = 1; flt2 = 3.1415; flt3 = -0.01; flt4 = 5e+22; flt5 = 1e+06; flt6 = -0.02; flt7 = 6.626e-34; flt8 = 9.22462e+06; fruit = [ { name = "apple"; physical = { color = "red"; shape = "round"; }; variety = [ { name = "red delicious"; } { name = "granny smith"; } ]; } { name = "banana"; variety = [ { name = "plantain"; } ]; } ]; g = { h = { i = { }; }; }; hex1 = 3735928559; hex2 = 3735928559; hex3 = 3735928559; int1 = 99; int2 = 42; int3 = 0; int4 = -17; int5 = 1000; int6 = 5349221; int7 = 12345; j = { "ʞ" = { l = { }; }; }; key = "value"; key2 = "value"; ld1 = { _type = "timestamp"; value = "1979-05-27"; }; ldt1 = { _type = "timestamp"; value = "1979-05-27T07:32:00"; }; ldt2 = { _type = "timestamp"; value = "1979-05-27T00:32:00.999999"; }; lt1 = { _type = "timestamp"; value = "07:32:00"; }; lt2 = { _type = "timestamp"; value = "00:32:00.999999"; }; name = "Orange"; oct1 = 342391; oct2 = 493; odt1 = { _type = "timestamp"; value = "1979-05-27T07:32:00Z"; }; odt2 = { _type = "timestamp"; value = "1979-05-27T00:32:00-07:00"; }; odt3 = { _type = "timestamp"; value = "1979-05-27T00:32:00.999999-07:00"; }; odt4 = { _type = "timestamp"; value = "1979-05-27T07:32:00Z"; }; physical = { color = "orange"; shape = "round"; }; products = [ { name = "Hammer"; sku = 738594937; } { } { color = "gray"; name = "Nail"; sku = 284758393; } ]; "quoted \"value\"" = "value"; site = { "google.com" = true; }; str = "I'm a string. \"You can quote me\". Name\tJosé\nLocation\tSF."; table-1 = { key1 = "some string"; key2 = 123; }; table-2 = { key1 = "another string"; key2 = 456; }; x = { y = { z = { w = { animal = { type = { name = "pug"; }; }; name = { first = "Tom"; last = "Preston-Werner"; }; point = { x = 1; y = 2; }; }; }; }; }; "ʎǝʞ" = "value"; }

tests/functional/lang/eval-okay-fromTOML-timestamps.nix

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -55,53 +55,11 @@ builtins.fromTOML ''
5555
odt2 = 1979-05-27T00:32:00-07:00
5656
odt3 = 1979-05-27T00:32:00.999999-07:00
5757
odt4 = 1979-05-27 07:32:00Z
58-
# milliseconds
59-
odt5 = 1979-05-27 07:32:00.1Z
60-
odt6 = 1979-05-27 07:32:00.12Z
61-
odt7 = 1979-05-27 07:32:00.123Z
62-
# microseconds
63-
odt8 = 1979-05-27t07:32:00.1234Z
64-
odt9 = 1979-05-27t07:32:00.12345Z
65-
odt10 = 1979-05-27t07:32:00.123456Z
66-
# nanoseconds
67-
odt11 = 1979-05-27 07:32:00.1234567Z
68-
odt12 = 1979-05-27 07:32:00.12345678Z
69-
odt13 = 1979-05-27 07:32:00.123456789Z
70-
# no more precision after nanoseconds
71-
odt14 = 1979-05-27t07:32:00.1234567891Z
72-
7358
ldt1 = 1979-05-27T07:32:00
74-
# milliseconds
75-
ldt2 = 1979-05-27T07:32:00.1
76-
ldt3 = 1979-05-27T07:32:00.12
77-
ldt4 = 1979-05-27T07:32:00.123
78-
# microseconds
79-
ldt5 = 1979-05-27t00:32:00.1234
80-
ldt6 = 1979-05-27t00:32:00.12345
81-
ldt7 = 1979-05-27t00:32:00.123456
82-
# nanoseconds
83-
ldt8 = 1979-05-27 00:32:00.1234567
84-
ldt9 = 1979-05-27 00:32:00.12345678
85-
ldt10 = 1979-05-27 00:32:00.123456789
86-
# no more precision after nanoseconds
87-
ldt11 = 1979-05-27t00:32:00.1234567891
88-
59+
ldt2 = 1979-05-27T00:32:00.999999
8960
ld1 = 1979-05-27
9061
lt1 = 07:32:00
91-
# milliseconds
92-
lt2 = 00:32:00.1
93-
lt3 = 00:32:00.12
94-
lt4 = 00:32:00.123
95-
# microseconds
96-
lt5 = 00:32:00.1234
97-
lt6 = 00:32:00.12345
98-
lt7 = 00:32:00.123456
99-
# nanoseconds
100-
lt8 = 00:32:00.1234567
101-
lt9 = 00:32:00.12345678
102-
lt10 = 00:32:00.123456789
103-
# no more precision after nanoseconds
104-
lt11 = 00:32:00.1234567891
62+
lt2 = 00:32:00.999999
10563
10664
arr1 = [ 1, 2, 3 ]
10765
arr2 = [ "red", "yellow", "green" ]

0 commit comments

Comments
 (0)