@systemfsoftware/effect-sim-kernel 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,366 @@
1
+ import { Clock, Config, Duration, Effect, Exit, Fiber, Layer, Scheduler } from "effect";
2
+ //#region src/Kernel/Bound.d.ts
3
+ type UnobservedPrimitive = 'Queue' | 'PubSub' | 'Semaphore' | 'Latch' | 'Scope finalizer';
4
+ interface Pruning {
5
+ readonly enabled: boolean;
6
+ readonly disabledBy: ReadonlyArray<UnobservedPrimitive>;
7
+ }
8
+ interface Bound {
9
+ readonly fibers: number;
10
+ readonly operations: number;
11
+ readonly preemptions: number;
12
+ readonly depth: number;
13
+ readonly runs: number;
14
+ readonly pruning: Pruning;
15
+ }
16
+ declare const pruned: Pruning;
17
+ declare const unpruned: (disabledBy: ReadonlyArray<UnobservedPrimitive>) => Pruning;
18
+ //#endregion
19
+ //#region src/internal/deadlock.d.ts
20
+ /** The process resources that can call back into the program from outside. */
21
+ /** @internal */
22
+ type WaitKind = 'RealTimer' | 'File' | 'Socket' | 'Other';
23
+ /** @internal */
24
+ interface SuspendedFiber {
25
+ readonly id: number;
26
+ readonly frames: ReadonlyArray<string>;
27
+ }
28
+ /** @internal */
29
+ type AnyFiber<A = unknown, E = unknown> = Fiber.Fiber<A, E>;
30
+ //#endregion
31
+ //#region src/internal/escapeRecorder.d.ts
32
+ /** @internal */
33
+ type TimerName = 'setTimeout' | 'setInterval' | 'setImmediate';
34
+ /** @internal */
35
+ interface Escape {
36
+ readonly timer: TimerName;
37
+ readonly site: string;
38
+ }
39
+ declare namespace TestClock_d_exports {
40
+ export { TestClock, layer, make };
41
+ }
42
+ /**
43
+ * The test-clock service a scenario reaches through the `Clock` service and
44
+ * Effect's own `TestClock` helpers.
45
+ */
46
+ interface TestClock extends Clock.Clock {
47
+ /**
48
+ * Increments the current clock time by the specified duration. Sleeps due on
49
+ * or before the new time fire in timestamp order, each batch's woken work
50
+ * running to a stop before the next batch.
51
+ */
52
+ adjust(duration: Duration.Input): Effect.Effect<void>;
53
+ /** Sets the current clock time to the specified timestamp. */
54
+ setTime(timestamp: number): Effect.Effect<void>;
55
+ /** Runs the effect with the kernel's root clock instead of the test clock. */
56
+ withLive<A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>;
57
+ }
58
+ /**
59
+ * Builds the run's test clock and registers it with the kernel, so the run
60
+ * settles its requests only when nothing else can run. Only available inside a
61
+ * kernel run.
62
+ */
63
+ declare const make: Effect.Effect<TestClock>;
64
+ /** The layer a harness provides in place of `TestClock.layer()`. */
65
+ declare const layer: Layer.Layer<Clock.Clock>;
66
+ //#endregion
67
+ //#region src/internal/kernel.d.ts
68
+ /** An index into the kernel's pending task list: the schedule's unit of choice. */
69
+ /** @internal */
70
+ type Decision = number;
71
+ /** What the schedule can pick at one step, handed to a `choose` callback. */
72
+ /** @internal */
73
+ interface ChoiceOption {
74
+ readonly fiberId: number | undefined;
75
+ /** The zero-preemption choice (Effect's dispatcher order). */
76
+ readonly isDefault: boolean;
77
+ /** A Promise or microtask resume, queued between steps (R36). */
78
+ readonly external: boolean;
79
+ /** The continuation of a fiber the kernel sliced. */
80
+ readonly forced: boolean;
81
+ }
82
+ /** @internal */
83
+ interface Choice {
84
+ /** Zero-based index of this step among the explored decisions. */
85
+ readonly index: number;
86
+ readonly options: ReadonlyArray<ChoiceOption>;
87
+ }
88
+ /** @internal */
89
+ interface StepRecord {
90
+ /** One-based step index. */
91
+ readonly step: number;
92
+ readonly choice: Decision;
93
+ readonly options: number;
94
+ /** What the zero-preemption schedule would have picked at this step. */
95
+ readonly fallback: Decision;
96
+ readonly deviation: boolean;
97
+ readonly forced: boolean;
98
+ readonly external: boolean;
99
+ /** The fiber that ran, as Effect numbered it. */
100
+ readonly fiberId: number | undefined;
101
+ /**
102
+ * The step touched state another fiber can observe — a `Ref` or `Deferred`
103
+ * field, another fiber's task, or more than one scheduled task — so reordering
104
+ * it can change the outcome. Seam for preemption-bounded search (pruning).
105
+ */
106
+ readonly visible: boolean;
107
+ }
108
+ /** Which fiber an interruption names (R5). */
109
+ /** @internal */
110
+ type FiberTarget = 'root' | 'lastRan' | number;
111
+ //#endregion
112
+ //#region src/internal/stepLoop.d.ts
113
+ /**
114
+ * The discriminant tags of the run outcome; the variants inherit them because
115
+ * an `Exit` cannot travel through a schema.
116
+ */
117
+ /** @internal */
118
+ declare const runOutcomeTags: {
119
+ readonly completed: {
120
+ readonly _tag: 'Completed';
121
+ };
122
+ readonly failed: {
123
+ readonly _tag: 'Failed';
124
+ };
125
+ readonly escape: {
126
+ readonly _tag: 'Escape';
127
+ };
128
+ readonly blocked: {
129
+ readonly _tag: 'Blocked';
130
+ };
131
+ readonly deadlock: {
132
+ readonly _tag: 'Deadlock';
133
+ };
134
+ readonly runaway: {
135
+ readonly _tag: 'Runaway';
136
+ };
137
+ };
138
+ /** @internal */
139
+ type RunCompleted<A, E> = RunHistory & typeof runOutcomeTags.completed & {
140
+ readonly exit: Exit.Exit<A, E>;
141
+ };
142
+ /** @internal */
143
+ type RunFailed = RunHistory & typeof runOutcomeTags.failed & {
144
+ readonly failure: RunFailure;
145
+ };
146
+ /** @internal */
147
+ interface RunHistory {
148
+ /** Which fiber ran at each step, in order (R3). */
149
+ readonly steps: ReadonlyArray<StepRecord>;
150
+ /** The decisions the schedule explored, in order (R4's replayable path). */
151
+ readonly decisions: ReadonlyArray<Decision>;
152
+ }
153
+ /** @internal */
154
+ type RunResult<A, E> = RunCompleted<A, E> | RunFailed;
155
+ /** Why a run failed, with what a report needs to name it. */
156
+ /** @internal */
157
+ type EscapeFailure = typeof runOutcomeTags.escape & {
158
+ readonly timer: TimerName;
159
+ readonly site: string;
160
+ };
161
+ /** @internal */
162
+ type BlockedFailure = typeof runOutcomeTags.blocked & {
163
+ readonly on: WaitKind;
164
+ readonly resources: ReadonlyArray<string>;
165
+ };
166
+ /** @internal */
167
+ type DeadlockFailure = typeof runOutcomeTags.deadlock & {
168
+ readonly suspended: ReadonlyArray<SuspendedFiber>;
169
+ };
170
+ /** @internal */
171
+ type RunawayFailure = typeof runOutcomeTags.runaway & {
172
+ readonly steps: number;
173
+ readonly pending: number;
174
+ };
175
+ /** @internal */
176
+ type RunFailure = EscapeFailure | BlockedFailure | DeadlockFailure | RunawayFailure;
177
+ /** @internal */
178
+ interface Interruption {
179
+ /** The one-based step after whose task the fiber is interrupted. */
180
+ readonly atStep: number;
181
+ /** Which fiber to interrupt; the root when omitted (R5). */
182
+ readonly target?: FiberTarget;
183
+ }
184
+ /** @internal */
185
+ interface RunOptions {
186
+ /**
187
+ * The decisions to take, one per explored step (R4). An `undefined` entry,
188
+ * or a step past the end of the path, takes Effect's order.
189
+ */
190
+ readonly path?: ReadonlyArray<Decision | undefined>;
191
+ /**
192
+ * Chooses beyond the recorded path (seam for PCT and bounded search).
193
+ * Returning undefined takes the zero-preemption choice.
194
+ */
195
+ readonly choose?: (choice: Choice) => Decision | undefined;
196
+ /** Interrupts one fiber at a chosen step (R5). */
197
+ readonly interrupt?: Interruption;
198
+ /**
199
+ * What a stall on the host means. `'fail'` (the default) names the wait and
200
+ * fails the run, so an explored schedule stays replayable (R36). `'await'`
201
+ * yields to the host until a file or socket wait settles, then continues
202
+ * stepping, for checks that run one ordered program against the real system.
203
+ * A real-timer wait still fails (`Escape`, per R2); `'await'` beside `path`
204
+ * or `choose` is rejected, so it cannot silently weaken an exploring run.
205
+ */
206
+ readonly external?: 'fail' | 'await';
207
+ /**
208
+ * `'body'` keeps every decision before `beginExploration` on Effect's order,
209
+ * so a harness's own setup is never explored (R15).
210
+ */
211
+ readonly explore?: 'all' | 'body';
212
+ /** Fails the run once it passes this many steps. */
213
+ readonly maxSteps?: number;
214
+ /** Microtask checkpoints drained after each step. */
215
+ readonly stepTurns?: number;
216
+ /** Microtask checkpoints drained once nothing is pending. */
217
+ readonly quiescenceTurns?: number;
218
+ /**
219
+ * Called once nothing in the process can run or wake a fiber after the
220
+ * kernel's clocks had their quiescent move (seam for live I/O waits, R16).
221
+ * Returning true continues the run; returning false classifies the stall.
222
+ */
223
+ readonly onQuiescent?: () => boolean;
224
+ }
225
+ /**
226
+ * Marks the point in a program where exploration may begin (R15). Under
227
+ * `explore: 'body'`, every decision before it stays on Effect's order.
228
+ */
229
+ /** @internal */
230
+ declare const beginExploration: Effect.Effect<void>;
231
+ //#endregion
232
+ //#region src/Kernel/Run.d.ts
233
+ declare const run: {
234
+ <A, E>(program: Effect.Effect<A, E>, options?: RunOptions): Promise<RunResult<A, E>>;
235
+ (options?: RunOptions): <A, E>(program: Effect.Effect<A, E>) => Promise<RunResult<A, E>>;
236
+ };
237
+ /**
238
+ * Whether the live run is inside a synchronous step. A library that samples a
239
+ * run from outside can tell work the run caused from work an outside fiber did
240
+ * between steps. `false` when no run is live.
241
+ */
242
+ declare const isStepping: () => boolean;
243
+ //#endregion
244
+ //#region src/Kernel/Pct.d.ts
245
+ interface PickOptions {
246
+ readonly seed: number;
247
+ readonly depth?: number;
248
+ readonly steps: number;
249
+ }
250
+ declare const pick: (options: PickOptions) => (choice: Choice) => Decision | undefined;
251
+ interface PctOptions<A, E> {
252
+ readonly seeds?: number;
253
+ readonly depth?: number;
254
+ readonly steps?: number;
255
+ readonly isFailure?: (result: RunResult<A, E>) => boolean;
256
+ readonly maxSteps?: number;
257
+ }
258
+ interface PctFailure<A, E> {
259
+ readonly seed: number;
260
+ readonly result: RunResult<A, E>;
261
+ }
262
+ interface PctOutcome<A, E> {
263
+ readonly failures: ReadonlyArray<PctFailure<A, E>>;
264
+ readonly bound: Bound;
265
+ }
266
+ declare const pct: {
267
+ <A, E>(program: Effect.Effect<A, E>, options?: PctOptions<A, E>): Promise<PctOutcome<A, E>>;
268
+ <A, E>(options?: PctOptions<A, E>): (program: Effect.Effect<A, E>) => Promise<PctOutcome<A, E>>;
269
+ };
270
+ //#endregion
271
+ //#region src/Kernel/Profile.d.ts
272
+ /**
273
+ * How much schedule exploration a run buys. `per-change` is the budget a pull
274
+ * request is judged on; `nightly` derives seed counts from a target miss rate;
275
+ * `local` is a developer's own machine, which caps the preemption bound and the
276
+ * seed count so feedback stays fast. A local pass is not the verdict: the same
277
+ * checks run at the per-change budget in CI.
278
+ */
279
+ type ProfileName = 'local' | 'per-change' | 'nightly';
280
+ declare const pctDepth = 3;
281
+ declare const perChangeSeeds = 250;
282
+ declare const localSeeds = 25;
283
+ declare const localPreemptions = 1;
284
+ declare const currentProfile: Effect.Effect<ProfileName, Config.ConfigError>;
285
+ interface Budget {
286
+ readonly fibers: number;
287
+ readonly steps: number;
288
+ }
289
+ declare const seedsFor: {
290
+ (budget: Budget, profile?: ProfileName): number;
291
+ (profile?: ProfileName): (budget: Budget) => number;
292
+ };
293
+ declare const currentSeedsFor: (budget: Budget) => Effect.Effect<number, Config.ConfigError>;
294
+ declare const preemptionsFor: {
295
+ (requested: number | undefined, profile: ProfileName): number | undefined;
296
+ (profile: ProfileName): (requested: number | undefined) => number | undefined;
297
+ };
298
+ declare const currentPreemptionsFor: (requested: number | undefined) => Effect.Effect<number | undefined, Config.ConfigError>;
299
+ //#endregion
300
+ //#region src/Kernel/Search.d.ts
301
+ declare const CompletedTag: {
302
+ readonly _tag: 'Completed';
303
+ };
304
+ declare const OverBudgetTag: {
305
+ readonly _tag: 'OverBudget';
306
+ };
307
+ type CompletedTag = typeof CompletedTag;
308
+ type OverBudgetTag = typeof OverBudgetTag;
309
+ declare const searchTags: {
310
+ readonly completed: {
311
+ readonly _tag: 'Completed';
312
+ };
313
+ readonly overBudget: {
314
+ readonly _tag: 'OverBudget';
315
+ };
316
+ };
317
+ interface SearchOptions<A, E> {
318
+ readonly preemptions?: number;
319
+ readonly maxSchedules?: number;
320
+ readonly isFailure?: (result: RunResult<A, E>) => boolean;
321
+ readonly maxSteps?: number;
322
+ readonly prune?: boolean;
323
+ }
324
+ interface SearchFailure<A, E> {
325
+ readonly path: ReadonlyArray<Decision>;
326
+ readonly preemptions: number;
327
+ readonly result: RunResult<A, E>;
328
+ }
329
+ interface SearchOutcome<A, E> extends CompletedTag {
330
+ readonly failures: ReadonlyArray<SearchFailure<A, E>>;
331
+ readonly bound: Bound;
332
+ }
333
+ interface OverBudgetOutcome<A, E> extends OverBudgetTag {
334
+ readonly failures: ReadonlyArray<SearchFailure<A, E>>;
335
+ readonly bound: Bound;
336
+ }
337
+ type SearchReport<A, E> = SearchOutcome<A, E> | OverBudgetOutcome<A, E>;
338
+ declare const search: {
339
+ <A, E>(program: Effect.Effect<A, E>, options?: SearchOptions<A, E>): Promise<SearchReport<A, E>>;
340
+ <A, E>(options?: SearchOptions<A, E>): (program: Effect.Effect<A, E>) => Promise<SearchReport<A, E>>;
341
+ };
342
+ //#endregion
343
+ //#region src/Kernel/Shrink.d.ts
344
+ interface ShrinkOptions<A, E> {
345
+ readonly path: ReadonlyArray<Decision>;
346
+ readonly isFailure?: (result: RunResult<A, E>) => boolean;
347
+ readonly maxSteps?: number;
348
+ }
349
+ interface ShrinkOutcome<A, E> {
350
+ readonly path: ReadonlyArray<Decision>;
351
+ readonly deviations: number;
352
+ readonly result: RunResult<A, E>;
353
+ }
354
+ declare const shrink: {
355
+ <A, E>(options: ShrinkOptions<A, E>): (program: Effect.Effect<A, E>) => Promise<ShrinkOutcome<A, E>>;
356
+ <A, E>(program: Effect.Effect<A, E>, options: ShrinkOptions<A, E>): Promise<ShrinkOutcome<A, E>>;
357
+ };
358
+ declare const shrinkCommands: {
359
+ <C>(commands: ReadonlyArray<C>, stillFails: (candidate: ReadonlyArray<C>) => Promise<boolean>): Promise<ReadonlyArray<C>>;
360
+ <C>(stillFails: (candidate: ReadonlyArray<C>) => Promise<boolean>): (commands: ReadonlyArray<C>) => Promise<ReadonlyArray<C>>;
361
+ };
362
+ declare namespace mod_d_exports {
363
+ export { AnyFiber, BlockedFailure, Bound, Budget, Choice, ChoiceOption, DeadlockFailure, Decision, Escape, EscapeFailure, FiberTarget, Interruption, OverBudgetOutcome, PctFailure, PctOptions, PctOutcome, 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 };
364
+ }
365
+ //#endregion
366
+ export { mod_d_exports as Kernel };