Files
zen/core/expression/tests/spec/standard/06-inputs.csv
T
stefan-gorules 4a378bafc4 feat(expression): lane VM and typed-mask engine for batch and columna evaluation (#553)
* 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.
2026-10-28 11:39:54 +01:00

13 KiB

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