@gmitch215/folio 1.0.1 → 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 +98 -460
- 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} +55 -8
- package/dist/{extract.d.ts → execution/extract.d.ts} +22 -13
- package/dist/{extract.js → execution/extract.js} +137 -10
- package/dist/execution/fold.d.ts +44 -0
- package/dist/execution/fold.js +105 -0
- package/dist/{guards.d.ts → execution/guards.d.ts} +2 -1
- package/dist/execution/runs.d.ts +44 -0
- package/dist/execution/runs.js +182 -0
- package/dist/{transaction.d.ts → execution/transaction.d.ts} +10 -0
- package/dist/execution/types.d.ts +221 -0
- package/dist/folds/affine-state.d.ts +142 -0
- package/dist/folds/affine-state.js +737 -0
- package/dist/folds/affine.d.ts +148 -0
- package/dist/folds/affine.js +562 -0
- package/dist/folds/boundaries.d.ts +48 -0
- package/dist/folds/boundaries.js +119 -0
- package/dist/folds/certified.d.ts +55 -0
- package/dist/folds/certified.js +178 -0
- package/dist/folds/certify.d.ts +87 -0
- package/dist/folds/certify.js +2611 -0
- package/dist/footprints/memo.d.ts +74 -0
- package/dist/footprints/memo.js +256 -0
- package/dist/footprints/ranges.d.ts +78 -0
- package/dist/footprints/ranges.js +263 -0
- package/dist/footprints/read-scan.d.ts +18 -0
- package/dist/footprints/read-scan.js +94 -0
- package/dist/footprints/read-windows.d.ts +77 -0
- package/dist/footprints/read-windows.js +245 -0
- package/dist/index.d.ts +16 -4
- package/dist/index.js +14 -2
- package/dist/iteration/admission.d.ts +149 -0
- package/dist/iteration/admission.js +201 -0
- package/dist/iteration/index.d.ts +239 -0
- package/dist/iteration/index.js +1210 -0
- package/dist/iteration/inline.d.ts +182 -0
- package/dist/{inline.js → iteration/inline.js} +277 -21
- package/dist/{iteration-owner.d.ts → iteration/owner.d.ts} +16 -3
- package/dist/{iteration-owner.js → iteration/owner.js} +6 -5
- package/dist/iteration/worker.js +216 -0
- package/dist/{managed.d.ts → managed/index.d.ts} +75 -3
- package/dist/managed/index.js +817 -0
- 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} +61 -1
- package/dist/{iteration-layout.js → memory/iteration-layout.js} +54 -3
- package/dist/memory/lease.d.ts +45 -0
- package/dist/memory/lease.js +274 -0
- 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} +17 -3
- package/dist/{context.js → node/context.js} +60 -14
- 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} +46 -49
- package/dist/{node.js → node/index.js} +101 -26
- package/dist/{tasks.d.ts → node/tasks.d.ts} +16 -17
- package/dist/{tasks.js → node/tasks.js} +12 -11
- package/dist/node/worker.d.ts +1 -0
- package/dist/{worker.js → node/worker.js} +2 -2
- package/dist/ownership/index.d.ts +161 -0
- package/dist/ownership/index.js +6565 -0
- package/dist/ownership/redirect.d.ts +30 -0
- package/dist/ownership/redirect.js +179 -0
- package/dist/ownership/slices.d.ts +44 -0
- package/dist/ownership/slices.js +72 -0
- package/dist/{frames.d.ts → remote/frames.d.ts} +6 -2
- package/dist/remote/frames.js +306 -0
- package/dist/{remote.d.ts → remote/index.d.ts} +7 -2
- package/dist/{remote.js → remote/index.js} +7 -2
- package/dist/routing/index.d.ts +203 -0
- package/dist/routing/index.js +671 -0
- package/dist/routing/worker.d.ts +1 -0
- package/dist/routing/worker.js +4 -0
- package/dist/slices/index.d.ts +126 -0
- package/dist/slices/index.js +441 -0
- package/dist/slices/worker.d.ts +1 -0
- package/dist/slices/worker.js +38 -0
- package/dist/workers.d.ts +5 -0
- package/dist/workers.js +5 -0
- package/package.json +32 -46
- package/dist/frames.js +0 -159
- package/dist/inline.d.ts +0 -68
- package/dist/iteration-admission.d.ts +0 -76
- package/dist/iteration-admission.js +0 -72
- package/dist/iteration-worker.js +0 -150
- package/dist/iteration.d.ts +0 -163
- package/dist/iteration.js +0 -435
- package/dist/managed.js +0 -421
- /package/dist/{browser-worker.d.ts → browser/worker.d.ts} +0 -0
- /package/dist/{browser-worker.js → browser/worker.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/{transaction.js → execution/transaction.js} +0 -0
- /package/dist/{iteration-worker.d.ts → execution/types.js} +0 -0
- /package/dist/{worker.d.ts → iteration/worker.d.ts} +0 -0
- /package/dist/{pages.js → memory/pages.js} +0 -0
- /package/dist/{values.d.ts → remote/values.d.ts} +0 -0
- /package/dist/{values.js → remote/values.js} +0 -0
package/dist/boot.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './memory/bake.ts';
|
package/dist/boot.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./memory/bake.js";
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { LoopPlan } from '../execution/compiler.ts';
|
|
2
|
+
import type { NativePlan } from '../execution/guards.ts';
|
|
3
|
+
import type { MemoryImport } from '../memory/imports.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Trusted build-time metadata for a precompiled original module. No compiler runs in the browser.
|
|
6
|
+
*/
|
|
7
|
+
export interface BrowserProgram {
|
|
8
|
+
module: WebAssembly.Module;
|
|
9
|
+
loops: Record<string, LoopPlan>;
|
|
10
|
+
native?: Record<string, NativePlan>;
|
|
11
|
+
/** The unchanged legacy preparation reasons; only an empty list admits worker instantiation. */
|
|
12
|
+
reasons: string[];
|
|
13
|
+
memories?: MemoryImport[];
|
|
14
|
+
}
|
|
15
|
+
/** A dedicated module worker, or an equivalent host-supplied message port. */
|
|
16
|
+
export type BrowserWorkerPort = Pick<Worker, 'postMessage' | 'addEventListener' | 'removeEventListener' | 'terminate'>;
|
|
17
|
+
/** Browser execution configuration. The caller retains exclusive ownership during open and run. */
|
|
18
|
+
export interface BrowserOptions {
|
|
19
|
+
memory?: WebAssembly.Memory;
|
|
20
|
+
imports?: WebAssembly.Imports;
|
|
21
|
+
workers?: number;
|
|
22
|
+
workerURL?: string | URL;
|
|
23
|
+
workerFactory?: (index: number) => BrowserWorkerPort;
|
|
24
|
+
minimumParallelWork?: number;
|
|
25
|
+
}
|
|
26
|
+
/** A whole-entry result. Values stay wrapped so native externref Promise identity holds. */
|
|
27
|
+
export interface BrowserExecutionReport {
|
|
28
|
+
values: unknown[];
|
|
29
|
+
mode: 'serial' | 'native-shared';
|
|
30
|
+
workers: number;
|
|
31
|
+
regions: number;
|
|
32
|
+
reason?: string;
|
|
33
|
+
}
|
|
34
|
+
/** Counted-loop extraction over physically shared memory, without JSPI or runtime compilation. */
|
|
35
|
+
export declare class BrowserFolio {
|
|
36
|
+
#private;
|
|
37
|
+
readonly exports: WebAssembly.Exports;
|
|
38
|
+
readonly memory?: WebAssembly.Memory;
|
|
39
|
+
readonly diagnostics: readonly string[];
|
|
40
|
+
private constructor();
|
|
41
|
+
/**
|
|
42
|
+
* Opens the original instance and attaches only compiler-admitted, initialization-free
|
|
43
|
+
* workers.
|
|
44
|
+
*/
|
|
45
|
+
static open(program: BrowserProgram, options?: BrowserOptions): Promise<BrowserFolio>;
|
|
46
|
+
/** Describes counted-loop coverage; general control-flow extraction stays with the owner. */
|
|
47
|
+
inspect(entry: string): {
|
|
48
|
+
mechanism: "counted-loop";
|
|
49
|
+
loop: boolean;
|
|
50
|
+
nativeGuard: boolean;
|
|
51
|
+
workers: number;
|
|
52
|
+
};
|
|
53
|
+
/** Derives guarded regions from one ordinary call, then joins every lane before returning. */
|
|
54
|
+
run(entry: string, args?: unknown[], options?: {
|
|
55
|
+
parallel?: 'auto' | 'off';
|
|
56
|
+
}): Promise<{
|
|
57
|
+
values: any[];
|
|
58
|
+
mode: "serial";
|
|
59
|
+
workers: number;
|
|
60
|
+
regions: number;
|
|
61
|
+
reason: string;
|
|
62
|
+
} | {
|
|
63
|
+
values: undefined[];
|
|
64
|
+
mode: "native-shared";
|
|
65
|
+
workers: number;
|
|
66
|
+
regions: number;
|
|
67
|
+
reason?: undefined;
|
|
68
|
+
}>;
|
|
69
|
+
/** Joins an active finite call before terminating dedicated workers. */
|
|
70
|
+
close(): Promise<void>;
|
|
71
|
+
/** Joins execution and releases workers for `await using`. */
|
|
72
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
73
|
+
}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/** Counted-loop extraction over physically shared memory, without JSPI or runtime compilation. */
|
|
2
|
+
export class BrowserFolio {
|
|
3
|
+
exports;
|
|
4
|
+
memory;
|
|
5
|
+
diagnostics;
|
|
6
|
+
#program;
|
|
7
|
+
#workers = [];
|
|
8
|
+
#listeners = [];
|
|
9
|
+
#minimumWork;
|
|
10
|
+
#sequence = 0;
|
|
11
|
+
#closed = false;
|
|
12
|
+
#busy = false;
|
|
13
|
+
#failure;
|
|
14
|
+
#active;
|
|
15
|
+
#closing;
|
|
16
|
+
constructor(program, options) {
|
|
17
|
+
this.#program = program;
|
|
18
|
+
this.#minimumWork = options.minimumParallelWork ?? 100_000;
|
|
19
|
+
if (!Number.isFinite(this.#minimumWork) || this.#minimumWork < 0)
|
|
20
|
+
throw new RangeError('minimumParallelWork must be finite and nonnegative');
|
|
21
|
+
this.memory = options.memory;
|
|
22
|
+
const descriptor = program.memories?.length === 1 ? program.memories[0] : undefined;
|
|
23
|
+
const original = options.imports ?? {};
|
|
24
|
+
const imports = descriptor && this.memory
|
|
25
|
+
? new Proxy(original, {
|
|
26
|
+
get: (target, module) => {
|
|
27
|
+
const namespace = Reflect.get(target, module, target);
|
|
28
|
+
if (module !== descriptor.module)
|
|
29
|
+
return namespace;
|
|
30
|
+
return new Proxy(namespace ?? {}, {
|
|
31
|
+
get: (bindings, name) => name === descriptor.name
|
|
32
|
+
? this.memory
|
|
33
|
+
: Reflect.get(bindings, name, bindings)
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
: original;
|
|
38
|
+
this.exports = new WebAssembly.Instance(program.module, imports).exports;
|
|
39
|
+
this.diagnostics = Object.freeze([...program.reasons]);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Opens the original instance and attaches only compiler-admitted, initialization-free
|
|
43
|
+
* workers.
|
|
44
|
+
*/
|
|
45
|
+
static async open(program, options = {}) {
|
|
46
|
+
const width = options.workers ?? 4;
|
|
47
|
+
if (!Number.isInteger(width) || width < 1 || width > 32)
|
|
48
|
+
throw new RangeError('workers must be an integer from 1 through 32');
|
|
49
|
+
const pool = new BrowserFolio(program, options);
|
|
50
|
+
const descriptor = program.memories?.length === 1 ? program.memories[0] : undefined;
|
|
51
|
+
const bindings = WebAssembly.Module.imports(program.module);
|
|
52
|
+
const eligible = width > 1 &&
|
|
53
|
+
program.reasons.length === 0 &&
|
|
54
|
+
Object.keys(program.native ?? {}).some((name) => Object.hasOwn(program.loops, name)) &&
|
|
55
|
+
descriptor?.shared &&
|
|
56
|
+
!descriptor.memory64 &&
|
|
57
|
+
bindings.length === 1 &&
|
|
58
|
+
bindings[0].kind === 'memory' &&
|
|
59
|
+
bindings[0].module === descriptor.module &&
|
|
60
|
+
bindings[0].name === descriptor.name &&
|
|
61
|
+
pool.memory &&
|
|
62
|
+
typeof SharedArrayBuffer !== 'undefined' &&
|
|
63
|
+
pool.memory.buffer.byteLength >= 4 &&
|
|
64
|
+
pool.memory.buffer instanceof SharedArrayBuffer;
|
|
65
|
+
if (!eligible)
|
|
66
|
+
return pool;
|
|
67
|
+
const memory = pool.memory;
|
|
68
|
+
const words = new Int32Array(memory.buffer);
|
|
69
|
+
const saved = Atomics.load(words, 0);
|
|
70
|
+
try {
|
|
71
|
+
for (let index = 0; index < width; index++) {
|
|
72
|
+
const worker = options.workerFactory
|
|
73
|
+
? options.workerFactory(index)
|
|
74
|
+
: new Worker(options.workerURL ?? new URL('./worker.js', import.meta.url), {
|
|
75
|
+
type: 'module'
|
|
76
|
+
});
|
|
77
|
+
pool.#workers.push(worker);
|
|
78
|
+
const fail = () => {
|
|
79
|
+
pool.#failure ??= new Error('browser worker failed; shared arena requires checkpoint recovery');
|
|
80
|
+
};
|
|
81
|
+
worker.addEventListener('error', fail);
|
|
82
|
+
worker.addEventListener('messageerror', fail);
|
|
83
|
+
pool.#listeners.push(() => {
|
|
84
|
+
worker.removeEventListener('error', fail);
|
|
85
|
+
worker.removeEventListener('messageerror', fail);
|
|
86
|
+
});
|
|
87
|
+
const before = (0x46100000 + index) | 0;
|
|
88
|
+
const after = (before ^ 0x00ffffff) | 0;
|
|
89
|
+
Atomics.store(words, 0, before);
|
|
90
|
+
const result = await pool.#request(worker, {
|
|
91
|
+
action: 'attach',
|
|
92
|
+
module: program.module,
|
|
93
|
+
memory,
|
|
94
|
+
importModule: descriptor.module,
|
|
95
|
+
importName: descriptor.name,
|
|
96
|
+
before,
|
|
97
|
+
after
|
|
98
|
+
});
|
|
99
|
+
if (result !== before || Atomics.load(words, 0) !== after)
|
|
100
|
+
throw new Error('browser worker shared-memory alias handshake failed');
|
|
101
|
+
}
|
|
102
|
+
return pool;
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
pool.#terminate();
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
finally {
|
|
109
|
+
Atomics.store(words, 0, saved);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/** Describes counted-loop coverage; general control-flow extraction stays with the owner. */
|
|
113
|
+
inspect(entry) {
|
|
114
|
+
return {
|
|
115
|
+
mechanism: 'counted-loop',
|
|
116
|
+
loop: Object.hasOwn(this.#program.loops, entry),
|
|
117
|
+
nativeGuard: Object.hasOwn(this.#program.native ?? {}, entry),
|
|
118
|
+
workers: this.#workers.length
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
#request(worker, message) {
|
|
122
|
+
const sequence = ++this.#sequence;
|
|
123
|
+
return new Promise((resolve, reject) => {
|
|
124
|
+
const cleanup = () => {
|
|
125
|
+
worker.removeEventListener('message', done);
|
|
126
|
+
worker.removeEventListener('error', fail);
|
|
127
|
+
worker.removeEventListener('messageerror', fail);
|
|
128
|
+
};
|
|
129
|
+
const fail = (event) => {
|
|
130
|
+
cleanup();
|
|
131
|
+
reject(new Error(event.message || 'browser worker failed'));
|
|
132
|
+
};
|
|
133
|
+
const done = (event) => {
|
|
134
|
+
if (event.data?.sequence !== sequence)
|
|
135
|
+
return;
|
|
136
|
+
cleanup();
|
|
137
|
+
if (event.data.error)
|
|
138
|
+
reject(new Error(event.data.error));
|
|
139
|
+
else
|
|
140
|
+
resolve(event.data.value);
|
|
141
|
+
};
|
|
142
|
+
worker.addEventListener('message', done);
|
|
143
|
+
worker.addEventListener('error', fail);
|
|
144
|
+
worker.addEventListener('messageerror', fail);
|
|
145
|
+
try {
|
|
146
|
+
worker.postMessage({ ...message, sequence });
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
cleanup();
|
|
150
|
+
reject(error);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
#disjoint(calls, proved, plan) {
|
|
155
|
+
const footprints = calls.map((call) => proved.accesses.map((access) => {
|
|
156
|
+
const first = Number(call.args[access.parameter]) >>> 0;
|
|
157
|
+
const count = Number(call.args[plan.countParameter]) >>> 0;
|
|
158
|
+
const step = plan.steps.find((item) => item.parameter === access.parameter)?.step ?? 0;
|
|
159
|
+
const last = first + (count - 1) * step;
|
|
160
|
+
return {
|
|
161
|
+
start: Math.min(first, last) + access.offset,
|
|
162
|
+
end: Math.max(first, last) + access.offset + access.bytes,
|
|
163
|
+
write: access.write,
|
|
164
|
+
wrap: last < 0 || last > 0xffffffff
|
|
165
|
+
};
|
|
166
|
+
}));
|
|
167
|
+
for (let index = 0; index < footprints.length; index++) {
|
|
168
|
+
for (const range of footprints[index]) {
|
|
169
|
+
if (range.wrap || range.start < 0 || range.end > this.memory.buffer.byteLength)
|
|
170
|
+
return false;
|
|
171
|
+
for (const other of footprints.slice(0, index).flat())
|
|
172
|
+
if ((range.write || other.write) &&
|
|
173
|
+
range.start < other.end &&
|
|
174
|
+
other.start < range.end)
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
/** Derives guarded regions from one ordinary call, then joins every lane before returning. */
|
|
181
|
+
run(entry, args = [], options = {}) {
|
|
182
|
+
if (this.#closed)
|
|
183
|
+
return Promise.reject(new Error('folio is closed'));
|
|
184
|
+
if (this.#failure)
|
|
185
|
+
return Promise.reject(this.#failure);
|
|
186
|
+
if (this.#busy)
|
|
187
|
+
return Promise.reject(new Error('memory already has an active run'));
|
|
188
|
+
this.#busy = true;
|
|
189
|
+
const running = this.#run(entry, args, options);
|
|
190
|
+
this.#active = running;
|
|
191
|
+
running
|
|
192
|
+
.finally(() => {
|
|
193
|
+
this.#busy = false;
|
|
194
|
+
if (this.#active === running)
|
|
195
|
+
this.#active = undefined;
|
|
196
|
+
})
|
|
197
|
+
.catch(() => { });
|
|
198
|
+
return running;
|
|
199
|
+
}
|
|
200
|
+
async #run(entry, args, options) {
|
|
201
|
+
const plan = Object.hasOwn(this.#program.loops, entry)
|
|
202
|
+
? this.#program.loops[entry]
|
|
203
|
+
: undefined;
|
|
204
|
+
const proved = Object.hasOwn(this.#program.native ?? {}, entry)
|
|
205
|
+
? this.#program.native[entry]
|
|
206
|
+
: undefined;
|
|
207
|
+
const numeric = args.every((arg) => typeof arg === 'number');
|
|
208
|
+
const count = plan && numeric ? Number(args[plan.countParameter]) >>> 0 : 0;
|
|
209
|
+
const work = numeric
|
|
210
|
+
? proved?.workParameters.reduce((value, parameter) => value * (Number(args[parameter]) >>> 0), count)
|
|
211
|
+
: undefined;
|
|
212
|
+
let reason = options.parallel === 'off'
|
|
213
|
+
? 'requested'
|
|
214
|
+
: !numeric
|
|
215
|
+
? 'opaque-input'
|
|
216
|
+
: !plan || !proved || this.#workers.length < 2
|
|
217
|
+
? 'no-parallel-plan'
|
|
218
|
+
: count < 2
|
|
219
|
+
? 'single-region'
|
|
220
|
+
: work !== undefined && work < this.#minimumWork
|
|
221
|
+
? 'small-workload'
|
|
222
|
+
: undefined;
|
|
223
|
+
const calls = [];
|
|
224
|
+
if (!reason && plan && proved) {
|
|
225
|
+
const regions = Math.min(count, this.#workers.length);
|
|
226
|
+
let begin = 0;
|
|
227
|
+
for (let index = 0; index < regions; index++) {
|
|
228
|
+
const end = Math.floor(((index + 1) * count) / regions);
|
|
229
|
+
const parameters = [...args];
|
|
230
|
+
parameters[plan.countParameter] = end - begin;
|
|
231
|
+
for (const { parameter, step } of plan.steps)
|
|
232
|
+
parameters[parameter] =
|
|
233
|
+
((Number(args[parameter]) | 0) + Math.imul(begin, step)) | 0;
|
|
234
|
+
calls.push({ export: entry, args: parameters });
|
|
235
|
+
begin = end;
|
|
236
|
+
}
|
|
237
|
+
if (!this.#disjoint(calls, proved, plan))
|
|
238
|
+
reason = 'guard-failed';
|
|
239
|
+
}
|
|
240
|
+
if (reason) {
|
|
241
|
+
const value = this.exports[entry](...args);
|
|
242
|
+
return { values: [value], mode: 'serial', workers: 0, regions: 1, reason };
|
|
243
|
+
}
|
|
244
|
+
const outcomes = await Promise.allSettled(calls.map((call, index) => this.#request(this.#workers[index], { action: 'run', call })));
|
|
245
|
+
if (outcomes.some((outcome) => outcome.status === 'rejected')) {
|
|
246
|
+
this.#failure = new Error('native region failed; shared arena requires checkpoint recovery');
|
|
247
|
+
this.#terminate();
|
|
248
|
+
throw this.#failure;
|
|
249
|
+
}
|
|
250
|
+
return {
|
|
251
|
+
values: [undefined],
|
|
252
|
+
mode: 'native-shared',
|
|
253
|
+
workers: calls.length,
|
|
254
|
+
regions: calls.length
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
#terminate() {
|
|
258
|
+
for (const detach of this.#listeners)
|
|
259
|
+
detach();
|
|
260
|
+
this.#listeners.length = 0;
|
|
261
|
+
for (const worker of this.#workers)
|
|
262
|
+
worker.terminate();
|
|
263
|
+
this.#workers.length = 0;
|
|
264
|
+
}
|
|
265
|
+
/** Joins an active finite call before terminating dedicated workers. */
|
|
266
|
+
close() {
|
|
267
|
+
this.#closed = true;
|
|
268
|
+
return (this.#closing ??= (async () => {
|
|
269
|
+
await this.#active?.catch(() => { });
|
|
270
|
+
this.#terminate();
|
|
271
|
+
})());
|
|
272
|
+
}
|
|
273
|
+
/** Joins execution and releases workers for `await using`. */
|
|
274
|
+
[Symbol.asyncDispose]() {
|
|
275
|
+
return this.close();
|
|
276
|
+
}
|
|
277
|
+
}
|
package/dist/browser.d.ts
CHANGED
|
@@ -1,68 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { NativePlan } from './guards.ts';
|
|
3
|
-
import type { MemoryImport } from './memory.ts';
|
|
4
|
-
/** Trusted build-time metadata for a precompiled original module. No compiler runs in the browser. */
|
|
5
|
-
export interface BrowserProgram {
|
|
6
|
-
module: WebAssembly.Module;
|
|
7
|
-
loops: Record<string, LoopPlan>;
|
|
8
|
-
native?: Record<string, NativePlan>;
|
|
9
|
-
/** The unchanged legacy preparation reasons; only an empty list admits worker instantiation. */
|
|
10
|
-
reasons: string[];
|
|
11
|
-
memories?: MemoryImport[];
|
|
12
|
-
}
|
|
13
|
-
/** A dedicated module worker, or an equivalent host-supplied message port. */
|
|
14
|
-
export type BrowserWorkerPort = Pick<Worker, 'postMessage' | 'addEventListener' | 'removeEventListener' | 'terminate'>;
|
|
15
|
-
/** Browser execution configuration. The caller retains exclusive ownership during open and run. */
|
|
16
|
-
export interface BrowserOptions {
|
|
17
|
-
memory?: WebAssembly.Memory;
|
|
18
|
-
imports?: WebAssembly.Imports;
|
|
19
|
-
workers?: number;
|
|
20
|
-
workerURL?: string | URL;
|
|
21
|
-
workerFactory?: (index: number) => BrowserWorkerPort;
|
|
22
|
-
minimumParallelWork?: number;
|
|
23
|
-
}
|
|
24
|
-
/** A whole-entry result. Values remain wrapped so native externref Promise identity is preserved. */
|
|
25
|
-
export interface BrowserExecutionReport {
|
|
26
|
-
values: unknown[];
|
|
27
|
-
mode: 'serial' | 'native-shared';
|
|
28
|
-
workers: number;
|
|
29
|
-
regions: number;
|
|
30
|
-
reason?: string;
|
|
31
|
-
}
|
|
32
|
-
/** Counted-loop extraction over physically shared memory, without JSPI or runtime compilation. */
|
|
33
|
-
export declare class BrowserFolio {
|
|
34
|
-
#private;
|
|
35
|
-
readonly exports: WebAssembly.Exports;
|
|
36
|
-
readonly memory?: WebAssembly.Memory;
|
|
37
|
-
readonly diagnostics: readonly string[];
|
|
38
|
-
private constructor();
|
|
39
|
-
/** Opens the original instance and attaches only compiler-admitted, initialization-free workers. */
|
|
40
|
-
static open(program: BrowserProgram, options?: BrowserOptions): Promise<BrowserFolio>;
|
|
41
|
-
/** Describes counted-loop coverage; generalized control-flow extraction remains at the owner. */
|
|
42
|
-
inspect(entry: string): {
|
|
43
|
-
mechanism: "counted-loop";
|
|
44
|
-
loop: boolean;
|
|
45
|
-
nativeGuard: boolean;
|
|
46
|
-
workers: number;
|
|
47
|
-
};
|
|
48
|
-
/** Derives guarded regions from one ordinary call, then joins every lane before returning. */
|
|
49
|
-
run(entry: string, args?: unknown[], options?: {
|
|
50
|
-
parallel?: 'auto' | 'off';
|
|
51
|
-
}): Promise<{
|
|
52
|
-
values: any[];
|
|
53
|
-
mode: "serial";
|
|
54
|
-
workers: number;
|
|
55
|
-
regions: number;
|
|
56
|
-
reason: string;
|
|
57
|
-
} | {
|
|
58
|
-
values: undefined[];
|
|
59
|
-
mode: "native-shared";
|
|
60
|
-
workers: number;
|
|
61
|
-
regions: number;
|
|
62
|
-
reason?: undefined;
|
|
63
|
-
}>;
|
|
64
|
-
/** Joins an active finite call before terminating dedicated workers. */
|
|
65
|
-
close(): Promise<void>;
|
|
66
|
-
/** Joins execution and releases workers for `await using`. */
|
|
67
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
68
|
-
}
|
|
1
|
+
export * from './browser/index.ts';
|