@gmitch215/folio 1.0.1 → 1.1.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 +398 -28
- package/dist/affine-state.d.ts +171 -0
- package/dist/affine-state.js +763 -0
- package/dist/affine.d.ts +160 -0
- package/dist/affine.js +571 -0
- package/dist/boundaries.d.ts +59 -0
- package/dist/boundaries.js +127 -0
- package/dist/certified.d.ts +66 -0
- package/dist/certified.js +192 -0
- package/dist/certify.d.ts +98 -0
- package/dist/certify.js +2628 -0
- package/dist/context.d.ts +16 -2
- package/dist/context.js +60 -14
- package/dist/coordinator.js +50 -3
- package/dist/extract.d.ts +19 -0
- package/dist/extract.js +133 -5
- package/dist/fold.d.ts +32 -0
- package/dist/fold.js +105 -0
- package/dist/frames.d.ts +5 -1
- package/dist/frames.js +156 -9
- package/dist/inline.d.ts +114 -0
- package/dist/inline.js +276 -13
- package/dist/iteration-admission.d.ts +116 -7
- package/dist/iteration-admission.js +137 -8
- package/dist/iteration-layout.d.ts +60 -0
- package/dist/iteration-layout.js +54 -3
- package/dist/iteration-owner.d.ts +14 -1
- package/dist/iteration-owner.js +2 -2
- package/dist/iteration-worker.js +124 -58
- package/dist/iteration.d.ts +179 -13
- package/dist/iteration.js +845 -70
- package/dist/lease.d.ts +45 -0
- package/dist/lease.js +274 -0
- package/dist/managed.d.ts +72 -0
- package/dist/managed.js +425 -27
- package/dist/memo.d.ts +99 -0
- package/dist/memo.js +250 -0
- package/dist/node.d.ts +43 -1
- package/dist/node.js +87 -11
- 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/ownership.d.ts +161 -0
- package/dist/ownership.js +6568 -0
- package/dist/ranges.d.ts +78 -0
- package/dist/ranges.js +263 -0
- package/dist/read-scan.d.ts +18 -0
- package/dist/read-scan.js +94 -0
- package/dist/read-windows.d.ts +103 -0
- package/dist/read-windows.js +244 -0
- package/dist/router-worker.d.ts +1 -0
- package/dist/router-worker.js +4 -0
- package/dist/router.d.ts +203 -0
- package/dist/router.js +667 -0
- package/dist/runs.d.ts +44 -0
- package/dist/runs.js +182 -0
- package/dist/slices-worker.d.ts +1 -0
- package/dist/slices-worker.js +38 -0
- package/dist/slices.d.ts +126 -0
- package/dist/slices.js +441 -0
- package/dist/tasks.d.ts +14 -4
- package/dist/tasks.js +12 -11
- package/dist/transaction.d.ts +10 -0
- package/package.json +40 -4
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { iterationGranules } from "./iteration-layout.js";
|
|
2
|
+
const READ = iterationGranules.read;
|
|
3
|
+
const WRITE = iterationGranules.write;
|
|
4
|
+
/** Smallest window worth marking: four read granules for the strided one, two for the fixed one. */
|
|
5
|
+
export const readWindowMinimum = { strided: 4 * READ, fixed: 2 * READ };
|
|
6
|
+
/**
|
|
7
|
+
* Executed Wasm instructions of one load of at most 8 bytes, counted on the lowering with the slot
|
|
8
|
+
* checks and no frame shadow (one node per instruction). The windows go before the exempt check
|
|
9
|
+
* (`window` order) or after it (`exempt` order, the `exemptFirst` option). The frame shadow adds
|
|
10
|
+
* 10 to a tracked load and to a miss and nothing to a hit or an exempt load.
|
|
11
|
+
*/
|
|
12
|
+
export const readWindowInstructions = {
|
|
13
|
+
tracked: 50,
|
|
14
|
+
frame: 10,
|
|
15
|
+
exempt: 15,
|
|
16
|
+
/** per window a load runs through without hitting it */
|
|
17
|
+
guard: 6,
|
|
18
|
+
/** a hit in the first window, and in the second, by order */
|
|
19
|
+
hit: { window: [11, 17], exempt: [21, 27] }
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Whether read windows pay for a loop, and in which order, from the counts of a batch on them. A
|
|
23
|
+
* hit replaces the mark and the slot checks of a tracked load; a miss executes the window guards on
|
|
24
|
+
* top of a tracked load; an exempt load executes them too when the windows come first; and the
|
|
25
|
+
* owner marks every window granule before each iteration. Windows are armed when the instructions
|
|
26
|
+
* saved exceed those spent by at least `margin` of the instructions the counted tracked loads
|
|
27
|
+
* cost. A window of the wrong size is still sound, so this decides cost only.
|
|
28
|
+
*/
|
|
29
|
+
export function readWindowsPay(counts, windows, frame, iterations, margin = readWindowMargin) {
|
|
30
|
+
const c = readWindowInstructions;
|
|
31
|
+
const n = (windows.strided ? 1 : 0) + (windows.fixed ? 1 : 0);
|
|
32
|
+
const tracked = c.tracked + (frame ? c.frame : 0);
|
|
33
|
+
const bytes = (windows.strided?.bytes ?? 0) + (windows.fixed?.bytes ?? 0);
|
|
34
|
+
// one store per 512 bytes of window for the bitmap, one per 4 KiB for the summary
|
|
35
|
+
const marking = Math.ceil(bytes / 512 + bytes / 4096) * 4 * Math.max(iterations, 1);
|
|
36
|
+
const guards = c.guard * n;
|
|
37
|
+
const verdict = (order) => {
|
|
38
|
+
const [first, second] = c.hit[order];
|
|
39
|
+
const hit = n === 2 ? (first + second) / 2 : first;
|
|
40
|
+
const saved = counts.hits * (tracked - hit);
|
|
41
|
+
const spent = (counts.misses + (order === 'window' ? counts.exempt : 0)) * guards + marking;
|
|
42
|
+
return { saved, spent, order, pay: false };
|
|
43
|
+
};
|
|
44
|
+
const windowFirst = verdict('window');
|
|
45
|
+
const exemptFirst = verdict('exempt');
|
|
46
|
+
const best = exemptFirst.saved - exemptFirst.spent > windowFirst.saved - windowFirst.spent
|
|
47
|
+
? exemptFirst
|
|
48
|
+
: windowFirst;
|
|
49
|
+
const loads = counts.hits + counts.misses;
|
|
50
|
+
return { ...best, pay: best.saved - best.spent > margin * loads * tracked };
|
|
51
|
+
}
|
|
52
|
+
/** Fraction of the counted tracked loads' instructions a window run must save to be armed. */
|
|
53
|
+
export const readWindowMargin = 0.05;
|
|
54
|
+
/** Windows of iteration `k` inside `[0, memoryBytes)`, at most two. */
|
|
55
|
+
export function readWindowsAt(windows, k, memoryBytes) {
|
|
56
|
+
const found = [];
|
|
57
|
+
const s = windows.strided;
|
|
58
|
+
if (s) {
|
|
59
|
+
const low = READ * Math.floor((s.low + (k - s.index) * s.stride) / READ);
|
|
60
|
+
if (low >= 0 && low + s.bytes <= memoryBytes)
|
|
61
|
+
found.push({ low, bytes: s.bytes });
|
|
62
|
+
}
|
|
63
|
+
if (windows.fixed && windows.fixed.low + windows.fixed.bytes <= memoryBytes)
|
|
64
|
+
found.push(windows.fixed);
|
|
65
|
+
return found;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Whether every window of iterations `first` to `first + count - 1` stays clear of the forbidden
|
|
69
|
+
* ranges (the arena, the grown logs), as `[low, end)` pairs. A load in a window skips the checks
|
|
70
|
+
* that would have found an access to those ranges.
|
|
71
|
+
*/
|
|
72
|
+
export function readWindowsClear(windows, first, count, memoryBytes, forbidden) {
|
|
73
|
+
const wanted = (windows.strided ? 1 : 0) + (windows.fixed ? 1 : 0);
|
|
74
|
+
for (let k = first; k < first + count; k++) {
|
|
75
|
+
const found = readWindowsAt(windows, k, memoryBytes);
|
|
76
|
+
if (found.length !== wanted)
|
|
77
|
+
return false;
|
|
78
|
+
for (const w of found)
|
|
79
|
+
for (const [low, end] of forbidden)
|
|
80
|
+
if (w.low < end && w.low + w.bytes > low)
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
/** Sets the read bits of every granule a window touches in the bitmap that starts at `base`. */
|
|
86
|
+
export function markReadWindow(u8, base, low, bytes) {
|
|
87
|
+
const first = Math.floor(low / READ);
|
|
88
|
+
const last = Math.floor((low + bytes - 1) / READ);
|
|
89
|
+
for (let g = first; g <= last;) {
|
|
90
|
+
if ((g & 7) === 0 && g + 7 <= last) {
|
|
91
|
+
u8[base + (g >> 3)] = 0xff;
|
|
92
|
+
g += 8;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
u8[base + (g >> 3)] |= 1 << (g & 7);
|
|
96
|
+
g++;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// does a sorted list of write granules hold one that touches [low, end)
|
|
100
|
+
function writesTouch(sorted, low, end) {
|
|
101
|
+
let a = 0, b = sorted.length;
|
|
102
|
+
const from = Math.floor(low / WRITE);
|
|
103
|
+
while (a < b) {
|
|
104
|
+
const mid = (a + b) >> 1;
|
|
105
|
+
if (sorted[mid] < from)
|
|
106
|
+
a = mid + 1;
|
|
107
|
+
else
|
|
108
|
+
b = mid;
|
|
109
|
+
}
|
|
110
|
+
return a < sorted.length && sorted[a] * WRITE < end;
|
|
111
|
+
}
|
|
112
|
+
// the value in the open interval with the most trailing zero bits, so a power-of-two record size wins
|
|
113
|
+
function pickStride(low, high) {
|
|
114
|
+
for (let step = 4096; step >= 1; step /= 2) {
|
|
115
|
+
const candidate = (Math.ceil(high / step) - 1) * step;
|
|
116
|
+
if (candidate > low && candidate < high)
|
|
117
|
+
return candidate;
|
|
118
|
+
}
|
|
119
|
+
return (low + high) / 2;
|
|
120
|
+
}
|
|
121
|
+
function intersectRuns(a, b) {
|
|
122
|
+
const out = [];
|
|
123
|
+
for (let i = 0, j = 0; i < a.length && j < b.length;) {
|
|
124
|
+
const low = Math.max(a[i], b[j]);
|
|
125
|
+
const end = Math.min(a[i] + a[i + 1], b[j] + b[j + 1]);
|
|
126
|
+
if (end > low)
|
|
127
|
+
out.push(low, end - low);
|
|
128
|
+
if (a[i] + a[i + 1] < b[j] + b[j + 1])
|
|
129
|
+
i += 2;
|
|
130
|
+
else
|
|
131
|
+
j += 2;
|
|
132
|
+
}
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
function subtractRange(runs, low, end) {
|
|
136
|
+
const out = [];
|
|
137
|
+
for (let i = 0; i < runs.length; i += 2) {
|
|
138
|
+
const from = runs[i];
|
|
139
|
+
const to = from + runs[i + 1];
|
|
140
|
+
if (to <= low || from >= end)
|
|
141
|
+
out.push(from, to - from);
|
|
142
|
+
else {
|
|
143
|
+
if (from < low)
|
|
144
|
+
out.push(from, low - from);
|
|
145
|
+
if (to > end)
|
|
146
|
+
out.push(end, to - end);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return out;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Windows from the read and write sets of tracked iterations that completed without a conflict.
|
|
153
|
+
* The strided one follows the largest read run of each iteration when the runs line up on one
|
|
154
|
+
* stride; when their lengths differ by more than a granule the window is the shortest one; the fixed one is the largest run
|
|
155
|
+
* every iteration read that is not inside the strided one. A window that another iteration wrote
|
|
156
|
+
* into, in the sample, is dropped: its reads would conflict. Needs three completed iterations.
|
|
157
|
+
*/
|
|
158
|
+
export function learnReadWindows(samples) {
|
|
159
|
+
const done = samples.filter((s) => s.status === 0).sort((a, b) => a.index - b.index);
|
|
160
|
+
if (done.length < 3)
|
|
161
|
+
return { reason: 'fewer than three completed iterations to learn from' };
|
|
162
|
+
const windows = {};
|
|
163
|
+
const why = [];
|
|
164
|
+
const runsOf = (s) => Array.from(s.reads);
|
|
165
|
+
const largest = done.map((s) => {
|
|
166
|
+
let start = -1, length = 0;
|
|
167
|
+
for (let i = 0; i < s.reads.length; i += 2)
|
|
168
|
+
if (s.reads[i + 1] > length) {
|
|
169
|
+
start = s.reads[i];
|
|
170
|
+
length = s.reads[i + 1];
|
|
171
|
+
}
|
|
172
|
+
return { start, length };
|
|
173
|
+
});
|
|
174
|
+
const others = (k, low, end) => done.some((s, j) => j !== k && writesTouch(s.written, low, end));
|
|
175
|
+
const lengths = largest.map((l) => l.length);
|
|
176
|
+
const maxLen = Math.max(...lengths);
|
|
177
|
+
const minLen = Math.min(...lengths);
|
|
178
|
+
if (minLen * READ < readWindowMinimum.strided)
|
|
179
|
+
why.push('no read run of 256 bytes in every iteration');
|
|
180
|
+
else {
|
|
181
|
+
// the first byte of iteration k lies in granule start[k], so every pair of iterations bounds
|
|
182
|
+
// the stride to an open interval of width 128 / distance; the stride is one value in all
|
|
183
|
+
let low = -Infinity, high = Infinity;
|
|
184
|
+
for (let i = 0; i < done.length; i++)
|
|
185
|
+
for (let j = i + 1; j < done.length; j++) {
|
|
186
|
+
const span = done[j].index - done[i].index;
|
|
187
|
+
const delta = (largest[j].start - largest[i].start) * READ;
|
|
188
|
+
low = Math.max(low, (delta - READ) / span);
|
|
189
|
+
high = Math.min(high, (delta + READ) / span);
|
|
190
|
+
}
|
|
191
|
+
if (!(low < high))
|
|
192
|
+
why.push('the largest read runs do not follow one stride');
|
|
193
|
+
else {
|
|
194
|
+
const stride = pickStride(low, high);
|
|
195
|
+
const first = done[0].index;
|
|
196
|
+
let origin = -Infinity;
|
|
197
|
+
done.forEach((o, k) => {
|
|
198
|
+
origin = Math.max(origin, largest[k].start * READ - (o.index - first) * stride);
|
|
199
|
+
});
|
|
200
|
+
// off the stride's own granules a prediction can fall one granule either way
|
|
201
|
+
const ragged = maxLen - minLen > 1;
|
|
202
|
+
const pad = (stride / READ) % 1 === 0 && (ragged || maxLen === minLen) ? 0 : 1;
|
|
203
|
+
const strided = {
|
|
204
|
+
index: first,
|
|
205
|
+
low: origin - pad * READ,
|
|
206
|
+
stride,
|
|
207
|
+
// runs of unequal length (a compressed stream) share their shortest prefix
|
|
208
|
+
bytes: ((ragged ? minLen : maxLen) + 2 * pad) * READ
|
|
209
|
+
};
|
|
210
|
+
const at = (index) => READ * Math.floor((strided.low + (index - strided.index) * strided.stride) / READ);
|
|
211
|
+
const clash = done.some((o, k) => others(k, at(o.index), at(o.index) + strided.bytes));
|
|
212
|
+
if (clash)
|
|
213
|
+
why.push('another iteration wrote inside the strided window');
|
|
214
|
+
else
|
|
215
|
+
windows.strided = strided;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
let common = runsOf(done[0]);
|
|
219
|
+
for (let k = 1; k < done.length; k++)
|
|
220
|
+
common = intersectRuns(common, runsOf(done[k]));
|
|
221
|
+
if (windows.strided) {
|
|
222
|
+
const s = windows.strided;
|
|
223
|
+
done.forEach((o) => {
|
|
224
|
+
const low = READ * Math.floor((s.low + (o.index - s.index) * s.stride) / READ);
|
|
225
|
+
common = subtractRange(common, low / READ, (low + s.bytes) / READ);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
let best = -1;
|
|
229
|
+
for (let i = 0; i < common.length; i += 2)
|
|
230
|
+
if (common[i + 1] * READ >= readWindowMinimum.fixed &&
|
|
231
|
+
(best < 0 || common[i + 1] > common[best + 1]))
|
|
232
|
+
best = i;
|
|
233
|
+
if (best >= 0) {
|
|
234
|
+
const low = common[best] * READ;
|
|
235
|
+
const bytes = common[best + 1] * READ;
|
|
236
|
+
if (done.some((s) => writesTouch(s.written, low, low + bytes)))
|
|
237
|
+
why.push('an iteration wrote inside the fixed window');
|
|
238
|
+
else
|
|
239
|
+
windows.fixed = { low, bytes };
|
|
240
|
+
}
|
|
241
|
+
if (!windows.strided && !windows.fixed)
|
|
242
|
+
return { reason: why.join('; ') || 'no read window found' };
|
|
243
|
+
return { windows };
|
|
244
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/router.d.ts
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { type CertificateRefusal, type StreamCertificate } from './certify.ts';
|
|
2
|
+
import { type OwnershipCertificate, type OwnershipOptions, type OwnershipRefusal } from './ownership.ts';
|
|
3
|
+
/** @since 1.1.0 */
|
|
4
|
+
export declare const ROUTER_VERSION = "folio-router-2";
|
|
5
|
+
/** `summary` is the certified stream fold, `window` the certified private window on slices. */
|
|
6
|
+
export type Route = 'summary' | 'window' | 'explicit' | 'tracked' | 'serial';
|
|
7
|
+
/** One value per ablation arm. `serial` never leaves the owner thread. */
|
|
8
|
+
export type RouterMode = 'serial' | 'w1' | 'w2' | 'independent' | 'shared' | 'router';
|
|
9
|
+
/** Every decision names one of these. The first four are routes taken, the rest are refusals. */
|
|
10
|
+
export declare const ROUTER_REASONS: readonly ["certified-summary", "certified-window", "explicit-runner", "tracked-eligible", "mode-serial", "single-worker", "below-floor", "dispatch-lost", "not-a-stream", "stream-refused", "no-route-in-mode", "no-certificate", "allocator-state", "shared-state", "unclassified-dependency", "wild-store", "layout-overlap", "assumption-unasserted", "tracked-ineligible", "memory-not-imported"];
|
|
11
|
+
export type RouterReason = (typeof ROUTER_REASONS)[number];
|
|
12
|
+
/** A single call over `len` bytes of one stream: `entry(state, ptr, len)`. */
|
|
13
|
+
export interface StreamCall {
|
|
14
|
+
kind: 'stream';
|
|
15
|
+
entry: string;
|
|
16
|
+
ptr: number;
|
|
17
|
+
len: number;
|
|
18
|
+
}
|
|
19
|
+
/** A loop of independent calls: `entry(...args(0, count))` equals the serial program. */
|
|
20
|
+
export interface RecordsCall {
|
|
21
|
+
kind: 'records';
|
|
22
|
+
entry: string;
|
|
23
|
+
count: number;
|
|
24
|
+
args: (from: number, to: number) => (number | bigint)[];
|
|
25
|
+
/** Every region the records touch, for the window guard. */
|
|
26
|
+
regions: [number, number][];
|
|
27
|
+
/**
|
|
28
|
+
* The regions the records write outside any window. The list must name every range the records
|
|
29
|
+
* write: a range left out keeps the writes of the records after a trap, and the serial replay does
|
|
30
|
+
* not undo them.
|
|
31
|
+
*/
|
|
32
|
+
writes: [number, number][];
|
|
33
|
+
}
|
|
34
|
+
export type RouterCall = StreamCall | RecordsCall;
|
|
35
|
+
/** What the caller knows about the program that no static test can establish. */
|
|
36
|
+
export interface RouterAssumptions {
|
|
37
|
+
/** Every host import returns the same value for the same arguments. */
|
|
38
|
+
importsDeterministic?: boolean;
|
|
39
|
+
/** Nothing reads the stack zone or the arena past the program memory after the call. */
|
|
40
|
+
residueUnobserved?: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface RouterConstants {
|
|
43
|
+
/** Serial time of the remaining records below which the tracked and explicit routes stay serial. */
|
|
44
|
+
trackedFloorMs: number;
|
|
45
|
+
/** The same for the window route. */
|
|
46
|
+
windowFloorMs: number;
|
|
47
|
+
/** Stream length below which the summary route stays serial. */
|
|
48
|
+
summaryMinBytes: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The tracked floor is the admission constants of the iteration route (fitted on the blake3 sweep,
|
|
52
|
+
* `results/corpus/iteration-admission`). The window floor is the smallest serial time at which all
|
|
53
|
+
* five paired runs of `aes-cbc-decrypt-shared` at 8 workers beat serial by 1.25 (4 records, 0.82
|
|
54
|
+
* ms; 3 records at 0.69 ms did not). The summary length is the smallest size at which every paired
|
|
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`.
|
|
57
|
+
*/
|
|
58
|
+
export declare const routerConstants: RouterConstants;
|
|
59
|
+
/** The per-record serial estimate after a tracked call: the lower of it and that call's plain first iteration. @internal */
|
|
60
|
+
export declare const lowerEstimate: (current: number, plainMs: number | undefined) => number;
|
|
61
|
+
export interface RouterOptions {
|
|
62
|
+
mode: RouterMode;
|
|
63
|
+
/** Initial pages of the memory the router allocates. */
|
|
64
|
+
pages: number;
|
|
65
|
+
/** Declared maximum of the shared memory a records call runs on; the module's own limit if lower. */
|
|
66
|
+
maxPages?: number;
|
|
67
|
+
workers?: number;
|
|
68
|
+
cache?: CertificateCache;
|
|
69
|
+
/** A module specifier or URL whose default export returns the imports besides the memory. */
|
|
70
|
+
imports?: string | URL;
|
|
71
|
+
assume?: RouterAssumptions;
|
|
72
|
+
/** Runs the records on a route the caller built; chosen after the window route in `router` mode. */
|
|
73
|
+
explicit?: (call: RecordsCall) => Promise<void>;
|
|
74
|
+
/** Overrides for `routerConstants`; a sweep sets them to 0 to force a dispatch. */
|
|
75
|
+
floors?: Partial<RouterConstants>;
|
|
76
|
+
/** Certifier options that change a certificate, and so the cache key. */
|
|
77
|
+
ownership?: OwnershipOptions;
|
|
78
|
+
}
|
|
79
|
+
export interface Consideration {
|
|
80
|
+
route: Route;
|
|
81
|
+
verdict: 'taken' | 'refused' | 'skipped';
|
|
82
|
+
reason: RouterReason;
|
|
83
|
+
detail: string;
|
|
84
|
+
}
|
|
85
|
+
export interface RouterDecision {
|
|
86
|
+
route: Route;
|
|
87
|
+
reason: RouterReason;
|
|
88
|
+
detail: string;
|
|
89
|
+
mode: RouterMode;
|
|
90
|
+
/** Wall time of the analyses this decision ran. Zero when every answer came from the cache. */
|
|
91
|
+
certifyMs: number;
|
|
92
|
+
cacheHit: boolean;
|
|
93
|
+
analyses: ('shape' | 'stream' | 'ownership')[];
|
|
94
|
+
considered: Consideration[];
|
|
95
|
+
}
|
|
96
|
+
export interface RouterRun {
|
|
97
|
+
/** The route that executed this call, which differs from the decision when the floor refuses. */
|
|
98
|
+
route: Route;
|
|
99
|
+
reason: RouterReason;
|
|
100
|
+
wallMs: number;
|
|
101
|
+
/** Time of the serial probe of record 0, on the call that measured it. */
|
|
102
|
+
probeMs?: number;
|
|
103
|
+
/** The stream's end state, for a stream call. */
|
|
104
|
+
state?: bigint;
|
|
105
|
+
/** The Folio report of a tracked call. */
|
|
106
|
+
tracked?: {
|
|
107
|
+
mode: string;
|
|
108
|
+
reason?: string;
|
|
109
|
+
iteration?: unknown;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
type Slot = 'shape' | 'stream' | 'ownership';
|
|
113
|
+
interface Entry {
|
|
114
|
+
shape?: ModuleShape;
|
|
115
|
+
stream?: StreamCertificate | CertificateRefusal;
|
|
116
|
+
ownership?: OwnershipCertificate | OwnershipRefusal;
|
|
117
|
+
/** Wall time the analysis took on the call that filled the slot. */
|
|
118
|
+
ms: Partial<Record<Slot, number>>;
|
|
119
|
+
}
|
|
120
|
+
/** The runtime a certificate was made on: a different engine or checker build is a different key. */
|
|
121
|
+
export declare const defaultBackend: () => string;
|
|
122
|
+
/**
|
|
123
|
+
* Certificates and refusals keyed by the SHA-256 of the module and a configuration key (backend,
|
|
124
|
+
* checker and router versions, and the options that change a certificate). A refusal is stored
|
|
125
|
+
* like a certificate, so a refused module costs a map lookup after the first call.
|
|
126
|
+
* @since 1.1.0
|
|
127
|
+
*/
|
|
128
|
+
export declare class CertificateCache {
|
|
129
|
+
#private;
|
|
130
|
+
readonly backend: string;
|
|
131
|
+
hits: number;
|
|
132
|
+
misses: number;
|
|
133
|
+
constructor(options?: {
|
|
134
|
+
backend?: string;
|
|
135
|
+
});
|
|
136
|
+
get size(): number;
|
|
137
|
+
key(bytes: Uint8Array, config: unknown): string;
|
|
138
|
+
/** Returns the stored answer of `slot`, or makes, times and stores it. `ms` is 0 on a hit. */
|
|
139
|
+
get<S extends Slot>(bytes: Uint8Array, config: unknown, slot: S, make: () => NonNullable<Entry[S]>): {
|
|
140
|
+
value: NonNullable<Entry[S]>;
|
|
141
|
+
ms: number;
|
|
142
|
+
hit: boolean;
|
|
143
|
+
};
|
|
144
|
+
/** Wall time the analysis took when it filled the slot, for an offline certification report. */
|
|
145
|
+
filledMs(bytes: Uint8Array, config: unknown, slot: Slot): number | undefined;
|
|
146
|
+
serialize(): string;
|
|
147
|
+
/** Loads what `serialize` wrote. Entries made under another backend never match a key. */
|
|
148
|
+
load(text: string): void;
|
|
149
|
+
}
|
|
150
|
+
export interface ModuleShape {
|
|
151
|
+
valid: boolean;
|
|
152
|
+
entryFound: boolean;
|
|
153
|
+
entryParams: string[];
|
|
154
|
+
entryResults: number;
|
|
155
|
+
functionImports: number;
|
|
156
|
+
memoryImported: boolean;
|
|
157
|
+
}
|
|
158
|
+
/** One decode of the module: what both certificate builders need to know before they start. */
|
|
159
|
+
export declare function analyzeModule(bytes: Uint8Array, entry: string): ModuleShape;
|
|
160
|
+
/** The prefix domain is tried after a plain refusal unless the caller chose an option the checker does not combine with it. @internal */
|
|
161
|
+
export declare function effectiveOwnership(given: OwnershipOptions | undefined): {
|
|
162
|
+
options: OwnershipOptions | null;
|
|
163
|
+
prefixFallback: boolean;
|
|
164
|
+
};
|
|
165
|
+
/** Everything `decide` needs and makes: the choice, the certificate the route runs on, and the trace. */
|
|
166
|
+
interface Plan {
|
|
167
|
+
decision: RouterDecision;
|
|
168
|
+
stream?: StreamCertificate;
|
|
169
|
+
window?: OwnershipCertificate;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Chooses the route from the module bytes and the call, without running the call. The order is the
|
|
173
|
+
* certified summary, then the certified window, then the explicit route when the caller supplied
|
|
174
|
+
* one, then the tracked route when its assumptions hold, else serial. Both certifiers are asked
|
|
175
|
+
* only for the call shape they can serve, and a refusal is cached like a certificate.
|
|
176
|
+
* @since 1.1.0
|
|
177
|
+
*/
|
|
178
|
+
export declare function decide(bytes: Uint8Array, call: RouterCall, options: RouterOptions): Plan;
|
|
179
|
+
/**
|
|
180
|
+
* The open route behind one call description: it holds the memory, the pools and the sticky
|
|
181
|
+
* admission decision. Write the inputs into `memory` after `open`, then `run`.
|
|
182
|
+
* @since 1.1.0
|
|
183
|
+
*/
|
|
184
|
+
export declare class Router {
|
|
185
|
+
#private;
|
|
186
|
+
readonly decision: RouterDecision;
|
|
187
|
+
/** Wall time of `open` after the decision: memory, instances and pools. */
|
|
188
|
+
readonly setupMs: number;
|
|
189
|
+
private constructor();
|
|
190
|
+
get memory(): WebAssembly.Memory;
|
|
191
|
+
/** The route the next call takes: the decision's, or serial once a floor test refused it. */
|
|
192
|
+
get route(): Route;
|
|
193
|
+
static open(bytes: Uint8Array, call: RouterCall, options: RouterOptions): Promise<Router>;
|
|
194
|
+
/** Calls another export of the module on the owner thread, for setup that is not part of the loop. */
|
|
195
|
+
exec(name: string, args?: (number | bigint)[]): unknown;
|
|
196
|
+
/** Runs the call. A records call probes record 0 once and then follows the floor test. */
|
|
197
|
+
run(options?: {
|
|
198
|
+
initial?: bigint;
|
|
199
|
+
}): Promise<RouterRun>;
|
|
200
|
+
close(): Promise<void>;
|
|
201
|
+
}
|
|
202
|
+
export declare const openRouter: typeof Router.open;
|
|
203
|
+
export {};
|