gdp-wired 0.44.0 → 0.46.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 (133) hide show
  1. package/README.md +58 -7
  2. package/dist/core/bitsets.d.ts +2 -0
  3. package/dist/core/bitsets.js +23 -0
  4. package/dist/core/bmc.js +6 -2
  5. package/dist/core/c/reader.d.ts +9 -1
  6. package/dist/core/c/reader.js +445 -38
  7. package/dist/core/calendar.d.ts +29 -0
  8. package/dist/core/calendar.js +82 -0
  9. package/dist/core/check.js +3 -2
  10. package/dist/core/cli.d.ts +4 -0
  11. package/dist/core/cli.js +335 -39
  12. package/dist/core/compose.js +3 -1
  13. package/dist/core/counts.d.ts +5 -2
  14. package/dist/core/counts.js +335 -88
  15. package/dist/core/cycles.js +8 -1
  16. package/dist/core/cyclic.d.ts +1 -0
  17. package/dist/core/cyclic.js +13 -7
  18. package/dist/core/data-synth.d.ts +3 -0
  19. package/dist/core/data-synth.js +252 -0
  20. package/dist/core/data.d.ts +8 -2
  21. package/dist/core/data.js +1113 -172
  22. package/dist/core/discover.js +3 -1
  23. package/dist/core/draft.d.ts +19 -0
  24. package/dist/core/draft.js +53 -0
  25. package/dist/core/dsl.d.ts +39 -3
  26. package/dist/core/dsl.js +250 -31
  27. package/dist/core/effect-prims.js +2 -2
  28. package/dist/core/effect.d.ts +1 -4
  29. package/dist/core/effect.js +1 -15
  30. package/dist/core/ex/reader.exs +17 -1
  31. package/dist/core/exists.d.ts +16 -1
  32. package/dist/core/exists.js +447 -50
  33. package/dist/core/extract-c.d.ts +2 -0
  34. package/dist/core/extract-c.js +185 -31
  35. package/dist/core/extract-check.d.ts +7 -0
  36. package/dist/core/extract-check.js +115 -3
  37. package/dist/core/extract-ex.js +3 -3
  38. package/dist/core/extract-go-check.d.ts +1 -1
  39. package/dist/core/extract-go-check.js +21 -13
  40. package/dist/core/extract-go.d.ts +1 -0
  41. package/dist/core/extract-go.js +58 -9
  42. package/dist/core/extract-ir.d.ts +1 -0
  43. package/dist/core/extract-ir.js +15 -0
  44. package/dist/core/extract-jvm.d.ts +1 -1
  45. package/dist/core/extract-jvm.js +65 -14
  46. package/dist/core/extract-orm.d.ts +12 -0
  47. package/dist/core/extract-orm.js +244 -0
  48. package/dist/core/extract-print.js +23 -1
  49. package/dist/core/extract-py.d.ts +1 -0
  50. package/dist/core/extract-py.js +4 -4
  51. package/dist/core/extract-rb.js +3 -3
  52. package/dist/core/extract-read.d.ts +25 -0
  53. package/dist/core/extract-read.js +60 -5
  54. package/dist/core/extract-rs.js +22 -20
  55. package/dist/core/extract-shapes.js +22 -0
  56. package/dist/core/extract-sol.d.ts +10 -1
  57. package/dist/core/extract-sol.js +89 -30
  58. package/dist/core/extract-step.d.ts +201 -4
  59. package/dist/core/extract-step.js +1514 -111
  60. package/dist/core/extract-swift.js +24 -13
  61. package/dist/core/extract.d.ts +9 -0
  62. package/dist/core/extract.js +88 -7
  63. package/dist/core/fiber-run.d.ts +5 -0
  64. package/dist/core/fiber-run.js +18 -0
  65. package/dist/core/fresh.d.ts +2 -2
  66. package/dist/core/fresh.js +7 -3
  67. package/dist/core/go/reader.go +7 -1
  68. package/dist/core/infer.d.ts +4 -1
  69. package/dist/core/infer.js +1020 -246
  70. package/dist/core/jvm/JavaReader.java +33 -8
  71. package/dist/core/jvm/Jvm.java +20 -1
  72. package/dist/core/jvm/KtReader.java +59 -6
  73. package/dist/core/laws.d.ts +10 -3
  74. package/dist/core/laws.js +193 -14
  75. package/dist/core/machine.d.ts +16 -3
  76. package/dist/core/machine.js +212 -28
  77. package/dist/core/nonterm.js +14 -1
  78. package/dist/core/orm/harness.js +61 -0
  79. package/dist/core/orm-fixtures/schema.prisma +5 -0
  80. package/dist/core/py/harness.py +260 -21
  81. package/dist/core/py/reader.py +278 -39
  82. package/dist/core/rb/reader.rb +52 -5
  83. package/dist/core/reader-fixtures/README.md +28 -0
  84. package/dist/core/reader-fixtures/c-693042.cpp +8 -0
  85. package/dist/core/reader-fixtures/go-685506.go +14 -0
  86. package/dist/core/reader-fixtures/jvm-724362.kt +8 -0
  87. package/dist/core/reader-fixtures/jvm-737430.kt +7 -0
  88. package/dist/core/reader-fixtures/jvm-765282.kt +3 -0
  89. package/dist/core/reader-fixtures/swift-735726.swift +15 -0
  90. package/dist/core/reader-fixtures/swift-735990.swift +15 -0
  91. package/dist/core/reader-fixtures/swift-739158.swift +4 -0
  92. package/dist/core/reader-fixtures/swift-744834.swift +15 -0
  93. package/dist/core/reader-fixtures/swift-746946.swift +31 -0
  94. package/dist/core/reader-fixtures/typescript-673062.ts.txt +2 -0
  95. package/dist/core/relation.d.ts +1 -1
  96. package/dist/core/relation.js +29 -2
  97. package/dist/core/relational.js +4 -2
  98. package/dist/core/rs/src/main.rs +18 -2
  99. package/dist/core/sample-cache.d.ts +8 -0
  100. package/dist/core/sample-cache.js +46 -0
  101. package/dist/core/security.d.ts +38 -0
  102. package/dist/core/security.js +88 -0
  103. package/dist/core/sol/harness.py +63 -7
  104. package/dist/core/sol-concrete.d.ts +23 -0
  105. package/dist/core/sol-concrete.js +195 -0
  106. package/dist/core/solver.js +8 -5
  107. package/dist/core/swift/Sources/gdp-swiftreader/main.swift +50 -7
  108. package/dist/core/system.d.ts +62 -1
  109. package/dist/core/system.js +263 -4
  110. package/dist/core/transfer.js +39 -9
  111. package/dist/core/translate.js +39 -10
  112. package/dist/core/watch.js +51 -6
  113. package/dist/interchange/check.js +10 -10
  114. package/dist/interchange/format.d.ts +4 -0
  115. package/dist/interchange/format.js +24 -6
  116. package/dist/kernel/cdcl.d.ts +5 -0
  117. package/dist/kernel/cdcl.js +88 -10
  118. package/dist/kernel/epr.js +141 -29
  119. package/dist/kernel/kernel.d.ts +31 -1
  120. package/dist/kernel/kernel.js +391 -101
  121. package/dist/kernel/model-sequence.d.ts +3 -0
  122. package/dist/kernel/model-sequence.js +34 -0
  123. package/dist/kernel/prove.d.ts +30 -1
  124. package/dist/kernel/prove.js +481 -71
  125. package/dist/kernel/reader.d.ts +3 -0
  126. package/dist/kernel/reader.js +101 -14
  127. package/dist/kernel/share.d.ts +1 -0
  128. package/dist/kernel/share.js +27 -0
  129. package/dist/lean-kernel/emit.d.ts +9 -3
  130. package/dist/lean-kernel/emit.js +200 -66
  131. package/dist/lean-kernel/lean-terms.js +5 -0
  132. package/dist/lean-kernel/library.js +10 -10
  133. package/package.json +7 -2
