@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.
Files changed (122) hide show
  1. package/README.md +78 -810
  2. package/dist/boot.d.ts +1 -0
  3. package/dist/boot.js +1 -0
  4. package/dist/browser/index.d.ts +73 -0
  5. package/dist/browser/index.js +277 -0
  6. package/dist/browser.d.ts +1 -68
  7. package/dist/browser.js +1 -274
  8. package/dist/continuation.d.ts +1 -0
  9. package/dist/continuation.js +1 -0
  10. package/dist/{compiler.d.ts → execution/compiler.d.ts} +1 -1
  11. package/dist/{compiler.js → execution/compiler.js} +5 -12
  12. package/dist/{coordinator.d.ts → execution/coordinator.d.ts} +1 -1
  13. package/dist/{coordinator.js → execution/coordinator.js} +5 -5
  14. package/dist/{extract.d.ts → execution/extract.d.ts} +3 -13
  15. package/dist/{extract.js → execution/extract.js} +7 -8
  16. package/dist/{fold.d.ts → execution/fold.d.ts} +15 -3
  17. package/dist/{guards.d.ts → execution/guards.d.ts} +2 -1
  18. package/dist/execution/types.d.ts +221 -0
  19. package/dist/{affine-state.d.ts → folds/affine-state.d.ts} +18 -47
  20. package/dist/{affine-state.js → folds/affine-state.js} +18 -44
  21. package/dist/{affine.d.ts → folds/affine.d.ts} +12 -24
  22. package/dist/{affine.js → folds/affine.js} +8 -17
  23. package/dist/{boundaries.d.ts → folds/boundaries.d.ts} +7 -18
  24. package/dist/{boundaries.js → folds/boundaries.js} +5 -13
  25. package/dist/{certified.d.ts → folds/certified.d.ts} +13 -24
  26. package/dist/{certified.js → folds/certified.js} +12 -26
  27. package/dist/{certify.d.ts → folds/certify.d.ts} +11 -22
  28. package/dist/{certify.js → folds/certify.js} +24 -41
  29. package/dist/{memo.d.ts → footprints/memo.d.ts} +8 -33
  30. package/dist/{memo.js → footprints/memo.js} +8 -2
  31. package/dist/{ranges.js → footprints/ranges.js} +1 -1
  32. package/dist/{read-scan.js → footprints/read-scan.js} +1 -1
  33. package/dist/{read-windows.d.ts → footprints/read-windows.d.ts} +6 -32
  34. package/dist/{read-windows.js → footprints/read-windows.js} +8 -7
  35. package/dist/index.d.ts +16 -4
  36. package/dist/index.js +14 -2
  37. package/dist/{iteration-admission.d.ts → iteration/admission.d.ts} +2 -38
  38. package/dist/{iteration.d.ts → iteration/index.d.ts} +8 -98
  39. package/dist/{iteration.js → iteration/index.js} +28 -28
  40. package/dist/{inline.js → iteration/inline.js} +2 -9
  41. package/dist/{iteration-owner.d.ts → iteration/owner.d.ts} +3 -3
  42. package/dist/{iteration-owner.js → iteration/owner.js} +4 -3
  43. package/dist/{iteration-worker.js → iteration/worker.js} +3 -3
  44. package/dist/{managed.d.ts → managed/index.d.ts} +3 -3
  45. package/dist/{managed.js → managed/index.js} +7 -9
  46. package/dist/managed/outbox.d.ts +128 -0
  47. package/dist/managed/outbox.js +156 -0
  48. package/dist/managed/pool.d.ts +221 -0
  49. package/dist/managed/pool.js +310 -0
  50. package/dist/managed/tasks.d.ts +154 -0
  51. package/dist/managed/tasks.js +183 -0
  52. package/dist/{bake.d.ts → memory/bake.d.ts} +12 -6
  53. package/dist/{bake.js → memory/bake.js} +9 -7
  54. package/dist/memory/continuation.d.ts +141 -0
  55. package/dist/memory/continuation.js +495 -0
  56. package/dist/memory/elastic-peer.d.ts +20 -0
  57. package/dist/memory/elastic-peer.js +39 -0
  58. package/dist/memory/elastic-sql.d.ts +11 -0
  59. package/dist/memory/elastic-sql.js +35 -0
  60. package/dist/memory/elastic.d.ts +130 -0
  61. package/dist/memory/elastic.js +475 -0
  62. package/dist/memory/growth-governor.d.ts +16 -0
  63. package/dist/memory/growth-governor.js +42 -0
  64. package/dist/memory/imports.d.ts +10 -0
  65. package/dist/memory/imports.js +89 -0
  66. package/dist/{iteration-layout.d.ts → memory/iteration-layout.d.ts} +1 -1
  67. package/dist/{pages.d.ts → memory/pages.d.ts} +3 -3
  68. package/dist/memory.d.ts +5 -10
  69. package/dist/memory.js +5 -89
  70. package/dist/{context.d.ts → node/context.d.ts} +1 -1
  71. package/dist/{host.d.ts → node/host.d.ts} +1 -1
  72. package/dist/{host.js → node/host.js} +2 -2
  73. package/dist/{node.d.ts → node/index.d.ts} +4 -49
  74. package/dist/{node.js → node/index.js} +16 -17
  75. package/dist/{tasks.d.ts → node/tasks.d.ts} +2 -13
  76. package/dist/{worker.js → node/worker.js} +2 -2
  77. package/dist/{ownership.js → ownership/index.js} +7 -10
  78. package/dist/{ownership-redirect.d.ts → ownership/redirect.d.ts} +2 -2
  79. package/dist/{ownership-redirect.js → ownership/redirect.js} +2 -2
  80. package/dist/{ownership-slices.d.ts → ownership/slices.d.ts} +3 -3
  81. package/dist/{ownership-slices.js → ownership/slices.js} +3 -3
  82. package/dist/{frames.d.ts → remote/frames.d.ts} +1 -1
  83. package/dist/{frames.js → remote/frames.js} +2 -2
  84. package/dist/{remote.d.ts → remote/index.d.ts} +7 -2
  85. package/dist/{remote.js → remote/index.js} +7 -2
  86. package/dist/{router.d.ts → routing/index.d.ts} +3 -3
  87. package/dist/{router.js → routing/index.js} +19 -15
  88. package/dist/{router-worker.js → routing/worker.js} +1 -1
  89. package/dist/{slices.d.ts → slices/index.d.ts} +2 -2
  90. package/dist/{slices.js → slices/index.js} +5 -5
  91. package/dist/slices/worker.d.ts +1 -0
  92. package/dist/{slices-worker.js → slices/worker.js} +2 -2
  93. package/dist/workers.d.ts +5 -0
  94. package/dist/workers.js +5 -0
  95. package/package.json +30 -80
  96. /package/dist/{browser-worker.d.ts → browser/worker.d.ts} +0 -0
  97. /package/dist/{browser-worker.js → browser/worker.js} +0 -0
  98. /package/dist/{fold.js → execution/fold.js} +0 -0
  99. /package/dist/{guards.js → execution/guards.js} +0 -0
  100. /package/dist/{import-order.d.ts → execution/import-order.d.ts} +0 -0
  101. /package/dist/{import-order.js → execution/import-order.js} +0 -0
  102. /package/dist/{runs.d.ts → execution/runs.d.ts} +0 -0
  103. /package/dist/{runs.js → execution/runs.js} +0 -0
  104. /package/dist/{transaction.d.ts → execution/transaction.d.ts} +0 -0
  105. /package/dist/{transaction.js → execution/transaction.js} +0 -0
  106. /package/dist/{iteration-worker.d.ts → execution/types.js} +0 -0
  107. /package/dist/{ranges.d.ts → footprints/ranges.d.ts} +0 -0
  108. /package/dist/{read-scan.d.ts → footprints/read-scan.d.ts} +0 -0
  109. /package/dist/{iteration-admission.js → iteration/admission.js} +0 -0
  110. /package/dist/{inline.d.ts → iteration/inline.d.ts} +0 -0
  111. /package/dist/{worker.d.ts → iteration/worker.d.ts} +0 -0
  112. /package/dist/{iteration-layout.js → memory/iteration-layout.js} +0 -0
  113. /package/dist/{lease.d.ts → memory/lease.d.ts} +0 -0
  114. /package/dist/{lease.js → memory/lease.js} +0 -0
  115. /package/dist/{pages.js → memory/pages.js} +0 -0
  116. /package/dist/{context.js → node/context.js} +0 -0
  117. /package/dist/{tasks.js → node/tasks.js} +0 -0
  118. /package/dist/{router-worker.d.ts → node/worker.d.ts} +0 -0
  119. /package/dist/{ownership.d.ts → ownership/index.d.ts} +0 -0
  120. /package/dist/{values.d.ts → remote/values.d.ts} +0 -0
  121. /package/dist/{values.js → remote/values.js} +0 -0
  122. /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
