mirror of
https://github.com/gorules/zen.git
synced 2026-12-04 08:09:17 +00:00
* feat(expression): lane VM and typed-mask engine for batch and columnar evaluation Adds a register-based lane VM (core/expression/src/lane) and a typed-mask engine (core/expression/src/typed) that evaluate ZEN expressions over batches and columns, matching the stack VM's results. zen-types gains shape-backed objects and dot-path helpers; existing public APIs only grow. The lane VM has no expression size limit: deep and wide expressions are compiled and run with the same stack growth the parser uses. ZEN_EXPRESSION_CONFIG.lane (off by default) switches Isolate::run_standard and run_unary to the lane VM at runtime. Lane internals and the typed module are doc(hidden); the documented entry points are LaneProgram, LaneRunner, Session, Columns and Output. Includes an executable specification of the expression language (core/expression/tests/spec, 28,852 cases) with differential tests that run every lane path against the stack VM. zen-expression and zen-types now declare rust-version 1.88. * refactor(types): remove the shape transition cap Shapes are freed when nothing uses them, so the 4,096-children cap per shape no longer bounds memory. Shape::with, Shape::of and Shape::without now always return a shape; objects only switch to a hash map past SPILL_AT keys, as on master. * fix(expression): debug-profile stack safety and Windows test build CI runs tests in the debug profile, where frames are larger and tail recursion is not optimised. Recursive lane, typed and parser helpers now grow the stack like the rest (Const::number, the kernel builder, typed lowering and lookup, lane compile helpers, Node::member_key). The parser's closure depth counter is u32 instead of u8, so 256 nested closures no longer wrap. median([]) and empty templates no longer overflow in debug builds; release results are unchanged. The deep/wide test runs on a 256 KiB stack so unprotected recursion fails quickly in any profile. The conformance helper compares with as_str(), which is unambiguous on Windows. * fix(expression): stack checks in the lane executor, LF test data on Windows In x86-64 debug builds Executor::cold has a ~93 KB frame, so nested closures (execute -> cold -> body) could use more stack between two checks than the stack-growth margin and overflow. execute and cold now check the stack themselves; both run per instruction batch, not per row. The expression test data is checked out with LF on every platform. Windows runners converted it to CRLF, which broke multi-line spec cases.
12 KiB
12 KiB
| 1 | expression (string);input (json 5);output (json 5);note |
|---|---|
| 2 | # add(n, unit): every unit and alias |
| 3 | d('2023-10-15').add(1, 'seconds');;'2023-10-15T00:00:01Z' |
| 4 | d('2023-10-15').add(1, 'second');;'2023-10-15T00:00:01Z' |
| 5 | d('2023-10-15').add(1, 'secs');;'2023-10-15T00:00:01Z' |
| 6 | d('2023-10-15').add(1, 'sec');;'2023-10-15T00:00:01Z' |
| 7 | d('2023-10-15').add(1, 's');;'2023-10-15T00:00:01Z' |
| 8 | d('2023-10-15').add(1, 'minutes');;'2023-10-15T00:01:00Z' |
| 9 | d('2023-10-15').add(1, 'minute');;'2023-10-15T00:01:00Z' |
| 10 | d('2023-10-15').add(1, 'min');;'2023-10-15T00:01:00Z' |
| 11 | d('2023-10-15').add(1, 'mins');;'2023-10-15T00:01:00Z' |
| 12 | d('2023-10-15').add(1, 'm');;'2023-10-15T00:01:00Z' |
| 13 | d('2023-10-15').add(1, 'hours');;'2023-10-15T01:00:00Z' |
| 14 | d('2023-10-15').add(1, 'hour');;'2023-10-15T01:00:00Z' |
| 15 | d('2023-10-15').add(1, 'hr');;'2023-10-15T01:00:00Z' |
| 16 | d('2023-10-15').add(1, 'hrs');;'2023-10-15T01:00:00Z' |
| 17 | d('2023-10-15').add(1, 'h');;'2023-10-15T01:00:00Z' |
| 18 | d('2023-10-15').add(1, 'days');;'2023-10-16T00:00:00Z' |
| 19 | d('2023-10-15').add(1, 'day');;'2023-10-16T00:00:00Z' |
| 20 | d('2023-10-15').add(1, 'd');;'2023-10-16T00:00:00Z' |
| 21 | d('2023-10-15').add(1, 'weeks');;'2023-10-22T00:00:00Z' |
| 22 | d('2023-10-15').add(1, 'week');;'2023-10-22T00:00:00Z' |
| 23 | d('2023-10-15').add(1, 'w');;'2023-10-22T00:00:00Z' |
| 24 | d('2023-10-15').add(1, 'months');;'2023-11-15T00:00:00Z' |
| 25 | d('2023-10-15').add(1, 'month');;'2023-11-15T00:00:00Z' |
| 26 | d('2023-10-15').add(1, 'mo');;'2023-11-15T00:00:00Z' |
| 27 | d('2023-10-15').add(1, 'M');;'2023-11-15T00:00:00Z' |
| 28 | d('2023-10-15').add(1, 'quarters');;'2024-01-15T00:00:00Z' |
| 29 | d('2023-10-15').add(1, 'quarter');;'2024-01-15T00:00:00Z' |
| 30 | d('2023-10-15').add(1, 'qtr');;'2024-01-15T00:00:00Z' |
| 31 | d('2023-10-15').add(1, 'q');;'2024-01-15T00:00:00Z' |
| 32 | d('2023-10-15').add(1, 'years');;'2024-10-15T00:00:00Z' |
| 33 | d('2023-10-15').add(1, 'year');;'2024-10-15T00:00:00Z' |
| 34 | d('2023-10-15').add(1, 'y');;'2024-10-15T00:00:00Z' |
| 35 | # add(n, unit): unknown units and case sensitivity |
| 36 | d('2023-10-15').add(1, 'ms');;!error |
| 37 | d('2023-10-15').add(1, 'millisecond');;!error |
| 38 | d('2023-10-15').add(1, 'D');;!error |
| 39 | d('2023-10-15').add(1, 'Y');;!error |
| 40 | d('2023-10-15').add(1, 'H');;!error |
| 41 | d('2023-10-15').add(1, 'W');;!error |
| 42 | d('2023-10-15').add(1, 'S');;!error |
| 43 | d('2023-10-15').add(1, 'Day');;!error |
| 44 | d('2023-10-15').add(1, 'fortnight');;!error |
| 45 | d('2023-10-15').add(1, '');;!error |
| 46 | d('2023-10-15').add(1);;!error |
| 47 | d('2023-10-15').add(null);;!error |
| 48 | d('2023-10-15').add(true, 'd');;!error |
| 49 | d('2023-10-15').add(1, null);;!error |
| 50 | # add(n, unit): zero, negative, fractional and large amounts |
| 51 | d('2023-10-15').add(0, 'd');;'2023-10-15T00:00:00Z' |
| 52 | d('2023-10-15').add(-1, 'd');;'2023-10-14T00:00:00Z' |
| 53 | d('2023-10-15').add(-1, 'M');;'2023-09-15T00:00:00Z' |
| 54 | d('2023-10-15').add(-1, 'y');;'2022-10-15T00:00:00Z' |
| 55 | d('2023-10-15').add(-2, 'q');;'2023-04-15T00:00:00Z' |
| 56 | d('2023-10-15').add(1.5, 'h');;'2023-10-15T01:30:00Z' |
| 57 | d('2023-10-15').add(1.5, 'd');;'2023-10-16T12:00:00Z' |
| 58 | d('2023-10-15').add(0.5, 'm');;'2023-10-15T00:00:30Z' |
| 59 | d('2023-10-15').add(0.5, 'w');;'2023-10-18T12:00:00Z' |
| 60 | d('2023-10-15').add(0.5, 's').timestamp();;1697328000000;question: sub-second amounts are truncated to whole seconds |
| 61 | d('2023-10-15').add(1.5, 'M');;'2023-11-15T00:00:00Z';question: fractional calendar amounts are truncated to whole months |
| 62 | d('2023-10-15').add(1.9, 'y');;'2024-10-15T00:00:00Z';question: fractional calendar amounts are truncated to whole years |
| 63 | d('2023-10-15').add(-1.5, 'M');;'2023-09-15T00:00:00Z';question: fractional calendar amounts are truncated toward zero |
| 64 | d('2023-10-15').add(1000, 'y');;'3023-10-15T00:00:00Z' |
| 65 | d('2023-10-15').add(10000, 'd');;'2051-03-02T00:00:00Z' |
| 66 | d('2023-10-15').add(1000000, 'y');;'Invalid date' |
| 67 | d('2023-10-15').add(1e30, 's');;!error |
| 68 | # sub(n, unit) |
| 69 | d('2023-10-15').sub(1, 's');;'2023-10-14T23:59:59Z' |
| 70 | d('2023-10-15').sub(1, 'm');;'2023-10-14T23:59:00Z' |
| 71 | d('2023-10-15').sub(1, 'h');;'2023-10-14T23:00:00Z' |
| 72 | d('2023-10-15').sub(1, 'd');;'2023-10-14T00:00:00Z' |
| 73 | d('2023-10-15').sub(1, 'w');;'2023-10-08T00:00:00Z' |
| 74 | d('2023-10-15').sub(1, 'M');;'2023-09-15T00:00:00Z' |
| 75 | d('2023-10-15').sub(1, 'q');;'2023-07-15T00:00:00Z' |
| 76 | d('2023-10-15').sub(1, 'y');;'2022-10-15T00:00:00Z' |
| 77 | d('2023-10-15').sub(-1, 'd');;'2023-10-16T00:00:00Z' |
| 78 | d('2023-10-15').sub(13, 'M');;'2022-09-15T00:00:00Z' |
| 79 | d('2023-01-01').sub(1, 's');;'2022-12-31T23:59:59Z' |
| 80 | d('2023-10-15').sub(1, 'ms');;!error |
| 81 | # duration strings |
| 82 | d('2023-10-15').add('1d');;'2023-10-16T00:00:00Z' |
| 83 | d('2023-10-15').add('1day');;'2023-10-16T00:00:00Z' |
| 84 | d('2023-10-15').add('2days');;'2023-10-17T00:00:00Z' |
| 85 | d('2023-10-15').add('1 d');;'2023-10-16T00:00:00Z' |
| 86 | d('2023-10-15').add(' 1d ');;'2023-10-16T00:00:00Z' |
| 87 | d('2023-10-15').add('2h 30m');;'2023-10-15T02:30:00Z' |
| 88 | d('2023-10-15').add('2h30m');;'2023-10-15T02:30:00Z' |
| 89 | d('2023-10-15').add('1w');;'2023-10-22T00:00:00Z' |
| 90 | d('2023-10-15').add('36h');;'2023-10-16T12:00:00Z' |
| 91 | d('2023-10-15').add('90m');;'2023-10-15T01:30:00Z' |
| 92 | d('2023-10-15').add('45s');;'2023-10-15T00:00:45Z' |
| 93 | d('2023-10-15').add('1M');;'2023-11-15T00:00:00Z' |
| 94 | d('2023-10-15').add('1m');;'2023-10-15T00:01:00Z' |
| 95 | d('2023-10-15').add('1mo');;'2023-11-15T00:00:00Z' |
| 96 | d('2023-10-15').add('1q');;'2024-01-15T00:00:00Z' |
| 97 | d('2023-10-15').add('1y');;'2024-10-15T00:00:00Z' |
| 98 | d('2023-10-15').add('1y 2M 3d 4h 5m 6s');;'2024-12-18T04:05:06Z' |
| 99 | d('2023-10-15').add('1d 5h');;'2023-10-16T05:00:00Z' |
| 100 | d('2023-10-15').add('1d 1d');;'2023-10-17T00:00:00Z' |
| 101 | d('2023-10-15').add('1M 1M');;'2023-12-15T00:00:00Z';bug: repeated month components overwrite instead of accumulating (hours and days do accumulate) |
| 102 | d('2023-10-15').add('1y 1y');;'2025-10-15T00:00:00Z';bug: repeated year components overwrite instead of accumulating |
| 103 | d('2023-10-15').add('1q 1M');;'2024-02-15T00:00:00Z';bug: a month component overwrites the preceding quarter instead of adding to it |
| 104 | d('2023-10-15').add('0d');;'2023-10-15T00:00:00Z' |
| 105 | d('2023-10-15').add('100000d');;'2297-07-30T00:00:00Z' |
| 106 | d('2023-10-15').sub('1d');;'2023-10-14T00:00:00Z' |
| 107 | d('2023-10-15').sub('2h 30m');;'2023-10-14T21:30:00Z' |
| 108 | d('2023-10-15').sub('1y 1M');;'2022-09-15T00:00:00Z' |
| 109 | d('2023-10-15').add('');;!error |
| 110 | d('2023-10-15').add(' ');;!error |
| 111 | d('2023-10-15').add('d');;!error |
| 112 | d('2023-10-15').add('10');;!error |
| 113 | d('2023-10-15').add('1x');;!error |
| 114 | d('2023-10-15').add('1D');;!error |
| 115 | d('2023-10-15').add('1ms');;!error |
| 116 | d('2023-10-15').add('-1d');;!error |
| 117 | d('2023-10-15').add('1.5h');;!error |
| 118 | d('2023-10-15').add('1d,2h');;!error |
| 119 | d('2023-10-15').add('P1D');;!error |
| 120 | d('2023-10-15').add('99999999999999999999d');;!error |
| 121 | # month-end clamping |
| 122 | d('2023-01-31').add(1, 'M');;'2023-02-28T00:00:00Z' |
| 123 | d('2024-01-31').add(1, 'M');;'2024-02-29T00:00:00Z' |
| 124 | d('2023-01-31').add(2, 'M');;'2023-03-31T00:00:00Z' |
| 125 | d('2023-03-31').add(1, 'M');;'2023-04-30T00:00:00Z' |
| 126 | d('2023-03-31').sub(1, 'M');;'2023-02-28T00:00:00Z' |
| 127 | d('2024-03-31').sub(1, 'M');;'2024-02-29T00:00:00Z' |
| 128 | d('2023-05-31').add(1, 'q');;'2023-08-31T00:00:00Z' |
| 129 | d('2023-11-30').add(1, 'q');;'2024-02-29T00:00:00Z' |
| 130 | d('2023-01-31').add(1, 'M').add(1, 'M');;'2023-03-28T00:00:00Z' |
| 131 | d('2023-12-31').add(1, 'M');;'2024-01-31T00:00:00Z' |
| 132 | d('2023-12-31').add(2, 'M');;'2024-02-29T00:00:00Z' |
| 133 | d('1900-01-31').add(1, 'M');;'1900-02-28T00:00:00Z' |
| 134 | d('2000-01-31').add(1, 'M');;'2000-02-29T00:00:00Z' |
| 135 | d('2024-02-29').add(12, 'M');;'2025-02-28T00:00:00Z' |
| 136 | d('2024-02-29').add(48, 'M');;'2028-02-29T00:00:00Z' |
| 137 | d('2024-02-29').add(4, 'y');;'2028-02-29T00:00:00Z' |
| 138 | d('2024-02-29').add(1, 'y');;'2025-02-28T00:00:00Z';bug: adding a year to Feb 29 gives an invalid date instead of clamping to Feb 28 like months do |
| 139 | d('2024-02-29').sub(1, 'y');;'2023-02-28T00:00:00Z';bug: subtracting a year from Feb 29 gives an invalid date instead of clamping |
| 140 | d('2024-02-29').add('1y');;'2025-02-28T00:00:00Z';bug: adding a year to Feb 29 gives an invalid date instead of clamping |
| 141 | d('2024-02-29').add(100, 'y');;'2124-02-29T00:00:00Z' |
| 142 | d('2000-02-29').add(100, 'y');;'2100-02-28T00:00:00Z';bug: 2100 is not a leap year, the result should clamp to Feb 28 instead of being invalid |
| 143 | d('2024-02-29').add(1, 'q');;'2024-05-29T00:00:00Z' |
| 144 | # duration components apply from the smallest unit up (seconds, then months, then years) |
| 145 | d('2023-01-30').add('1M 1d');;'2023-02-28T00:00:00Z';question: seconds/days apply before months; applying the largest unit first (Temporal, moment) would give 2023-03-01 |
| 146 | d('2024-02-28').add('1y 1d');;'Invalid date';question: the day is applied first (Feb 29) and the year then fails; largest-first would give 2025-03-01 |
| 147 | # date arithmetic through operators is not defined |
| 148 | d('2023-10-15') + '1d';;'2023-10-15T00:00:00Z1d' |
| 149 | d('2023-10-15') - d('2023-10-14');;!error |
| 150 | d('2023-10-15') + 86400000;;!error |
| 151 | # add/sub on an invalid date stays invalid |
| 152 | d('foo').add(1, 'd');;'Invalid date' |
| 153 | d('foo').sub('1d');;'Invalid date' |
| 154 | d(null).add(1, 'M').isValid();;false |
| 155 | # add/sub on rows: repeated dates, month ends, leap days, invalid, missing |
| 156 | d(s).add(1, 'month');{s: '2023-01-31'};'2023-02-28T00:00:00Z' |
| 157 | d(s).add(1, 'month');{s: '2023-01-31'};'2023-02-28T00:00:00Z' |
| 158 | d(s).add(1, 'month');{s: '2024-01-31'};'2024-02-29T00:00:00Z' |
| 159 | d(s).add(1, 'month');{s: '2023-12-15 13:45'};'2024-01-15T13:45:00Z' |
| 160 | d(s).add(1, 'month');{s: '2024-02-29'};'2024-03-29T00:00:00Z' |
| 161 | d(s).add(1, 'month');{s: 'garbage'};'Invalid date' |
| 162 | d(s).add(1, 'month');{s: null};'Invalid date' |
| 163 | d(s).add(1, 'month');{};'Invalid date' |
| 164 | d(s).add(1, 'month');{s: 0};'1970-02-01T00:00:00Z' |
| 165 | d(s).add(1, 'y');{s: '2023-06-15'};'2024-06-15T00:00:00Z' |
| 166 | d(s).add(1, 'y');{s: '2023-06-15'};'2024-06-15T00:00:00Z' |
| 167 | d(s).add(1, 'y');{s: '2024-02-29'};'2025-02-28T00:00:00Z';bug: adding a year to Feb 29 gives an invalid date instead of clamping |
| 168 | d(s).add(1, 'y');{s: '2023-02-28'};'2024-02-28T00:00:00Z' |
| 169 | d(s).add(1, 'y');{s: '1999-12-31 23:59:59'};'2000-12-31T23:59:59Z' |
| 170 | d(s).add(1, 'y');{s: 'x'};'Invalid date' |
| 171 | d(s).sub(1, 'd');{s: '2024-03-01'};'2024-02-29T00:00:00Z' |
| 172 | d(s).sub(1, 'd');{s: '2023-03-01'};'2023-02-28T00:00:00Z' |
| 173 | d(s).sub(1, 'd');{s: '2023-01-01'};'2022-12-31T00:00:00Z' |
| 174 | d(s).sub(1, 'd');{s: '2023-01-01'};'2022-12-31T00:00:00Z' |
| 175 | d(s).sub(1, 'd');{s: '1970-01-01'};'1969-12-31T00:00:00Z' |
| 176 | d(s).sub(1, 'd');{s: ''};'Invalid date' |
| 177 | d(s).add(n, u);{s: '2023-10-15', n: 1, u: 'd'};'2023-10-16T00:00:00Z' |
| 178 | d(s).add(n, u);{s: '2023-10-15', n: 2, u: 'M'};'2023-12-15T00:00:00Z' |
| 179 | d(s).add(n, u);{s: '2023-10-15', n: 2, u: 'm'};'2023-10-15T00:02:00Z' |
| 180 | d(s).add(n, u);{s: '2023-10-15', n: -3, u: 'q'};'2023-01-15T00:00:00Z' |
| 181 | d(s).add(n, u);{s: '2023-10-15', n: 1.5, u: 'h'};'2023-10-15T01:30:00Z' |
| 182 | d(s).add(n, u);{s: '2023-10-15', n: 1, u: 'x'};!error |
| 183 | d(s).add(n, u);{s: '2023-10-15', n: null, u: 'd'};!error |
| 184 | d(s).add(n, u);{s: 'x', n: 1, u: 'd'};'Invalid date' |
| 185 | d(s).add(dur);{s: '2023-10-15', dur: '1d'};'2023-10-16T00:00:00Z' |
| 186 | d(s).add(dur);{s: '2023-10-15', dur: '2h 30m'};'2023-10-15T02:30:00Z' |
| 187 | d(s).add(dur);{s: '2023-10-15', dur: '1M'};'2023-11-15T00:00:00Z' |
| 188 | d(s).add(dur);{s: '2023-01-31', dur: '1M'};'2023-02-28T00:00:00Z' |
| 189 | d(s).add(dur);{s: '2023-10-15', dur: 'soon'};!error |
| 190 | d(s).add(dur);{s: '2023-10-15', dur: null};!error |
| 191 | d(s, 'UTC').add(1, 'M');{s: '2023-01-31'};'2023-02-28T00:00:00Z' |
| 192 | d(s, 'UTC').add(1, 'M');{s: '2023-01-31'};'2023-02-28T00:00:00Z' |
| 193 | d(s, 'UTC').add(1, 'M');{s: '2024-01-30'};'2024-02-29T00:00:00Z' |
| 194 | d(s, 'UTC').add(1, 'M');{s: '2023-10-15T23:59:59Z'};'2023-11-15T23:59:59Z' |
| 195 | d(s, 'UTC').add(1, 'M');{s: 'bad'};'Invalid date' |
| 196 | d(s, 'UTC').add(1, 'M');{};'Invalid date' |
| 197 | d(s, 'Etc/GMT+5').add(1, 'd');{s: '2023-10-15'};'2023-10-16T00:00:00-05:00' |
| 198 | d(s, 'Etc/GMT+5').add(1, 'd');{s: '2023-12-31 22:00'};'2024-01-01T22:00:00-05:00' |
| 199 | d(s, 'Etc/GMT+5').add(1, 'd');{s: '2024-02-28'};'2024-02-29T00:00:00-05:00' |
| 200 | d(s, 'Etc/GMT+5').add(1, 'd');{s: 'nope'};'Invalid date' |
| 201 | d(s, 'Asia/Kolkata').sub(1, 'M');{s: '2023-03-31'};'2023-02-28T00:00:00+05:30' |
| 202 | d(s, 'Asia/Kolkata').sub(1, 'M');{s: '2024-03-31'};'2024-02-29T00:00:00+05:30' |
| 203 | d(s, 'Asia/Kolkata').sub(1, 'M');{s: '2023-01-15 12:00'};'2022-12-15T12:00:00+05:30' |
| 204 | d(s, 'Asia/Kolkata').sub(1, 'M');{s: '2023-01-15 12:00'};'2022-12-15T12:00:00+05:30' |
| 205 | d(s, 'Asia/Kathmandu').add(1, 'q');{s: '2023-11-30'};'2024-02-29T00:00:00+05:45' |
| 206 | d(s, 'Asia/Kathmandu').add(1, 'q');{s: '2023-08-31'};'2023-11-30T00:00:00+05:45' |
| 207 | d(s, 'Asia/Kathmandu').add(1, 'q');{s: null};'Invalid date' |
| 208 | d(s).add(1, 'h').hour();{s: '2023-10-15 23:30'};0 |
| 209 | d(s).add(1, 'h').hour();{s: '2023-10-15 10:30'};11 |
| 210 | d(s).add(1, 'h').hour();{s: 'x'};null |
| 211 | d(s).add(1, 'h').hour();{};null |