@elaraai/east 1.0.104 → 1.0.105
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/compile/builtins/primitives.d.ts +1 -1
- package/dist/src/compile/control.d.ts.map +1 -1
- package/dist/src/compile/control.js +10 -5
- package/dist/src/compile/control.js.map +1 -1
- package/dist/src/compile.open_beast.spec.js +7 -3
- package/dist/src/compile.open_beast.spec.js.map +1 -1
- package/dist/src/query/jq/narrow.d.ts +68 -0
- package/dist/src/query/jq/narrow.d.ts.map +1 -0
- package/dist/src/query/jq/narrow.js +691 -0
- package/dist/src/query/jq/narrow.js.map +1 -0
- package/dist/src/query/jq/split.d.ts +35 -11
- package/dist/src/query/jq/split.d.ts.map +1 -1
- package/dist/src/query/jq/split.js +205 -35
- package/dist/src/query/jq/split.js.map +1 -1
- package/dist/src/query/jq/translate-builtins.d.ts.map +1 -1
- package/dist/src/query/jq/translate-builtins.js +43 -8
- package/dist/src/query/jq/translate-builtins.js.map +1 -1
- package/dist/src/query/jq/translate.d.ts +55 -4
- package/dist/src/query/jq/translate.d.ts.map +1 -1
- package/dist/src/query/jq/translate.js +174 -21
- package/dist/src/query/jq/translate.js.map +1 -1
- package/dist/src/runner_exec.d.ts +10 -0
- package/dist/src/runner_exec.d.ts.map +1 -1
- package/dist/src/runner_exec.js +11 -3
- package/dist/src/runner_exec.js.map +1 -1
- package/dist/src/runner_exec.spec.js +40 -2
- package/dist/src/runner_exec.spec.js.map +1 -1
- package/dist/src/serialization/beast2/index.d.ts +2 -1
- package/dist/src/serialization/beast2/index.d.ts.map +1 -1
- package/dist/src/serialization/beast2/index.js +2 -1
- package/dist/src/serialization/beast2/index.js.map +1 -1
- package/dist/src/serialization/beast2/v5/codec.d.ts +30 -1
- package/dist/src/serialization/beast2/v5/codec.d.ts.map +1 -1
- package/dist/src/serialization/beast2/v5/codec.js +24 -3
- package/dist/src/serialization/beast2/v5/codec.js.map +1 -1
- package/dist/src/serialization/beast2/v5/lazy.d.ts +23 -4
- package/dist/src/serialization/beast2/v5/lazy.d.ts.map +1 -1
- package/dist/src/serialization/beast2/v5/lazy.js +84 -19
- package/dist/src/serialization/beast2/v5/lazy.js.map +1 -1
- package/dist/src/serialization/beast2/v5/project.d.ts +156 -0
- package/dist/src/serialization/beast2/v5/project.d.ts.map +1 -0
- package/dist/src/serialization/beast2/v5/project.js +830 -0
- package/dist/src/serialization/beast2/v5/project.js.map +1 -0
- package/dist/src/serialization/beast2/v5/project.spec.d.ts +6 -0
- package/dist/src/serialization/beast2/v5/project.spec.d.ts.map +1 -0
- package/dist/src/serialization/beast2/v5/project.spec.js +273 -0
- package/dist/src/serialization/beast2/v5/project.spec.js.map +1 -0
- package/dist/src/serialization/beast2/v5/runs.d.ts +78 -7
- package/dist/src/serialization/beast2/v5/runs.d.ts.map +1 -1
- package/dist/src/serialization/beast2/v5/runs.js +218 -7
- package/dist/src/serialization/beast2/v5/runs.js.map +1 -1
- package/dist/src/serialization/beast2/v5/runs.spec.js +223 -6
- package/dist/src/serialization/beast2/v5/runs.spec.js.map +1 -1
- package/dist/src/serialization/beast2/v5/stream.d.ts +30 -2
- package/dist/src/serialization/beast2/v5/stream.d.ts.map +1 -1
- package/dist/src/serialization/beast2/v5/stream.js +30 -5
- package/dist/src/serialization/beast2/v5/stream.js.map +1 -1
- package/dist/src/serialization/index.d.ts +1 -1
- package/dist/src/serialization/index.d.ts.map +1 -1
- package/dist/src/serialization/index.js +1 -1
- package/dist/src/serialization/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,830 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
import { isTypeValueEqual } from "../../../type_value_equal.js";
|
|
6
|
+
import { variant } from "../../../containers/variant.js";
|
|
7
|
+
import { ref } from "../../../containers/ref.js";
|
|
8
|
+
import { SortedMap } from "../../../containers/sortedmap.js";
|
|
9
|
+
import { compareFor } from "../../../comparison.js";
|
|
10
|
+
import { TAG_NEW, TAG_REF, buildV5Decoder, readContainerTag } from "./codec.js";
|
|
11
|
+
/** What a container met in a dropped field is defined as. */
|
|
12
|
+
const SKIPPED = Object.freeze({});
|
|
13
|
+
/** The shape {@link SKIPPED} was decoded to: no reference may name it. */
|
|
14
|
+
const SKIPPED_SHAPE = Object.freeze({});
|
|
15
|
+
/** The deepest a type may nest for a projection, as a decode may. */
|
|
16
|
+
const MAX_DEPTH = 256;
|
|
17
|
+
/** Prints a type value for an error, without the cost of the printer. */
|
|
18
|
+
function kindOf(type) {
|
|
19
|
+
return type.type;
|
|
20
|
+
}
|
|
21
|
+
/** Whether a type holds a function anywhere: a dropped field of one cannot be
|
|
22
|
+
* parsed past without decoding its IR, so a projection refuses it. */
|
|
23
|
+
function holdsFunction(type, depth = 0) {
|
|
24
|
+
if (depth > MAX_DEPTH)
|
|
25
|
+
return false;
|
|
26
|
+
switch (type.type) {
|
|
27
|
+
case "Function":
|
|
28
|
+
case "AsyncFunction":
|
|
29
|
+
return true;
|
|
30
|
+
case "Array":
|
|
31
|
+
case "Set":
|
|
32
|
+
case "Ref":
|
|
33
|
+
case "Vector":
|
|
34
|
+
case "Matrix":
|
|
35
|
+
return holdsFunction(type.value, depth + 1);
|
|
36
|
+
case "Dict": {
|
|
37
|
+
const dict = type.value;
|
|
38
|
+
return holdsFunction(dict.key, depth + 1) || holdsFunction(dict.value, depth + 1);
|
|
39
|
+
}
|
|
40
|
+
case "Struct":
|
|
41
|
+
case "Variant":
|
|
42
|
+
return type.value.some((part) => holdsFunction(part.type, depth + 1));
|
|
43
|
+
case "Recursive": {
|
|
44
|
+
const node = type.value;
|
|
45
|
+
return node.type === "wrapper" && holdsFunction(node.value.inner, depth + 1);
|
|
46
|
+
}
|
|
47
|
+
default:
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Builds the parser that steps past one value of `type`. A container it
|
|
53
|
+
* meets takes a definition, as a decode's does, recorded as skipped; a
|
|
54
|
+
* back-reference it meets is checked to be in range and followed no further.
|
|
55
|
+
*/
|
|
56
|
+
function buildSkipper(type, typeCtx) {
|
|
57
|
+
switch (type.type) {
|
|
58
|
+
case "Never":
|
|
59
|
+
case "Null":
|
|
60
|
+
return () => { };
|
|
61
|
+
case "Boolean":
|
|
62
|
+
return (reader) => { reader.readUint8(); };
|
|
63
|
+
case "Integer":
|
|
64
|
+
case "DateTime":
|
|
65
|
+
return (reader) => { reader.readZigzag(); };
|
|
66
|
+
case "Float":
|
|
67
|
+
return (reader) => { reader.skip(8); };
|
|
68
|
+
case "String":
|
|
69
|
+
case "Blob":
|
|
70
|
+
return (reader) => { reader.skip(reader.readVarint()); };
|
|
71
|
+
case "Vector": {
|
|
72
|
+
const width = type.value.type === "Boolean" ? 1 : 8;
|
|
73
|
+
return (reader) => { reader.skip(reader.readVarint() * width); };
|
|
74
|
+
}
|
|
75
|
+
case "Matrix": {
|
|
76
|
+
const width = type.value.type === "Boolean" ? 1 : 8;
|
|
77
|
+
return (reader) => {
|
|
78
|
+
const rows = reader.readVarint();
|
|
79
|
+
const cols = reader.readVarint();
|
|
80
|
+
reader.skip(rows * cols * width);
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
case "Struct": {
|
|
84
|
+
const fields = type.value.map((field) => buildSkipper(field.type, typeCtx));
|
|
85
|
+
return (reader, ctx) => {
|
|
86
|
+
for (const skip of fields)
|
|
87
|
+
skip(reader, ctx);
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
case "Variant": {
|
|
91
|
+
const cases = type.value.map((part) => buildSkipper(part.type, typeCtx));
|
|
92
|
+
return (reader, ctx) => {
|
|
93
|
+
const tag = reader.readVarint();
|
|
94
|
+
const skip = cases[tag];
|
|
95
|
+
if (skip === undefined)
|
|
96
|
+
throw new Error(`Invalid variant tag ${tag}`);
|
|
97
|
+
skip(reader, ctx);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
case "Array":
|
|
101
|
+
case "Set":
|
|
102
|
+
case "Dict":
|
|
103
|
+
case "Ref": {
|
|
104
|
+
let skipElement;
|
|
105
|
+
const skipContainer = (reader, ctx) => {
|
|
106
|
+
const tag = reader.readUint8();
|
|
107
|
+
if (tag === TAG_REF) {
|
|
108
|
+
const delta = reader.readVarint();
|
|
109
|
+
if (delta < 1 || delta > ctx.containers.length) {
|
|
110
|
+
throw new Error(`beast2 v5: container backref delta ${delta} out of range (${ctx.containers.length} definitions visible)`);
|
|
111
|
+
}
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (tag !== TAG_NEW)
|
|
115
|
+
throw new Error(`beast2 v5: invalid container tag 0x${tag.toString(16)}`);
|
|
116
|
+
ctx.containers.push(SKIPPED);
|
|
117
|
+
if (type.type === "Ref") {
|
|
118
|
+
skipElement(reader, ctx);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
for (;;) {
|
|
122
|
+
const n = reader.readVarint();
|
|
123
|
+
if (n === 0)
|
|
124
|
+
break;
|
|
125
|
+
for (let i = 0; i < n; i++)
|
|
126
|
+
skipElement(reader, ctx);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
if (type.type === "Dict") {
|
|
130
|
+
const dict = type.value;
|
|
131
|
+
const key = buildSkipper(dict.key, typeCtx);
|
|
132
|
+
const value = buildSkipper(dict.value, typeCtx);
|
|
133
|
+
skipElement = (reader, ctx) => { key(reader, ctx); value(reader, ctx); };
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
skipElement = buildSkipper(type.value, typeCtx);
|
|
137
|
+
}
|
|
138
|
+
return skipContainer;
|
|
139
|
+
}
|
|
140
|
+
case "Recursive": {
|
|
141
|
+
const node = type.value;
|
|
142
|
+
if (node.type === "wrapper") {
|
|
143
|
+
const wrapper = node.value;
|
|
144
|
+
let inner;
|
|
145
|
+
const skip = (reader, ctx) => inner(reader, ctx);
|
|
146
|
+
typeCtx.set(wrapper.id, skip);
|
|
147
|
+
inner = buildSkipper(wrapper.inner, typeCtx);
|
|
148
|
+
return skip;
|
|
149
|
+
}
|
|
150
|
+
const target = typeCtx.get(node.value);
|
|
151
|
+
if (target === undefined)
|
|
152
|
+
throw new Error("beast2 v5 projection: recursive type context not found");
|
|
153
|
+
return target;
|
|
154
|
+
}
|
|
155
|
+
default:
|
|
156
|
+
// A function: refused when the plan is built, so never parsed past.
|
|
157
|
+
throw new TypeError(`beast2 v5 projection: cannot parse past a value of type ${kindOf(type)}`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Builds the decoder of a wire value as its projection. A subtree whose
|
|
162
|
+
* projected type is its wire type decodes whole; anything else must narrow
|
|
163
|
+
* the wire type as {@link buildV5ProjectedDecoder} describes.
|
|
164
|
+
*/
|
|
165
|
+
function buildProjected(wire, proj, depth) {
|
|
166
|
+
if (depth > MAX_DEPTH)
|
|
167
|
+
throw new TypeError("beast2 v5 projection: type nesting too deep");
|
|
168
|
+
if (isTypeValueEqual(wire, proj)) {
|
|
169
|
+
// Decoded wire-shaped: its containers record no shape.
|
|
170
|
+
const whole = buildV5Decoder(wire);
|
|
171
|
+
return (reader, ctx) => {
|
|
172
|
+
const saved = ctx.curShape ?? null;
|
|
173
|
+
ctx.curShape = null;
|
|
174
|
+
const value = whole(reader, ctx);
|
|
175
|
+
ctx.curShape = saved;
|
|
176
|
+
return value;
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
if (wire.type !== proj.type) {
|
|
180
|
+
throw new TypeError(`beast2 v5 projection: the projected type is ${kindOf(proj)} where the wire type is ${kindOf(wire)}`);
|
|
181
|
+
}
|
|
182
|
+
switch (wire.type) {
|
|
183
|
+
case "Struct": {
|
|
184
|
+
const wireFields = wire.value;
|
|
185
|
+
const projFields = proj.value;
|
|
186
|
+
const kept = new Map();
|
|
187
|
+
for (const field of projFields) {
|
|
188
|
+
if (kept.has(field.name) || !wireFields.some((w) => w.name === field.name)) {
|
|
189
|
+
throw new TypeError(`beast2 v5 projection: the wire type has no field '${field.name}' to keep`);
|
|
190
|
+
}
|
|
191
|
+
kept.set(field.name, field.type);
|
|
192
|
+
}
|
|
193
|
+
const steps = wireFields.map(({ name, type }) => {
|
|
194
|
+
const projected = kept.get(name);
|
|
195
|
+
if (projected !== undefined)
|
|
196
|
+
return { name, decode: buildProjected(type, projected, depth + 1), skip: null };
|
|
197
|
+
if (holdsFunction(type)) {
|
|
198
|
+
throw new TypeError(`beast2 v5 projection: cannot project away function-typed field '${name}' — function values must decode whole`);
|
|
199
|
+
}
|
|
200
|
+
return { name, decode: null, skip: buildSkipper(type, new Map()) };
|
|
201
|
+
});
|
|
202
|
+
return (reader, ctx) => {
|
|
203
|
+
const result = {};
|
|
204
|
+
for (const step of steps) {
|
|
205
|
+
if (step.decode !== null)
|
|
206
|
+
result[step.name] = step.decode(reader, ctx);
|
|
207
|
+
else
|
|
208
|
+
step.skip(reader, ctx);
|
|
209
|
+
}
|
|
210
|
+
if (ctx.frozen)
|
|
211
|
+
Object.freeze(result);
|
|
212
|
+
return result;
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
case "Variant": {
|
|
216
|
+
const wireCases = wire.value;
|
|
217
|
+
const projCases = proj.value;
|
|
218
|
+
if (wireCases.length !== projCases.length || wireCases.some((c, i) => c.name !== projCases[i].name)) {
|
|
219
|
+
throw new TypeError("beast2 v5 projection: variant case lists must match exactly (the wire encodes case indices); case payloads may project");
|
|
220
|
+
}
|
|
221
|
+
const cases = wireCases.map((c, i) => ({ name: c.name, decode: buildProjected(c.type, projCases[i].type, depth + 1) }));
|
|
222
|
+
return (reader, ctx) => {
|
|
223
|
+
const tag = reader.readVarint();
|
|
224
|
+
const projected = cases[tag];
|
|
225
|
+
if (projected === undefined)
|
|
226
|
+
throw new Error(`Invalid variant tag ${tag}`);
|
|
227
|
+
const value = variant(projected.name, projected.decode(reader, ctx));
|
|
228
|
+
if (ctx.frozen)
|
|
229
|
+
Object.freeze(value);
|
|
230
|
+
return value;
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
case "Array": {
|
|
234
|
+
// This closure's shape object is what its containers are decoded to.
|
|
235
|
+
const shape = {};
|
|
236
|
+
const element = buildProjected(wire.value, proj.value, depth + 1);
|
|
237
|
+
return (reader, ctx) => {
|
|
238
|
+
ctx.curShape = shape;
|
|
239
|
+
const aliased = readContainerTag(reader, ctx);
|
|
240
|
+
if (aliased !== undefined)
|
|
241
|
+
return aliased;
|
|
242
|
+
const array = [];
|
|
243
|
+
ctx.containers.push(array);
|
|
244
|
+
ctx.projShapes.set(array, shape);
|
|
245
|
+
for (;;) {
|
|
246
|
+
const n = reader.readVarint();
|
|
247
|
+
if (n === 0)
|
|
248
|
+
break;
|
|
249
|
+
for (let i = 0; i < n; i++)
|
|
250
|
+
array.push(element(reader, ctx));
|
|
251
|
+
}
|
|
252
|
+
if (ctx.frozen)
|
|
253
|
+
Object.freeze(array);
|
|
254
|
+
return array;
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
case "Ref": {
|
|
258
|
+
const shape = {};
|
|
259
|
+
const inner = buildProjected(wire.value, proj.value, depth + 1);
|
|
260
|
+
return (reader, ctx) => {
|
|
261
|
+
ctx.curShape = shape;
|
|
262
|
+
const aliased = readContainerTag(reader, ctx);
|
|
263
|
+
if (aliased !== undefined)
|
|
264
|
+
return aliased;
|
|
265
|
+
const cell = ref(undefined);
|
|
266
|
+
ctx.containers.push(cell);
|
|
267
|
+
ctx.projShapes.set(cell, shape);
|
|
268
|
+
cell.value = inner(reader, ctx);
|
|
269
|
+
if (ctx.frozen)
|
|
270
|
+
Object.freeze(cell);
|
|
271
|
+
return cell;
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
case "Set":
|
|
275
|
+
throw new TypeError("beast2 v5 projection: Set elements cannot project — they are the container's keys (element order and identity would change)");
|
|
276
|
+
case "Dict": {
|
|
277
|
+
const wireDict = wire.value;
|
|
278
|
+
const projDict = proj.value;
|
|
279
|
+
if (!isTypeValueEqual(wireDict.key, projDict.key)) {
|
|
280
|
+
throw new TypeError("beast2 v5 projection: Dict keys cannot project — they order the container; the projected key type must equal the wire key type");
|
|
281
|
+
}
|
|
282
|
+
const shape = {};
|
|
283
|
+
const key = buildProjected(wireDict.key, wireDict.key, depth + 1);
|
|
284
|
+
const value = buildProjected(wireDict.value, projDict.value, depth + 1);
|
|
285
|
+
const cmp = compareFor(wireDict.key);
|
|
286
|
+
return (reader, ctx) => {
|
|
287
|
+
ctx.curShape = shape;
|
|
288
|
+
const aliased = readContainerTag(reader, ctx);
|
|
289
|
+
if (aliased !== undefined)
|
|
290
|
+
return aliased;
|
|
291
|
+
const map = new SortedMap(undefined, cmp);
|
|
292
|
+
ctx.containers.push(map);
|
|
293
|
+
ctx.projShapes.set(map, shape);
|
|
294
|
+
let has = false;
|
|
295
|
+
let prev;
|
|
296
|
+
for (;;) {
|
|
297
|
+
const n = reader.readVarint();
|
|
298
|
+
if (n === 0)
|
|
299
|
+
break;
|
|
300
|
+
for (let i = 0; i < n; i++) {
|
|
301
|
+
const k = key(reader, ctx);
|
|
302
|
+
if (has && cmp(prev, k) >= 0) {
|
|
303
|
+
throw new Error(`beast2 v5: Dict keys are not strictly ascending in East order — the wire must hold the canonical value (corrupt or pre-contract blob)`);
|
|
304
|
+
}
|
|
305
|
+
prev = k;
|
|
306
|
+
has = true;
|
|
307
|
+
map.set(k, value(reader, ctx));
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (ctx.frozen)
|
|
311
|
+
Object.freeze(map);
|
|
312
|
+
return map;
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
default:
|
|
316
|
+
throw new TypeError(`beast2 v5 projection: a ${kindOf(wire)} must be identical to the wire type to decode (only struct fields subset; variant payloads, array elements, ref contents and dict values may project within)`);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Builds a decoder that reads a value of the wire type `wire` as its
|
|
321
|
+
* projection `projected`: the struct fields `projected` keeps, by name, and
|
|
322
|
+
* within variant payloads, array elements, ref contents and dict values, each
|
|
323
|
+
* projected in turn. Any other part of `projected` must equal the wire's.
|
|
324
|
+
*
|
|
325
|
+
* The bytes are read as a whole decode reads them, so a value decodes to the
|
|
326
|
+
* kept fields of its whole decode. A dropped field is parsed past without
|
|
327
|
+
* being built; a container in it still takes a definition, and a
|
|
328
|
+
* back-reference that names a container decoded to another shape than its own
|
|
329
|
+
* throws {@link Beast2ProjectionAliasError}, after which the caller decodes
|
|
330
|
+
* whole.
|
|
331
|
+
*
|
|
332
|
+
* @param wire - the type the bytes hold
|
|
333
|
+
* @param projected - the type to decode them as
|
|
334
|
+
* @returns the decoder, which sets up the projection's state on the context
|
|
335
|
+
* it is given
|
|
336
|
+
* @throws {TypeError} When `projected` does not narrow `wire` so: a field it
|
|
337
|
+
* keeps that the wire lacks, a variant whose cases differ, a Set or a Dict's
|
|
338
|
+
* key narrowed, a function-typed field dropped, or a part of another kind
|
|
339
|
+
* that differs.
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* ```ts
|
|
343
|
+
* const Row = StructType({ id: IntegerType, lines: ArrayType(StringType) });
|
|
344
|
+
* const decode = buildV5ProjectedDecoder(asTypeValue(Row), asTypeValue(StructType({ id: IntegerType })));
|
|
345
|
+
* // At a row's bytes in a segment: `lines` is parsed past, never built.
|
|
346
|
+
* decode(reader, ctx); // { id: 1n }
|
|
347
|
+
* ```
|
|
348
|
+
* @internal
|
|
349
|
+
*/
|
|
350
|
+
export function buildV5ProjectedDecoder(wire, projected) {
|
|
351
|
+
const decode = buildProjected(wire, projected, 0);
|
|
352
|
+
return (reader, ctx) => {
|
|
353
|
+
ctx.projShapes ??= new WeakMap([[SKIPPED, SKIPPED_SHAPE]]);
|
|
354
|
+
return decode(reader, ctx);
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* A segment decoder that decodes each element of an Array root, or each value
|
|
359
|
+
* of a Dict root, as `projected` narrows it: what `Beast2Pages` decodes a
|
|
360
|
+
* projected segment with. A Dict's keys decode whole and are checked to
|
|
361
|
+
* ascend, as a whole segment's are.
|
|
362
|
+
*
|
|
363
|
+
* @param wire - the root type the bytes hold: an Array or a Dict
|
|
364
|
+
* @param projected - the root type to decode them as
|
|
365
|
+
* @returns the decoder of a segment's `n` elements
|
|
366
|
+
* @throws {TypeError} When `projected` does not narrow `wire` (see
|
|
367
|
+
* {@link buildV5ProjectedDecoder}), or the root is a Set.
|
|
368
|
+
* @internal
|
|
369
|
+
*/
|
|
370
|
+
export function buildProjectedSegmentDecoder(wire, projected) {
|
|
371
|
+
if (wire.type === "Array" && projected.type === "Array") {
|
|
372
|
+
const element = buildV5ProjectedDecoder(wire.value, projected.value);
|
|
373
|
+
return (reader, ctx, n) => {
|
|
374
|
+
const array = new Array(n);
|
|
375
|
+
for (let i = 0; i < n; i++)
|
|
376
|
+
array[i] = element(reader, ctx);
|
|
377
|
+
if (ctx.frozen)
|
|
378
|
+
Object.freeze(array);
|
|
379
|
+
return array;
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
if (wire.type === "Dict" && projected.type === "Dict") {
|
|
383
|
+
const wireDict = wire.value;
|
|
384
|
+
const projDict = projected.value;
|
|
385
|
+
if (!isTypeValueEqual(wireDict.key, projDict.key)) {
|
|
386
|
+
throw new TypeError("beast2 v5 projection: Dict keys cannot project — they order the container; the projected key type must equal the wire key type");
|
|
387
|
+
}
|
|
388
|
+
const key = buildV5ProjectedDecoder(wireDict.key, wireDict.key);
|
|
389
|
+
const value = buildV5ProjectedDecoder(wireDict.value, projDict.value);
|
|
390
|
+
const cmp = compareFor(wireDict.key);
|
|
391
|
+
return (reader, ctx, n, order) => {
|
|
392
|
+
const map = new SortedMap(undefined, cmp);
|
|
393
|
+
for (let i = 0; i < n; i++) {
|
|
394
|
+
const k = key(reader, ctx);
|
|
395
|
+
if (order) {
|
|
396
|
+
if (order.has && cmp(order.prev, k) >= 0) {
|
|
397
|
+
throw new Error(`beast2 v5: Dict keys are not strictly ascending in East order — the wire must hold the canonical value (corrupt or pre-contract blob)`);
|
|
398
|
+
}
|
|
399
|
+
order.prev = k;
|
|
400
|
+
order.has = true;
|
|
401
|
+
}
|
|
402
|
+
map.set(k, value(reader, ctx));
|
|
403
|
+
}
|
|
404
|
+
if (ctx.frozen)
|
|
405
|
+
Object.freeze(map);
|
|
406
|
+
return map;
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
throw new TypeError(`beast2 v5 projection: a projected segment holds an Array's elements or a Dict's values, not a ${kindOf(wire)}'s`);
|
|
410
|
+
}
|
|
411
|
+
/** The longest chain of field accesses recorded, as east-c's. */
|
|
412
|
+
const MAX_PATH = 64;
|
|
413
|
+
/** The most arguments an inline call binds, as east-c's. */
|
|
414
|
+
const MAX_ARGS = 16;
|
|
415
|
+
function newMask() {
|
|
416
|
+
return { whole: false, fields: new Map(), elem: null };
|
|
417
|
+
}
|
|
418
|
+
function maskChild(mask, name) {
|
|
419
|
+
let child = mask.fields.get(name);
|
|
420
|
+
if (child === undefined) {
|
|
421
|
+
child = newMask();
|
|
422
|
+
mask.fields.set(name, child);
|
|
423
|
+
}
|
|
424
|
+
return child;
|
|
425
|
+
}
|
|
426
|
+
/** Records a read of the whole of `path` below `mask`. */
|
|
427
|
+
function insertPath(mask, path) {
|
|
428
|
+
let m = mask;
|
|
429
|
+
for (const name of path) {
|
|
430
|
+
if (m.whole)
|
|
431
|
+
return;
|
|
432
|
+
m = maskChild(m, name);
|
|
433
|
+
}
|
|
434
|
+
m.whole = true;
|
|
435
|
+
}
|
|
436
|
+
/** The node at `path`, made on the way down without marking anything whole;
|
|
437
|
+
* `null` when it, or a node above it, is already whole. */
|
|
438
|
+
function maskNodeAt(mask, path) {
|
|
439
|
+
let m = mask;
|
|
440
|
+
for (const name of path) {
|
|
441
|
+
if (m.whole)
|
|
442
|
+
return null;
|
|
443
|
+
m = maskChild(m, name);
|
|
444
|
+
}
|
|
445
|
+
return m.whole ? null : m;
|
|
446
|
+
}
|
|
447
|
+
function maskElem(mask) {
|
|
448
|
+
mask.elem ??= newMask();
|
|
449
|
+
return mask.elem;
|
|
450
|
+
}
|
|
451
|
+
function findTarget(targets, name) {
|
|
452
|
+
for (let t = targets; t !== null; t = t.next)
|
|
453
|
+
if (t.name === name)
|
|
454
|
+
return t;
|
|
455
|
+
return null;
|
|
456
|
+
}
|
|
457
|
+
/** The name an IR Variable node binds or reads. */
|
|
458
|
+
function nameOf(node) {
|
|
459
|
+
return node.value.name;
|
|
460
|
+
}
|
|
461
|
+
/** `node` without the casts around it: east-c drops an `As` as it reads the
|
|
462
|
+
* IR, so the walk sees through one. */
|
|
463
|
+
function uncast(node) {
|
|
464
|
+
let n = node;
|
|
465
|
+
while (n.type === "As")
|
|
466
|
+
n = n.value.value;
|
|
467
|
+
return n;
|
|
468
|
+
}
|
|
469
|
+
/** A chain of field accesses: rooted at a target, with its path, outermost
|
|
470
|
+
* access first; rooted elsewhere, with the expression at its root; or too
|
|
471
|
+
* deep to record. */
|
|
472
|
+
function chainRoot(node, targets) {
|
|
473
|
+
const reversed = [];
|
|
474
|
+
let cur = uncast(node);
|
|
475
|
+
while (cur.type === "GetField") {
|
|
476
|
+
if (reversed.length === MAX_PATH)
|
|
477
|
+
return { kind: "decline" };
|
|
478
|
+
reversed.push(cur.value.field);
|
|
479
|
+
cur = uncast(cur.value.struct);
|
|
480
|
+
}
|
|
481
|
+
if (cur.type !== "Variable")
|
|
482
|
+
return { kind: "other", inner: cur };
|
|
483
|
+
const target = findTarget(targets, cur.value.name);
|
|
484
|
+
if (target === null)
|
|
485
|
+
return { kind: "other", inner: cur };
|
|
486
|
+
return { kind: "target", target, path: reversed.reverse() };
|
|
487
|
+
}
|
|
488
|
+
/** An iteration (or a size) of `expr`: a target-rooted chain's element mask,
|
|
489
|
+
* made on the way; or nothing to narrow — `walkExpr` saying whether the
|
|
490
|
+
* caller must still walk `expr`, which it need not when the chain is already
|
|
491
|
+
* whole. */
|
|
492
|
+
function chainElem(expr, targets) {
|
|
493
|
+
const e = uncast(expr);
|
|
494
|
+
if (e.type !== "GetField" && e.type !== "Variable")
|
|
495
|
+
return { kind: "none", walkExpr: true };
|
|
496
|
+
const root = chainRoot(e, targets);
|
|
497
|
+
if (root.kind === "decline")
|
|
498
|
+
return root;
|
|
499
|
+
if (root.kind === "other")
|
|
500
|
+
return { kind: "none", walkExpr: true };
|
|
501
|
+
const node = maskNodeAt(root.target.mask, root.path);
|
|
502
|
+
if (node === null)
|
|
503
|
+
return { kind: "none", walkExpr: false };
|
|
504
|
+
return { kind: "elem", elem: maskElem(node) };
|
|
505
|
+
}
|
|
506
|
+
function walkAll(nodes, targets) {
|
|
507
|
+
for (const node of nodes)
|
|
508
|
+
if (!walk(node, targets))
|
|
509
|
+
return false;
|
|
510
|
+
return true;
|
|
511
|
+
}
|
|
512
|
+
/** A call of an inline Function node: an argument that is a target-rooted
|
|
513
|
+
* chain binds the parameter it lands in to that chain's mask, so the callee's
|
|
514
|
+
* reads of the parameter are the caller's reads of the chain; any other
|
|
515
|
+
* argument is walked where it is, and its parameter shadowing a live target
|
|
516
|
+
* declines, as any binder does. */
|
|
517
|
+
function walkInlineCall(args, parameters, body, targets) {
|
|
518
|
+
// A chain already whole: what the parameter reads narrows nothing there.
|
|
519
|
+
const whole = { whole: true, fields: new Map(), elem: null };
|
|
520
|
+
let inner = targets;
|
|
521
|
+
for (let i = 0; i < args.length; i++) {
|
|
522
|
+
const arg = uncast(args[i]);
|
|
523
|
+
const parameter = nameOf(parameters[i]);
|
|
524
|
+
const root = arg.type === "Variable" || arg.type === "GetField" ? chainRoot(arg, targets) : { kind: "other", inner: arg };
|
|
525
|
+
if (root.kind === "decline")
|
|
526
|
+
return false;
|
|
527
|
+
if (root.kind === "other") {
|
|
528
|
+
if (findTarget(targets, parameter) !== null)
|
|
529
|
+
return false;
|
|
530
|
+
if (!walk(args[i], targets))
|
|
531
|
+
return false;
|
|
532
|
+
continue;
|
|
533
|
+
}
|
|
534
|
+
const node = maskNodeAt(root.target.mask, root.path);
|
|
535
|
+
inner = { name: parameter, mask: node ?? whole, root: false, next: inner };
|
|
536
|
+
}
|
|
537
|
+
return walk(body, inner);
|
|
538
|
+
}
|
|
539
|
+
/** Walks `node`, recording the masks of `targets`: false when the root
|
|
540
|
+
* variable escapes whole, a binder shadows a target, or anything is not
|
|
541
|
+
* positively recognized — the loop then decodes whole. east-c's
|
|
542
|
+
* `paged_mask_walk`, case for case. */
|
|
543
|
+
function walk(node, targets) {
|
|
544
|
+
switch (node.type) {
|
|
545
|
+
case "Value":
|
|
546
|
+
case "Break":
|
|
547
|
+
case "Continue":
|
|
548
|
+
return true;
|
|
549
|
+
case "Variable": {
|
|
550
|
+
const target = findTarget(targets, node.value.name);
|
|
551
|
+
if (target === null)
|
|
552
|
+
return true;
|
|
553
|
+
if (target.root)
|
|
554
|
+
return false; // the row escapes whole
|
|
555
|
+
target.mask.whole = true; // an inner element escapes: that subtree, whole
|
|
556
|
+
return true;
|
|
557
|
+
}
|
|
558
|
+
case "GetField": {
|
|
559
|
+
const root = chainRoot(node, targets);
|
|
560
|
+
if (root.kind === "decline")
|
|
561
|
+
return false;
|
|
562
|
+
if (root.kind === "target") {
|
|
563
|
+
insertPath(root.target.mask, root.path);
|
|
564
|
+
return true;
|
|
565
|
+
}
|
|
566
|
+
return walk(root.inner, targets);
|
|
567
|
+
}
|
|
568
|
+
case "As":
|
|
569
|
+
return walk(node.value.value, targets);
|
|
570
|
+
case "Let":
|
|
571
|
+
case "Assign":
|
|
572
|
+
if (findTarget(targets, nameOf(node.value.variable)) !== null)
|
|
573
|
+
return false;
|
|
574
|
+
return walk(node.value.value, targets);
|
|
575
|
+
case "Block":
|
|
576
|
+
return walkAll(node.value.statements, targets);
|
|
577
|
+
case "IfElse":
|
|
578
|
+
for (const branch of node.value.ifs) {
|
|
579
|
+
if (!walk(branch.predicate, targets) || !walk(branch.body, targets))
|
|
580
|
+
return false;
|
|
581
|
+
}
|
|
582
|
+
return walk(node.value.else_body, targets);
|
|
583
|
+
case "Match":
|
|
584
|
+
if (!walk(node.value.variant, targets))
|
|
585
|
+
return false;
|
|
586
|
+
for (const c of node.value.cases) {
|
|
587
|
+
if (findTarget(targets, nameOf(c.variable)) !== null)
|
|
588
|
+
return false;
|
|
589
|
+
if (!walk(c.body, targets))
|
|
590
|
+
return false;
|
|
591
|
+
}
|
|
592
|
+
return true;
|
|
593
|
+
case "While":
|
|
594
|
+
return walk(node.value.predicate, targets) && walk(node.value.body, targets);
|
|
595
|
+
case "ForArray":
|
|
596
|
+
case "ForDict": {
|
|
597
|
+
const collection = (node.type === "ForArray" ? node.value.array : node.value.dict);
|
|
598
|
+
if (findTarget(targets, nameOf(node.value.value)) !== null)
|
|
599
|
+
return false;
|
|
600
|
+
if (findTarget(targets, nameOf(node.value.key)) !== null)
|
|
601
|
+
return false;
|
|
602
|
+
// Iterating a target-rooted array narrows its items, or a dict its
|
|
603
|
+
// values, to what the body reads of the loop's value variable.
|
|
604
|
+
const elem = chainElem(collection, targets);
|
|
605
|
+
if (elem.kind === "decline")
|
|
606
|
+
return false;
|
|
607
|
+
const walkExpr = elem.kind === "none" ? elem.walkExpr : false;
|
|
608
|
+
if (walkExpr && !walk(collection, targets))
|
|
609
|
+
return false;
|
|
610
|
+
if (elem.kind === "elem") {
|
|
611
|
+
return walk(node.value.body, { name: nameOf(node.value.value), mask: elem.elem, root: false, next: targets });
|
|
612
|
+
}
|
|
613
|
+
return walk(node.value.body, targets);
|
|
614
|
+
}
|
|
615
|
+
case "ForSet":
|
|
616
|
+
// Set elements never narrow: the set is read whole.
|
|
617
|
+
if (findTarget(targets, nameOf(node.value.key)) !== null)
|
|
618
|
+
return false;
|
|
619
|
+
return walk(node.value.set, targets) && walk(node.value.body, targets);
|
|
620
|
+
case "Function":
|
|
621
|
+
case "AsyncFunction":
|
|
622
|
+
// A parameter shadowing a target hides it; captures are declarations,
|
|
623
|
+
// and the body's uses are what count.
|
|
624
|
+
for (const parameter of node.value.parameters) {
|
|
625
|
+
if (findTarget(targets, nameOf(parameter)) !== null)
|
|
626
|
+
return false;
|
|
627
|
+
}
|
|
628
|
+
return walk(node.value.body, targets);
|
|
629
|
+
case "Call":
|
|
630
|
+
case "CallAsync": {
|
|
631
|
+
const callee = uncast(node.value.function);
|
|
632
|
+
const args = node.value.arguments;
|
|
633
|
+
if ((callee.type === "Function" || callee.type === "AsyncFunction") &&
|
|
634
|
+
args.length === callee.value.parameters.length && args.length <= MAX_ARGS) {
|
|
635
|
+
return walkInlineCall(args, callee.value.parameters, callee.value.body, targets);
|
|
636
|
+
}
|
|
637
|
+
return walk(node.value.function, targets) && walkAll(args, targets);
|
|
638
|
+
}
|
|
639
|
+
case "Platform":
|
|
640
|
+
return walkAll(node.value.arguments, targets);
|
|
641
|
+
case "Builtin": {
|
|
642
|
+
// The size of a target-rooted array or dict reads no element field:
|
|
643
|
+
// its elements narrow to nothing unless something else reads them.
|
|
644
|
+
const args = node.value.arguments;
|
|
645
|
+
if (args.length === 1 && (node.value.builtin === "ArraySize" || node.value.builtin === "DictSize")) {
|
|
646
|
+
const elem = chainElem(args[0], targets);
|
|
647
|
+
if (elem.kind === "decline")
|
|
648
|
+
return false;
|
|
649
|
+
if (elem.kind === "elem" || !elem.walkExpr)
|
|
650
|
+
return true;
|
|
651
|
+
}
|
|
652
|
+
return walkAll(args, targets);
|
|
653
|
+
}
|
|
654
|
+
case "Return":
|
|
655
|
+
return walk(node.value.value, targets);
|
|
656
|
+
case "Error":
|
|
657
|
+
return walk(node.value.message, targets);
|
|
658
|
+
case "TryCatch":
|
|
659
|
+
if (findTarget(targets, nameOf(node.value.message)) !== null)
|
|
660
|
+
return false;
|
|
661
|
+
if (findTarget(targets, nameOf(node.value.stack)) !== null)
|
|
662
|
+
return false;
|
|
663
|
+
return walk(node.value.try_body, targets) && walk(node.value.catch_body, targets) &&
|
|
664
|
+
walk(node.value.finally_body, targets);
|
|
665
|
+
case "NewArray":
|
|
666
|
+
case "NewSet":
|
|
667
|
+
case "NewVector":
|
|
668
|
+
case "NewMatrix":
|
|
669
|
+
return walkAll(node.value.values, targets);
|
|
670
|
+
case "NewDict":
|
|
671
|
+
for (const entry of node.value.values) {
|
|
672
|
+
if (!walk(entry.key, targets) || !walk(entry.value, targets))
|
|
673
|
+
return false;
|
|
674
|
+
}
|
|
675
|
+
return true;
|
|
676
|
+
case "NewRef":
|
|
677
|
+
case "Variant":
|
|
678
|
+
case "WrapRecursive":
|
|
679
|
+
case "UnwrapRecursive":
|
|
680
|
+
return walk(node.value.value, targets);
|
|
681
|
+
case "Struct":
|
|
682
|
+
for (const field of node.value.fields) {
|
|
683
|
+
if (!walk(field.value, targets))
|
|
684
|
+
return false;
|
|
685
|
+
}
|
|
686
|
+
return true;
|
|
687
|
+
default:
|
|
688
|
+
return false; // a kind the walk has not been taught: decline
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
/** The type `mask` keeps of `wire`, in the wire's field order: struct fields
|
|
692
|
+
* by name, and through an iterated Array's element or Dict's value by its
|
|
693
|
+
* element mask. `wire` itself when nothing narrows. */
|
|
694
|
+
function maskToType(wire, mask) {
|
|
695
|
+
if (mask.whole)
|
|
696
|
+
return wire;
|
|
697
|
+
switch (wire.type) {
|
|
698
|
+
case "Struct": {
|
|
699
|
+
const fields = wire.value
|
|
700
|
+
.filter((field) => mask.fields.has(field.name))
|
|
701
|
+
.map((field) => ({ name: field.name, type: maskToType(field.type, mask.fields.get(field.name)) }));
|
|
702
|
+
return variant("Struct", fields);
|
|
703
|
+
}
|
|
704
|
+
case "Array": {
|
|
705
|
+
if (mask.elem === null)
|
|
706
|
+
return wire;
|
|
707
|
+
const element = maskToType(wire.value, mask.elem);
|
|
708
|
+
return isTypeValueEqual(element, wire.value) ? wire : variant("Array", element);
|
|
709
|
+
}
|
|
710
|
+
case "Dict": {
|
|
711
|
+
if (mask.elem === null)
|
|
712
|
+
return wire;
|
|
713
|
+
const dict = wire.value;
|
|
714
|
+
const value = maskToType(dict.value, mask.elem);
|
|
715
|
+
return isTypeValueEqual(value, dict.value) ? wire : variant("Dict", { key: dict.key, value });
|
|
716
|
+
}
|
|
717
|
+
default:
|
|
718
|
+
return wire;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
/** The projection a loop's body admits over `root`, with its segment decoder:
|
|
722
|
+
* what {@link loopProjectionType} says, built. */
|
|
723
|
+
function loopProjection(body, target, root) {
|
|
724
|
+
let row;
|
|
725
|
+
if (root.type === "Array")
|
|
726
|
+
row = root.value;
|
|
727
|
+
else if (root.type === "Dict")
|
|
728
|
+
row = root.value.value;
|
|
729
|
+
else
|
|
730
|
+
return null; // Set elements are keys: they never narrow
|
|
731
|
+
if (row.type !== "Struct")
|
|
732
|
+
return null;
|
|
733
|
+
const mask = newMask();
|
|
734
|
+
if (!walk(body, { name: target, mask, root: true, next: null }) || mask.whole)
|
|
735
|
+
return null;
|
|
736
|
+
const narrow = maskToType(row, mask);
|
|
737
|
+
if (isTypeValueEqual(narrow, row))
|
|
738
|
+
return null; // every field read
|
|
739
|
+
const type = root.type === "Array"
|
|
740
|
+
? variant("Array", narrow)
|
|
741
|
+
: variant("Dict", { key: root.value.key, value: narrow });
|
|
742
|
+
try {
|
|
743
|
+
return { type, decoder: buildProjectedSegmentDecoder(root, type) };
|
|
744
|
+
}
|
|
745
|
+
catch (err) {
|
|
746
|
+
// A plan the builder refuses — a dropped function-typed field: decode
|
|
747
|
+
// whole.
|
|
748
|
+
if (err instanceof TypeError)
|
|
749
|
+
return null;
|
|
750
|
+
throw err;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* The projection a `$.for` over a lazy collection decodes its segments to:
|
|
755
|
+
* the struct fields its body reads of the loop's value variable — an Array's
|
|
756
|
+
* element, a Dict's value — through chains of field accesses, following inner
|
|
757
|
+
* loops into nested Arrays and Dicts and inline calls into their bodies. Any
|
|
758
|
+
* other use of the variable, a binder that shadows it, or an IR node the walk
|
|
759
|
+
* has not been taught declines, and the loop decodes whole. Dict keys and Set
|
|
760
|
+
* elements never narrow.
|
|
761
|
+
*
|
|
762
|
+
* This is east-c's `east_beast2_projection_for_loop`, rule for rule, so every
|
|
763
|
+
* runtime decodes a loop's segments to the same fields.
|
|
764
|
+
*
|
|
765
|
+
* @param body - the loop's body
|
|
766
|
+
* @param target - the name of the loop's value variable
|
|
767
|
+
* @param root - the type of the collection the loop walks
|
|
768
|
+
* @returns the root type narrowed to what the body reads, or `null` when the
|
|
769
|
+
* loop decodes whole: it declined, it reads every field, the row is not a
|
|
770
|
+
* struct, or the narrowing would drop a function-typed field
|
|
771
|
+
* @internal
|
|
772
|
+
*/
|
|
773
|
+
export function loopProjectionType(body, target, root) {
|
|
774
|
+
return loopProjection(body, target, root)?.type ?? null;
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* The projector of a compiled `$.for`: for each type the collections it walks
|
|
778
|
+
* hold, the projection {@link loopProjectionType} infers from its body, built
|
|
779
|
+
* the first time the loop meets that type. As east-c's, the projection follows
|
|
780
|
+
* the type the bytes hold, not the type the program declared.
|
|
781
|
+
*
|
|
782
|
+
* @param body - the loop's body
|
|
783
|
+
* @param target - the name of the loop's value variable
|
|
784
|
+
* @returns the loop's projector
|
|
785
|
+
* @internal
|
|
786
|
+
*/
|
|
787
|
+
export function loopProjectorFor(body, target) {
|
|
788
|
+
const built = new WeakMap();
|
|
789
|
+
return (wire) => {
|
|
790
|
+
let decoder = built.get(wire);
|
|
791
|
+
if (decoder === undefined) {
|
|
792
|
+
decoder = loopProjection(body, target, wire)?.decoder ?? null;
|
|
793
|
+
built.set(wire, decoder);
|
|
794
|
+
}
|
|
795
|
+
return decoder;
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
let segmentsProjected = 0;
|
|
799
|
+
let segmentsWhole = 0;
|
|
800
|
+
/**
|
|
801
|
+
* Counts one segment a compiled loop over a lazy collection decoded:
|
|
802
|
+
* projected, or whole — a loop that infers no projection, a Set's, or a
|
|
803
|
+
* segment whose projected decode fell back.
|
|
804
|
+
*
|
|
805
|
+
* @param projected - whether the segment was decoded projected
|
|
806
|
+
* @internal
|
|
807
|
+
*/
|
|
808
|
+
export function countPagedLoopSegment(projected) {
|
|
809
|
+
if (projected)
|
|
810
|
+
segmentsProjected++;
|
|
811
|
+
else
|
|
812
|
+
segmentsWhole++;
|
|
813
|
+
}
|
|
814
|
+
/**
|
|
815
|
+
* What the compiled loops over lazy collections have decoded in this process:
|
|
816
|
+
* how many segments to the fields their bodies read, and how many whole. A
|
|
817
|
+
* runner's `-v` reports it beside its account of each lazy input, as east-c's
|
|
818
|
+
* runners report theirs, so a unit's log says whether projection applied.
|
|
819
|
+
*
|
|
820
|
+
* @returns the segments decoded projected and whole, since the process began
|
|
821
|
+
*
|
|
822
|
+
* @example
|
|
823
|
+
* ```ts
|
|
824
|
+
* const { segmentsProjected, segmentsWhole } = beast2PagedLoopStats();
|
|
825
|
+
* ```
|
|
826
|
+
*/
|
|
827
|
+
export function beast2PagedLoopStats() {
|
|
828
|
+
return { segmentsProjected, segmentsWhole };
|
|
829
|
+
}
|
|
830
|
+
//# sourceMappingURL=project.js.map
|