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

5.0 KiB

1expression (string);input (json 5);output (json 5);note
2# Nullish coalescing: only null and missing fall through
3null ?? 1;;1
41 ?? 2;;1
50 ?? 1;;0
6false ?? 1;;false
7true ?? 1;;true
8'' ?? 'x';;''
9[] ?? 1;;[]
10{} ?? 1;;{}
11null ?? null;;null
12null ?? false;;false
13null ?? null ?? 3;;3
14null ?? 2 ?? 3;;2
151 ?? null ?? 3;;1
16d('2024-01-01') ?? 1;;'2024-01-01T00:00:00Z'
17# Nullish coalescing: the right side is evaluated only when needed
181 ?? (1 + {});;1
190 ?? (1 + {});;0
20false ?? (1 + {});;false
21null ?? (1 + {});;!error
22# Nullish coalescing binds tighter than arithmetic and comparison
23null ?? 1 + 2;;3
242 ?? 1 + 2;;4
25null ?? 2 * 3;;6
26null ?? 2 ^ 3;;8
272 ^ null ?? 3;;8
28null ?? 1 == 1;;true
29null ?? 2 == 1;;false
30null ?? false or true;;true
31null ?? true and false;;false
32null ?? 1 in [1];;true
331 + (null ?? 2);;3
34-(null ?? 5);;-5
35-null ?? 5;;!error
36null ?? -5;;-5
37# Nullish coalescing: variable operands
38x ?? 'default';{x: 'set'};'set'
39x ?? 'default';{x: null};'default'
40x ?? 'default';{};'default'
41x ?? 'default';{x: ''};''
42x ?? 'default';{x: 0};0
43x ?? 'default';{x: false};false
44x ?? 'default';{x: []};[]
45x ?? 0;{x: 5};5
46x ?? 0;{x: null};0
47x ?? 0;{};0
48x ?? 0;{x: -0.5};-0.5
49x ?? 0;{x: '7'};'7'
50a ?? b;{a: 1b: 2};1
51a ?? b;{a: nullb: 2};2
52a ?? b;{b: 2};2
53a ?? b;{a: null};null
54a ?? b;{};null
55a ?? b;{a: falseb: true};false
56a ?? b ?? c;{a: 1b: 2c: 3};1
57a ?? b ?? c;{b: 2c: 3};2
58a ?? b ?? c;{c: 3};3
59a ?? b ?? c;{};null
60a ?? b ?? c;{a: 0c: 3};0
61x.y ?? 'd';{x: {y: 1}};1
62x.y ?? 'd';{x: {}};'d'
63x.y ?? 'd';{x: null};'d'
64x.y ?? 'd';{};'d'
65x.y ?? 'd';{x: {y: false}};false
66x.y.z ?? 'd';{};'d'
67x.y.z ?? 'd';{x: {y: {z: 0}}};0
68x[0] ?? 'd';{x: []};'d'
69x[0] ?? 'd';{x: [null]};'d'
70x[0] ?? 'd';{x: [0]};0
71x ?? 1 + 1;{x: 5};6
72x ?? 1 + 1;{};2
73x ?? 1 + 1;{x: null};2
74x ?? 1 + 1;{x: 'a'};!error
75x ?? 1 * 3;{x: 2};6
76x ?? 1 * 3;{};3
77x ?? 1 > 0;{x: 5};true
78x ?? 1 > 0;{x: -5};false
79x ?? 1 > 0;{};true
80x ?? 1 > 0;{x: 'a'};!error
81(x ?? 0) >= 18;{x: 21};true
82(x ?? 0) >= 18;{};false
83(x ?? 0) >= 18;{x: null};false
84(x ?? 0) >= 18;{x: 18};true
85x ?? false or y;{y: true};true
86x ?? false or y;{x: true};true
87x ?? false or y;{x: falsey: false};false
88x ?? false or y;{x: 1y: true};!error
89# Ternary: condition must be a boolean
90true ? 1 : 2;;1
91false ? 1 : 2;;2
921 == 1 ? 'y' : 'n';;'y'
931 == 2 ? 'y' : 'n';;'n'
94null ? 1 : 2;;!error
951 ? 1 : 2;;!error
960 ? 1 : 2;;!error
97'' ? 1 : 2;;!error
98'true' ? 1 : 2;;!error
99[] ? 1 : 2;;!error
100{} ? 1 : 2;;!error
101# Ternary: only the chosen branch is evaluated
102true ? 1 : (1 + {});;1
103false ? (1 + {}) : 2;;2
104true ? (1 + {}) : 2;;!error
105false ? 1 : (1 + {});;!error
106true ? null : 1;;null
107false ? 1 : [12];;[12]
108true ? {a: 1} : 0;;{a: 1}
109# Ternary: nesting is right-associative
110true ? 1 : false ? 2 : 3;;1
111false ? 1 : true ? 2 : 3;;2
112false ? 1 : false ? 2 : 3;;3
113true ? false ? 1 : 2 : 3;;2
114true ? true ? 1 : 2 : 3;;1
115false ? true ? 1 : 2 : 3;;3
116(true ? false : true) ? 1 : 2;;2
117true ? 1 : 2 ? 3 : 4;;1
118false ? 1 : (true ? 2 : 3);;2
119# Ternary: lowest precedence
120true or false ? 'a' : 'b';;'a'
121false and true ? 'a' : 'b';;'b'
1221 + 1 == 2 ? 'a' : 'b';;'a'
123true ? 1 : 2 + 10;;1
124false ? 1 : 2 + 10;;12
125null ?? true ? 'a' : 'b';;'a'
126null ?? false ? 'a' : 'b';;'b'
127(true ? 1 : 2) + 10;;11
128true ? 1 + 1 : 0;;2
129not true ? 'a' : 'b';;'b'
1301 in [1] ? 'a' : 'b';;'a'
131[true ? 1 : 2false ? 1 : 2];;[12]
132{k: false ? 'a' : 'b'};;{k: 'b'}
133# Ternary: variable operands
134x ? 'yes' : 'no';{x: true};'yes'
135x ? 'yes' : 'no';{x: false};'no'
136x ? 'yes' : 'no';{x: null};!error
137x ? 'yes' : 'no';{};!error
138x ? 'yes' : 'no';{x: 1};!error
139x ? 'yes' : 'no';{x: 'true'};!error
140age >= 18 ? 'adult' : 'minor';{age: 18};'adult'
141age >= 18 ? 'adult' : 'minor';{age: 17.9};'minor'
142age >= 18 ? 'adult' : 'minor';{age: 99};'adult'
143age >= 18 ? 'adult' : 'minor';{age: null};!error
144age >= 18 ? 'adult' : 'minor';{};!error
145score >= 90 ? 'A' : score >= 80 ? 'B' : score >= 70 ? 'C' : 'F';{score: 95};'A'
146score >= 90 ? 'A' : score >= 80 ? 'B' : score >= 70 ? 'C' : 'F';{score: 90};'A'
147score >= 90 ? 'A' : score >= 80 ? 'B' : score >= 70 ? 'C' : 'F';{score: 85};'B'
148score >= 90 ? 'A' : score >= 80 ? 'B' : score >= 70 ? 'C' : 'F';{score: 70};'C'
149score >= 90 ? 'A' : score >= 80 ? 'B' : score >= 70 ? 'C' : 'F';{score: 0};'F'
150score >= 90 ? 'A' : score >= 80 ? 'B' : score >= 70 ? 'C' : 'F';{score: '95'};!error
151x == null ? 'missing' : x;{};'missing'
152x == null ? 'missing' : x;{x: null};'missing'
153x == null ? 'missing' : x;{x: 0};0
154x == null ? 'missing' : x;{x: false};false
155x == null ? 'missing' : x;{x: 'v'};'v'
156c ? a : b;{c: truea: 1b: 2};1
157c ? a : b;{c: falsea: 1b: 2};2
158c ? a : b;{c: trueb: 2};null
159c ? a : b;{c: falsea: 1};null
160c ? a : b;{c: truea: 1b: 'x'};1
161c ? a : b;{c: nulla: 1b: 2};!error
162c ? a + {} : b;{c: falsea: 1b: 2};2
163c ? a + {} : b;{c: truea: 1b: 2};!error
164x > 0 ? x : -x;{x: 5};5
165x > 0 ? x : -x;{x: -5};5
166x > 0 ? x : -x;{x: 0};0
167x > 0 ? x : -x;{x: -0.25};0.25
168x in [1..5] ? 'in' : 'out';{x: 3};'in'
169x in [1..5] ? 'in' : 'out';{x: 6};'out'
170x in [1..5] ? 'in' : 'out';{x: null};!error
171(x ?? 0) > 0 ? 'pos' : 'non';{x: 1};'pos'
172(x ?? 0) > 0 ? 'pos' : 'non';{};'non'
173(x ?? 0) > 0 ? 'pos' : 'non';{x: -1};'non'