@gmitch215/folio 0.0.0-stage → 1.0.1
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/LICENSE +21 -0
- package/README.md +541 -2
- package/dist/bake.d.ts +179 -0
- package/dist/bake.js +704 -0
- package/dist/browser-worker.d.ts +9 -0
- package/dist/browser-worker.js +37 -0
- package/dist/browser.d.ts +68 -0
- package/dist/browser.js +274 -0
- package/dist/compiler.d.ts +79 -0
- package/dist/compiler.js +620 -0
- package/dist/context.d.ts +33 -0
- package/dist/context.js +93 -0
- package/dist/coordinator.d.ts +27 -0
- package/dist/coordinator.js +191 -0
- package/dist/extract.d.ts +165 -0
- package/dist/extract.js +1817 -0
- package/dist/frames.d.ts +33 -0
- package/dist/frames.js +159 -0
- package/dist/guards.d.ts +12 -0
- package/dist/guards.js +202 -0
- package/dist/host.d.ts +60 -0
- package/dist/host.js +374 -0
- package/dist/import-order.d.ts +2 -0
- package/dist/import-order.js +114 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2 -0
- package/dist/inline.d.ts +68 -0
- package/dist/inline.js +503 -0
- package/dist/iteration-admission.d.ts +76 -0
- package/dist/iteration-admission.js +72 -0
- package/dist/iteration-layout.d.ts +75 -0
- package/dist/iteration-layout.js +118 -0
- package/dist/iteration-owner.d.ts +32 -0
- package/dist/iteration-owner.js +223 -0
- package/dist/iteration-worker.d.ts +1 -0
- package/dist/iteration-worker.js +150 -0
- package/dist/iteration.d.ts +163 -0
- package/dist/iteration.js +435 -0
- package/dist/managed.d.ts +92 -0
- package/dist/managed.js +421 -0
- package/dist/memory.d.ts +10 -0
- package/dist/memory.js +89 -0
- package/dist/node.d.ts +138 -0
- package/dist/node.js +1153 -0
- package/dist/pages.d.ts +109 -0
- package/dist/pages.js +339 -0
- package/dist/remote.d.ts +86 -0
- package/dist/remote.js +255 -0
- package/dist/tasks.d.ts +107 -0
- package/dist/tasks.js +330 -0
- package/dist/transaction.d.ts +23 -0
- package/dist/transaction.js +93 -0
- package/dist/values.d.ts +3 -0
- package/dist/values.js +25 -0
- package/dist/worker.d.ts +1 -0
- package/dist/worker.js +86 -0
- package/package.json +130 -5
package/dist/context.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
/** A changed memory or table size requires a newly instantiated context. */
|
|
3
|
+
export class ContextResetError extends Error {
|
|
4
|
+
/** Which binding changed size. */
|
|
5
|
+
kind;
|
|
6
|
+
constructor(kind) {
|
|
7
|
+
super(`context ${kind} changed; instantiate and initialize a new context`);
|
|
8
|
+
this.name = 'ContextResetError';
|
|
9
|
+
this.kind = kind;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Captures private Wasm state after initialization. `prepareContext` exposes hidden bindings.
|
|
14
|
+
* Each restore checks current bytes, so different inputs may dirty different pages. Callers own
|
|
15
|
+
* exclusive access and reset host resources and objects behind externref values separately.
|
|
16
|
+
* Memory/table growth requires recreation because Wasm cannot shrink those bindings.
|
|
17
|
+
* @since 1.0.1
|
|
18
|
+
*/
|
|
19
|
+
export class InstanceCheckpoint {
|
|
20
|
+
#memories;
|
|
21
|
+
#globals;
|
|
22
|
+
#tables;
|
|
23
|
+
constructor(instance, plan) {
|
|
24
|
+
if (plan.reasons.length)
|
|
25
|
+
throw new TypeError(`context requires recreation: ${plan.reasons.join('; ')}`);
|
|
26
|
+
this.#memories = plan.memories.map((name) => {
|
|
27
|
+
const memory = instance.exports[name];
|
|
28
|
+
if (!(memory instanceof WebAssembly.Memory))
|
|
29
|
+
throw new TypeError(`missing context memory ${name}`);
|
|
30
|
+
return { memory, bytes: Uint8Array.from(new Uint8Array(memory.buffer)) };
|
|
31
|
+
});
|
|
32
|
+
this.#globals = plan.globals.map((name) => {
|
|
33
|
+
const global = instance.exports[name];
|
|
34
|
+
if (!(global instanceof WebAssembly.Global))
|
|
35
|
+
throw new TypeError(`missing context global ${name}`);
|
|
36
|
+
return { global, value: global.value };
|
|
37
|
+
});
|
|
38
|
+
this.#tables = plan.tables.map((name) => {
|
|
39
|
+
const table = instance.exports[name];
|
|
40
|
+
if (!(table instanceof WebAssembly.Table))
|
|
41
|
+
throw new TypeError(`missing context table ${name}`);
|
|
42
|
+
return {
|
|
43
|
+
table,
|
|
44
|
+
slots: Array.from({ length: table.length }, (_, index) => table.get(index))
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/** Restores all mutable bindings. `full` skips page comparison and copies every memory byte. */
|
|
49
|
+
restore(strategy = 'changed') {
|
|
50
|
+
if (strategy !== 'changed' && strategy !== 'full')
|
|
51
|
+
throw new TypeError('invalid context reset strategy');
|
|
52
|
+
for (const { memory, bytes } of this.#memories)
|
|
53
|
+
if (memory.buffer.byteLength !== bytes.length)
|
|
54
|
+
throw new ContextResetError('memory-size');
|
|
55
|
+
for (const { table, slots } of this.#tables)
|
|
56
|
+
if (table.length !== slots.length)
|
|
57
|
+
throw new ContextResetError('table-size');
|
|
58
|
+
const report = {
|
|
59
|
+
checkedBytes: 0,
|
|
60
|
+
copiedBytes: 0,
|
|
61
|
+
changedPages: 0,
|
|
62
|
+
globals: 0,
|
|
63
|
+
tableSlots: 0
|
|
64
|
+
};
|
|
65
|
+
for (const { memory, bytes } of this.#memories) {
|
|
66
|
+
const target = new Uint8Array(memory.buffer);
|
|
67
|
+
for (let offset = 0; offset < bytes.length; offset += 65536) {
|
|
68
|
+
const source = bytes.subarray(offset, offset + 65536), current = target.subarray(offset, offset + 65536);
|
|
69
|
+
if (strategy === 'changed')
|
|
70
|
+
report.checkedBytes += current.length;
|
|
71
|
+
if (strategy === 'full' ||
|
|
72
|
+
!Buffer.from(current.buffer, current.byteOffset, current.length).equals(Buffer.from(source.buffer, source.byteOffset, source.length))) {
|
|
73
|
+
current.set(source);
|
|
74
|
+
report.copiedBytes += current.length;
|
|
75
|
+
report.changedPages++;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
for (const { global, value } of this.#globals) {
|
|
80
|
+
if (!Object.is(global.value, value)) {
|
|
81
|
+
global.value = value;
|
|
82
|
+
report.globals++;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
for (const { table, slots } of this.#tables)
|
|
86
|
+
for (let index = 0; index < slots.length; index++)
|
|
87
|
+
if (!Object.is(table.get(index), slots[index])) {
|
|
88
|
+
table.set(index, slots[index]);
|
|
89
|
+
report.tableSlots++;
|
|
90
|
+
}
|
|
91
|
+
return report;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ExecutionReport } from './node.ts';
|
|
2
|
+
import type { TransactionResult } from './transaction.ts';
|
|
3
|
+
export interface RegionCall {
|
|
4
|
+
export: string;
|
|
5
|
+
args: readonly (number | bigint)[];
|
|
6
|
+
}
|
|
7
|
+
/** Owns only effect-free regions. The original Wasm stack remains the coordinator. */
|
|
8
|
+
export declare class Coordinator {
|
|
9
|
+
#private;
|
|
10
|
+
readonly report: ExecutionReport;
|
|
11
|
+
constructor(options: {
|
|
12
|
+
memory: WebAssembly.Memory;
|
|
13
|
+
workerMemory: WebAssembly.Memory;
|
|
14
|
+
width: number;
|
|
15
|
+
profile: boolean;
|
|
16
|
+
/** Wasm global the generated barriers read; raised while regions are queued or running. */
|
|
17
|
+
pending?: {
|
|
18
|
+
value: unknown;
|
|
19
|
+
};
|
|
20
|
+
dispatch: (worker: number, calls: RegionCall[], generation: number) => Promise<TransactionResult[]>;
|
|
21
|
+
native: (call: RegionCall) => void;
|
|
22
|
+
});
|
|
23
|
+
enqueue(call: RegionCall): Promise<void> | undefined;
|
|
24
|
+
/** Bounded polling also joins an earlier trapping region before an infinite loop. */
|
|
25
|
+
poll(): Promise<void> | undefined;
|
|
26
|
+
flush(): Promise<void> | undefined;
|
|
27
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
function trap(result) {
|
|
2
|
+
if (!result.trap)
|
|
3
|
+
return;
|
|
4
|
+
if (result.errorKind === 'TypeError')
|
|
5
|
+
throw new TypeError(result.trap);
|
|
6
|
+
if (result.errorKind === 'RangeError')
|
|
7
|
+
throw new RangeError(result.trap);
|
|
8
|
+
throw new WebAssembly.RuntimeError(result.trap);
|
|
9
|
+
}
|
|
10
|
+
/** Owns only effect-free regions. The original Wasm stack remains the coordinator. */
|
|
11
|
+
export class Coordinator {
|
|
12
|
+
report;
|
|
13
|
+
#queue = [];
|
|
14
|
+
#memory;
|
|
15
|
+
#workerMemory;
|
|
16
|
+
#width;
|
|
17
|
+
#dispatch;
|
|
18
|
+
#native;
|
|
19
|
+
#profile;
|
|
20
|
+
#pending;
|
|
21
|
+
#armed = false;
|
|
22
|
+
#polls = 0;
|
|
23
|
+
#generation = 0;
|
|
24
|
+
#flushing;
|
|
25
|
+
constructor(options) {
|
|
26
|
+
this.#pending = options.pending;
|
|
27
|
+
this.#memory = options.memory;
|
|
28
|
+
this.#workerMemory = options.workerMemory;
|
|
29
|
+
this.#width = options.width;
|
|
30
|
+
this.#dispatch = options.dispatch;
|
|
31
|
+
this.#native = options.native;
|
|
32
|
+
this.#profile = options.profile
|
|
33
|
+
? {
|
|
34
|
+
wallMs: 0,
|
|
35
|
+
workerWallMs: [],
|
|
36
|
+
workerCpuMs: [],
|
|
37
|
+
validationMs: 0,
|
|
38
|
+
commitMs: 0,
|
|
39
|
+
replayMs: 0,
|
|
40
|
+
readBytes: 0,
|
|
41
|
+
writeBytes: 0
|
|
42
|
+
}
|
|
43
|
+
: undefined;
|
|
44
|
+
this.report = {
|
|
45
|
+
values: [],
|
|
46
|
+
workers: 0,
|
|
47
|
+
regions: 0,
|
|
48
|
+
replayed: 0,
|
|
49
|
+
fallbacks: 0,
|
|
50
|
+
mode: 'serial',
|
|
51
|
+
extraction: 'control-flow',
|
|
52
|
+
memoryMode: this.#memory === this.#workerMemory ? 'shared' : 'snapshot',
|
|
53
|
+
snapshotBytes: 0,
|
|
54
|
+
...(this.#profile ? { profile: this.#profile } : {})
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
enqueue(call) {
|
|
58
|
+
if (!this.#armed) {
|
|
59
|
+
this.#armed = true;
|
|
60
|
+
if (this.#pending)
|
|
61
|
+
this.#pending.value = 1;
|
|
62
|
+
}
|
|
63
|
+
this.#queue.push(call);
|
|
64
|
+
this.report.regions++;
|
|
65
|
+
// Amortize transport/join cost without changing per-region validation order.
|
|
66
|
+
return this.#queue.length >= this.#width * 16 ? this.flush() : undefined;
|
|
67
|
+
}
|
|
68
|
+
/** Bounded polling also joins an earlier trapping region before an infinite loop. */
|
|
69
|
+
poll() {
|
|
70
|
+
if (++this.#polls < 1024)
|
|
71
|
+
return undefined;
|
|
72
|
+
this.#polls = 0;
|
|
73
|
+
return this.flush();
|
|
74
|
+
}
|
|
75
|
+
flush() {
|
|
76
|
+
if (this.#flushing)
|
|
77
|
+
return this.#flushing;
|
|
78
|
+
if (!this.#queue.length) {
|
|
79
|
+
this.#settle();
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
const batch = this.#queue.splice(0);
|
|
83
|
+
const pending = this.#execute(batch);
|
|
84
|
+
this.#flushing = pending;
|
|
85
|
+
return pending.finally(() => {
|
|
86
|
+
this.#flushing = undefined;
|
|
87
|
+
this.#settle();
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
#settle() {
|
|
91
|
+
if (!this.#armed || this.#queue.length)
|
|
92
|
+
return;
|
|
93
|
+
this.#armed = false;
|
|
94
|
+
if (this.#pending)
|
|
95
|
+
this.#pending.value = 0;
|
|
96
|
+
}
|
|
97
|
+
async #execute(batch) {
|
|
98
|
+
if (batch.length === 1) {
|
|
99
|
+
// An observation boundary left no independent companion. Keep the work
|
|
100
|
+
// at its original owner; IPC and a full ordinary-memory snapshot buy nothing.
|
|
101
|
+
if (this.report.mode === 'serial')
|
|
102
|
+
this.report.reason = 'single-region';
|
|
103
|
+
this.#native(batch[0]);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (this.report.reason === 'single-region')
|
|
107
|
+
delete this.report.reason;
|
|
108
|
+
if (this.#memory !== this.#workerMemory) {
|
|
109
|
+
try {
|
|
110
|
+
const pages = this.#memory.buffer.byteLength / 65536;
|
|
111
|
+
const current = this.#workerMemory.buffer.byteLength / 65536;
|
|
112
|
+
if (pages > current)
|
|
113
|
+
this.#workerMemory.grow(pages - current);
|
|
114
|
+
new Uint8Array(this.#workerMemory.buffer).set(new Uint8Array(this.#memory.buffer));
|
|
115
|
+
this.report.snapshotBytes += this.#memory.buffer.byteLength;
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
if (!(error instanceof RangeError))
|
|
119
|
+
throw error;
|
|
120
|
+
// A failed optimization allocation must not introduce a program trap.
|
|
121
|
+
this.report.fallbacks++;
|
|
122
|
+
for (const call of batch)
|
|
123
|
+
this.#native(call);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
this.report.mode = 'speculative';
|
|
128
|
+
const width = Math.min(this.#width, batch.length);
|
|
129
|
+
this.report.workers = Math.max(this.report.workers, width);
|
|
130
|
+
const lanes = Array.from({ length: width }, (_, lane) => batch.filter((_, index) => index % width === lane));
|
|
131
|
+
const generation = ++this.#generation;
|
|
132
|
+
const outcomes = await Promise.allSettled(lanes.map((calls, i) => this.#dispatch(i, calls, generation)));
|
|
133
|
+
const failure = outcomes.find((outcome) => outcome.status === 'rejected');
|
|
134
|
+
if (failure?.status === 'rejected')
|
|
135
|
+
throw failure.reason;
|
|
136
|
+
const dirty = new Set();
|
|
137
|
+
const canonical = new Uint8Array(this.#memory.buffer);
|
|
138
|
+
const shared = new Uint8Array(this.#workerMemory.buffer);
|
|
139
|
+
const observe = (result) => {
|
|
140
|
+
if (!this.#profile)
|
|
141
|
+
return;
|
|
142
|
+
this.#profile.workerWallMs.push(result.timing.wallMs);
|
|
143
|
+
this.#profile.workerCpuMs.push(result.timing.cpuMs);
|
|
144
|
+
this.#profile.readBytes += result.reads.length;
|
|
145
|
+
this.#profile.writeBytes += result.writes.length;
|
|
146
|
+
};
|
|
147
|
+
const commit = (result) => {
|
|
148
|
+
const start = this.#profile ? performance.now() : 0;
|
|
149
|
+
for (const [address, value] of result.writes) {
|
|
150
|
+
canonical[address] = value;
|
|
151
|
+
if (this.#memory !== this.#workerMemory)
|
|
152
|
+
shared[address] = value;
|
|
153
|
+
dirty.add(address);
|
|
154
|
+
}
|
|
155
|
+
if (this.#profile)
|
|
156
|
+
this.#profile.commitMs += performance.now() - start;
|
|
157
|
+
};
|
|
158
|
+
for (let i = 0; i < batch.length; i++) {
|
|
159
|
+
const outcome = outcomes[i % width];
|
|
160
|
+
let result = outcome.value[Math.floor(i / width)];
|
|
161
|
+
observe(result);
|
|
162
|
+
const start = this.#profile ? performance.now() : 0;
|
|
163
|
+
const conflict = result.reads.some((address) => dirty.has(address));
|
|
164
|
+
if (this.#profile)
|
|
165
|
+
this.#profile.validationMs += performance.now() - start;
|
|
166
|
+
if (result.exhausted || conflict) {
|
|
167
|
+
if (result.exhausted)
|
|
168
|
+
this.report.fallbacks++;
|
|
169
|
+
else {
|
|
170
|
+
this.report.replayed++;
|
|
171
|
+
this.report.reason = 'dependency';
|
|
172
|
+
}
|
|
173
|
+
if (!result.exhausted) {
|
|
174
|
+
const replayStart = this.#profile ? performance.now() : 0;
|
|
175
|
+
result = (await this.#dispatch(0, [batch[i]], ++this.#generation))[0];
|
|
176
|
+
observe(result);
|
|
177
|
+
if (this.#profile)
|
|
178
|
+
this.#profile.replayMs += performance.now() - replayStart;
|
|
179
|
+
}
|
|
180
|
+
if (result.exhausted) {
|
|
181
|
+
// Unknown native write footprints invalidate every later speculative result.
|
|
182
|
+
for (let rest = i; rest < batch.length; rest++)
|
|
183
|
+
this.#native(batch[rest]);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
commit(result);
|
|
188
|
+
trap(result);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/** Region admission. Both values are estimates in instruction units, not guarantees. */
|
|
2
|
+
export interface AdmissionOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Net work a region needs before dispatch, join and validation can pay for themselves; 0 admits
|
|
5
|
+
* every pure region. A loop bounded by a parameter is checked against the call's arguments.
|
|
6
|
+
*/
|
|
7
|
+
minimumRegionWork?: number;
|
|
8
|
+
/** Iterations assumed for a loop whose bound is neither a constant nor a parameter. */
|
|
9
|
+
assumedTripCount?: number;
|
|
10
|
+
}
|
|
11
|
+
/** Calibrated on Apple M2 Pro; see `results/execution/admission/admission-calibration.summary.json`. */
|
|
12
|
+
export declare const DEFAULT_MINIMUM_REGION_WORK = 200000;
|
|
13
|
+
export declare const DEFAULT_ASSUMED_TRIP_COUNT = 1000;
|
|
14
|
+
export interface ControlPlan {
|
|
15
|
+
coordinator: Uint8Array;
|
|
16
|
+
workerOriginal: Uint8Array;
|
|
17
|
+
transactional: Uint8Array;
|
|
18
|
+
namespace: string;
|
|
19
|
+
serialGlobal: string;
|
|
20
|
+
pendingGlobal: string;
|
|
21
|
+
memoryExport: string;
|
|
22
|
+
shared: boolean;
|
|
23
|
+
initial: number;
|
|
24
|
+
maximum: number;
|
|
25
|
+
entries: string[];
|
|
26
|
+
regions: {
|
|
27
|
+
importName: string;
|
|
28
|
+
exportName: string;
|
|
29
|
+
parameters: ('i32' | 'i64')[];
|
|
30
|
+
}[];
|
|
31
|
+
diagnostics: string[];
|
|
32
|
+
}
|
|
33
|
+
export interface Work {
|
|
34
|
+
compute: number;
|
|
35
|
+
accesses: number;
|
|
36
|
+
}
|
|
37
|
+
/** Work that grows with the product of the listed parameters, each bounding a loop. */
|
|
38
|
+
export interface Term extends Work {
|
|
39
|
+
params: number[];
|
|
40
|
+
}
|
|
41
|
+
/** Which locals feed a loop bound untouched, and which are written and so can count. */
|
|
42
|
+
export interface LoopInputs {
|
|
43
|
+
input(index: number): boolean;
|
|
44
|
+
counter(index: number): boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Trip-weighted instruction and tracked-access counts of one body, calls included. A loop bounded
|
|
48
|
+
* by an untouched input makes a term in that local; other unknown bounds use `assumedTrips`.
|
|
49
|
+
*/
|
|
50
|
+
export declare function estimateTerms(body: number, callee: (name: string) => Work | undefined, assumedTrips: number, inputs?: LoopInputs): Term[];
|
|
51
|
+
/** Numeric work with every parameter-bounded loop assumed to run `assumedTrips` times. */
|
|
52
|
+
export declare function settleWork(terms: readonly Term[], assumedTrips: number): Work;
|
|
53
|
+
export declare function estimateWork(body: number, callee: (name: string) => Work | undefined, assumedTrips: number): Work;
|
|
54
|
+
export declare const netWork: (work: Work) => number;
|
|
55
|
+
/** Resolves defaults and rejects values the estimate cannot use. */
|
|
56
|
+
export declare function admission(options: AdmissionOptions): {
|
|
57
|
+
minimumWork: number;
|
|
58
|
+
assumedTrips: number;
|
|
59
|
+
};
|
|
60
|
+
export declare function extract(original: Uint8Array, prepareTracked: (bytes: Uint8Array) => {
|
|
61
|
+
transactional?: Uint8Array;
|
|
62
|
+
}, options?: AdmissionOptions & {
|
|
63
|
+
refused?: (reason: string) => void;
|
|
64
|
+
/** called once per candidate span or pure function with its estimate and verdict */
|
|
65
|
+
observed?: (site: {
|
|
66
|
+
name: string;
|
|
67
|
+
kind: string;
|
|
68
|
+
compute: number;
|
|
69
|
+
accesses: number;
|
|
70
|
+
}) => void;
|
|
71
|
+
}): ControlPlan | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* The stack route: functions a worker could run when it holds a private copy of one mutable i32
|
|
74
|
+
* global, the stack pointer, and calls may recurse. Nothing consumes it yet, and it never changes
|
|
75
|
+
* the control plan or the module-wide reasons.
|
|
76
|
+
*/
|
|
77
|
+
export interface StackRoute {
|
|
78
|
+
/** True when at least one function can run on a worker and no global is refused for the module. */
|
|
79
|
+
eligible: boolean;
|
|
80
|
+
/** The one admitted mutable global and its initial value, when a function reads it. */
|
|
81
|
+
stack?: {
|
|
82
|
+
name: string;
|
|
83
|
+
initial: number;
|
|
84
|
+
};
|
|
85
|
+
/** Immutable globals with a constant initializer that the set reads. */
|
|
86
|
+
constants: string[];
|
|
87
|
+
/** The worker set: closed under calls, in module order. */
|
|
88
|
+
functions: string[];
|
|
89
|
+
/** The members that sit on a call cycle. */
|
|
90
|
+
recursive: string[];
|
|
91
|
+
/** Static work per member; a recursive member counts one level of its own calls. */
|
|
92
|
+
work: Record<string, Work>;
|
|
93
|
+
/** Why the module is or is not eligible. */
|
|
94
|
+
diagnostics: string[];
|
|
95
|
+
}
|
|
96
|
+
/** Computes the stack route of a module. A failure is reported in `diagnostics`, never thrown. */
|
|
97
|
+
export declare function stackRoute(original: Uint8Array, options?: AdmissionOptions): StackRoute;
|
|
98
|
+
/** One local of the owner that the schedule or the outlined body needs. */
|
|
99
|
+
export interface IterationLocal {
|
|
100
|
+
local: number;
|
|
101
|
+
/** `induction` is the trip counter; `stride` advances by a constant each iteration */
|
|
102
|
+
kind: 'induction' | 'stride' | 'invariant' | 'frame';
|
|
103
|
+
/** position in the `iterate` argument list; absent when the body never reads the local */
|
|
104
|
+
argument?: number;
|
|
105
|
+
/** where the value at loop entry comes from, when it is an owner parameter or a constant */
|
|
106
|
+
start?: {
|
|
107
|
+
parameter: number;
|
|
108
|
+
} | {
|
|
109
|
+
constant: number;
|
|
110
|
+
};
|
|
111
|
+
/** change per iteration, modulo 2^32; the value for iteration k is `start + k * stride` */
|
|
112
|
+
stride?: number;
|
|
113
|
+
/**
|
|
114
|
+
* a stride held in an owner local the loop never writes: the step is `stride * entry[strideLocal]`
|
|
115
|
+
* with `stride` 1 or -1, read at loop entry, and the value for iteration k is `start + k * step`
|
|
116
|
+
*/
|
|
117
|
+
strideLocal?: number;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The iteration route: one owner function whose single loop runs independent calls into the worker
|
|
121
|
+
* set. It reads the stack route and changes nothing; `Folio.open` consumes it when no older route
|
|
122
|
+
* covers the program. `module` holds the worker set, the stack global and the constants, with
|
|
123
|
+
* `iterate` doing one iteration of the body.
|
|
124
|
+
*
|
|
125
|
+
* The route proves a shape, not independence. A loop-carried dependence through the owner frame
|
|
126
|
+
* is caught at run time: the lowered worker module tracks the frame bytes each iteration reads
|
|
127
|
+
* before it writes them, and validation fails an iteration that read a byte an earlier iteration
|
|
128
|
+
* of its batch wrote. Reads of stale callee stack below the frame and imported host functions that
|
|
129
|
+
* touch memory are not tracked.
|
|
130
|
+
*/
|
|
131
|
+
export interface IterationRoute {
|
|
132
|
+
eligible: boolean;
|
|
133
|
+
owner?: string;
|
|
134
|
+
/** the loop label, when the owner names it */
|
|
135
|
+
loop?: string;
|
|
136
|
+
/** the loop runs the entry value of `local` times; an entry value of zero runs it 2^32 times */
|
|
137
|
+
trip?: {
|
|
138
|
+
local: number;
|
|
139
|
+
parameter?: number;
|
|
140
|
+
constant?: number;
|
|
141
|
+
};
|
|
142
|
+
/** every local the body reads or the schedule advances; `iterate` takes them in `argument` order */
|
|
143
|
+
locals: IterationLocal[];
|
|
144
|
+
/**
|
|
145
|
+
* the owner's frame: `local` holds `global - size` after the prologue and `iterate` takes it last.
|
|
146
|
+
* The image at [global - size, global) is copied into each slot at enqueue; a body that reads a
|
|
147
|
+
* frame byte an earlier iteration wrote is not detected here.
|
|
148
|
+
*/
|
|
149
|
+
frame?: {
|
|
150
|
+
global: string;
|
|
151
|
+
size: number;
|
|
152
|
+
local: number;
|
|
153
|
+
copy: true;
|
|
154
|
+
};
|
|
155
|
+
/** export names in `module` */
|
|
156
|
+
iterate?: string;
|
|
157
|
+
stackExport?: string;
|
|
158
|
+
module?: Uint8Array;
|
|
159
|
+
diagnostics: string[];
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Finds an owner whose single loop is a countdown over independent calls into the stack route's
|
|
163
|
+
* worker set and outlines one iteration of it. A refusal is a named diagnostic, never an exception.
|
|
164
|
+
*/
|
|
165
|
+
export declare function iterationRoute(original: Uint8Array, route: StackRoute): IterationRoute;
|