@systemfsoftware/effect-sim-kernel 2.0.5 → 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 -2
- package/dist/index.d.ts +38 -2
- package/dist/index.mjs +162 -13
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# @systemfsoftware/effect-sim-kernel
|
|
2
2
|
|
|
3
|
-
# @systemfsoftware/effect-sim-kernel@2.0.
|
|
3
|
+
# @systemfsoftware/effect-sim-kernel@2.0.6
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Requires Effect ^4.1.4.
|
package/dist/index.d.ts
CHANGED
|
@@ -112,6 +112,31 @@ interface StepRecord {
|
|
|
112
112
|
* it can change the outcome. Seam for preemption-bounded search (pruning).
|
|
113
113
|
*/
|
|
114
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;
|
|
115
140
|
}
|
|
116
141
|
/** Which fiber an interruption names (R5). */
|
|
117
142
|
/** @internal */
|
|
@@ -155,6 +180,9 @@ declare const runOutcomeTags: {
|
|
|
155
180
|
readonly runaway: {
|
|
156
181
|
readonly _tag: 'Runaway';
|
|
157
182
|
};
|
|
183
|
+
readonly replayTraceDiverged: {
|
|
184
|
+
readonly _tag: 'ReplayTraceDiverged';
|
|
185
|
+
};
|
|
158
186
|
};
|
|
159
187
|
/** @internal */
|
|
160
188
|
type RunCompleted<A, E> = RunHistory & typeof runOutcomeTags.completed & {
|
|
@@ -168,6 +196,7 @@ type RunFailed = RunHistory & typeof runOutcomeTags.failed & {
|
|
|
168
196
|
interface RunHistory {
|
|
169
197
|
/** Which fiber ran at each step, in order (R3). */
|
|
170
198
|
readonly steps: ReadonlyArray<StepRecord>;
|
|
199
|
+
readonly boundaries: ReadonlyArray<BoundaryRecord>;
|
|
171
200
|
/** The decisions the schedule explored, in order (R4's replayable path). */
|
|
172
201
|
readonly decisions: ReadonlyArray<Decision>;
|
|
173
202
|
}
|
|
@@ -194,7 +223,13 @@ type RunawayFailure = typeof runOutcomeTags.runaway & {
|
|
|
194
223
|
readonly pending: number;
|
|
195
224
|
};
|
|
196
225
|
/** @internal */
|
|
197
|
-
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;
|
|
198
233
|
/** @internal */
|
|
199
234
|
interface Interruption {
|
|
200
235
|
/** The one-based step after whose task the fiber is interrupted. */
|
|
@@ -209,6 +244,7 @@ interface RunOptions {
|
|
|
209
244
|
* or a step past the end of the path, takes Effect's order.
|
|
210
245
|
*/
|
|
211
246
|
readonly path?: ReadonlyArray<Decision | undefined>;
|
|
247
|
+
readonly expectTrace?: ReadonlyArray<TraceSnapshot>;
|
|
212
248
|
/**
|
|
213
249
|
* Chooses beyond the recorded path (seam for PCT and bounded search).
|
|
214
250
|
* Returning undefined takes the zero-preemption choice.
|
|
@@ -371,7 +407,7 @@ declare const shrinkCommands: {
|
|
|
371
407
|
<C>(stillFails: (candidate: ReadonlyArray<C>) => Promise<boolean>): (commands: ReadonlyArray<C>) => Promise<ReadonlyArray<C>>;
|
|
372
408
|
};
|
|
373
409
|
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 };
|
|
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 };
|
|
375
411
|
}
|
|
376
412
|
//#endregion
|
|
377
413
|
export { mod_d_exports as Kernel };
|
package/dist/index.mjs
CHANGED
|
@@ -196,7 +196,8 @@ const FIBER_METHODS = [
|
|
|
196
196
|
"addObserver",
|
|
197
197
|
"interruptUnsafe",
|
|
198
198
|
"pollUnsafe",
|
|
199
|
-
"evaluate"
|
|
199
|
+
"evaluate",
|
|
200
|
+
"yieldNow"
|
|
200
201
|
];
|
|
201
202
|
const REF_FIELDS = ["ref"];
|
|
202
203
|
const DEFERRED_FIELDS = ["effect", "resumes"];
|
|
@@ -465,13 +466,18 @@ const dispatchInterrupt = (fiber, kernel, original, args) => {
|
|
|
465
466
|
if (kernel.afterQueuedResume(fiber, interruptAgain(fiber, args))) return void 0;
|
|
466
467
|
return dispatchObserved(fiber, kernel, original, args);
|
|
467
468
|
};
|
|
468
|
-
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)));
|
|
469
474
|
/** @internal */
|
|
470
475
|
const makeKernel = (options) => {
|
|
471
476
|
const pending = [];
|
|
472
477
|
const fibers = /* @__PURE__ */ new Set();
|
|
473
478
|
const evaluated = /* @__PURE__ */ new WeakSet();
|
|
474
479
|
const steps = [];
|
|
480
|
+
const boundaries = [];
|
|
475
481
|
const decisions = [];
|
|
476
482
|
const escapes = [];
|
|
477
483
|
const touches = /* @__PURE__ */ new Set();
|
|
@@ -496,6 +502,14 @@ const makeKernel = (options) => {
|
|
|
496
502
|
let root = void 0;
|
|
497
503
|
let running = false;
|
|
498
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;
|
|
499
513
|
const taskAt = (index) => pending[index];
|
|
500
514
|
const stepOn = (task) => task === void 0 ? -1 : task.step;
|
|
501
515
|
const stepAt = (index) => stepOn(taskAt(index));
|
|
@@ -603,6 +617,20 @@ const makeKernel = (options) => {
|
|
|
603
617
|
const endStep = () => {
|
|
604
618
|
phase = "paused";
|
|
605
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]);
|
|
606
634
|
const ranOn = (task) => ranInTask ?? task.owner;
|
|
607
635
|
const runTask = (task) => {
|
|
608
636
|
beginStep();
|
|
@@ -616,8 +644,52 @@ const makeKernel = (options) => {
|
|
|
616
644
|
const touchesFiber = (ran) => ran !== void 0 && touches.has(ran);
|
|
617
645
|
const extraScheduling = () => scheduledInStep > 1 || globalWorkThisStep;
|
|
618
646
|
const sharedWork = (ran) => extraScheduling() || touchesFiber(ran);
|
|
619
|
-
const isVisible = (task, ran) =>
|
|
620
|
-
|
|
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) => ({
|
|
621
693
|
step: stepCount,
|
|
622
694
|
choice: input.choice,
|
|
623
695
|
options: input.options,
|
|
@@ -626,12 +698,40 @@ const makeKernel = (options) => {
|
|
|
626
698
|
forced: task.forced,
|
|
627
699
|
external: task.external,
|
|
628
700
|
fiberId: ran?.id,
|
|
629
|
-
visible: isVisible(task, ran)
|
|
701
|
+
visible: isVisible(task, ran),
|
|
702
|
+
boundary,
|
|
703
|
+
activeBlocked,
|
|
704
|
+
runnableFibers: runnable
|
|
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())
|
|
630
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
|
+
};
|
|
631
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);
|
|
632
732
|
lastRan = ran;
|
|
633
|
-
steps.push(
|
|
634
|
-
|
|
733
|
+
steps.push(record);
|
|
734
|
+
recordDecision(input);
|
|
635
735
|
};
|
|
636
736
|
const queuedResumeOf = (fiber) => (task) => task.external && task.owner === fiber;
|
|
637
737
|
const afterQueuedResume = (fiber, after) => {
|
|
@@ -654,6 +754,9 @@ const makeKernel = (options) => {
|
|
|
654
754
|
return task;
|
|
655
755
|
};
|
|
656
756
|
const step = (input) => {
|
|
757
|
+
clearBoundary();
|
|
758
|
+
captureBoundary();
|
|
759
|
+
runnableAtDecision = runnableIds(pending);
|
|
657
760
|
const task = takeTask(input.choice);
|
|
658
761
|
if (task === void 0) throw new Error(`effect-sim-kernel: no task to run at decision ${input.choice}`);
|
|
659
762
|
const ran = runTask(task);
|
|
@@ -674,6 +777,7 @@ const makeKernel = (options) => {
|
|
|
674
777
|
pending,
|
|
675
778
|
fibers,
|
|
676
779
|
steps,
|
|
780
|
+
boundaries,
|
|
677
781
|
decisions,
|
|
678
782
|
escapes,
|
|
679
783
|
scheduler,
|
|
@@ -691,6 +795,9 @@ const makeKernel = (options) => {
|
|
|
691
795
|
get running() {
|
|
692
796
|
return running;
|
|
693
797
|
},
|
|
798
|
+
get traceDivergence() {
|
|
799
|
+
return traceDivergence;
|
|
800
|
+
},
|
|
694
801
|
start: (started) => {
|
|
695
802
|
root = started;
|
|
696
803
|
running = true;
|
|
@@ -711,6 +818,11 @@ const makeKernel = (options) => {
|
|
|
711
818
|
});
|
|
712
819
|
scheduledInStep++;
|
|
713
820
|
},
|
|
821
|
+
noteYieldBoundary: (kind, fiber) => {
|
|
822
|
+
if (phase !== "step") return;
|
|
823
|
+
yieldBoundary = kind;
|
|
824
|
+
yieldBoundaryFiber = fiber;
|
|
825
|
+
},
|
|
714
826
|
firstEvaluation: (fiber) => {
|
|
715
827
|
if (evaluated.has(fiber)) return false;
|
|
716
828
|
evaluated.add(fiber);
|
|
@@ -944,7 +1056,8 @@ const runOutcomeTags = {
|
|
|
944
1056
|
escape: { _tag: "Escape" },
|
|
945
1057
|
blocked: { _tag: "Blocked" },
|
|
946
1058
|
deadlock: { _tag: "Deadlock" },
|
|
947
|
-
runaway: { _tag: "Runaway" }
|
|
1059
|
+
runaway: { _tag: "Runaway" },
|
|
1060
|
+
replayTraceDiverged: { _tag: "ReplayTraceDiverged" }
|
|
948
1061
|
};
|
|
949
1062
|
const DEFAULT_MAX_STEPS = 5e4;
|
|
950
1063
|
const DEFAULT_STEP_TURNS = 4;
|
|
@@ -1049,14 +1162,24 @@ const completedOn = (kernel, exit) => ({
|
|
|
1049
1162
|
...runOutcomeTags.completed,
|
|
1050
1163
|
exit,
|
|
1051
1164
|
steps: kernel.steps,
|
|
1165
|
+
boundaries: kernel.boundaries,
|
|
1052
1166
|
decisions: kernel.decisions
|
|
1053
1167
|
});
|
|
1054
1168
|
const failedOn = (kernel, failure) => ({
|
|
1055
1169
|
...runOutcomeTags.failed,
|
|
1056
1170
|
failure,
|
|
1057
1171
|
steps: kernel.steps,
|
|
1172
|
+
boundaries: kernel.boundaries,
|
|
1058
1173
|
decisions: kernel.decisions
|
|
1059
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
|
+
};
|
|
1060
1183
|
const interruptLive = (kernel, fiber) => {
|
|
1061
1184
|
if (fiber !== void 0) kernel.interrupt(fiber);
|
|
1062
1185
|
};
|
|
@@ -1072,7 +1195,12 @@ const applyInterrupt = (kernel, options) => {
|
|
|
1072
1195
|
const advance$1 = (state) => {
|
|
1073
1196
|
state.kernel.step(decide(state.kernel, state.options));
|
|
1074
1197
|
applyInterrupt(state.kernel, state.options);
|
|
1075
|
-
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);
|
|
1076
1204
|
};
|
|
1077
1205
|
const seamOffersProgress = (seam) => seam !== void 0 && seam();
|
|
1078
1206
|
const resettled = (state) => {
|
|
@@ -1082,14 +1210,31 @@ const resettled = (state) => {
|
|
|
1082
1210
|
const stalled = (state) => drain(quiescenceTurnsOf(state.options)).then(() => resettled(state));
|
|
1083
1211
|
const quiescent = (state) => {
|
|
1084
1212
|
const exit = state.root.pollUnsafe();
|
|
1085
|
-
if (exit !== void 0) return Promise.resolve(
|
|
1213
|
+
if (exit !== void 0) return Promise.resolve(completedOrShortTrace(state, exit));
|
|
1086
1214
|
return stalled(state);
|
|
1087
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;
|
|
1088
1233
|
const settled$1 = (state) => {
|
|
1089
1234
|
if (state.kernel.pending.length > 0) return Promise.resolve(void 0);
|
|
1090
1235
|
return quiescent(state);
|
|
1091
1236
|
};
|
|
1092
|
-
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);
|
|
1093
1238
|
const escapeOrRunaway = (kernel, options, guard) => {
|
|
1094
1239
|
const escaped = kernel.escapes[0];
|
|
1095
1240
|
if (escaped !== void 0) return escapeFailureOf(escaped);
|
|
@@ -1112,6 +1257,7 @@ const continued = (state, halted) => halted !== void 0 ? Promise.resolve(halted)
|
|
|
1112
1257
|
const drive = (state) => iteration(state).then((halted) => continued(state, halted));
|
|
1113
1258
|
const RUN_OPTION_KEYS = [
|
|
1114
1259
|
"choose",
|
|
1260
|
+
"expectTrace",
|
|
1115
1261
|
"explore",
|
|
1116
1262
|
"external",
|
|
1117
1263
|
"interrupt",
|
|
@@ -1134,7 +1280,10 @@ const isProgram = (candidate) => !isRunOptions(candidate);
|
|
|
1134
1280
|
* active queues behind it, so two runs never share the global hooks.
|
|
1135
1281
|
*/
|
|
1136
1282
|
const lockedRun = (program, options, release) => {
|
|
1137
|
-
const kernel = makeKernel({
|
|
1283
|
+
const kernel = makeKernel({
|
|
1284
|
+
exploring: options.explore !== "body",
|
|
1285
|
+
expectTrace: options.expectTrace
|
|
1286
|
+
});
|
|
1138
1287
|
const recorder = installEscapeRecorder((escape) => {
|
|
1139
1288
|
kernel.escapes.push(escape);
|
|
1140
1289
|
});
|
|
@@ -1663,7 +1812,7 @@ const deviationsBefore = (steps) => {
|
|
|
1663
1812
|
let spent = 0;
|
|
1664
1813
|
return steps.map((step) => {
|
|
1665
1814
|
const before = spent;
|
|
1666
|
-
spent += Number(step.deviation);
|
|
1815
|
+
spent += Number(step.deviation && !step.activeBlocked);
|
|
1667
1816
|
return before;
|
|
1668
1817
|
});
|
|
1669
1818
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@systemfsoftware/effect-sim-kernel",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"author": "Ryan Lee <drdgvhbh@gmail.com>",
|
|
6
6
|
"repository": {
|
|
@@ -33,21 +33,21 @@
|
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@microsoft/api-extractor": "^7.59.4",
|
|
36
|
-
"@systemfsoftware/oxlint-config-recommended": "^
|
|
36
|
+
"@systemfsoftware/oxlint-config-recommended": "^8.0.3",
|
|
37
37
|
"@systemfsoftware/tsconfig": "^2.1.0",
|
|
38
38
|
"@systemfsoftware/tsdown-config": "^0.1.2",
|
|
39
|
-
"@systemfsoftware/vitest": "^4.1.
|
|
39
|
+
"@systemfsoftware/vitest": "^4.1.3",
|
|
40
40
|
"@systemfsoftware/vitest-config": "^0.1.3",
|
|
41
41
|
"@types/node": "^26.6.5",
|
|
42
|
-
"effect": "^4.1.
|
|
43
|
-
"oxlint": "~1.
|
|
42
|
+
"effect": "^4.1.4",
|
|
43
|
+
"oxlint": "~1.93.0",
|
|
44
44
|
"rimraf": "^6.1.3",
|
|
45
45
|
"tsdown": "^0.23.0",
|
|
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",
|