Files
zen/core/expression/tests/spec/standard/11-05-null-programs.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

12 KiB

1expression (string)input (json 5)output (json 5)note
2# An assignment of null keeps the key, and later reads see null
3y = x.a; y{}null
4y = x.a; y{x: {a: 3}}3
5y = x.a; y{x: 5}null
6y = x.a{}{y: null}
7y = x.a; y ?? 'none'{}'none'
8y = x.a; y ?? 'none'{x: {a: false}}false
9y = x.a; y + 1{}!error
10y = x.a; y + 1{x: {a: 1}}2
11y = x.a; y == null{x: {}}true
12y = x.a; y.b.c{x: {a: 1}}null
13y = null; $root{y: 1}{y: null}
14y = x ?? 0; y + 1{x: null}1
15y = x ?? 0; y + 1{x: 4}5
16y = x ?? 0; y + 1{x: 'a'}!error
17y = x / 0; y{x: 1}null
18y = x / 0; y ?? 'div0'{x: 1}'div0'
19y = x / 0; y + 1{x: 1}!error
20y = x / z; y ?? 0{x: 1, z: 0}0
21y = x / z; y ?? 0{x: 1, z: 4}0.25
22y = x / z; y ?? 0{x: 1}!error
23y = [x, x.a]; y{}[null, null]
24y = {v: x}; y.v ?? 'd'{}'d'
25y = {v: x}; y{}{v: null}
26# An error after assignments aborts the whole program
27x = 1; 1 + {}{}!error
28x = 1; y = x + {}; x{}!error
29x = 1 + {}; 2{}!error
30x = 1; y = null; y + 1{}!error
31x = 1; y = null; y ?? x{}1
32x = 1; y = 2; upper(y){}!error
33x = a; x.b = 1; x{a: null}{b: 1}
34x = a * 2; x{a: null}!error
35x = a * 2; x{a: 3}6
36x = a * 2; x{}!error
37x = a ?? 1; y = x * 2; y{}2
38x = a ?? 1; y = x * 2; y{a: 5}10
39x = a ?? 1; y = x * 2; y{a: 'q'}!error
40x = true ? 1 : 1 + {}; x{}1
41x = false and 1 + {}; x{}false
42x = null ?? 3; x{}3
43x = [1 + {}]; 1{}!error
44x = map([1, 2], # / 0); x{}[null, null]
45x = map([1, 2], # / 0); x[0] ?? 'z'{}'z'
46# Dotted assignment into null, missing and non-object values
47a.b = 1; a{a: null}{b: 1}
48a.b = 1; a{}{b: 1}
49a.b = 1; a{a: 5}{b: 1}
50a.b = 1; a{a: {c: null}}{c: null, b: 1}
51a.b = 1; a{a: {b: null}}{b: 1}
52x = a.b; a.b = 7; x{a: null}null
53x = a.b; a.b = 7; x{}null
54x = a.b; a.b = 7; x{a: {b: null}}null
55x = a.b; a.b = 7; x{a: {b: 2}}2
56a.n = (a.n ?? 0) + 1; a.n{a: null}1
57a.n = (a.n ?? 0) + 1; a.n{}1
58a.n = (a.n ?? 0) + 1; a.n{a: {n: null}}1
59a.n = (a.n ?? 0) + 1; a.n{a: {n: 4}}5
60a.n = (a.n ?? 0) + 1; a.n{a: {n: 'x'}}!error
61a.n = a.n + 1; a.n{a: null}!error
62a.n = a.n + 1; a.n{a: {n: 4}}5
63a.n = a.n + 1; a.n{}!error
64# A null inside array and object literals is kept, an error is not
65[a, b.c, a ?? 0]{a: 1, b: {c: 2}}[1, 2, 1]
66[a, b.c, a ?? 0]{a: null, b: null}[null, null, 0]
67[a, b.c, a ?? 0]{}[null, null, 0]
68[a, b.c, a ?? 0]{a: 'x', b: 5}['x', null, 'x']
69{a: a, c: b.c}{a: 1, b: {c: 2}}{a: 1, c: 2}
70{a: a, c: b.c}{a: null, b: null}{a: null, c: null}
71{a: a, c: b.c}{}{a: null, c: null}
72{a: a, c: b.c}{a: 'x', b: 5}{a: 'x', c: null}
73[a, b.c + 1]{a: 1, b: {c: 2}}[1, 3]
74[a, b.c + 1]{a: null, b: null}!error
75[a, b.c + 1]{}!error
76[a, b.c + 1]{a: 'x', b: 5}!error
77{x: a, y: a * 2}{a: 1, b: {c: 2}}{x: 1, y: 2}
78{x: a, y: a * 2}{a: null, b: null}!error
79{x: a, y: a * 2}{}!error
80{x: a, y: a * 2}{a: 'x', b: 5}!error
81len([a, b, c]){a: 1, b: {c: 2}}3
82len([a, b, c]){a: null, b: null}3
83len([a, b, c]){}3
84len([a, b, c]){a: 'x', b: 5}3
85[a, b][1].c{a: 1, b: {c: 2}}2
86[a, b][1].c{a: null, b: null}null
87[a, b][1].c{}null
88[a, b][1].c{a: 'x', b: 5}null
89{k: a}.k ?? 9{a: 1, b: {c: 2}}1bug: postfix access works on a parenthesized object literal but not a bare one
90{k: a}.k ?? 9{a: null, b: null}9bug: postfix access works on a parenthesized object literal but not a bare one
91{k: a}.k ?? 9{}9bug: postfix access works on a parenthesized object literal but not a bare one
92{k: a}.k ?? 9{a: 'x', b: 5}'x'bug: postfix access works on a parenthesized object literal but not a bare one
93({k: a}).k ?? 9{a: 1, b: {c: 2}}1
94({k: a}).k ?? 9{a: null, b: null}9
95({k: a}).k ?? 9{}9
96({k: a}).k ?? 9{a: 'x', b: 5}'x'
97[[a]][0][0] ?? 9{a: 1, b: {c: 2}}1
98[[a]][0][0] ?? 9{a: null, b: null}9
99[[a]][0][0] ?? 9{}9
100[[a]][0][0] ?? 9{a: 'x', b: 5}'x'
101{[a]: 1}{a: 'k'}{k: 1}
102{[a]: 1}{a: null}{null: 1}question: a null computed key becomes the string 'null'
103{[a]: 1}{}{null: 1}question: a null computed key becomes the string 'null'
104{[a]: 1}{a: 2}{'2': 1}
105# Templates interpolate null as the text null and fail on errors inside an interpolation
106`${n} (${age})`{n: 'Ann', age: 30}'Ann (30)'
107`${n} (${age})`{n: 'Ann', age: null}'Ann (null)'
108`${n} (${age})`{n: 'Ann'}'Ann (null)'
109`${n} (${age})`{}'null (null)'
110`${n} (${age})`{n: ['A'], age: 1}!error
111`${n} (${age})`{n: 'Ann', age: 2.50}'Ann (2.50)'
112`${n ?? '?'} (${age ?? '-'})`{n: 'Ann', age: 30}'Ann (30)'
113`${n ?? '?'} (${age ?? '-'})`{n: 'Ann', age: null}'Ann (-)'
114`${n ?? '?'} (${age ?? '-'})`{n: 'Ann'}'Ann (-)'
115`${n ?? '?'} (${age ?? '-'})`{}'? (-)'
116`${n ?? '?'} (${age ?? '-'})`{n: ['A'], age: 1}!error
117`${n ?? '?'} (${age ?? '-'})`{n: 'Ann', age: 2.50}'Ann (2.50)'
118`${n} is ${age + 1}`{n: 'Ann', age: 30}'Ann is 31'
119`${n} is ${age + 1}`{n: 'Ann', age: null}!error
120`${n} is ${age + 1}`{n: 'Ann'}!error
121`${n} is ${age + 1}`{}!error
122`${n} is ${age + 1}`{n: ['A'], age: 1}!error
123`${n} is ${age + 1}`{n: 'Ann', age: 2.50}'Ann is 3.50'
124`${age == null ? 'unknown' : age}`{n: 'Ann', age: 30}'30'
125`${age == null ? 'unknown' : age}`{n: 'Ann', age: null}'unknown'
126`${age == null ? 'unknown' : age}`{n: 'Ann'}'unknown'
127`${age == null ? 'unknown' : age}`{}'unknown'
128`${age == null ? 'unknown' : age}`{n: ['A'], age: 1}'1'
129`${age == null ? 'unknown' : age}`{n: 'Ann', age: 2.50}'2.50'
130`${upper(n)}`{n: 'Ann', age: 30}'ANN'
131`${upper(n)}`{n: 'Ann', age: null}'ANN'
132`${upper(n)}`{n: 'Ann'}'ANN'
133`${upper(n)}`{}!error
134`${upper(n)}`{n: ['A'], age: 1}!error
135`${upper(n)}`{n: 'Ann', age: 2.50}'ANN'
136`${type(age)}`{n: 'Ann', age: 30}'number'
137`${type(age)}`{n: 'Ann', age: null}'null'
138`${type(age)}`{n: 'Ann'}'null'
139`${type(age)}`{}'null'
140`${type(age)}`{n: ['A'], age: 1}'number'
141`${type(age)}`{n: 'Ann', age: 2.50}'number'
142`${age / 0}`{n: 'Ann', age: 30}'null'
143`${age / 0}`{n: 'Ann', age: null}!error
144`${age / 0}`{n: 'Ann'}!error
145`${age / 0}`{}!error
146`${age / 0}`{n: ['A'], age: 1}'null'
147`${age / 0}`{n: 'Ann', age: 2.50}'null'
148`${n}` == 'null'{n: 'Ann', age: 30}false
149`${n}` == 'null'{n: 'Ann', age: null}false
150`${n}` == 'null'{n: 'Ann'}false
151`${n}` == 'null'{}true
152`${n}` == 'null'{n: ['A'], age: 1}!error
153`${n}` == 'null'{n: 'Ann', age: 2.50}false
154# String concatenation with null is an errorstring() and templates are the null-safe forms
155s + t{s: 'a', t: 'b'}'ab'
156s + t{s: 'a', t: null}!error
157s + t{s: 'a'}!error
158s + t{t: 'b'}!error
159s + t{s: 'a', t: 1}!error
160s + (t ?? ''){s: 'a', t: 'b'}'ab'
161s + (t ?? ''){s: 'a', t: null}'a'
162s + (t ?? ''){s: 'a'}'a'
163s + (t ?? ''){t: 'b'}!error
164s + (t ?? ''){s: 'a', t: 1}!error
165(s ?? '') + (t ?? ''){s: 'a', t: 'b'}'ab'
166(s ?? '') + (t ?? ''){s: 'a', t: null}'a'
167(s ?? '') + (t ?? ''){s: 'a'}'a'
168(s ?? '') + (t ?? ''){t: 'b'}'b'
169(s ?? '') + (t ?? ''){s: 'a', t: 1}!error
170s + string(t){s: 'a', t: 'b'}'ab'
171s + string(t){s: 'a', t: null}'anull'
172s + string(t){s: 'a'}'anull'
173s + string(t){t: 'b'}!error
174s + string(t){s: 'a', t: 1}'a1'
175`${s}${t}`{s: 'a', t: 'b'}'ab'
176`${s}${t}`{s: 'a', t: null}'anull'
177`${s}${t}`{s: 'a'}'anull'
178`${s}${t}`{t: 'b'}'nullb'
179`${s}${t}`{s: 'a', t: 1}'a1'
180t == null ? s : s + t{s: 'a', t: 'b'}'ab'
181t == null ? s : s + t{s: 'a', t: null}'a'
182t == null ? s : s + t{s: 'a'}'a'
183t == null ? s : s + t{t: 'b'}!error
184t == null ? s : s + t{s: 'a', t: 1}!error
185# Member access chains mixing computed keys, indexes and nulls
186m[k][i].v{m: {x: [{v: 1}]}, k: 'x', i: 0}1
187m[k][i].v{m: {x: [{v: 1}]}, k: 'y', i: 0}null
188m[k][i].v{m: {x: [{v: 1}]}, k: null, i: 0}null
189m[k][i].v{m: {x: [{v: 1}]}, k: 'x', i: 1}null
190m[k][i].v{m: {x: [{v: 1}]}, k: 'x'}null
191m[k][i].v{m: {x: [null]}, k: 'x', i: 0}null
192m[k][i].v{m: null, k: 'x', i: 0}null
193m[k][i].v{}null
194m[k][i].v ?? -1{m: {x: [{v: 1}]}, k: 'x', i: 0}1
195m[k][i].v ?? -1{m: {x: [{v: 1}]}, k: 'y', i: 0}-1
196m[k][i].v ?? -1{m: {x: [{v: 1}]}, k: null, i: 0}-1
197m[k][i].v ?? -1{m: {x: [{v: 1}]}, k: 'x', i: 1}-1
198m[k][i].v ?? -1{m: {x: [{v: 1}]}, k: 'x'}-1
199m[k][i].v ?? -1{m: {x: [null]}, k: 'x', i: 0}-1
200m[k][i].v ?? -1{m: null, k: 'x', i: 0}-1
201m[k][i].v ?? -1{}-1
202m[k][i].v + 1{m: {x: [{v: 1}]}, k: 'x', i: 0}2
203m[k][i].v + 1{m: {x: [{v: 1}]}, k: 'y', i: 0}!error
204m[k][i].v + 1{m: {x: [{v: 1}]}, k: null, i: 0}!error
205m[k][i].v + 1{m: {x: [{v: 1}]}, k: 'x', i: 1}!error
206m[k][i].v + 1{m: {x: [{v: 1}]}, k: 'x'}!error
207m[k][i].v + 1{m: {x: [null]}, k: 'x', i: 0}!error
208m[k][i].v + 1{m: null, k: 'x', i: 0}!error
209m[k][i].v + 1{}!error
210m[k ?? 'x'][i ?? 0].v{m: {x: [{v: 1}]}, k: 'x', i: 0}1
211m[k ?? 'x'][i ?? 0].v{m: {x: [{v: 1}]}, k: 'y', i: 0}null
212m[k ?? 'x'][i ?? 0].v{m: {x: [{v: 1}]}, k: null, i: 0}1
213m[k ?? 'x'][i ?? 0].v{m: {x: [{v: 1}]}, k: 'x', i: 1}null
214m[k ?? 'x'][i ?? 0].v{m: {x: [{v: 1}]}, k: 'x'}1
215m[k ?? 'x'][i ?? 0].v{m: {x: [null]}, k: 'x', i: 0}null
216m[k ?? 'x'][i ?? 0].v{m: null, k: 'x', i: 0}null
217m[k ?? 'x'][i ?? 0].v{}null
218m[k][i]{m: {x: [{v: 1}]}, k: 'x', i: 0}{v: 1}
219m[k][i]{m: {x: [{v: 1}]}, k: 'y', i: 0}null
220m[k][i]{m: {x: [{v: 1}]}, k: null, i: 0}null
221m[k][i]{m: {x: [{v: 1}]}, k: 'x', i: 1}null
222m[k][i]{m: {x: [{v: 1}]}, k: 'x'}null
223m[k][i]{m: {x: [null]}, k: 'x', i: 0}null
224m[k][i]{m: null, k: 'x', i: 0}null
225m[k][i]{}null
226# Slices of null are errors while indexes of null are null
227xs[0]{xs: [1, 2, 3]}1
228xs[0]{xs: null}null
229xs[0]{}null
230xs[0]{xs: 'abc'}'a'
231xs[0:1]{xs: [1, 2, 3]}[1, 2]
232xs[0:1]{xs: null}!errorquestion: slicing null errors while indexing null yields null
233xs[0:1]{}!errorquestion: slicing null errors while indexing null yields null
234xs[0:1]{xs: 'abc'}'ab'
235(xs ?? [0, 0])[0:1]{xs: [1, 2, 3]}[1, 2]
236(xs ?? [0, 0])[0:1]{xs: null}[0, 0]
237(xs ?? [0, 0])[0:1]{}[0, 0]
238(xs ?? [0, 0])[0:1]{xs: 'abc'}'ab'
239xs[0:1] ?? []{xs: [1, 2, 3]}[1, 2]
240xs[0:1] ?? []{xs: null}!errorquestion: slicing null errors while indexing null yields null
241xs[0:1] ?? []{}!errorquestion: slicing null errors while indexing null yields null
242xs[0:1] ?? []{xs: 'abc'}'ab'
243# A division-by-zero null reaching other operators and functions
244(x / y) ^ 2{x: 1, y: 0}!error
2452 ^ (x / y){x: 1, y: 0}!error
246(x / y) % 2{x: 1, y: 0}!error
247abs(x / y){x: 1, y: 0}!error
248abs(x / y){x: -1, y: 2}0.5
249len([x / y]){x: 1, y: 0}1
250[x / y] == [null]{x: 1, y: 0}truebug: == on arrays/objects is always false, even for a value compared with itself (Variable itself itself implements deep equality)
251(x / y) in [null, 0]{x: 1, y: 0}true
252(x / y) in [null, 0]{x: 0, y: 1}true
253(x / y) in [null, 0]{x: 1, y: 1}false
254count([1 / 0, 2 / 0, 1 / 1], # == null)2
255filter([1, 0, 2], 1 / # > 0)!error
256filter([1, 0, 2], (1 / #) != null)[1, 2]
257map([1, 0, 2], (1 / #) ?? 'inf')[1, 'inf', 0.5]
258some([0, 1], 1 / # > 0)!error
259some([1, 0], 1 / # > 0)true
260max(map([1, 0, 4], (8 / #) ?? 0))8
261# Coalesced defaults feeding functions
262max([x ?? 0, y ?? 0]){y: 3}3
263max([x ?? 0, y ?? 0]){x: -1, y: null}0
264max([x ?? 0, y ?? 0]){x: 'a'}!error
265min(map(xs, # ?? 99)){xs: [null, 5]}5
266min(map(xs, # ?? 99)){xs: [null]}99
267min(map(xs, # ?? 99)){xs: []}!error
268median(map(xs, # ?? 0)){xs: [null, 5, 1]}1
269mode(xs ?? [1]){}1
270avg(xs ?? [1, 2]){}1.5
271avg(xs ?? [1, 2]){xs: null}1.5
272avg(xs ?? [1, 2]){xs: [4]}4
273fuzzyMatch(s ?? '', 'a'){}0
274extract(s ?? '', '(a)'){}[]
275extract(s ?? '', '(a)'){s: 'xa'}['a', 'a']
276d(x ?? 0).year(){}1970
277string(x ?? null){}'null'
278bool(x ?? 'true'){}true
279bool(x ?? 'true'){x: false}false
280(x ?? 1) ^ (y ?? 2){}1
281(x ?? 1) ^ (y ?? 2){x: 3}9
282not (x ?? true){}false
283not (x ?? true){x: false}true
284-(x ?? 1){}-1
285-(x ?? 1){x: null}-1
286-(x ?? 1){x: 2}-2
287`${(x ?? [])[0]}`{}'null'
288`${len(x ?? '')}`{}'0'
289`${len(x ?? '')}`{x: 'abc'}'3'
290# Reassigning null and extending null in a program
291x = null; x.y.z{}null
292x = null; x[0]{}null
293x = null; x[0:1]{}!error
294x = {}; x.a.b = 1; x{}{a: {b: 1}}
295x.a = null; x.a.b = 1; x{}{a: {b: 1}}
296x.a = 1; x.a = null; x{}{a: null}
297x.a = 1; x.a = null; x.a ?? 'gone'{}'gone'
298x = 1; x = null; x ?? 2{}2
299x = 1; x = x / 0; x{}null
300x = [1, null]; x[1] ?? x[0]{}1
301x = m[k]; x ?? 'nokey'{m: {a: 1}, k: 'a'}1
302x = m[k]; x ?? 'nokey'{m: {a: 1}, k: 'b'}'nokey'
303x = m[k]; x ?? 'nokey'{m: {a: 1}}'nokey'
304x = m[k]; x ?? 'nokey'{k: 'a'}'nokey'
305# $root reads follow the same null rules
306$root.a.b ?? 1{a: null}1
307$root.a.b ?? 1{a: {b: 0}}0
308$root.a.b + 1{}!error
309$root[k] ?? 'd'{}'d'
310$root[k] ?? 'd'{k: null}'d'
311$root[k] ?? 'd'{k: 'k'}'k'
312$root.xs[0].a ?? -1{xs: [{a: 3}]}3
313$root.xs[0].a ?? -1{xs: []}-1
314$root.xs[0].a ?? -1{xs: null}-1