@@ -150,7 +150,9 @@ function powers(e) {
150
150
  case 'min':
151
151
  case 'max':
152
152
  case 'if':
153
- case 'get': return undefined;
153
+ case 'get':
154
+ case 'tup':
155
+ case 'proj': return undefined;
154
156
  }
155
157
  }
156
158
  // The law a goal is of (the kernel names each goal after its law: '<law> @step').
@@ -0,0 +1,19 @@
1
+ import type { Extraction } from './extract.js';
2
+ import { type LawOpts } from './laws.js';
3
+ export type Draft = {
4
+ method?: string;
5
+ name: string;
6
+ expr: string;
7
+ answers: string;
8
+ };
9
+ export declare function draftPrompt(x: Extraction, clause: string, cite: string): string;
10
+ export declare function parseDraft(text: string): Draft[];
11
+ export declare function vetDrafts(x: Extraction, ds: Draft[], opts?: LawOpts): {
12
+ kept: Draft[];
13
+ refused: {
14
+ d: Draft;
15
+ why: string;
16
+ }[];
17
+ };
18
+ export declare const draftComments: (c: string, d: Draft, cite: string, by: string) => string[];
19
+ export declare const reviewOf: (text: string) => "reviewed" | "unreviewed" | "unmarked";
@@ -0,0 +1,53 @@
1
+ import { LawError, buildLaw, buildTwoRuns, isTwoRuns, namesWithClock } from "./laws.js";
2
+ // The question: the clause, the code's names and what a law can say.
3
+ export function draftPrompt(x, clause, cite) {
4
+ const role = { input: 'request', param: 'made with', answer: 'answered call', result: 'result', failed: 'failed', method: 'method', clock: 'clock', state: 'state', const: 'constant' };
5
+ const names = namesWithClock(x).filter(n => n.role !== 'const').map(n => ` ${n.role === 'input' && n.method ? `${n.method}(${n.code})` : n.code} ${role[n.role]}${n.map ? ` (fields: ${n.map.fields.join(', ')})` : ''}`);
6
+ return `You draft machine-checked laws for code that must meet a regulation. A person reviews every law you draft; a prover then checks it against the code.
7
+
8
+ The clause (${cite}):
9
+ ${clause.trim()}
10
+
11
+ The code (${x.model?.name ?? 'its rule'}) has these names (the code's name, then its role: state is a field, request an argument of a method, clock the request's time):
12
+ ${names.join('\n')}
13
+
14
+ A law is one expression over those names: comparisons (< <= > >= == !=), + - and * by a constant, and/or/not/implies, a map at a key (m[k].field, k in m), forall k in m: ..., a choice by its value (status == "open"). On a method (method set below) it is a law of one call of it: fields are the state after the call, old(x) before, the method's arguments by name, now the request's time. Durations: now - t < 30 days, 72 hours, now - t <= 10 business days. The code acts only when it is called, so a deadline is a law of the call that acts: what that call leaves meets the deadline (on the method that grants a request: granted implies now - received <= 30 days; or a call past the deadline doesn't grant). About two runs: "<argument> never reaches <field>, <field>" (that argument never changes those fields), "isolated by <argument>" (one caller's calls never change what another sees).
15
+
16
+ State what the clause requires, not what the code does: a law the code breaks is what the review is for. Draft only laws whose every name is in the list; leave out what the clause asks of something this code doesn't hold. Answer with JSON only, an array (empty if nothing applies):
17
+ [{"method": "<the method it is about, or null for a law of every state>", "name": "<a short sentence>", "expr": "<the expression>", "answers": "<the words of the clause it answers>"}]`;
18
+ }
19
+ // The drafter's answer: the first JSON array in it.
20
+ export function parseDraft(text) {
21
+ const at = text.indexOf('['), end = text.lastIndexOf(']');
22
+ if (at < 0 || end < at)
23
+ throw new Error('the answer holds no JSON array');
24
+ const xs = JSON.parse(text.slice(at, end + 1));
25
+ const str = (v) => (typeof v === 'string' ? v : v === undefined || v === null ? '' : JSON.stringify(v));
26
+ return xs.map(o => ({ ...(typeof o.method === 'string' && o.method ? { method: o.method } : {}), name: str(o.name).replace(/:/g, ' -').trim().replace(/[.\s]+$/, ''), expr: str(o.expr).trim(), answers: str(o.answers).trim() }));
27
+ }
28
+ // Each draft read over the code's names as `check` would read it: kept, or refused with why.
29
+ export function vetDrafts(x, ds, opts = {}) {
30
+ const kept = [], refused = [];
31
+ for (const d of ds) {
32
+ if (!d.name || !d.expr) {
33
+ refused.push({ d, why: 'no name or no expression' });
34
+ continue;
35
+ }
36
+ try {
37
+ const l = { name: d.name, expr: d.expr, ...(d.method ? { method: d.method } : {}) };
38
+ if (isTwoRuns(d.expr))
39
+ buildTwoRuns(x, l);
40
+ else
41
+ buildLaw(x, l, opts);
42
+ kept.push(d);
43
+ }
44
+ catch (e) {
45
+ refused.push({ d, why: e instanceof LawError ? e.message : String(e.message) });
46
+ }
47
+ }
48
+ return { kept, refused };
49
+ }
50
+ // The comments to paste: each law with its citation, marked unreviewed.
51
+ export const draftComments = (c, d, cite, by) => [`${c} gdp: law ${d.name}: ${d.expr}`, `${c} gdp: cite ${d.name}: ${cite}: "${d.answers.replace(/\s+/g, ' ')}" [unreviewed: drafted by ${by}]`];
52
+ // A citation's review: signed off by a person, marked unreviewed, or neither (written by hand, its review the writer's).
53
+ export const reviewOf = (text) => (/\[\s*reviewed-by:\s*[^\]]+\]/i.test(text) ? 'reviewed' : /\[\s*unreviewed\b/i.test(text) ? 'unreviewed' : 'unmarked');
@@ -4,6 +4,7 @@ import { type Report } from '../kernel/prove.js';
4
4
  import { findRing } from './live.js';
