@gmitch215/folio 1.1.0 → 1.2.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.
- package/README.md +78 -810
- package/dist/boot.d.ts +1 -0
- package/dist/boot.js +1 -0
- package/dist/browser/index.d.ts +73 -0
- package/dist/browser/index.js +277 -0
- package/dist/browser.d.ts +1 -68
- package/dist/browser.js +1 -274
- package/dist/continuation.d.ts +1 -0
- package/dist/continuation.js +1 -0
- package/dist/{compiler.d.ts → execution/compiler.d.ts} +1 -1
- package/dist/{compiler.js → execution/compiler.js} +5 -12
- package/dist/{coordinator.d.ts → execution/coordinator.d.ts} +1 -1
- package/dist/{coordinator.js → execution/coordinator.js} +5 -5
- package/dist/{extract.d.ts → execution/extract.d.ts} +3 -13
- package/dist/{extract.js → execution/extract.js} +7 -8
- package/dist/{fold.d.ts → execution/fold.d.ts} +15 -3
- package/dist/{guards.d.ts → execution/guards.d.ts} +2 -1
- package/dist/execution/types.d.ts +221 -0
- package/dist/{affine-state.d.ts → folds/affine-state.d.ts} +18 -47
- package/dist/{affine-state.js → folds/affine-state.js} +18 -44
- package/dist/{affine.d.ts → folds/affine.d.ts} +12 -24
- package/dist/{affine.js → folds/affine.js} +8 -17
- package/dist/{boundaries.d.ts → folds/boundaries.d.ts} +7 -18
- package/dist/{boundaries.js → folds/boundaries.js} +5 -13
- package/dist/{certified.d.ts → folds/certified.d.ts} +13 -24
- package/dist/{certified.js → folds/certified.js} +12 -26
- package/dist/{certify.d.ts → folds/certify.d.ts} +11 -22
- package/dist/{certify.js → folds/certify.js} +24 -41
- package/dist/{memo.d.ts → footprints/memo.d.ts} +8 -33
- package/dist/{memo.js → footprints/memo.js} +8 -2
- package/dist/{ranges.js → footprints/ranges.js} +1 -1
- package/dist/{read-scan.js → footprints/read-scan.js} +1 -1
- package/dist/{read-windows.d.ts → footprints/read-windows.d.ts} +6 -32
- package/dist/{read-windows.js → footprints/read-windows.js} +8 -7
- package/dist/index.d.ts +16 -4
- package/dist/index.js +14 -2
- package/dist/{iteration-admission.d.ts → iteration/admission.d.ts} +2 -38
- package/dist/{iteration.d.ts → iteration/index.d.ts} +8 -98
- package/dist/{iteration.js → iteration/index.js} +28 -28
- package/dist/{inline.js → iteration/inline.js} +2 -9
- package/dist/{iteration-owner.d.ts → iteration/owner.d.ts} +3 -3
- package/dist/{iteration-owner.js → iteration/owner.js} +4 -3
- package/dist/{iteration-worker.js → iteration/worker.js} +3 -3
- package/dist/{managed.d.ts → managed/index.d.ts} +3 -3
- package/dist/{managed.js → managed/index.js} +7 -9
- package/dist/managed/outbox.d.ts +128 -0
- package/dist/managed/outbox.js +156 -0
- package/dist/managed/pool.d.ts +221 -0
- package/dist/managed/pool.js +310 -0
- package/dist/managed/tasks.d.ts +154 -0
- package/dist/managed/tasks.js +183 -0
- package/dist/{bake.d.ts → memory/bake.d.ts} +12 -6
- package/dist/{bake.js → memory/bake.js} +9 -7
- package/dist/memory/continuation.d.ts +141 -0
- package/dist/memory/continuation.js +495 -0
- package/dist/memory/elastic-peer.d.ts +20 -0
- package/dist/memory/elastic-peer.js +39 -0
- package/dist/memory/elastic-sql.d.ts +11 -0
- package/dist/memory/elastic-sql.js +35 -0
- package/dist/memory/elastic.d.ts +130 -0
- package/dist/memory/elastic.js +475 -0
- package/dist/memory/growth-governor.d.ts +16 -0
- package/dist/memory/growth-governor.js +42 -0
- package/dist/memory/imports.d.ts +10 -0
- package/dist/memory/imports.js +89 -0
- package/dist/{iteration-layout.d.ts → memory/iteration-layout.d.ts} +1 -1
- package/dist/{pages.d.ts → memory/pages.d.ts} +3 -3
- package/dist/memory.d.ts +5 -10
- package/dist/memory.js +5 -89
- package/dist/{context.d.ts → node/context.d.ts} +1 -1
- package/dist/{host.d.ts → node/host.d.ts} +1 -1
- package/dist/{host.js → node/host.js} +2 -2
- package/dist/{node.d.ts → node/index.d.ts} +4 -49
- package/dist/{node.js → node/index.js} +16 -17
- package/dist/{tasks.d.ts → node/tasks.d.ts} +2 -13
- package/dist/{worker.js → node/worker.js} +2 -2
- package/dist/{ownership.js → ownership/index.js} +7 -10
- package/dist/{ownership-redirect.d.ts → ownership/redirect.d.ts} +2 -2
- package/dist/{ownership-redirect.js → ownership/redirect.js} +2 -2
- package/dist/{ownership-slices.d.ts → ownership/slices.d.ts} +3 -3
- package/dist/{ownership-slices.js → ownership/slices.js} +3 -3
- package/dist/{frames.d.ts → remote/frames.d.ts} +1 -1
- package/dist/{frames.js → remote/frames.js} +2 -2
- package/dist/{remote.d.ts → remote/index.d.ts} +7 -2
- package/dist/{remote.js → remote/index.js} +7 -2
- package/dist/{router.d.ts → routing/index.d.ts} +3 -3
- package/dist/{router.js → routing/index.js} +19 -15
- package/dist/{router-worker.js → routing/worker.js} +1 -1
- package/dist/{slices.d.ts → slices/index.d.ts} +2 -2
- package/dist/{slices.js → slices/index.js} +5 -5
- package/dist/slices/worker.d.ts +1 -0
- package/dist/{slices-worker.js → slices/worker.js} +2 -2
- package/dist/workers.d.ts +5 -0
- package/dist/workers.js +5 -0
- package/package.json +30 -80
- /package/dist/{browser-worker.d.ts → browser/worker.d.ts} +0 -0
- /package/dist/{browser-worker.js → browser/worker.js} +0 -0
- /package/dist/{fold.js → execution/fold.js} +0 -0
- /package/dist/{guards.js → execution/guards.js} +0 -0
- /package/dist/{import-order.d.ts → execution/import-order.d.ts} +0 -0
- /package/dist/{import-order.js → execution/import-order.js} +0 -0
- /package/dist/{runs.d.ts → execution/runs.d.ts} +0 -0
- /package/dist/{runs.js → execution/runs.js} +0 -0
- /package/dist/{transaction.d.ts → execution/transaction.d.ts} +0 -0
- /package/dist/{transaction.js → execution/transaction.js} +0 -0
- /package/dist/{iteration-worker.d.ts → execution/types.js} +0 -0
- /package/dist/{ranges.d.ts → footprints/ranges.d.ts} +0 -0
- /package/dist/{read-scan.d.ts → footprints/read-scan.d.ts} +0 -0
- /package/dist/{iteration-admission.js → iteration/admission.js} +0 -0
- /package/dist/{inline.d.ts → iteration/inline.d.ts} +0 -0
- /package/dist/{worker.d.ts → iteration/worker.d.ts} +0 -0
- /package/dist/{iteration-layout.js → memory/iteration-layout.js} +0 -0
- /package/dist/{lease.d.ts → memory/lease.d.ts} +0 -0
- /package/dist/{lease.js → memory/lease.js} +0 -0
- /package/dist/{pages.js → memory/pages.js} +0 -0
- /package/dist/{context.js → node/context.js} +0 -0
- /package/dist/{tasks.js → node/tasks.js} +0 -0
- /package/dist/{router-worker.d.ts → node/worker.d.ts} +0 -0
- /package/dist/{ownership.d.ts → ownership/index.d.ts} +0 -0
- /package/dist/{values.d.ts → remote/values.d.ts} +0 -0
- /package/dist/{values.js → remote/values.js} +0 -0
- /package/dist/{slices-worker.d.ts → routing/worker.d.ts} +0 -0
|
@@ -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
|
+
}
|
|
@@ -12,8 +12,8 @@ export interface PageVersion {
|
|
|
12
12
|
fence: number;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
* Transport boundary for immutable pages. Reads return independent copies. Staging is idempotent
|
|
16
|
-
* identical versions and bytes; discarding fences that version against delayed stage requests.
|
|
15
|
+
* Transport boundary for immutable pages. Reads return independent copies. Staging is idempotent
|
|
16
|
+
* for identical versions and bytes; discarding fences that version against delayed stage requests.
|
|
17
17
|
* Implementations must authenticate the scope and enforce their own storage, request and deadline
|
|
18
18
|
* limits. A never-settling request retains its directory locks; expiry cannot cancel an RPC.
|
|
19
19
|
*/
|
|
@@ -34,7 +34,7 @@ export declare class MemoryPageOwner implements PageOwner {
|
|
|
34
34
|
stage(scope: PageScope, version: PageVersion, bytes: Uint8Array): Promise<void>;
|
|
35
35
|
discard(scope: PageScope, version: PageVersion): Promise<void>;
|
|
36
36
|
}
|
|
37
|
-
/** Bounds
|
|
37
|
+
/** Bounds cover retained metadata, resident pages and commit snapshots, not caller-owned copies. */
|
|
38
38
|
export interface PageDirectoryOptions {
|
|
39
39
|
/** Fresh incarnation for one trusted active directory; never reuse it after a restart. */
|
|
40
40
|
scope: PageScope;
|
package/dist/memory.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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[];
|
|
1
|
+
export * from './memory/elastic-peer.ts';
|
|
2
|
+
export * from './memory/elastic-sql.ts';
|
|
3
|
+
export * from './memory/elastic.ts';
|
|
4
|
+
export * from './memory/growth-governor.ts';
|
|
5
|
+
export * from './memory/pages.ts';
|
package/dist/memory.js
CHANGED
|
@@ -1,89 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
}
|
|
1
|
+
export * from "./memory/elastic-peer.js";
|
|
2
|
+
export * from "./memory/elastic-sql.js";
|
|
3
|
+
export * from "./memory/elastic.js";
|
|
4
|
+
export * from "./memory/growth-governor.js";
|
|
5
|
+
export * from "./memory/pages.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PreparedContext } from '
|
|
1
|
+
import type { PreparedContext } from '../execution/compiler.ts';
|
|
2
2
|
/** A changed memory or table size requires a newly instantiated context. */
|
|
3
3
|
export declare class ContextResetError extends Error {
|
|
4
4
|
/** Which binding changed size. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FolioOptions, ProgramInput } from './
|
|
1
|
+
import type { FolioOptions, ProgramInput } from './index.ts';
|
|
2
2
|
/** A trusted program registered under an artifact id. */
|
|
3
3
|
export interface HostArtifact {
|
|
4
4
|
/** The program or prepared plan every session of this artifact runs. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { decodeBytes, decodeValue, encodeBytes, encodeValue } from "../remote/index.js";
|
|
2
|
+
import { Folio } from "./index.js";
|
|
3
3
|
class ProtocolError extends Error {
|
|
4
4
|
status;
|
|
5
5
|
constructor(message, status = 400) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { PreparedProgram } from '
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
1
|
+
import type { PreparedProgram } from '../execution/compiler.ts';
|
|
2
|
+
import type { ExecutionProfile, ExecutionReport } from '../execution/types.ts';
|
|
3
|
+
import type { IterationStallOptions } from '../iteration/index.ts';
|
|
4
4
|
/** Wraps an asynchronous host import for Wasm stack suspension. */
|
|
5
5
|
export declare function suspending<Args extends unknown[], Value>(fn: (...args: Args) => Promise<Value>): WebAssembly.ImportValue;
|
|
6
6
|
/** Source bytes, a compiled module, or a plan from `prepare`. A compiled module keeps its native path. */
|
|
@@ -19,52 +19,7 @@ export interface RunOptions {
|
|
|
19
19
|
/** Bound participating workers without rebuilding the isolate group. */
|
|
20
20
|
maximumWorkers?: number;
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
export interface ExecutionReport {
|
|
24
|
-
/** Return values of the call, or of each call in a batch. */
|
|
25
|
-
values: unknown[];
|
|
26
|
-
/** Workers that executed regions; zero for a serial run. */
|
|
27
|
-
workers: number;
|
|
28
|
-
/** Regions discovered and dispatched. */
|
|
29
|
-
regions: number;
|
|
30
|
-
/** Regions that conflicted and replayed against committed state. */
|
|
31
|
-
replayed: number;
|
|
32
|
-
/** Regions or batches that fell back to native execution at the owner. */
|
|
33
|
-
fallbacks: number;
|
|
34
|
-
/** `native-shared` ran proved kernels on the shared allocation without tracking. */
|
|
35
|
-
mode: 'serial' | 'speculative' | 'native-shared';
|
|
36
|
-
/** Set when the control-flow extractor or the iteration route produced the regions. */
|
|
37
|
-
extraction?: 'control-flow' | 'iteration';
|
|
38
|
-
/** `shared` regions read the physical allocation; `snapshot` ran on a copied arena. */
|
|
39
|
-
memoryMode?: 'shared' | 'snapshot';
|
|
40
|
-
/** Bytes copied into the worker group for snapshot execution. */
|
|
41
|
-
snapshotBytes?: number;
|
|
42
|
-
/** Why a run stayed serial or left the fast path. */
|
|
43
|
-
reason?: 'requested' | 'small-workload' | 'no-parallel-plan' | 'single-region' | 'unsupported-module' | 'dependency' | 'guard-failed' | 'snapshot-unavailable' | 'previous-conflicts' | 'opaque-input' | IterationReason;
|
|
44
|
-
/** The iteration executor's counts, summed over the owner calls of the run. */
|
|
45
|
-
iteration?: IterationReport;
|
|
46
|
-
/** Present when `FolioOptions.profile` is set. */
|
|
47
|
-
profile?: ExecutionProfile;
|
|
48
|
-
}
|
|
49
|
-
/** Opt-in timings. Process CPU is measured once at the coordinator, not summed from these. */
|
|
50
|
-
export interface ExecutionProfile {
|
|
51
|
-
/** Elapsed time of the whole run. */
|
|
52
|
-
wallMs: number;
|
|
53
|
-
/** Elapsed time of each region or batch observation on its worker. */
|
|
54
|
-
workerWallMs: number[];
|
|
55
|
-
/** Thread CPU time of each observation. */
|
|
56
|
-
workerCpuMs: number[];
|
|
57
|
-
/** Ordered dependency validation. */
|
|
58
|
-
validationMs: number;
|
|
59
|
-
/** Committing validated writes to canonical memory. */
|
|
60
|
-
commitMs: number;
|
|
61
|
-
/** Re-executing conflicted regions. */
|
|
62
|
-
replayMs: number;
|
|
63
|
-
/** Bytes tracked as read by speculative regions. */
|
|
64
|
-
readBytes: number;
|
|
65
|
-
/** Bytes tracked as written by speculative regions. */
|
|
66
|
-
writeBytes: number;
|
|
67
|
-
}
|
|
22
|
+
export type { ExecutionProfile, ExecutionReport };
|
|
68
23
|
/** Pool construction options. */
|
|
69
24
|
export interface FolioOptions {
|
|
70
25
|
/**
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { availableParallelism } from 'node:os';
|
|
2
2
|
import { isArrayBuffer, isSharedArrayBuffer, isUint8Array } from 'node:util/types';
|
|
3
3
|
import { Worker } from 'node:worker_threads';
|
|
4
|
-
import { Coordinator } from "
|
|
5
|
-
import { decideAdmission, decideBatch, decideBound, decideCollapse, decideProof, decideRemaining } from "
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { numberBits, restoreNumbers } from "
|
|
4
|
+
import { Coordinator } from "../execution/coordinator.js";
|
|
5
|
+
import { decideAdmission, decideBatch, decideBound, decideCollapse, decideProof, decideRemaining } from "../iteration/admission.js";
|
|
6
|
+
import { memoryImports } from "../memory/imports.js";
|
|
7
|
+
import { iterationArguments, iterationFit, iterationWindowBytes } from "../memory/iteration-layout.js";
|
|
8
|
+
import { numberBits, restoreNumbers } from "../remote/values.js";
|
|
9
9
|
/** Wraps an asynchronous host import for Wasm stack suspension. */
|
|
10
10
|
export function suspending(fn) {
|
|
11
11
|
const runtime = WebAssembly;
|
|
@@ -99,7 +99,7 @@ async function selectIteration(program, options, size) {
|
|
|
99
99
|
Object.keys(program.native ?? {}).length)
|
|
100
100
|
return;
|
|
101
101
|
const refuse = (reason, detail) => ({ reason, detail });
|
|
102
|
-
const { iterationOwner } = await import("
|
|
102
|
+
const { iterationOwner } = await import("../iteration/owner.js");
|
|
103
103
|
const built = iterationOwner(program.original, route, program.stackRoute?.stack?.name);
|
|
104
104
|
if (!('owner' in built))
|
|
105
105
|
return built;
|
|
@@ -278,7 +278,7 @@ export class Folio {
|
|
|
278
278
|
const candidate = new WebAssembly.Module(Uint8Array.from(control.coordinator));
|
|
279
279
|
const originalImports = WebAssembly.Module.imports(native);
|
|
280
280
|
const retainedImports = WebAssembly.Module.imports(candidate).filter((item) => item.module !== control.namespace);
|
|
281
|
-
//
|
|
281
|
+
// binding accessors are effects too, so keep the engine's lookup order
|
|
282
282
|
if (JSON.stringify(originalImports) === JSON.stringify(retainedImports)) {
|
|
283
283
|
this.#control = control;
|
|
284
284
|
executable = candidate;
|
|
@@ -304,8 +304,8 @@ export class Folio {
|
|
|
304
304
|
const automatic = new Map();
|
|
305
305
|
let controlBindings;
|
|
306
306
|
let iterationBindings;
|
|
307
|
-
//
|
|
308
|
-
//
|
|
307
|
+
// resolve bindings when the engine asks, in its order
|
|
308
|
+
// spreading caller namespaces would run their accessors early or twice
|
|
309
309
|
const imports = new Proxy(Object.create(null), {
|
|
310
310
|
get: (_, module) => {
|
|
311
311
|
if (this.#control && module === this.#control.namespace) {
|
|
@@ -381,9 +381,8 @@ export class Folio {
|
|
|
381
381
|
});
|
|
382
382
|
}
|
|
383
383
|
});
|
|
384
|
-
//
|
|
385
|
-
//
|
|
386
|
-
// retain their native identity and return-value semantics.
|
|
384
|
+
// jspi promise resolution can assimilate an externref promise result, so only
|
|
385
|
+
// explicitly asynchronous entries get that abi; other exports keep their identity
|
|
387
386
|
const promising = options.promising ?? [];
|
|
388
387
|
for (const name of promising) {
|
|
389
388
|
if (!WebAssembly.Module.exports(native).some((value) => value.name === name && value.kind === 'function'))
|
|
@@ -455,7 +454,7 @@ export class Folio {
|
|
|
455
454
|
reasons: ['compiled module has no inspectable source bytes']
|
|
456
455
|
}
|
|
457
456
|
: isUint8Array(input) || isArrayBuffer(input)
|
|
458
|
-
? (await import("
|
|
457
|
+
? (await import("../execution/compiler.js")).prepare(isUint8Array(input) ? input : new Uint8Array(input), {
|
|
459
458
|
minimumRegionWork: options.minimumRegionWork,
|
|
460
459
|
assumedTripCount: options.assumedTripCount
|
|
461
460
|
})
|
|
@@ -716,7 +715,7 @@ export class Folio {
|
|
|
716
715
|
await it.pool?.close();
|
|
717
716
|
it.pool = undefined;
|
|
718
717
|
try {
|
|
719
|
-
const { IterationPool } = await import("
|
|
718
|
+
const { IterationPool } = await import("../iteration/index.js");
|
|
720
719
|
it.pool = await IterationPool.open(it.route, it.memory, {
|
|
721
720
|
arenaBase: it.arenaBase,
|
|
722
721
|
windowBytes: iterationWindowBytes,
|
|
@@ -803,7 +802,7 @@ export class Folio {
|
|
|
803
802
|
report.reason = run.reason ?? 'no-parallel-plan';
|
|
804
803
|
return report;
|
|
805
804
|
}
|
|
806
|
-
//
|
|
805
|
+
// host call the owner's loop makes: 1 when every iteration ran, 0 to run the loop here
|
|
807
806
|
#iterate(values) {
|
|
808
807
|
const it = this.#iteration;
|
|
809
808
|
const run = it.run;
|
|
@@ -944,8 +943,8 @@ export class Folio {
|
|
|
944
943
|
failed = true;
|
|
945
944
|
failure = error;
|
|
946
945
|
}
|
|
947
|
-
//
|
|
948
|
-
//
|
|
946
|
+
// if the original coordinator traps first, pending regions still own the
|
|
947
|
+
// earlier effects and the trap in program order
|
|
949
948
|
await coordinator.flush();
|
|
950
949
|
if (failed)
|
|
951
950
|
throw failure;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type MessagePort } from 'node:worker_threads';
|
|
2
|
+
import type { TaskRecord } from '../execution/types.ts';
|
|
2
3
|
/** Task input and output are copied between threads. Strings and bytes are both accepted. */
|
|
3
4
|
export type TaskInput = string | Uint8Array;
|
|
4
5
|
/** Options for one submitted task. */
|
|
@@ -16,19 +17,7 @@ export interface TaskLink {
|
|
|
16
17
|
port: MessagePort;
|
|
17
18
|
signal: SharedArrayBuffer;
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
export interface TaskRecord {
|
|
21
|
-
id: string;
|
|
22
|
-
worker: number;
|
|
23
|
-
name: string;
|
|
24
|
-
submitMs: number;
|
|
25
|
-
startMs: number;
|
|
26
|
-
endMs: number;
|
|
27
|
-
waitMs: number;
|
|
28
|
-
cpuMs?: number;
|
|
29
|
-
inputBytes: number;
|
|
30
|
-
outputBytes: number;
|
|
31
|
-
}
|
|
20
|
+
export type { TaskRecord };
|
|
32
21
|
/** Options for `TaskPool`. */
|
|
33
22
|
export interface TaskPoolOptions {
|
|
34
23
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parentPort, threadId, workerData } from 'node:worker_threads';
|
|
2
|
-
import { SpeculationLimit, transaction } from "
|
|
3
|
-
import { numberBits, restoreNumbers } from "
|
|
2
|
+
import { SpeculationLimit, transaction } from "../execution/transaction.js";
|
|
3
|
+
import { numberBits, restoreNumbers } from "../remote/values.js";
|
|
4
4
|
const { module, nativeModule, memory, importModule, importName } = workerData;
|
|
5
5
|
const nativeInstance = new WebAssembly.Instance(nativeModule, {
|
|
6
6
|
[importModule]: { [importName]: memory }
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import binaryen from 'binaryen';
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
|
-
import { stackRoute } from "
|
|
3
|
+
import { stackRoute } from "../execution/extract.js";
|
|
4
4
|
export const OWNERSHIP_REASONS = [
|
|
5
5
|
'isolation',
|
|
6
6
|
'read-before-write',
|
|
@@ -1743,9 +1743,8 @@ function callTable(ctx, v, args, index, S) {
|
|
|
1743
1743
|
return callOver(ctx, name, args, S);
|
|
1744
1744
|
}
|
|
1745
1745
|
// #region symbolic extents
|
|
1746
|
-
// facts
|
|
1747
|
-
// y<id> is
|
|
1748
|
-
// the symbol has a bound with another one
|
|
1746
|
+
// symbol facts live in the cell map and never go stale, since a symbol names one value
|
|
1747
|
+
// y<id> is its interval, d<a>|<b> a bias-shifted bound on S_a - S_b, D<id> a bound with another symbol
|
|
1749
1748
|
const FACT_BIAS = 2 ** 31;
|
|
1750
1749
|
const yKey = (id) => `y${id}`;
|
|
1751
1750
|
const dKey = (a, b) => `d${a}|${b}`;
|
|
@@ -2643,9 +2642,8 @@ function dataHull(ctx, addr, offset, v) {
|
|
|
2643
2642
|
// the shared data-range summary: the hull of the little-endian words of `bytes` bytes at the addresses
|
|
2644
2643
|
// first, first + step, ... up to last, read from the active data segment that holds them all, when no store of
|
|
2645
2644
|
// the closure reaches the range. A struct table read at its stride gets one field's hull: pass step = the stride
|
|
2646
|
-
// and first = the field's first address. The caller proves
|
|
2647
|
-
//
|
|
2648
|
-
// caller with its own remainder.
|
|
2645
|
+
// and first = the field's first address. The caller proves every address the real read may name is listed
|
|
2646
|
+
// V.m gives a multiple, not a remainder, so a table base off the stride needs the caller's own remainder
|
|
2649
2647
|
function dataRange(ctx, first, last, step, bytes, signed) {
|
|
2650
2648
|
if (step < 1 || (bytes !== 1 && bytes !== 2 && bytes !== 4))
|
|
2651
2649
|
return undefined;
|
|
@@ -3980,9 +3978,8 @@ const notRecord = (v) => !v.r || !!v.bs || !!v.cn;
|
|
|
3980
3978
|
// the kind of a flagged value: n unflagged, k made from the count, b made from a base (or no record pointer
|
|
3981
3979
|
// at all), p a record pointer (a base plus the stepped counter), c a counter-derived scalar
|
|
3982
3980
|
const flagKind = (v) => (!v.c ? 'n' : v.cn ? 'k' : v.bs ? 'b' : v.r ? 'p' : 'c');
|
|
3983
|
-
//
|
|
3984
|
-
//
|
|
3985
|
-
// flagged value, a base plus a base, or a counter added to a pointer that is not a base, is not.
|
|
3981
|
+
// a record pointer is a base plus the stepped counter and nothing else; its address is the same in a slice
|
|
3982
|
+
// a pointer plus any other flagged value, a base plus a base, or a counter on a non-base is not one
|
|
3986
3983
|
function combineFlags(r, a, b, op) {
|
|
3987
3984
|
const ka = flagKind(a);
|
|
3988
3985
|
const kb = flagKind(b);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type IterationRoute, type OwnershipPlan } from '
|
|
2
|
-
import { type OwnershipCertificate } from './
|
|
1
|
+
import { type IterationRoute, type OwnershipPlan } from '../execution/extract.ts';
|
|
2
|
+
import { type OwnershipCertificate } from './index.ts';
|
|
3
3
|
export type RedirectErrorCode = 'unbound' | 'stale' | 'invalid' | 'unsupported';
|
|
4
4
|
export declare class OwnershipRedirectError extends Error {
|
|
5
5
|
readonly code: RedirectErrorCode;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import binaryen from 'binaryen';
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
|
-
import { iterationRoute, redirectDelta, stackRoute } from "
|
|
4
|
-
import { memoryAccesses, verifyOwnership } from "./
|
|
3
|
+
import { iterationRoute, redirectDelta, stackRoute } from "../execution/extract.js";
|
|
4
|
+
import { memoryAccesses, verifyOwnership } from "./index.js";
|
|
5
5
|
export class OwnershipRedirectError extends Error {
|
|
6
6
|
code;
|
|
7
7
|
constructor(code, detail) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type OwnershipCertificate } from './
|
|
3
|
-
import { type
|
|
1
|
+
import { type SlicePoolOptions, type SliceReport, type SliceRunOptions } from '../slices/index.ts';
|
|
2
|
+
import { type OwnershipCertificate } from './index.ts';
|
|
3
|
+
import { type OwnershipRedirect } from './redirect.ts';
|
|
4
4
|
/**
|
|
5
5
|
* `layout`: a record region overlaps a certified window, so the certificate does not apply.
|
|
6
6
|
* `wild-store`: the module stores to an address outside every window that no record owns, and
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { checkConfig, guardRecords } from "./
|
|
3
|
-
import {
|
|
1
|
+
import { SlicePool } from "../slices/index.js";
|
|
2
|
+
import { checkConfig, guardRecords } from "./index.js";
|
|
3
|
+
import { redirectOwnership } from "./redirect.js";
|
|
4
4
|
/**
|
|
5
5
|
* `layout`: a record region overlaps a certified window, so the certificate does not apply.
|
|
6
6
|
* `wild-store`: the module stores to an address outside every window that no record owns, and
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { checkRuns, runBytes, runsOfSorted, writeRunsOf } from "../execution/runs.js";
|
|
2
|
+
import { decodeValue, encodeValue } from "./index.js";
|
|
3
3
|
const magic = 0x314f4c46;
|
|
4
4
|
const encoder = new TextEncoder();
|
|
5
5
|
const decoder = new TextDecoder('utf-8', { fatal: true });
|
|
@@ -64,11 +64,16 @@ export declare class RemoteFolio {
|
|
|
64
64
|
capabilities: unknown;
|
|
65
65
|
};
|
|
66
66
|
private constructor();
|
|
67
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* Opens a session on a registered artifact. `workers` asks for a group width within host limits.
|
|
69
|
+
*/
|
|
68
70
|
static open(url: string | URL, artifact: string, options?: RemoteOptions & {
|
|
69
71
|
workers?: number;
|
|
70
72
|
}): Promise<RemoteFolio>;
|
|
71
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* Resends the exact uncertain request. The host returns its cached result without repeating
|
|
75
|
+
* effects.
|
|
76
|
+
*/
|
|
72
77
|
retryPending(): Promise<any>;
|
|
73
78
|
/** Runs one allowlisted export in order on the host. */
|
|
74
79
|
run(entry: string, args?: readonly unknown[], options?: {
|
|
@@ -158,7 +158,9 @@ export class RemoteFolio {
|
|
|
158
158
|
this.#headers.set('content-type', 'application/json');
|
|
159
159
|
this.#maximum = options.maximumResponseBytes ?? 2 * 1024 * 1024;
|
|
160
160
|
}
|
|
161
|
-
/**
|
|
161
|
+
/**
|
|
162
|
+
* Opens a session on a registered artifact. `workers` asks for a group width within host limits.
|
|
163
|
+
*/
|
|
162
164
|
static async open(url, artifact, options = {}) {
|
|
163
165
|
const headers = new Headers(options.headers);
|
|
164
166
|
headers.set('content-type', 'application/json');
|
|
@@ -218,7 +220,10 @@ export class RemoteFolio {
|
|
|
218
220
|
this.#busy = false;
|
|
219
221
|
}
|
|
220
222
|
}
|
|
221
|
-
/**
|
|
223
|
+
/**
|
|
224
|
+
* Resends the exact uncertain request. The host returns its cached result without repeating
|
|
225
|
+
* effects.
|
|
226
|
+
*/
|
|
222
227
|
async retryPending() {
|
|
223
228
|
if (this.#busy || !this.#pending)
|
|
224
229
|
throw new Error('no uncertain request is available');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type CertificateRefusal, type StreamCertificate } from '
|
|
2
|
-
import { type OwnershipCertificate, type OwnershipOptions, type OwnershipRefusal } from '
|
|
1
|
+
import { type CertificateRefusal, type StreamCertificate } from '../folds/certify.ts';
|
|
2
|
+
import { type OwnershipCertificate, type OwnershipOptions, type OwnershipRefusal } from '../ownership/index.ts';
|
|
3
3
|
/** @since 1.1.0 */
|
|
4
4
|
export declare const ROUTER_VERSION = "folio-router-2";
|
|
5
5
|
/** `summary` is the certified stream fold, `window` the certified private window on slices. */
|
|
@@ -53,7 +53,7 @@ export interface RouterConstants {
|
|
|
53
53
|
* five paired runs of `aes-cbc-decrypt-shared` at 8 workers beat serial by 1.25 (4 records, 0.82
|
|
54
54
|
* ms; 3 records at 0.69 ms did not). The summary length is the smallest size at which every paired
|
|
55
55
|
* run of two hand stream modules did (1 MiB; 256 KiB did not). One driver and two hand modules,
|
|
56
|
-
* Mac, loaded
|
|
56
|
+
* Mac, loaded.
|
|
57
57
|
*/
|
|
58
58
|
export declare const routerConstants: RouterConstants;
|
|
59
59
|
/** The per-record serial estimate after a tracked call: the lower of it and that call's plain first iteration. @internal */
|