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
@@ -0,0 +1,29 @@
1
+ import { type Cond, Int, type IntLike, Term } from './dsl.js';
2
+ export type Calendar = {
3
+ weekend?: string[];
4
+ holidays?: string[];
5
+ utc_offset?: string;
6
+ };
7
+ export declare class CalendarError extends Error {
8
+ }
9
+ export type Pinned = {
10
+ t: Int;
11
+ w: Int;
12
+ };
13
+ export declare function businessDays(cal: Calendar, clock?: 's' | 'ms'): {
14
+ calendar: {
15
+ weekend: string[];
16
+ holidays: number;
17
+ offset: string;
18
+ clock: "s" | "ms";
19
+ };
20
+ upTo: (x: IntLike | Pinned) => Int;
21
+ between: (a: IntLike | Pinned, b: IntLike | Pinned) => Int;
22
+ pin: (x: IntLike, w: IntLike) => {
23
+ at: Pinned;
24
+ guard: Cond;
25
+ };
26
+ count: (a: number, b: number) => number;
27
+ };
28
+ export type BusinessDays = ReturnType<typeof businessDays>;
29
+ export declare const keyInt: (k: Term, k2?: Term) => Int;
@@ -0,0 +1,82 @@
1
+ // Business days over a calendar (`gdp-wired/laws`): "within 10 business days" decided in the kernel's own arithmetic,
2
+ // nothing new trusted. A calendar is its weekend days, its holidays (dates) and its offset from UTC, stated once
3
+ // (`[calendar]` in gdp.toml, or given here); the request's time is the clock's (seconds or milliseconds since 1970 UTC).
4
+ //
5
+ // The count. A time x is on day s(x) = ⌊(x + offset)/D⌋ + 10 (D a day in the clock's units; day 0 the Monday 1969-12-22,
6
+ // so a time from 1970 on, at any offset within ±14 h, is on a day at least 0). C(x), the business days up to and
7
+ // including x's day, is
8
+ // C(x) = k·w + #{p a working weekday : p <= r} − #{h a holiday on a working weekday : h <= s(x)}
9
+ // with w = ⌊y/7D⌋ x's week, r its weekday (0 Monday), y = x + offset + 10·D and k the working days in a week. Each
10
+ // "p <= r" is y >= 7D·w + D·p, and each "h <= s(x)" is y >= D·h: comparisons linear in y and w. So C is linear but for
11
+ // the one division ⌊y/7D⌋. Where the law may read functions (a law about every state) that is divBy(7D), the kernel's
12
+ // own div$k with its facts; a law of one step can't read a function, so there the week is a key the law holds at
13
+ // every value of, under the guard 7D·w <= y < 7D·w + 7D, which only ⌊y/7D⌋ meets: ∀w. guard → L is L at ⌊y/7D⌋.
14
+ //
15
+ // Elapsed business days from a to b: C(b) − C(a), the business days after a's day up to and including b's (the day
16
+ // of receipt doesn't count; the last day counts whole). Negative where b is before a. `now - received <= 10 business
17
+ // days` in a law is C(now) − C(received) <= 10.
18
+ //
19
+ // What it doesn't model: daylight saving (one fixed offset), a holiday not listed (a year with no list has none),
20
+ // half days. The calendar is the person's statement, like a law's citation; the arithmetic over it is exact.
21
+ import { Int, all, when } from "./dsl.js";
22
+ const DAYS = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'];
23
+ export class CalendarError extends Error {
24
+ }
25
+ // Day index of a date (YYYY-MM-DD) from the Monday 1969-12-22.
26
+ const dayOf = (d) => {
27
+ const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(d.trim());
28
+ const t = m ? Date.UTC(Number(m[1]), Number(m[2]) - 1, Number(m[3])) : NaN;
29
+ if (!m || Number.isNaN(t) || new Date(t).toISOString().slice(0, 10) !== d.trim())
30
+ throw new CalendarError(`${d}: a holiday is a date, YYYY-MM-DD`);
31
+ return t / 86_400_000 + 10;
32
+ };
33
+ export function businessDays(cal, clock = 's') {
34
+ const unit = clock === 'ms' ? 1000 : 1, D = 86_400 * unit, W = 7 * D;
35
+ const weekend = (cal.weekend ?? ['sat', 'sun']).map(d => d.trim().toLowerCase().slice(0, 3));
36
+ for (const d of weekend)
37
+ if (!DAYS.includes(d))
38
+ throw new CalendarError(`${d}: a weekend day is one of ${DAYS.join(', ')}`);
39
+ const work = DAYS.map((_, p) => p).filter(p => !weekend.includes(DAYS[p]));
40
+ if (!work.length)
41
+ throw new CalendarError('a calendar whose every day is a weekend day has no business day');
42
+ const off = /^([+-])(\d{2}):(\d{2})$/.exec((cal.utc_offset ?? '+00:00').trim());
43
+ if (!off || Number(off[2]) * 60 + Number(off[3]) > 14 * 60 || Number(off[3]) > 59)
44
+ throw new CalendarError(`${cal.utc_offset}: an offset from UTC is ±HH:MM, at most 14 hours`);
45
+ const offset = (off[1] === '-' ? -1 : 1) * (Number(off[2]) * 3600 + Number(off[3]) * 60) * unit;
46
+ // (the holidays that take a working day away, each once, in order)
47
+ const hols = [...new Set((cal.holidays ?? []).map(dayOf))].filter(h => work.includes(((h % 7) + 7) % 7)).sort((a, b) => a - b);
48
+ const shift = (x) => Int.of(x).plus(offset + 10 * D);
49
+ // (the holidays on or before y's day, as a balanced choice: one path per count, never 2^n)
50
+ const held = (y, lo, hi) => {
51
+ if (lo > hi)
52
+ return Int.of(0);
53
+ const mid = (lo + hi) >> 1;
54
+ return when(y.atLeast(hols[mid] * D), held(y, mid + 1, hi).plus(mid - lo + 1), held(y, lo, mid - 1));
55
+ };
56
+ // C at y = x + offset + 10D in week w.
57
+ const count = (y, w) => work.reduce((n, p) => n.plus(when(y.atLeast(w.times(W).plus(p * D)), Int.of(1), Int.of(0))), w.times(work.length)).minus(held(y, 0, hols.length - 1));
58
+ const pinned = (x) => typeof x === 'object' && x !== null && 'w' in x && 't' in x;
59
+ const C = (x) => (pinned(x) ? count(shift(x.t), x.w) : count(shift(x), shift(x).divBy(W)));
60
+ return {
61
+ calendar: { weekend, holidays: hols.length, offset: cal.utc_offset ?? '+00:00', clock },
62
+ // The business days up to and including x's day (from 1969-12-22), and from a's day to b's.
63
+ upTo: C,
64
+ between: (a, b) => C(b).minus(C(a)),
65
+ // x's week pinned to the key w (a step law's), with the guard only ⌊y/7D⌋ meets.
66
+ pin: (x, w) => {
67
+ const y = shift(x), wk = Int.of(w);
68
+ return { at: { t: Int.of(x), w: wk }, guard: all(wk.times(W).atMost(y), y.lt(wk.times(W).plus(W))) };
69
+ },
70
+ // The same count computed (for runs and tests): the business days from a's day to b's.
71
+ count: (a, b) => {
72
+ const c = (x) => {
73
+ const y = x + offset + 10 * D, s = Math.floor(y / D), w = Math.floor(y / W), r = s - 7 * w;
74
+ return w * work.length + work.filter(p => p <= r).length - hols.filter(h => h <= s).length;
75
+ };
76
+ return c(b) - c(a);
77
+ },
78
+ };
79
+ }
80
+ // A key's term as an integer (a step law's key is a natural; the week of a time before 1969-12-22 has none, so a key
81
+ // for one is the difference of two).
82
+ export const keyInt = (k, k2) => (k2 ? new Int(k, k2) : Int.of(k));
@@ -17,7 +17,8 @@ export function checkRefutation(constraints, steps, integral = true) {
17
17
  return false;
18
18
  if (!integral && !(Number.isInteger(s.a) && Number.isInteger(s.b) && s.a >= 0 && s.b >= 0))
19
19
  return false;
20
- const out = {};
20
+ // (on no prototype: a row's variable named __proto__ is summed like any other, never dropped)
21
+ const out = Object.create(null);
21
22
  // Each product safe too: a rounded one is past 2^53, but the other row's could bring the sum back under it.
22
23
  for (const [lin, m] of [[rows[s.a], s.ma], [rows[s.b], s.mb]])
23
24
  for (const [key, c] of Object.entries(lin)) {
@@ -48,7 +49,7 @@ export function checkWitness(constraints, witness) {
48
49
  return constraints.every(c => {
49
50
  let sum = 0;
50
51
  for (const [key, a] of Object.entries(c.lin)) {
51
- const value = key === '1' ? 1 : witness[key], term = a * value;
52
+ const value = key === '1' ? 1 : Object.hasOwn(witness, key) ? witness[key] : undefined, term = a * value;
52
53
  if (!(Number.isSafeInteger(a) && Number.isSafeInteger(value) && Number.isSafeInteger(term) && Number.isSafeInteger(sum + term)))
53
54
  return false;
54
55
  sum += term;
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import type { Extraction, Name } from './extract.js';
3
+ import { type SecurityCandidate } from './security.js';
3
4
  import { type Verdict } from './dsl.js';
4
5
  import { type LawText } from './laws.js';
5
6
  export declare const colors: (env: Record<string, string | undefined>, tty: boolean, json?: boolean) => boolean;
@@ -52,6 +53,7 @@ export type RuleOut = {
52
53
  file: string;
53
54
  lang: string;
54
55
  entry?: string;
56
+ ctor?: string;
55
57
  ok: boolean;
56
58
  refusals: {
57
59
  where: string;
@@ -60,10 +62,12 @@ export type RuleOut = {
60
62
  notes: string[];
61
63
  names: Name[];
62
64
  checked?: string;
65
+ env?: string[];
63
66
  laws: LawOut[];
64
67
  proposed: LawOut[];
65
68
  brokenProposed?: number;
66
69
  source?: string;
70
+ security?: (LawOut & Pick<SecurityCandidate, 'securityKind' | 'review'>)[];
67
71
  };
68
72
  type Scoped = LawText & {
69
73
  cls?: string;