5
5
  export type TermLike = Term | number;
6
6
  export declare const termOf: (t: TermLike) => E;
7
+ export type Rounding = 'halfEven' | 'halfUp' | 'halfDown' | 'halfAway';
7
8
  export declare class Term {
8
9
  readonly e: E;
9
10
  readonly val?: number | undefined;
@@ -14,6 +15,10 @@ export declare class Term {
14
15
  mul(b: TermLike): Term;
15
16
  modBy(k: number): Term;
16
17
  divBy(k: number): Term;
18
+ floorTo(k: number): Term;
19
+ ceilTo(k: number): Term;
20
+ roundTo(k: number, mode?: Rounding): Term;
21
+ onTick(k: number): Cond;
17
22
  lt(b: TermLike): Cond;
18
23
  atMost(b: TermLike): Cond;
19
24
  gt(b: TermLike): Cond;
@@ -101,6 +106,10 @@ export declare class Int {
101
106
  get isNegative(): Cond;
102
107
  modBy(k: number): Term;
103
108
  divBy(k: number): Int;
109
+ floorTo(k: number): Int;
110
+ ceilTo(k: number): Int;
111
+ roundTo(k: number, mode?: Rounding): Int;
112
+ onTick(k: number): Cond;
104
113
  get abs(): Term;
105
114
  get clamped(): Term;
106
115
  }
@@ -124,6 +133,11 @@ export declare class Decimal {
124
133
  min(b: DecimalLike): Decimal;
125
134
  max(b: DecimalLike): Decimal;
126
135
  get isNegative(): Cond;
136
+ private tick;
137
+ floorTo(t: number): Decimal;
138
+ ceilTo(t: number): Decimal;
139
+ roundTo(t: number, mode?: Rounding): Decimal;
140
+ onTick(t: number): Cond;
127
141
  }
128
142
  export declare const nat: Kind<Term>;
129
143
  export declare const upTo: (maxValue: number) => Kind<Term>;
@@ -311,6 +325,18 @@ export declare class MapRef {
311
325
  sizeBelow(n: number): Term;
312
326
  sum(of?: (cell: Term) => TermLike): Term;
313
327
  }
328
+ export declare class RelRef {
329
+ readonly name: string;
330
+ readonly sorts: readonly string[];
331
+ constructor(name: string, sorts: readonly string[]);
332
+ private key;
333
+ at(...xs: TermLike[]): Term;
334
+ has(...xs: TermLike[]): Cond;
335
+ each(f: (...xs: Term[]) => Cond): MapWrite;
336
+ union(f: (...xs: Term[]) => Cond): MapWrite;
337
+ add(xs: TermLike[], c?: Cond): MapWrite;
338
+ remove(xs: TermLike[], c?: Cond): MapWrite;
339
+ }
314
340
  export type ListOp = {
315
341
  readonly when: Cond;
316
342
  readonly at: (k: Term) => TermLike;
@@ -518,10 +544,13 @@ type Update<S extends Obj, M extends Obj> = Partial<{
518
544
  }>;
519
545
  type Spec = {
520
546
  name: string;
547
+ ghost?: (m: Machine) => Machine;
521
548
  params: [string, Kind<unknown>][];
522
549
  inputs: [string, Kind<unknown>][];
523
550
  state: [string, number | ((p: never) => TermLike)][];
524
551
  maps: [string, number][];
552
+ rels?: [string, string[]][];
553
+ sorts?: string[];
525
554
  lists?: string[];
526
555
  cells?: [string, Kind<unknown>][];
527
556
  items?: [string, Kind<unknown>][];
@@ -530,7 +559,8 @@ type Spec = {
530
559
  carried?: string[];
531
560
  counts?: [string, (env: never) => {
532
561
  below: TermLike;
533
- body: (x: Term, k: Term) => Cond | TermLike;
562
+ body: (x: Term, k: Term, y: Term) => Cond | TermLike;
563
+ base?: number;
534
564
  }][];
535
565
  seqs?: string[];
536
566
  seqTables?: string[];
@@ -575,6 +605,11 @@ export declare class Rule<P extends Obj = {}, I extends Obj = {}, S extends Obj
575
605
  maps<T extends Record<string, number | Init<unknown>>>(init: T): Rule<P, I, S, M & {
576
606
  [k in keyof T]: T[k] extends Init<infer V> ? CellsRef<V> : MapRef;
577
607
  }, F, R, Su, Q>;
608
+ sorts(...names: string[]): Rule<P, I, S, M, F, R, Su, Q>;
609
+ relations<T extends Record<string, readonly string[]>>(rels: T): Rule<P, I, S, M & {
610
+ [k in keyof T]: RelRef;
611
+ }, F, R, Su, Q>;
612
+ relations(f: (env: P & I & Su & Q) => Relation[]): Rule<P, I, S, M, F, R, Su, Q>;
578
613
  ints<T extends Record<string, number | ((p: P) => IntLike)>>(init: T): Rule<P, I, S & {
579
614
  [k in keyof T]: Int;
580
615
  }, M, F, R, Su, Q>;
@@ -607,7 +642,8 @@ export declare class Rule<P extends Obj = {}, I extends Obj = {}, S extends Obj
607
642
  }, S, M, F, R, Su, Q>;
608
643
  counts<T extends Record<string, (env: P & I & S & M) => {
609
644
  below: TermLike;
610
- body: (x: Term, k: Term) => Cond | TermLike;
645
+ body: (x: Term, k: Term, y: Term) => Cond | TermLike;
646
+ base?: number;
611
647
  }>>(cs: T): Rule<P, I & {
612
648
  [k in keyof T]: MapRef;
613
649
  }, S, M, F, R, Su, Q>;
@@ -637,7 +673,6 @@ export declare class Rule<P extends Obj = {}, I extends Obj = {}, S extends Obj
637
673
  [k in keyof T]: Maybe<Term>;
638
674
  }>;
639
675
  keep(f: (env: P & I & S & M & F & Su & Q) => Cond): Rule<P, I, S, M, F, R, Su, Q>;
640
- relations(f: (env: P & I & Su & Q) => Relation[]): Rule<P, I, S, M, F, R, Su, Q>;
641
676
  prune(order: keyof R & string, after: (p: P) => TermLike): Rule<P, I, S, M, F, R, Su, Q>;
642
677
  law(name: string, f: (env: P & S & M & Su) => Cond | Forall): Law;
643
678
  private lawOf;
@@ -672,6 +707,7 @@ export declare class Rule<P extends Obj = {}, I extends Obj = {}, S extends Obj
672
707
  private whatIs;
673
708
  private distinct;
674
709
  get machine(): Machine;
710
+ withGhosts(ghost: (m: Machine) => Machine): this;
675
711
  crossCheck(laws: Law[], stepLaws?: StepLaw[], opts?: {
676
712
  trials?: number;
677
713
  depth?: number;