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