@systemfsoftware/effect-sim-kernel 1.0.0 → 2.0.5
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 +19 -15
- package/dist/index.mjs +109 -31
- package/package.json +13 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,47 +1,5 @@
|
|
|
1
1
|
# @systemfsoftware/effect-sim-kernel
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# @systemfsoftware/effect-sim-kernel@2.0.5
|
|
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
|
+
Follows Effect 4.1.4's automatic yields. A resumed fiber continues inline instead of being queued as a new step, so a run stopped after any step releases the resources its scope acquired. Previously, under Effect 4.1.4, such a stop could leave an acquired resource unreleased, or leave the run waiting with no runnable step.
|
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
|
}
|
|
@@ -252,14 +260,14 @@ declare const run: {
|
|
|
252
260
|
//#region src/Kernel/Pct.d.ts
|
|
253
261
|
interface PickOptions {
|
|
254
262
|
readonly seed: number;
|
|
255
|
-
readonly depth?:
|
|
256
|
-
readonly steps:
|
|
263
|
+
readonly depth?: PctDepth;
|
|
264
|
+
readonly steps: PctStepCount;
|
|
257
265
|
}
|
|
258
266
|
declare const pick: (options: PickOptions) => (choice: Choice) => Decision | undefined;
|
|
259
267
|
interface PctOptions<A, E> {
|
|
260
|
-
readonly seeds?:
|
|
261
|
-
readonly depth?:
|
|
262
|
-
readonly steps?:
|
|
268
|
+
readonly seeds?: PctSeedCount;
|
|
269
|
+
readonly depth?: PctDepth;
|
|
270
|
+
readonly steps?: PctStepCount;
|
|
263
271
|
readonly isFailure?: (result: RunResult<A, E>) => boolean;
|
|
264
272
|
readonly maxSteps?: number;
|
|
265
273
|
}
|
|
@@ -284,20 +292,16 @@ declare const pct: {
|
|
|
284
292
|
* not the verdict: the same checks run at the per-change budget in CI.
|
|
285
293
|
*/
|
|
286
294
|
type ProfileName = 'local' | 'per-change';
|
|
287
|
-
declare const pctDepth
|
|
295
|
+
declare const pctDepth: PctDepth;
|
|
288
296
|
declare const perChangeSeeds = 250;
|
|
289
297
|
declare const localSeeds = 25;
|
|
290
298
|
declare const localPreemptions = 1;
|
|
291
299
|
declare const currentProfile: Effect.Effect<ProfileName, Config.ConfigError>;
|
|
292
|
-
interface Budget {
|
|
293
|
-
readonly fibers: number;
|
|
294
|
-
readonly steps: number;
|
|
295
|
-
}
|
|
296
300
|
declare const seedsFor: {
|
|
297
|
-
(
|
|
298
|
-
(profile?: ProfileName): (
|
|
301
|
+
(baseline: RunHistory, profile?: ProfileName): number;
|
|
302
|
+
(profile?: ProfileName): (baseline: RunHistory) => number;
|
|
299
303
|
};
|
|
300
|
-
declare const currentSeedsFor: (
|
|
304
|
+
declare const currentSeedsFor: (baseline: RunHistory) => Effect.Effect<number, Config.ConfigError>;
|
|
301
305
|
declare const preemptionsFor: {
|
|
302
306
|
(requested: number | undefined, profile: ProfileName): number | undefined;
|
|
303
307
|
(profile: ProfileName): (requested: number | undefined) => number | undefined;
|
|
@@ -367,7 +371,7 @@ declare const shrinkCommands: {
|
|
|
367
371
|
<C>(stillFails: (candidate: ReadonlyArray<C>) => Promise<boolean>): (commands: ReadonlyArray<C>) => Promise<ReadonlyArray<C>>;
|
|
368
372
|
};
|
|
369
373
|
declare namespace mod_d_exports {
|
|
370
|
-
export { AnyFiber, BlockedFailure, Bound,
|
|
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 };
|
|
371
375
|
}
|
|
372
376
|
//#endregion
|
|
373
377
|
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
|
/**
|
|
@@ -407,10 +412,33 @@ const dispatchObserved = (fiber, kernel, original, args) => {
|
|
|
407
412
|
noteOtherFiberWork(fiber, kernel);
|
|
408
413
|
return applyOriginal(original, fiber, args);
|
|
409
414
|
};
|
|
415
|
+
/**
|
|
416
|
+
* The fibers whose original `evaluate` is on the stack right now. Effect 4.0.1
|
|
417
|
+
* restores a fiber's async context by calling `evaluate` again from inside its
|
|
418
|
+
* own evaluation (`FiberImpl.evaluate` re-enters through
|
|
419
|
+
* `AsyncResource.runInAsyncScope`), so one resume arrives as two nested calls.
|
|
420
|
+
* The nested call is that first resume continuing, not a new one: running the
|
|
421
|
+
* original inline keeps a resume one kernel step, as it was under 4.0.0, where
|
|
422
|
+
* queueing the nested call would spend an extra step on every slice. Only the
|
|
423
|
+
* outermost call marks the fiber; a nested call returns before marking, so the
|
|
424
|
+
* slot never outlives the evaluation it names.
|
|
425
|
+
*/
|
|
426
|
+
const evaluating = /* @__PURE__ */ new WeakSet();
|
|
427
|
+
const withEvaluation = (fiber, run) => {
|
|
428
|
+
evaluating.add(fiber);
|
|
429
|
+
try {
|
|
430
|
+
return run();
|
|
431
|
+
} finally {
|
|
432
|
+
evaluating.delete(fiber);
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
const isEvaluating = (fiber) => evaluating.has(fiber);
|
|
410
436
|
const isResumableBy = (fiber, kernel) => fiber.pollUnsafe() === void 0 && dispatcherOf(fiber) === kernel.dispatcher;
|
|
411
437
|
const isResumingRun = (fiber, kernel) => kernel.running && isResumableBy(fiber, kernel);
|
|
412
438
|
const resumeExternallyThrough = (fiber, kernel, original, args) => {
|
|
413
|
-
kernel.resumeExternally(fiber, () =>
|
|
439
|
+
kernel.resumeExternally(fiber, () => {
|
|
440
|
+
withEvaluation(fiber, () => applyOriginal(original, fiber, args));
|
|
441
|
+
});
|
|
414
442
|
};
|
|
415
443
|
/**
|
|
416
444
|
* A fiber's first evaluation inside a step is a start, not a resume: Effect runs
|
|
@@ -421,12 +449,15 @@ const resumeExternallyThrough = (fiber, kernel, original, args) => {
|
|
|
421
449
|
const startsInStep = (fiber, kernel) => kernel.firstEvaluation(fiber) && kernel.phase === "step";
|
|
422
450
|
const queuedOrObserved = (fiber, kernel, original, args) => {
|
|
423
451
|
if (isResumingRun(fiber, kernel)) return resumeExternallyThrough(fiber, kernel, original, args);
|
|
424
|
-
return dispatchObserved(fiber, kernel, original, args);
|
|
452
|
+
return withEvaluation(fiber, () => dispatchObserved(fiber, kernel, original, args));
|
|
425
453
|
};
|
|
426
|
-
const
|
|
427
|
-
if (startsInStep(fiber, kernel)) return dispatchObserved(fiber, kernel, original, args);
|
|
454
|
+
const dispatchOutermost = (fiber, kernel, original, args) => {
|
|
455
|
+
if (startsInStep(fiber, kernel)) return withEvaluation(fiber, () => dispatchObserved(fiber, kernel, original, args));
|
|
428
456
|
return queuedOrObserved(fiber, kernel, original, args);
|
|
429
457
|
};
|
|
458
|
+
const isAutomaticResume = (fiber) => Reflect.get(fiber, "_autoYielded") === true;
|
|
459
|
+
const dispatchResumption = (fiber, kernel, original, args) => isAutomaticResume(fiber) ? withEvaluation(fiber, () => dispatchObserved(fiber, kernel, original, args)) : dispatchOutermost(fiber, kernel, original, args);
|
|
460
|
+
const dispatchEvaluate = (fiber, kernel, original, args) => isEvaluating(fiber) ? dispatchObserved(fiber, kernel, original, args) : dispatchResumption(fiber, kernel, original, args);
|
|
430
461
|
const interruptAgain = (fiber, args) => () => {
|
|
431
462
|
Reflect.apply(Reflect.get(fiber, "interruptUnsafe"), fiber, args);
|
|
432
463
|
};
|
|
@@ -1149,6 +1180,42 @@ const runImpl = (program, options = {}) => {
|
|
|
1149
1180
|
/** @internal */
|
|
1150
1181
|
const run = dual((args) => args.length > 0 && isProgram(args[0]), runImpl);
|
|
1151
1182
|
//#endregion
|
|
1183
|
+
//#region src/Kernel/Profile.ts
|
|
1184
|
+
const pctDepth = PctDepth.make(3);
|
|
1185
|
+
const isProfileName = Schema.is(ProfileNames);
|
|
1186
|
+
const profileOf = (name) => isProfileName(name) ? name : "per-change";
|
|
1187
|
+
const currentProfile = Effect.map(Config.option(Config.String("CONFORMANCE_PROFILE")), Option.match({
|
|
1188
|
+
onNone: () => profileOf(""),
|
|
1189
|
+
onSome: profileOf
|
|
1190
|
+
}));
|
|
1191
|
+
const SEEDS = {
|
|
1192
|
+
local: 25,
|
|
1193
|
+
"per-change": 250
|
|
1194
|
+
};
|
|
1195
|
+
/**
|
|
1196
|
+
* Whether the explored part of a run ever had more than one runnable task to
|
|
1197
|
+
* pick from — the running fiber's own continuation counts, since a sliced
|
|
1198
|
+
* fiber waits in the pending list like any other task. A run without a choice
|
|
1199
|
+
* point has exactly one schedule: a seeded replay can only take the decisions
|
|
1200
|
+
* the run already took. Steps before `beginExploration` (a case's layer build)
|
|
1201
|
+
* are never explored, so they do not count.
|
|
1202
|
+
*/
|
|
1203
|
+
const hasChoicePoint = (history) => history.steps.slice(history.steps.length - history.decisions.length).some((step) => step.options > 1);
|
|
1204
|
+
const seedsWhen = (choicePoint, profile) => choicePoint ? SEEDS[profile] : 0;
|
|
1205
|
+
/**
|
|
1206
|
+
* The seeded replays a baseline run is worth under a profile. A baseline with
|
|
1207
|
+
* no choice point has one schedule, so a seed could only replay it: it gets
|
|
1208
|
+
* none. Any other baseline gets the profile's seed count.
|
|
1209
|
+
*/
|
|
1210
|
+
const seedsForImpl = (baseline, profile = "per-change") => seedsWhen(hasChoicePoint(baseline), profile);
|
|
1211
|
+
const isBaselineFirst = (args) => typeof args[0] === "object" && args[0] !== null;
|
|
1212
|
+
const seedsFor = dual(isBaselineFirst, seedsForImpl);
|
|
1213
|
+
const currentSeedsFor = (baseline) => Effect.map(currentProfile, (profile) => seedsFor(baseline, profile));
|
|
1214
|
+
const localBoundOf = (requested) => Math.min(requested ?? 1, 1);
|
|
1215
|
+
const boundImpl = (requested, profile) => profile === "local" ? localBoundOf(requested) : requested;
|
|
1216
|
+
const preemptionsFor = dual(2, boundImpl);
|
|
1217
|
+
const currentPreemptionsFor = (requested) => Effect.map(currentProfile, (profile) => preemptionsFor(requested, profile));
|
|
1218
|
+
//#endregion
|
|
1152
1219
|
//#region src/Kernel/Pct.ts
|
|
1153
1220
|
/**
|
|
1154
1221
|
* Seeded PCT (Burckhardt, Kothari & Musuvathi): each fiber gets a random
|
|
@@ -1156,7 +1223,8 @@ const run = dual((args) => args.length > 0 && isProgram(args[0]), runImpl);
|
|
|
1156
1223
|
* points among the first `steps` explored decisions lower the running fiber's
|
|
1157
1224
|
* priority. A seed replays the whole schedule deterministically, and a
|
|
1158
1225
|
* parent-owned child-start task is targeted positionally so a newly started
|
|
1159
|
-
* child still gets its own chance to run.
|
|
1226
|
+
* child still gets its own chance to run. A baseline with no choice point has
|
|
1227
|
+
* one schedule, so unless the caller names a seed count it gets no seeds.
|
|
1160
1228
|
*/
|
|
1161
1229
|
const mulberry32 = (seed) => {
|
|
1162
1230
|
let state = seed | 0;
|
|
@@ -1212,7 +1280,7 @@ const applyChange = (picker, choice, best) => {
|
|
|
1212
1280
|
};
|
|
1213
1281
|
const pick = (options) => {
|
|
1214
1282
|
const rng = mulberry32(options.seed);
|
|
1215
|
-
const depth = options.depth ??
|
|
1283
|
+
const depth = options.depth ?? pctDepth;
|
|
1216
1284
|
const picker = {
|
|
1217
1285
|
priorities: /* @__PURE__ */ new Map(),
|
|
1218
1286
|
changes: changePoints(rng, depth, options.steps),
|
|
@@ -1276,23 +1344,29 @@ const exploreSeeds = (state, seed) => {
|
|
|
1276
1344
|
};
|
|
1277
1345
|
const absorbBaseline = (state, baseline) => {
|
|
1278
1346
|
const survey = surveyed(baseline, state.survey);
|
|
1279
|
-
state.
|
|
1347
|
+
state.seeds = state.requestedSeeds ?? seedsFor(baseline, "per-change");
|
|
1348
|
+
state.steps = PctStepCount.make(survey.steps);
|
|
1280
1349
|
state.survey.fibers = survey.fibers;
|
|
1281
1350
|
state.survey.steps = survey.steps;
|
|
1282
1351
|
};
|
|
1352
|
+
const derivedChoiceFree = (state) => state.requestedSeeds === void 0 && state.seeds === 0;
|
|
1353
|
+
const judgedAlone = (state, baseline) => {
|
|
1354
|
+
if (derivedChoiceFree(state)) collectedFailure(state, 0, baseline);
|
|
1355
|
+
};
|
|
1283
1356
|
const baselineOptions = (state) => {
|
|
1284
1357
|
if (state.maxSteps === void 0) return {};
|
|
1285
1358
|
return { maxSteps: state.maxSteps };
|
|
1286
1359
|
};
|
|
1287
|
-
const
|
|
1288
|
-
const
|
|
1289
|
-
const stepsOf = (options) => options.steps ??
|
|
1360
|
+
const depthOf = (options) => options.depth ?? pctDepth;
|
|
1361
|
+
const NO_STEPS = PctStepCount.make(0);
|
|
1362
|
+
const stepsOf = (options) => options.steps ?? NO_STEPS;
|
|
1290
1363
|
const failureCheckOf = (options) => options.isFailure ?? failKept$2;
|
|
1291
1364
|
const pctImpl = (program, options = {}) => {
|
|
1292
1365
|
const state = {
|
|
1293
1366
|
program,
|
|
1294
1367
|
depth: depthOf(options),
|
|
1295
|
-
|
|
1368
|
+
requestedSeeds: options.seeds,
|
|
1369
|
+
seeds: 0,
|
|
1296
1370
|
steps: stepsOf(options),
|
|
1297
1371
|
isFailure: failureCheckOf(options),
|
|
1298
1372
|
maxSteps: options.maxSteps,
|
|
@@ -1304,6 +1378,7 @@ const pctImpl = (program, options = {}) => {
|
|
|
1304
1378
|
};
|
|
1305
1379
|
return run(program, baselineOptions(state)).then((baseline) => {
|
|
1306
1380
|
absorbBaseline(state, baseline);
|
|
1381
|
+
judgedAlone(state, baseline);
|
|
1307
1382
|
return exploreSeeds(state, 0).then((failures) => ({
|
|
1308
1383
|
failures,
|
|
1309
1384
|
bound: boundOf$1(state.survey, state.depth, state.seeds + 1)
|
|
@@ -1867,6 +1942,9 @@ const layer = Layer.effectContext(Effect.map(make, contextOf));
|
|
|
1867
1942
|
//#endregion
|
|
1868
1943
|
//#region src/Kernel/mod.ts
|
|
1869
1944
|
var Kernel_exports = /* @__PURE__ */ __exportAll({
|
|
1945
|
+
PctDepth: () => PctDepth,
|
|
1946
|
+
PctSeedCount: () => PctSeedCount,
|
|
1947
|
+
PctStepCount: () => PctStepCount,
|
|
1870
1948
|
TestClock: () => TestClock_exports,
|
|
1871
1949
|
beginExploration: () => beginExploration,
|
|
1872
1950
|
currentPreemptionsFor: () => currentPreemptionsFor,
|
|
@@ -1877,7 +1955,7 @@ var Kernel_exports = /* @__PURE__ */ __exportAll({
|
|
|
1877
1955
|
localSeeds: () => 25,
|
|
1878
1956
|
outcomeTags: () => runOutcomeTags,
|
|
1879
1957
|
pct: () => pct,
|
|
1880
|
-
pctDepth: () =>
|
|
1958
|
+
pctDepth: () => pctDepth,
|
|
1881
1959
|
perChangeSeeds: () => 250,
|
|
1882
1960
|
pick: () => pick,
|
|
1883
1961
|
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.5",
|
|
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": "^6.0.1",
|
|
37
|
+
"@systemfsoftware/tsconfig": "^2.1.0",
|
|
38
|
+
"@systemfsoftware/tsdown-config": "^0.1.2",
|
|
39
|
+
"@systemfsoftware/vitest": "^4.1.1",
|
|
40
|
+
"@systemfsoftware/vitest-config": "^0.1.3",
|
|
41
|
+
"@types/node": "^26.6.5",
|
|
42
|
+
"effect": "^4.1.2",
|
|
43
|
+
"oxlint": "~1.89.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.2"
|
|
51
51
|
},
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"access": "public",
|