gdp-wired 0.42.0 → 0.44.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 (66) hide show
  1. package/README.md +14 -3
  2. package/dist/core/cli.d.ts +8 -1
  3. package/dist/core/cli.js +271 -30
  4. package/dist/core/counts.d.ts +8 -1
  5. package/dist/core/counts.js +171 -302
  6. package/dist/core/data.js +2 -2
  7. package/dist/core/dsl.js +26 -30
  8. package/dist/core/effect-prims.d.ts +60 -0
  9. package/dist/core/effect-prims.js +625 -0
  10. package/dist/core/effect-schedule.d.ts +103 -0
  11. package/dist/core/effect-schedule.js +817 -0
  12. package/dist/core/effect.d.ts +36 -1
  13. package/dist/core/effect.js +656 -29
  14. package/dist/core/ex/harness.exs +2 -0
  15. package/dist/core/exists.d.ts +5 -0
  16. package/dist/core/exists.js +98 -34
  17. package/dist/core/extract-c.d.ts +2 -0
  18. package/dist/core/extract-c.js +5 -3
  19. package/dist/core/extract-check.d.ts +2 -0
  20. package/dist/core/extract-check.js +45 -4
  21. package/dist/core/extract-ex.js +2 -2
  22. package/dist/core/extract-go-check.js +4 -6
  23. package/dist/core/extract-go.d.ts +3 -0
  24. package/dist/core/extract-go.js +4 -4
  25. package/dist/core/extract-jvm.js +6 -3
  26. package/dist/core/extract-print.js +9 -2
  27. package/dist/core/extract-py.js +2 -2
  28. package/dist/core/extract-rb.js +2 -2
  29. package/dist/core/extract-read.js +2 -1
  30. package/dist/core/extract-rs.js +12 -7
  31. package/dist/core/extract-sol.js +4 -4
  32. package/dist/core/extract-step.d.ts +18 -0
  33. package/dist/core/extract-step.js +135 -31
  34. package/dist/core/extract-swift.js +3 -3
  35. package/dist/core/extract.d.ts +8 -0
  36. package/dist/core/extract.js +13 -1
  37. package/dist/core/infer.d.ts +1 -0
  38. package/dist/core/infer.js +10 -7
  39. package/dist/core/jvm/Harness.java +8 -1
  40. package/dist/core/jvm/Jvm.java +1 -1
  41. package/dist/core/jvm/KtReader.java +3 -0
  42. package/dist/core/laws.d.ts +4 -0
  43. package/dist/core/laws.js +176 -9
  44. package/dist/core/machine.d.ts +3 -0
  45. package/dist/core/machine.js +17 -3
  46. package/dist/core/py/harness.py +64 -19
  47. package/dist/core/py/reader.py +51 -1
  48. package/dist/core/sol/Replay.sol +52 -0
  49. package/dist/core/sol/harness.py +508 -0
  50. package/dist/core/system.d.ts +44 -0
  51. package/dist/core/system.js +435 -0
  52. package/dist/interchange/check.d.ts +18 -1
  53. package/dist/interchange/check.js +9 -2
  54. package/dist/interchange/cli.d.ts +2 -0
  55. package/dist/interchange/cli.js +45 -0
  56. package/dist/interchange/format.d.ts +1 -1
  57. package/dist/interchange/format.js +15 -7
  58. package/dist/kernel/cdcl.js +32 -12
  59. package/dist/kernel/kernel.js +3 -2
  60. package/dist/kernel/prove.d.ts +1 -0
  61. package/dist/kernel/prove.js +69 -8
  62. package/dist/kernel/reader.js +3 -2
  63. package/dist/lean-kernel/emit.js +3 -3
  64. package/dist/lean-kernel/lean-terms.d.ts +1 -0
  65. package/dist/lean-kernel/lean-terms.js +8 -4
  66. package/package.json +12 -3
@@ -60,6 +60,8 @@ defmodule GdpHarness do
60
60
  end
61
61
  end
62
62
  def arg(%{"none" => true}), do: nil
63
+ # (a value the rule never reads: any value, nil)
64
+ def arg(%{"inert" => true}), do: nil
63
65
  def state_of(st) do
64
66
  for l <- s("leaves"), l["kind"] not in ["frame", "map"], into: %{} do
65
67
  v = Map.get(st, String.to_atom(hd(l["path"])))
@@ -8,6 +8,11 @@ export declare function substVarsE(e: E, s: Record<string, E>): E;
8
8
  export declare function substVars(c: C, s: Record<string, E>): C;
9
9
  export declare function small(m: Machine, p: Env, b: number, cap?: number, work?: number, walks?: number): State[];
10
10
  export declare function ghostOf(m: Machine, law: Law): SomeWitness | undefined;
11
+ export declare function smallOf(m: Machine): {
12
+ p: Env;
13
+ sts: State[];
14
+ }[];
15
+ export declare function trueSmall(m: Machine, laws: Law[], ghosted?: Machine): boolean;
11
16
  export declare function holdsAt(m: Machine, law: Law, p: Env, st: State, b: number): boolean;
