Files
zen/core/expression/tests/spec/standard/02-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

6.9 KiB

1expression (string);input (json 5);output (json 5);note
2# Addition over input values
3a + b;{a: 1, b: 2};3
4a + b;{a: -1, b: 1};0
5a + b;{a: 0.1, b: 0.2};0.3
6a + b;{a: 0.1000000000000000000000000001, b: 1};1.1000000000000000000000000001
7a + b;{a: 79228162514264337593543950335, b: 0};79228162514264337593543950335
8a + b;{a: 79228162514264337593543950335, b: 1};!error
9a + b;{a: -79228162514264337593543950335, b: -1};!error
10a + b;{a: 9223372036854775807, b: 1};9223372036854775808
11a + b;{a: 1.5, b: null};!error
12a + b;{a: 1.5};!error
13# Subtraction over input values
14a - b;{a: 3, b: 5};-2
15a - b;{a: 0.3, b: 0.1};0.2
16a - b;{a: -0.5, b: -0.5};0
17a - b;{a: 1.0000000000000000000000000001, b: 1};0.0000000000000000000000000001
18a - b;{a: -79228162514264337593543950335, b: 1};!error
19a - b;{a: 10, b: true};!error
20a - b;{a: 10, b: '3'};!error
21# Multiplication over input values
22a * b;{a: 6, b: 7};42
23a * b;{a: 0.1, b: 0.1};0.01
24a * b;{a: -2.5, b: 4};-10
25a * b;{a: 0, b: -5};0
26a * b;{a: 4294967296, b: 4294967296};18446744073709551616
27a * b;{a: 79228162514264337593543950335, b: 2};!error
28a * b;{a: 1e-28, b: 1e-28};0
29a * b;{a: null, b: 0};!error
30# Division over input values
31a / b;{a: 1, b: 3};0.3333333333333333333333333333
32a / b;{a: 10, b: 4};2.5
33a / b;{a: 1, b: 0};null
34a / b;{a: 0, b: 0};null
35a / b;{a: -1, b: 0.0};null
36a / b;{a: 7, b: -2};-3.5
37a / b;{a: 0.3, b: 0.1};3
38a / b;{a: 79228162514264337593543950335, b: 0.5};!error;bug: division overflow returns null instead of an error
39a / b;{a: 1, b: null};!error
40a / b;{a: 1};!error
41a / b;{a: 1, b: 'x'};!error
42# Division by zero from input alongside non-zero divisors
43(a / b) ?? -1;{a: 1, b: 2};0.5
44(a / b) ?? -1;{a: 1, b: 0};-1
45(a / b) ?? -1;{a: 5, b: 5};1
46(a / b) ?? -1;{a: 0, b: 0};-1
47a / b ?? -1;{a: 1, b: 0};null
48a / b ?? -1;{a: 1, b: null};-1
49a / b ?? -1;{a: 1, b: 4};0.25
50# Modulo over input values
51a % b;{a: 7, b: 3};1
52a % b;{a: -7, b: 3};-1
53a % b;{a: 7, b: -3};1
54a % b;{a: -7, b: -3};-1
55a % b;{a: 5.5, b: 2};1.5
56a % b;{a: 7, b: 0};null
57a % b;{a: 0, b: 0};null
58a % b;{a: 7, b: null};!error
59a % b;{a: '7', b: 3};!error
60a % b;{b: 3};!error
61# Power over input values
62a ^ b;{a: 2, b: 10};1024
63a ^ b;{a: 2, b: -1};0.5
64a ^ b;{a: 0, b: 0};1
65a ^ b;{a: -2, b: 3};-8
66a ^ b;{a: 1.5, b: 2};2.25
67a ^ b;{a: 10, b: 28};10000000000000000000000000000
68a ^ b;{a: 10, b: 29};!error
69a ^ b;{a: 2, b: null};!error
70a ^ b;{a: true, b: 2};!error
71a ^ b;{a: 2};!error
72# Unary minus over input values
73-a;{a: 5};-5
74-a;{a: -5};5
75-a;{a: 0};0
76-a;{a: 1.5};-1.5
77-a;{a: 79228162514264337593543950335};-79228162514264337593543950335
78-a;{a: -79228162514264337593543950335};79228162514264337593543950335
79-a;{a: null};!error
80-a;{};!error
81-a;{a: '5'};!error
82-a;{a: true};!error
83-a;{a: [5]};!error
84# Unary plus over input values
85+a;{a: 5};5
86+a;{a: -1.5};-1.5
87+a;{a: 0};0
88+a;{a: null};null;question: unary plus passes non-numbers through unchanged, unlike unary minus
89+a;{a: 'x'};'x';question: unary plus passes strings through unchanged
90+a;{};null;question: unary plus on a missing key yields null instead of failing like unary minus
91# Unary minus combined with binary operators
92-a * b;{a: 2, b: 3};-6
93-a * b;{a: -2, b: 3};6
94-a * b;{a: 0.5, b: -4};2
95-a * b;{a: null, b: 3};!error
96-a * b;{a: 2};!error
97-a ^ 2;{a: 3};9;question: unary minus binds tighter than ^, (-a) ^ 2
98-a ^ 2;{a: -3};9
99-a ^ 2;{a: 0.5};0.25
100-a ^ 2;{a: null};!error
101a - -b;{a: 1, b: 2};3
102a - -b;{a: 1, b: -2};-1
103a - -b;{a: 1.5, b: 0.5};2
104a - -b;{a: 1, b: null};!error
105# Precedence over input values
106a + b * c;{a: 1, b: 2, c: 3};7
107a + b * c;{a: 0.1, b: 0.2, c: 10};2.1
108a + b * c;{a: -1, b: -2, c: -3};5
109a + b * c;{a: 1, b: 2, c: null};!error
110a + b * c;{a: null, b: 2, c: 3};!error
111a + b * c;{a: 1, b: 2};!error
112a - b - c;{a: 10, b: 2, c: 3};5
113a - b - c;{a: 0, b: 0, c: 0};0
114a - b - c;{a: 1.5, b: -1.5, c: 3};0
115a - b - c;{a: 10, b: 'x', c: 3};!error
116a / b / c;{a: 100, b: 10, c: 5};2
117a / b / c;{a: 100, b: 0, c: 5};!error;question: 100 / 0 is null, then null / 5 fails; null does not propagate through arithmetic
118a / b / c;{a: 1, b: 3, c: 3};0.1111111111111111111111111111
119a / b / c;{a: 1, b: 1, c: 0};null
120a * b % c;{a: 2, b: 3, c: 4};2
121a * b % c;{a: 2.5, b: 3, c: 4};3.5
122a * b % c;{a: -2, b: 3, c: 4};-2
123a * b % c;{a: 2, b: 3, c: 0};null
124a ^ b ^ c;{a: 2, b: 3, c: 2};512
125a ^ b ^ c;{a: 2, b: 2, c: 3};256
126a ^ b ^ c;{a: 10, b: 1, c: 0};10
127a ^ b ^ c;{a: 2, b: 3, c: null};!error
128(a + b) * c;{a: 1, b: 2, c: 3};9
129(a + b) * c;{a: 0.1, b: 0.2, c: 3};0.9
130(a + b) * c;{a: 'x', b: 'y', c: 3};!error
131(a + b) * c;{a: 1, b: 2, c: 0};0
132# Decimal exactness with input values
133a * 3 == b;{a: 0.1, b: 0.3};true
134a * 3 == b;{a: 1.1, b: 3.3};true
135a * 3 == b;{a: 0.3333333333333333333333333333, b: 1};false
136a * 3 == b;{a: 2, b: 6};true
137a + b == c;{a: 0.1, b: 0.2, c: 0.3};true
138a + b == c;{a: 0.7, b: 0.1, c: 0.8};true
139a + b == c;{a: 1e-28, b: 1e-28, c: 2e-28};true
140a + b == c;{a: 1, b: 2, c: 4};false
141a / b * b;{a: 1, b: 3};0.9999999999999999999999999999
142a / b * b;{a: 2, b: 3};2.0000000000000000000000000001
143a / b * b;{a: 6, b: 3};6
144a / b * b;{a: 1, b: 7};1.0000000000000000000000000003
145# Scale of input values observed via string()
146string(a + b);{a: 1.10, b: 1};'2.10'
147string(a + b);{a: 1.5, b: 1.5};'3.0'
148string(a + b);{a: 1, b: 2};'3'
149string(a + b);{a: 0.1, b: 0.2};'0.3'
150string(a * b);{a: 2.50, b: 2};'5.00'
151string(a * b);{a: 1.5, b: 1.5};'2.25'
152string(a * b);{a: 0.10, b: 10};'1.00'
153string(a - b);{a: 2.50, b: 0.50};'2.00'
154string(a - b);{a: 1, b: 1};'0'
155string(a - b);{a: 0.1, b: 0.1};'0.0'
156# Input values near the decimal range
157a + 1;{a: 79228162514264337593543950334};79228162514264337593543950335
158a + 1;{a: 79228162514264337593543950335};!error
159a + 1;{a: -79228162514264337593543950335};-79228162514264337593543950334
160a + 1;{a: 0.0000000000000000000000000001};1.0000000000000000000000000001
161a + 1;{a: -1};0
162a + 1;{a: null};!error
163a * 2;{a: 39614081257132168796771975167};79228162514264337593543950334
164a * 2;{a: 39614081257132168796771975168};!error
165a * 2;{a: 0.5};1
166a * 2;{a: -39614081257132168796771975167};-79228162514264337593543950334
167a * 2;{a: 'a'};!error
168# Mixed literal and input operands
169a * 1.1;{a: 100};110
170a * 1.1;{a: 0};0
171a * 1.1;{a: -10};-11
172a * 1.1;{a: 0.1};0.11
173a * 1.1;{a: null};!error
174100 - a;{a: 99.99};0.01
175100 - a;{a: -0.01};100.01
176100 - a;{a: 100};0
177100 - a;{a: 100.0000000000000000000000001};-0.0000000000000000000000001
178100 - a;{a: false};!error
1791 / a;{a: 3};0.3333333333333333333333333333
1801 / a;{a: 0};null
1811 / a;{a: 0.0000000000000000000000000001};10000000000000000000000000000
1821 / a;{a: -8};-0.125
1831 / a;{a: '1'};!error
1842 ^ a;{a: 10};1024
1852 ^ a;{a: -2};0.25
1862 ^ a;{a: 0};1
1872 ^ a;{a: 96};!error
1882 ^ a;{a: []};!error
189a % 2;{a: 7};1
190a % 2;{a: -7};-1
191a % 2;{a: 7.5};1.5
192a % 2;{a: 0};0
193a % 2;{a: null};!error
194# Nested member operands
195o.x + o.y;{o: {x: 1, y: 2}};3
196o.x + o.y;{o: {x: 0.1, y: 0.2}};0.3
197o.x + o.y;{o: {x: 1}};!error
198o.x + o.y;{o: null};!error
199o.x + o.y;{};!error
200list[0] * list[1];{list: [3, 4]};12
201list[0] * list[1];{list: [0.5, 0.5]};0.25
202list[0] * list[1];{list: [3]};!error
203list[0] * list[1];{list: []};!error
204list[0] * list[1];{list: [3, 'x']};!error