eutaxy 0.0.0-stage → 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.
Files changed (43) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +16 -2
  3. package/dist/aws.d.mts +15464 -0
  4. package/dist/aws.d.mts.map +1 -0
  5. package/dist/aws.mjs +24057 -0
  6. package/dist/aws.mjs.map +1 -0
  7. package/dist/bin.d.mts +1 -0
  8. package/dist/bin.mjs +17 -0
  9. package/dist/bin.mjs.map +1 -0
  10. package/dist/checksum-DhS6ofSm.mjs +6049 -0
  11. package/dist/checksum-DhS6ofSm.mjs.map +1 -0
  12. package/dist/cli-NqY61bpo.mjs +2 -0
  13. package/dist/cli.d.mts +8 -0
  14. package/dist/cli.d.mts.map +1 -0
  15. package/dist/cli.mjs +2 -0
  16. package/dist/cloudflare.d.mts +272 -0
  17. package/dist/cloudflare.d.mts.map +1 -0
  18. package/dist/cloudflare.mjs +1815 -0
  19. package/dist/cloudflare.mjs.map +1 -0
  20. package/dist/es5-DtZuPEgt.mjs +1721 -0
  21. package/dist/es5-DtZuPEgt.mjs.map +1 -0
  22. package/dist/event-streams-BANyO9xt.mjs +801 -0
  23. package/dist/event-streams-BANyO9xt.mjs.map +1 -0
  24. package/dist/explore-BHYvAZKN.d.mts +84 -0
  25. package/dist/explore-BHYvAZKN.d.mts.map +1 -0
  26. package/dist/index.d.mts +252 -0
  27. package/dist/index.d.mts.map +1 -0
  28. package/dist/index.mjs +261 -0
  29. package/dist/index.mjs.map +1 -0
  30. package/dist/platform-eVgCMbX0.d.mts +385 -0
  31. package/dist/platform-eVgCMbX0.d.mts.map +1 -0
  32. package/dist/rolldown-runtime-C1I3wEg2.mjs +43 -0
  33. package/dist/src-BD3jkjgG.mjs +477 -0
  34. package/dist/src-BD3jkjgG.mjs.map +1 -0
  35. package/dist/src-C19_yfMM.mjs +2237 -0
  36. package/dist/src-C19_yfMM.mjs.map +1 -0
  37. package/dist/src-CgfGiH25.mjs +1546 -0
  38. package/dist/src-CgfGiH25.mjs.map +1 -0
  39. package/dist/src-s6uYyC0B.mjs +89 -0
  40. package/dist/src-s6uYyC0B.mjs.map +1 -0
  41. package/dist/verdict-evEM5Gxx.mjs +12 -0
  42. package/dist/verdict-evEM5Gxx.mjs.map +1 -0
  43. package/package.json +76 -3
package/dist/index.mjs ADDED
@@ -0,0 +1,261 @@
1
+ import "./src-s6uYyC0B.mjs";
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
+ import { t as describeVerdict } from "./verdict-evEM5Gxx.mjs";
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,IA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