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.
13 KiB
13 KiB
| 1 | expression (string);input (json 5);output (json 5);note |
|---|---|
| 2 | # round(a, 2) over mixed inputs |
| 3 | round(a, 2);{a: 0.5};0.5 |
| 4 | round(a, 2);{a: 1.25};1.25 |
| 5 | round(a, 2);{a: -0.10};-0.1 |
| 6 | round(a, 2);{a: 1234567.891};1234567.89 |
| 7 | round(a, 2);{a: 1.005};1.01 |
| 8 | round(a, 2);{a: -1.005};-1.01 |
| 9 | round(a, 2);{a: 2.675};2.68 |
| 10 | round(a, 2);{a: 9223372036854775807};9223372036854775807 |
| 11 | round(a, 2);{a: 922337203685477580.735};922337203685477580.74 |
| 12 | round(a, 2);{a: 92233720368547758.075};92233720368547758.08 |
| 13 | round(a, 2);{a: 0};0 |
| 14 | round(a, 2);{a: -0.004};0 |
| 15 | round(a, 2);{a: 79228162514264337593543950335};79228162514264337593543950335 |
| 16 | round(a, 2);{a: 0.0000000000000000000000000001};0 |
| 17 | round(a, 2);{a: null};!error |
| 18 | round(a, 2);{};!error |
| 19 | round(a, 2);{a: '1.5'};!error |
| 20 | round(a, 2);{a: true};!error |
| 21 | round(a, 2);{a: [1.5]};!error |
| 22 | # string(round(a, 2)) observes scale |
| 23 | string(round(a, 2));{a: 0.5};'0.5' |
| 24 | string(round(a, 2));{a: 1.25};'1.25' |
| 25 | string(round(a, 2));{a: -0.10};'-0.10' |
| 26 | string(round(a, 2));{a: 1234567.891};'1234567.89' |
| 27 | string(round(a, 2));{a: 1.995};'2.00' |
| 28 | string(round(a, 2));{a: -1.995};'-2.00' |
| 29 | string(round(a, 2));{a: 7};'7' |
| 30 | string(round(a, 2));{a: 1.2500};'1.25' |
| 31 | string(round(a, 2));{a: -0.004};'0.00' |
| 32 | string(round(a, 2));{a: 9223372036854775807};'9223372036854775807' |
| 33 | # round(a) ties away from zero |
| 34 | round(a);{a: 0.5};1 |
| 35 | round(a);{a: -0.5};-1 |
| 36 | round(a);{a: 2.5};3 |
| 37 | round(a);{a: -2.5};-3 |
| 38 | round(a);{a: 1.49};1 |
| 39 | round(a);{a: -1.25};-1 |
| 40 | round(a);{a: 1234567.891};1234568 |
| 41 | round(a);{a: 9223372036854775806.5};9223372036854775807 |
| 42 | round(a);{a: 9223372036854775807.5};9223372036854775808 |
| 43 | round(a);{a: -9223372036854775808.5};-9223372036854775809 |
| 44 | round(a);{a: 0};0 |
| 45 | round(a);{a: null};!error |
| 46 | string(round(a));{a: -0.4};'0' |
| 47 | string(round(a));{a: 2.50};'3' |
| 48 | string(round(a));{a: -0.10};'0' |
| 49 | # round(a, p) with input precision |
| 50 | round(a, p);{a: 3.14159, p: 0};3 |
| 51 | round(a, p);{a: 3.14159, p: 1};3.1 |
| 52 | round(a, p);{a: 3.14159, p: 4};3.1416 |
| 53 | round(a, p);{a: 3.14159, p: 10};3.14159 |
| 54 | round(a, p);{a: -3.14159, p: 3};-3.142 |
| 55 | round(a, p);{a: 3.14159, p: -1};!error;question: negative precision is rejected |
| 56 | round(a, p);{a: 3.14159, p: null};!error;question: null precision fails; could mean the default precision 0 |
| 57 | round(a, p);{a: 3.14159};!error |
| 58 | round(a, p);{a: 3.14159, p: '2'};!error |
| 59 | string(round(a, p));{a: 2.5, p: 3};'2.5' |
| 60 | string(round(a, p));{a: 2.5555, p: 3};'2.556' |
| 61 | # floor, ceil, trunc, abs over mixed inputs |
| 62 | floor(a);{a: 0.5};0 |
| 63 | floor(a);{a: 1.25};1 |
| 64 | floor(a);{a: -0.10};-1 |
| 65 | floor(a);{a: 1234567.891};1234567 |
| 66 | floor(a);{a: 9223372036854775807};9223372036854775807 |
| 67 | floor(a);{a: -9223372036854775807.5};-9223372036854775808 |
| 68 | floor(a);{a: -9223372036854775808.5};-9223372036854775809 |
| 69 | floor(a);{a: 0};0 |
| 70 | floor(a);{a: null};!error |
| 71 | floor(a);{};!error |
| 72 | ceil(a);{a: 0.5};1 |
| 73 | ceil(a);{a: 1.25};2 |
| 74 | ceil(a);{a: -0.10};0 |
| 75 | ceil(a);{a: 1234567.891};1234568 |
| 76 | ceil(a);{a: 9223372036854775806.1};9223372036854775807 |
| 77 | ceil(a);{a: 9223372036854775807.1};9223372036854775808 |
| 78 | ceil(a);{a: -9223372036854775808.9};-9223372036854775808 |
| 79 | ceil(a);{a: null};!error |
| 80 | ceil(a);{a: 'x'};!error |
| 81 | string(ceil(a));{a: -0.10};'0';bug: ceil of a negative fraction yields negative zero '-0' |
| 82 | string(ceil(a));{a: 1.00};'1' |
| 83 | string(floor(a));{a: -0.10};'-1' |
| 84 | string(floor(a));{a: 2.90};'2' |
| 85 | trunc(a);{a: 0.5};0 |
| 86 | trunc(a);{a: 1.25};1 |
| 87 | trunc(a);{a: -1.25};-1 |
| 88 | trunc(a);{a: 1234567.891};1234567 |
| 89 | trunc(a);{a: -9223372036854775808.9};-9223372036854775808 |
| 90 | trunc(a);{a: 9223372036854775807.9};9223372036854775807 |
| 91 | trunc(a);{a: null};!error |
| 92 | string(trunc(a));{a: -0.10};'0';bug: truncating a negative fraction yields negative zero '-0' |
| 93 | string(trunc(a, 1));{a: 1.25};'1.2' |
| 94 | string(trunc(a, 1));{a: -1.25};'-1.2' |
| 95 | string(trunc(a, 1));{a: 1234567.891};'1234567.8' |
| 96 | string(trunc(a, 1));{a: 5};'5.0';question: trunc pads the result to the requested scale while round(5, 1) keeps scale '5' |
| 97 | abs(a);{a: 0.5};0.5 |
| 98 | abs(a);{a: -1.25};1.25 |
| 99 | abs(a);{a: -0.10};0.1 |
| 100 | abs(a);{a: -9223372036854775808};9223372036854775808 |
| 101 | abs(a);{a: -79228162514264337593543950335};79228162514264337593543950335 |
| 102 | abs(a);{a: 0};0 |
| 103 | abs(a);{a: null};!error |
| 104 | abs(a);{a: '-1'};!error |
| 105 | string(abs(a));{a: -0.10};'0.10' |
| 106 | # sum(list) |
| 107 | sum(list);{list: []};0 |
| 108 | sum(list);{list: [0.5, 1.25, -0.10]};1.65 |
| 109 | sum(list);{list: [1234567.891, 0.109]};1234568 |
| 110 | sum(list);{list: [9223372036854775807, 1]};9223372036854775808 |
| 111 | sum(list);{list: [9223372036854775807, 9223372036854775807]};18446744073709551614 |
| 112 | sum(list);{list: [-9223372036854775808, -9223372036854775808]};-18446744073709551616 |
| 113 | sum(list);{list: [922337203685477580.7, 0.1]};922337203685477580.8 |
| 114 | sum(list);{list: [92233720368547758.07, 0.01]};92233720368547758.08 |
| 115 | sum(list);{list: [0.5, -0.5]};0 |
| 116 | sum(list);{list: [0.1000000000000000000000000001, 1]};1.1000000000000000000000000001 |
| 117 | sum(list);{list: [79228162514264337593543950335, 1]};!error |
| 118 | sum(list);{list: [1, null]};!error |
| 119 | sum(list);{list: ['1']};!error |
| 120 | sum(list);{list: [1, true]};!error |
| 121 | sum(list);{list: [[1]]};!error |
| 122 | sum(list);{list: null};!error |
| 123 | sum(list);{};!error |
| 124 | sum(list);{list: 5};!error |
| 125 | string(sum(list));{list: []};'0' |
| 126 | string(sum(list));{list: [0.5, 1.25, -0.10]};'1.65' |
| 127 | string(sum(list));{list: [1234567.891, 0.109]};'1234568.000' |
| 128 | string(sum(list));{list: [0.5, -0.5]};'0.0' |
| 129 | string(sum(list));{list: [0.1, 0.20]};'0.30' |
| 130 | string(sum(list));{list: [1, 2, 3]};'6' |
| 131 | string(sum(list));{list: [1.10, 2]};'3.10' |
| 132 | string(sum(list));{list: [-0.25, 0.25, -0.50]};'-0.50' |
| 133 | # sum over map and filter results |
| 134 | sum(map(list, # * 1.5));{list: []};0 |
| 135 | sum(map(list, # * 1.5));{list: [0.5, 1.25, -0.10]};2.475 |
| 136 | sum(map(list, # * 1.5));{list: [1234567.891]};1851851.8365 |
| 137 | sum(map(list, # * 1.5));{list: [9223372036854775807, 1]};13835058055282163712 |
| 138 | sum(map(list, # * 1.5));{list: [2, -2]};0 |
| 139 | sum(map(list, # * 1.5));{list: [1, null]};!error |
| 140 | sum(map(list, # * 1.5));{list: ['2']};!error |
| 141 | string(sum(map(list, # * 1.5)));{list: [2, 4]};'9.0' |
| 142 | string(sum(map(list, # * 1.5)));{list: [0.10, 0.30]};'0.600' |
| 143 | sum(map(list, #.price * #.qty));{list: [{price: 9.99, qty: 3}, {price: 0.01, qty: 1}]};29.98 |
| 144 | sum(map(list, #.price * #.qty));{list: [{price: 1.25, qty: -2}, {price: 0.5, qty: 5}]};0 |
| 145 | sum(map(list, #.price * #.qty));{list: []};0 |
| 146 | sum(map(list, #.price * #.qty));{list: [{price: 1}]};!error |
| 147 | string(sum(map(list, #.price * #.qty)));{list: [{price: 9.99, qty: 3}, {price: 0.01, qty: 1}]};'29.98' |
| 148 | sum(filter(list, # > 0));{list: [0.5, 1.25, -0.10]};1.75 |
| 149 | sum(filter(list, # > 0));{list: [-1, -2]};0 |
| 150 | sum(filter(list, # > 0));{list: [9223372036854775807, 9223372036854775807, -1]};18446744073709551614 |
| 151 | sum(filter(list, # > 0));{list: []};0 |
| 152 | string(sum(filter(list, # > 0)));{list: [1.50, -3, 2]};'3.50' |
| 153 | # max and min over filter results |
| 154 | max(filter(list, # > 0));{list: [0.5, 1.25, -0.10]};1.25 |
| 155 | max(filter(list, # > 0));{list: [1234567.891, 9223372036854775807, 1]};9223372036854775807 |
| 156 | max(filter(list, # > 0));{list: [0.0000000000000000000000000001, -1]};0.0000000000000000000000000001 |
| 157 | max(filter(list, # > 0));{list: [-1, -2]};!error |
| 158 | max(filter(list, # > 0));{list: []};!error |
| 159 | max(filter(list, # > 0));{list: [1, null]};!error |
| 160 | min(filter(list, # > 0));{list: [0.5, 1.25, -0.10]};0.5 |
| 161 | min(filter(list, # > 0));{list: [9223372036854775808, 9223372036854775807]};9223372036854775807 |
| 162 | min(filter(list, # > 0));{list: [-5]};!error |
| 163 | min(map(list, # - 1));{list: [0.5, 1.25, -0.10]};-1.1 |
| 164 | max(map(list, # * -1));{list: [0.5, 1.25, -0.10]};0.1 |
| 165 | string(max(filter(list, # > 0)));{list: [1.50, 1.5, -1]};'1.5';question: among equal values max returns the last one, so the result scale depends on order |
| 166 | string(min(filter(list, # > 0)));{list: [1.50, 1.5, -1]};'1.50';question: among equal values min returns the first one, so the result scale depends on order |
| 167 | # min and max over list inputs |
| 168 | max(list);{list: [0.5, 1.25, -0.10]};1.25 |
| 169 | max(list);{list: [-0.10, -0.5]};-0.1 |
| 170 | max(list);{list: [9223372036854775807, 9223372036854775808, 1234567.891]};9223372036854775808 |
| 171 | max(list);{list: [-79228162514264337593543950335, 79228162514264337593543950335]};79228162514264337593543950335 |
| 172 | max(list);{list: [0]};0 |
| 173 | max(list);{list: []};!error |
| 174 | max(list);{list: [1, '2']};!error |
| 175 | max(list);{list: null};!error |
| 176 | max(list);{};!error |
| 177 | min(list);{list: [0.5, 1.25, -0.10]};-0.1 |
| 178 | min(list);{list: [-9223372036854775808, -9223372036854775809]};-9223372036854775809 |
| 179 | min(list);{list: [1234567.891, 1234567.89]};1234567.89 |
| 180 | min(list);{list: [0.0000000000000000000000000001, 0.0000000000000000000000000002]};0.0000000000000000000000000001 |
| 181 | min(list);{list: []};!error |
| 182 | min(list);{list: [null]};!error |
| 183 | string(max(list));{list: [1, 1.0, 1.00]};'1.00';question: among equal values max returns the last one, so the result scale depends on order |
| 184 | string(min(list));{list: [1, 1.0, 1.00]};'1';question: among equal values min returns the first one, so the result scale depends on order |
| 185 | string(max(list));{list: [2.50, 1]};'2.50' |
| 186 | string(min(list));{list: [-0.10, 3]};'-0.10' |
| 187 | # max([a, b, c]) and min with literals |
| 188 | max([a, b, 1.5]);{a: 0.5, b: 1.25};1.5 |
| 189 | max([a, b, 1.5]);{a: 1234567.891, b: -0.10};1234567.891 |
| 190 | max([a, b, 1.5]);{a: -1, b: -2};1.5 |
| 191 | max([a, b, 1.5]);{a: 9223372036854775807, b: 0};9223372036854775807 |
| 192 | max([a, b, 1.5]);{a: 1.5, b: 1.50};1.5 |
| 193 | max([a, b, 1.5]);{a: null, b: 1};!error |
| 194 | max([a, b, 1.5]);{a: 1};!error |
| 195 | max([a, b, 1.5]);{a: '3', b: 1};!error |
| 196 | string(max([a, b, 1.5]));{a: 1.50, b: 0};'1.5';question: among equal values max returns the last one, so the result scale depends on order |
| 197 | string(max([a, b, 1.5]));{a: 1.25, b: 1.500};'1.5';question: among equal values max returns the last one, so the result scale depends on order |
| 198 | min([a, b, c]);{a: 0.5, b: 1.25, c: -0.10};-0.1 |
| 199 | min([a, b, c]);{a: 9223372036854775807, b: 9223372036854775806, c: 9223372036854775808};9223372036854775806 |
| 200 | min([a, b, c]);{a: 0, b: 0.0, c: -0};0 |
| 201 | min([a, b, c]);{a: -79228162514264337593543950335, b: 0, c: 1};-79228162514264337593543950335 |
| 202 | min([a, b, c]);{a: 1, b: 2};!error |
| 203 | min([a, b, c]);{a: 1, b: 2, c: false};!error |
| 204 | string(min([a, b, c]));{a: 2, b: 2.0, c: 2.00};'2';question: among equal values min returns the first one, so the result scale depends on order |
| 205 | string(min([a, b, c]));{a: 0.10, b: 0.1, c: 5};'0.10' |
| 206 | sum([a, b, c]);{a: 0.5, b: 1.25, c: -0.10};1.65 |
| 207 | sum([a, b, c]);{a: 9223372036854775807, b: 9223372036854775807, c: 2};18446744073709551616 |
| 208 | sum([a, b, c]);{a: 1, b: null, c: 2};!error |
| 209 | string(sum([a, b, c]));{a: 0.5, b: 0.25, c: -0.75};'0.00' |
| 210 | avg([a, b]);{a: 1, b: 2};1.5 |
| 211 | avg([a, b]);{a: 0.5, b: -0.10};0.2 |
| 212 | avg([a, b]);{a: 9223372036854775807, b: 9223372036854775807};9223372036854775807 |
| 213 | avg([a, b]);{a: 1};!error |
| 214 | # avg(list) |
| 215 | avg(list);{list: [1, 2]};1.5 |
| 216 | avg(list);{list: [1, 1, 2]};1.3333333333333333333333333333 |
| 217 | avg(list);{list: [0.5, 1.25, -0.10]};0.55 |
| 218 | avg(list);{list: [1234567.891, 0.109]};617284 |
| 219 | avg(list);{list: [9223372036854775807, 9223372036854775806]};9223372036854775806.5 |
| 220 | avg(list);{list: [-0.5, 0.5]};0 |
| 221 | avg(list);{list: [7]};7 |
| 222 | avg(list);{list: []};!error;question: average of an empty list fails; could be null |
| 223 | avg(list);{list: [1, null]};!error |
| 224 | avg(list);{list: null};!error |
| 225 | string(avg(list));{list: [1.50, 2.50]};'2.00' |
| 226 | string(avg(list));{list: [10, 20, 30]};'20' |
| 227 | avg(map(list, # * 2));{list: [0.5, 1.25, -0.10]};1.1 |
| 228 | avg(filter(list, # > 0));{list: [0.5, 1.25, -0.10]};0.875 |
| 229 | avg(filter(list, # > 0));{list: [-1]};!error |
| 230 | round(avg(list), 2);{list: [1, 1, 2]};1.33 |
| 231 | round(avg(list), 2);{list: [1, 2, 2]};1.67 |
| 232 | round(avg(list), 2);{list: [0.125, 0.125]};0.13 |
| 233 | string(round(avg(list), 2));{list: [1, 2]};'1.50';question: the mean's scale follows Decimal division (3 / 2 prints '1.50'), not the inputs' scale |
| 234 | string(avg(list));{list: [1, 2]};'1.50';question: the mean's scale follows Decimal division (3 / 2 prints '1.50'), not the inputs' scale |
| 235 | string(avg(list));{list: [1, 3]};'2' |
| 236 | round(sum(list), 1);{list: [0.25, 0.1]};0.4 |
| 237 | round(sum(list), 1);{list: [-0.25, -0.1]};-0.4 |
| 238 | string(round(sum(list), 1));{list: [0.04, -0.08]};'0.0' |
| 239 | # median and mode over list inputs |
| 240 | median(list);{list: [0.5, 1.25, -0.10]};0.5 |
| 241 | median(list);{list: [0.5, 1.25, -0.10, 1234567.891]};0.875 |
| 242 | median(list);{list: [9223372036854775807, 9223372036854775807]};9223372036854775807 |
| 243 | median(list);{list: [3]};3 |
| 244 | median(list);{list: [2, 1]};1.5 |
| 245 | median(list);{list: []};!error |
| 246 | median(list);{list: [1, 'a']};!error |
| 247 | mode(list);{list: [0.5, 1.25, 0.5]};0.5 |
| 248 | mode(list);{list: [-0.10, -0.1, 3]};-0.1 |
| 249 | mode(list);{list: [9223372036854775807, 9223372036854775807, 1]};9223372036854775807 |
| 250 | mode(list);{list: [1, 2, 3]};3;question: ties resolve to the largest value |
| 251 | mode(list);{list: []};!error |
| 252 | mode(list);{list: [null]};!error |
| 253 | # number and isNumeric over input strings |
| 254 | number(s);{s: '1.5'};1.5 |
| 255 | number(s);{s: ' 42 '};42 |
| 256 | number(s);{s: '1e3'};1000 |
| 257 | number(s);{s: '-0.10'};-0.1 |
| 258 | number(s);{s: '9223372036854775807'};9223372036854775807 |
| 259 | number(s);{s: ''};!error |
| 260 | number(s);{s: 'abc'};!error |
| 261 | number(s);{s: null};!error |
| 262 | number(s);{s: 12.50};12.5 |
| 263 | number(s);{s: true};1 |
| 264 | string(number(s));{s: '-0.10'};'-0.10' |
| 265 | string(number(s));{s: '1234567.891'};'1234567.891' |
| 266 | isNumeric(s);{s: '1.5'};true |
| 267 | isNumeric(s);{s: ' 42 '};true |
| 268 | isNumeric(s);{s: 'abc'};false |
| 269 | isNumeric(s);{s: ''};false |
| 270 | isNumeric(s);{s: null};false |
| 271 | isNumeric(s);{};false |
| 272 | isNumeric(s);{s: 3};true |
| 273 | isNumeric(s);{s: [1]};false |
| 274 | sum(map(list, number(#)));{list: ['0.5', '1.25', '-0.10']};1.65 |
| 275 | sum(map(filter(list, isNumeric(#)), number(#)));{list: ['1', 'x', '2.5', '']};3.5 |
| 276 | # aggregates in conditions |
| 277 | sum(list) > 100;{list: [50, 50.01]};true |
| 278 | sum(list) > 100;{list: [50, 50]};false |
| 279 | max(list) - min(list);{list: [0.5, 1.25, -0.10]};1.35 |
| 280 | max(list) - min(list);{list: [9223372036854775807, -9223372036854775808]};18446744073709551615 |
| 281 | avg(list) == median(list);{list: [1, 2, 3]};true |
| 282 | round(a * b, 2);{a: 19.99, b: 0.075};1.5 |
| 283 | round(a * b, 2);{a: 1234567.891, b: 1.5};1851851.84 |
| 284 | round(a * b, 2);{a: -0.10, b: 0.05};-0.01 |
| 285 | round(a / b, 4);{a: 1, b: 3};0.3333 |
| 286 | round(a / b, 4);{a: 2, b: 3};0.6667 |
| 287 | round(a / b, 4);{a: 1, b: 0};!error |