gdp-wired 0.43.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 (44) hide show
  1. package/README.md +8 -3
  2. package/dist/core/cli.d.ts +6 -0
  3. package/dist/core/cli.js +48 -6
  4. package/dist/core/data.js +2 -2
  5. package/dist/core/effect-prims.d.ts +60 -0
  6. package/dist/core/effect-prims.js +625 -0
  7. package/dist/core/effect.d.ts +17 -1
  8. package/dist/core/effect.js +108 -4
  9. package/dist/core/ex/harness.exs +2 -0
  10. package/dist/core/extract-c.d.ts +2 -0
  11. package/dist/core/extract-c.js +5 -3
  12. package/dist/core/extract-check.d.ts +1 -0
  13. package/dist/core/extract-check.js +8 -1
  14. package/dist/core/extract-ex.js +2 -2
  15. package/dist/core/extract-go-check.js +4 -6
  16. package/dist/core/extract-go.d.ts +3 -0
  17. package/dist/core/extract-go.js +4 -4
  18. package/dist/core/extract-jvm.js +6 -3
  19. package/dist/core/extract-py.js +2 -2
  20. package/dist/core/extract-rb.js +2 -2
  21. package/dist/core/extract-rs.js +12 -7
  22. package/dist/core/extract-sol.js +4 -4
  23. package/dist/core/extract-step.d.ts +9 -0
  24. package/dist/core/extract-step.js +48 -9
  25. package/dist/core/extract-swift.js +3 -3
  26. package/dist/core/infer.js +3 -3
  27. package/dist/core/jvm/Harness.java +8 -1
  28. package/dist/core/jvm/Jvm.java +1 -1
  29. package/dist/core/jvm/KtReader.java +3 -0
  30. package/dist/core/machine.d.ts +3 -0
  31. package/dist/core/machine.js +15 -1
  32. package/dist/core/py/harness.py +51 -13
  33. package/dist/core/sol/Replay.sol +52 -0
  34. package/dist/core/sol/harness.py +508 -0
  35. package/dist/core/system.js +12 -3
  36. package/dist/interchange/check.d.ts +18 -1
  37. package/dist/interchange/check.js +9 -2
  38. package/dist/interchange/cli.d.ts +2 -0
  39. package/dist/interchange/cli.js +45 -0
  40. package/dist/interchange/format.d.ts +1 -1
  41. package/dist/interchange/format.js +15 -7
  42. package/dist/kernel/cdcl.js +32 -12
  43. package/dist/kernel/reader.js +3 -2
  44. package/package.json +12 -3
package/README.md CHANGED
@@ -177,7 +177,10 @@ All of these are proven automatically, and each proof is also a Lean theorem:
177
177
  a run of two fibers; `Effect.retry` and `Effect.repeat` inside a method are part of its step. A `Schedule` is a rule of
178
178
  its decisions (attempt, retries, delay, elapsed, done; exponential a `recur` function, jitter an input within its
179
179
  range), every combinator a fragment of one machine, checked by stepping Effect's own schedule
