@gmitch215/folio 0.0.0-stage → 1.0.0

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.
@@ -0,0 +1,398 @@
1
+ import { Coordinator } from "./coordinator.js";
2
+ import { decodeFrame, decodeResults, encodeFrame, encodeResults, validateIdentity } from "./frames.js";
3
+ import { SpeculationLimit, transaction } from "./transaction.js";
4
+ function integer(value, minimum, maximum, label) {
5
+ if (!Number.isSafeInteger(value) || value < minimum || value > maximum)
6
+ throw new RangeError(`invalid ${label}`);
7
+ return value;
8
+ }
9
+ /**
10
+ * The lane runtime: runs tracked regions from a binary frame against a private copy of the
11
+ * frozen snapshot and returns byte read and write sets. Holds no state between frames.
12
+ */
13
+ export class FolioLane {
14
+ #module;
15
+ #initial;
16
+ #maximum;
17
+ #maximumFrameBytes;
18
+ #maximumMemoryBytes;
19
+ #memory;
20
+ #instance;
21
+ #active;
22
+ constructor(module, options) {
23
+ this.#module = module;
24
+ this.#initial = integer(options.initial, 0, 65536, 'initial memory');
25
+ this.#maximum = integer(options.maximum, this.#initial, 65536, 'maximum memory');
26
+ this.#maximumMemoryBytes = options.maximumMemoryBytes ?? 32 * 1048576;
27
+ this.#maximumFrameBytes = options.maximumFrameBytes ?? this.#maximumMemoryBytes + 1048576;
28
+ integer(this.#maximumMemoryBytes, 65536, 0x100000000, 'lane memory limit');
29
+ integer(this.#maximumFrameBytes, 65536, 0x100100000, 'lane frame limit');
30
+ }
31
+ /** Validates the frame, runs its calls in order and returns the encoded results. */
32
+ execute(frame) {
33
+ const { header, payload } = decodeFrame(frame, this.#maximumFrameBytes);
34
+ validateIdentity(header);
35
+ integer(header.fuel, 1, 1000000000, 'fuel');
36
+ integer(header.maxBytes, 8, 1048576, 'tracking budget');
37
+ if (!Array.isArray(header.calls) || !header.calls.length || header.calls.length > 16)
38
+ throw new RangeError('invalid lane call count');
39
+ for (const call of header.calls) {
40
+ if (typeof call?.export !== 'string' ||
41
+ !Array.isArray(call.args) ||
42
+ call.args.length > 256 ||
43
+ call.args.some((value) => typeof value !== 'number' && typeof value !== 'bigint'))
44
+ throw new TypeError('invalid lane call');
45
+ }
46
+ const pages = payload.length / 65536;
47
+ if (!Number.isInteger(pages) ||
48
+ pages < this.#initial ||
49
+ pages > this.#maximum ||
50
+ payload.length > this.#maximumMemoryBytes)
51
+ throw new RangeError('invalid lane snapshot');
52
+ if (!this.#memory || !this.#instance || this.#memory.buffer.byteLength !== payload.length) {
53
+ const binding = WebAssembly.Module.imports(this.#module).filter((item) => item.kind === 'memory');
54
+ if (binding.length !== 1)
55
+ throw new TypeError('one lane memory required');
56
+ this.#memory = new WebAssembly.Memory({
57
+ initial: pages,
58
+ maximum: this.#maximum,
59
+ shared: true
60
+ });
61
+ this.#instance = new WebAssembly.Instance(this.#module, {
62
+ [binding[0].module]: { [binding[0].name]: this.#memory },
63
+ folio: {
64
+ load: (...args) => this.#active.load(...args),
65
+ store: (...args) => this.#active.store(...args),
66
+ load64: (...args) => this.#active.load64(...args),
67
+ store64: (...args) => this.#active.store64(...args),
68
+ copy: (...args) => this.#active.copy(...args),
69
+ fill: (...args) => this.#active.fill(...args),
70
+ exhausted: () => {
71
+ throw new SpeculationLimit('speculative instruction budget');
72
+ }
73
+ }
74
+ });
75
+ }
76
+ new Uint8Array(this.#memory.buffer).set(payload);
77
+ let remaining = header.maxBytes;
78
+ const results = [];
79
+ for (const call of header.calls) {
80
+ if (remaining <= 0) {
81
+ results.push({ reads: [], writes: [], exhausted: true });
82
+ continue;
83
+ }
84
+ this.#active = transaction(this.#memory, remaining);
85
+ let error, value;
86
+ try {
87
+ this.#instance.exports.__folio_set_fuel(header.fuel);
88
+ const entry = this.#instance.exports[call.export];
89
+ if (typeof entry !== 'function')
90
+ throw new TypeError('unknown lane export');
91
+ value = entry(...call.args);
92
+ }
93
+ catch (caught) {
94
+ error = caught;
95
+ }
96
+ if (error instanceof RangeError) {
97
+ results.push({ reads: [], writes: [], exhausted: true });
98
+ continue;
99
+ }
100
+ const result = this.#active.result(value, error);
101
+ remaining -= result.reads.length + result.writes.length;
102
+ results.push(result);
103
+ }
104
+ this.#active = undefined;
105
+ return encodeResults(header, results, this.#maximumFrameBytes);
106
+ }
107
+ /** Drops the instance and its memory; a later frame builds them again. */
108
+ close() {
109
+ this.#active = this.#instance = this.#memory = undefined;
110
+ }
111
+ }
112
+ /**
113
+ * The owner side of the managed backend. The original Wasm stack keeps control flow and host
114
+ * effects, and JSPI joins regions that lanes execute over copied snapshots.
115
+ */
116
+ export class ManagedFolio {
117
+ /** The original native exports. */
118
+ exports;
119
+ /** Optimization refusals and fallbacks seen so far. */
120
+ diagnostics = [];
121
+ #artifact;
122
+ #lanes;
123
+ #instance;
124
+ #serial = new WebAssembly.Global({ value: 'i32', mutable: true }, 1);
125
+ #pendingGlobal = new WebAssembly.Global({ value: 'i32', mutable: true }, 0);
126
+ #controlled = new Map();
127
+ #promising = new Map();
128
+ #maximumSnapshotBytes;
129
+ #maximumFrameBytes;
130
+ #fuel;
131
+ #maxBytes;
132
+ #session = crypto.randomUUID();
133
+ #memory;
134
+ #scheduler;
135
+ #epoch = 0;
136
+ #sequence = 0;
137
+ #busy = false;
138
+ #closed = false;
139
+ #pending;
140
+ #closing;
141
+ constructor(artifact, options) {
142
+ this.#artifact = artifact;
143
+ this.#lanes = options.lanes;
144
+ integer(this.#lanes.length, 1, 64, 'lane count');
145
+ this.#maximumSnapshotBytes = integer(options.maximumSnapshotBytes ?? 32 * 1048576, 65536, 0x100000000, 'snapshot limit');
146
+ this.#maximumFrameBytes = integer(options.maximumFrameBytes ?? this.#maximumSnapshotBytes + 1048576, 65536, 0x100100000, 'frame limit');
147
+ this.#fuel = integer(options.fuel ?? 100000000, 1, 1000000000, 'fuel');
148
+ this.#maxBytes = integer(options.maxTransactionBytes ?? 262144, 8, 1048576, 'tracking budget');
149
+ const runtime = WebAssembly;
150
+ const control = artifact.control;
151
+ let module = artifact.original, enabled = false;
152
+ if (control &&
153
+ artifact.coordinator &&
154
+ runtime.Suspending &&
155
+ runtime.promising &&
156
+ this.#lanes.length > 1) {
157
+ const original = WebAssembly.Module.imports(artifact.original);
158
+ const retained = WebAssembly.Module.imports(artifact.coordinator).filter((item) => item.module !== control.namespace);
159
+ if (JSON.stringify(original) === JSON.stringify(retained)) {
160
+ module = artifact.coordinator;
161
+ enabled = true;
162
+ }
163
+ else
164
+ this.diagnostics.push('rewritten import sequence differs; using native execution');
165
+ }
166
+ else
167
+ this.diagnostics.push('no active coordinator; using native execution');
168
+ const supplied = options.imports ?? Object.create(null);
169
+ const memories = WebAssembly.Module.imports(artifact.original).filter((item) => item.kind === 'memory');
170
+ if (memories.length > 1 && options.memory)
171
+ throw new TypeError('bind multiple memories by name in imports');
172
+ const automatic = new Map();
173
+ const imports = new Proxy(Object.create(null), {
174
+ get: (_, namespace) => {
175
+ if (enabled && namespace === control.namespace) {
176
+ const bindings = {
177
+ [control.serialGlobal]: this.#serial,
178
+ [control.pendingGlobal]: this.#pendingGlobal,
179
+ barrier: new runtime.Suspending(() => this.#scheduler?.flush()),
180
+ poll: new runtime.Suspending(() => this.#scheduler?.poll())
181
+ };
182
+ for (const region of control.regions)
183
+ bindings[region.importName] = new runtime.Suspending((...args) => {
184
+ if (this.#scheduler && this.#serial.value === 0)
185
+ return this.#scheduler.enqueue({
186
+ export: region.exportName,
187
+ args
188
+ });
189
+ this.#instance.exports[region.exportName](...args);
190
+ });
191
+ return bindings;
192
+ }
193
+ const bound = Reflect.get(supplied, namespace, supplied);
194
+ if (!memories.some((item) => item.module === namespace))
195
+ return bound;
196
+ if (bound !== undefined &&
197
+ (bound === null || !['object', 'function'].includes(typeof bound)))
198
+ return bound;
199
+ return new Proxy(Object.create(null), {
200
+ get: (_, name) => {
201
+ if (!memories.some((item) => item.module === namespace && item.name === name))
202
+ return bound === undefined
203
+ ? undefined
204
+ : Reflect.get(bound, name, bound);
205
+ let memory = (memories.length === 1 ? options.memory : undefined) ??
206
+ (bound === undefined ? undefined : Reflect.get(bound, name, bound));
207
+ if (memory === undefined) {
208
+ const key = JSON.stringify([namespace, name]);
209
+ memory = automatic.get(key);
210
+ if (!memory) {
211
+ const limits = artifact.memories?.find((item) => item.module === namespace && item.name === name);
212
+ if (!limits || limits.memory64)
213
+ throw new TypeError(`provide imported memory ${namespace}.${name}`);
214
+ memory = new WebAssembly.Memory({
215
+ initial: limits.initial,
216
+ ...(limits.maximum === undefined
217
+ ? {}
218
+ : { maximum: limits.maximum }),
219
+ shared: limits.shared
220
+ });
221
+ automatic.set(key, memory);
222
+ }
223
+ }
224
+ if (memories.length === 1)
225
+ this.#memory = memory;
226
+ return memory;
227
+ }
228
+ });
229
+ }
230
+ });
231
+ this.#instance = new WebAssembly.Instance(module, imports);
232
+ this.exports = Object.create(null);
233
+ for (const item of WebAssembly.Module.exports(artifact.original))
234
+ Object.defineProperty(this.exports, item.name, {
235
+ value: this.#instance.exports[item.name],
236
+ enumerable: true
237
+ });
238
+ Object.freeze(this.exports);
239
+ if (enabled) {
240
+ this.#memory = this.#instance.exports[control.memoryExport];
241
+ for (const name of control.entries)
242
+ this.#controlled.set(name, runtime.promising(this.#instance.exports[name]));
243
+ }
244
+ else if (!this.#memory) {
245
+ const own = Object.values(this.exports).filter((item) => item instanceof WebAssembly.Memory);
246
+ if (own.length === 1)
247
+ this.#memory = own[0];
248
+ }
249
+ for (const name of options.promising ?? []) {
250
+ if (!runtime.promising || typeof this.exports[name] !== 'function')
251
+ throw new TypeError('invalid promising export');
252
+ this.#promising.set(name, runtime.promising(this.exports[name]));
253
+ }
254
+ }
255
+ /** The canonical memory, which must fit the owner runtime. Throws when there is no unique one. */
256
+ get memory() {
257
+ if (!this.#memory)
258
+ throw new TypeError('no unique accessible memory');
259
+ return this.#memory;
260
+ }
261
+ /** Runs one entry; regions go to lanes and results commit in order. One run at a time. */
262
+ run(name, args = [], options = {}) {
263
+ if (this.#closed)
264
+ return Promise.reject(new Error('folio is closed'));
265
+ if (this.#busy)
266
+ return Promise.reject(new Error('memory already has an active run'));
267
+ const entry = this.exports[name];
268
+ if (typeof entry !== 'function')
269
+ return Promise.reject(new TypeError('unknown function export'));
270
+ const width = Math.min(this.#lanes.length, integer(options.maximumWorkers ?? this.#lanes.length, 1, 64, 'maximumWorkers'));
271
+ this.#busy = true;
272
+ let resolve, reject;
273
+ const pending = new Promise((success, failure) => {
274
+ resolve = success;
275
+ reject = failure;
276
+ });
277
+ this.#pending = pending;
278
+ void pending
279
+ .finally(() => {
280
+ this.#busy = false;
281
+ this.#pending = undefined;
282
+ })
283
+ .catch(() => { });
284
+ void this.#execute(name, entry, args, width, options.parallel === 'off').then(resolve, reject);
285
+ return pending;
286
+ }
287
+ async #execute(name, entry, args, width, serial) {
288
+ const bytes = { sent: 0, received: 0 };
289
+ let snapshotBytes = 0;
290
+ let transportFallbacks = 0;
291
+ const finish = (report) => ({
292
+ ...report,
293
+ backend: 'managed-coherent',
294
+ memoryMode: 'copied',
295
+ transportBytes: bytes,
296
+ transportFallbacks
297
+ });
298
+ const controlled = this.#controlled.get(name);
299
+ if (serial ||
300
+ !controlled ||
301
+ width < 2 ||
302
+ args.some((value) => typeof value !== 'number' && typeof value !== 'bigint')) {
303
+ const value = this.#promising.has(name)
304
+ ? await this.#promising.get(name)(...args)
305
+ : entry(...args);
306
+ return finish({
307
+ values: [value],
308
+ workers: 0,
309
+ regions: 1,
310
+ replayed: 0,
311
+ fallbacks: 0,
312
+ mode: 'serial'
313
+ });
314
+ }
315
+ const epoch = ++this.#epoch;
316
+ const scheduler = new Coordinator({
317
+ memory: this.memory,
318
+ workerMemory: this.memory,
319
+ width,
320
+ profile: false,
321
+ pending: this.#pendingGlobal,
322
+ native: (call) => {
323
+ const previous = this.#serial.value;
324
+ this.#serial.value = 1;
325
+ try {
326
+ this.#instance.exports[call.export](...call.args);
327
+ }
328
+ finally {
329
+ this.#serial.value = previous;
330
+ }
331
+ },
332
+ dispatch: async (lane, calls) => {
333
+ try {
334
+ if (this.memory.buffer.byteLength > this.#maximumSnapshotBytes)
335
+ throw new RangeError('snapshot exceeds limit');
336
+ const identity = { session: this.#session, epoch, sequence: ++this.#sequence };
337
+ const frame = encodeFrame({ ...identity, calls, fuel: this.#fuel, maxBytes: this.#maxBytes }, new Uint8Array(this.memory.buffer), this.#maximumFrameBytes);
338
+ snapshotBytes += this.memory.buffer.byteLength;
339
+ bytes.sent += frame.length;
340
+ const response = await this.#lanes[lane].execute(frame);
341
+ bytes.received += response.length;
342
+ return decodeResults(response, identity, {
343
+ maximumFrameBytes: this.#maximumFrameBytes,
344
+ memoryBytes: this.memory.buffer.byteLength,
345
+ maxBytes: this.#maxBytes,
346
+ calls: calls.length
347
+ });
348
+ }
349
+ catch (error) {
350
+ transportFallbacks++;
351
+ this.diagnostics.push(`lane unavailable; native fallback: ${error instanceof Error ? error.message : String(error)}`);
352
+ return calls.map(() => ({ reads: [], writes: [], exhausted: true }));
353
+ }
354
+ }
355
+ });
356
+ this.#scheduler = scheduler;
357
+ this.#serial.value = 0;
358
+ try {
359
+ let value, failure, failed = false;
360
+ try {
361
+ value = await controlled(...args);
362
+ }
363
+ catch (error) {
364
+ failed = true;
365
+ failure = error;
366
+ }
367
+ await scheduler.flush();
368
+ if (failed)
369
+ throw failure;
370
+ scheduler.report.values = [value];
371
+ scheduler.report.snapshotBytes = snapshotBytes;
372
+ return finish(scheduler.report);
373
+ }
374
+ finally {
375
+ this.#serial.value = 1;
376
+ this.#pendingGlobal.value = 0;
377
+ this.#scheduler = undefined;
378
+ }
379
+ }
380
+ /** Waits for the active run, then closes every lane. A failed disposer does not skip the rest. */
381
+ close() {
382
+ if (this.#closing)
383
+ return this.#closing;
384
+ this.#closed = true;
385
+ this.#closing = (async () => {
386
+ await this.#pending?.catch(() => { });
387
+ const outcomes = await Promise.allSettled(this.#lanes.map(async (lane) => lane.close?.()));
388
+ const failed = outcomes.find((result) => result.status === 'rejected');
389
+ if (failed?.status === 'rejected')
390
+ throw failed.reason;
391
+ })();
392
+ return this.#closing;
393
+ }
394
+ /** `await using` support; equivalent to `close()`. */
395
+ [Symbol.asyncDispose]() {
396
+ return this.close();
397
+ }
398
+ }
@@ -0,0 +1,10 @@
1
+ export interface MemoryImport {
2
+ module: string;
3
+ name: string;
4
+ initial: number;
5
+ maximum?: number;
6
+ shared: boolean;
7
+ memory64: boolean;
8
+ }
9
+ /** Reads imported memory limits without changing the module or compiling its functions. */
10
+ export declare function memoryImports(bytes: Uint8Array): MemoryImport[];
package/dist/memory.js ADDED
@@ -0,0 +1,89 @@
1
+ /** Reads imported memory limits without changing the module or compiling its functions. */
2
+ export function memoryImports(bytes) {
3
+ let offset = 8;
4
+ const byte = () => {
5
+ if (offset >= bytes.length)
6
+ throw new RangeError('truncated wasm metadata');
7
+ return bytes[offset++];
8
+ };
9
+ const unsigned = () => {
10
+ let value = 0n, shift = 0n;
11
+ for (let i = 0; i < 10; i++) {
12
+ const part = byte();
13
+ value |= BigInt(part & 127) << shift;
14
+ if (!(part & 128)) {
15
+ if (value > BigInt(Number.MAX_SAFE_INTEGER))
16
+ throw new RangeError('memory limit exceeds JS integer precision');
17
+ return Number(value);
18
+ }
19
+ shift += 7n;
20
+ }
21
+ throw new RangeError('invalid wasm integer');
22
+ };
23
+ const name = () => {
24
+ const length = unsigned();
25
+ const end = offset + length;
26
+ if (end > bytes.length)
27
+ throw new RangeError('truncated wasm name');
28
+ const value = new TextDecoder().decode(bytes.subarray(offset, end));
29
+ offset = end;
30
+ return value;
31
+ };
32
+ const reference = () => {
33
+ const type = byte();
34
+ if (type === 0x63 || type === 0x64) {
35
+ while (byte() & 128) { }
36
+ }
37
+ };
38
+ while (offset < bytes.length) {
39
+ const section = byte();
40
+ const length = unsigned();
41
+ const end = offset + length;
42
+ if (end > bytes.length)
43
+ throw new RangeError('truncated wasm section');
44
+ if (section !== 2) {
45
+ offset = end;
46
+ continue;
47
+ }
48
+ const count = unsigned();
49
+ const memories = [];
50
+ for (let i = 0; i < count; i++) {
51
+ const module = name(), base = name(), kind = byte();
52
+ if (kind === 0)
53
+ unsigned();
54
+ else if (kind === 1) {
55
+ reference();
56
+ const flags = unsigned();
57
+ unsigned();
58
+ if (flags & 1)
59
+ unsigned();
60
+ }
61
+ else if (kind === 2) {
62
+ const flags = unsigned();
63
+ if (flags & ~7)
64
+ throw new TypeError('unsupported memory-limit metadata');
65
+ const initial = unsigned(), maximum = flags & 1 ? unsigned() : undefined;
66
+ memories.push({
67
+ module,
68
+ name: base,
69
+ initial,
70
+ maximum,
71
+ shared: Boolean(flags & 2),
72
+ memory64: Boolean(flags & 4)
73
+ });
74
+ }
75
+ else if (kind === 3) {
76
+ reference();
77
+ byte();
78
+ }
79
+ else if (kind === 4) {
80
+ byte();
81
+ unsigned();
82
+ }
83
+ else
84
+ throw new TypeError('unsupported wasm import metadata');
85
+ }
86
+ return memories;
87
+ }
88
+ return [];
89
+ }
package/dist/node.d.ts ADDED
@@ -0,0 +1,124 @@
1
+ import type { PreparedProgram } from './compiler.ts';
2
+ /** Wraps an asynchronous host import for Wasm stack suspension. */
3
+ export declare function suspending<Args extends unknown[], Value>(fn: (...args: Args) => Promise<Value>): WebAssembly.ImportValue;
4
+ /** Source bytes, a compiled module, or a plan from `prepare`. A compiled module keeps its native path. */
5
+ export type ProgramInput = PreparedProgram | Uint8Array | ArrayBuffer | WebAssembly.Module;
6
+ /** One exported call in an ordered `runAll` batch. */
7
+ export interface Call {
8
+ /** Name of the exported function. */
9
+ export: string;
10
+ /** Arguments in Wasm order; i64 parameters take bigint. */
11
+ args: readonly unknown[];
12
+ }
13
+ /** Per-run routing and worker limits. */
14
+ export interface RunOptions {
15
+ /** `auto` routes by plan, `off` runs the original entry, `speculate` forces tracked regions. */
16
+ parallel?: 'auto' | 'off' | 'speculate';
17
+ /** Bound participating workers without rebuilding the isolate group. */
18
+ maximumWorkers?: number;
19
+ }
20
+ /** What a run did: results, how it was routed and what the speculation cost. */
21
+ export interface ExecutionReport {
22
+ /** Return values of the call, or of each call in a batch. */
23
+ values: unknown[];
24
+ /** Workers that executed regions; zero for a serial run. */
25
+ workers: number;
26
+ /** Regions discovered and dispatched. */
27
+ regions: number;
28
+ /** Regions that conflicted and replayed against committed state. */
29
+ replayed: number;
30
+ /** Regions or batches that fell back to native execution at the owner. */
31
+ fallbacks: number;
32
+ /** `native-shared` ran proved kernels on the shared allocation without tracking. */
33
+ mode: 'serial' | 'speculative' | 'native-shared';
34
+ /** Set when the generalized control-flow extractor produced the regions. */
35
+ extraction?: 'control-flow';
36
+ /** `shared` regions read the physical allocation; `snapshot` ran on a copied arena. */
37
+ memoryMode?: 'shared' | 'snapshot';
38
+ /** Bytes copied into the worker group for snapshot execution. */
39
+ snapshotBytes?: number;
40
+ /** Why a run stayed serial or left the fast path. */
41
+ reason?: 'requested' | 'small-workload' | 'no-parallel-plan' | 'single-region' | 'unsupported-module' | 'dependency' | 'guard-failed' | 'snapshot-unavailable' | 'opaque-input';
42
+ /** Present when `FolioOptions.profile` is set. */
43
+ profile?: ExecutionProfile;
44
+ }
45
+ /** Opt-in timings. Process CPU is measured once at the coordinator, not summed from these. */
46
+ export interface ExecutionProfile {
47
+ /** Elapsed time of the whole run. */
48
+ wallMs: number;
49
+ /** Elapsed time of each region or batch observation on its worker. */
50
+ workerWallMs: number[];
51
+ /** Thread CPU time of each observation. */
52
+ workerCpuMs: number[];
53
+ /** Ordered dependency validation. */
54
+ validationMs: number;
55
+ /** Committing validated writes to canonical memory. */
56
+ commitMs: number;
57
+ /** Re-executing conflicted regions. */
58
+ replayMs: number;
59
+ /** Bytes tracked as read by speculative regions. */
60
+ readBytes: number;
61
+ /** Bytes tracked as written by speculative regions. */
62
+ writeBytes: number;
63
+ }
64
+ /** Pool construction options. */
65
+ export interface FolioOptions {
66
+ /** Bind an existing single imported memory instead of allocating one from the module's limits. */
67
+ memory?: WebAssembly.Memory;
68
+ /** Isolate count; defaults to up to four. One worker uses the native entry and creates no thread. */
69
+ workers?: number;
70
+ /** Host imports, memories, tables and globals as for native instantiation. */
71
+ imports?: WebAssembly.Imports;
72
+ /** Instruction budget per speculative region before it yields to the native head. */
73
+ fuel?: number;
74
+ /** Bytes of read and write tracking a lane may retain. */
75
+ maxTransactionBytes?: number;
76
+ /** Estimated iterations below which a proved kernel stays at its original entry. */
77
+ minimumParallelWork?: number;
78
+ /** Exports that return a Promise because they suspend on async host imports. */
79
+ promising?: readonly string[];
80
+ /** Collect execution timings; disabled by default to keep the hot path small. */
81
+ profile?: boolean;
82
+ /** Static admission threshold used when `open` prepares raw bytes; a prepared plan keeps its own. */
83
+ minimumRegionWork?: number;
84
+ /** Iterations assumed for loops with no constant bound when `open` prepares raw bytes. */
85
+ assumedTripCount?: number;
86
+ }
87
+ /** A same-process isolate group; callers give it exclusive memory access during each run. */
88
+ export declare class Folio {
89
+ #private;
90
+ /** Active sharing, extraction and validation mode; a one-worker pool reports none and serial. */
91
+ get capabilities(): Readonly<{
92
+ physicalSharing: "none" | "same-process";
93
+ automaticRegions: "none" | "control-flow" | "counted-loops";
94
+ dependence: "serial" | "ordered-validation";
95
+ }>;
96
+ /** The original native exports, for trusted host integration. Raw calls bypass tracking. */
97
+ get exports(): WebAssembly.Exports;
98
+ /** The unique accessible arena, including a coordinator-exposed hidden memory. Throws otherwise. */
99
+ get memory(): WebAssembly.Memory;
100
+ /** Named imported and exported memory wrappers. */
101
+ get memories(): Readonly<Record<string, WebAssembly.Memory>>;
102
+ /** Module-wide reasons the optimizer refused or fell back. A refusal is not a proved dependency. */
103
+ get diagnostics(): readonly string[];
104
+ /** Whether `entry` has an automatic plan or a native guard, by which mechanism, and why not. */
105
+ inspect(entry: string): Readonly<{
106
+ automatic: boolean;
107
+ nativeGuard: boolean;
108
+ mechanism: "counted-loop" | "control-flow" | "native";
109
+ diagnostics: readonly string[];
110
+ }>;
111
+ /** Thread ids of the worker isolates, in start order. */
112
+ readonly threadIds: number[];
113
+ private constructor();
114
+ /** Instantiates the program, starts the worker group and returns a ready pool. */
115
+ static open(input: ProgramInput, options?: FolioOptions): Promise<Folio>;
116
+ /** Splits compiler-recognized loops automatically; otherwise runs the original entry. */
117
+ run(entry: string, args?: Call['args'], options?: RunOptions): Promise<ExecutionReport>;
118
+ /** Preserves call order while discovering memory dependencies at runtime. */
119
+ runAll(calls: readonly Call[], options?: RunOptions): Promise<ExecutionReport>;
120
+ /** Joins worker termination and outstanding JSPI calls. Repeated calls share one join. */
121
+ close(): Promise<void>;
122
+ /** `await using` support; equivalent to `close()`. */
123
+ [Symbol.asyncDispose](): Promise<void>;
124
+ }