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.
- package/README.md +8 -3
- package/dist/core/cli.d.ts +6 -0
- package/dist/core/cli.js +48 -6
- package/dist/core/data.js +2 -2
- package/dist/core/effect-prims.d.ts +60 -0
- package/dist/core/effect-prims.js +625 -0
- package/dist/core/effect.d.ts +17 -1
- package/dist/core/effect.js +108 -4
- package/dist/core/ex/harness.exs +2 -0
- package/dist/core/extract-c.d.ts +2 -0
- package/dist/core/extract-c.js +5 -3
- package/dist/core/extract-check.d.ts +1 -0
- package/dist/core/extract-check.js +8 -1
- package/dist/core/extract-ex.js +2 -2
- package/dist/core/extract-go-check.js +4 -6
- package/dist/core/extract-go.d.ts +3 -0
- package/dist/core/extract-go.js +4 -4
- package/dist/core/extract-jvm.js +6 -3
- package/dist/core/extract-py.js +2 -2
- package/dist/core/extract-rb.js +2 -2
- package/dist/core/extract-rs.js +12 -7
- package/dist/core/extract-sol.js +4 -4
- package/dist/core/extract-step.d.ts +9 -0
- package/dist/core/extract-step.js +48 -9
- package/dist/core/extract-swift.js +3 -3
- package/dist/core/infer.js +3 -3
- package/dist/core/jvm/Harness.java +8 -1
- package/dist/core/jvm/Jvm.java +1 -1
- package/dist/core/jvm/KtReader.java +3 -0
- package/dist/core/machine.d.ts +3 -0
- package/dist/core/machine.js +15 -1
- package/dist/core/py/harness.py +51 -13
- package/dist/core/sol/Replay.sol +52 -0
- package/dist/core/sol/harness.py +508 -0
- package/dist/core/system.js +12 -3
- package/dist/interchange/check.d.ts +18 -1
- package/dist/interchange/check.js +9 -2
- package/dist/interchange/cli.d.ts +2 -0
- package/dist/interchange/cli.js +45 -0
- package/dist/interchange/format.d.ts +1 -1
- package/dist/interchange/format.js +15 -7
- package/dist/kernel/cdcl.js +32 -12
- package/dist/kernel/reader.js +3 -2
- package/package.json +12 -3
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { canon, columnTerm, factorsOf, isCell, isMonomial, termColumn } from "../kernel/kernel.js";
|
|
2
|
-
|
|
2
|
+
// 1.1 adds a liveness's fairness and levels (strong fairness, Live.lean's sleads_sound): a document is written at the
|
|
3
|
+
// lowest version that holds it (1.0 unless a liveness is strong or has levels), and read at either.
|
|
4
|
+
export const FORMAT = 'gdp-wired-interchange', VERSION = '1.1', VERSIONS = ['1.0', '1.1'];
|
|
3
5
|
export const KINDS = ['goals', 'laws', 'stepLaws', 'kInduction', 'progress', 'liveness', 'loop', 'recur', 'fold', 'cyclic', 'qgoals', 'qmachine', 'termination'];
|
|
4
6
|
// Why a value is outside the format: where, and what.
|
|
5
7
|
export class FormatError extends Error {
|
|
@@ -484,12 +486,15 @@ const encRank = (r, at) => (Array.isArray(r) ? r.map((e, i) => encE(e, `${at}[${
|
|
|
484
486
|
const decRank = (x, at) => (Array.isArray(x) ? x.map((e, i) => decE(e, `${at}[${i}]`)) : decE(x, at));
|
|
485
487
|
const encHelpful = (h, at) => clean({ when: h.when && encC(h.when, `${at}.when`), request: pairs(h.request, encE, `${at}.request`) });
|
|
486
488
|
const decHelpful = (x, at) => { const o = obj(x, at, ['request'], ['when']); return clean({ when: opt(o, 'when', decC, at), request: record(o.request, decE, `${at}.request`) }); };
|
|
489
|
+
const fairnessOf = (x, at) => (x === 'weak' || x === 'strong' ? x : fail(at, '"weak" or "strong"'));
|
|
487
490
|
const encLiveness = (l, at) => clean({ name: str(l.name, `${at}.name`), from: encC(l.from, `${at}.from`), to: encC(l.to, `${at}.to`), rank: encRank(l.rank, `${at}.rank`),
|
|
488
|
-
request: l.request && pairs(l.request, encE, `${at}.request`), helpful: l.helpful && l.helpful.map((h, i) => encHelpful(h, `${at}.helpful[${i}]`))
|
|
491
|
+
request: l.request && pairs(l.request, encE, `${at}.request`), helpful: l.helpful && l.helpful.map((h, i) => encHelpful(h, `${at}.helpful[${i}]`)),
|
|
492
|
+
fairness: l.fairness && fairnessOf(l.fairness, `${at}.fairness`), levels: l.levels && l.levels.map((n, i) => nat(n, `${at}.levels[${i}]`)) });
|
|
489
493
|
const decLiveness = (x, at) => {
|
|
490
|
-
const o = obj(x, at, ['name', 'from', 'to', 'rank'], ['request', 'helpful']);
|
|
494
|
+
const o = obj(x, at, ['name', 'from', 'to', 'rank'], ['request', 'helpful', 'fairness', 'levels']);
|
|
491
495
|
return clean({ name: str(o.name, `${at}.name`), from: decC(o.from, `${at}.from`), to: decC(o.to, `${at}.to`), rank: decRank(o.rank, `${at}.rank`),
|
|
492
|
-
request: opt(o, 'request', (y, a) => record(y, decE, a), at), helpful: opt(o, 'helpful', (y, a) => arr(y, a).map((h, i) => decHelpful(h, `${a}[${i}]`)), at)
|
|
496
|
+
request: opt(o, 'request', (y, a) => record(y, decE, a), at), helpful: opt(o, 'helpful', (y, a) => arr(y, a).map((h, i) => decHelpful(h, `${a}[${i}]`)), at),
|
|
497
|
+
fairness: opt(o, 'fairness', fairnessOf, at), levels: opt(o, 'levels', (y, a) => arr(y, a).map((n, i) => nat(n, `${a}[${i}]`)), at) });
|
|
493
498
|
};
|
|
494
499
|
const encLoop = (l, at) => clean({ name: str(l.name, `${at}.name`), params: strs(l.params, `${at}.params`), inputs: strs(l.inputs, `${at}.inputs`), state: pairs(l.state, encE, `${at}.state`),
|
|
495
500
|
while: encC(l.while, `${at}.while`), body: pairs(l.body, encE, `${at}.body`), pre: l.pre && encC(l.pre, `${at}.pre`), assume: l.assume && encC(l.assume, `${at}.assume`) });
|
|
@@ -595,15 +600,18 @@ export function toInterchange(c, meta) {
|
|
|
595
600
|
default: return fail('kind', `no kind ${JSON.stringify(c.kind)}`);
|
|
596
601
|
}
|
|
597
602
|
})();
|
|
598
|
-
|
|
603
|
+
const v11 = c.kind === 'liveness' && (c.liveness.fairness !== undefined || c.liveness.levels !== undefined);
|
|
604
|
+
return clean({ format: FORMAT, version: v11 ? '1.1' : '1.0', kind: c.kind, meta, columns: 'terms' in cols && cols.terms.length ? cols.terms : undefined, ...body });
|
|
599
605
|
}
|
|
600
606
|
// A document read back into the kernel's objects, or a FormatError saying where it leaves the format.
|
|
601
607
|
export function fromInterchange(doc) {
|
|
602
608
|
const head = isObj(doc) ? doc : fail('document', 'an object');
|
|
603
609
|
if (head.format !== FORMAT)
|
|
604
610
|
fail('format', `${JSON.stringify(FORMAT)}`);
|
|
605
|
-
if (head.version
|
|
606
|
-
fail('version',
|
|
611
|
+
if (!VERSIONS.includes(head.version))
|
|
612
|
+
fail('version', `one of ${VERSIONS.join(', ')} (this reader's)`);
|
|
613
|
+
if (head.version === '1.0' && head.kind === 'liveness' && isObj(head.liveness) && ('fairness' in head.liveness || 'levels' in head.liveness))
|
|
614
|
+
fail('liveness', 'no fairness or levels in a 1.0 document (1.1\'s)');
|
|
607
615
|
const kind = head.kind;
|
|
608
616
|
if (!KINDS.includes(kind))
|
|
609
617
|
fail('kind', `one of ${KINDS.join(', ')}`);
|
package/dist/kernel/cdcl.js
CHANGED
|
@@ -167,7 +167,8 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
167
167
|
const key = keyOf(lin);
|
|
168
168
|
if (!vars.has(key)) {
|
|
169
169
|
const flip = key !== canon(lin), stored = flip ? atomOf(lin, false).lin : lin, terms = Object.entries(stored).filter(([x0]) => x0 !== '1');
|
|
170
|
-
const x = { name: key, lin: stored, terms, col: terms.some(([x0]) => x0.startsWith('⟦')), id: byId.length, level: -1, at: -1, act: 0, phase: !flip
|
|
170
|
+
const x = { name: key, lin: stored, terms, col: terms.some(([x0]) => x0.startsWith('⟦')), quiet: undefined, id: byId.length, hp: undefined, cond: undefined, val: undefined, level: -1, reason: undefined, at: -1, act: 0, phase: !flip,
|
|
171
|
+
bj: undefined, bjAt: undefined, bsig: undefined, bver: undefined, sj: undefined, sx: undefined, pair: undefined, fs: undefined, aq: undefined, an: undefined };
|
|
171
172
|
byId.push(x);
|
|
172
173
|
vals.push(0);
|
|
173
174
|
rel.push(-1);
|
|
@@ -314,8 +315,10 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
314
315
|
if (vals[id])
|
|
315
316
|
activate(id);
|
|
316
317
|
};
|
|
318
|
+
// (its stack kept between calls: an assignment of a relevant variable calls it, and an array a call cost every one)
|
|
319
|
+
const todo = [];
|
|
317
320
|
const activate = (id0) => {
|
|
318
|
-
for (
|
|
321
|
+
for (todo.push(id0); todo.length;) {
|
|
319
322
|
const id = todo.pop(), own = ownBy[2 * id + (vals[id] === 1 ? 1 : 0)];
|
|
320
323
|
if (!own)
|
|
321
324
|
continue;
|
|
@@ -356,8 +359,10 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
356
359
|
lowAt = Math.min(lowAt, trail.length);
|
|
357
360
|
levels.length = l;
|
|
358
361
|
};
|
|
362
|
+
const undone = [];
|
|
359
363
|
const undoClausal = (l) => {
|
|
360
|
-
const keep = levels[l] ?? trail.length
|
|
364
|
+
const keep = levels[l] ?? trail.length;
|
|
365
|
+
undone.length = 0;
|
|
361
366
|
while (trail.length > keep) {
|
|
362
367
|
trail.pop();
|
|
363
368
|
const x = tv.pop(), q = x.aq;
|
|
@@ -568,13 +573,15 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
568
573
|
// is unit, its other watched pair's variable flipped, or, that pair holding too, a conflict.
|
|
569
574
|
const propagateClausal = () => {
|
|
570
575
|
// (each watch a clause and a blocker, a pair of it that, where it doesn't hold, satisfies the clause untouched)
|
|
576
|
+
// (holds and opposed read inline: vals[c >> 1] is 2 − (c & 1) where pair c holds, 1 + (c & 1) where it's opposed)
|
|
571
577
|
while (qhead < trail.length) {
|
|
572
578
|
const x = tv[qhead++], code = 2 * x.id + (x.val ? 1 : 0), ws = wl[code];
|
|
573
579
|
if (!ws)
|
|
574
580
|
continue;
|
|
575
581
|
let n = 0;
|
|
576
582
|
for (let i = 0; i < ws.length;) {
|
|
577
|
-
|
|
583
|
+
const blocker = ws[i + 1];
|
|
584
|
+
if (vals[blocker >> 1] === 1 + (blocker & 1)) {
|
|
578
585
|
i += 2;
|
|
579
586
|
continue;
|
|
580
587
|
}
|
|
@@ -591,15 +598,20 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
591
598
|
c[1] = code;
|
|
592
599
|
}
|
|
593
600
|
const o = c[0];
|
|
594
|
-
if (
|
|
601
|
+
if (vals[o >> 1] === 1 + (o & 1)) {
|
|
595
602
|
ws[i + 1] = o;
|
|
596
603
|
i += 2;
|
|
597
604
|
continue;
|
|
598
605
|
}
|
|
599
606
|
let j = 2;
|
|
600
|
-
|
|
607
|
+
const len = c.length;
|
|
608
|
+
while (j < len) {
|
|
609
|
+
const z = c[j];
|
|
610
|
+
if (vals[z >> 1] !== 2 - (z & 1))
|
|
611
|
+
break;
|
|
601
612
|
j++;
|
|
602
|
-
|
|
613
|
+
}
|
|
614
|
+
if (j < len) {
|
|
603
615
|
const z = c[j];
|
|
604
616
|
c[j] = code;
|
|
605
617
|
c[1] = z;
|
|
@@ -610,7 +622,7 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
610
622
|
continue;
|
|
611
623
|
}
|
|
612
624
|
if (!vals[o >> 1]) {
|
|
613
|
-
|
|
625
|
+
assignClausal(byId[o >> 1], !(o & 1), ci);
|
|
614
626
|
i += 2;
|
|
615
627
|
continue;
|
|
616
628
|
}
|
|
@@ -694,8 +706,13 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
694
706
|
}, ms => { st.coreMs += ms; });
|
|
695
707
|
// The clausal mode's conflict analysis: the same resolutions, in one pass down the trail (the clause kept as it is
|
|
696
708
|
// resolved, its literals at its latest level counted, each step the latest of them on the trail).
|
|
709
|
+
// (whether a variable is in the clause being resolved: its stamp `an` this call's, so the walk down the trail reads
|
|
710
|
+
// each variable once, not the clause's map by its name)
|
|
711
|
+
let anN = 0;
|
|
697
712
|
const analyzeClausal = (c) => {
|
|
698
|
-
const lits = new Map(c.lits);
|
|
713
|
+
const lits = new Map(c.lits), an = ++anN;
|
|
714
|
+
for (const name of lits.keys())
|
|
715
|
+
vars.get(name).an = an;
|
|
699
716
|
let node = c.node, { top, here } = levelsOf(c), p = trail.length - 1;
|
|
700
717
|
if (top < level()) {
|
|
701
718
|
undoTo(top);
|
|
@@ -703,9 +720,9 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
703
720
|
p = trail.length - 1;
|
|
704
721
|
}
|
|
705
722
|
while (lits.size && !(top > 0 && here === 1)) {
|
|
706
|
-
while (p >= 0 && !(
|
|
723
|
+
while (p >= 0 && !(tv[p].an === an && tv[p].level === top))
|
|
707
724
|
p--;
|
|
708
|
-
const name = trail[p], x =
|
|
725
|
+
const name = trail[p], x = tv[p];
|
|
709
726
|
if (top > 0 && x.reason === undefined)
|
|
710
727
|
break;
|
|
711
728
|
const r = clauses[x.reason];
|
|
@@ -715,11 +732,14 @@ export function cdclSession(goal, root, opts = {}) {
|
|
|
715
732
|
st.resolved++;
|
|
716
733
|
node = nodes.length - 1;
|
|
717
734
|
lits.delete(name);
|
|
735
|
+
x.an = 0;
|
|
718
736
|
here--;
|
|
719
737
|
for (const [w, q] of r.lits)
|
|
720
738
|
if (w !== name && !lits.has(w)) {
|
|
739
|
+
const y = vars.get(w);
|
|
721
740
|
lits.set(w, q);
|
|
722
|
-
|
|
741
|
+
y.an = an;
|
|
742
|
+
if (y.level === top)
|
|
723
743
|
here++;
|
|
724
744
|
}
|
|
725
745
|
}
|
package/dist/kernel/reader.js
CHANGED
|
@@ -388,9 +388,10 @@ export class Reader {
|
|
|
388
388
|
out.push({ lin: row.lin, w: join(row.w, closed.w), label: '' });
|
|
389
389
|
// (the last open part's own value is a read: open while it is)
|
|
390
390
|
const last = this.truth(open[0]);
|
|
391
|
-
// (and the facts are kept only while the part's own value is: its reason is theirs, though not their rows'
|
|
391
|
+
// (and the facts are kept only while the part's own value is: its reason is theirs, though not their rows'; and
|
|
392
|
+
// while the closed parts' are: one closed through an open term column opens when the column's choice is decided)
|
|
392
393
|
const x = both(both(closed, r), last);
|
|
393
|
-
return { w: x.w, pos: x.pos, fin:
|
|
394
|
+
return { w: x.w, pos: x.pos, fin: x.fin && last.t !== undefined };
|
|
394
395
|
}
|
|
395
396
|
case '<':
|
|
396
397
|
case '<=':
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gdp-wired",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.44.0",
|
|
4
4
|
"description": "An automatic prover for stateful rules (budgets, caps, windows, workflows, policies): laws proven with no proof to write, checked again in Lean, counterexamples found on the GPU, the rule shipped as code",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"verification",
|
|
@@ -140,6 +140,10 @@
|
|
|
140
140
|
"types": "./dist/core/extract-go.d.ts",
|
|
141
141
|
"default": "./dist/core/extract-go.js"
|
|
142
142
|
},
|
|
143
|
+
"./extract-sol": {
|
|
144
|
+
"types": "./dist/core/extract-sol.d.ts",
|
|
145
|
+
"default": "./dist/core/extract-sol.js"
|
|
146
|
+
},
|
|
143
147
|
"./cli": {
|
|
144
148
|
"types": "./dist/core/cli.d.ts",
|
|
145
149
|
"default": "./dist/core/cli.js"
|
|
@@ -152,10 +156,15 @@
|
|
|
152
156
|
"types": "./dist/core/relational.d.ts",
|
|
153
157
|
"default": "./dist/core/relational.js"
|
|
154
158
|
},
|
|
159
|
+
"./interchange": {
|
|
160
|
+
"types": "./dist/interchange/check.d.ts",
|
|
161
|
+
"default": "./dist/interchange/check.js"
|
|
162
|
+
},
|
|
155
163
|
"./package.json": "./package.json"
|
|
156
164
|
},
|
|
157
165
|
"bin": {
|
|
158
|
-
"gdp-wired": "dist/core/cli.js"
|
|
166
|
+
"gdp-wired": "dist/core/cli.js",
|
|
167
|
+
"gdp-wired-check": "dist/interchange/cli.js"
|
|
159
168
|
},
|
|
160
169
|
"files": [
|
|
161
170
|
"dist",
|
|
@@ -185,7 +194,7 @@
|
|
|
185
194
|
"prepublishOnly": "bun scripts/build.ts",
|
|
186
195
|
"smoke": "sh scripts/smoke.sh",
|
|
187
196
|
"bar": "bun gates/bar.ts",
|
|
188
|
-
"test": "bun scripts/gen-lean-library.ts --check && cd core && bun test exports.test.ts cli.test.ts solver.test.ts dsl.test.ts sums.test.ts arith.test.ts conformance.test.ts compose.test.ts relational.test.ts quantifiers.test.ts functions.test.ts keyterms.test.ts lists.test.ts liveness.test.ts sizes.test.ts values.test.ts rationals.test.ts builders.test.ts gdp.test.ts datatypes.test.ts lemmas.test.ts discover.test.ts infer.test.ts cyclic.test.ts cycles.test.ts nonterm.test.ts data.test.ts hypothesis.test.ts seqs.test.ts abstract.test.ts search.test.ts invoices.test.ts folds.test.ts trees.test.ts pairs.test.ts chart.test.ts xstate.test.ts extract.test.ts effect.test.ts effect-schedule.test.ts effect-stm.test.ts && cd ../kernel && bun test tamper.test.ts refusals.test.ts steplaw.test.ts sets.test.ts cdcl.test.ts && cd ../examples && bun test examples.test.ts && cd .. && bun examples/readme.ts && bun examples/guide.ts && bun examples/composition.ts && bun examples/sets.ts && bun examples/quantifiers.ts && bun examples/functions.ts && bun examples/datatypes.ts && bun examples/lemmas.ts && bun examples/discover.ts && bun examples/invoices.ts && bun examples/folds.ts && bun examples/trees.ts && bun examples/pairs.ts && bun examples/groups.ts && bun examples/charts.ts && bun examples/xstate.ts && bun examples/effect.ts && bun examples/effect-retry.ts && bun examples/effect-stm.ts && bun examples/infer.ts && bun examples/arith.ts && bun examples/cyclic.ts && bun examples/cycles.ts && bun examples/data.ts && bun examples/abstract.ts && bun test compare/tip/translate.test.ts && bun examples/scopes.ts && bun examples/lists.ts && bun examples/sizes.ts && bun examples/liveness.ts && bun examples/sums.ts && bun examples/nonterm.ts && bun examples/rationals.ts && bun examples/budget.ts && bun examples/gdp.ts && bun examples/steps.ts && bun examples/jev-fabric/run.ts"
|
|
197
|
+
"test": "bun scripts/gen-lean-library.ts --check && cd core && bun test exports.test.ts cli.test.ts solver.test.ts rand.test.ts dsl.test.ts sums.test.ts arith.test.ts conformance.test.ts compose.test.ts relational.test.ts quantifiers.test.ts functions.test.ts keyterms.test.ts lists.test.ts liveness.test.ts sizes.test.ts values.test.ts rationals.test.ts builders.test.ts gdp.test.ts datatypes.test.ts lemmas.test.ts discover.test.ts infer.test.ts cyclic.test.ts cycles.test.ts nonterm.test.ts data.test.ts hypothesis.test.ts seqs.test.ts abstract.test.ts search.test.ts invoices.test.ts folds.test.ts trees.test.ts pairs.test.ts chart.test.ts xstate.test.ts extract.test.ts effect.test.ts effect-schedule.test.ts effect-stm.test.ts effect-queue.test.ts && cd ../kernel && bun test tamper.test.ts refusals.test.ts steplaw.test.ts sets.test.ts cdcl.test.ts && cd ../examples && bun test examples.test.ts && cd .. && bun examples/readme.ts && bun examples/guide.ts && bun examples/composition.ts && bun examples/sets.ts && bun examples/quantifiers.ts && bun examples/functions.ts && bun examples/datatypes.ts && bun examples/lemmas.ts && bun examples/discover.ts && bun examples/invoices.ts && bun examples/folds.ts && bun examples/trees.ts && bun examples/pairs.ts && bun examples/groups.ts && bun examples/charts.ts && bun examples/xstate.ts && bun examples/effect.ts && bun examples/effect-retry.ts && bun examples/effect-stm.ts && bun examples/effect-queue.ts && bun examples/infer.ts && bun examples/arith.ts && bun examples/cyclic.ts && bun examples/cycles.ts && bun examples/data.ts && bun examples/abstract.ts && bun test compare/tip/translate.test.ts && bun examples/scopes.ts && bun examples/lists.ts && bun examples/sizes.ts && bun examples/liveness.ts && bun examples/sums.ts && bun examples/nonterm.ts && bun examples/rationals.ts && bun examples/budget.ts && bun examples/gdp.ts && bun examples/steps.ts && bun examples/jev-fabric/run.ts"
|
|
189
198
|
},
|
|
190
199
|
"devDependencies": {
|
|
191
200
|
"@gdp-ts/core": "0.1.0",
|