eutaxy 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/aws.d.mts +1 -1
- package/dist/aws.mjs +2 -2
- package/dist/aws.mjs.map +1 -1
- package/dist/bin.mjs +2 -2
- package/dist/cli-NqY61bpo.mjs +2 -0
- package/dist/cli.d.mts.map +1 -1
- package/dist/cli.mjs +2 -2
- package/dist/cloudflare.d.mts +84 -7
- package/dist/cloudflare.d.mts.map +1 -1
- package/dist/cloudflare.mjs +980 -248
- package/dist/cloudflare.mjs.map +1 -1
- package/dist/{explore-YVHTRjjS.d.mts → explore-BHYvAZKN.d.mts} +23 -2
- package/dist/explore-BHYvAZKN.d.mts.map +1 -0
- package/dist/index.d.mts +233 -5
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +259 -3
- package/dist/index.mjs.map +1 -0
- package/dist/{platform-TwATAkL3.d.mts → platform-eVgCMbX0.d.mts} +121 -5
- package/dist/platform-eVgCMbX0.d.mts.map +1 -0
- package/dist/{src-BGdIBGkN.mjs → src-BD3jkjgG.mjs} +182 -16
- package/dist/src-BD3jkjgG.mjs.map +1 -0
- package/dist/{src-Brt0dfNL.mjs → src-C19_yfMM.mjs} +1029 -78
- package/dist/src-C19_yfMM.mjs.map +1 -0
- package/dist/src-CgfGiH25.mjs +1546 -0
- package/dist/src-CgfGiH25.mjs.map +1 -0
- package/dist/verdict-evEM5Gxx.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/cli-Dr-Ziogu.mjs +0 -2
- package/dist/explore-YVHTRjjS.d.mts.map +0 -1
- package/dist/platform-TwATAkL3.d.mts.map +0 -1
- package/dist/src-BBXd0WEp.mjs +0 -117
- package/dist/src-BBXd0WEp.mjs.map +0 -1
- package/dist/src-BGdIBGkN.mjs.map +0 -1
- package/dist/src-Brt0dfNL.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,221 @@
|
|
|
1
|
-
import { C as
|
|
2
|
-
import { a as BoundsReached, c as Violated, i as Bounded, l as describeVerdict, n as explore, o as ScenarioVerdict, r as replay, s as Unsupported, t as ExploreOptions } from "./explore-
|
|
1
|
+
import { C as FaultDecision, D as EffectRecord, E as EffectLog, S as checkInvariants, T as Schedule, _ as RowCondition, b as Violation, d as AtMostOncePerKey, f as EffectSelector, g as Refines, h as Invariant, l as validateScenario, m as Implies, n as Platform, o as ScenarioSpec, p as EveryRow, r as Bounds, t as EventRef, u as AtLeastOnce, v as StateQuery, w as FaultKind, x as checkInvariant, y as Unique } from "./platform-eVgCMbX0.mjs";
|
|
2
|
+
import { a as BoundsReached, c as Violated, i as Bounded, l as describeVerdict, n as explore, o as ScenarioVerdict, r as replay, s as Unsupported, t as ExploreOptions } from "./explore-BHYvAZKN.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Spec verdicts: what is known about one property of one pure function.
|
|
5
|
+
* Kept apart from scenario verdicts in every report. The ladder starts at
|
|
6
|
+
* `CHECKED` (held on every input the simulator passed); `TESTED` and
|
|
7
|
+
* `PROVEN` come with the provers.
|
|
8
|
+
*/
|
|
9
|
+
interface SpecVerdictBase {
|
|
10
|
+
/** The module, as the scenario names it. */
|
|
11
|
+
readonly module: string;
|
|
12
|
+
readonly function: string;
|
|
13
|
+
/** The `@ensures` name, or `@total` / `@throws` for those markers. */
|
|
14
|
+
readonly property: string;
|
|
15
|
+
/** The property as written. */
|
|
16
|
+
readonly text: string;
|
|
17
|
+
readonly assumptions: readonly string[];
|
|
18
|
+
}
|
|
19
|
+
interface Checked extends SpecVerdictBase {
|
|
20
|
+
readonly kind: "CHECKED";
|
|
21
|
+
/** Distinct inputs the property was evaluated on. */
|
|
22
|
+
readonly inputs: number;
|
|
23
|
+
/** Distinct inputs outside the claim: a precondition failed, or a value fell outside its binder's domain. */
|
|
24
|
+
readonly discarded: number;
|
|
25
|
+
}
|
|
26
|
+
/** One assignment that breaks the property, as JavaScript literals, and the call it came from. */
|
|
27
|
+
interface Counterexample {
|
|
28
|
+
/** In the property's binder order. */
|
|
29
|
+
readonly binders: readonly {
|
|
30
|
+
readonly name: string;
|
|
31
|
+
readonly value: string;
|
|
32
|
+
}[];
|
|
33
|
+
readonly call: string;
|
|
34
|
+
/** Set when evaluating the property threw instead of returning false. */
|
|
35
|
+
readonly error?: string;
|
|
36
|
+
}
|
|
37
|
+
interface Refuted extends SpecVerdictBase {
|
|
38
|
+
readonly kind: "REFUTED";
|
|
39
|
+
readonly rung: "CHECKED";
|
|
40
|
+
readonly counterexample: Counterexample;
|
|
41
|
+
}
|
|
42
|
+
type SpecUnknownCause = "gave_up" | "unsupported" | "unavailable";
|
|
43
|
+
interface SpecUnknown extends SpecVerdictBase {
|
|
44
|
+
readonly kind: "UNKNOWN";
|
|
45
|
+
readonly cause: SpecUnknownCause;
|
|
46
|
+
readonly reason: string;
|
|
47
|
+
}
|
|
48
|
+
type SpecVerdict = Checked | Refuted | SpecUnknown;
|
|
49
|
+
/** One line per spec verdict, for error messages; full rendering lives in `report`. */
|
|
50
|
+
export declare function describeSpecVerdict(v: SpecVerdict): string;
|
|
51
|
+
interface ObservedCall {
|
|
52
|
+
readonly function: string;
|
|
53
|
+
/** The arguments as passed; primitives exactly, objects by reference. */
|
|
54
|
+
readonly args: readonly unknown[];
|
|
55
|
+
readonly threw: boolean;
|
|
56
|
+
}
|
|
57
|
+
interface CoreObserver {
|
|
58
|
+
readonly calls: readonly ObservedCall[];
|
|
59
|
+
/** Functions that could not be observed, with why. */
|
|
60
|
+
readonly unobservable: {
|
|
61
|
+
readonly [fn: string]: string;
|
|
62
|
+
};
|
|
63
|
+
/** Put the original exports back. Safe to call twice. */
|
|
64
|
+
restore(): void;
|
|
65
|
+
}
|
|
66
|
+
export declare function observeCore(namespace: object, functions: readonly string[]): CoreObserver;
|
|
3
67
|
/** The scenario restricted to the kept events, with per-message invariants re-derived. */
|
|
4
68
|
export declare function restrictSpec(platform: Platform, spec: ScenarioSpec, keepIds: readonly string[]): ScenarioSpec;
|
|
69
|
+
/**
|
|
70
|
+
* SpecIR: function specs as plain data. The surface syntax is Lemma
|
|
71
|
+
* (https://github.com/jessealama/lemma-lang, grammar.ebnf and
|
|
72
|
+
* semantics.md); the IR is Eutaxy's own, so engines and the simulator read
|
|
73
|
+
* one shape whatever the annotation looked like. Leaves are opaque
|
|
74
|
+
* TypeScript expressions, kept as written.
|
|
75
|
+
*/
|
|
76
|
+
/** Lemma's binder domains. */
|
|
77
|
+
type Domain = "int" | "nat" | "number" | "boolean" | "string" | "bigint";
|
|
78
|
+
/**
|
|
79
|
+
* One end of an interval: a numeric literal as written (sign included), or
|
|
80
|
+
* `∞` / `-∞` for either infinity. `[` and `]` include the endpoint.
|
|
81
|
+
*/
|
|
82
|
+
interface Endpoint {
|
|
83
|
+
readonly value: string;
|
|
84
|
+
readonly inclusive: boolean;
|
|
85
|
+
}
|
|
86
|
+
/** A binder's constraint: an interval for numeric domains, a whole-string regex for `string`. */
|
|
87
|
+
type Guard = {
|
|
88
|
+
readonly kind: "interval";
|
|
89
|
+
readonly lower: Endpoint;
|
|
90
|
+
readonly upper: Endpoint;
|
|
91
|
+
} | {
|
|
92
|
+
readonly kind: "regex";
|
|
93
|
+
readonly pattern: string;
|
|
94
|
+
readonly flags: string;
|
|
95
|
+
};
|
|
96
|
+
interface Binder {
|
|
97
|
+
readonly name: string;
|
|
98
|
+
readonly domain: Domain;
|
|
99
|
+
readonly guard?: Guard;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* A formula over boolean atoms. Atoms and equation sides are TypeScript
|
|
103
|
+
* expressions, verbatim. `and` and `or` are n-ary (both are associative);
|
|
104
|
+
* `implies` keeps Lemma's chain: every segment but the last is an
|
|
105
|
+
* antecedent. An implication at a property's root is not a formula node but
|
|
106
|
+
* the property's preconditions (`Property.requires`).
|
|
107
|
+
*/
|
|
108
|
+
type Formula = {
|
|
109
|
+
readonly kind: "atom";
|
|
110
|
+
readonly text: string;
|
|
111
|
+
} | {
|
|
112
|
+
readonly kind: "equation";
|
|
113
|
+
readonly left: string;
|
|
114
|
+
readonly right: string;
|
|
115
|
+
/** `≢` rather than `≡`. */
|
|
116
|
+
readonly negated: boolean;
|
|
117
|
+
} | {
|
|
118
|
+
readonly kind: "not";
|
|
119
|
+
readonly operand: Formula;
|
|
120
|
+
} | {
|
|
121
|
+
readonly kind: "and" | "or";
|
|
122
|
+
readonly operands: readonly Formula[];
|
|
123
|
+
} | {
|
|
124
|
+
readonly kind: "implies";
|
|
125
|
+
readonly antecedents: readonly Formula[];
|
|
126
|
+
readonly consequent: Formula;
|
|
127
|
+
} | {
|
|
128
|
+
readonly kind: "iff";
|
|
129
|
+
readonly left: Formula;
|
|
130
|
+
readonly right: Formula;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* A universally quantified claim: for every assignment of the binders from
|
|
134
|
+
* their (guarded) domains where every precondition holds, `claim` holds.
|
|
135
|
+
* Assignments failing a precondition are outside the claim.
|
|
136
|
+
*/
|
|
137
|
+
interface Property {
|
|
138
|
+
readonly binders: readonly Binder[];
|
|
139
|
+
readonly requires: readonly Formula[];
|
|
140
|
+
readonly claim: Formula;
|
|
141
|
+
}
|
|
142
|
+
/** An `@ensures{name}` annotation. */
|
|
143
|
+
interface NamedProperty {
|
|
144
|
+
readonly name: string;
|
|
145
|
+
readonly property: Property;
|
|
146
|
+
/** The annotation's property text, as written. */
|
|
147
|
+
readonly text: string;
|
|
148
|
+
}
|
|
149
|
+
/** The specs on one exported function. */
|
|
150
|
+
interface FunctionSpec {
|
|
151
|
+
readonly name: string;
|
|
152
|
+
/** Parameter names in order; null for a destructured or rest parameter. */
|
|
153
|
+
readonly params: readonly (string | null)[];
|
|
154
|
+
readonly ensures: readonly NamedProperty[];
|
|
155
|
+
/** `@total`: the function terminates on every input. */
|
|
156
|
+
readonly total: boolean;
|
|
157
|
+
/** `@throws`: the function throws (Lemma has not fixed its semantics yet). */
|
|
158
|
+
readonly throws: boolean;
|
|
159
|
+
/** 1-based line of the declaration. */
|
|
160
|
+
readonly line: number;
|
|
161
|
+
}
|
|
162
|
+
/** A problem with an annotation, located in the module. */
|
|
163
|
+
interface SpecError {
|
|
164
|
+
readonly line: number;
|
|
165
|
+
readonly message: string;
|
|
166
|
+
}
|
|
167
|
+
/** Every spec in one module, the names it exports, and the annotations that did not parse. */
|
|
168
|
+
interface ModuleSpecs {
|
|
169
|
+
readonly functions: readonly FunctionSpec[];
|
|
170
|
+
readonly exports: readonly string[];
|
|
171
|
+
readonly errors: readonly SpecError[];
|
|
172
|
+
}
|
|
173
|
+
export declare function extractSpecs(source: string): ModuleSpecs;
|
|
174
|
+
/** A property that is not Lemma. `stage` says which part rejected it. */
|
|
175
|
+
export declare class LemmaSyntaxError extends Error {
|
|
176
|
+
readonly stage: "prefix" | "formula";
|
|
177
|
+
constructor(stage: "prefix" | "formula", message: string);
|
|
178
|
+
}
|
|
179
|
+
/** Parse the text after `@ensures{name}`. Throws LemmaSyntaxError. */
|
|
180
|
+
export declare function parseProperty(text: string): Property;
|
|
181
|
+
/** The outcome a predicate returns for one assignment. */
|
|
182
|
+
type PredicateOutcome = "held" | "discarded" | "refuted";
|
|
183
|
+
/** The property as Lemma text (what follows `@ensures{name}`). */
|
|
184
|
+
export declare function printProperty(p: Property): string;
|
|
185
|
+
/** What generated predicates call when free names did not resolve. */
|
|
186
|
+
export declare function lemmaUnresolved(names: readonly string[]): never;
|
|
187
|
+
/** The atom check generated predicates call: its argument when it is a boolean. */
|
|
188
|
+
export declare function lemmaBool(value: unknown): boolean;
|
|
189
|
+
interface CheckedInput {
|
|
190
|
+
readonly module: string;
|
|
191
|
+
readonly fn: FunctionSpec;
|
|
192
|
+
readonly property: NamedProperty;
|
|
193
|
+
/** The calls the simulator made, with their arguments. */
|
|
194
|
+
readonly calls: readonly {
|
|
195
|
+
readonly args: readonly unknown[];
|
|
196
|
+
}[];
|
|
197
|
+
/** The compiled predicate over the binders, or undefined when it could not be built. */
|
|
198
|
+
readonly predicate: ((...binders: never[]) => PredicateOutcome) | undefined;
|
|
199
|
+
/** Why the function's calls could not be observed, when they could not. */
|
|
200
|
+
readonly unobservable?: string;
|
|
201
|
+
}
|
|
202
|
+
export declare function checkedRung(input: CheckedInput): SpecVerdict;
|
|
203
|
+
/** Compiled predicates of a module, by function and property name. */
|
|
204
|
+
interface ModulePredicates {
|
|
205
|
+
readonly [fn: string]: {
|
|
206
|
+
readonly [property: string]: (...binders: never[]) => PredicateOutcome;
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
/** Every spec verdict for one module, from what was observed of its calls. */
|
|
210
|
+
export declare function checkSpecModule(module: string, specs: ModuleSpecs, predicates: ModulePredicates, observed: {
|
|
211
|
+
readonly calls: readonly {
|
|
212
|
+
readonly function: string;
|
|
213
|
+
readonly args: readonly unknown[];
|
|
214
|
+
}[];
|
|
215
|
+
readonly unobservable: {
|
|
216
|
+
readonly [fn: string]: string;
|
|
217
|
+
};
|
|
218
|
+
}): SpecVerdict[];
|
|
5
219
|
interface RegressionTestOptions {
|
|
6
220
|
/** Import lines for the scenario, the platform's dependencies, and anything the platform expression needs. */
|
|
7
221
|
readonly imports: readonly string[];
|
|
@@ -12,13 +226,27 @@ interface RegressionTestOptions {
|
|
|
12
226
|
/** Module that exports `replay`, `restrictSpec` and `checkInvariants`; the public facade by default. */
|
|
13
227
|
readonly engineModule?: string;
|
|
14
228
|
readonly expect?: "holds" | "violates";
|
|
229
|
+
/**
|
|
230
|
+
* Core functions to observe during the replay, as `refines` needs their
|
|
231
|
+
* decisions in the log: an expression for each module's namespace (from
|
|
232
|
+
* the imports) and the functions to observe on it.
|
|
233
|
+
*/
|
|
234
|
+
readonly observe?: readonly {
|
|
235
|
+
readonly namespace: string;
|
|
236
|
+
readonly functions: readonly string[];
|
|
237
|
+
}[];
|
|
15
238
|
}
|
|
16
239
|
export declare function emitRegressionTest(verdict: Violated, options: RegressionTestOptions): string;
|
|
17
|
-
/**
|
|
18
|
-
|
|
240
|
+
/**
|
|
241
|
+
* The JSON report: one object, canonical, with a schema version at the top.
|
|
242
|
+
* Spec verdicts, when there are any, sit beside the scenario's, never in it.
|
|
243
|
+
*/
|
|
244
|
+
export declare function renderJson(verdict: ScenarioVerdict, specs?: readonly SpecVerdict[]): string;
|
|
245
|
+
/** Spec verdicts as text: one line each, a counterexample under a refutation. */
|
|
246
|
+
export declare function renderSpecs(specs: readonly SpecVerdict[]): string;
|
|
19
247
|
/** The trace as a fixed-width table; evidence rows are marked with `*`. */
|
|
20
248
|
export declare function renderTrace(log: EffectLog, evidence?: readonly number[]): string;
|
|
21
249
|
/** A readable report: verdict, what it rests on, and for a violation the schedule and trace. */
|
|
22
250
|
export declare function renderText(verdict: ScenarioVerdict): string;
|
|
23
|
-
export { type AtLeastOnce, type AtMostOncePerKey, type Bounded, type Bounds, type BoundsReached, type EffectLog, type EffectRecord, type EffectSelector, type EventRef, type EveryRow, type ExploreOptions, type FaultDecision, type FaultKind, type Implies, type Invariant, type Platform, type RegressionTestOptions, type RowCondition, type ScenarioSpec, type ScenarioVerdict, type Schedule, type StateQuery, type Unsupported, type Violated, type Violation, checkInvariant, checkInvariants, describeVerdict, explore, replay, validateScenario };
|
|
251
|
+
export { type AtLeastOnce, type AtMostOncePerKey, type Binder, type Bounded, type Bounds, type BoundsReached, type Checked, type CoreObserver, type Counterexample, type Domain, type EffectLog, type EffectRecord, type EffectSelector, type EventRef, type EveryRow, type ExploreOptions, type FaultDecision, type FaultKind, type Formula, type FunctionSpec, type Guard, type Implies, type Invariant, type ModulePredicates, type ModuleSpecs, type NamedProperty, type ObservedCall, type Platform, type Property, type Refines, type Refuted, type RegressionTestOptions, type RowCondition, type ScenarioSpec, type ScenarioVerdict, type Schedule, type SpecUnknown, type SpecVerdict, type StateQuery, type Unique, type Unsupported, type Violated, type Violation, checkInvariant, checkInvariants, describeVerdict, explore, replay, validateScenario };
|
|
24
252
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../engine/src/shrink.ts","../../report/src/regression.ts","../../report/src/render.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../core/src/spec-verdict.ts","../../engine/src/observe.ts","../../engine/src/shrink.ts","../../spec/src/ir.ts","../../spec/src/extract.ts","../../spec/src/parse.ts","../../spec/src/predicate.ts","../../spec/src/print.ts","../../prover/src/checked.ts","../../report/src/regression.ts","../../report/src/render.ts"],"mappings":";;;;;;;;UAOU;;WAEC;WACA;;WAEA;;WAEA;WACA;;UAGM,gBAAgB;WACtB;;WAEA;;WAEA;;;UAIM;;WAEN;aAA6B;aAAuB;;WACpD;;WAEA;;UAGM,gBAAgB;WACtB;WACA;WACA,gBAAgB;;KAGf;UAEK,oBAAoB;WAC1B;WACA,OAAO;WACP;;KAGC,cAAc,UAAU,UAAU;;wBAG9B,oBAAoB,GAAG;UCnCtB;WACN;;WAEA;WACA;;UAGM;WACN,gBAAgB;;WAEhB;cAA0B;;;EAEnC;;wBA0Cc,YAAY,mBAAmB,+BAA+B;;wBCjC9D,aACd,UAAU,UACV,MAAM,cACN,6BACC;;;;;;;;;KCjCS;;;;;UAQK;WACN;WACA;;;KAIC;WACG;WAA2B,OAAO;WAAmB,OAAO;;WAC5D;WAAwB;WAA0B;;UAEhD;WACN;WACA,QAAQ;WACR,QAAQ;;;;;;;;;KAUP;WACG;WAAuB;;WAEvB;WACA;WACA;;WAEA;;WAEA;WAAsB,SAAS;;WAC/B;WAA6B,mBAAmB;;WAEhD;WACA,sBAAsB;WACtB,YAAY;;WAEZ;WAAsB,MAAM;WAAkB,OAAO;;;;;;;UAOnD;WACN,kBAAkB;WAClB,mBAAmB;WACnB,OAAO;;;UAID;WACN;WACA,UAAU;;WAEV;;;UAIM;WACN;;WAEA;WACA,kBAAkB;;WAElB;;WAEA;;WAEA;;;UAIM;WACN;WACA;;;UAIM;WACN,oBAAoB;WACpB;WACA,iBAAiB;;wBCuEZ,aAAa,iBAAiB;;qBCjJjC,yBAAyB;WAC3B;EACT,YAAY,6BAA6B;;;wBAmC3B,cAAc,eAAe;;KCnDjC;;wBCgEI,cAAc,GAAG;;wBClDjB,gBAAgB;;wBAOhB,UAAU;UAqET;WACN;WACA,IAAI;WACJ,UAAU;;WAEV;aAA2B;;;WAE3B,gBAAgB,qBAAqB;;WAErC;;wBAGK,YAAY,OAAO,eAAe;;UA2HjC;YACL;cAAyB,uBAAuB,qBAAqB;;;;wBAIjE,gBACd,gBACA,OAAO,aACP,YAAY,kBACZ;WACW;aAA2B;aAA2B;;WACtD;cAA0B;;IAEpC;UC9Oc;;WAEN;;WAEA;;WAEA;;WAEA;WACA;;;;;;WAMA;aACE;aACA;;;wBAIG,mBAAmB,SAAS,UAAU,SAAS;;;;;wBCf/C,WAAW,SAAS,iBAAiB,iBAAgB;;wBAUrD,YAAY,gBAAgB;;wBAqC5B,YAAY,KAAK,WAAW;;wBAuB5B,WAAW,SAAS"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,261 @@
|
|
|
1
1
|
import "./src-s6uYyC0B.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { g as checkInvariants, h as checkInvariant, i as restrictSpec, m as validateScenario, n as explore, r as replay, t as observeCore } from "./src-C19_yfMM.mjs";
|
|
3
3
|
import { t as describeVerdict } from "./verdict-evEM5Gxx.mjs";
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import { a as emitRegressionTest, c as LemmaSyntaxError, i as renderTrace, l as endpointNumber, n as renderSpecs, r as renderText, s as extractSpecs, t as renderJson, u as parseProperty } from "./src-CgfGiH25.mjs";
|
|
5
|
+
// packages/core/src/spec-verdict.ts
|
|
6
|
+
/** One line per spec verdict, for error messages; full rendering lives in `report`. */
|
|
7
|
+
function describeSpecVerdict(v) {
|
|
8
|
+
const what = `${v.function} ${v.property}`;
|
|
9
|
+
switch (v.kind) {
|
|
10
|
+
case "CHECKED": return `CHECKED ${what}: held on ${v.inputs} input(s) the simulator passed`;
|
|
11
|
+
case "REFUTED": return `REFUTED ${what}: ${v.counterexample.call}${v.counterexample.error ? ` threw ${v.counterexample.error}` : ""}`;
|
|
12
|
+
case "UNKNOWN": return `UNKNOWN ${what}: ${v.cause}: ${v.reason}`;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
// packages/spec/src/print.ts
|
|
16
|
+
const precedence = {
|
|
17
|
+
iff: 1,
|
|
18
|
+
implies: 2,
|
|
19
|
+
or: 3,
|
|
20
|
+
and: 4,
|
|
21
|
+
not: 5,
|
|
22
|
+
atom: 6,
|
|
23
|
+
equation: 6
|
|
24
|
+
};
|
|
25
|
+
function guardText(g) {
|
|
26
|
+
if (g.kind === "regex") return `/${g.pattern}/${g.flags}`;
|
|
27
|
+
return `${g.lower.inclusive ? "[" : "("}${g.lower.value}, ${g.upper.value}${g.upper.inclusive ? "]" : ")"}`;
|
|
28
|
+
}
|
|
29
|
+
function sameGroup(a, b) {
|
|
30
|
+
return a.domain === b.domain && a.guard === void 0 === (b.guard === void 0) && (a.guard === void 0 || b.guard !== void 0 && guardText(a.guard) === guardText(b.guard));
|
|
31
|
+
}
|
|
32
|
+
function prefixText(binders) {
|
|
33
|
+
const groups = [];
|
|
34
|
+
for (const b of binders) {
|
|
35
|
+
const last = groups[groups.length - 1];
|
|
36
|
+
if (last && sameGroup(last[0], b)) last.push(b);
|
|
37
|
+
else groups.push([b]);
|
|
38
|
+
}
|
|
39
|
+
return `forall ${groups.map((g) => {
|
|
40
|
+
const head = g[0];
|
|
41
|
+
const guard = head.guard ? ` ∈ ${guardText(head.guard)}` : "";
|
|
42
|
+
return `(${g.map((b) => b.name).join(" ")}: ${head.domain}${guard})`;
|
|
43
|
+
}).join(" ")}`;
|
|
44
|
+
}
|
|
45
|
+
/** Print a formula, parenthesized when its precedence is below `min`. */
|
|
46
|
+
function printFormula(f, min = 0) {
|
|
47
|
+
let s;
|
|
48
|
+
switch (f.kind) {
|
|
49
|
+
case "atom":
|
|
50
|
+
s = f.text;
|
|
51
|
+
break;
|
|
52
|
+
case "equation":
|
|
53
|
+
s = `${f.left} ${f.negated ? "≢" : "≡"} ${f.right}`;
|
|
54
|
+
break;
|
|
55
|
+
case "not":
|
|
56
|
+
s = `¬${printFormula(f.operand, precedence.not)}`;
|
|
57
|
+
break;
|
|
58
|
+
case "and":
|
|
59
|
+
case "or":
|
|
60
|
+
s = f.operands.map((o) => printFormula(o, precedence[f.kind] + 1)).join(f.kind === "and" ? " ∧ " : " ∨ ");
|
|
61
|
+
break;
|
|
62
|
+
case "implies":
|
|
63
|
+
s = [...f.antecedents, f.consequent].map((o) => printFormula(o, precedence.or)).join(" → ");
|
|
64
|
+
break;
|
|
65
|
+
case "iff": s = `${printFormula(f.left, precedence.implies)} ↔ ${printFormula(f.right, precedence.implies)}`;
|
|
66
|
+
}
|
|
67
|
+
return precedence[f.kind] < min ? `(${s})` : s;
|
|
68
|
+
}
|
|
69
|
+
/** The property as Lemma text (what follows `@ensures{name}`). */
|
|
70
|
+
function printProperty(p) {
|
|
71
|
+
const body = p.requires.length > 0 ? [...p.requires, p.claim].map((f) => printFormula(f, precedence.or)).join(" → ") : printFormula(p.claim, p.claim.kind === "implies" ? precedence.or : 0);
|
|
72
|
+
return `${prefixText(p.binders)} { ${body} }`;
|
|
73
|
+
}
|
|
74
|
+
// packages/prover/src/checked.ts
|
|
75
|
+
/** Thrown by `lemmaBool` when an atom is not a genuine boolean: the property is malformed, not false. */
|
|
76
|
+
var AtomNotBoolean = class extends TypeError {};
|
|
77
|
+
/** Thrown by `lemmaUnresolved`: the property names something neither its module nor the globals define. */
|
|
78
|
+
var UnresolvedName = class extends ReferenceError {};
|
|
79
|
+
/** What generated predicates call when free names did not resolve. */
|
|
80
|
+
function lemmaUnresolved(names) {
|
|
81
|
+
throw new UnresolvedName(`the property refers to ${names.join(", ")}, which neither its module exports nor the globals define`);
|
|
82
|
+
}
|
|
83
|
+
/** The atom check generated predicates call: its argument when it is a boolean. */
|
|
84
|
+
function lemmaBool(value) {
|
|
85
|
+
if (typeof value !== "boolean") throw new AtomNotBoolean(`a Lemma atom evaluated to ${render(value)}, not a boolean`);
|
|
86
|
+
return value;
|
|
87
|
+
}
|
|
88
|
+
/** A value as a JavaScript literal, exact for the binder domains. */
|
|
89
|
+
function render(value) {
|
|
90
|
+
switch (typeof value) {
|
|
91
|
+
case "bigint": return `${value}n`;
|
|
92
|
+
case "number": return Object.is(value, -0) ? "-0" : String(value);
|
|
93
|
+
case "string": return JSON.stringify(value);
|
|
94
|
+
case "undefined": return "undefined";
|
|
95
|
+
case "boolean": return String(value);
|
|
96
|
+
case "function": return "[function]";
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const text = JSON.stringify(value, (_, v) => typeof v === "bigint" ? `${v}n` : v);
|
|
100
|
+
return text === void 0 ? String(value) : text.length > 200 ? `${text.slice(0, 200)}…` : text;
|
|
101
|
+
} catch {
|
|
102
|
+
return String(value);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function bound(value, integral) {
|
|
106
|
+
if (integral && !value.endsWith("∞")) return BigInt(value.replace(/_/g, "").replace(/n$/, ""));
|
|
107
|
+
return endpointNumber(value);
|
|
108
|
+
}
|
|
109
|
+
/** Whether a value lies in a binder's domain and guard. */
|
|
110
|
+
function inDomain(b, v) {
|
|
111
|
+
switch (b.domain) {
|
|
112
|
+
case "int":
|
|
113
|
+
if (!(typeof v === "number" && Number.isInteger(v))) return false;
|
|
114
|
+
break;
|
|
115
|
+
case "nat":
|
|
116
|
+
if (!(typeof v === "number" && Number.isInteger(v) && v >= 0)) return false;
|
|
117
|
+
break;
|
|
118
|
+
case "number":
|
|
119
|
+
if (typeof v !== "number") return false;
|
|
120
|
+
break;
|
|
121
|
+
case "bigint":
|
|
122
|
+
if (typeof v !== "bigint") return false;
|
|
123
|
+
break;
|
|
124
|
+
case "string":
|
|
125
|
+
if (typeof v !== "string") return false;
|
|
126
|
+
break;
|
|
127
|
+
case "boolean": return typeof v === "boolean";
|
|
128
|
+
}
|
|
129
|
+
const g = b.guard;
|
|
130
|
+
if (!g) return true;
|
|
131
|
+
if (g.kind === "regex") return new RegExp(`^(?:${g.pattern})$`, g.flags).test(v);
|
|
132
|
+
const integral = b.domain !== "number";
|
|
133
|
+
const x = integral ? BigInt(v) : v;
|
|
134
|
+
const lo = bound(g.lower.value, integral);
|
|
135
|
+
const hi = bound(g.upper.value, integral);
|
|
136
|
+
const aboveLower = g.lower.inclusive ? x >= lo : x > lo;
|
|
137
|
+
const belowUpper = g.upper.inclusive ? x <= hi : x < hi;
|
|
138
|
+
return aboveLower && belowUpper;
|
|
139
|
+
}
|
|
140
|
+
function checkedRung(input) {
|
|
141
|
+
const { module, fn, property } = input;
|
|
142
|
+
const base = {
|
|
143
|
+
module,
|
|
144
|
+
function: fn.name,
|
|
145
|
+
property: property.name,
|
|
146
|
+
text: property.text
|
|
147
|
+
};
|
|
148
|
+
const unknown = (cause, reason) => ({
|
|
149
|
+
...base,
|
|
150
|
+
kind: "UNKNOWN",
|
|
151
|
+
cause,
|
|
152
|
+
reason,
|
|
153
|
+
assumptions: []
|
|
154
|
+
});
|
|
155
|
+
if (input.unobservable) return unknown("unavailable", `calls to ${fn.name} could not be observed: ${input.unobservable}`);
|
|
156
|
+
const predicate = input.predicate;
|
|
157
|
+
if (!predicate) return unknown("unavailable", "the property's predicate was not compiled");
|
|
158
|
+
const binders = property.property.binders;
|
|
159
|
+
const positions = [];
|
|
160
|
+
for (const b of binders) {
|
|
161
|
+
const at = fn.params.indexOf(b.name);
|
|
162
|
+
if (at < 0) return unknown("unsupported", `binder ${b.name} is not a parameter of ${fn.name}, so the inputs the simulator passed do not determine it`);
|
|
163
|
+
positions.push(at);
|
|
164
|
+
}
|
|
165
|
+
const seen = /* @__PURE__ */ new Set();
|
|
166
|
+
let held = 0;
|
|
167
|
+
let discarded = 0;
|
|
168
|
+
for (const call of input.calls) {
|
|
169
|
+
const values = positions.map((p) => call.args[p]);
|
|
170
|
+
const key = values.map(render).join(", ");
|
|
171
|
+
if (seen.has(key)) continue;
|
|
172
|
+
seen.add(key);
|
|
173
|
+
if (!binders.every((b, i) => inDomain(b, values[i]))) {
|
|
174
|
+
discarded++;
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
const counterexample = (error) => ({
|
|
178
|
+
binders: binders.map((b, i) => ({
|
|
179
|
+
name: b.name,
|
|
180
|
+
value: render(values[i])
|
|
181
|
+
})),
|
|
182
|
+
call: `${fn.name}(${call.args.map(render).join(", ")})`,
|
|
183
|
+
...error === void 0 ? {} : { error }
|
|
184
|
+
});
|
|
185
|
+
let outcome;
|
|
186
|
+
try {
|
|
187
|
+
outcome = predicate(...values);
|
|
188
|
+
} catch (err) {
|
|
189
|
+
if (err instanceof AtomNotBoolean || err instanceof ReferenceError) return unknown("unsupported", `the property could not be evaluated: ${String(err)}`);
|
|
190
|
+
return {
|
|
191
|
+
...base,
|
|
192
|
+
kind: "REFUTED",
|
|
193
|
+
rung: "CHECKED",
|
|
194
|
+
counterexample: counterexample(String(err)),
|
|
195
|
+
assumptions: []
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
if (outcome === "refuted") return {
|
|
199
|
+
...base,
|
|
200
|
+
kind: "REFUTED",
|
|
201
|
+
rung: "CHECKED",
|
|
202
|
+
counterexample: counterexample(),
|
|
203
|
+
assumptions: []
|
|
204
|
+
};
|
|
205
|
+
if (outcome === "discarded") discarded++;
|
|
206
|
+
else held++;
|
|
207
|
+
}
|
|
208
|
+
if (held === 0) return unknown("gave_up", input.calls.length === 0 ? `the simulator never called ${fn.name}` : `none of the ${seen.size} distinct input(s) the simulator passed is inside the claim (domains, guards, preconditions)`);
|
|
209
|
+
return {
|
|
210
|
+
...base,
|
|
211
|
+
kind: "CHECKED",
|
|
212
|
+
inputs: held,
|
|
213
|
+
discarded,
|
|
214
|
+
assumptions: [`held on the ${held} distinct input(s) the simulator passed to ${fn.name}; inputs it never passed are not covered`]
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
/** Verdicts for the markers the CHECKED rung cannot decide. */
|
|
218
|
+
function markerVerdicts(module, fn) {
|
|
219
|
+
const out = [];
|
|
220
|
+
const base = {
|
|
221
|
+
module,
|
|
222
|
+
function: fn.name,
|
|
223
|
+
assumptions: []
|
|
224
|
+
};
|
|
225
|
+
if (fn.total) out.push({
|
|
226
|
+
...base,
|
|
227
|
+
property: "@total",
|
|
228
|
+
text: "@total",
|
|
229
|
+
kind: "UNKNOWN",
|
|
230
|
+
cause: "unsupported",
|
|
231
|
+
reason: "termination is not observable on the inputs the simulator passed; @total needs a prover"
|
|
232
|
+
});
|
|
233
|
+
if (fn.throws) out.push({
|
|
234
|
+
...base,
|
|
235
|
+
property: "@throws",
|
|
236
|
+
text: "@throws",
|
|
237
|
+
kind: "UNKNOWN",
|
|
238
|
+
cause: "unsupported",
|
|
239
|
+
reason: "Lemma has not fixed what @throws claims yet"
|
|
240
|
+
});
|
|
241
|
+
return out;
|
|
242
|
+
}
|
|
243
|
+
/** Every spec verdict for one module, from what was observed of its calls. */
|
|
244
|
+
function checkSpecModule(module, specs, predicates, observed) {
|
|
245
|
+
return specs.functions.flatMap((fn) => {
|
|
246
|
+
const calls = observed.calls.filter((c) => c.function === fn.name);
|
|
247
|
+
const unobservable = Object.hasOwn(observed.unobservable, fn.name) ? observed.unobservable[fn.name] : void 0;
|
|
248
|
+
const own = Object.hasOwn(predicates, fn.name) ? predicates[fn.name] : void 0;
|
|
249
|
+
return [...fn.ensures.map((property) => checkedRung({
|
|
250
|
+
module,
|
|
251
|
+
fn,
|
|
252
|
+
property,
|
|
253
|
+
calls,
|
|
254
|
+
predicate: own && Object.hasOwn(own, property.name) ? own[property.name] : void 0,
|
|
255
|
+
...unobservable === void 0 ? {} : { unobservable }
|
|
256
|
+
})), ...markerVerdicts(module, fn)];
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
export { LemmaSyntaxError, checkInvariant, checkInvariants, checkSpecModule, checkedRung, describeSpecVerdict, describeVerdict, emitRegressionTest, explore, extractSpecs, lemmaBool, lemmaUnresolved, observeCore, parseProperty, printProperty, renderJson, renderSpecs, renderText, renderTrace, replay, restrictSpec, validateScenario };
|
|
260
|
+
|
|
261
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../core/src/spec-verdict.ts","../../spec/src/print.ts","../../prover/src/checked.ts"],"sourcesContent":["/**\n * Spec verdicts: what is known about one property of one pure function.\n * Kept apart from scenario verdicts in every report. The ladder starts at\n * `CHECKED` (held on every input the simulator passed); `TESTED` and\n * `PROVEN` come with the provers.\n */\n\ninterface SpecVerdictBase {\n /** The module, as the scenario names it. */\n readonly module: string;\n readonly function: string;\n /** The `@ensures` name, or `@total` / `@throws` for those markers. */\n readonly property: string;\n /** The property as written. */\n readonly text: string;\n readonly assumptions: readonly string[];\n}\n\nexport interface Checked extends SpecVerdictBase {\n readonly kind: \"CHECKED\";\n /** Distinct inputs the property was evaluated on. */\n readonly inputs: number;\n /** Distinct inputs outside the claim: a precondition failed, or a value fell outside its binder's domain. */\n readonly discarded: number;\n}\n\n/** One assignment that breaks the property, as JavaScript literals, and the call it came from. */\nexport interface Counterexample {\n /** In the property's binder order. */\n readonly binders: readonly { readonly name: string; readonly value: string }[];\n readonly call: string;\n /** Set when evaluating the property threw instead of returning false. */\n readonly error?: string;\n}\n\nexport interface Refuted extends SpecVerdictBase {\n readonly kind: \"REFUTED\";\n readonly rung: \"CHECKED\";\n readonly counterexample: Counterexample;\n}\n\nexport type SpecUnknownCause = \"gave_up\" | \"unsupported\" | \"unavailable\";\n\nexport interface SpecUnknown extends SpecVerdictBase {\n readonly kind: \"UNKNOWN\";\n readonly cause: SpecUnknownCause;\n readonly reason: string;\n}\n\nexport type SpecVerdict = Checked | Refuted | SpecUnknown;\n\n/** One line per spec verdict, for error messages; full rendering lives in `report`. */\nexport function describeSpecVerdict(v: SpecVerdict): string {\n const what = `${v.function} ${v.property}`;\n switch (v.kind) {\n case \"CHECKED\":\n return `CHECKED ${what}: held on ${v.inputs} input(s) the simulator passed`;\n case \"REFUTED\":\n return `REFUTED ${what}: ${v.counterexample.call}${v.counterexample.error ? ` threw ${v.counterexample.error}` : \"\"}`;\n case \"UNKNOWN\":\n return `UNKNOWN ${what}: ${v.cause}: ${v.reason}`;\n }\n}\n","/**\n * Print SpecIR back as Lemma, canonically: glyph connectives, binders with\n * the same domain and guard grouped, and parentheses only where precedence\n * or a root-level material implication needs them. Parsing what it prints\n * gives the same IR.\n */\n\nimport type { Binder, Formula, Guard, Property } from \"./ir.ts\";\n\nconst precedence: { readonly [k in Formula[\"kind\"]]: number } = {\n iff: 1,\n implies: 2,\n or: 3,\n and: 4,\n not: 5,\n atom: 6,\n equation: 6,\n};\n\nfunction guardText(g: Guard): string {\n if (g.kind === \"regex\") return `/${g.pattern}/${g.flags}`;\n return `${g.lower.inclusive ? \"[\" : \"(\"}${g.lower.value}, ${g.upper.value}${g.upper.inclusive ? \"]\" : \")\"}`;\n}\n\nfunction sameGroup(a: Binder, b: Binder): boolean {\n return (\n a.domain === b.domain &&\n (a.guard === undefined) === (b.guard === undefined) &&\n (a.guard === undefined || (b.guard !== undefined && guardText(a.guard) === guardText(b.guard)))\n );\n}\n\nfunction prefixText(binders: readonly Binder[]): string {\n const groups: Binder[][] = [];\n for (const b of binders) {\n const last = groups[groups.length - 1];\n if (last && sameGroup(last[0] as Binder, b)) last.push(b);\n else groups.push([b]);\n }\n const text = groups.map((g) => {\n const head = g[0] as Binder;\n const guard = head.guard ? ` ∈ ${guardText(head.guard)}` : \"\";\n return `(${g.map((b) => b.name).join(\" \")}: ${head.domain}${guard})`;\n });\n return `forall ${text.join(\" \")}`;\n}\n\n/** Print a formula, parenthesized when its precedence is below `min`. */\nexport function printFormula(f: Formula, min = 0): string {\n let s: string;\n switch (f.kind) {\n case \"atom\":\n s = f.text;\n break;\n case \"equation\":\n s = `${f.left} ${f.negated ? \"≢\" : \"≡\"} ${f.right}`;\n break;\n case \"not\":\n s = `¬${printFormula(f.operand, precedence.not)}`;\n break;\n case \"and\":\n case \"or\":\n s = f.operands\n .map((o) => printFormula(o, precedence[f.kind] + 1))\n .join(f.kind === \"and\" ? \" ∧ \" : \" ∨ \");\n break;\n case \"implies\":\n s = [...f.antecedents, f.consequent].map((o) => printFormula(o, precedence.or)).join(\" → \");\n break;\n case \"iff\":\n s = `${printFormula(f.left, precedence.implies)} ↔ ${printFormula(f.right, precedence.implies)}`;\n break;\n }\n return precedence[f.kind] < min ? `(${s})` : s;\n}\n\n/** The property as Lemma text (what follows `@ensures{name}`). */\nexport function printProperty(p: Property): string {\n // A root implication is the preconditions; a material one there needs its parentheses.\n const body =\n p.requires.length > 0\n ? [...p.requires, p.claim].map((f) => printFormula(f, precedence.or)).join(\" → \")\n : printFormula(p.claim, p.claim.kind === \"implies\" ? precedence.or : 0);\n return `${prefixText(p.binders)} { ${body} }`;\n}\n","/**\n * The `CHECKED` rung: a property evaluated on every input the simulator\n * actually passed to its function. Binders are matched to the function's\n * parameters by name, so each recorded call is one assignment; a value\n * outside its binder's domain or guard, or one failing a precondition, is\n * outside the claim and discarded. One assignment where the claim is false\n * refutes the property. Holding on all of them is `CHECKED`, which says\n * nothing about inputs the simulator never passed.\n */\n\nimport type { Counterexample, SpecVerdict } from \"@eutaxy/core\";\nimport {\n type Binder,\n endpointNumber,\n type FunctionSpec,\n type ModuleSpecs,\n type NamedProperty,\n type PredicateOutcome,\n} from \"@eutaxy/spec\";\n\n/** Thrown by `lemmaBool` when an atom is not a genuine boolean: the property is malformed, not false. */\nexport class AtomNotBoolean extends TypeError {}\n\n/** Thrown by `lemmaUnresolved`: the property names something neither its module nor the globals define. */\nexport class UnresolvedName extends ReferenceError {}\n\n/** What generated predicates call when free names did not resolve. */\nexport function lemmaUnresolved(names: readonly string[]): never {\n throw new UnresolvedName(\n `the property refers to ${names.join(\", \")}, which neither its module exports nor the globals define`,\n );\n}\n\n/** The atom check generated predicates call: its argument when it is a boolean. */\nexport function lemmaBool(value: unknown): boolean {\n if (typeof value !== \"boolean\")\n throw new AtomNotBoolean(`a Lemma atom evaluated to ${render(value)}, not a boolean`);\n return value;\n}\n\n/** A value as a JavaScript literal, exact for the binder domains. */\nexport function render(value: unknown): string {\n switch (typeof value) {\n case \"bigint\":\n return `${value}n`;\n case \"number\":\n return Object.is(value, -0) ? \"-0\" : String(value);\n case \"string\":\n return JSON.stringify(value);\n case \"undefined\":\n return \"undefined\";\n case \"boolean\":\n return String(value);\n case \"function\":\n return \"[function]\";\n }\n try {\n const text = JSON.stringify(value, (_, v: unknown) => (typeof v === \"bigint\" ? `${v}n` : v));\n return text === undefined ? String(value) : text.length > 200 ? `${text.slice(0, 200)}…` : text;\n } catch {\n return String(value);\n }\n}\n\nfunction bound(value: string, integral: boolean): number | bigint {\n if (integral && !value.endsWith(\"∞\")) return BigInt(value.replace(/_/g, \"\").replace(/n$/, \"\"));\n return endpointNumber(value);\n}\n\n/** Whether a value lies in a binder's domain and guard. */\nexport function inDomain(b: Binder, v: unknown): boolean {\n switch (b.domain) {\n case \"int\":\n if (!(typeof v === \"number\" && Number.isInteger(v))) return false;\n break;\n case \"nat\":\n if (!(typeof v === \"number\" && Number.isInteger(v) && v >= 0)) return false;\n break;\n case \"number\":\n if (typeof v !== \"number\") return false;\n break;\n case \"bigint\":\n if (typeof v !== \"bigint\") return false;\n break;\n case \"string\":\n if (typeof v !== \"string\") return false;\n break;\n case \"boolean\":\n return typeof v === \"boolean\";\n }\n const g = b.guard;\n if (!g) return true;\n if (g.kind === \"regex\") return new RegExp(`^(?:${g.pattern})$`, g.flags).test(v as string);\n // Integer domains compare exactly: an integer double converts to bigint without loss.\n const integral = b.domain !== \"number\";\n const x = integral ? BigInt(v as number | bigint) : (v as number);\n const lo = bound(g.lower.value, integral);\n const hi = bound(g.upper.value, integral);\n const aboveLower = g.lower.inclusive ? x >= lo : x > lo;\n const belowUpper = g.upper.inclusive ? x <= hi : x < hi;\n return aboveLower && belowUpper;\n}\n\nexport interface CheckedInput {\n readonly module: string;\n readonly fn: FunctionSpec;\n readonly property: NamedProperty;\n /** The calls the simulator made, with their arguments. */\n readonly calls: readonly { readonly args: readonly unknown[] }[];\n /** The compiled predicate over the binders, or undefined when it could not be built. */\n readonly predicate: ((...binders: never[]) => PredicateOutcome) | undefined;\n /** Why the function's calls could not be observed, when they could not. */\n readonly unobservable?: string;\n}\n\nexport function checkedRung(input: CheckedInput): SpecVerdict {\n const { module, fn, property } = input;\n const base = { module, function: fn.name, property: property.name, text: property.text };\n const unknown = (\n cause: \"gave_up\" | \"unsupported\" | \"unavailable\",\n reason: string,\n ): SpecVerdict => ({\n ...base,\n kind: \"UNKNOWN\",\n cause,\n reason,\n assumptions: [],\n });\n if (input.unobservable)\n return unknown(\n \"unavailable\",\n `calls to ${fn.name} could not be observed: ${input.unobservable}`,\n );\n const predicate = input.predicate as ((...binders: unknown[]) => PredicateOutcome) | undefined;\n if (!predicate) return unknown(\"unavailable\", \"the property's predicate was not compiled\");\n const binders = property.property.binders;\n const positions: number[] = [];\n for (const b of binders) {\n const at = fn.params.indexOf(b.name);\n if (at < 0)\n return unknown(\n \"unsupported\",\n `binder ${b.name} is not a parameter of ${fn.name}, so the inputs the simulator passed do not determine it`,\n );\n positions.push(at);\n }\n const seen = new Set<string>();\n let held = 0;\n let discarded = 0;\n for (const call of input.calls) {\n const values = positions.map((p) => call.args[p]);\n const key = values.map(render).join(\", \");\n if (seen.has(key)) continue;\n seen.add(key);\n if (!binders.every((b, i) => inDomain(b, values[i]))) {\n discarded++;\n continue;\n }\n const counterexample = (error?: string): Counterexample => ({\n binders: binders.map((b, i) => ({ name: b.name, value: render(values[i]) })),\n call: `${fn.name}(${call.args.map(render).join(\", \")})`,\n ...(error === undefined ? {} : { error }),\n });\n let outcome: PredicateOutcome;\n try {\n outcome = predicate(...values);\n } catch (err) {\n // An atom that is not a boolean, or a name nothing defines, is a malformed property. Any other throw, the function's own\n // included (JSON.parse's SyntaxError, say), means the claim is not true there.\n // A ReferenceError, likewise: compiled TypeScript under test hardly throws one, a name the\n // property's scope analysis missed does, and that must never pass for a refutation.\n if (err instanceof AtomNotBoolean || err instanceof ReferenceError)\n return unknown(\"unsupported\", `the property could not be evaluated: ${String(err)}`);\n return {\n ...base,\n kind: \"REFUTED\",\n rung: \"CHECKED\",\n counterexample: counterexample(String(err)),\n assumptions: [],\n };\n }\n\n if (outcome === \"refuted\")\n return {\n ...base,\n kind: \"REFUTED\",\n rung: \"CHECKED\",\n counterexample: counterexample(),\n assumptions: [],\n };\n if (outcome === \"discarded\") discarded++;\n else held++;\n }\n if (held === 0)\n return unknown(\n \"gave_up\",\n input.calls.length === 0\n ? `the simulator never called ${fn.name}`\n : `none of the ${seen.size} distinct input(s) the simulator passed is inside the claim (domains, guards, preconditions)`,\n );\n return {\n ...base,\n kind: \"CHECKED\",\n inputs: held,\n discarded,\n assumptions: [\n `held on the ${held} distinct input(s) the simulator passed to ${fn.name}; inputs it never passed are not covered`,\n ],\n };\n}\n\n/** Verdicts for the markers the CHECKED rung cannot decide. */\nexport function markerVerdicts(module: string, fn: FunctionSpec): SpecVerdict[] {\n const out: SpecVerdict[] = [];\n const base = { module, function: fn.name, assumptions: [] };\n if (fn.total)\n out.push({\n ...base,\n property: \"@total\",\n text: \"@total\",\n kind: \"UNKNOWN\",\n cause: \"unsupported\",\n reason:\n \"termination is not observable on the inputs the simulator passed; @total needs a prover\",\n });\n if (fn.throws)\n out.push({\n ...base,\n property: \"@throws\",\n text: \"@throws\",\n kind: \"UNKNOWN\",\n cause: \"unsupported\",\n reason: \"Lemma has not fixed what @throws claims yet\",\n });\n return out;\n}\n\n/** Compiled predicates of a module, by function and property name. */\nexport interface ModulePredicates {\n readonly [fn: string]: { readonly [property: string]: (...binders: never[]) => PredicateOutcome };\n}\n\n/** Every spec verdict for one module, from what was observed of its calls. */\nexport function checkSpecModule(\n module: string,\n specs: ModuleSpecs,\n predicates: ModulePredicates,\n observed: {\n readonly calls: readonly { readonly function: string; readonly args: readonly unknown[] }[];\n readonly unobservable: { readonly [fn: string]: string };\n },\n): SpecVerdict[] {\n return specs.functions.flatMap((fn) => {\n const calls = observed.calls.filter((c) => c.function === fn.name);\n // Own properties only: a function named toString must not find Object.prototype's.\n const unobservable = Object.hasOwn(observed.unobservable, fn.name)\n ? observed.unobservable[fn.name]\n : undefined;\n const own = Object.hasOwn(predicates, fn.name) ? predicates[fn.name] : undefined;\n return [\n ...fn.ensures.map((property) =>\n checkedRung({\n module,\n fn,\n property,\n calls,\n predicate: own && Object.hasOwn(own, property.name) ? own[property.name] : undefined,\n ...(unobservable === undefined ? {} : { unobservable }),\n }),\n ),\n ...markerVerdicts(module, fn),\n ];\n });\n}\n"],"mappings":";;;;;;AAoDA,SAAgB,oBAAoB,GAAwB;CAC1D,MAAM,OAAO,GAAG,EAAE,SAAS,GAAG,EAAE;CAChC,QAAQ,EAAE,MAAV;EACE,KAAK,WACH,OAAO,WAAW,KAAK,YAAY,EAAE,OAAO;EAC9C,KAAK,WACH,OAAO,WAAW,KAAK,IAAI,EAAE,eAAe,OAAO,EAAE,eAAe,QAAQ,UAAU,EAAE,eAAe,UAAU;EACnH,KAAK,WACH,OAAO,WAAW,KAAK,IAAI,EAAE,MAAM,IAAI,EAAE;CAC7C;AACF;;ACrDA,MAAM,aAA0D;CAC9D,KAAK;CACL,SAAS;CACT,IAAI;CACJ,KAAK;CACL,KAAK;CACL,MAAM;CACN,UAAU;AACZ;AAEA,SAAS,UAAU,GAAkB;CACnC,IAAI,EAAE,SAAS,SAAS,OAAO,IAAI,EAAE,QAAQ,GAAG,EAAE;CAClD,OAAO,GAAG,EAAE,MAAM,YAAY,MAAM,MAAM,EAAE,MAAM,MAAM,IAAI,EAAE,MAAM,QAAQ,EAAE,MAAM,YAAY,MAAM;AACxG;AAEA,SAAS,UAAU,GAAW,GAAoB;CAChD,OACE,EA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