180
- (`examples/effect-retry.ts`, `examples/effect-stm.ts`). `conforms(rule, service)` runs a rule written by hand
180
+ (`examples/effect-retry.ts`, `examples/effect-stm.ts`). A `Queue` (bounded, dropping, sliding, unbounded) or a
181
+ `Semaphore` the service makes is modelled once, its own laws proven (bounded, nothing lost, FIFO, the permits) and
182
+ run beside Effect's own on random operations and fibers, so a law states only the service's own
183
+ (`examples/effect-queue.ts`: a worker pool, a release without its acquire refuted by a run). `conforms(rule, service)` runs a rule written by hand
181
184
  beside a running service (Effect's own Semaphore, a store), and `fromSchema(schema)` is a Schema's kind
182
185
  (`examples/effect.ts`; what is read and refused, with what Effect projects write, in `research/effect/README.md`).
183
186
  - **What nobody stated, looked for when the prover alone stops**: where `proveRule` or `proveSteps` doesn't prove the laws
@@ -561,7 +564,7 @@ Proving and checking: a law over 64 steps proves in about 5 s, and Lean checks i
561
564
  | `kernel/` | The trusted kernel and the untrusted prover, with soundness fuzz (`kernel.test.ts`, `history.test.ts`) |
562
565
  | `lean-kernel/` | The kernel's Lean twin, its soundness proofs, and the exported trees |
563
566
  | `examples/` | The builders at work: `domains/` (187 rules across 21 domains, each with laws and broken variants), `harness.ts` (the triple check), `readme.ts`, `guide.ts` (the guide's code), `groups.ts` (two groups decided at every pair), `budget.ts`, `gdp.ts` (gdp-ts's example, its checks proven), `exists.ts` (laws with "there exists"), `datatypes.ts` (records and variants), `lemmas.ts` (recurrences and their lemmas), `invoices.ts` (lists a request carries), `folds.ts` (folds over trees), `trees.ts` (trees and lists of lists in the state), `composition.ts`, `sets.ts`, `quantifiers.ts`, `functions.ts`, `arith.ts` (division and remainder by a constant, integers in rules and datatypes), `lists.ts`, `sizes.ts`, `liveness.ts`, `steps.ts` (laws over up to 64 steps), and `jev-fabric/` (a Bend project's 59 proven laws, ported) |
564
- | `docs/` | The comparison with Bend and Lean, and the full scope |
567
+ | `docs/` | [ARCHITECTURE.md](docs/ARCHITECTURE.md) (the trust boundaries and what guards each), [FRONTENDS.md](docs/FRONTENDS.md) (how a language's reader plugs in), [interchange.md](docs/interchange.md) (certificates as JSON, for checkers in other languages), the comparison with Bend and Lean |
565
568
  | `compare/` | The same three rules in gdp-wired, Bend and plain Lean, checked and measured |
566
569
  | `research/` | Everything around the library ([`research/README.md`](research/README.md)): the GPU searches (`search/`, `hw/`, `modal-gpu/`), invariant and rank synthesis (`synth/`), relational laws and guard synthesis (`next/`), bit-vector laws (`sat/`), the enumeration and benchmarks (`enum/`, `gpu/`, `perf/`), the first Lean checker (`lean/`) and the first prototype, the audit path (`audit/`) |
567
570
  | `supercomputer/` | Everything above as jobs on boat (a warm pool), Modal and RunPod: `suite.json` is the regression suite (`modal/` links here until every lane has merged the rename) |
@@ -578,7 +581,9 @@ The npm package is the library: the builders (`gdp-wired`), the runtimes (`gdp-w
578
581
  `typescript` installed), Effect services (`gdp-wired/effect`, with `typescript` and `effect`), lemmas nobody stated (`gdp-wired/discover`), invariant
579
582
  inference (`gdp-wired/infer`), the
580
583
  Lean export (`gdp-wired/lean`), the kernel (`gdp-wired/kernel`), the prover (`gdp-wired/prove`), the derivation checker
581
- and solver (`gdp-wired/check`, `gdp-wired/solver`). Everything else here (examples, comparisons, the Lean twin, the GPU
584
+ and solver (`gdp-wired/check`, `gdp-wired/solver`), and the interchange reader and checker (`gdp-wired/interchange`, with
585
+ the `gdp-wired-check` bin: `npx -p gdp-wired gdp-wired-check cert.json` checks a certificate `gdp-wired check --cert`
586
+ wrote with the kernel alone, no search). Everything else here (examples, comparisons, the Lean twin, the GPU
582
587
  searches) runs from a clone and needs [Bun](https://bun.sh); Lean 4.34.0 for `lean/` and `lean-kernel/`; a WebGPU
583
588
  runtime (Chrome, or Dawn's node bindings) for the GPU parts. Releases: bump `version` in `package.json` and push to
584
589
  main; `.github/workflows/publish.yml` publishes it with npm provenance.
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import type { Extraction, Name } from './extract.js';
3
3
  import { type Verdict } from './dsl.js';
4
+ import { type LawText } from './laws.js';
4
5
  export declare const colors: (env: Record<string, string | undefined>, tty: boolean, json?: boolean) => boolean;
5
6
  export type Opts = {
6
7
  entry?: string;
@@ -64,6 +65,11 @@ export type RuleOut = {
64
65
  brokenProposed?: number;
65
66
  source?: string;
66
67
  };
68
+ type Scoped = LawText & {
69
+ cls?: string;
70
+ fn?: string;
71
+ };
72
+ export declare function scoped(file: string): Scoped[];
67
73
  export declare function checkTarget(t: Target, o: Opts): Promise<RuleOut[]>;
68
74
  export declare function runOf(x: Extraction, run: NonNullable<Verdict['run']>): string[];
69
75
  export declare const proposedLaws: (x: Extraction, lang: Lang, ms?: number) => {
package/dist/core/cli.js CHANGED
@@ -332,7 +332,26 @@ async function rulesOf0(t, o, laws) {
332
332
  const fns = [...new Set(laws.filter(l => !l.cls && l.fn).map(l => l.fn))];
333
333
  return several.length || fns.length ? Promise.all([...several, ...fns].map(c => one(c))) : [first];
334
334
  }
335
- function scoped(file) {
335
+ // (a class statement's name: its keyword at the start of a line, after modifiers; never a word in a comment)
336
+ const classAt = (line) => {
337
+ const m = /^\s*(?:(?:export|default|public|private|protected|internal|abstract|final|sealed|open|data|static|partial|pub(?:\([^)]*\))?|unsafe)\s+)*(?:class|struct|actor|defmodule|module|object|impl(?:<[^>]*>)?|record|interface|contract)\s+([\w.:]+)|^\s*type\s+(\w+)\s+struct\b/.exec(line.replace(/(#|\/\/).*$/, ''));
338
+ return m ? (m[1] ?? m[2]).split(/[.:<]/).filter(Boolean).pop() : undefined;
339
+ };
340
+ // (a type written like a call declares a value, never a function: `mapping(address => uint256) public balances;`, its
341
+ // parentheses closed, then a name (after modifiers) and `;` or `=`; a function's qualifiers (const, override, ...) are no
342
+ // name. A law on such a value is on no function, nor is one followed by another class's statement before any.)
343
+ const declares = (code, open) => {
344
+ let d = 0, i = open;
345
+ for (; i < code.length; i++) {
346
+ if (code[i] === '(')
347
+ d++;
348
+ else if (code[i] === ')' && --d === 0)
349
+ break;
350
+ }
351
+ const m = /^\s*(?:[A-Za-z_$][\w$]*\s+)*([A-Za-z_$][\w$]*)\s*(?:;|=(?![=>]))/.exec(code.slice(i + 1));
352
+ return !!m && !/^(const|override|final|noexcept|volatile|default|delete)$/.test(m[1]);
353
+ };
354
+ export function scoped(file) {
336
355
  const text = fs.readFileSync(file, 'utf8'), lines = text.split('\n');
337
356
  return lawsIn(text, path.basename(file)).map(l => {
338
357
  let cls, fn;
@@ -340,10 +359,21 @@ function scoped(file) {
340
359
  // docstring's or a comment's prose; in Python, at an indentation that encloses the law's)
341
360
  const indent = (x) => /^\s*/.exec(x)[0].length, lawIndent = indent(lines[l.line - 1]), py = file.endsWith('.py');
342
361
  for (let i = l.line - 1; i >= 0 && !cls; i--) {
343
- const m = /^\s*(?:(?:export|default|public|private|protected|internal|abstract|final|sealed|open|data|static|partial|pub(?:\([^)]*\))?|unsafe)\s+)*(?:class|struct|actor|defmodule|module|object|impl(?:<[^>]*>)?|record|interface|contract)\s+([\w.:]+)|^\s*type\s+(\w+)\s+struct\b/.exec(lines[i].replace(/(#|\/\/).*$/, ''));
362
+ const m = classAt(lines[i]);
344
363
  if (m && (!py || indent(lines[i]) < lawIndent))
345
- cls = (m[1] ?? m[2]).split(/[.:<]/).filter(Boolean).pop();
364
+ cls = m;
365
+ }
366
+ // (a law right above a class statement, past comments, blank lines and annotations, is that class's: a contract's,
367
+ // a struct's, a class's, never its first member's; one indented inside a class above a class after it isn't)
368
+ let above;
369
+ for (let i = l.line; i < lines.length; i++) {
370
+ if (/^\s*(\/\/|\/?\*|#|@|--|$)/.test(lines[i]))
371
+ continue;
372
+ above = indent(lines[i]) >= lawIndent ? classAt(lines[i]) : undefined;
373
+ break;
346
374
  }
375
+ if (above)
376
+ return { ...l, cls: above };
347
377
  // (in TypeScript, a law right above a declaration of a value, a schedule's say, is that value's)
348
378
  let top = false;
349
379
  if (/\.[cm]?[jt]sx?$/.test(file)) {
@@ -357,10 +387,15 @@ function scoped(file) {
357
387
  }
358
388
  }
359
389
  let fnLine = -1;
360
- for (let i = l.line - 1; i < lines.length && !fn; i++) {
390
+ let onValue = false;
391
+ for (let i = l.line - 1; i < lines.length && !fn && !onValue; i++) {
361
392
  const code = i === l.line - 1 ? lines[i].replace(/(#|\/\/|--).*$/, '') : lines[i];
393
+ if (i >= l.line && classAt(code))
394
+ break;
362
395
  const m = /\b(?:def|defp|fn|fun|func|function)\s+(?:\([^)]*\)\s*)?(?:self\.)?(\w+)|^\s*(?:(?:public|private|protected|static|final|synchronized|async|override|open|suspend|inline|virtual|const|[\w<>[\],?]+)\s+)*(\w+)\s*\(/.exec(code);
363
- if (m && !/^(if|for|while|switch|return|catch|new)$/.test(m[1] ?? m[2])) {
396
+ if (m && !m[1] && declares(code, m.index + m[0].length - 1))
397
+ onValue = true;
398
+ else if (m && !/^(if|for|while|switch|return|catch|new)$/.test(m[1] ?? m[2])) {
364
399
  fn = m[1] ?? m[2];
365
400
  fnLine = i;
366
401
  }
@@ -396,7 +431,8 @@ export async function checkTarget(t, o) {
396
431
  const others = Object.fromEntries(rules.filter(r => r.x.ok).map(r => [r.entry ?? r.x.model?.name ?? '', r.x]));
397
432
  const cfg = configFor(t.lang === 'go' || t.lang === 'rust' || fs.statSync(t.at).isDirectory() ? t.at : path.dirname(t.at));
398
433
  const ctx = { ms: o.ms, clock: unit === 's' ? 1 : unit === 'ms' ? 1000 : undefined, others, cites, cert: o.cert, file: path.relative(proc.cwd(), t.at) || t.at };
399
- for (const { entry, x } of rules) {
434
+ for (const { entry, x: x0 } of rules) {
435
+ let x = x0;
400
436
  const name = entry ?? (x.model?.name || undefined);
401
437
  // (a target that is the working directory, a crate's or a package's: `.`)
402
438
  const r = { file: path.relative(proc.cwd(), t.at) || '.', lang: LANG_NAME[t.lang], ...(name ? { entry: name } : {}), ok: x.ok, refusals: x.refusals, notes: x.notes, names: x.names ?? [], laws: [], proposed: [], ...(x.source ? { source: x.source } : {}) };
@@ -413,6 +449,12 @@ export async function checkTarget(t, o) {
413
449
  r.laws = mine.map(l => ({ name: l.name, expr: l.expr, where: l.where, verdict: 'not read', why: 'the rule was refused', ms: 0 }));
414
450
  continue;
415
451
  }
452
+ // (an Effect service's primitives: the lemmas of their use proven first, each proven one beside every law)
453
+ if (x.lemmas?.length) {
454
+ const { withLemmas } = await import("./effect.js"), w = withLemmas(x, { ms: Math.max(o.ms, 30_000) });
455
+ x = w.x;
456
+ r.notes = [...r.notes, ...w.proven.map(n => `lemma proven, beside every law: ${n}`), ...w.unproven.map(n => `lemma not proven (left out): ${n}`)];
457
+ }
416
458
  const ev = x.evidence;
417
459
  if (ev)
418
460
  r.checked = `checked against ${'probes' in ev ? `the code: ${ev.requests} requests from the start, ${ev.fromStates} from drawn states, ${ev.probes.steps} from the prover's witnesses` : `XState's own actor: ${ev.events} events`}${ev.coverage.arms ? `, ${ev.coverage.hit} of ${ev.coverage.arms} branch arms` : ''}${'startsOutside' in ev && ev.startsOutside ? `; ${ev.startsOutside} starts whose constructor passes 2^53 - 1 left out (outside the rule's numbers: the claim is for starts within them)` : ''}`;
package/dist/core/data.js CHANGED
@@ -26,7 +26,7 @@
26
26
  // using the others at the fields of their datatypes (mutual induction). Lemmas the law needs are found by the values
27
27
  // (theory exploration: equations between terms the random values agree on, then the shapes of a predicate kept), proven
28
28
  // the same way at lower levels, and used at the terms of the law they match.
29
- import { argsKey, atMost as leC, get, n as k, same as eqC, walk, x as ev } from "./machine.js";
29
+ import { argsKey, atMost as leC, get, n as k, same as eqC, walk, x as ev, lcgFloat } from "./machine.js";
30
30
  import { substC, substE } from "../kernel/kernel.js";
31
31
  import { and as andC, implies, proveCyclic } from "./cyclic.js";
32
32
  import { clock, counted, pairedKeys, withDeadline } from "../kernel/prove.js";
@@ -1160,7 +1160,7 @@ export const showValue = (d, v) => {
1160
1160
  const c = d.ctors[v.c];
1161
1161
  return c.fields.length ? `${c.name}(${c.fields.map((f, i) => showValue(fieldSort(f), v.f[i])).join(', ')})` : c.name;
1162
1162
  };
1163
- export const rng = (seed) => () => { seed = (seed * 1103515245 + 12345) % 2147483648; return seed / 2147483648; };
1163
+ export const rng = (seed) => () => (seed = lcgFloat(seed)) / 2147483648; // (a search's draws: machine.ts's lcgFloat)
1164
1164
  // `full`: a value that fills its size (a constructor with a field of the group, unless the size is spent, or at 1 in 8),
1165
1165
  // where the plain draw mostly stops at a leaf (a list of length 0 or 1, most often).
1166
1166
  export function randomValue(s, rand, size, natMax = 5, full = false) {
@@ -0,0 +1,60 @@
1
+ import ts from 'typescript';
2
+ import type { StepLaw } from './dsl.js';
3
+ import { type Law } from './machine.js';
4
+ import { type Setup } from './extract-read.js';
5
+ import type { Extraction } from './extract.js';
6
+ export type Strategy = 'bounded' | 'dropping' | 'sliding' | 'unbounded';
7
+ export type Prim = {
8
+ name: string;
9
+ kind: 'queue';
10
+ strategy: Strategy;
11
+ capacity?: number | string;
12
+ fields: string[];
13
+ } | {
14
+ name: string;
15
+ kind: 'semaphore';
16
+ permits: number | string;
17
+ fields: string[];
18
+ };
19
+ type Api = (e: ts.Expression) => string | undefined;
20
+ export declare const WAITS_FOREVER = "an operation that interrupts its fiber on a shut-down queue (every one on Effect 3, take on Effect 4) is read as a wait that never ends: the fiber takes no step after it, which is what an interrupted one does";
21
+ export declare function rewritePrims(s: Setup, made: {
22
+ fn: ts.FunctionLikeDeclaration;
23
+ params: readonly ts.ParameterDeclaration[];
24
+ }, api: Api, v4: boolean, opts?: {
25
+ params?: boolean;
26
+ }): {
27
+ code: string;
28
+ prims: Prim[];
29
+ notes: string[];
30
+ } | undefined;
31
+ type Mod = Record<string, any>;
32
+ export type Spec = {
33
+ kind: 'queue';
34
+ strategy: Strategy;
35
+ } | {
36
+ kind: 'semaphore';
37
+ };
38
+ export declare function primitiveRule(spec: Spec, effect: Mod, opts?: {
39
+ runs?: number;
40
+ file?: string;
41
+ }): Extraction;
42
+ export declare function primitiveLaws(x: Extraction, spec: Spec): {
43
+ laws: Law[];
44
+ stepLaws: StepLaw[];
45
+ refuted: Law[];
46
+ };
47
+ export declare function primitiveConforms(spec: Spec, effect: Mod, opts?: {
48
+ runs?: number;
49
+ depth?: number;
50
+ seed?: number;
51
+ x?: Extraction;
52
+ file?: string;
53
+ }): Promise<{
54
+ checked: number;
55
+ waited: number;
56
+ blocked: number;
57
+ interrupted: number;
58
+ failure?: string;
59
+ }>;
60
+ export {};