12
17
  export declare function someHolds(body: C, vars: string[], env: Env, st: State, m: Machine): {
13
18
  holds: boolean;
@@ -154,12 +154,13 @@ function solved(atoms, g) {
154
154
  return out;
155
155
  }
156
156
  const atomsOf2 = (c) => (c.op === 'and' || c.op === 'or' ? c.xs.flatMap(atomsOf2) : c.op === 'not' ? atomsOf2(c.x) : [c]);
157
- // --- the small instances (core/counts.ts's filter and the ghost maps' below) --------------------------------------------------------------------------------------------------
157
+ // --- the small instances ---------------------------------------------------------------------------------------------
158
158
  // Every state reached from the start with the params at `p`, each input below `b`, each carried map a subset of 0 .. b − 1.
159
159
  // (at most `cap` states, and `work` steps tried: a wide request space ends the BFS early, its states still reachable;
160
160
  // then, with `walks` steps more, random walks past it, each step a change of a kind (the variables it writes) chosen
161
161
  // alike among those a few requests make: an action the BFS's levels never reach, a leader past a majority's votes, is
162
- // taken as often as any other)
162
+ // taken as often as any other. Each state's step from the state it was first reached from is kept: `pathTo`.)
163
+ const pathTo = new WeakMap();
163
164
  export function small(m, p, b, cap = 3000, work = 300_000, walks = 0) {
164
165
  const run = interpret(m), start = run.init(p);
165
166
  const subsets = Array.from({ length: 1 << b }, (_, s) => new Map(Array.from({ length: b }, (_, i) => i).filter(i => (s >> i) & 1).map(i => [i, 1])));
@@ -172,6 +173,8 @@ export function small(m, p, b, cap = 3000, work = 300_000, walks = 0) {
172
173
  reqs = reqs.flatMap(r => subsets.map(s => ({ ...r, [c]: s })));
173
174
  const idOf = (s) => key([s.scalars, Object.entries(s.maps).map(([n, cs]) => [n, [...cs].filter(([, x]) => x).sort((a, c) => a[0] - c[0])])]);
174
175
  const seen = new Map([[idOf(start), start]]), queue = [start];
176
+ const reached = (next, from, r) => { const id = idOf(next), had = seen.get(id); if (had)
177
+ return had; seen.set(id, next); pathTo.set(next, [from, r]); return next; };
175
178
  while (queue.length && seen.size < cap && work > 0) {
176
179
  const st = queue.shift();
177
180
  for (const r of reqs) {
@@ -184,11 +187,9 @@ export function small(m, p, b, cap = 3000, work = 300_000, walks = 0) {
184
187
  catch {
185
188
  continue;
186
189
  }
187
- const id = idOf(next);
188
- if (!seen.has(id)) {
189
- seen.set(id, next);
190
+ const n0 = seen.size;
191
+ if (reached(next, st, r) && seen.size > n0)
190
192
  queue.push(next);
191
- }
192
193
  }
193
194
  }
194
195
  if (!queue.length)
@@ -203,24 +204,22 @@ export function small(m, p, b, cap = 3000, work = 300_000, walks = 0) {
203
204
  for (let d = 0; d < 40 && walks > 0; d++) {
204
205
  const by = new Map();
205
206
  for (let i = 0; i < 48; i++, walks--) {
207
+ const r = reqs[rnd(reqs.length)];
206
208
  let next;
207
209
  try {
208
- next = run.step(p, st, reqs[rnd(reqs.length)]);
210
+ next = run.step(p, st, r);
209
211
  }
210
212
  catch {
211
213
  continue;
212
214
  }
213
215
  const kd = kindOf(st, next);
214
216
  if (kd)
215
- by.set(kd, [...by.get(kd) ?? [], next]);
217
+ by.set(kd, [...by.get(kd) ?? [], [next, r]]);
216
218
  }
217
219
  if (!by.size)
218
220
  break;
219
- const ks = [...by.values()], at = ks[rnd(ks.length)];
220
- st = at[rnd(at.length)];
221
- const id = idOf(st);
222
- if (!seen.has(id))
223
- seen.set(id, st);
221
+ const ks = [...by.values()], at = ks[rnd(ks.length)], [next, r] = at[rnd(at.length)];
222
+ st = reached(next, st, r);
224
223
  }
225
224
  }
226
225
  return [...seen.values()];
@@ -242,17 +241,49 @@ export function ghostOf(m, law) {
242
241
  for (const t of ts.values())
243
242
  for (const start of starts) {
244
243
  const step = { op: 'if', c: keep, then: v(x), else: t }, gm = { ...m, state: { ...m.state, [x]: start }, step: { ...m.step, state: { ...m.step.state, [x]: step } } };
245
- const ok = [2, 3].every(q => { const ps = Object.fromEntries(m.params.map(p => [p, q])); try {
246
- return small(gm, ps, 3, 3000, 100_000).every(st => holdsAt(gm, { ...law, some: undefined }, ps, st, 3));
247
- }
248
- catch {
249
- return false;
250
- } });
251
- if (ok)
244
+ if (trueSmall(m, [{ ...law, some: undefined }], gm))
252
245
  return { ghost: { [x]: { start, step } } };
253
246
  }
254
247
  return undefined;
255
248
  }
249
+ // The small instances, the one filter of every candidate (core/counts.ts's laws, the witnesses and ghosts here): each
250
+ // param 2 and 3, every input and carried set below 3, every state the BFS reaches in 300,000 steps (3,000 at most) and
251
+ // the walks past it in a third as many; an instance whose params the machine refuses has no states. Read once a machine.
252
+ const smalls = new WeakMap();
253
+ export function smallOf(m) {
254
+ let out = smalls.get(m);
255
+ if (!out)
256
+ smalls.set(m, (out = [2, 3].map(x => { const p = Object.fromEntries(m.params.map(q => [q, x])); try {
257
+ return { p, sts: small(m, p, 3, 3000, 300_000, 100_000) };
258
+ }
259
+ catch {
260
+ return { p, sts: [] };
261
+ } })));
262
+ return out;
263
+ }
264
+ // Laws true at every small state, at every key below one past their values. With `ghosted`, the machine with ghosts
265
+ // (state no step of m reads), each small state of m with the ghosts' values along the steps it was first reached by:
266
+ // one instance a machine, however many ghosts are asked of it.
267
+ export function trueSmall(m, laws, ghosted) {
268
+ const g = ghosted ?? m, run = ghosted && interpret(ghosted);
269
+ return smallOf(m).every(({ p, sts }) => {
270
+ const at = new Map();
271
+ return sts.every(st => {
272
+ let s = st;
273
+ if (run) {
274
+ const from = pathTo.get(st);
275
+ try {
276
+ s = from ? run.step(p, at.get(from[0]), from[1]) : run.init(p);
277
+ }
278
+ catch {
279
+ return false;
280
+ }
281
+ at.set(st, s);
282
+ }
283
+ return laws.every(l => holdsAt(g, l, p, s, 4));
284
+ });
285
+ });
286
+ }
256
287
  // A law at a state, its counts the state's, at every key below b.
257
288
  // (a state's view once: a law is read at every state, and every law at each)
258
289
  const views = new WeakMap();
@@ -500,17 +531,44 @@ function mapGhostsOf(m, law, taken) {
500
531
  for (const n of namesOf(w2.key))
501
532
  keyed.add(n);
502
533
  const action = (i) => !keyed.has(i);
503
- for (const inj of injections)
504
- for (const val of m.inputs.filter(i => !kv.includes(i) && !action(i))) {
534
+ const ghost = (val, inner) => {
535
+ for (const inj of injections) {
505
536
  let name = `${mp}$w`;
506
- for (let j = 2; taken.has(name); j++)
537
+ for (let j = 2; taken.has(name) || name === inner?.name; j++)
507
538
  name = `${mp}$w${j}`;
508
539
  const at = substVarsE(w.key, Object.fromEntries(kv.map((n, j) => [n, v(inj[j])]))), atW = { op: 'get', map: name, key: at };
509
540
  const Pw = substVars(P.length === 1 ? P[0] : { op: 'or', xs: P }, { [x]: atW }), has = { op: '<=', a: k(1), b: { op: 'get', map: mp, key: at } };
510
- out.push({ name, write: { key: w.key, value: { op: 'if', c: set, then: v(val), else: { op: 'get', map: name, key: w.key } } }, at,
511
- holds: substVars(law.holds, { [x]: atW }),
541
+ out.push({ name, write: { key: w.key, value: { op: 'if', c: set, then: val, else: { op: 'get', map: name, key: w.key } } }, at,
542
+ holds: substVars(law.holds, { [x]: atW }), ...(inner ? { inner } : {}),
512
543
  inv: { name: `${law.name}: ${name} where ${mp} is set`, forall: law.forall, ...(law.keys ? { keys: law.keys } : {}), holds: { op: 'or', xs: [{ op: 'not', x: { op: 'and', xs: [...guards, has] } }, Pw] } } });
513
544
  }
545
+ };
546
+ for (const val of m.inputs.filter(i => !kv.includes(i) && !action(i)))
547
+ ghost(v(val));
548
+ // (a ghost of a ghost, after those: the value another write's ghost holds, read at that write's key in this step's
549
+ // request: G[i·N + p] := r where DbResponseSent[i·N + p] is set, W[n·N + p] := G[i·N + p] where ResponseSent is.
550
+ // G's own law: where its write's cell is set, what the write's guard says of r, at G's cell)
551
+ for (const [mp2, w2] of Object.entries(m.step.maps ?? {})) {
552
+ if (mp2 === mp || 'each' in w2)
553
+ continue;
554
+ const kv2 = namesOf(w2.key);
555
+ if (!kv2.length || !kv2.every(n => m.inputs.includes(n) && keyed.has(n)))
556
+ continue;
557
+ const set2 = substC({ op: '<=', a: k(1), b: w2.value }, { vars: {}, maps: { [mp2]: () => k(0) }, flags: Object.fromEntries(Object.keys(m.step.flags ?? {}).map(f => [f, { op: 'flag', name: f }])) });
558
+ const conj = (c, depth = 0) => (c.op === 'and' ? c.xs.flatMap(y => conj(y, depth)) : c.op === 'flag' && depth < 3 && m.step.flags?.[c.name] && m.step.flags[c.name].op !== 'all' ? conj(m.step.flags[c.name], depth + 1) : [c]);
559
+ const lits = [...new Set([...JSON.stringify(w2.value).matchAll(/"op":"flag","name":"([^"]+)"/g)].map(x => x[1]))].flatMap(f => conj({ op: 'flag', name: f }));
560
+ for (const val2 of m.inputs.filter(i => !kv2.includes(i) && !action(i))) {
561
+ let gname = `${mp2}$g`;
562
+ for (let j = 2; taken.has(gname); j++)
563
+ gname = `${mp2}$g${j}`;
564
+ const ks = kv2.map((_, j) => `g${j}$key`), G = (t) => ({ op: 'get', map: gname, key: t }), K2 = substVarsE(w2.key, Object.fromEntries(kv2.map((n, j) => [n, v(ks[j])])));
565
+ const says = lits.filter(c => c.op !== 'flag' && namesOf(c).includes(val2) && namesOf(c).every(n => n === val2 || kv2.includes(n))).map(c => substVars(c, { [val2]: G(K2), ...Object.fromEntries(kv2.map((n, j) => [n, v(ks[j])])) }));
566
+ if (!says.length)
567
+ continue;
568
+ const inv = { name: `${gname} where ${mp2} is set`, forall: ks[0], ...(ks.length > 1 ? { keys: ks.slice(1) } : {}), holds: { op: 'or', xs: [{ op: 'not', x: { op: '<=', a: k(1), b: { op: 'get', map: mp2, key: K2 } } }, says.length === 1 ? says[0] : { op: 'and', xs: says }] } };
569
+ ghost(G(w2.key), { name: gname, write: { key: w2.key, value: { op: 'if', c: set2, then: v(val2), else: G(w2.key) } }, inv });
570
+ }
571
+ }
514
572
  }
515
573
  return out;
516
574
  }
@@ -518,7 +576,7 @@ const takenOf = (m) => new Set([...Object.keys(m.maps ?? {}), ...(m.inputMaps ??
518
576
  const firstPicks = new Map();
519
577
  // The machine with a ghost map (kernel.ts's ghostedMachine of Ghosted, whose ghostedOk it must pass).
520
578
  const withMap = (m, g) => {
521
- const o = { orig: m, vars: {}, maps: { [g.name]: { start: 0, write: g.write } } };
579
+ const o = { orig: m, vars: {}, maps: { ...(g.inner ? { [g.inner.name]: { start: 0, write: g.inner.write } } : {}), [g.name]: { start: 0, write: g.write } } };
522
580
  if (!ghostedOk(o))
523
581
  throw new Error(`${g.name}: not a ghost of ${m.name}`);
524
582
  return ghostedMachine(o);
@@ -531,7 +589,7 @@ function built(m0, plans, cases) {
531
589
  if (p.pick.mode === 'map') {
532
590
  const g = p.maps[p.pick.at];
533
591
  m = withMap(m, g);
534
- invs.push(g.inv);
592
+ invs.push(...(g.inner ? [g.inner.inv] : []), g.inv);
535
593
  }
536
594
  const state = { ...m.state }, step = { ...m.step.state }, ghosts = [];
537
595
  const laws = plans.map(p => {
@@ -653,16 +711,17 @@ export function proveSome(m, laws, opts = {}) {
653
711
  const rounds = opts.rounds ?? 24;
654
712
  // (a law about every key with no witness term: the next ghost map past `from` that keeps its law and the ghost's own
655
713
  // on every state of the small instances, each param 2 and 3)
656
- const smallOk = (mm, ls) => [2, 3].every(x => { const ps = Object.fromEntries(m.params.map(q => [q, x])); return small(mm, ps, 2, 1500, 100_000).every(st => ls.every(l => holdsAt(mm, l, ps, st, 2))); });
714
+ // (a ghost map named apart from the machine's names and from the other laws' plans' maps)
715
+ const apart = (p) => new Set([...takenOf(m), ...[...plans.values()].flatMap(q => (q !== p ? q.maps.map(g => g.name) : []))]);
657
716
  const toMap = (p, from) => {
658
- if (from < 0)
659
- p.maps = mapGhostsOf(m, p.law, takenOf(m));
660
717
  const others = [...plans.values()].filter(q => q !== p && q.pick.mode === 'map');
718
+ if (from < 0)
719
+ p.maps = mapGhostsOf(m, p.law, apart(p));
661
720
  for (let j = from + 1; j < p.maps.length; j++) {
662
721
  const g = p.maps[j];
663
722
  try {
664
723
  const mm = withMap(others.reduce((acc, q) => withMap(acc, q.maps[q.pick.at]), m), g);
665
- const ok = smallOk(mm, [g.inv, { ...p.law, holds: g.holds, some: undefined }]);
724
+ const ok = trueSmall(m, [...(g.inner ? [g.inner.inv] : []), g.inv, { ...p.law, holds: g.holds, some: undefined }], mm);
666
725
  if (log)
667
726
  console.error(`exists: map ${g.name} at ${showE(g.at)} := ${showE(g.write.value)}: ${ok ? 'kept' : 'false on the small instances'}`);
668
727
  if (ok) {
@@ -686,16 +745,21 @@ export function proveSome(m, laws, opts = {}) {
686
745
  if (p.law.forall && !p.given && p.groups.length === 1 && p.groups[0].length === 1 && mapsRead(p.law) && p.pick.mode === 'term' && !first) {
687
746
  // (the first pick a machine's law got, again: a search asks the same law with each candidate set)
688
747
  const id = key([m.step, m.assume ?? null, m.maps ?? null, p.law.holds]), had = firstPicks.get(id);
748
+ // (a ghost map this machine refuses, one with sums, say, is no pick here)
689
749
  if (had?.mode === 'map') {
690
- p.maps = mapGhostsOf(m, p.law, takenOf(m));
691
- p.pick = { ...had };
750
+ p.maps = mapGhostsOf(m, p.law, apart(p));
751
+ try {
752
+ withMap(m, p.maps[had.at]);
753
+ p.pick = { ...had };
754
+ }
755
+ catch { /* the term */ }
692
756
  }
693
757
  else if (had)
694
758
  p.pick = { mode: 'term', at: [...had.at] };
695
759
  }
696
760
  if (p.law.forall && !p.given && p.groups.length === 1 && p.groups[0].length === 1 && mapsRead(p.law) && p.pick.mode === 'term' && !first && !firstPicks.has(key([m.step, m.assume ?? null, m.maps ?? null, p.law.holds]))) {
697
761
  const x = p.groups[0][0], at = p.terms[0].findIndex(t => { try {
698
- return smallOk(m, [{ ...p.law, holds: substVars(p.law.holds, { [x]: t[0] }), some: undefined }]);
762
+ return trueSmall(m, [{ ...p.law, holds: substVars(p.law.holds, { [x]: t[0] }), some: undefined }]);
699
763
  }
700
764
  catch {
701
765
  return false;
@@ -17,6 +17,8 @@ export type COptions = {
17
17
  clang?: string;
18
18
  root?: string;
19
19
  fails?: Record<string, string>;
20
+ answers?: Record<string, string>;
21
+ skip?: string[];
20
22
  onError?: 'refuse' | 'discard';
21
23
  domains?: Record<string, 'nat' | 'int'>;
22
24
  check?: GoCheckOptions;
@@ -85,7 +85,7 @@ export function extractC(at, given = {}, cpp = false) {
85
85
  ;
86
86
  ({ c, flags } = readCFile(file, opts, cpp));
87
87
  c.pkg.dir = node('node:path').resolve(file).replace(/\/[^/]*$/, '');
88
- read = readGo(c.pkg, { entry: c.entry, methods: opts.functions?.map(f => f.split('/')[0]) ?? c.methods, ...(opts.onError ? { onError: opts.onError } : {}), ...(opts.fails ? { fails: opts.fails } : {}), ...(opts.strict ? { strict: true } : {}) });
88
+ read = readGo(c.pkg, { entry: c.entry, methods: opts.functions?.map(f => f.split('/')[0]) ?? c.methods, ...(opts.onError ? { onError: opts.onError } : {}), ...(opts.fails ? { fails: opts.fails } : {}), ...(opts.strict ? { strict: true } : {}), ...(opts.answers ? { answers: opts.answers } : {}), ...(opts.skip ? { skip: opts.skip } : {}) });
89
89
  }
90
90
  catch (e) {
91
91
  if (e instanceof Refusal)
@@ -386,7 +386,8 @@ export function checkC(file, flags, c, read, r, sorts, opts, cpp) {
386
386
  }
387
387
  // The same flags; undefined behavior trapped (the rule refuses it, so the code must fail there too); another
388
388
  // file's functions linked as stubs that report themselves (the rule refuses their calls: one reached is the
389
- // code's failure where the rule took the step, a difference).
389
+ // code's failure where the rule took the step, a difference), but those left out (skip, stated or inferred: they
390
+ // change nothing the rule keeps, and nothing reads their value), which do nothing.
390
391
  const clang = opts.clang ?? (cpp ? 'clang++' : 'clang'), stubs = `${work}/gdp_stubs.c`;
391
392
  const link = (more) => cp.execFileSync(clang, [...(cpp ? ['-x', 'c++'] : []), ...flags, '-w', '-O0', '-fsanitize=undefined', '-fsanitize-trap=undefined', '-fno-sanitize=vptr,function', ...strictFlex(clang), h, ...(more.length ? ['-x', 'c', ...more] : []), '-o', `${work}/harness`,], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 1 << 26 });
392
393
  const why = (x) => String(x.stderr ?? x.message);
@@ -397,7 +398,8 @@ export function checkC(file, flags, c, read, r, sorts, opts, cpp) {
397
398
  const names = [...new Set([...why(x).matchAll(/undefined (?:reference to [`']|symbol: )_?([A-Za-z_]\w*)|"_([A-Za-z_]\w*)", referenced from/g)].map(m => m[1] ?? m[2]))];
398
399
  if (!names.length)
399
400
  return { ...empty, mismatch: `the file doesn't build with the check's harness: ${why(x).split('\n').filter(l => /error/.test(l)).slice(0, 6).join(' | ')}` };
400
- fs.writeFileSync(stubs, `void gdp_extern_called(const char *);\n${names.map(n => `void ${n}(void) { gdp_extern_called(${JSON.stringify(n)}); }`).join('\n')}\n`);
401
+ const out = new Set(read.leftOut ?? []);
402
+ fs.writeFileSync(stubs, `void gdp_extern_called(const char *);\n${names.map(n => (out.has(n) ? `void ${n}(void) {}` : `void ${n}(void) { gdp_extern_called(${JSON.stringify(n)}); }`)).join('\n')}\n`);
401
403
  try {
402
404
  link([stubs]);
403
405
  }
@@ -27,6 +27,7 @@ export type Evidence = {
27
27
  };
28
28
  refusedBoth: number;
29
29
  outside: number;
30
+ startsOutside?: number;
30
31
  edge: number;
31
32
  edgeSample?: string;
32
33
  compiledAgreed: number;
@@ -100,6 +101,7 @@ export type CodeSide = {
100
101
  } | {
101
102
  ok: false;
102
103
  error: string;
104
+ outside?: true;
103
105
  };
104
106
  reduce?: (snap: Snap, e: Ev, args: unknown[], params: Record<string, Raw>) => {
105
107
  refused: string;
@@ -518,6 +518,11 @@ export function drive(m, r, sorts, code, opts = {}) {
518
518
  try {
519
519
  if (isClass) {
520
520
  const self = side.self, c = code.call(self, e, args);
521
+ if (!c.ok && c.outside) {
522
+ next.stop = true;
523
+ ev.outside++;
524
+ return undefined;
525
+ }
521
526
  if (!c.ok)
522
527
  res = { refused: c.error };
523
528
  else
@@ -636,7 +641,9 @@ export function drive(m, r, sorts, code, opts = {}) {
636
641
  // A class's object: made by its constructor, or set to a snapshot.
637
642
  // (a param the precondition fixes from the others, a start's quotient: computed from them)
638
643
  const drawParams = () => {
639
- const ps = Object.fromEntries(m.params.filter(v => !v.derived).map(v => [v.name, v.note?.startsWith('Date.now()') ? rand(10_000) : draw(v.sort, sorts, v.name, rand, consts, bound, strs)]));
644
+ // (a param given as a natural (domains) is drawn as one, as an input is)
645
+ const nat = (v, x) => (opts.given?.[v.name] === 'nat' && typeof x === 'number' ? Math.abs(x) : x);
646
+ const ps = Object.fromEntries(m.params.filter(v => !v.derived).map(v => [v.name, v.note?.startsWith('Date.now()') ? rand(10_000) : nat(v, draw(v.sort, sorts, v.name, rand, consts, bound, strs))]));
640
647
  for (const v of m.params) {
641
648
  const d = v.derived;
642
649
  if (d)
@@ -660,7 +667,19 @@ export function drive(m, r, sorts, code, opts = {}) {
660
667
  return ruleRefuses ? {} : { problem: `new ${m.entry}(${JSON.stringify(params)}) throws (${made.error}), the rule's precondition holds` };
661
668
  if (ruleRefuses)
662
669
  return { problem: `new ${m.entry}(${JSON.stringify(params)}) is made, the rule's ${ps === undefined ? 'param kinds refuse' : 'precondition refuses'} it` };
663
- const st = interp.init(ps);
670
+ // (a start whose constructor arithmetic passes 2^53 - 1: outside the rule's numbers, as a step past them is; the
671
+ // claim is for starts within them, and the check draws on)
672
+ let st;
673
+ try {
674
+ st = interp.init(ps);
675
+ }
676
+ catch (x) {
677
+ if (/2\^53/.test(x.message)) {
678
+ ev.startsOutside = (ev.startsOutside ?? 0) + 1;
679
+ return {};
680
+ }
681
+ throw x;
682
+ }
664
683
  try {
665
684
  const snap = code.snapOf(made.value, params);
666
685
  const diff = sameSnap(snap, ruleSnap(r, m, st, sorts));
@@ -672,7 +691,18 @@ export function drive(m, r, sorts, code, opts = {}) {
672
691
  return { problem: `new ${m.entry}: ${x.message}` };
673
692
  }
674
693
  }
675
- const st = interp.init(ps ?? {}), snap = ruleSnap(r, m, st, sorts);
694
+ let st;
695
+ try {
696
+ st = interp.init(ps ?? {});
697
+ }
698
+ catch (x) {
699
+ if (/2\^53/.test(x.message)) {
700
+ ev.startsOutside = (ev.startsOutside ?? 0) + 1;
701
+ return {};
702
+ }
703
+ throw x;
704
+ }
705
+ const snap = ruleSnap(r, m, st, sorts);
676
706
  const problem = code.init?.(snap, params);
677
707
  if (problem)
678
708
  return { problem };
@@ -753,7 +783,18 @@ export function drive(m, r, sorts, code, opts = {}) {
753
783
  }
754
784
  if (evalTerm(m.pre, params) !== true)
755
785
  return undefined;
756
- const st = ruleState(interp.init(ps), snap, m, sorts);
786
+ let st0;
787
+ try {
788
+ st0 = interp.init(ps);
789
+ }
790
+ catch (x) {
791
+ if (/2\^53/.test(x.message)) {
792
+ ev.startsOutside = (ev.startsOutside ?? 0) + 1;
793
+ return undefined;
794
+ }
795
+ throw x;
796
+ }
797
+ const st = ruleState(st0, snap, m, sorts);
757
798
  // A state the code can't hold (a value outside its type, Go's): no state of the code is that one.
758
799
  const self = isClass ? code.at(snap, params) : undefined;
759
800
  if (isClass && self === undefined)
@@ -1,7 +1,7 @@
1
1
  import { Refusal, pathOf } from "./extract-read.js";
2
- import { extractStep, node } from "./extract-step.js";
2
+ import { asset, extractStep, node } from "./extract-step.js";
3
3
  export { proveRule, proveSteps } from "./dsl.js";
4
- const here = (f) => new URL(`./ex/${f}`, import.meta.url).pathname;
4
+ const here = (f) => asset(`ex/${f}`);
5
5
  export function readElixir(file, module, elixir = 'elixir') {
6
6
  const cp = node('node:child_process'), path = node('node:path');
7
7
  let out;
@@ -1,5 +1,5 @@
1
1
  import { Outside, constantsOf, draw, drive, evalTerm } from "./extract-check.js";
2
- import { stubbed } from "./extract-step.js";
2
+ import { openHarness, stubbed } from "./extract-step.js";
3
3
  import { node } from "./extract-go.js";
4
4
  // --- the harness ------------------------------------------------------------------------------------------------------
5
5
  // Go source beside the package: a state set from JSON and read back as JSON, leaf by leaf; each method called with its
@@ -392,13 +392,11 @@ export function checkGo(dir, pkg, read, r, sorts, gopts) {
392
392
  // it, call a method on it), every state compared; `count` reads the coverage after the harness exits.
393
393
  export function speak(work, bin, env, pkg, read, r, sorts, opts, count) {
394
394
  const m = read.model, bound = opts.bound ?? 12;
395
- const fs = node('node:fs'), cp = node('node:child_process');
395
+ const fs = node('node:fs');
396
396
  let child, wi = -1, ro = -1;
397
397
  try {
398
- cp.execFileSync('mkfifo', [`${work}/in`, `${work}/out`], {});
399
- child = node('node:child_process').spawn(bin, [`${work}/in`, `${work}/out`], { stdio: 'ignore', env });
400
- wi = fs.openSync(`${work}/in`, 'w');
401
- ro = fs.openSync(`${work}/out`, 'r');
398
+ ;
399
+ ({ child, wi, ro } = openHarness(work, bin, [], { stdio: 'ignore', env }));
402
400
  const buf = new Uint8Array(1 << 20), dec = new TextDecoder();
403
401
  let pend = '';
404
402
  const line = () => {
@@ -187,11 +187,14 @@ export type GoOptions = {
187
187
  check?: GoCheckOptions;
188
188
  fails?: Record<string, string>;
189
189
  strict?: boolean;
190
+ answers?: Record<string, string>;
191
+ skip?: string[];
190
192
  };
191
193
  export type GoRead = {
192
194
  answers?: (Answer & {
193
195
  range?: [number, number];
194
196
  })[];
197
+ leftOut?: string[];
195
198
  ctor?: {
196
199
  name: string;
197
200
  t: number;
@@ -37,7 +37,7 @@
37
37
  import * as I from "./extract-ir.js";
38
38
  import { Refusal, pathOf } from "./extract-read.js";
39
39
  import { fromModel } from "./extract.js";
40
- import { Stepper, iteTerm, mapWritesOf, phiP, rangeLaws, rangeOf, varTerm } from "./extract-step.js";
40
+ import { asset, Stepper, iteTerm, mapWritesOf, phiP, rangeLaws, rangeOf, varTerm } from "./extract-step.js";
41
41
  import { checkGo } from "./extract-go-check.js";
42
42
  export { proveRule, proveSteps } from "./dsl.js";
43
43
  const refuse = (x, what) => { throw new Refusal(typeof x === 'string' ? x : x.p || '?', what); };
@@ -52,7 +52,7 @@ class Go {
52
52
  this.pkg = pkg;
53
53
  this.opts = opts;
54
54
  const mod = { lang: pkg.lang ?? 'go', file: pkg.files[0]?.name ?? 'go', path: pkg.dir ? `${pkg.dir}/${pkg.files[0]?.name ?? ''}` : '', module: pkg.package, root: pkg.dir ?? '', entries: [], recs: {}, funcs: this.funcs, split: false };
55
- this.g = new Stepper(mod, { entry: opts.entry, ...(opts.onError ? { onError: opts.onError } : {}) }, inf);
55
+ this.g = new Stepper(mod, { entry: opts.entry, ...(opts.onError ? { onError: opts.onError } : {}), ...(opts.answers ? { answers: opts.answers } : {}), ...(opts.skip ? { skip: opts.skip } : {}) }, inf);
56
56
  for (const f of pkg.funcs)
57
57
  this.funcs[`${f.recv?.type ?? ''}.${f.name}`] = this.fn(f);
58
58
  }
@@ -951,7 +951,7 @@ function readGo1(pkg, o, go) {
951
951
  // Unsigned inputs are naturals (the input's kind); a state variable's sort is the printer's to decide (a natural where
952
952
  // every write is proven one: a wrap by cases may not be, though it stays within the type, which its law says).
953
953
  const unsigned = [...g.ints].filter(([n, ty]) => { const [lo, hi] = rangeOf(ty); return lo === 0 && hi > 0 && (g.inputs.some(v => v.name === n) || cparams.some(v => v.name === n)); }).map(([n]) => n);
954
- return { ...(pkg.ctor ? { ctor: ctorArgs } : {}), model, edges: g.edges, unsigned, leaves: go.leaves.filter(l => l.kind === 'frame' || state.some(v => v.name === l.name) || maps.some(d => d.name === l.name) || lists.some(d => d.name === l.name)), spans: [...g.spans.values()], entry: opts.entry, methods, ...(answers.length ? { answers } : {}) };
954
+ return { ...(pkg.ctor ? { ctor: ctorArgs } : {}), ...(g.leftOut.size ? { leftOut: [...g.leftOut] } : {}), model, edges: g.edges, unsigned, leaves: go.leaves.filter(l => l.kind === 'frame' || state.some(v => v.name === l.name) || maps.some(d => d.name === l.name) || lists.some(d => d.name === l.name)), spans: [...g.spans.values()], entry: opts.entry, methods, ...(answers.length ? { answers } : {}) };
955
955
  }
956
956
  function termOf(v, at) {
957
957
  if (v.t === 'num')
@@ -1028,7 +1028,7 @@ export const node = (id) => { const m = proc?.getBuiltinModule?.(id); if (!m)
1028
1028
  // The reader, built once per version of its source (into the system's temporary directory).
1029
1029
  export function readerBinary() {
1030
1030
  const fs = node('node:fs'), cp = node('node:child_process'), os = node('node:os'), crypto = node('node:crypto');
1031
- const dir = new URL('./go/', import.meta.url).pathname;
1031
+ const dir = asset('go/');
1032
1032
  const src = fs.readFileSync(`${dir}reader.go`, 'utf8'), h = crypto.createHash('sha256').update(src).digest('hex').slice(0, 12);
1033
1033
  const bin = `${os.tmpdir()}/gdp-goreader-${h}`;
1034
1034
  if (!fs.existsSync(bin))
@@ -1,7 +1,7 @@
1
1
  import { Refusal, pathOf } from "./extract-read.js";
2
- import { entryNames, extractStep, node } from "./extract-step.js";
2
+ import { asset, entryNames, extractStep, node } from "./extract-step.js";
3
3
  export { proveRule, proveSteps } from "./dsl.js";
4
- const here = (f) => new URL(`./jvm/${f}`, import.meta.url).pathname;
4
+ const here = (f) => asset(`jvm/${f}`);
5
5
  const TOOLS = ['Jvm.java', 'JavaReader.java', 'Harness.java', 'Rt.java'];
6
6
  // (a JVM's stack trace: its exception's line first)
7
7
  const errText = (e) => { const ls = String(e.stderr || e.stdout || e.message).split('\n').filter(l => l.trim() && !/^\s+at /.test(l)); return ls.slice(-3).join(' | ').slice(0, 600); };
@@ -137,13 +137,16 @@ function answerSites(mod, keys) {
137
137
  return out;
138
138
  }
139
139
  const BOXES = { int: 'java.lang.Integer', long: 'java.lang.Long', short: 'java.lang.Short', byte: 'java.lang.Byte', char: 'java.lang.Character', boolean: 'java.lang.Boolean', float: 'java.lang.Float', double: 'java.lang.Double' };
140
+ const STATED = { int: 'int', long: 'long', short: 'short', byte: 'byte', char: 'char', float: 'double', double: 'double', bool: 'boolean', boolean: 'boolean', str: 'java.lang.String', String: 'java.lang.String', i32: 'int', i64: 'long' };
140
141
  const KT = { int: 'Int', long: 'Long', short: 'Short', byte: 'Byte', char: 'Char', boolean: 'Boolean', float: 'Float', double: 'Double', 'java.lang.String': 'String' };
141
142
  // The code compiled for the check: a copy of the file with the clock's and the answered calls' sites rewritten.
142
143
  function compiled(lang, mod, read, o, made) {
143
144
  const fs = node('node:fs'), cp = node('node:child_process'), os = node('node:os'), path = node('node:path');
144
145
  const j = jvmOf(mod), kotlin = lang === 'kotlin';
146
+ // (a call of a generic result, a type variable's: the answer given in the type it is stated in)
147
+ const sortOf = new Map(read.answers.map(a => [a.key, STATED[a.sort.replace(/\s*\|\s*None$|\?$/, '')]]));
145
148
  const sites = [...j.rewrites.map(r => ({ span: r.span, text: 'gdp.Rt.now()' })), ...answerSites(mod, read.answers.filter(a => !a.patch.store).map(a => a.key)).map(s => {
146
- const t = s.jt.replace(/\?$/, '').replace(/<.*$/, ''), box = BOXES[t] ?? t;
149
+ const t0 = s.jt.replace(/\?$/, '').replace(/<.*$/, ''), t = (t0 === 'java.lang.Object' || !(t0 in BOXES || t0.includes('.'))) ? sortOf.get(s.key) ?? t0 : t0, box = BOXES[t] ?? t;
147
150
  return { span: s.span, text: kotlin ? `(gdp.Rt.answer(${JSON.stringify(s.key)}, ${box}::class.java) as ${KT[t] ?? t.split('.').pop()}${s.jt.endsWith('?') ? '?' : ''})` : `((${box}) gdp.Rt.answer(${JSON.stringify(s.key)}, ${box}.class))` };
148
151
  })];
149
152
  if (o.prebuilt)
@@ -342,8 +342,15 @@ function pn(e, P, ctx, mode, recv = false) {
342
342
  case 'neg': return `${pn(e.a, P, ctx, 'int', true)}.negate()`;
343
343
  case 'mulk': return `${R(e.a)}.times(${e.k})`;
344
344
  case 'mul':
345
- if (!(natOK(e.a, ctx) && natOK(e.b, ctx)))
346
- throw new Refusal(P.m.file, 'a product of two numbers that may be negative (Int multiplies only by constants)');
345
+ if (!(natOK(e.a, ctx) && natOK(e.b, ctx))) {
346
+ // (each factor at least 0 where the product is read, the path's conditions say so: their product over the
347
+ // naturals, each factor clamped at 0, which is itself there)
348
+ if (!(nonneg(e.a, ctx) && nonneg(e.b, ctx)))
349
+ throw new Refusal(P.m.file, 'a product of two numbers that may be negative (Int multiplies only by constants)');
350
+ const f = (x, recv) => (natOK(x, ctx) ? pn(x, P, ctx, 'nat', recv) : `${pn(x, P, ctx, 'int', true)}.clamped`);
351
+ const prod = `${f(e.a, true)}.mul(${f(e.b, false)})`;
352
+ return nat ? prod : `Int.of(${prod})`;
353
+ }
347
354
  return `${pn(e.a, P, ctx, 'nat', true)}.mul(${pn(e.b, P, ctx, 'nat')})`;
348
355
  case 'min': return nat ? `min(${A(e.a)}, ${A(e.b)})` : `${R(e.a)}.min(${A(e.b)})`;
349
356
  case 'max':
@@ -1,7 +1,7 @@
1
1
  import { Refusal, pathOf } from "./extract-read.js";
2
- import { entryNames, extractStep, node } from "./extract-step.js";
2
+ import { asset, entryNames, extractStep, node } from "./extract-step.js";
3
3
  export { proveRule, proveSteps } from "./dsl.js";
4
- const here = (f) => new URL(`./py/${f}`, import.meta.url).pathname;
4
+ const here = (f) => asset(`py/${f}`);
5
5
  // The module as the reader lowers it (the names given and the module's functions).
6
6
  export function readPython(file, names, opts = {}) {
7
7
  const cp = node('node:child_process'), path = node('node:path');
@@ -1,7 +1,7 @@
1
1
  import { Refusal, pathOf } from "./extract-read.js";
2
- import { entryNames, extractStep, node } from "./extract-step.js";
2
+ import { asset, entryNames, extractStep, node } from "./extract-step.js";
3
3
  export { proveRule, proveSteps } from "./dsl.js";
4
- const here = (f) => new URL(`./rb/${f}`, import.meta.url).pathname;
4
+ const here = (f) => asset(`rb/${f}`);
5
5
  // The file as the reader lowers it (the class named).
6
6
  export function readRuby(file, names, opts = {}) {
7
7
  const cp = node('node:child_process'), path = node('node:path');
@@ -1649,7 +1649,8 @@ export class Exec {
1649
1649
  return [v, { ...q2, locals: p.locals }];
1650
1650
  }
1651
1651
  const flow = this.block(d.body.statements, q);
1652
- const outs = [...flow.rets, ...(flow.live ? [[flow.live, { t: 'undef' }]] : [])];
1652
+ // (the paths that return or fall off the end; those no run takes, a failure's, left out)
1653
+ const outs = [...flow.rets, ...(flow.live ? [[flow.live, { t: 'undef' }]] : [])].filter(([q2]) => this.feasible(q2));
1653
1654
  if (!outs.length)
1654
1655
  return [{ t: 'undef' }, { ...p, pc: [...p.pc, I.F] }];
1655
1656
  const [first, ...rest] = outs;