@systemfsoftware/effect-sim-kernel 2.0.5 → 2.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/CHANGELOG.md +8 -2
- package/README.md +10 -0
- package/dist/index.d.ts +72 -23
- package/dist/index.mjs +270 -80
- package/dist/rolldown-runtime-D3KUYPsf.mjs +12 -0
- package/package.json +13 -13
- package/dist/rolldown-runtime-D7D4PA-g.mjs +0 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @systemfsoftware/effect-sim-kernel
|
|
2
2
|
|
|
3
|
-
# @systemfsoftware/effect-sim-kernel@2.0
|
|
3
|
+
# @systemfsoftware/effect-sim-kernel@2.1.0
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Dev dependency bump (@types/node) only; the packed tarball is unchanged.
|
|
6
|
+
|
|
7
|
+
No consumer-visible package changes.
|
|
8
|
+
|
|
9
|
+
On Node 26 a run that waited on a file read as a deadlock: Node 26 leaves pending file requests out of `process.getActiveResourcesInfo()`, the list the kernel read its host waits from. `Kernel.run` takes a `host` option naming where it reads them, and `Kernel.fileRequestHooks(createHook)` follows file requests through `async_hooks` while keeping the process list for sockets, DNS lookups and timers. The kernel still imports no Node module: the caller passes `createHook`. `Conformance.released` reads the source from `Kernel.HostResourcesService` when it is provided.
|
|
10
|
+
|
|
11
|
+
Rebuilt with tsdown 0.23.7 against the updated dev dependencies: the bundled `dist/` files carry a different hashed runtime chunk name and comment markers, and the declared devDependency ranges move. The public API and runtime behaviour are unchanged.
|
package/README.md
CHANGED
|
@@ -61,6 +61,16 @@ await Kernel.run(program, { external: 'await' })
|
|
|
61
61
|
|
|
62
62
|
A real-timer wait still fails (`Escape`) under `'await'` — timers go through the controlled clock instead. `'await'` beside `path` or `choose` is refused, since an awaited host wait cannot take an explored schedule. For checks that run one ordered program against the real system, use `'await'` with no exploration options.
|
|
63
63
|
|
|
64
|
+
A run reads the host's pending waits from `process.getActiveResourcesInfo()` unless it is given another source. Node 26 leaves pending file reads and writes out of that list, so on Node 26 a file wait reads as a deadlock. Pass the `host` option there; the kernel imports no Node module, so the caller hands in `createHook`:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import { createHook } from 'node:async_hooks'
|
|
68
|
+
|
|
69
|
+
await Kernel.run(program, { external: 'await', host: Kernel.fileRequestHooks(createHook) })
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`Kernel.fileRequestHooks` keeps the process list for sockets, DNS lookups and timers, and follows each file request through `async_hooks` from the moment it is issued until its callback runs. An Effect caller that runs the kernel for its own callers reads the source from `Kernel.HostResourcesService` and passes it on, as `Conformance.released` does. `Kernel.search`, `Kernel.shrink` and `Kernel.pick` take no `host` and read the process list, so on Node 26 a file stall under them is named a deadlock rather than a file wait; they explore schedules and fail on any host wait either way.
|
|
73
|
+
|
|
64
74
|
## One kernel at a time
|
|
65
75
|
|
|
66
76
|
The global hooks (Effect's `Scheduler`, the fiber resume methods, `Ref`/`Deferred` field observation) are installed for the lifetime of one run and restored at its release. A second `Kernel.run` started while one is active queues behind it, in arrival order, instead of sharing the hooks — one kernel owns the process at a time, so two runs never interleave and a scenario never sees another run's decisions. `Kernel.search`, `Kernel.shrink` and `Kernel.pick` reach the kernel through the same queue, one run at a time.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import * as Context from "effect/Context";
|
|
2
|
+
import { Clock, Config, Duration, Effect, Exit, Fiber, Layer, Schema } from "effect";
|
|
3
3
|
type UnobservedPrimitive = 'Queue' | 'PubSub' | 'Semaphore' | 'Latch' | 'Scope finalizer';
|
|
4
4
|
interface Pruning {
|
|
5
5
|
readonly enabled: boolean;
|
|
@@ -15,8 +15,33 @@ interface Bound {
|
|
|
15
15
|
}
|
|
16
16
|
declare const pruned: Pruning;
|
|
17
17
|
declare const unpruned: (disabledBy: ReadonlyArray<UnobservedPrimitive>) => Pruning;
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
/** @internal */
|
|
19
|
+
interface HostResourceWatch {
|
|
20
|
+
readonly names: () => ReadonlyArray<string>;
|
|
21
|
+
readonly end: () => void;
|
|
22
|
+
}
|
|
23
|
+
/** @internal */
|
|
24
|
+
interface HostResources {
|
|
25
|
+
readonly begin: () => HostResourceWatch;
|
|
26
|
+
}
|
|
27
|
+
declare const HostResourcesService_base: Context.ServiceClass<HostResourcesService, "@systemfsoftware/effect-sim-kernel/internal/hostResources/HostResourcesService", HostResources>;
|
|
28
|
+
/** @internal */
|
|
29
|
+
declare class HostResourcesService extends HostResourcesService_base {}
|
|
30
|
+
/** @internal */
|
|
31
|
+
declare const processResources: HostResources;
|
|
32
|
+
interface HookCallbacks {
|
|
33
|
+
readonly init: (asyncId: number, type: string) => void;
|
|
34
|
+
readonly before: (asyncId: number) => void;
|
|
35
|
+
readonly destroy: (asyncId: number) => void;
|
|
36
|
+
}
|
|
37
|
+
interface Hook {
|
|
38
|
+
readonly enable: () => void;
|
|
39
|
+
readonly disable: () => void;
|
|
40
|
+
}
|
|
41
|
+
/** @internal */
|
|
42
|
+
type CreateHook = (callbacks: HookCallbacks) => Hook;
|
|
43
|
+
/** @internal */
|
|
44
|
+
declare const fileRequestHooks: (createHook: CreateHook) => HostResources;
|
|
20
45
|
declare const PctDepth: Schema.brand<Schema.Int, "PctDepth">;
|
|
21
46
|
type PctDepth = typeof PctDepth.Type;
|
|
22
47
|
declare const PctSeedCount: Schema.brand<Schema.Int, "PctSeedCount">;
|
|
@@ -50,8 +75,6 @@ interface TestClock extends Clock.Clock {
|
|
|
50
75
|
declare const make: Effect.Effect<TestClock>;
|
|
51
76
|
/** The layer a harness provides in place of `TestClock.layer()`. */
|
|
52
77
|
declare const layer: Layer.Layer<Clock.Clock>;
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region src/internal/deadlock.d.ts
|
|
55
78
|
/** The process resources that can call back into the program from outside. */
|
|
56
79
|
/** @internal */
|
|
57
80
|
type WaitKind = 'RealTimer' | 'File' | 'Socket' | 'Other';
|
|
@@ -62,8 +85,6 @@ interface SuspendedFiber {
|
|
|
62
85
|
}
|
|
63
86
|
/** @internal */
|
|
64
87
|
type AnyFiber<A = unknown, E = unknown> = Fiber.Fiber<A, E>;
|
|
65
|
-
//#endregion
|
|
66
|
-
//#region src/internal/escapeRecorder.d.ts
|
|
67
88
|
/** @internal */
|
|
68
89
|
type TimerName = 'setTimeout' | 'setInterval' | 'setImmediate';
|
|
69
90
|
/** @internal */
|
|
@@ -71,8 +92,6 @@ interface Escape {
|
|
|
71
92
|
readonly timer: TimerName;
|
|
72
93
|
readonly site: string;
|
|
73
94
|
}
|
|
74
|
-
//#endregion
|
|
75
|
-
//#region src/internal/kernel.d.ts
|
|
76
95
|
/** An index into the kernel's pending task list: the schedule's unit of choice. */
|
|
77
96
|
/** @internal */
|
|
78
97
|
type Decision = number;
|
|
@@ -112,6 +131,31 @@ interface StepRecord {
|
|
|
112
131
|
* it can change the outcome. Seam for preemption-bounded search (pruning).
|
|
113
132
|
*/
|
|
114
133
|
readonly visible: boolean;
|
|
134
|
+
readonly boundary: BoundaryKind | undefined;
|
|
135
|
+
readonly activeBlocked: boolean;
|
|
136
|
+
readonly runnableFibers: ReadonlyArray<number | undefined>;
|
|
137
|
+
}
|
|
138
|
+
/** @internal */
|
|
139
|
+
type BoundaryKind = 'auto-yield' | 'explicit-yield';
|
|
140
|
+
/** @internal */
|
|
141
|
+
interface BoundaryRecord {
|
|
142
|
+
readonly step: number;
|
|
143
|
+
readonly kind: BoundaryKind;
|
|
144
|
+
readonly activeFiber: number | undefined;
|
|
145
|
+
readonly runnableFibers: ReadonlyArray<number | undefined>;
|
|
146
|
+
readonly chosenFiber: number | undefined;
|
|
147
|
+
readonly preempted: boolean;
|
|
148
|
+
}
|
|
149
|
+
/** @internal */
|
|
150
|
+
interface TraceSnapshot {
|
|
151
|
+
readonly boundary: BoundaryKind | undefined;
|
|
152
|
+
readonly runnable: ReadonlyArray<number | undefined>;
|
|
153
|
+
}
|
|
154
|
+
/** @internal */
|
|
155
|
+
interface TraceDivergence {
|
|
156
|
+
readonly atStep: number;
|
|
157
|
+
readonly expected: TraceSnapshot | undefined;
|
|
158
|
+
readonly actual: TraceSnapshot | undefined;
|
|
115
159
|
}
|
|
116
160
|
/** Which fiber an interruption names (R5). */
|
|
117
161
|
/** @internal */
|
|
@@ -129,8 +173,6 @@ declare const isStepping: () => boolean;
|
|
|
129
173
|
*/
|
|
130
174
|
/** @internal */
|
|
131
175
|
declare const beginExploration: Effect.Effect<void>;
|
|
132
|
-
//#endregion
|
|
133
|
-
//#region src/internal/stepLoop.d.ts
|
|
134
176
|
/**
|
|
135
177
|
* The discriminant tags of the run outcome; the variants inherit them because
|
|
136
178
|
* an `Exit` cannot travel through a schema.
|
|
@@ -155,6 +197,9 @@ declare const runOutcomeTags: {
|
|
|
155
197
|
readonly runaway: {
|
|
156
198
|
readonly _tag: 'Runaway';
|
|
157
199
|
};
|
|
200
|
+
readonly replayTraceDiverged: {
|
|
201
|
+
readonly _tag: 'ReplayTraceDiverged';
|
|
202
|
+
};
|
|
158
203
|
};
|
|
159
204
|
/** @internal */
|
|
160
205
|
type RunCompleted<A, E> = RunHistory & typeof runOutcomeTags.completed & {
|
|
@@ -168,6 +213,7 @@ type RunFailed = RunHistory & typeof runOutcomeTags.failed & {
|
|
|
168
213
|
interface RunHistory {
|
|
169
214
|
/** Which fiber ran at each step, in order (R3). */
|
|
170
215
|
readonly steps: ReadonlyArray<StepRecord>;
|
|
216
|
+
readonly boundaries: ReadonlyArray<BoundaryRecord>;
|
|
171
217
|
/** The decisions the schedule explored, in order (R4's replayable path). */
|
|
172
218
|
readonly decisions: ReadonlyArray<Decision>;
|
|
173
219
|
}
|
|
@@ -194,7 +240,13 @@ type RunawayFailure = typeof runOutcomeTags.runaway & {
|
|
|
194
240
|
readonly pending: number;
|
|
195
241
|
};
|
|
196
242
|
/** @internal */
|
|
197
|
-
type
|
|
243
|
+
type ReplayTraceDivergedFailure = typeof runOutcomeTags.replayTraceDiverged & {
|
|
244
|
+
readonly atStep: number;
|
|
245
|
+
readonly expected: TraceSnapshot | undefined;
|
|
246
|
+
readonly actual: TraceSnapshot | undefined;
|
|
247
|
+
};
|
|
248
|
+
/** @internal */
|
|
249
|
+
type RunFailure = EscapeFailure | BlockedFailure | DeadlockFailure | RunawayFailure | ReplayTraceDivergedFailure;
|
|
198
250
|
/** @internal */
|
|
199
251
|
interface Interruption {
|
|
200
252
|
/** The one-based step after whose task the fiber is interrupted. */
|
|
@@ -209,6 +261,7 @@ interface RunOptions {
|
|
|
209
261
|
* or a step past the end of the path, takes Effect's order.
|
|
210
262
|
*/
|
|
211
263
|
readonly path?: ReadonlyArray<Decision | undefined>;
|
|
264
|
+
readonly expectTrace?: ReadonlyArray<TraceSnapshot>;
|
|
212
265
|
/**
|
|
213
266
|
* Chooses beyond the recorded path (seam for PCT and bounded search).
|
|
214
267
|
* Returning undefined takes the zero-preemption choice.
|
|
@@ -225,6 +278,11 @@ interface RunOptions {
|
|
|
225
278
|
* or `choose` is rejected, so it cannot silently weaken an exploring run.
|
|
226
279
|
*/
|
|
227
280
|
readonly external?: 'fail' | 'await';
|
|
281
|
+
/**
|
|
282
|
+
* Where the run reads the host resources alive while it stalls. The default reads the process's own list,
|
|
283
|
+
* which Node 26 leaves pending file requests out of; pass `fileRequestHooks(createHook)` there.
|
|
284
|
+
*/
|
|
285
|
+
readonly host?: HostResources;
|
|
228
286
|
/**
|
|
229
287
|
* `'body'` keeps every decision before `beginExploration` on Effect's order,
|
|
230
288
|
* so a harness's own setup is never explored (R15).
|
|
@@ -256,8 +314,6 @@ declare const run: {
|
|
|
256
314
|
<A, E>(program: Effect.Effect<A, E>, options?: RunOptions): Promise<RunResult<A, E>>;
|
|
257
315
|
(options?: RunOptions): <A, E>(program: Effect.Effect<A, E>) => Promise<RunResult<A, E>>;
|
|
258
316
|
};
|
|
259
|
-
//#endregion
|
|
260
|
-
//#region src/Kernel/Pct.d.ts
|
|
261
317
|
interface PickOptions {
|
|
262
318
|
readonly seed: number;
|
|
263
319
|
readonly depth?: PctDepth;
|
|
@@ -283,8 +339,6 @@ declare const pct: {
|
|
|
283
339
|
<A, E>(program: Effect.Effect<A, E>, options?: PctOptions<A, E>): Promise<PctOutcome<A, E>>;
|
|
284
340
|
<A, E>(options?: PctOptions<A, E>): (program: Effect.Effect<A, E>) => Promise<PctOutcome<A, E>>;
|
|
285
341
|
};
|
|
286
|
-
//#endregion
|
|
287
|
-
//#region src/Kernel/Profile.d.ts
|
|
288
342
|
/**
|
|
289
343
|
* How much schedule exploration a run buys. `per-change` is the budget a pull
|
|
290
344
|
* request is judged on; `local` is a developer's own machine, which caps the
|
|
@@ -307,8 +361,6 @@ declare const preemptionsFor: {
|
|
|
307
361
|
(profile: ProfileName): (requested: number | undefined) => number | undefined;
|
|
308
362
|
};
|
|
309
363
|
declare const currentPreemptionsFor: (requested: number | undefined) => Effect.Effect<number | undefined, Config.ConfigError>;
|
|
310
|
-
//#endregion
|
|
311
|
-
//#region src/Kernel/Search.d.ts
|
|
312
364
|
declare const CompletedTag: {
|
|
313
365
|
readonly _tag: 'Completed';
|
|
314
366
|
};
|
|
@@ -350,8 +402,6 @@ declare const search: {
|
|
|
350
402
|
<A, E>(program: Effect.Effect<A, E>, options?: SearchOptions<A, E>): Promise<SearchReport<A, E>>;
|
|
351
403
|
<A, E>(options?: SearchOptions<A, E>): (program: Effect.Effect<A, E>) => Promise<SearchReport<A, E>>;
|
|
352
404
|
};
|
|
353
|
-
//#endregion
|
|
354
|
-
//#region src/Kernel/Shrink.d.ts
|
|
355
405
|
interface ShrinkOptions<A, E> {
|
|
356
406
|
readonly path: ReadonlyArray<Decision>;
|
|
357
407
|
readonly isFailure?: (result: RunResult<A, E>) => boolean;
|
|
@@ -371,7 +421,6 @@ declare const shrinkCommands: {
|
|
|
371
421
|
<C>(stillFails: (candidate: ReadonlyArray<C>) => Promise<boolean>): (commands: ReadonlyArray<C>) => Promise<ReadonlyArray<C>>;
|
|
372
422
|
};
|
|
373
423
|
declare namespace mod_d_exports {
|
|
374
|
-
export { AnyFiber, BlockedFailure, Bound, Choice, ChoiceOption, DeadlockFailure, Decision, Escape, EscapeFailure, FiberTarget, Interruption, OverBudgetOutcome, PctDepth, PctFailure, PctOptions, PctOutcome, PctSeedCount, PctStepCount, PickOptions, ProfileName, Pruning, RunCompleted, RunFailed, RunFailure, RunHistory, RunOptions, RunResult, RunawayFailure, SearchFailure, SearchOptions, SearchOutcome, SearchReport, ShrinkOptions, ShrinkOutcome, StepRecord, SuspendedFiber, TestClock_d_exports as TestClock, TimerName, UnobservedPrimitive, WaitKind, beginExploration, currentPreemptionsFor, currentProfile, currentSeedsFor, isStepping, localPreemptions, localSeeds, runOutcomeTags as outcomeTags, pct, pctDepth, perChangeSeeds, pick, preemptionsFor, pruned, run, search, searchTags, seedsFor, shrink, shrinkCommands, unpruned };
|
|
424
|
+
export { AnyFiber, BlockedFailure, Bound, BoundaryKind, BoundaryRecord, Choice, ChoiceOption, CreateHook, DeadlockFailure, Decision, Escape, EscapeFailure, FiberTarget, HostResourceWatch, HostResources, HostResourcesService, Interruption, OverBudgetOutcome, PctDepth, PctFailure, PctOptions, PctOutcome, PctSeedCount, PctStepCount, PickOptions, ProfileName, Pruning, ReplayTraceDivergedFailure, RunCompleted, RunFailed, RunFailure, RunHistory, RunOptions, RunResult, RunawayFailure, SearchFailure, SearchOptions, SearchOutcome, SearchReport, ShrinkOptions, ShrinkOutcome, StepRecord, SuspendedFiber, TestClock_d_exports as TestClock, TimerName, TraceDivergence, TraceSnapshot, UnobservedPrimitive, WaitKind, beginExploration, currentPreemptionsFor, currentProfile, currentSeedsFor, fileRequestHooks, isStepping, localPreemptions, localSeeds, runOutcomeTags as outcomeTags, pct, pctDepth, perChangeSeeds, pick, preemptionsFor, processResources, pruned, run, search, searchTags, seedsFor, shrink, shrinkCommands, unpruned };
|
|
375
425
|
}
|
|
376
|
-
//#endregion
|
|
377
426
|
export { mod_d_exports as Kernel };
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { t as __exportAll } from "./rolldown-runtime-
|
|
2
|
-
import
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D3KUYPsf.mjs";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
3
|
+
import { Clock, Config, Context as Context$1, Deferred, Duration, Effect, Latch, Layer, Match, Option, Order, PubSub, Queue, Ref, Scheduler, Schema, Scope, Semaphore } from "effect";
|
|
3
4
|
import { dual } from "effect/Function";
|
|
4
|
-
|
|
5
|
+
// src/Kernel/Bound.ts
|
|
5
6
|
const pruned = {
|
|
6
7
|
enabled: true,
|
|
7
8
|
disabledBy: []
|
|
@@ -10,8 +11,51 @@ const unpruned = (disabledBy) => ({
|
|
|
10
11
|
enabled: false,
|
|
11
12
|
disabledBy
|
|
12
13
|
});
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
// src/internal/hostResources.ts
|
|
15
|
+
/** @internal */
|
|
16
|
+
var HostResourcesService = class extends Context.Service()("@systemfsoftware/effect-sim-kernel/internal/hostResources/HostResourcesService") {};
|
|
17
|
+
const NO_RESOURCES = [];
|
|
18
|
+
const isHostObject$4 = (candidate) => typeof candidate === "object" && candidate !== null;
|
|
19
|
+
const listsActiveResources = (candidate) => typeof Reflect.get(candidate, "getActiveResourcesInfo") === "function";
|
|
20
|
+
const isHostProcess = (candidate) => isHostObject$4(candidate) && listsActiveResources(candidate);
|
|
21
|
+
const activeResourceNames = () => {
|
|
22
|
+
const host = Reflect.get(globalThis, "process");
|
|
23
|
+
return isHostProcess(host) ? host.getActiveResourcesInfo() : NO_RESOURCES;
|
|
24
|
+
};
|
|
25
|
+
const endNothing = () => void 0;
|
|
26
|
+
/** @internal */
|
|
27
|
+
const processResources = { begin: () => ({
|
|
28
|
+
names: activeResourceNames,
|
|
29
|
+
end: endNothing
|
|
30
|
+
}) };
|
|
31
|
+
const FILE_REQUEST_KINDS = ["FSREQCALLBACK", "FSREQPROMISE"];
|
|
32
|
+
const LISTED_FILE_REQUEST = /^FSReq/u;
|
|
33
|
+
const isListedFileRequest = (name) => LISTED_FILE_REQUEST.test(name);
|
|
34
|
+
const listedWithoutFileRequests = () => activeResourceNames().filter((name) => !isListedFileRequest(name));
|
|
35
|
+
const watchFileRequests = (createHook) => {
|
|
36
|
+
const pending = /* @__PURE__ */ new Map();
|
|
37
|
+
const settle = (asyncId) => {
|
|
38
|
+
pending.delete(asyncId);
|
|
39
|
+
};
|
|
40
|
+
const hook = createHook({
|
|
41
|
+
init: (asyncId, type) => {
|
|
42
|
+
if (FILE_REQUEST_KINDS.includes(type)) pending.set(asyncId, type);
|
|
43
|
+
},
|
|
44
|
+
before: settle,
|
|
45
|
+
destroy: settle
|
|
46
|
+
});
|
|
47
|
+
hook.enable();
|
|
48
|
+
return {
|
|
49
|
+
names: () => [...listedWithoutFileRequests(), ...pending.values()],
|
|
50
|
+
end: () => {
|
|
51
|
+
hook.disable();
|
|
52
|
+
pending.clear();
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
/** @internal */
|
|
57
|
+
const fileRequestHooks = (createHook) => ({ begin: () => watchFileRequests(createHook) });
|
|
58
|
+
// src/Kernel/Pct.schema.ts
|
|
15
59
|
const generatedBetween = (minimum, maximum) => Schema.makeFilter(() => void 0, { arbitraryConstraint: {
|
|
16
60
|
order: Order.Number,
|
|
17
61
|
minimum,
|
|
@@ -29,12 +73,10 @@ const PctStepCount = Schema.Int.pipe(Schema.check(Schema.isBetween({
|
|
|
29
73
|
minimum: 0,
|
|
30
74
|
maximum: Number.MAX_SAFE_INTEGER
|
|
31
75
|
}, { message: "a PCT step count is a whole number of explored decisions, at least 0" })), Schema.check(generatedBetween(0, 1e4)), Schema.brand("PctStepCount"));
|
|
32
|
-
|
|
33
|
-
//#region src/internal/profile.schema.ts
|
|
76
|
+
// src/internal/profile.schema.ts
|
|
34
77
|
/** @internal */
|
|
35
78
|
const ProfileNames = Schema.Literals(["local", "per-change"]);
|
|
36
|
-
|
|
37
|
-
//#region src/internal/clocks.ts
|
|
79
|
+
// src/internal/clocks.ts
|
|
38
80
|
/**
|
|
39
81
|
* The kernel's clocks (R2, R37). The root clock is virtual time the run owns:
|
|
40
82
|
* every sleep registers here, no host timer is ever created, and `advance`
|
|
@@ -176,8 +218,7 @@ const makeRunClocks = () => ({
|
|
|
176
218
|
*/
|
|
177
219
|
/** @internal */
|
|
178
220
|
const stepClocks = (clocks) => clocks.testClocks.some((testClock) => testClock.stepTowardRequest()) || clocks.clock.advance();
|
|
179
|
-
|
|
180
|
-
//#region src/internal/kernel.ts
|
|
221
|
+
// src/internal/kernel.ts
|
|
181
222
|
/**
|
|
182
223
|
* The kernel instance (KTD2): it supplies Effect's `Scheduler`, wraps the fiber
|
|
183
224
|
* resume methods, and observes `Ref` and `Deferred` field access. The hooks are
|
|
@@ -196,7 +237,8 @@ const FIBER_METHODS = [
|
|
|
196
237
|
"addObserver",
|
|
197
238
|
"interruptUnsafe",
|
|
198
239
|
"pollUnsafe",
|
|
199
|
-
"evaluate"
|
|
240
|
+
"evaluate",
|
|
241
|
+
"yieldNow"
|
|
200
242
|
];
|
|
201
243
|
const REF_FIELDS = ["ref"];
|
|
202
244
|
const DEFERRED_FIELDS = ["effect", "resumes"];
|
|
@@ -331,7 +373,7 @@ const interceptFields$1 = (proto, fields, guard) => {
|
|
|
331
373
|
const DEFAULT_VALUE = "~effect/Context/defaultValue";
|
|
332
374
|
const FIBER_CACHE = "_fiberCache";
|
|
333
375
|
const emptyContextRoot = () => {
|
|
334
|
-
const root = Reflect.get(Context.empty(), "cacheRoot");
|
|
376
|
+
const root = Reflect.get(Context$1.empty(), "cacheRoot");
|
|
335
377
|
if (!isHostObject$3(root)) throw new Error("effect-sim-kernel: Context no longer has a cache root on the pinned Effect version");
|
|
336
378
|
return root;
|
|
337
379
|
};
|
|
@@ -345,7 +387,7 @@ const restoreFiberCache = (root, captured) => {
|
|
|
345
387
|
else Reflect.defineProperty(root, FIBER_CACHE, captured);
|
|
346
388
|
};
|
|
347
389
|
const cachedDefaultOf = (reference) => {
|
|
348
|
-
Context.getOption(Context.empty(), reference);
|
|
390
|
+
Context$1.getOption(Context$1.empty(), reference);
|
|
349
391
|
const descriptor = captureDescriptor(reference, DEFAULT_VALUE);
|
|
350
392
|
if (descriptor === void 0) throw new Error("effect-sim-kernel: Context no longer caches reference defaults on the pinned Effect version");
|
|
351
393
|
return descriptor;
|
|
@@ -465,13 +507,18 @@ const dispatchInterrupt = (fiber, kernel, original, args) => {
|
|
|
465
507
|
if (kernel.afterQueuedResume(fiber, interruptAgain(fiber, args))) return void 0;
|
|
466
508
|
return dispatchObserved(fiber, kernel, original, args);
|
|
467
509
|
};
|
|
468
|
-
const
|
|
510
|
+
const dispatchYieldNow = (fiber, kernel, original, args) => {
|
|
511
|
+
kernel.noteYieldBoundary(args[2] === true ? "auto-yield" : "explicit-yield", fiber);
|
|
512
|
+
return dispatchObserved(fiber, kernel, original, args);
|
|
513
|
+
};
|
|
514
|
+
const dispatchFiberCall = (fiber, method, original, args, kernel) => Match.value(method).pipe(Match.when("evaluate", () => dispatchEvaluate(fiber, kernel, original, args)), Match.when("yieldNow", () => dispatchYieldNow(fiber, kernel, original, args)), Match.when("interruptUnsafe", () => dispatchInterrupt(fiber, kernel, original, args)), Match.orElse(() => dispatchObserved(fiber, kernel, original, args)));
|
|
469
515
|
/** @internal */
|
|
470
516
|
const makeKernel = (options) => {
|
|
471
517
|
const pending = [];
|
|
472
518
|
const fibers = /* @__PURE__ */ new Set();
|
|
473
519
|
const evaluated = /* @__PURE__ */ new WeakSet();
|
|
474
520
|
const steps = [];
|
|
521
|
+
const boundaries = [];
|
|
475
522
|
const decisions = [];
|
|
476
523
|
const escapes = [];
|
|
477
524
|
const touches = /* @__PURE__ */ new Set();
|
|
@@ -496,6 +543,14 @@ const makeKernel = (options) => {
|
|
|
496
543
|
let root = void 0;
|
|
497
544
|
let running = false;
|
|
498
545
|
let restoreHooks = void 0;
|
|
546
|
+
let yieldBoundary = void 0;
|
|
547
|
+
let yieldBoundaryFiber = void 0;
|
|
548
|
+
let boundaryForStep = void 0;
|
|
549
|
+
let boundaryActiveForStep = void 0;
|
|
550
|
+
let runnableAtDecision = [];
|
|
551
|
+
let traceDivergence = void 0;
|
|
552
|
+
const appearanceOrder = /* @__PURE__ */ new Map();
|
|
553
|
+
let appearances = 0;
|
|
499
554
|
const taskAt = (index) => pending[index];
|
|
500
555
|
const stepOn = (task) => task === void 0 ? -1 : task.step;
|
|
501
556
|
const stepAt = (index) => stepOn(taskAt(index));
|
|
@@ -603,6 +658,20 @@ const makeKernel = (options) => {
|
|
|
603
658
|
const endStep = () => {
|
|
604
659
|
phase = "paused";
|
|
605
660
|
};
|
|
661
|
+
const clearBoundary = () => {
|
|
662
|
+
boundaryForStep = void 0;
|
|
663
|
+
boundaryActiveForStep = void 0;
|
|
664
|
+
};
|
|
665
|
+
const captureBoundary = () => {
|
|
666
|
+
if (yieldBoundary === void 0) return;
|
|
667
|
+
boundaryForStep = yieldBoundary;
|
|
668
|
+
boundaryActiveForStep = yieldBoundaryFiber;
|
|
669
|
+
yieldBoundary = void 0;
|
|
670
|
+
yieldBoundaryFiber = void 0;
|
|
671
|
+
};
|
|
672
|
+
const runnableIds = (tasks) => tasks.map((task) => task.owner?.id);
|
|
673
|
+
const ownerPending = (fiber) => fiber !== void 0 && pending.some((task) => task.owner === fiber);
|
|
674
|
+
const sameRunnable = (left, right) => left.length === right.length && left.every((id, index) => id === right[index]);
|
|
606
675
|
const ranOn = (task) => ranInTask ?? task.owner;
|
|
607
676
|
const runTask = (task) => {
|
|
608
677
|
beginStep();
|
|
@@ -616,8 +685,52 @@ const makeKernel = (options) => {
|
|
|
616
685
|
const touchesFiber = (ran) => ran !== void 0 && touches.has(ran);
|
|
617
686
|
const extraScheduling = () => scheduledInStep > 1 || globalWorkThisStep;
|
|
618
687
|
const sharedWork = (ran) => extraScheduling() || touchesFiber(ran);
|
|
619
|
-
const isVisible = (task, ran) =>
|
|
620
|
-
|
|
688
|
+
const isVisible = (task, ran) => [
|
|
689
|
+
task.external,
|
|
690
|
+
sharedWork(ran),
|
|
691
|
+
touches.size > 0
|
|
692
|
+
].some(Boolean);
|
|
693
|
+
const expectedAt = (step) => options.expectTrace?.[step - 1];
|
|
694
|
+
const knownAppearance = (id) => appearanceOrder.get(id);
|
|
695
|
+
const noteAppearance = (id) => {
|
|
696
|
+
appearances += 1;
|
|
697
|
+
appearanceOrder.set(id, appearances);
|
|
698
|
+
return appearances;
|
|
699
|
+
};
|
|
700
|
+
const appearanceOf = (id) => {
|
|
701
|
+
if (id === void 0) return void 0;
|
|
702
|
+
return appearanceFor(id);
|
|
703
|
+
};
|
|
704
|
+
const appearanceFor = (id) => knownAppearance(id) ?? noteAppearance(id);
|
|
705
|
+
const normalizedRunnable = () => runnableAtDecision.map(appearanceOf);
|
|
706
|
+
const divergedAlready = () => traceDivergence !== void 0;
|
|
707
|
+
const runnableMatches = (expected, actual) => sameRunnable(expected.runnable, actual.runnable);
|
|
708
|
+
const traceMatches = (expected, actual) => [expected.boundary === actual.boundary, runnableMatches(expected, actual)].every(Boolean);
|
|
709
|
+
const snapshotOf = (record) => ({
|
|
710
|
+
boundary: record.boundary,
|
|
711
|
+
runnable: record.runnableFibers
|
|
712
|
+
});
|
|
713
|
+
const traceMismatch = (record) => (expected) => (actual) => [traceMatches(expected, actual)].every(Boolean) ? void 0 : {
|
|
714
|
+
atStep: record.step,
|
|
715
|
+
expected,
|
|
716
|
+
actual
|
|
717
|
+
};
|
|
718
|
+
const mismatchAt = (record) => {
|
|
719
|
+
const expected = expectedAt(record.step);
|
|
720
|
+
if (expected === void 0) return extraStepDivergence(record);
|
|
721
|
+
return traceMismatch(record)(expected)(snapshotOf(record));
|
|
722
|
+
};
|
|
723
|
+
const extraStepDivergence = (record) => ({
|
|
724
|
+
atStep: record.step,
|
|
725
|
+
expected: void 0,
|
|
726
|
+
actual: snapshotOf(record)
|
|
727
|
+
});
|
|
728
|
+
const tracing = () => options.expectTrace !== void 0;
|
|
729
|
+
const checkTrace = (record) => {
|
|
730
|
+
if ([divergedAlready(), !tracing()].some(Boolean)) return;
|
|
731
|
+
traceDivergence = mismatchAt(record);
|
|
732
|
+
};
|
|
733
|
+
const stepRecord = (input, task, ran, boundary, activeBlocked, runnable) => ({
|
|
621
734
|
step: stepCount,
|
|
622
735
|
choice: input.choice,
|
|
623
736
|
options: input.options,
|
|
@@ -626,12 +739,40 @@ const makeKernel = (options) => {
|
|
|
626
739
|
forced: task.forced,
|
|
627
740
|
external: task.external,
|
|
628
741
|
fiberId: ran?.id,
|
|
629
|
-
visible: isVisible(task, ran)
|
|
742
|
+
visible: isVisible(task, ran),
|
|
743
|
+
boundary,
|
|
744
|
+
activeBlocked,
|
|
745
|
+
runnableFibers: runnable
|
|
746
|
+
});
|
|
747
|
+
const boundaryPreempted = (chosenId, activeId) => [chosenId !== activeId, runnableAtDecision.includes(activeId)].every(Boolean);
|
|
748
|
+
const ranId = (ran) => ran?.id;
|
|
749
|
+
const boundaryActiveId = () => boundaryActiveForStep?.id;
|
|
750
|
+
const boundaryRecordFor = (kind, ran) => ({
|
|
751
|
+
step: stepCount,
|
|
752
|
+
kind,
|
|
753
|
+
activeFiber: boundaryActiveId(),
|
|
754
|
+
runnableFibers: runnableAtDecision,
|
|
755
|
+
chosenFiber: ranId(ran),
|
|
756
|
+
preempted: boundaryPreempted(ranId(ran), boundaryActiveId())
|
|
630
757
|
});
|
|
758
|
+
const recordBoundary = (ran) => {
|
|
759
|
+
const kind = boundaryForStep;
|
|
760
|
+
if (kind === void 0) return;
|
|
761
|
+
boundaries.push(boundaryRecordFor(kind, ran));
|
|
762
|
+
};
|
|
763
|
+
const hasLastRan = () => lastRan !== void 0;
|
|
764
|
+
const previousBlocked = () => hasLastRan() && !ownerPending(lastRan);
|
|
765
|
+
const recordDecision = (input) => {
|
|
766
|
+
if (exploring) decisions.push(input.choice);
|
|
767
|
+
};
|
|
631
768
|
const recordStep = (input, task, ran) => {
|
|
769
|
+
const runnable = normalizedRunnable();
|
|
770
|
+
const record = stepRecord(input, task, ran, boundaryForStep, previousBlocked(), runnable);
|
|
771
|
+
checkTrace(record);
|
|
772
|
+
recordBoundary(ran);
|
|
632
773
|
lastRan = ran;
|
|
633
|
-
steps.push(
|
|
634
|
-
|
|
774
|
+
steps.push(record);
|
|
775
|
+
recordDecision(input);
|
|
635
776
|
};
|
|
636
777
|
const queuedResumeOf = (fiber) => (task) => task.external && task.owner === fiber;
|
|
637
778
|
const afterQueuedResume = (fiber, after) => {
|
|
@@ -654,6 +795,9 @@ const makeKernel = (options) => {
|
|
|
654
795
|
return task;
|
|
655
796
|
};
|
|
656
797
|
const step = (input) => {
|
|
798
|
+
clearBoundary();
|
|
799
|
+
captureBoundary();
|
|
800
|
+
runnableAtDecision = runnableIds(pending);
|
|
657
801
|
const task = takeTask(input.choice);
|
|
658
802
|
if (task === void 0) throw new Error(`effect-sim-kernel: no task to run at decision ${input.choice}`);
|
|
659
803
|
const ran = runTask(task);
|
|
@@ -674,6 +818,7 @@ const makeKernel = (options) => {
|
|
|
674
818
|
pending,
|
|
675
819
|
fibers,
|
|
676
820
|
steps,
|
|
821
|
+
boundaries,
|
|
677
822
|
decisions,
|
|
678
823
|
escapes,
|
|
679
824
|
scheduler,
|
|
@@ -691,6 +836,9 @@ const makeKernel = (options) => {
|
|
|
691
836
|
get running() {
|
|
692
837
|
return running;
|
|
693
838
|
},
|
|
839
|
+
get traceDivergence() {
|
|
840
|
+
return traceDivergence;
|
|
841
|
+
},
|
|
694
842
|
start: (started) => {
|
|
695
843
|
root = started;
|
|
696
844
|
running = true;
|
|
@@ -711,6 +859,11 @@ const makeKernel = (options) => {
|
|
|
711
859
|
});
|
|
712
860
|
scheduledInStep++;
|
|
713
861
|
},
|
|
862
|
+
noteYieldBoundary: (kind, fiber) => {
|
|
863
|
+
if (phase !== "step") return;
|
|
864
|
+
yieldBoundary = kind;
|
|
865
|
+
yieldBoundaryFiber = fiber;
|
|
866
|
+
},
|
|
714
867
|
firstEvaluation: (fiber) => {
|
|
715
868
|
if (evaluated.has(fiber)) return false;
|
|
716
869
|
evaluated.add(fiber);
|
|
@@ -742,26 +895,18 @@ const makeKernel = (options) => {
|
|
|
742
895
|
restoreHooks = acquireHooks(kernel);
|
|
743
896
|
return kernel;
|
|
744
897
|
};
|
|
745
|
-
|
|
746
|
-
//#region src/internal/deadlock.ts
|
|
898
|
+
// src/internal/deadlock.ts
|
|
747
899
|
const NO_FRAMES = [];
|
|
748
|
-
const NO_RESOURCES = [];
|
|
749
900
|
const isHostObject$2 = (candidate) => typeof candidate === "object";
|
|
750
901
|
const isFrameList = (candidate) => Array.isArray(candidate);
|
|
751
|
-
const isHostProcess = (candidate) => isHostObject$2(candidate);
|
|
752
|
-
const hostProcess = () => Reflect.get(globalThis, "process");
|
|
753
|
-
const resourceNames = () => {
|
|
754
|
-
const host = hostProcess();
|
|
755
|
-
return isHostProcess(host) ? host.getActiveResourcesInfo() : NO_RESOURCES;
|
|
756
|
-
};
|
|
757
902
|
const bump = (counts, resource) => {
|
|
758
903
|
counts.set(resource, (counts.get(resource) ?? 0) + 1);
|
|
759
904
|
};
|
|
760
905
|
/** A snapshot of the process resources alive right now, by resource kind. */
|
|
761
906
|
/** @internal */
|
|
762
|
-
const resourceCounts = () => {
|
|
907
|
+
const resourceCounts = (names) => {
|
|
763
908
|
const counts = /* @__PURE__ */ new Map();
|
|
764
|
-
for (const resource of
|
|
909
|
+
for (const resource of names) bump(counts, resource);
|
|
765
910
|
return counts;
|
|
766
911
|
};
|
|
767
912
|
const extraOf = (before, entry) => entry[1] - (before.get(entry[0]) ?? 0);
|
|
@@ -771,11 +916,11 @@ const appendExtra = (appeared, before, entry) => {
|
|
|
771
916
|
};
|
|
772
917
|
/** Resource kinds that appeared since `before`, as `"<kind> x<count>"` entries. */
|
|
773
918
|
/** @internal */
|
|
774
|
-
const newResources = (before) => {
|
|
919
|
+
const newResources = dual(2, (before, now) => {
|
|
775
920
|
const appeared = [];
|
|
776
|
-
for (const entry of
|
|
921
|
+
for (const entry of now) appendExtra(appeared, before, entry);
|
|
777
922
|
return appeared;
|
|
778
|
-
};
|
|
923
|
+
});
|
|
779
924
|
const FAMILY_PATTERNS = [
|
|
780
925
|
[/Socket|TCP|UDP|Pipe|GetAddrInfo/u, "Socket"],
|
|
781
926
|
[/FS|File/u, "File"],
|
|
@@ -849,8 +994,7 @@ const describeSuspended = (fibers) => {
|
|
|
849
994
|
for (const fiber of fibers) collectSuspended(suspended, fiber);
|
|
850
995
|
return suspended;
|
|
851
996
|
};
|
|
852
|
-
|
|
853
|
-
//#region src/internal/escapeRecorder.ts
|
|
997
|
+
// src/internal/escapeRecorder.ts
|
|
854
998
|
const TIMER_NAMES = [
|
|
855
999
|
"setTimeout",
|
|
856
1000
|
"setInterval",
|
|
@@ -908,8 +1052,7 @@ const hostImmediateOf = (originals) => {
|
|
|
908
1052
|
return immediate === void 0 ? syncImmediate : immediate;
|
|
909
1053
|
};
|
|
910
1054
|
const syncImmediate = (handler) => handler();
|
|
911
|
-
|
|
912
|
-
//#region src/internal/runQueue.ts
|
|
1055
|
+
// src/internal/runQueue.ts
|
|
913
1056
|
let tail = Promise.resolve();
|
|
914
1057
|
/** @internal */
|
|
915
1058
|
const acquireRun = () => {
|
|
@@ -918,8 +1061,7 @@ const acquireRun = () => {
|
|
|
918
1061
|
tail = turn.promise;
|
|
919
1062
|
return previous.then(() => turn.resolve);
|
|
920
1063
|
};
|
|
921
|
-
|
|
922
|
-
//#region src/internal/stepLoop.ts
|
|
1064
|
+
// src/internal/stepLoop.ts
|
|
923
1065
|
/**
|
|
924
1066
|
* The async step loop (R1, R4, R5, R36). It picks one pending task per step —
|
|
925
1067
|
* by a caller-supplied decision path, a `choose` callback, or Effect's own
|
|
@@ -944,7 +1086,8 @@ const runOutcomeTags = {
|
|
|
944
1086
|
escape: { _tag: "Escape" },
|
|
945
1087
|
blocked: { _tag: "Blocked" },
|
|
946
1088
|
deadlock: { _tag: "Deadlock" },
|
|
947
|
-
runaway: { _tag: "Runaway" }
|
|
1089
|
+
runaway: { _tag: "Runaway" },
|
|
1090
|
+
replayTraceDiverged: { _tag: "ReplayTraceDiverged" }
|
|
948
1091
|
};
|
|
949
1092
|
const DEFAULT_MAX_STEPS = 5e4;
|
|
950
1093
|
const DEFAULT_STEP_TURNS = 4;
|
|
@@ -1005,8 +1148,9 @@ const runawayOf = (kernel, options, guard) => {
|
|
|
1005
1148
|
pending: kernel.pending.length
|
|
1006
1149
|
};
|
|
1007
1150
|
};
|
|
1008
|
-
const
|
|
1009
|
-
|
|
1151
|
+
const countsNow = (watch) => resourceCounts(watch.names());
|
|
1152
|
+
const quiescenceFailure = (kernel, before, watch) => {
|
|
1153
|
+
const resources = newResources(before, countsNow(watch));
|
|
1010
1154
|
if (resources.length === 0) return {
|
|
1011
1155
|
...runOutcomeTags.deadlock,
|
|
1012
1156
|
suspended: describeSuspended(kernel.fibers)
|
|
@@ -1028,35 +1172,45 @@ const hostCheckYield = (state) => {
|
|
|
1028
1172
|
return promise;
|
|
1029
1173
|
};
|
|
1030
1174
|
const hostYield = (state) => hostCheckYield(state).then(() => drain(DEFAULT_STEP_TURNS)).then(() => drain(DEFAULT_QUIESCENCE_TURNS));
|
|
1031
|
-
const awaitedResources = (state) => newResources(state.before);
|
|
1175
|
+
const awaitedResources = (state) => newResources(state.before, countsNow(state.watch));
|
|
1032
1176
|
const waitsRemain = (resources) => resources.some((resource) => waitKindOf([resource]) === "File" || waitKindOf([resource]) === "Socket");
|
|
1033
1177
|
const loweredBaseline = (before, now) => new Map([...before].map(([name, count]) => [name, Math.min(count, now.get(name) ?? 0)]));
|
|
1034
1178
|
const revivedDrive = (state) => drive({
|
|
1035
1179
|
...state,
|
|
1036
|
-
before: loweredBaseline(state.before,
|
|
1180
|
+
before: loweredBaseline(state.before, countsNow(state.watch))
|
|
1037
1181
|
});
|
|
1038
1182
|
const waitedOutcome = (state) => revivedAfterHost(state, 0);
|
|
1039
1183
|
const revivedAfterHost = (state, waited) => hostYield(state).then(() => revivedAfterYield(state, waited));
|
|
1040
1184
|
const revivedAfterYield = (state, waited) => tasksPending(state) ? revivedDrive(state) : revivedByResources(state, waited);
|
|
1041
1185
|
const revivedByResources = (state, waited) => waitsRemain(awaitedResources(state)) ? revivedAfterLimit(state, waited) : revivedAfterHost(state, waited + 1);
|
|
1042
|
-
const revivedAfterLimit = (state, waited) => waited > MAX_HOST_WAITS ? Promise.resolve(failedOn(state.kernel, quiescenceFailure(state.kernel, state.before))) : revivedAfterHost(state, waited + 1);
|
|
1186
|
+
const revivedAfterLimit = (state, waited) => waited > MAX_HOST_WAITS ? Promise.resolve(failedOn(state.kernel, quiescenceFailure(state.kernel, state.before, state.watch))) : revivedAfterHost(state, waited + 1);
|
|
1043
1187
|
const waitForExternal = (state, _excuse) => drain(quiescenceTurnsOf(state.options)).then(() => waitedOutcome(state));
|
|
1044
1188
|
const awaitedStall = (state, excuse) => awaitsStall(state.options, excuse) ? waitForExternal(state, excuse) : Promise.resolve(failedOn(state.kernel, excuse));
|
|
1045
1189
|
const stallByExternal = (state, excuse) => awaitedStall(state, excuse);
|
|
1046
|
-
const classifyStall = (state) => seamOffersProgress(state.options.onQuiescent) ? Promise.resolve(void 0) : stallByExternal(state, quiescenceFailure(state.kernel, state.before));
|
|
1190
|
+
const classifyStall = (state) => seamOffersProgress(state.options.onQuiescent) ? Promise.resolve(void 0) : stallByExternal(state, quiescenceFailure(state.kernel, state.before, state.watch));
|
|
1047
1191
|
const seamOrFailure = (state) => classifyStall(state);
|
|
1048
1192
|
const completedOn = (kernel, exit) => ({
|
|
1049
1193
|
...runOutcomeTags.completed,
|
|
1050
1194
|
exit,
|
|
1051
1195
|
steps: kernel.steps,
|
|
1196
|
+
boundaries: kernel.boundaries,
|
|
1052
1197
|
decisions: kernel.decisions
|
|
1053
1198
|
});
|
|
1054
1199
|
const failedOn = (kernel, failure) => ({
|
|
1055
1200
|
...runOutcomeTags.failed,
|
|
1056
1201
|
failure,
|
|
1057
1202
|
steps: kernel.steps,
|
|
1203
|
+
boundaries: kernel.boundaries,
|
|
1058
1204
|
decisions: kernel.decisions
|
|
1059
1205
|
});
|
|
1206
|
+
const replayDivergedOf = (kernel) => {
|
|
1207
|
+
const divergence = kernel.traceDivergence;
|
|
1208
|
+
if (divergence === void 0) return void 0;
|
|
1209
|
+
return {
|
|
1210
|
+
...runOutcomeTags.replayTraceDiverged,
|
|
1211
|
+
...divergence
|
|
1212
|
+
};
|
|
1213
|
+
};
|
|
1060
1214
|
const interruptLive = (kernel, fiber) => {
|
|
1061
1215
|
if (fiber !== void 0) kernel.interrupt(fiber);
|
|
1062
1216
|
};
|
|
@@ -1072,7 +1226,12 @@ const applyInterrupt = (kernel, options) => {
|
|
|
1072
1226
|
const advance$1 = (state) => {
|
|
1073
1227
|
state.kernel.step(decide(state.kernel, state.options));
|
|
1074
1228
|
applyInterrupt(state.kernel, state.options);
|
|
1075
|
-
return drain(stepTurnsOf(state.options));
|
|
1229
|
+
return drain(stepTurnsOf(state.options)).then(() => divergedResult(state));
|
|
1230
|
+
};
|
|
1231
|
+
const divergedResult = (state) => {
|
|
1232
|
+
const failure = replayDivergedOf(state.kernel);
|
|
1233
|
+
if (failure === void 0) return void 0;
|
|
1234
|
+
return failedOn(state.kernel, failure);
|
|
1076
1235
|
};
|
|
1077
1236
|
const seamOffersProgress = (seam) => seam !== void 0 && seam();
|
|
1078
1237
|
const resettled = (state) => {
|
|
@@ -1082,14 +1241,31 @@ const resettled = (state) => {
|
|
|
1082
1241
|
const stalled = (state) => drain(quiescenceTurnsOf(state.options)).then(() => resettled(state));
|
|
1083
1242
|
const quiescent = (state) => {
|
|
1084
1243
|
const exit = state.root.pollUnsafe();
|
|
1085
|
-
if (exit !== void 0) return Promise.resolve(
|
|
1244
|
+
if (exit !== void 0) return Promise.resolve(completedOrShortTrace(state, exit));
|
|
1086
1245
|
return stalled(state);
|
|
1087
1246
|
};
|
|
1247
|
+
const completedOrShortTrace = (state, exit) => {
|
|
1248
|
+
const short = shortTraceFailure(state.options.expectTrace, state.kernel.steps.length);
|
|
1249
|
+
if (short === void 0) return completedOn(state.kernel, exit);
|
|
1250
|
+
return failedOn(state.kernel, short);
|
|
1251
|
+
};
|
|
1252
|
+
const shortTraceFailure = (expectTrace, steps) => {
|
|
1253
|
+
if (traceLongEnough(expectTrace, steps)) return void 0;
|
|
1254
|
+
return shortDivergence(expectTrace, steps);
|
|
1255
|
+
};
|
|
1256
|
+
const expectAtIndex = (expectTrace, index) => expectTrace?.[index];
|
|
1257
|
+
const shortDivergence = (expectTrace, steps) => ({
|
|
1258
|
+
...runOutcomeTags.replayTraceDiverged,
|
|
1259
|
+
atStep: steps + 1,
|
|
1260
|
+
expected: expectAtIndex(expectTrace, steps),
|
|
1261
|
+
actual: void 0
|
|
1262
|
+
});
|
|
1263
|
+
const traceLongEnough = (expectTrace, steps) => expectTrace === void 0 || steps >= expectTrace.length;
|
|
1088
1264
|
const settled$1 = (state) => {
|
|
1089
1265
|
if (state.kernel.pending.length > 0) return Promise.resolve(void 0);
|
|
1090
1266
|
return quiescent(state);
|
|
1091
1267
|
};
|
|
1092
|
-
const progressed = (state, done) => done !== void 0 ? Promise.resolve(done) : advance$1(state)
|
|
1268
|
+
const progressed = (state, done) => done !== void 0 ? Promise.resolve(done) : advance$1(state);
|
|
1093
1269
|
const escapeOrRunaway = (kernel, options, guard) => {
|
|
1094
1270
|
const escaped = kernel.escapes[0];
|
|
1095
1271
|
if (escaped !== void 0) return escapeFailureOf(escaped);
|
|
@@ -1112,8 +1288,10 @@ const continued = (state, halted) => halted !== void 0 ? Promise.resolve(halted)
|
|
|
1112
1288
|
const drive = (state) => iteration(state).then((halted) => continued(state, halted));
|
|
1113
1289
|
const RUN_OPTION_KEYS = [
|
|
1114
1290
|
"choose",
|
|
1291
|
+
"expectTrace",
|
|
1115
1292
|
"explore",
|
|
1116
1293
|
"external",
|
|
1294
|
+
"host",
|
|
1117
1295
|
"interrupt",
|
|
1118
1296
|
"maxSteps",
|
|
1119
1297
|
"onQuiescent",
|
|
@@ -1133,25 +1311,41 @@ const isProgram = (candidate) => !isRunOptions(candidate);
|
|
|
1133
1311
|
* taken, and a per-step record of which fiber ran. A run started while one is
|
|
1134
1312
|
* active queues behind it, so two runs never share the global hooks.
|
|
1135
1313
|
*/
|
|
1314
|
+
const endingRun = (started, end) => {
|
|
1315
|
+
try {
|
|
1316
|
+
return started().finally(end);
|
|
1317
|
+
} catch (error) {
|
|
1318
|
+
end();
|
|
1319
|
+
return Promise.reject(error);
|
|
1320
|
+
}
|
|
1321
|
+
};
|
|
1136
1322
|
const lockedRun = (program, options, release) => {
|
|
1137
|
-
const kernel = makeKernel({
|
|
1323
|
+
const kernel = makeKernel({
|
|
1324
|
+
exploring: options.explore !== "body",
|
|
1325
|
+
expectTrace: options.expectTrace
|
|
1326
|
+
});
|
|
1138
1327
|
const recorder = installEscapeRecorder((escape) => {
|
|
1139
1328
|
kernel.escapes.push(escape);
|
|
1140
1329
|
});
|
|
1141
1330
|
const userSeam = options.onQuiescent;
|
|
1142
|
-
const
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
kernel
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1331
|
+
const watch = (options.host ?? processResources).begin();
|
|
1332
|
+
return endingRun(() => {
|
|
1333
|
+
const root = Effect.runFork(Effect.provideService(program, Clock.Clock, kernel.clocks.clock), { scheduler: kernel.scheduler });
|
|
1334
|
+
kernel.start(root);
|
|
1335
|
+
return drive({
|
|
1336
|
+
kernel,
|
|
1337
|
+
root,
|
|
1338
|
+
options: {
|
|
1339
|
+
...options,
|
|
1340
|
+
onQuiescent: () => stepClocks(kernel.clocks) || seamOffersProgress(userSeam)
|
|
1341
|
+
},
|
|
1342
|
+
before: countsNow(watch),
|
|
1343
|
+
watch,
|
|
1344
|
+
guard: 0,
|
|
1345
|
+
hostImmediate: recorder.hostImmediate
|
|
1346
|
+
});
|
|
1347
|
+
}, () => {
|
|
1348
|
+
watch.end();
|
|
1155
1349
|
recorder.restore();
|
|
1156
1350
|
kernel.release();
|
|
1157
1351
|
release();
|
|
@@ -1179,8 +1373,7 @@ const runImpl = (program, options = {}) => {
|
|
|
1179
1373
|
*/
|
|
1180
1374
|
/** @internal */
|
|
1181
1375
|
const run = dual((args) => args.length > 0 && isProgram(args[0]), runImpl);
|
|
1182
|
-
|
|
1183
|
-
//#region src/Kernel/Profile.ts
|
|
1376
|
+
// src/Kernel/Profile.ts
|
|
1184
1377
|
const pctDepth = PctDepth.make(3);
|
|
1185
1378
|
const isProfileName = Schema.is(ProfileNames);
|
|
1186
1379
|
const profileOf = (name) => isProfileName(name) ? name : "per-change";
|
|
@@ -1215,8 +1408,7 @@ const localBoundOf = (requested) => Math.min(requested ?? 1, 1);
|
|
|
1215
1408
|
const boundImpl = (requested, profile) => profile === "local" ? localBoundOf(requested) : requested;
|
|
1216
1409
|
const preemptionsFor = dual(2, boundImpl);
|
|
1217
1410
|
const currentPreemptionsFor = (requested) => Effect.map(currentProfile, (profile) => preemptionsFor(requested, profile));
|
|
1218
|
-
|
|
1219
|
-
//#region src/Kernel/Pct.ts
|
|
1411
|
+
// src/Kernel/Pct.ts
|
|
1220
1412
|
/**
|
|
1221
1413
|
* Seeded PCT (Burckhardt, Kothari & Musuvathi): each fiber gets a random
|
|
1222
1414
|
* priority, the highest-priority runnable task runs, and `depth - 1` change
|
|
@@ -1386,8 +1578,7 @@ const pctImpl = (program, options = {}) => {
|
|
|
1386
1578
|
});
|
|
1387
1579
|
};
|
|
1388
1580
|
const pct = dual((args) => args.length === 2 || Effect.isEffect(args[0]), pctImpl);
|
|
1389
|
-
|
|
1390
|
-
//#region src/internal/Unobserved.ts
|
|
1581
|
+
// src/internal/Unobserved.ts
|
|
1391
1582
|
/**
|
|
1392
1583
|
* Unobserved shared-primitive detection (R35, AE12). The kernel observes `Ref`
|
|
1393
1584
|
* and `Deferred` only, so a run that touches `Queue`, `PubSub`, `Semaphore`,
|
|
@@ -1534,7 +1725,7 @@ const scopedContext = (fiber) => {
|
|
|
1534
1725
|
};
|
|
1535
1726
|
const heldScope = (fiber) => {
|
|
1536
1727
|
const context = scopedContext(fiber);
|
|
1537
|
-
return context === void 0 ? void 0 : Option.getOrUndefined(Context.getOption(context, Scope.Scope));
|
|
1728
|
+
return context === void 0 ? void 0 : Option.getOrUndefined(Context$1.getOption(context, Scope.Scope));
|
|
1538
1729
|
};
|
|
1539
1730
|
const holdIn = (scope, holder) => {
|
|
1540
1731
|
currentKernel()?.holdScope(scope, holder);
|
|
@@ -1663,7 +1854,7 @@ const deviationsBefore = (steps) => {
|
|
|
1663
1854
|
let spent = 0;
|
|
1664
1855
|
return steps.map((step) => {
|
|
1665
1856
|
const before = spent;
|
|
1666
|
-
spent += Number(step.deviation);
|
|
1857
|
+
spent += Number(step.deviation && !step.activeBlocked);
|
|
1667
1858
|
return before;
|
|
1668
1859
|
});
|
|
1669
1860
|
};
|
|
@@ -1760,8 +1951,7 @@ const searchImpl = (program, options = {}) => {
|
|
|
1760
1951
|
return driveSearch(state);
|
|
1761
1952
|
};
|
|
1762
1953
|
const search = dual((args) => args.length === 2 || Effect.isEffect(args[0]), searchImpl);
|
|
1763
|
-
|
|
1764
|
-
//#region src/Kernel/Shrink.ts
|
|
1954
|
+
// src/Kernel/Shrink.ts
|
|
1765
1955
|
const failKept = (result) => "failure" in result;
|
|
1766
1956
|
const withoutSteps = (state) => {
|
|
1767
1957
|
const maxSteps = state.maxSteps;
|
|
@@ -1910,8 +2100,7 @@ const shrinkCommandsImpl = (commands, stillFails) => commandsPass({
|
|
|
1910
2100
|
passes: 0
|
|
1911
2101
|
});
|
|
1912
2102
|
const shrinkCommands = dual((args) => Array.isArray(args[0]), shrinkCommandsImpl);
|
|
1913
|
-
|
|
1914
|
-
//#region src/Kernel/TestClock.ts
|
|
2103
|
+
// src/Kernel/TestClock.ts
|
|
1915
2104
|
/**
|
|
1916
2105
|
* The kernel's controllable test clock (R37): what a harness provides in place
|
|
1917
2106
|
* of `TestClock.layer()`. Programs keep calling Effect's `TestClock` API —
|
|
@@ -1936,12 +2125,12 @@ const make = Effect.sync(() => {
|
|
|
1936
2125
|
kernel.clocks.testClocks.push(testClock);
|
|
1937
2126
|
return testClock;
|
|
1938
2127
|
});
|
|
1939
|
-
const contextOf = (testClock) => Context.makeUnsafe(/* @__PURE__ */ new Map([[Clock.Clock.key, testClock]]));
|
|
2128
|
+
const contextOf = (testClock) => Context$1.makeUnsafe(/* @__PURE__ */ new Map([[Clock.Clock.key, testClock]]));
|
|
1940
2129
|
/** The layer a harness provides in place of `TestClock.layer()`. */
|
|
1941
2130
|
const layer = Layer.effectContext(Effect.map(make, contextOf));
|
|
1942
|
-
|
|
1943
|
-
//#region src/Kernel/mod.ts
|
|
2131
|
+
// src/Kernel/mod.ts
|
|
1944
2132
|
var Kernel_exports = /* @__PURE__ */ __exportAll({
|
|
2133
|
+
HostResourcesService: () => HostResourcesService,
|
|
1945
2134
|
PctDepth: () => PctDepth,
|
|
1946
2135
|
PctSeedCount: () => PctSeedCount,
|
|
1947
2136
|
PctStepCount: () => PctStepCount,
|
|
@@ -1950,6 +2139,7 @@ var Kernel_exports = /* @__PURE__ */ __exportAll({
|
|
|
1950
2139
|
currentPreemptionsFor: () => currentPreemptionsFor,
|
|
1951
2140
|
currentProfile: () => currentProfile,
|
|
1952
2141
|
currentSeedsFor: () => currentSeedsFor,
|
|
2142
|
+
fileRequestHooks: () => fileRequestHooks,
|
|
1953
2143
|
isStepping: () => isStepping,
|
|
1954
2144
|
localPreemptions: () => 1,
|
|
1955
2145
|
localSeeds: () => 25,
|
|
@@ -1959,6 +2149,7 @@ var Kernel_exports = /* @__PURE__ */ __exportAll({
|
|
|
1959
2149
|
perChangeSeeds: () => 250,
|
|
1960
2150
|
pick: () => pick,
|
|
1961
2151
|
preemptionsFor: () => preemptionsFor,
|
|
2152
|
+
processResources: () => processResources,
|
|
1962
2153
|
pruned: () => pruned,
|
|
1963
2154
|
run: () => run,
|
|
1964
2155
|
search: () => search,
|
|
@@ -1968,5 +2159,4 @@ var Kernel_exports = /* @__PURE__ */ __exportAll({
|
|
|
1968
2159
|
shrinkCommands: () => shrinkCommands,
|
|
1969
2160
|
unpruned: () => unpruned
|
|
1970
2161
|
});
|
|
1971
|
-
//#endregion
|
|
1972
2162
|
export { Kernel_exports as Kernel };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, flags) => {
|
|
4
|
+
let target = Object.setPrototypeOf({}, null);
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!(flags & 1)) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return flags & 2 ? target : Object.preventExtensions(target);
|
|
11
|
+
};
|
|
12
|
+
export { __exportAll as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@systemfsoftware/effect-sim-kernel",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"author": "Ryan Lee <drdgvhbh@gmail.com>",
|
|
6
6
|
"repository": {
|
|
@@ -32,22 +32,22 @@
|
|
|
32
32
|
"./package.json": "./package.json"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@microsoft/api-extractor": "^7.
|
|
36
|
-
"@systemfsoftware/oxlint-config-recommended": "^
|
|
35
|
+
"@microsoft/api-extractor": "^7.60.1",
|
|
36
|
+
"@systemfsoftware/oxlint-config-recommended": "^8.0.4",
|
|
37
37
|
"@systemfsoftware/tsconfig": "^2.1.0",
|
|
38
|
-
"@systemfsoftware/tsdown-config": "^0.1.
|
|
39
|
-
"@systemfsoftware/vitest": "^4.
|
|
40
|
-
"@systemfsoftware/vitest-config": "^0.1.
|
|
41
|
-
"@types/node": "^26.6.
|
|
42
|
-
"effect": "^4.1.
|
|
43
|
-
"oxlint": "~1.
|
|
44
|
-
"rimraf": "^6.1.
|
|
45
|
-
"tsdown": "^0.23.
|
|
38
|
+
"@systemfsoftware/tsdown-config": "^0.1.3",
|
|
39
|
+
"@systemfsoftware/vitest": "^4.2.0",
|
|
40
|
+
"@systemfsoftware/vitest-config": "^0.1.4",
|
|
41
|
+
"@types/node": "^26.6.6",
|
|
42
|
+
"effect": "^4.1.4",
|
|
43
|
+
"oxlint": "~1.93.0",
|
|
44
|
+
"rimraf": "^6.1.4",
|
|
45
|
+
"tsdown": "^0.23.7",
|
|
46
46
|
"typescript": "^7.0.2",
|
|
47
47
|
"vitest": "^5.1.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"effect": "^4.1.
|
|
50
|
+
"effect": "^4.1.4"
|
|
51
51
|
},
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"access": "public",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"scripts": {
|
|
57
57
|
"clean": "rimraf dist",
|
|
58
58
|
"build": "tsdown -l warn && pnpm api:check",
|
|
59
|
-
"typecheck": "tsc -b",
|
|
59
|
+
"typecheck": "effect-tsgo tsc -b",
|
|
60
60
|
"test": "vitest run",
|
|
61
61
|
"lint": "f=${OXLINT_FORMAT:-${AGENT:+agent}}; oxlint . --format=${f:-default}",
|
|
62
62
|
"api:check": "api-extractor-quiet run",
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __exportAll = (all, no_symbols) => {
|
|
4
|
-
let target = {};
|
|
5
|
-
for (var name in all) __defProp(target, name, {
|
|
6
|
-
get: all[name],
|
|
7
|
-
enumerable: true
|
|
8
|
-
});
|
|
9
|
-
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
-
return target;
|
|
11
|
-
};
|
|
12
|
-
//#endregion
|
|
13
|
-
export { __exportAll as t };
|