+ }
@@ -1,4 +1,4 @@
1
- import type { IterationLocal } from './extract.ts';
1
+ import type { IterationLocal } from '../execution/extract.ts';
2
2
  /** Granule sizes of the inline lowering the iteration executor runs. */
3
3
  export declare const iterationGranules: {
4
4
  readonly read: 64;
@@ -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 for
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 apply to retained metadata, resident pages and commit snapshots, not caller-owned copies. */
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 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[];
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
- /** 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
- }
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 './compiler.ts';
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 './node.ts';
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 { Folio } from "./node.js";
2
- import { decodeBytes, decodeValue, encodeBytes, encodeValue } from "./remote.js";
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 './compiler.ts';
2
- import type { IterationReason } from './iteration-owner.ts';
3
- import type { IterationReport, IterationStallOptions } from './iteration.ts';
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
- /** What a run did: results, how it was routed and what the speculation cost. */
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 "./coordinator.js";
5
- import { decideAdmission, decideBatch, decideBound, decideCollapse, decideProof, decideRemaining } from "./iteration-admission.js";
6
- import { iterationArguments, iterationFit, iterationWindowBytes } from "./iteration-layout.js";
7
- import { memoryImports } from "./memory.js";
8
- import { numberBits, restoreNumbers } from "./values.js";
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("./iteration-owner.js");
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
- // Binding accessors are effects too: retain the original engine lookup sequence.
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
- // Resolve bindings when the engine asks for them, in its original order.
308
- // Enumerating/spreading caller namespaces would invoke accessors early or twice.
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
- // JSPI Promise resolution can assimilate an externref Promise result.
385
- // Only explicitly asynchronous entries get that ABI; ordinary exports
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("./compiler.js")).prepare(isUint8Array(input) ? input : new Uint8Array(input), {
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("./iteration.js");
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
- // the host function the owner's loop calls: 1 when every iteration ran, 0 to run the loop itself
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
- // If the original coordinator traps first, pending preceding regions still
948
- // own the earlier effects/trap in program order.
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
- /** Timing and size evidence for one joined task. Timestamps are epoch milliseconds. */
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 "./transaction.js";
3
- import { numberBits, restoreNumbers } from "./values.js";
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 "./extract.js";
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 about symbols live in the cell map and never go stale, because a symbol names one value:
1747
- // y<id> is the interval of the symbol, d<a>|<b> is a bias-shifted upper bound of S_a - S_b, D<id> marks that
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 that every address the real read may name is in the
2647
- // list; V.m gives a multiple, not a remainder, so a table base that is not a multiple of the stride needs a
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
- // where an operator forms a value from two operands of which one is flagged. A record pointer is a base plus
3984
- // the stepped counter and nothing else: its absolute address is the same in a slice. A pointer plus any other
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 './extract.ts';
2
- import { type OwnershipCertificate } from './ownership.ts';
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 "./extract.js";
4
- import { memoryAccesses, verifyOwnership } from "./ownership.js";
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 OwnershipRedirect } from './ownership-redirect.ts';
2
- import { type OwnershipCertificate } from './ownership.ts';
3
- import { type SlicePoolOptions, type SliceReport, type SliceRunOptions } from './slices.ts';
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 { redirectOwnership } from "./ownership-redirect.js";
2
- import { checkConfig, guardRecords } from "./ownership.js";
3
- import { SlicePool } from "./slices.js";
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,4 +1,4 @@
1
- import type { TransactionResult } from './transaction.ts';
1
+ import type { TransactionResult } from '../execution/transaction.ts';
2
2
  /** Lossless page encoding; omitted pages contain only zero bytes. */
3
3
  export interface SnapshotPages {
4
4
  memoryBytes: number;
@@ -1,5 +1,5 @@
1
- import { decodeValue, encodeValue } from "./remote.js";
2
- import { checkRuns, runBytes, runsOfSorted, writeRunsOf } from "./runs.js";
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
- /** Opens a session on a registered artifact; `workers` asks for a group width within host limits. */
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
- /** Resends the exact uncertain request; the host returns its cached result without repeating effects. */
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
- /** Opens a session on a registered artifact; `workers` asks for a group width within host limits. */
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
- /** Resends the exact uncertain request; the host returns its cached result without repeating effects. */
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 './certify.ts';
2
- import { type OwnershipCertificate, type OwnershipOptions, type OwnershipRefusal } from './ownership.ts';
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: `scratchpad/v11/w3/dev/fit-*.jsonl`.
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 */