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.
8.7 KiB
8.7 KiB
| 1 | expression (string);input (json 5);output (json 5);note |
|---|---|
| 2 | # map: element transformation, one result per element, order preserved |
| 3 | map([1, 2, 3], # * 2);;[2, 4, 6] |
| 4 | map([], # * 2);;[] |
| 5 | map([7], # + 1);;[8] |
| 6 | map([1, 2, 3], #);;[1, 2, 3] |
| 7 | map([1, 2], 'x');;['x', 'x'] |
| 8 | map([1, 2], null);;[null, null] |
| 9 | map([1, 2], 5);;[5, 5] |
| 10 | map([1, 'a', true, null], #);;[1, 'a', true, null] |
| 11 | map([1, 'a', true, null, [1], {a: 1}], type(#));;['number', 'string', 'bool', 'null', 'array', 'object'] |
| 12 | map([1, null, 3], # ?? 0);;[1, 0, 3] |
| 13 | map([1, null, 3], # * 2);;!error |
| 14 | map([1, 2, 3], # > 1 ? 'big' : 'small');;['small', 'big', 'big'] |
| 15 | map([1, 2, 3], # == 2 ? 'x' : null);;[null, 'x', null] |
| 16 | map([0.1, 0.2], # + 0.1);;[0.2, 0.3] |
| 17 | map([1.5, 2.25, -0.10], # * 2);;[3, 4.5, -0.2] |
| 18 | map([1.5, 2.25, -0.10], string(# * 2));;['3.0', '4.50', '-0.20'] |
| 19 | map(['a', 'b', 'c'], # + '!');;['a!', 'b!', 'c!'] |
| 20 | map(['héllo', '日本', ''], upper(#));;['HÉLLO', '日本', ''] |
| 21 | map([true, false], not #);;[false, true] |
| 22 | map([[1, 2], [], [3]], len(#));;[2, 0, 1] |
| 23 | map([[1, 2], [3]], #);;[[1, 2], [3]] |
| 24 | map([{a: 1}, {a: 2}], #);;[{a: 1}, {a: 2}] |
| 25 | map([{a: 1}, {b: 2}], #.a);;[1, null] |
| 26 | map([{a: {b: 1}}, {a: null}, {}], #.a.b);;[1, null, null] |
| 27 | map([1, 2], [#, # * 10]);;[[1, 10], [2, 20]] |
| 28 | map([1, 2], {v: #});;[{v: 1}, {v: 2}] |
| 29 | map([1, 2], {v: #, [string(#)]: # * 2});;[{v: 1, '1': 2}, {v: 2, '2': 4}] |
| 30 | map([1, 2], `n${#}`);;['n1', 'n2'] |
| 31 | map([d('2024-01-01'), d('2024-01-02')], #.day());;[1, 2] |
| 32 | map([1, 0, 2], 1 / #);;[1, null, 0.5];question: division by zero inside a closure yields null (not an error); see operators chapter |
| 33 | map([1, 2, 3], # % 2 == 0);;[false, true, false] |
| 34 | # map: non-list first argument |
| 35 | map(null, #);;!error;question: a null list is an error rather than an empty list |
| 36 | map(5, #);;!error |
| 37 | map('abc', #);;!error |
| 38 | map(true, #);;!error |
| 39 | map({a: 1}, #);;!error |
| 40 | map(d('2024-01-01'), #);;!error |
| 41 | # map: parse errors |
| 42 | map([1, 2]);;!error |
| 43 | map();;!error |
| 44 | map([1, 2], #, 3);;!error |
| 45 | map([1, 2], # , );;!error |
| 46 | map([1, 2] as, #);;!error |
| 47 | map([1, 2] as 1, #);;!error |
| 48 | # map: element errors propagate |
| 49 | map([1, 'a', 3], # * 2);;!error |
| 50 | map([1, 2, 'a'], # * 2);;!error |
| 51 | map(['a', 1], upper(#));;!error |
| 52 | # filter: keeps elements whose predicate is true, preserves order and values |
| 53 | filter([1, 2, 3, 4, 5], # > 3);;[4, 5] |
| 54 | filter([], # > 3);;[] |
| 55 | filter([4], # > 3);;[4] |
| 56 | filter([1], # > 3);;[] |
| 57 | filter([1, 2, 3], true);;[1, 2, 3] |
| 58 | filter([1, 2, 3], false);;[] |
| 59 | filter([true, false, true], #);;[true, true] |
| 60 | filter([1, null, 3], # != null);;[1, 3] |
| 61 | filter([1, 'a', true, null], # == 'a');;['a'] |
| 62 | filter([1, 'a', true, null], type(#) == 'number');;[1] |
| 63 | filter([1.5, 2.25, -0.10], # < 2);;[1.5, -0.10] |
| 64 | filter(['a', 'b', 'c', 'd'], # in ['a', 'c']);;['a', 'c'] |
| 65 | filter(['héllo', 'abc', 'hé'], startsWith(#, 'h'));;['héllo', 'hé'] |
| 66 | filter([{a: 1}, {a: null}, {}], #.a != null);;[{a: 1}] |
| 67 | filter([{id: 1}, {id: 2}], #.id > 1);;[{id: 2}] |
| 68 | filter([[1, 2], [3]], len(#) > 1);;[[1, 2]] |
| 69 | filter([[1, 2], [3]], some(#, # > 2));;[[3]] |
| 70 | filter([1, 2, 3], not (# == 2));;[1, 3] |
| 71 | filter([1, 2, 3], !(# == 2));;[1, 3] |
| 72 | filter([d('2024-01-01'), d('2024-03-02')], #.month() > 1);;['2024-03-02T00:00:00Z'] |
| 73 | # filter: predicate must be boolean |
| 74 | filter([1, 2], 1);;!error |
| 75 | filter([1, 2], 'yes');;!error |
| 76 | filter([1, 2], null);;!error;question: a null predicate is an error, not treated as false |
| 77 | filter([1, null, 3], #);;!error |
| 78 | filter([1, 2], [#]);;!error |
| 79 | filter([], 1);;[] |
| 80 | # filter: non-list first argument and element errors |
| 81 | filter(null, true);;!error |
| 82 | filter(5, true);;!error |
| 83 | filter('abc', true);;!error |
| 84 | filter({a: 1}, true);;!error |
| 85 | filter([1, 'a', 3], # > 1);;!error |
| 86 | filter([1, 0, 2], 1 / # > 0);;!error |
| 87 | # some: true when any element matches, stops at the first match |
| 88 | some([1, 2, 3], # > 2);;true |
| 89 | some([1, 2, 3], # > 3);;false |
| 90 | some([], true);;false |
| 91 | some([], # > 0);;false |
| 92 | some([5], # > 3);;true |
| 93 | some([1], # > 3);;false |
| 94 | some(['a', 'b', 'c'], # == 'b');;true |
| 95 | some(['a', 'b', 'c'], # == 'd');;false |
| 96 | some([1, 'a', null], # == null);;true |
| 97 | some([{a: 1}, {}], #.a == null);;true |
| 98 | some([[1], [2, 3]], 3 in #);;true |
| 99 | some([false, false], #);;false |
| 100 | some([false, true], #);;true |
| 101 | some([2, 'a'], # > 1);;true |
| 102 | some(['a', 2], # > 1);;!error |
| 103 | some([5, null], # > 3);;true |
| 104 | some([1, null, 5], # > 3);;!error |
| 105 | some([1, 2], 'a');;!error |
| 106 | some([false, null], #);;!error;question: a null predicate result is an error, not falsy |
| 107 | some(null, true);;!error |
| 108 | some('abc', true);;!error |
| 109 | some({a: 1}, true);;!error |
| 110 | # all: true when every element matches, stops at the first failure |
| 111 | all([1, 2, 3], # > 0);;true |
| 112 | all([1, 2, 3], # > 1);;false |
| 113 | all([], false);;true |
| 114 | all([], # > 100);;true |
| 115 | all([1], # > 0);;true |
| 116 | all([0], # > 0);;false |
| 117 | all(['a', 'b', 'c'], # in ['a', 'b', 'c', 'd']);;true |
| 118 | all(['a', 'b', 'c'], # in ['a', 'b']);;false |
| 119 | all([true, true], #);;true |
| 120 | all([true, false], #);;false |
| 121 | all([1, 2], # > 0 and # < 3);;true |
| 122 | all([{a: 1}, {a: 2}], #.a > 0);;true |
| 123 | all([{a: 1}, {}], #.a != null);;false |
| 124 | all([0, 'a'], # > 0);;false |
| 125 | all(['a', 0], # > 0);;!error |
| 126 | all([1, 'a'], # > 0);;!error |
| 127 | all([true, null], #);;!error;question: a null predicate result is an error, not falsy |
| 128 | all([1, 2], 1);;!error |
| 129 | all(null, true);;!error |
| 130 | all(5, true);;!error |
| 131 | # none: true when no element matches, stops at the first match |
| 132 | none([1, 2, 3], # > 5);;true |
| 133 | none([1, 2, 3], # > 2);;false |
| 134 | none([], true);;true |
| 135 | none([], # > 0);;true |
| 136 | none([1], # == 1);;false |
| 137 | none([1], # == 2);;true |
| 138 | none(['a', 'b'], # == 'c');;true |
| 139 | none([false, false], #);;true |
| 140 | none([true, false], #);;false |
| 141 | none([{a: 1}, {a: 2}], #.a > 5);;true |
| 142 | none([5, 'a'], # > 1);;false |
| 143 | none(['a', 5], # > 1);;!error |
| 144 | none([1, 2], 'x');;!error |
| 145 | none(null, true);;!error |
| 146 | none({a: 1}, true);;!error |
| 147 | # one: true when exactly one element matches |
| 148 | one([1, 2, 3], # == 2);;true |
| 149 | one([1, 2, 3], # == 5);;false |
| 150 | one([1, 2, 3], # > 1);;false |
| 151 | one([1, 2, 3], # > 0);;false |
| 152 | one([], true);;false |
| 153 | one([1], true);;true |
| 154 | one([1], false);;false |
| 155 | one([1, 1], # == 1);;false |
| 156 | one(['a', 'b', 'c'], # == 'c');;true |
| 157 | one([true, false], #);;true |
| 158 | one([true, true], #);;false |
| 159 | one([{a: 1}, {a: 2}, {}], #.a == 2);;true |
| 160 | one([1, 1, 'a'], # == 1);;false |
| 161 | one([1, 2, 'a'], # > 0);;!error;question: one() keeps evaluating after a second match, so a later erroring element fails the whole call |
| 162 | one(['a', 1], # > 0);;!error |
| 163 | one([1, 2], 1);;!error |
| 164 | one(null, true);;!error |
| 165 | one('abc', true);;!error |
| 166 | # count: number of matching elements |
| 167 | count([1, 2, 3, 4, 5, 2], # == 2);;2 |
| 168 | count([1, 2, 3], # > 5);;0 |
| 169 | count([], true);;0 |
| 170 | count([], # > 0);;0 |
| 171 | count([1], true);;1 |
| 172 | count([1, 2, 3], true);;3 |
| 173 | count([1, 2, 3], false);;0 |
| 174 | count([true, false, true], #);;2 |
| 175 | count([1, 'a', null, true], type(#) == 'string');;1 |
| 176 | count([{a: 1}, {a: 2}, {}], #.a != null);;2 |
| 177 | count([[1], [], [2, 3]], len(#) > 0);;2 |
| 178 | count(['héllo', 'hé', 'x'], contains(#, 'é'));;2 |
| 179 | count([1..10], # % 3 == 0);;3 |
| 180 | count([1, 2], 1);;!error |
| 181 | count([1, 'a'], # > 0);;!error |
| 182 | count([1], #);;!error |
| 183 | count(null, true);;!error |
| 184 | count({a: 1}, true);;!error |
| 185 | # count agrees with len of filter and with len for an always-true predicate |
| 186 | count([1, 2, 3, 4], # % 2 == 0) == len(filter([1, 2, 3, 4], # % 2 == 0));;true |
| 187 | count([1, 2, 3], true) == len([1, 2, 3]);;true |
| 188 | count([[1, 2, 3]], true);;1 |
| 189 | len([[1, 2, 3]]);;1 |
| 190 | # flatMap: map then flatten one level |
| 191 | flatMap([[1, 2], [3, 4], [5, 6]], #);;[1, 2, 3, 4, 5, 6] |
| 192 | flatMap([], #);;[] |
| 193 | flatMap([[]], #);;[] |
| 194 | flatMap([[], [1]], #);;[1] |
| 195 | flatMap([1, 2], [#, # * 10]);;[1, 10, 2, 20] |
| 196 | flatMap([1, 2], [#]);;[1, 2] |
| 197 | flatMap([1, 2], #);;[1, 2] |
| 198 | flatMap([1, [2, [3]]], #);;[1, 2, [3]] |
| 199 | flatMap([[1], [2]], [#]);;[[1], [2]] |
| 200 | flatMap([[1], null], #);;[1, null] |
| 201 | flatMap([1, 2], []);;[] |
| 202 | flatMap(['a', 'b'], [#, upper(#)]);;['a', 'A', 'b', 'B'] |
| 203 | flatMap([{t: ['a', 'b']}, {t: []}, {}], #.t);;['a', 'b', null] |
| 204 | flatMap([{t: ['a', 'b']}, {t: []}, {}], #.t ?? []);;['a', 'b'] |
| 205 | flatMap([[1, 2], [3]], map(#, # + 1));;[2, 3, 4] |
| 206 | flatMap(null, #);;!error |
| 207 | flatMap('ab', #);;!error |
| 208 | flatMap([1, 'a'], # * 2);;!error |
| 209 | # intervals as closure sources |
| 210 | map([0..3], #);;[0, 1, 2, 3] |
| 211 | map((0..3], #);;[1, 2, 3] |
| 212 | map([0..3), #);;[0, 1, 2] |
| 213 | map((0..3), #);;[1, 2] |
| 214 | map([1..1], #);;[1] |
| 215 | map((1..1), #);;[] |
| 216 | map([3..1], #);;[] |
| 217 | map([-2..1], #);;[-2, -1, 0, 1] |
| 218 | map([1..5], # * 2);;[2, 4, 6, 8, 10] |
| 219 | filter([0..10], # % 2 == 0);;[0, 2, 4, 6, 8, 10] |
| 220 | some([1..3], # == 2);;true |
| 221 | all((0..5], # > 0);;true |
| 222 | none([1..3), # == 3);;true |
| 223 | one([1..3], # == 3);;true |
| 224 | count((1..5), true);;3 |
| 225 | flatMap([1..2], [#, #]);;[1, 1, 2, 2] |
| 226 | sum(map([1..4], #));;10 |
| 227 | map([a..b], #);{a: 1, b: 4};[1, 2, 3, 4] |
| 228 | map((a..b), #);{a: 1, b: 4};[2, 3] |
| 229 | map([a..b], #);{a: 'x', b: 4};!error |
| 230 | map([a..b], #);{a: null, b: 4};!error |
| 231 | map(['a'..'c'], #);;!error |
| 232 | map([1.5..3], #);;[2, 3];bug: iterating [1.5..3] yields 1, which lies outside the interval (bound truncated) |
| 233 | map([1..2.5), #);;[1, 2];bug: iterating [1..2.5) drops 2, which lies inside the interval (bound truncated before exclusion) |
| 234 | map((0.5..2], #);;[1, 2] |
| 235 | map([0..2], #) == [0, 1, 2];;false;question: array == compares by identity, so equal arrays are not equal (see equality chapter) |
| 236 | 1..5;;!error |
| 237 | map(1..5, #);;!error |