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

9.4 KiB

1expression (string)input (json 5)output (json 5)note
2# A program of only assignments returns an object of the assigned keys (not the whole environment)
3x = 1{}{x: 1}
4x = 1{y: 2}{x: 1}
5x = 1{x: 5}{x: 1}
6x = 1{x: 2, y: 3}{x: 1}
7x = 1{a: null}{x: 1}
8x = null{x: 5}{x: null}
9x = 'a'{}{x: 'a'}
10x = [1, 2]{}{x: [1, 2]}
11x = {a: 1}{}{x: {a: 1}}
12x = 1; y = 2{}{x: 1, y: 2}
13x = 1; y = 2{z: 3}{x: 1, y: 2}
14x = 1; y = x + 1{}{x: 1, y: 2}
15x = 1; x = x + 1{}{x: 2}
16x.y = 1; x = 2{}{x: 2}
17a.b = 1{}{a: {b: 1}}
18a.b = 1{a: {c: 2}}{a: {b: 1}}
19a.b = 1{a: {b: 0, c: 1}}{a: {b: 1}}
20a.b.c = 1{}{a: {b: {c: 1}}}
21a.b.c = 1{a: {b: 5}}{a: {b: {c: 1}}}
22a.b.c = 1; a.b.d = 2{}{a: {b: {c: 1, d: 2}}}
23a.b = 1; a.c = 2{a: {z: 0}}{a: {b: 1, c: 2}}
24x.y.z = 1{x: {y: {w: 2}}}{x: {y: {z: 1}}}
25# The assigned-keys object disagrees with the environment when a scalar is later extended
26a = 1; a.b = 2{}{a: {b: 2}}bug: env holds a = {b: 2} (a reads back as {b: 2}) but the returned object keeps a = 1
27a.b = 1; a.b.c = 2{}{a: {b: {c: 2}}}bug: env holds a.b = {c: 2} but the returned object silently keeps a.b = 1
28a = 1; a.b = 2; a{}{b: 2}
29a.b = 1; a.b.c = 2; a{}{b: {c: 2}}
30# Trailing semicolon
31x = 1;{}{x: 1}
32x = 1; y = 2;{}{x: 1, y: 2}
33x = 1; x;{}1bug: a trailing is accepted after an assignment but rejected after the final expression
34x = 1; x + 1;{}2bug: a trailing is accepted after an assignment but rejected after the final expression
35x = 1;; x{}!error
36# Final expression is the result
37x = 1; x{}1
38a = 5; b = 10; a + b{}15
39x = 1; y = 2; x + y{}3
40x = 1 ; y = 2 ; x + y{}3
41x=1;y=x*2;y{}2
42x = 1; x = x + 1; x{}2
43x = 1; x = 'a'; x = [x]; x{}['a']
44x = 1; y = x; x = 2; y{}1
45x = 1; y = 2; [x, y, z]{}[1, 2, null]
46x = 1; (x + 1){}2
47x = 1; {a: x}{}{a: 1}
48x = 1; [x]{}[1]
49x = 1; `v${x}`{}'v1'
50x = 1; -x{}-1
51x = 1; not true{}false
52x = 1; 'str'{}'str'
53x = 1; map([1], # + x){}[2]
54x = 'a'; y = x + 'b'; y{}'ab'
55x = [1, 2]; x[0]{}1
56x = [1, 2, 3]; x[1:2]{}[2, 3]
57x = 'ab'; x[0]{}'a'
58x = {a: 1}; x.a{}1
59x = 1; y = x.z; y{}null
60x = 1 == 1; x{}true
61x = 1 ?? 2; x{}1
62x = true and false; x{}false
63x = 1 > 0 ? 'a' : 'b'; x{}'a'
64x = [1..5]; 3 in x{}true
65user.name = 'Eve'; user.name{}'Eve'
66config.debug = true; config.env = 'dev'; config{}{debug: true, env: 'dev'}
67config.debug = true; config.env = 'dev'; $root{}{config: {debug: true, env: 'dev'}}
68# Assignments read the input
69x = x + 1; x{x: 1}2
70x = x + 1; x{x: 1.5}2.5
71x = x + 1; x{x: null}!error
72x = x + 1; x{}!error
73x = x + 1; x{x: 'a'}!error
74x = x ?? 'd'; x{x: null}'d'
75x = x ?? 'd'; x{}'d'
76x = x ?? 'd'; x{x: 'v'}'v'
77x = x ?? 'd'; x{x: 0}0
78x = x ?? 'd'; x{x: false}false
79total = price * qty; total{price: 2, qty: 3}6
80total = price * qty; total{price: 2.5, qty: 2}5
81total = price * qty; total{price: 0, qty: 2}0
82total = price * qty; total{price: null, qty: 2}!error
83total = price * qty; total{qty: 2}!error
84total = price * qty; total{price: '2', qty: 2}!error
85x = a[0]; x{a: [7]}7
86x = a[0]; x{a: []}null
87x = a[0]; x{a: null}null
88x = a[0]; x{}null
89x = a.b; x{a: {b: 'v'}}'v'
90x = a.b; x{a: 5}null
91x = a.b; x{}null
92u.name = upper(u.name); u{u: {name: 'ann', age: 3}}{name: 'ANN', age: 3}
93u.name = upper(u.name); u{u: {name: 'ann'}}{name: 'ANN'}
94u.name = upper(u.name); u{u: {name: 'x', tags: [1]}}{name: 'X', tags: [1]}
95a.b = a.b + 1; a{a: {b: 1, c: 2}}{b: 2, c: 2}
96a.b = a.b + 1{a: {b: 1, c: 2}}{a: {b: 2}}
97a.b = a.b + 1; a.b{a: null}!error
98a.b = (a.b ?? 0) + 1; a.b{a: {b: 41}}42
99a.b = (a.b ?? 0) + 1; a.b{a: null}1
100a.b = (a.b ?? 0) + 1; a.b{a: 5}1
101a.b = (a.b ?? 0) + 1; a.b{}1
102a.b = (a.b ?? 0) + 1; a.b{a: {c: 1}}1
103# Dotted assignment merges into existing objects and replaces non-objects
104a.b = 1; a{a: {c: 2}}{b: 1, c: 2}
105a.b = 1; a{a: {}}{b: 1}
106a.b = 1; a{a: 5}{b: 1}
107a.b = 1; a{a: null}{b: 1}
108a.b = 1; a{a: [1]}{b: 1}
109a.b = 1; a{a: 'str'}{b: 1}
110a.b = 1; a{}{b: 1}
111a.b.c = 1; a{a: {b: 5}}{b: {c: 1}}
112x.y.z = 1; x{x: {y: {w: 2}, v: 3}}{v: 3, y: {w: 2, z: 1}}
113x.y.z = 1; x.y{x: {y: {w: 2}}}{w: 2, z: 1}
114x.y.z = 1; x.y.z{}1
115a.b = 1; $root{a: {c: 2}}{a: {b: 1, c: 2}}
116a.b = 1; a.b{}1
117a.b = 1; a['b']{}1
118a.b = 1; a[k]{k: 'b'}1
119a.b = 1; a.b + a.c{a: {c: 2}}3
120a.b = 1; x = a.b + 1; x{}2
121a.b.c = 1; a.b.d = 2; a{}{b: {c: 1, d: 2}}
122x.y = 1; x.y = 2; x{}{y: 2}
123x = 1; x.y = 2; x{}{y: 2}
124x.y = 1; x = 2; x{}2
125x = {a: 1}; x.a = 2; x{}{a: 2}
126x = {a: 1}; x.b = 2; x{}{a: 1, b: 2}
127# $root sees assignments
128x = 1; $root{}{x: 1}
129x = 1; $root{x: 0}{x: 1}
130x = 1; $root{y: 2}{x: 1, y: 2}
131x = x + 1; $root{x: 1, y: 2}{x: 2, y: 2}
132x = 1; y = 2; $root{x: 0, y: 0, z: 0}{x: 1, y: 2, z: 0}
133x = 1; y = $root; y{a: 2}{a: 2, x: 1}
134x = 1; y = $root; y.x{a: 2}1
135x = 1; k = 'x'; $root[k]{}1
136x = 1; ($root).x{x: 5}1
137x = 1; $root.x{}1bug: $root.x compiles to a fast path that reads the original input while $root and ($root).x see the assignment
138x = 1; $root.x{x: 5}1bug: $root.x reads the original input (5) while ($root).x reads the assigned 1
139x = 1; $root['x']{}1bug: $root['x'] compiles to a fast path that reads the original input
140x = 1; $root['x']{x: 5}1bug: $root['x'] reads the original input while $root[k] with k = 'x' sees the assignment
141a.b = 1; $root.a.b{}1bug: $root.a.b reads the original input instead of the assigned value
142a.b = 1; $root.a.b{a: {b: 0}}1bug: $root.a.b reads the original input instead of the assigned value
143x.y = 1; $root.x{x: {z: 1}}{y: 1, z: 1}bug: $root.x reads the original input instead of the assigned value
144x.y = 1; $root.x.y{x: {z: 1}}1bug: $root.x.y reads the original input instead of the assigned value
145# Assigning to $root and $-prefixed names
146$root = 1{}{'$root': 1}question: $root is accepted as an assignment target and creates a literal '$root' key
147$root.x = 1{}{'$root': {x: 1}}question: $root.x = 1 writes a nested '$root' key instead of assigning x at the root
148$root.x = 1; x{}nullquestion: $root.x = 1 does not make x visible
149$root.x = 1; $root{}{'$root': {x: 1}}question: $root.x = 1 writes a literal '$root' key into the environment
150$x = 1; $x{}1
151$ = 1; ${}1
152_x = 1; _x{}1
153x1 = 1; x1{}1
154len = 1; len{}1
155d = 1; d{}1
156x = 1; X{}null
157# Invalid assignment targets and malformed programs
158a['b'] = 1{}!error
159a[0] = 1{a: [0]}!error
160a[k] = 1{k: 'b'}!error
161a.b[0] = 1{}!error
162true = 1{}!error
163null = 1{}!error
164in = 1{}!error
165x.true = 1; x{}!error
166= 1{}!error
167x ={}!error
168x = ;{}!error
169x = 1 = 2{}!error
170x = 1, y = 2{}!error
171x = 1 y = 2{}!error
172x == 1; y = 2{x: 1}!error
173x = 1; x + 1; 5{}!error
1745; x = 1{}!error
1751 + 1; 2{}!error
176x = 3; filter(list, # > x); x{list: [1, 5]}!error
177# An assignment as the value of another assignment
178x = 1; y = x.w = 2{}{x: 1, y: {x: {w: 2}}}question: y = x.w = 2 parses the right side as a nested assignment program whose value is its assigned-keys object and which also rebinds x
179# Assignment values that error or produce null
180x = 1 + {}; 2{}!error
181x = y; x{}null
182x = null; x{x: 5}null
183x = 1; x + y{y: 2}3
184x = y + 1; y = 5; x{}!error
185x = y + 1; y = 5; x{y: 1}2
186x = y + 1; y = 5; [x, y]{y: 1}[2, 5]
187# Assignments need an object environment
188x = 1!errorquestion: assignments need an object environment - with no input they fail
189x = 1; x!errorquestion: assignments need an object environment - with no input they fail
190x = 15!error
191x = 1[1]!error
192x = 1's'!error
193x = 1true!error
194# Values are copied on assignment - later writes do not reach other names or the input
195b = a; a = 5; b{a: {x: 1}}{x: 1}
196b = a; a.c = 1; b{a: {x: 1}}{x: 1}
197x.y = 1; z = x; x.w = 2; z{}{y: 1}
198b = list; list = map(list, 0); b{list: [1, 2]}[1, 2]
199f = map(list, #); list = [9]; f{list: [1, 2]}[1, 2]
200b = a; b.c = 1; a{a: {x: 1}}{x: 1}bug: b.c = 1 mutates the object shared with a (and the caller's input) in place
201b = a; b.c = 1; a{a: {}}{}bug: b.c = 1 mutates the object shared with a (and the caller's input) in place
202b = a; b.x = 2; a.x{a: {x: 1}}1bug: b.x = 2 overwrites a.x through the shared reference
203b = a; b.c = 1; $root{a: {x: 1}}{a: {x: 1}, b: {c: 1, x: 1}}bug: b.c = 1 leaks into a through the shared reference
204b = a; b.c = 1{a: {x: 1}}{b: {c: 1, x: 1}}
205b = a.x; b.z = 2; a{a: {x: {y: 1}}}{x: {y: 1}}bug: b.z = 2 mutates the nested input object a.x in place
206c = {v: 1}; d = c; d.v = 2; c.v{}1bug: d.v = 2 mutates c through the shared reference
207c = {v: 1}; d = c; c.v = 2; d.v{}1bug: c.v = 2 mutates d through the shared reference (the reverse direction on input a does not)
208x.y = 1; z = x; z.w = 2; x{}{y: 1}bug: z.w = 2 mutates x through the shared reference while x.w = 2 does not reach z
209x.y = 1; z = x; z.w = 2; $root{}{x: {y: 1}, z: {w: 2, y: 1}}bug: z.w = 2 leaks into x through the shared reference
210# Parenthesized statement sequences
211(t = 1; t + 1){}2
212(t = 1; t + 1) * 10{}20
2131 + (t = 1; t){}2
214(a = 1; b = 2; a + b){}3
215x = (y = 1; z = 2; y + z); x{}3
216x = 1; y = (z = 2; z + x){}{x: 1, y: 3}
217(t = 1){}!error
218x = (y = 1; z = 2); x{}!error
219(t = 1; t + 1); t{}!errorquestion: a program cannot begin with a parenthesized sequence followed by more statements