@systemfsoftware/effect-sim-kernel 1.0.0 → 2.0.6
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 +2 -44
- package/README.md +13 -0
- package/dist/index.d.ts +56 -16
- package/dist/index.mjs +271 -44
- package/package.json +14 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,47 +1,5 @@
|
|
|
1
1
|
# @systemfsoftware/effect-sim-kernel
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# @systemfsoftware/effect-sim-kernel@2.0.6
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
- Require `effect` `^4` (stable 4.0.0). Release candidates are no longer supported: imports follow 4.0.0's module layout (`effect/http`, `effect/rpc`, `effect/http-api`, `effect/cluster`, `effect/process`, `effect/socket`, `effect/persistence`, `effect/reactivity`, `effect/encoding`, `effect/Arbitrary`), which does not exist in any 4.0.0 RC.
|
|
8
|
-
|
|
9
|
-
## 0.2.0
|
|
10
|
-
|
|
11
|
-
### Minor Changes
|
|
12
|
-
|
|
13
|
-
- The `nightly` profile is removed. `ProfileName` is now `'local' | 'per-change'`, and `CONFORMANCE_PROFILE=nightly` falls back to `per-change` (250 seeds) instead of deriving a seed count from a 1% miss rate. Callers passing `'nightly'` to `Kernel.seedsFor` no longer type-check.
|
|
14
|
-
|
|
15
|
-
- Kernel runs are serialized. A run started while another is live now waits behind it, in arrival order, instead of failing: two runs never interleave, so a scenario never sees another run's decisions, and a suite whose cases drive the kernel can run its tests concurrently.
|
|
16
|
-
|
|
17
|
-
`@systemfsoftware/vitest` adds `captureRunBinding`, the running test's run binding. `bind(effect)` re-provides it to an effect a library runs on a runtime of its own — its own scheduler, a worker, a simulation kernel — so the checks inside it count as that test's assertions, report softly, and see the same `owned` regions.
|
|
18
|
-
|
|
19
|
-
`@systemfsoftware/effect-spec-runtime` runs a case that declares no live reason through that runner, and a case's annotations now reach the test's report.
|
|
20
|
-
|
|
21
|
-
### Patch Changes
|
|
22
|
-
|
|
23
|
-
- Kernel.search enumerates each run's branches in linear time. It used to re-count a schedule's spent preemptions from the start of the run for every branch position, which cost about a fifth of a bounded search's time; the schedules explored are unchanged.
|
|
24
|
-
|
|
25
|
-
## 0.1.1
|
|
26
|
-
|
|
27
|
-
### Minor Changes
|
|
28
|
-
|
|
29
|
-
- The `nightly` profile is removed. `ProfileName` is now `'local' | 'per-change'`, and `CONFORMANCE_PROFILE=nightly` falls back to `per-change` (250 seeds) instead of deriving a seed count from a 1% miss rate. Callers passing `'nightly'` to `Kernel.seedsFor` no longer type-check.
|
|
30
|
-
|
|
31
|
-
## 0.1.0
|
|
32
|
-
|
|
33
|
-
### Minor Changes
|
|
34
|
-
|
|
35
|
-
- Kernel runs in one process queue behind each other in arrival order instead of refusing a second run that starts while one is live. New `Kernel.isStepping()` returns true only while the kernel is executing a step of a run.
|
|
36
|
-
|
|
37
|
-
- New package: a deterministic simulation kernel for Effect v4. `Kernel.run(program, options)` runs any Effect program under a schedule you control and returns its `Exit`, the decisions the schedule took, and a record of which fiber ran at every step. A failed run names why: `Escape` (the program reached a real timer), `Blocked` (it waits on a file or socket outside the process), `Deadlock` (nothing can wake a suspended fiber; every suspended fiber is listed with its frames), or `Runaway`. Replay a run exactly with `path`, steer it with `choose`, and interrupt a fiber at a chosen step with `interrupt`. `external: 'await'` waits for real file and socket I/O on Effect's own order. `Kernel.search`, `Kernel.pct` and `Kernel.shrink` explore schedules up to a stated preemption bound and budget, and shrink a failing schedule to its smallest form. `Kernel.TestClock.layer` stands in for Effect's `TestClock`, so `TestClock.adjust` and `setTime` move the kernel's virtual time. Only one kernel run can be active at a time, and a second one started beside it is refused.
|
|
38
|
-
|
|
39
|
-
A runtime the program starts for itself during a run (`Effect.runFork` or `Effect.runPromise` with no scheduler of its own) runs under the same schedule and virtual clock, and a runtime started after the run finishes runs on the host again.
|
|
40
|
-
|
|
41
|
-
- New `local` conformance profile (`CONFORMANCE_PROFILE=local`): seeded runs use `Kernel.localSeeds` (25) instead of 250, and `Kernel.preemptionsFor` / `Kernel.currentPreemptionsFor` cap a search's preemption bound at `Kernel.localPreemptions` (1). An unset profile is still `per-change`, and `Kernel.search` itself is never capped.
|
|
42
|
-
|
|
43
|
-
- Kernel runs are serialized. A run started while another is live now waits behind it, in arrival order, instead of failing: two runs never interleave, so a scenario never sees another run's decisions, and a suite whose cases drive the kernel can run its tests concurrently.
|
|
44
|
-
|
|
45
|
-
`@systemfsoftware/vitest` adds `captureRunBinding`, the running test's run binding. `bind(effect)` re-provides it to an effect a library runs on a runtime of its own — its own scheduler, a worker, a simulation kernel — so the checks inside it count as that test's assertions, report softly, and see the same `owned` regions.
|
|
46
|
-
|
|
47
|
-
`@systemfsoftware/effect-spec-runtime` runs a case that declares no live reason through that runner, and a case's annotations now reach the test's report.
|
|
5
|
+
Requires Effect ^4.1.4.
|
package/README.md
CHANGED
|
@@ -77,6 +77,19 @@ await Kernel.run(program, { explore: 'body' })
|
|
|
77
77
|
|
|
78
78
|
Decisions before `Kernel.beginExploration` stay on Effect's order and are not recorded.
|
|
79
79
|
|
|
80
|
+
## Seeded schedules
|
|
81
|
+
|
|
82
|
+
`Kernel.pick({ seed, steps })` is a seeded PCT chooser: a seed replays its schedule exactly, and its priority change points fall among the first `steps` explored decisions. `steps` is a `Kernel.PctStepCount`, a whole number of at least 0, usually `Kernel.PctStepCount.make(baseline.decisions.length)`. Its optional `depth` is a `Kernel.PctDepth`, a whole number of at least 1 (`Kernel.PctDepth.make(4)`); it defaults to `Kernel.pctDepth`, 3. `Kernel.seedsFor(baseline, profile)` and `Kernel.currentSeedsFor(baseline)` say how many seeds a baseline run is worth:
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
const baseline = await Kernel.run(program, { explore: 'body' })
|
|
86
|
+
const seeds = await Effect.runPromise(Kernel.currentSeedsFor(baseline))
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
A baseline with a **choice point** — an explored step where more than one runnable task was pending, the running fiber's own continuation included — gets the profile's count: 250 at `per-change`, 25 at `local` (`CONFORMANCE_PROFILE=local`). A baseline without one has a single schedule, so every seed would replay it: it gets 0. The fiber count does not decide this — a fiber forked and interrupted before it ever runs is a choice point, and steps before `Kernel.beginExploration` never count.
|
|
90
|
+
|
|
91
|
+
`Kernel.pct(program)` applies the same rule when no `seeds` option is given, and its `bound.runs` counts the runs it made: 1 for a choice-free program. That one run is judged, and a failure there is reported as seed 0, which replays it. An explicit `seeds` is a `Kernel.PctSeedCount`, a whole number of at least 0, and is always honoured.
|
|
92
|
+
|
|
80
93
|
## Test time
|
|
81
94
|
|
|
82
95
|
Every clock the program can reach is the kernel's virtual root clock: time moves only when nothing can run, no in-process wait reaches a real timer, and a program that touches one fails the run.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Clock, Config, Duration, Effect, Exit, Fiber, Layer, Scheduler } from "effect";
|
|
1
|
+
import { Clock, Config, Duration, Effect, Exit, Fiber, Layer, Scheduler, Schema } from "effect";
|
|
2
2
|
//#region src/Kernel/Bound.d.ts
|
|
3
3
|
type UnobservedPrimitive = 'Queue' | 'PubSub' | 'Semaphore' | 'Latch' | 'Scope finalizer';
|
|
4
4
|
interface Pruning {
|
|
@@ -15,6 +15,14 @@ interface Bound {
|
|
|
15
15
|
}
|
|
16
16
|
declare const pruned: Pruning;
|
|
17
17
|
declare const unpruned: (disabledBy: ReadonlyArray<UnobservedPrimitive>) => Pruning;
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/Kernel/Pct.schema.d.ts
|
|
20
|
+
declare const PctDepth: Schema.brand<Schema.Int, "PctDepth">;
|
|
21
|
+
type PctDepth = typeof PctDepth.Type;
|
|
22
|
+
declare const PctSeedCount: Schema.brand<Schema.Int, "PctSeedCount">;
|
|
23
|
+
type PctSeedCount = typeof PctSeedCount.Type;
|
|
24
|
+
declare const PctStepCount: Schema.brand<Schema.Int, "PctStepCount">;
|
|
25
|
+
type PctStepCount = typeof PctStepCount.Type;
|
|
18
26
|
declare namespace TestClock_d_exports {
|
|
19
27
|
export { TestClock, layer, make };
|
|
20
28
|
}
|
|
@@ -104,6 +112,31 @@ interface StepRecord {
|
|
|
104
112
|
* it can change the outcome. Seam for preemption-bounded search (pruning).
|
|
105
113
|
*/
|
|
106
114
|
readonly visible: boolean;
|
|
115
|
+
readonly boundary: BoundaryKind | undefined;
|
|
116
|
+
readonly activeBlocked: boolean;
|
|
117
|
+
readonly runnableFibers: ReadonlyArray<number | undefined>;
|
|
118
|
+
}
|
|
119
|
+
/** @internal */
|
|
120
|
+
type BoundaryKind = 'auto-yield' | 'explicit-yield';
|
|
121
|
+
/** @internal */
|
|
122
|
+
interface BoundaryRecord {
|
|
123
|
+
readonly step: number;
|
|
124
|
+
readonly kind: BoundaryKind;
|
|
125
|
+
readonly activeFiber: number | undefined;
|
|
126
|
+
readonly runnableFibers: ReadonlyArray<number | undefined>;
|
|
127
|
+
readonly chosenFiber: number | undefined;
|
|
128
|
+
readonly preempted: boolean;
|
|
129
|
+
}
|
|
130
|
+
/** @internal */
|
|
131
|
+
interface TraceSnapshot {
|
|
132
|
+
readonly boundary: BoundaryKind | undefined;
|
|
133
|
+
readonly runnable: ReadonlyArray<number | undefined>;
|
|
134
|
+
}
|
|
135
|
+
/** @internal */
|
|
136
|
+
interface TraceDivergence {
|
|
137
|
+
readonly atStep: number;
|
|
138
|
+
readonly expected: TraceSnapshot | undefined;
|
|
139
|
+
readonly actual: TraceSnapshot | undefined;
|
|
107
140
|
}
|
|
108
141
|
/** Which fiber an interruption names (R5). */
|
|
109
142
|
/** @internal */
|
|
@@ -147,6 +180,9 @@ declare const runOutcomeTags: {
|
|
|
147
180
|
readonly runaway: {
|
|
148
181
|
readonly _tag: 'Runaway';
|
|
149
182
|
};
|
|
183
|
+
readonly replayTraceDiverged: {
|
|
184
|
+
readonly _tag: 'ReplayTraceDiverged';
|
|
185
|
+
};
|
|
150
186
|
};
|
|
151
187
|
/** @internal */
|
|
152
188
|
type RunCompleted<A, E> = RunHistory & typeof runOutcomeTags.completed & {
|
|
@@ -160,6 +196,7 @@ type RunFailed = RunHistory & typeof runOutcomeTags.failed & {
|
|
|
160
196
|
interface RunHistory {
|
|
161
197
|
/** Which fiber ran at each step, in order (R3). */
|
|
162
198
|
readonly steps: ReadonlyArray<StepRecord>;
|
|
199
|
+
readonly boundaries: ReadonlyArray<BoundaryRecord>;
|
|
163
200
|
/** The decisions the schedule explored, in order (R4's replayable path). */
|
|
164
201
|
readonly decisions: ReadonlyArray<Decision>;
|
|
165
202
|
}
|
|
@@ -186,7 +223,13 @@ type RunawayFailure = typeof runOutcomeTags.runaway & {
|
|
|
186
223
|
readonly pending: number;
|
|
187
224
|
};
|
|
188
225
|
/** @internal */
|
|
189
|
-
type
|
|
226
|
+
type ReplayTraceDivergedFailure = typeof runOutcomeTags.replayTraceDiverged & {
|
|
227
|
+
readonly atStep: number;
|
|
228
|
+
readonly expected: TraceSnapshot | undefined;
|
|
229
|
+
readonly actual: TraceSnapshot | undefined;
|
|
230
|
+
};
|
|
231
|
+
/** @internal */
|
|
232
|
+
type RunFailure = EscapeFailure | BlockedFailure | DeadlockFailure | RunawayFailure | ReplayTraceDivergedFailure;
|
|
190
233
|
/** @internal */
|
|
191
234
|
interface Interruption {
|
|
192
235
|
/** The one-based step after whose task the fiber is interrupted. */
|
|
@@ -201,6 +244,7 @@ interface RunOptions {
|
|
|
201
244
|
* or a step past the end of the path, takes Effect's order.
|
|
202
245
|
*/
|
|
203
246
|
readonly path?: ReadonlyArray<Decision | undefined>;
|
|
247
|
+
readonly expectTrace?: ReadonlyArray<TraceSnapshot>;
|
|
204
248
|
/**
|
|
205
249
|
* Chooses beyond the recorded path (seam for PCT and bounded search).
|
|
206
250
|
* Returning undefined takes the zero-preemption choice.
|
|
@@ -252,14 +296,14 @@ declare const run: {
|
|
|
252
296
|
//#region src/Kernel/Pct.d.ts
|
|
253
297
|
interface PickOptions {
|
|
254
298
|
readonly seed: number;
|
|
255
|
-
readonly depth?:
|
|
256
|
-
readonly steps:
|
|
299
|
+
readonly depth?: PctDepth;
|
|
300
|
+
readonly steps: PctStepCount;
|
|
257
301
|
}
|
|
258
302
|
declare const pick: (options: PickOptions) => (choice: Choice) => Decision | undefined;
|
|
259
303
|
interface PctOptions<A, E> {
|
|
260
|
-
readonly seeds?:
|
|
261
|
-
readonly depth?:
|
|
262
|
-
readonly steps?:
|
|
304
|
+
readonly seeds?: PctSeedCount;
|
|
305
|
+
readonly depth?: PctDepth;
|
|
306
|
+
readonly steps?: PctStepCount;
|
|
263
307
|
readonly isFailure?: (result: RunResult<A, E>) => boolean;
|
|
264
308
|
readonly maxSteps?: number;
|
|
265
309
|
}
|
|
@@ -284,20 +328,16 @@ declare const pct: {
|
|
|
284
328
|
* not the verdict: the same checks run at the per-change budget in CI.
|
|
285
329
|
*/
|
|
286
330
|
type ProfileName = 'local' | 'per-change';
|
|
287
|
-
declare const pctDepth
|
|
331
|
+
declare const pctDepth: PctDepth;
|
|
288
332
|
declare const perChangeSeeds = 250;
|
|
289
333
|
declare const localSeeds = 25;
|
|
290
334
|
declare const localPreemptions = 1;
|
|
291
335
|
declare const currentProfile: Effect.Effect<ProfileName, Config.ConfigError>;
|
|
292
|
-
interface Budget {
|
|
293
|
-
readonly fibers: number;
|
|
294
|
-
readonly steps: number;
|
|
295
|
-
}
|
|
296
336
|
declare const seedsFor: {
|
|
297
|
-
(
|
|
298
|
-
(profile?: ProfileName): (
|
|
337
|
+
(baseline: RunHistory, profile?: ProfileName): number;
|
|
338
|
+
(profile?: ProfileName): (baseline: RunHistory) => number;
|
|
299
339
|
};
|
|
300
|
-
declare const currentSeedsFor: (
|
|
340
|
+
declare const currentSeedsFor: (baseline: RunHistory) => Effect.Effect<number, Config.ConfigError>;
|
|
301
341
|
declare const preemptionsFor: {
|
|
302
342
|
(requested: number | undefined, profile: ProfileName): number | undefined;
|
|
303
343
|
(profile: ProfileName): (requested: number | undefined) => number | undefined;
|
|
@@ -367,7 +407,7 @@ declare const shrinkCommands: {
|
|
|
367
407
|
<C>(stillFails: (candidate: ReadonlyArray<C>) => Promise<boolean>): (commands: ReadonlyArray<C>) => Promise<ReadonlyArray<C>>;
|
|
368
408
|
};
|
|
369
409
|
declare namespace mod_d_exports {
|
|
370
|
-
export { AnyFiber, BlockedFailure, Bound,
|
|
410
|
+
export { AnyFiber, BlockedFailure, Bound, BoundaryKind, BoundaryRecord, Choice, ChoiceOption, DeadlockFailure, Decision, Escape, EscapeFailure, FiberTarget, 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, isStepping, localPreemptions, localSeeds, runOutcomeTags as outcomeTags, pct, pctDepth, perChangeSeeds, pick, preemptionsFor, pruned, run, search, searchTags, seedsFor, shrink, shrinkCommands, unpruned };
|
|
371
411
|
}
|
|
372
412
|
//#endregion
|
|
373
413
|
export { mod_d_exports as Kernel };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
-
import { Clock, Config, Context, Deferred, Duration, Effect, Latch, Layer, Match, Option, PubSub, Queue, Ref, Scheduler, Scope, Semaphore } from "effect";
|
|
2
|
+
import { Clock, Config, Context, Deferred, Duration, Effect, Latch, Layer, Match, Option, Order, PubSub, Queue, Ref, Scheduler, Schema, Scope, Semaphore } from "effect";
|
|
3
3
|
import { dual } from "effect/Function";
|
|
4
4
|
//#region src/Kernel/Bound.ts
|
|
5
5
|
const pruned = {
|
|
@@ -10,24 +10,29 @@ const unpruned = (disabledBy) => ({
|
|
|
10
10
|
enabled: false,
|
|
11
11
|
disabledBy
|
|
12
12
|
});
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/Kernel/Pct.schema.ts
|
|
15
|
+
const generatedBetween = (minimum, maximum) => Schema.makeFilter(() => void 0, { arbitraryConstraint: {
|
|
16
|
+
order: Order.Number,
|
|
17
|
+
minimum,
|
|
18
|
+
maximum
|
|
19
|
+
} });
|
|
20
|
+
const PctDepth = Schema.Int.pipe(Schema.check(Schema.isBetween({
|
|
21
|
+
minimum: 1,
|
|
22
|
+
maximum: Number.MAX_SAFE_INTEGER
|
|
23
|
+
}, { message: "a PCT depth is a whole number of at least 1" })), Schema.check(generatedBetween(1, 5)), Schema.brand("PctDepth"));
|
|
24
|
+
const PctSeedCount = Schema.Int.pipe(Schema.check(Schema.isBetween({
|
|
25
|
+
minimum: 0,
|
|
26
|
+
maximum: Number.MAX_SAFE_INTEGER
|
|
27
|
+
}, { message: "a PCT seed count is a whole number of at least 0" })), Schema.check(generatedBetween(0, 3)), Schema.brand("PctSeedCount"));
|
|
28
|
+
const PctStepCount = Schema.Int.pipe(Schema.check(Schema.isBetween({
|
|
29
|
+
minimum: 0,
|
|
30
|
+
maximum: Number.MAX_SAFE_INTEGER
|
|
31
|
+
}, { message: "a PCT step count is a whole number of explored decisions, at least 0" })), Schema.check(generatedBetween(0, 1e4)), Schema.brand("PctStepCount"));
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/internal/profile.schema.ts
|
|
34
|
+
/** @internal */
|
|
35
|
+
const ProfileNames = Schema.Literals(["local", "per-change"]);
|
|
31
36
|
//#endregion
|
|
32
37
|
//#region src/internal/clocks.ts
|
|
33
38
|
/**
|
|
@@ -191,7 +196,8 @@ const FIBER_METHODS = [
|
|
|
191
196
|
"addObserver",
|
|
192
197
|
"interruptUnsafe",
|
|
193
198
|
"pollUnsafe",
|
|
194
|
-
"evaluate"
|
|
199
|
+
"evaluate",
|
|
200
|
+
"yieldNow"
|
|
195
201
|
];
|
|
196
202
|
const REF_FIELDS = ["ref"];
|
|
197
203
|
const DEFERRED_FIELDS = ["effect", "resumes"];
|
|
@@ -407,10 +413,33 @@ const dispatchObserved = (fiber, kernel, original, args) => {
|
|
|
407
413
|
noteOtherFiberWork(fiber, kernel);
|
|
408
414
|
return applyOriginal(original, fiber, args);
|
|
409
415
|
};
|
|
416
|
+
/**
|
|
417
|
+
* The fibers whose original `evaluate` is on the stack right now. Effect 4.0.1
|
|
418
|
+
* restores a fiber's async context by calling `evaluate` again from inside its
|
|
419
|
+
* own evaluation (`FiberImpl.evaluate` re-enters through
|
|
420
|
+
* `AsyncResource.runInAsyncScope`), so one resume arrives as two nested calls.
|
|
421
|
+
* The nested call is that first resume continuing, not a new one: running the
|
|
422
|
+
* original inline keeps a resume one kernel step, as it was under 4.0.0, where
|
|
423
|
+
* queueing the nested call would spend an extra step on every slice. Only the
|
|
424
|
+
* outermost call marks the fiber; a nested call returns before marking, so the
|
|
425
|
+
* slot never outlives the evaluation it names.
|
|
426
|
+
*/
|
|
427
|
+
const evaluating = /* @__PURE__ */ new WeakSet();
|
|
428
|
+
const withEvaluation = (fiber, run) => {
|
|
429
|
+
evaluating.add(fiber);
|
|
430
|
+
try {
|
|
431
|
+
return run();
|
|
432
|
+
} finally {
|
|
433
|
+
evaluating.delete(fiber);
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
const isEvaluating = (fiber) => evaluating.has(fiber);
|
|
410
437
|
const isResumableBy = (fiber, kernel) => fiber.pollUnsafe() === void 0 && dispatcherOf(fiber) === kernel.dispatcher;
|
|
411
438
|
const isResumingRun = (fiber, kernel) => kernel.running && isResumableBy(fiber, kernel);
|
|
412
439
|
const resumeExternallyThrough = (fiber, kernel, original, args) => {
|
|
413
|
-
kernel.resumeExternally(fiber, () =>
|
|
440
|
+
kernel.resumeExternally(fiber, () => {
|
|
441
|
+
withEvaluation(fiber, () => applyOriginal(original, fiber, args));
|
|
442
|
+
});
|
|
414
443
|
};
|
|
415
444
|
/**
|
|
416
445
|
* A fiber's first evaluation inside a step is a start, not a resume: Effect runs
|
|
@@ -421,12 +450,15 @@ const resumeExternallyThrough = (fiber, kernel, original, args) => {
|
|
|
421
450
|
const startsInStep = (fiber, kernel) => kernel.firstEvaluation(fiber) && kernel.phase === "step";
|
|
422
451
|
const queuedOrObserved = (fiber, kernel, original, args) => {
|
|
423
452
|
if (isResumingRun(fiber, kernel)) return resumeExternallyThrough(fiber, kernel, original, args);
|
|
424
|
-
return dispatchObserved(fiber, kernel, original, args);
|
|
453
|
+
return withEvaluation(fiber, () => dispatchObserved(fiber, kernel, original, args));
|
|
425
454
|
};
|
|
426
|
-
const
|
|
427
|
-
if (startsInStep(fiber, kernel)) return dispatchObserved(fiber, kernel, original, args);
|
|
455
|
+
const dispatchOutermost = (fiber, kernel, original, args) => {
|
|
456
|
+
if (startsInStep(fiber, kernel)) return withEvaluation(fiber, () => dispatchObserved(fiber, kernel, original, args));
|
|
428
457
|
return queuedOrObserved(fiber, kernel, original, args);
|
|
429
458
|
};
|
|
459
|
+
const isAutomaticResume = (fiber) => Reflect.get(fiber, "_autoYielded") === true;
|
|
460
|
+
const dispatchResumption = (fiber, kernel, original, args) => isAutomaticResume(fiber) ? withEvaluation(fiber, () => dispatchObserved(fiber, kernel, original, args)) : dispatchOutermost(fiber, kernel, original, args);
|
|
461
|
+
const dispatchEvaluate = (fiber, kernel, original, args) => isEvaluating(fiber) ? dispatchObserved(fiber, kernel, original, args) : dispatchResumption(fiber, kernel, original, args);
|
|
430
462
|
const interruptAgain = (fiber, args) => () => {
|
|
431
463
|
Reflect.apply(Reflect.get(fiber, "interruptUnsafe"), fiber, args);
|
|
432
464
|
};
|
|
@@ -434,13 +466,18 @@ const dispatchInterrupt = (fiber, kernel, original, args) => {
|
|
|
434
466
|
if (kernel.afterQueuedResume(fiber, interruptAgain(fiber, args))) return void 0;
|
|
435
467
|
return dispatchObserved(fiber, kernel, original, args);
|
|
436
468
|
};
|
|
437
|
-
const
|
|
469
|
+
const dispatchYieldNow = (fiber, kernel, original, args) => {
|
|
470
|
+
kernel.noteYieldBoundary(args[2] === true ? "auto-yield" : "explicit-yield", fiber);
|
|
471
|
+
return dispatchObserved(fiber, kernel, original, args);
|
|
472
|
+
};
|
|
473
|
+
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)));
|
|
438
474
|
/** @internal */
|
|
439
475
|
const makeKernel = (options) => {
|
|
440
476
|
const pending = [];
|
|
441
477
|
const fibers = /* @__PURE__ */ new Set();
|
|
442
478
|
const evaluated = /* @__PURE__ */ new WeakSet();
|
|
443
479
|
const steps = [];
|
|
480
|
+
const boundaries = [];
|
|
444
481
|
const decisions = [];
|
|
445
482
|
const escapes = [];
|
|
446
483
|
const touches = /* @__PURE__ */ new Set();
|
|
@@ -465,6 +502,14 @@ const makeKernel = (options) => {
|
|
|
465
502
|
let root = void 0;
|
|
466
503
|
let running = false;
|
|
467
504
|
let restoreHooks = void 0;
|
|
505
|
+
let yieldBoundary = void 0;
|
|
506
|
+
let yieldBoundaryFiber = void 0;
|
|
507
|
+
let boundaryForStep = void 0;
|
|
508
|
+
let boundaryActiveForStep = void 0;
|
|
509
|
+
let runnableAtDecision = [];
|
|
510
|
+
let traceDivergence = void 0;
|
|
511
|
+
const appearanceOrder = /* @__PURE__ */ new Map();
|
|
512
|
+
let appearances = 0;
|
|
468
513
|
const taskAt = (index) => pending[index];
|
|
469
514
|
const stepOn = (task) => task === void 0 ? -1 : task.step;
|
|
470
515
|
const stepAt = (index) => stepOn(taskAt(index));
|
|
@@ -572,6 +617,20 @@ const makeKernel = (options) => {
|
|
|
572
617
|
const endStep = () => {
|
|
573
618
|
phase = "paused";
|
|
574
619
|
};
|
|
620
|
+
const clearBoundary = () => {
|
|
621
|
+
boundaryForStep = void 0;
|
|
622
|
+
boundaryActiveForStep = void 0;
|
|
623
|
+
};
|
|
624
|
+
const captureBoundary = () => {
|
|
625
|
+
if (yieldBoundary === void 0) return;
|
|
626
|
+
boundaryForStep = yieldBoundary;
|
|
627
|
+
boundaryActiveForStep = yieldBoundaryFiber;
|
|
628
|
+
yieldBoundary = void 0;
|
|
629
|
+
yieldBoundaryFiber = void 0;
|
|
630
|
+
};
|
|
631
|
+
const runnableIds = (tasks) => tasks.map((task) => task.owner?.id);
|
|
632
|
+
const ownerPending = (fiber) => fiber !== void 0 && pending.some((task) => task.owner === fiber);
|
|
633
|
+
const sameRunnable = (left, right) => left.length === right.length && left.every((id, index) => id === right[index]);
|
|
575
634
|
const ranOn = (task) => ranInTask ?? task.owner;
|
|
576
635
|
const runTask = (task) => {
|
|
577
636
|
beginStep();
|
|
@@ -585,8 +644,52 @@ const makeKernel = (options) => {
|
|
|
585
644
|
const touchesFiber = (ran) => ran !== void 0 && touches.has(ran);
|
|
586
645
|
const extraScheduling = () => scheduledInStep > 1 || globalWorkThisStep;
|
|
587
646
|
const sharedWork = (ran) => extraScheduling() || touchesFiber(ran);
|
|
588
|
-
const isVisible = (task, ran) =>
|
|
589
|
-
|
|
647
|
+
const isVisible = (task, ran) => [
|
|
648
|
+
task.external,
|
|
649
|
+
sharedWork(ran),
|
|
650
|
+
touches.size > 0
|
|
651
|
+
].some(Boolean);
|
|
652
|
+
const expectedAt = (step) => options.expectTrace?.[step - 1];
|
|
653
|
+
const knownAppearance = (id) => appearanceOrder.get(id);
|
|
654
|
+
const noteAppearance = (id) => {
|
|
655
|
+
appearances += 1;
|
|
656
|
+
appearanceOrder.set(id, appearances);
|
|
657
|
+
return appearances;
|
|
658
|
+
};
|
|
659
|
+
const appearanceOf = (id) => {
|
|
660
|
+
if (id === void 0) return void 0;
|
|
661
|
+
return appearanceFor(id);
|
|
662
|
+
};
|
|
663
|
+
const appearanceFor = (id) => knownAppearance(id) ?? noteAppearance(id);
|
|
664
|
+
const normalizedRunnable = () => runnableAtDecision.map(appearanceOf);
|
|
665
|
+
const divergedAlready = () => traceDivergence !== void 0;
|
|
666
|
+
const runnableMatches = (expected, actual) => sameRunnable(expected.runnable, actual.runnable);
|
|
667
|
+
const traceMatches = (expected, actual) => [expected.boundary === actual.boundary, runnableMatches(expected, actual)].every(Boolean);
|
|
668
|
+
const snapshotOf = (record) => ({
|
|
669
|
+
boundary: record.boundary,
|
|
670
|
+
runnable: record.runnableFibers
|
|
671
|
+
});
|
|
672
|
+
const traceMismatch = (record) => (expected) => (actual) => [traceMatches(expected, actual)].every(Boolean) ? void 0 : {
|
|
673
|
+
atStep: record.step,
|
|
674
|
+
expected,
|
|
675
|
+
actual
|
|
676
|
+
};
|
|
677
|
+
const mismatchAt = (record) => {
|
|
678
|
+
const expected = expectedAt(record.step);
|
|
679
|
+
if (expected === void 0) return extraStepDivergence(record);
|
|
680
|
+
return traceMismatch(record)(expected)(snapshotOf(record));
|
|
681
|
+
};
|
|
682
|
+
const extraStepDivergence = (record) => ({
|
|
683
|
+
atStep: record.step,
|
|
684
|
+
expected: void 0,
|
|
685
|
+
actual: snapshotOf(record)
|
|
686
|
+
});
|
|
687
|
+
const tracing = () => options.expectTrace !== void 0;
|
|
688
|
+
const checkTrace = (record) => {
|
|
689
|
+
if ([divergedAlready(), !tracing()].some(Boolean)) return;
|
|
690
|
+
traceDivergence = mismatchAt(record);
|
|
691
|
+
};
|
|
692
|
+
const stepRecord = (input, task, ran, boundary, activeBlocked, runnable) => ({
|
|
590
693
|
step: stepCount,
|
|
591
694
|
choice: input.choice,
|
|
592
695
|
options: input.options,
|
|
@@ -595,12 +698,40 @@ const makeKernel = (options) => {
|
|
|
595
698
|
forced: task.forced,
|
|
596
699
|
external: task.external,
|
|
597
700
|
fiberId: ran?.id,
|
|
598
|
-
visible: isVisible(task, ran)
|
|
701
|
+
visible: isVisible(task, ran),
|
|
702
|
+
boundary,
|
|
703
|
+
activeBlocked,
|
|
704
|
+
runnableFibers: runnable
|
|
599
705
|
});
|
|
706
|
+
const boundaryPreempted = (chosenId, activeId) => [chosenId !== activeId, runnableAtDecision.includes(activeId)].every(Boolean);
|
|
707
|
+
const ranId = (ran) => ran?.id;
|
|
708
|
+
const boundaryActiveId = () => boundaryActiveForStep?.id;
|
|
709
|
+
const boundaryRecordFor = (kind, ran) => ({
|
|
710
|
+
step: stepCount,
|
|
711
|
+
kind,
|
|
712
|
+
activeFiber: boundaryActiveId(),
|
|
713
|
+
runnableFibers: runnableAtDecision,
|
|
714
|
+
chosenFiber: ranId(ran),
|
|
715
|
+
preempted: boundaryPreempted(ranId(ran), boundaryActiveId())
|
|
716
|
+
});
|
|
717
|
+
const recordBoundary = (ran) => {
|
|
718
|
+
const kind = boundaryForStep;
|
|
719
|
+
if (kind === void 0) return;
|
|
720
|
+
boundaries.push(boundaryRecordFor(kind, ran));
|
|
721
|
+
};
|
|
722
|
+
const hasLastRan = () => lastRan !== void 0;
|
|
723
|
+
const previousBlocked = () => hasLastRan() && !ownerPending(lastRan);
|
|
724
|
+
const recordDecision = (input) => {
|
|
725
|
+
if (exploring) decisions.push(input.choice);
|
|
726
|
+
};
|
|
600
727
|
const recordStep = (input, task, ran) => {
|
|
728
|
+
const runnable = normalizedRunnable();
|
|
729
|
+
const record = stepRecord(input, task, ran, boundaryForStep, previousBlocked(), runnable);
|
|
730
|
+
checkTrace(record);
|
|
731
|
+
recordBoundary(ran);
|
|
601
732
|
lastRan = ran;
|
|
602
|
-
steps.push(
|
|
603
|
-
|
|
733
|
+
steps.push(record);
|
|
734
|
+
recordDecision(input);
|
|
604
735
|
};
|
|
605
736
|
const queuedResumeOf = (fiber) => (task) => task.external && task.owner === fiber;
|
|
606
737
|
const afterQueuedResume = (fiber, after) => {
|
|
@@ -623,6 +754,9 @@ const makeKernel = (options) => {
|
|
|
623
754
|
return task;
|
|
624
755
|
};
|
|
625
756
|
const step = (input) => {
|
|
757
|
+
clearBoundary();
|
|
758
|
+
captureBoundary();
|
|
759
|
+
runnableAtDecision = runnableIds(pending);
|
|
626
760
|
const task = takeTask(input.choice);
|
|
627
761
|
if (task === void 0) throw new Error(`effect-sim-kernel: no task to run at decision ${input.choice}`);
|
|
628
762
|
const ran = runTask(task);
|
|
@@ -643,6 +777,7 @@ const makeKernel = (options) => {
|
|
|
643
777
|
pending,
|
|
644
778
|
fibers,
|
|
645
779
|
steps,
|
|
780
|
+
boundaries,
|
|
646
781
|
decisions,
|
|
647
782
|
escapes,
|
|
648
783
|
scheduler,
|
|
@@ -660,6 +795,9 @@ const makeKernel = (options) => {
|
|
|
660
795
|
get running() {
|
|
661
796
|
return running;
|
|
662
797
|
},
|
|
798
|
+
get traceDivergence() {
|
|
799
|
+
return traceDivergence;
|
|
800
|
+
},
|
|
663
801
|
start: (started) => {
|
|
664
802
|
root = started;
|
|
665
803
|
running = true;
|
|
@@ -680,6 +818,11 @@ const makeKernel = (options) => {
|
|
|
680
818
|
});
|
|
681
819
|
scheduledInStep++;
|
|
682
820
|
},
|
|
821
|
+
noteYieldBoundary: (kind, fiber) => {
|
|
822
|
+
if (phase !== "step") return;
|
|
823
|
+
yieldBoundary = kind;
|
|
824
|
+
yieldBoundaryFiber = fiber;
|
|
825
|
+
},
|
|
683
826
|
firstEvaluation: (fiber) => {
|
|
684
827
|
if (evaluated.has(fiber)) return false;
|
|
685
828
|
evaluated.add(fiber);
|
|
@@ -913,7 +1056,8 @@ const runOutcomeTags = {
|
|
|
913
1056
|
escape: { _tag: "Escape" },
|
|
914
1057
|
blocked: { _tag: "Blocked" },
|
|
915
1058
|
deadlock: { _tag: "Deadlock" },
|
|
916
|
-
runaway: { _tag: "Runaway" }
|
|
1059
|
+
runaway: { _tag: "Runaway" },
|
|
1060
|
+
replayTraceDiverged: { _tag: "ReplayTraceDiverged" }
|
|
917
1061
|
};
|
|
918
1062
|
const DEFAULT_MAX_STEPS = 5e4;
|
|
919
1063
|
const DEFAULT_STEP_TURNS = 4;
|
|
@@ -1018,14 +1162,24 @@ const completedOn = (kernel, exit) => ({
|
|
|
1018
1162
|
...runOutcomeTags.completed,
|
|
1019
1163
|
exit,
|
|
1020
1164
|
steps: kernel.steps,
|
|
1165
|
+
boundaries: kernel.boundaries,
|
|
1021
1166
|
decisions: kernel.decisions
|
|
1022
1167
|
});
|
|
1023
1168
|
const failedOn = (kernel, failure) => ({
|
|
1024
1169
|
...runOutcomeTags.failed,
|
|
1025
1170
|
failure,
|
|
1026
1171
|
steps: kernel.steps,
|
|
1172
|
+
boundaries: kernel.boundaries,
|
|
1027
1173
|
decisions: kernel.decisions
|
|
1028
1174
|
});
|
|
1175
|
+
const replayDivergedOf = (kernel) => {
|
|
1176
|
+
const divergence = kernel.traceDivergence;
|
|
1177
|
+
if (divergence === void 0) return void 0;
|
|
1178
|
+
return {
|
|
1179
|
+
...runOutcomeTags.replayTraceDiverged,
|
|
1180
|
+
...divergence
|
|
1181
|
+
};
|
|
1182
|
+
};
|
|
1029
1183
|
const interruptLive = (kernel, fiber) => {
|
|
1030
1184
|
if (fiber !== void 0) kernel.interrupt(fiber);
|
|
1031
1185
|
};
|
|
@@ -1041,7 +1195,12 @@ const applyInterrupt = (kernel, options) => {
|
|
|
1041
1195
|
const advance$1 = (state) => {
|
|
1042
1196
|
state.kernel.step(decide(state.kernel, state.options));
|
|
1043
1197
|
applyInterrupt(state.kernel, state.options);
|
|
1044
|
-
return drain(stepTurnsOf(state.options));
|
|
1198
|
+
return drain(stepTurnsOf(state.options)).then(() => divergedResult(state));
|
|
1199
|
+
};
|
|
1200
|
+
const divergedResult = (state) => {
|
|
1201
|
+
const failure = replayDivergedOf(state.kernel);
|
|
1202
|
+
if (failure === void 0) return void 0;
|
|
1203
|
+
return failedOn(state.kernel, failure);
|
|
1045
1204
|
};
|
|
1046
1205
|
const seamOffersProgress = (seam) => seam !== void 0 && seam();
|
|
1047
1206
|
const resettled = (state) => {
|
|
@@ -1051,14 +1210,31 @@ const resettled = (state) => {
|
|
|
1051
1210
|
const stalled = (state) => drain(quiescenceTurnsOf(state.options)).then(() => resettled(state));
|
|
1052
1211
|
const quiescent = (state) => {
|
|
1053
1212
|
const exit = state.root.pollUnsafe();
|
|
1054
|
-
if (exit !== void 0) return Promise.resolve(
|
|
1213
|
+
if (exit !== void 0) return Promise.resolve(completedOrShortTrace(state, exit));
|
|
1055
1214
|
return stalled(state);
|
|
1056
1215
|
};
|
|
1216
|
+
const completedOrShortTrace = (state, exit) => {
|
|
1217
|
+
const short = shortTraceFailure(state.options.expectTrace, state.kernel.steps.length);
|
|
1218
|
+
if (short === void 0) return completedOn(state.kernel, exit);
|
|
1219
|
+
return failedOn(state.kernel, short);
|
|
1220
|
+
};
|
|
1221
|
+
const shortTraceFailure = (expectTrace, steps) => {
|
|
1222
|
+
if (traceLongEnough(expectTrace, steps)) return void 0;
|
|
1223
|
+
return shortDivergence(expectTrace, steps);
|
|
1224
|
+
};
|
|
1225
|
+
const expectAtIndex = (expectTrace, index) => expectTrace?.[index];
|
|
1226
|
+
const shortDivergence = (expectTrace, steps) => ({
|
|
1227
|
+
...runOutcomeTags.replayTraceDiverged,
|
|
1228
|
+
atStep: steps + 1,
|
|
1229
|
+
expected: expectAtIndex(expectTrace, steps),
|
|
1230
|
+
actual: void 0
|
|
1231
|
+
});
|
|
1232
|
+
const traceLongEnough = (expectTrace, steps) => expectTrace === void 0 || steps >= expectTrace.length;
|
|
1057
1233
|
const settled$1 = (state) => {
|
|
1058
1234
|
if (state.kernel.pending.length > 0) return Promise.resolve(void 0);
|
|
1059
1235
|
return quiescent(state);
|
|
1060
1236
|
};
|
|
1061
|
-
const progressed = (state, done) => done !== void 0 ? Promise.resolve(done) : advance$1(state)
|
|
1237
|
+
const progressed = (state, done) => done !== void 0 ? Promise.resolve(done) : advance$1(state);
|
|
1062
1238
|
const escapeOrRunaway = (kernel, options, guard) => {
|
|
1063
1239
|
const escaped = kernel.escapes[0];
|
|
1064
1240
|
if (escaped !== void 0) return escapeFailureOf(escaped);
|
|
@@ -1081,6 +1257,7 @@ const continued = (state, halted) => halted !== void 0 ? Promise.resolve(halted)
|
|
|
1081
1257
|
const drive = (state) => iteration(state).then((halted) => continued(state, halted));
|
|
1082
1258
|
const RUN_OPTION_KEYS = [
|
|
1083
1259
|
"choose",
|
|
1260
|
+
"expectTrace",
|
|
1084
1261
|
"explore",
|
|
1085
1262
|
"external",
|
|
1086
1263
|
"interrupt",
|
|
@@ -1103,7 +1280,10 @@ const isProgram = (candidate) => !isRunOptions(candidate);
|
|
|
1103
1280
|
* active queues behind it, so two runs never share the global hooks.
|
|
1104
1281
|
*/
|
|
1105
1282
|
const lockedRun = (program, options, release) => {
|
|
1106
|
-
const kernel = makeKernel({
|
|
1283
|
+
const kernel = makeKernel({
|
|
1284
|
+
exploring: options.explore !== "body",
|
|
1285
|
+
expectTrace: options.expectTrace
|
|
1286
|
+
});
|
|
1107
1287
|
const recorder = installEscapeRecorder((escape) => {
|
|
1108
1288
|
kernel.escapes.push(escape);
|
|
1109
1289
|
});
|
|
@@ -1149,6 +1329,42 @@ const runImpl = (program, options = {}) => {
|
|
|
1149
1329
|
/** @internal */
|
|
1150
1330
|
const run = dual((args) => args.length > 0 && isProgram(args[0]), runImpl);
|
|
1151
1331
|
//#endregion
|
|
1332
|
+
//#region src/Kernel/Profile.ts
|
|
1333
|
+
const pctDepth = PctDepth.make(3);
|
|
1334
|
+
const isProfileName = Schema.is(ProfileNames);
|
|
1335
|
+
const profileOf = (name) => isProfileName(name) ? name : "per-change";
|
|
1336
|
+
const currentProfile = Effect.map(Config.option(Config.String("CONFORMANCE_PROFILE")), Option.match({
|
|
1337
|
+
onNone: () => profileOf(""),
|
|
1338
|
+
onSome: profileOf
|
|
1339
|
+
}));
|
|
1340
|
+
const SEEDS = {
|
|
1341
|
+
local: 25,
|
|
1342
|
+
"per-change": 250
|
|
1343
|
+
};
|
|
1344
|
+
/**
|
|
1345
|
+
* Whether the explored part of a run ever had more than one runnable task to
|
|
1346
|
+
* pick from — the running fiber's own continuation counts, since a sliced
|
|
1347
|
+
* fiber waits in the pending list like any other task. A run without a choice
|
|
1348
|
+
* point has exactly one schedule: a seeded replay can only take the decisions
|
|
1349
|
+
* the run already took. Steps before `beginExploration` (a case's layer build)
|
|
1350
|
+
* are never explored, so they do not count.
|
|
1351
|
+
*/
|
|
1352
|
+
const hasChoicePoint = (history) => history.steps.slice(history.steps.length - history.decisions.length).some((step) => step.options > 1);
|
|
1353
|
+
const seedsWhen = (choicePoint, profile) => choicePoint ? SEEDS[profile] : 0;
|
|
1354
|
+
/**
|
|
1355
|
+
* The seeded replays a baseline run is worth under a profile. A baseline with
|
|
1356
|
+
* no choice point has one schedule, so a seed could only replay it: it gets
|
|
1357
|
+
* none. Any other baseline gets the profile's seed count.
|
|
1358
|
+
*/
|
|
1359
|
+
const seedsForImpl = (baseline, profile = "per-change") => seedsWhen(hasChoicePoint(baseline), profile);
|
|
1360
|
+
const isBaselineFirst = (args) => typeof args[0] === "object" && args[0] !== null;
|
|
1361
|
+
const seedsFor = dual(isBaselineFirst, seedsForImpl);
|
|
1362
|
+
const currentSeedsFor = (baseline) => Effect.map(currentProfile, (profile) => seedsFor(baseline, profile));
|
|
1363
|
+
const localBoundOf = (requested) => Math.min(requested ?? 1, 1);
|
|
1364
|
+
const boundImpl = (requested, profile) => profile === "local" ? localBoundOf(requested) : requested;
|
|
1365
|
+
const preemptionsFor = dual(2, boundImpl);
|
|
1366
|
+
const currentPreemptionsFor = (requested) => Effect.map(currentProfile, (profile) => preemptionsFor(requested, profile));
|
|
1367
|
+
//#endregion
|
|
1152
1368
|
//#region src/Kernel/Pct.ts
|
|
1153
1369
|
/**
|
|
1154
1370
|
* Seeded PCT (Burckhardt, Kothari & Musuvathi): each fiber gets a random
|
|
@@ -1156,7 +1372,8 @@ const run = dual((args) => args.length > 0 && isProgram(args[0]), runImpl);
|
|
|
1156
1372
|
* points among the first `steps` explored decisions lower the running fiber's
|
|
1157
1373
|
* priority. A seed replays the whole schedule deterministically, and a
|
|
1158
1374
|
* parent-owned child-start task is targeted positionally so a newly started
|
|
1159
|
-
* child still gets its own chance to run.
|
|
1375
|
+
* child still gets its own chance to run. A baseline with no choice point has
|
|
1376
|
+
* one schedule, so unless the caller names a seed count it gets no seeds.
|
|
1160
1377
|
*/
|
|
1161
1378
|
const mulberry32 = (seed) => {
|
|
1162
1379
|
let state = seed | 0;
|
|
@@ -1212,7 +1429,7 @@ const applyChange = (picker, choice, best) => {
|
|
|
1212
1429
|
};
|
|
1213
1430
|
const pick = (options) => {
|
|
1214
1431
|
const rng = mulberry32(options.seed);
|
|
1215
|
-
const depth = options.depth ??
|
|
1432
|
+
const depth = options.depth ?? pctDepth;
|
|
1216
1433
|
const picker = {
|
|
1217
1434
|
priorities: /* @__PURE__ */ new Map(),
|
|
1218
1435
|
changes: changePoints(rng, depth, options.steps),
|
|
@@ -1276,23 +1493,29 @@ const exploreSeeds = (state, seed) => {
|
|
|
1276
1493
|
};
|
|
1277
1494
|
const absorbBaseline = (state, baseline) => {
|
|
1278
1495
|
const survey = surveyed(baseline, state.survey);
|
|
1279
|
-
state.
|
|
1496
|
+
state.seeds = state.requestedSeeds ?? seedsFor(baseline, "per-change");
|
|
1497
|
+
state.steps = PctStepCount.make(survey.steps);
|
|
1280
1498
|
state.survey.fibers = survey.fibers;
|
|
1281
1499
|
state.survey.steps = survey.steps;
|
|
1282
1500
|
};
|
|
1501
|
+
const derivedChoiceFree = (state) => state.requestedSeeds === void 0 && state.seeds === 0;
|
|
1502
|
+
const judgedAlone = (state, baseline) => {
|
|
1503
|
+
if (derivedChoiceFree(state)) collectedFailure(state, 0, baseline);
|
|
1504
|
+
};
|
|
1283
1505
|
const baselineOptions = (state) => {
|
|
1284
1506
|
if (state.maxSteps === void 0) return {};
|
|
1285
1507
|
return { maxSteps: state.maxSteps };
|
|
1286
1508
|
};
|
|
1287
|
-
const
|
|
1288
|
-
const
|
|
1289
|
-
const stepsOf = (options) => options.steps ??
|
|
1509
|
+
const depthOf = (options) => options.depth ?? pctDepth;
|
|
1510
|
+
const NO_STEPS = PctStepCount.make(0);
|
|
1511
|
+
const stepsOf = (options) => options.steps ?? NO_STEPS;
|
|
1290
1512
|
const failureCheckOf = (options) => options.isFailure ?? failKept$2;
|
|
1291
1513
|
const pctImpl = (program, options = {}) => {
|
|
1292
1514
|
const state = {
|
|
1293
1515
|
program,
|
|
1294
1516
|
depth: depthOf(options),
|
|
1295
|
-
|
|
1517
|
+
requestedSeeds: options.seeds,
|
|
1518
|
+
seeds: 0,
|
|
1296
1519
|
steps: stepsOf(options),
|
|
1297
1520
|
isFailure: failureCheckOf(options),
|
|
1298
1521
|
maxSteps: options.maxSteps,
|
|
@@ -1304,6 +1527,7 @@ const pctImpl = (program, options = {}) => {
|
|
|
1304
1527
|
};
|
|
1305
1528
|
return run(program, baselineOptions(state)).then((baseline) => {
|
|
1306
1529
|
absorbBaseline(state, baseline);
|
|
1530
|
+
judgedAlone(state, baseline);
|
|
1307
1531
|
return exploreSeeds(state, 0).then((failures) => ({
|
|
1308
1532
|
failures,
|
|
1309
1533
|
bound: boundOf$1(state.survey, state.depth, state.seeds + 1)
|
|
@@ -1588,7 +1812,7 @@ const deviationsBefore = (steps) => {
|
|
|
1588
1812
|
let spent = 0;
|
|
1589
1813
|
return steps.map((step) => {
|
|
1590
1814
|
const before = spent;
|
|
1591
|
-
spent += Number(step.deviation);
|
|
1815
|
+
spent += Number(step.deviation && !step.activeBlocked);
|
|
1592
1816
|
return before;
|
|
1593
1817
|
});
|
|
1594
1818
|
};
|
|
@@ -1867,6 +2091,9 @@ const layer = Layer.effectContext(Effect.map(make, contextOf));
|
|
|
1867
2091
|
//#endregion
|
|
1868
2092
|
//#region src/Kernel/mod.ts
|
|
1869
2093
|
var Kernel_exports = /* @__PURE__ */ __exportAll({
|
|
2094
|
+
PctDepth: () => PctDepth,
|
|
2095
|
+
PctSeedCount: () => PctSeedCount,
|
|
2096
|
+
PctStepCount: () => PctStepCount,
|
|
1870
2097
|
TestClock: () => TestClock_exports,
|
|
1871
2098
|
beginExploration: () => beginExploration,
|
|
1872
2099
|
currentPreemptionsFor: () => currentPreemptionsFor,
|
|
@@ -1877,7 +2104,7 @@ var Kernel_exports = /* @__PURE__ */ __exportAll({
|
|
|
1877
2104
|
localSeeds: () => 25,
|
|
1878
2105
|
outcomeTags: () => runOutcomeTags,
|
|
1879
2106
|
pct: () => pct,
|
|
1880
|
-
pctDepth: () =>
|
|
2107
|
+
pctDepth: () => pctDepth,
|
|
1881
2108
|
perChangeSeeds: () => 250,
|
|
1882
2109
|
pick: () => pick,
|
|
1883
2110
|
preemptionsFor: () => preemptionsFor,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@systemfsoftware/effect-sim-kernel",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.6",
|
|
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.59.
|
|
36
|
-
"@systemfsoftware/oxlint-config-recommended": "^
|
|
37
|
-
"@systemfsoftware/tsconfig": "^2.0
|
|
38
|
-
"@systemfsoftware/tsdown-config": "^0.1.
|
|
39
|
-
"@systemfsoftware/vitest": "^1.
|
|
40
|
-
"@systemfsoftware/vitest-config": "^0.1.
|
|
41
|
-
"@types/node": "^26",
|
|
42
|
-
"effect": "^4",
|
|
43
|
-
"oxlint": "~1.
|
|
35
|
+
"@microsoft/api-extractor": "^7.59.4",
|
|
36
|
+
"@systemfsoftware/oxlint-config-recommended": "^8.0.3",
|
|
37
|
+
"@systemfsoftware/tsconfig": "^2.1.0",
|
|
38
|
+
"@systemfsoftware/tsdown-config": "^0.1.2",
|
|
39
|
+
"@systemfsoftware/vitest": "^4.1.3",
|
|
40
|
+
"@systemfsoftware/vitest-config": "^0.1.3",
|
|
41
|
+
"@types/node": "^26.6.5",
|
|
42
|
+
"effect": "^4.1.4",
|
|
43
|
+
"oxlint": "~1.93.0",
|
|
44
44
|
"rimraf": "^6.1.3",
|
|
45
45
|
"tsdown": "^0.23.0",
|
|
46
|
-
"typescript": "^7",
|
|
47
|
-
"vitest": "^5"
|
|
46
|
+
"typescript": "^7.0.2",
|
|
47
|
+
"vitest": "^5.1.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"effect": "^4"
|
|
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",
|