gdp-wired 0.43.0 → 0.45.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/c/reader.js +22 -7
- package/dist/core/check.js +3 -2
- package/dist/core/cli.d.ts +7 -0
- package/dist/core/cli.js +184 -12
- package/dist/core/counts.d.ts +1 -1
- package/dist/core/counts.js +30 -12
- package/dist/core/data.d.ts +6 -1
- package/dist/core/data.js +894 -152
- package/dist/core/dsl.d.ts +2 -0
- package/dist/core/dsl.js +88 -10
- 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/ex/reader.exs +17 -1
- package/dist/core/exists.d.ts +15 -1
- package/dist/core/exists.js +263 -41
- package/dist/core/extract-c.d.ts +2 -0
- package/dist/core/extract-c.js +22 -13
- package/dist/core/extract-check.d.ts +7 -0
- package/dist/core/extract-check.js +57 -4
- package/dist/core/extract-ex.js +5 -5
- package/dist/core/extract-go-check.js +22 -17
- package/dist/core/extract-go.d.ts +3 -0
- package/dist/core/extract-go.js +24 -9
- package/dist/core/extract-jvm.js +68 -16
- package/dist/core/extract-print.js +3 -0
- package/dist/core/extract-py.js +5 -5
- package/dist/core/extract-rb.js +5 -5
- package/dist/core/extract-read.d.ts +8 -0
- package/dist/core/extract-read.js +55 -0
- package/dist/core/extract-rs.js +28 -25
- package/dist/core/extract-shapes.js +20 -0
- package/dist/core/extract-sol.js +23 -12
- package/dist/core/extract-step.d.ts +59 -3
- package/dist/core/extract-step.js +334 -64
- package/dist/core/extract-swift.js +22 -15
- package/dist/core/extract.d.ts +1 -0
- package/dist/core/extract.js +27 -2
- package/dist/core/fresh.d.ts +2 -2
- package/dist/core/fresh.js +7 -3
- package/dist/core/go/reader.go +7 -1
- package/dist/core/infer.js +113 -40
- package/dist/core/jvm/Harness.java +8 -1
- package/dist/core/jvm/JavaReader.java +10 -2
- package/dist/core/jvm/Jvm.java +18 -2
- package/dist/core/jvm/KtReader.java +60 -5
- package/dist/core/machine.d.ts +2 -0
- package/dist/core/machine.js +32 -6
- package/dist/core/py/harness.py +128 -24
- package/dist/core/py/reader.py +50 -5
- package/dist/core/rb/reader.rb +52 -5
- package/dist/core/rs/src/main.rs +10 -0
- package/dist/core/sol/Replay.sol +52 -0
- package/dist/core/sol/harness.py +511 -0
- package/dist/core/solver.js +5 -4
- package/dist/core/system.d.ts +62 -1
- package/dist/core/system.js +274 -6
- package/dist/core/transfer.js +17 -0
- package/dist/core/watch.js +1 -1
- package/dist/interchange/check.d.ts +18 -1
- package/dist/interchange/check.js +19 -12
- package/dist/interchange/cli.d.ts +2 -0
- package/dist/interchange/cli.js +45 -0
- package/dist/interchange/format.d.ts +5 -1
- package/dist/interchange/format.js +25 -9
- package/dist/kernel/cdcl.js +65 -14
- package/dist/kernel/epr.js +35 -5
- package/dist/kernel/kernel.d.ts +2 -0
- package/dist/kernel/kernel.js +67 -40
- package/dist/kernel/prove.d.ts +22 -0
- package/dist/kernel/prove.js +156 -7
- package/dist/kernel/reader.js +3 -2
- package/dist/lean-kernel/emit.d.ts +9 -3
- package/dist/lean-kernel/emit.js +170 -29
- package/dist/lean-kernel/library.js +1 -1
- package/package.json +12 -3
package/dist/core/system.js
CHANGED
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
import { all, any, atMost, get, ite, n, not, plus, same, x } from "./machine.js";
|
|
20
20
|
import { substC, substE } from "../kernel/kernel.js";
|
|
21
21
|
import { Cond, Term, nat, oneOf, rule } from "./dsl.js";
|
|
22
|
+
import { interpret } from "./machine.js";
|
|
23
|
+
import { allowed, watch } from "./watch.js";
|
|
22
24
|
const models = new WeakMap();
|
|
23
25
|
const modelled = (m, ...ms) => { models.set(m, [...(models.get(m) ?? []), ...ms]); return m; };
|
|
24
26
|
// m made from `from`: the models it assumes, and the scalars it keeps shared (`sharedOf`), carried over.
|
|
@@ -153,9 +155,18 @@ export function asRule(m, kinds = {}) {
|
|
|
153
155
|
r = r.params(Object.fromEntries(m.params.map(p => [p, kindOf(p)])));
|
|
154
156
|
if (m.inputs.length)
|
|
155
157
|
r = r.inputs(Object.fromEntries(m.inputs.map(i => [i, kindOf(i)])));
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
158
|
+
// (a state variable given an integer's kind, x beside x$neg as Int keeps one, is that integer to the laws: both start at
|
|
159
|
+
// constants)
|
|
160
|
+
const ints = Object.keys(m.state).filter(v => kinds[v] && `${v}$neg` in m.state && m.state[v].op === 'const' && m.state[`${v}$neg`].op === 'const');
|
|
161
|
+
const at = (v) => m.state[v].value;
|
|
162
|
+
r = r.state({ ...mapValues(Object.fromEntries(Object.entries(m.state).filter(([v]) => !ints.some(i => v === i || v === `${i}$neg`))), e => (e.op === 'const' ? e.value : () => new Term(e))),
|
|
163
|
+
...Object.fromEntries(ints.map(v => [v, kinds[v].from(at(v) - at(`${v}$neg`))])) });
|
|
164
|
+
// (a map given a kind of cells, its parts as the machine has them (m.has, m.value), is those cells to the laws)
|
|
165
|
+
const cells = Object.entries(kinds).filter(([n, k]) => k.vars(n).length > 1 && k.vars(n).every(p => p in (m.maps ?? {})));
|
|
166
|
+
const parts = new Set(cells.flatMap(([n, k]) => k.vars(n)));
|
|
167
|
+
const plainMaps = Object.fromEntries(Object.entries(m.maps ?? {}).filter(([n]) => !parts.has(n)));
|
|
168
|
+
if (Object.keys(plainMaps).length || cells.length)
|
|
169
|
+
r = r.maps({ ...plainMaps, ...Object.fromEntries(cells.map(([n, k]) => [n, k.from(k.decode(n, Object.fromEntries(k.vars(n).map(p => [p, m.maps[p]]))))])) });
|
|
159
170
|
if (m.step.flags && Object.keys(m.step.flags).length)
|
|
160
171
|
r = r.flags(() => mapValues(m.step.flags, c => new Cond(c)));
|
|
161
172
|
r = r.step(() => ({ ...mapValues(m.step.state, e => new Term(e)), ...mapValues(m.step.maps, (w, map) => ({ map, ...w })) }));
|
|
@@ -189,7 +200,7 @@ function writesWhen(v, cell) {
|
|
|
189
200
|
return xs.length ? any(...xs) : false;
|
|
190
201
|
}
|
|
191
202
|
// m's one step (a request's) as a transaction of several: `pc$` 0 begins it (the request's inputs kept as in$<input>),
|
|
192
|
-
// then the reads (read committed: each store read site at its own step, inner ones first, as rd$<i
|
|
203
|
+
// then the reads (read committed: each store read site at its own step, inner ones first, as rd$<i>, a record's parts at one key one step; snapshot: all at
|
|
193
204
|
// the begin), then the commit, which computes m's step from what was read and writes it (snapshot: unless a cell it
|
|
194
205
|
// writes moved since the begin, aborted$ then 1), then done. m's scalars are the request's own (a result, a flag); its
|
|
195
206
|
// maps are the stores. 'atomic' is m itself. Each step reads only its own process's state and the stores, so
|
|
@@ -282,7 +293,9 @@ export function isolation(m, level) {
|
|
|
282
293
|
return c;
|
|
283
294
|
return { ...c, a: sigma(c.a), b: sigma(c.b) };
|
|
284
295
|
};
|
|
285
|
-
|
|
296
|
+
// (a record's parts at one key are one read: one GET returns the record)
|
|
297
|
+
const groupOf = (st) => `${st.map.replace(/\.[^.]*$/, '')}|${JSON.stringify(st.key)}`, groups = [...new Set(sites.map(groupOf))], gi = (j) => groups.indexOf(groupOf(sites[j]));
|
|
298
|
+
const r = groups.length, snap = level === 'snapshot';
|
|
286
299
|
const commit = snap ? 1 : r + 1, done = commit + 1;
|
|
287
300
|
const at = (k) => same(x('pc$'), n(k));
|
|
288
301
|
const valid = snap ? all(...pointWrites.map(w => { const on = writesWhen(w.value, get(w.map, w.key)); const cell = get(w.map, sigma(w.key)), was = sigma(get(w.map, w.key)); return on === false ? same(n(0), n(0)) : any(...(on === true ? [] : [not(sigmaC(on))]), same(cell, was)); })) : undefined;
|
|
@@ -291,7 +304,7 @@ export function isolation(m, level) {
|
|
|
291
304
|
const state = {
|
|
292
305
|
'pc$': ite(at(0), n(snap || !r ? commit : 1), ite(at(commit), n(done), reads)),
|
|
293
306
|
...Object.fromEntries(m.inputs.map(i => [inp(i), ite(at(0), x(i), x(inp(i)))])),
|
|
294
|
-
...Object.fromEntries(sites.map((s, j) => [rd(j), ite(at(snap ? 0 : j + 1), snap ? s.e : get(s.map, sigma(s.key)), x(rd(j)))])),
|
|
307
|
+
...Object.fromEntries(sites.map((s, j) => [rd(j), ite(at(snap ? 0 : gi(j) + 1), snap ? s.e : get(s.map, sigma(s.key)), x(rd(j)))])),
|
|
295
308
|
...mapValues(m.step.state, (e, s) => ite(commits, sigma(e), x(s))),
|
|
296
309
|
...(snap ? { 'aborted$': ite(at(commit), valid.op === 'and' && !valid.xs.length ? n(0) : ite(valid, n(0), n(1)), x('aborted$')) } : {}),
|
|
297
310
|
};
|
|
@@ -309,8 +322,11 @@ export function isolation(m, level) {
|
|
|
309
322
|
...(m.assume ? { assume: any(not(at(0)), m.assume) } : {}),
|
|
310
323
|
...(m.pre ? { pre: m.pre } : {}),
|
|
311
324
|
};
|
|
325
|
+
readsOf.set(out, groups.map(g => g.slice(0, g.indexOf('|'))));
|
|
312
326
|
return from(out, m, ISOLATION[level]);
|
|
313
327
|
}
|
|
328
|
+
// The stores a transaction reads, one per read step (read committed's; snapshot's are all at its begin).
|
|
329
|
+
export const readsOf = new WeakMap();
|
|
314
330
|
export const DELIVERY = {
|
|
315
331
|
'exactly-once': { name: 'exactly-once delivery', assumes: 'a message is taken by one handler step, once, and the take commits with the handler\'s writes (a transactional consume, an inbox row in the same transaction)',
|
|
316
332
|
checked: 'a transactional consume (Kafka transactions, an inbox row in the handler\'s transaction)' },
|
|
@@ -424,3 +440,255 @@ export function expires(cells, at, opts = {}) {
|
|
|
424
440
|
sharedOf.set(m, [now]);
|
|
425
441
|
return modelled(m, TTL);
|
|
426
442
|
}
|
|
443
|
+
const WORDS = [
|
|
444
|
+
[/^(atomic|serializable|lua|one step|locked|for update)$/, e => { e.isolation = 'atomic'; }],
|
|
445
|
+
[/^read committed$/, e => { e.isolation = 'read committed'; }],
|
|
446
|
+
[/^(snapshot|repeatable read)$/, e => { e.isolation = 'snapshot'; }],
|
|
447
|
+
[/^(keys expire|expiry|ttl|eviction|keys evicted)$/, e => { e.expiry = true; }],
|
|
448
|
+
[/^(retries|retried|at-least-once|at least once|redelivery|duplicates)$/, e => { e.retries = true; }],
|
|
449
|
+
[/^(an object per call|objects apart|a process per call|one object per call)$/, e => { e.apart = true; }],
|
|
450
|
+
];
|
|
451
|
+
export function envOf(text) {
|
|
452
|
+
const e = {};
|
|
453
|
+
for (const w of (Array.isArray(text) ? text : [text]).flatMap(t => t.split(/\s*[,;]\s*|\s+and\s+/)).map(w => w.trim().replace(/\s+/g, ' ')).filter(Boolean)) {
|
|
454
|
+
// (a call's flow: its methods in order, `acquire then release`)
|
|
455
|
+
if (/^[\w.]+( then [\w.]+)+$/.test(w)) {
|
|
456
|
+
e.flow = w.split(' then ');
|
|
457
|
+
continue;
|
|
458
|
+
}
|
|
459
|
+
const f = WORDS.find(([re]) => re.test(w.toLowerCase()));
|
|
460
|
+
if (!f)
|
|
461
|
+
throw new Error(`env: ${JSON.stringify(w)} is not an environment gdp-wired models (atomic, read committed, snapshot, keys expire, retries, a flow: <method> then <method>)`);
|
|
462
|
+
f[1](e);
|
|
463
|
+
}
|
|
464
|
+
return e;
|
|
465
|
+
}
|
|
466
|
+
export const envText = (e) => [e.isolation, e.expiry && 'keys expire', e.retries && 'retries', e.apart && 'an object per call', e.flow?.join(' then ')].filter(Boolean).join(', ');
|
|
467
|
+
export function inEnv(r, env, o = {}) {
|
|
468
|
+
let m = machineOf(r);
|
|
469
|
+
const level = env.isolation ?? 'atomic', split = level !== 'atomic', flow = env.flow, lifted = split || !!flow, P = 'calls', act = 'act$', id = 'p$';
|
|
470
|
+
const stores = o.stores ?? [], own = [...(o.own ?? [])], hk = {};
|
|
471
|
+
if (flow) {
|
|
472
|
+
const k = flow.length;
|
|
473
|
+
const is = (f) => {
|
|
474
|
+
if (!o.method) {
|
|
475
|
+
if (k > 1)
|
|
476
|
+
throw new Error(`a flow of ${k} methods, and the rule has one`);
|
|
477
|
+
return same(n(0), n(0));
|
|
478
|
+
}
|
|
479
|
+
const i = o.method.values.indexOf(f);
|
|
480
|
+
if (i < 0)
|
|
481
|
+
throw new Error(`${f} is no method of ${m.name} (${o.method.values.join(', ')})`);
|
|
482
|
+
return same(x(o.method.name), n(i));
|
|
483
|
+
};
|
|
484
|
+
// (a method done: not failed, and where its result says whether it did it, that result true)
|
|
485
|
+
const failedOk = o.failed && m.step.state?.[o.failed] ? [same(m.step.state[o.failed], n(0))] : [];
|
|
486
|
+
const oks = (o.oks ?? []).filter(r => flow.includes(r.method) && m.step.state?.[r.rule]).map(r => any(not(is(r.method)), not(same(m.step.state[r.rule], n(0)))));
|
|
487
|
+
const done = failedOk.length || oks.length ? all(...failedOk, ...oks) : undefined, stage = x('stage$');
|
|
488
|
+
for (const [map, w] of Object.entries(m.step.maps ?? {}))
|
|
489
|
+
if ('key' in w)
|
|
490
|
+
hk[map] = `hk$${map}`;
|
|
491
|
+
m = { ...m, state: { ...m.state, 'stage$': n(0), 'held$': n(0), ...Object.fromEntries(Object.values(hk).map(h => [h, n(0)])) },
|
|
492
|
+
step: { ...m.step, state: { ...m.step.state,
|
|
493
|
+
'stage$': done ? ite(done, plus(stage, n(1)), n(k)) : plus(stage, n(1)),
|
|
494
|
+
'held$': ite(all(is(flow[0]), ...(done ? [done] : [])), n(1), ite(is(flow[k - 1]), n(0), x('held$'))),
|
|
495
|
+
...Object.fromEntries(Object.entries(hk).map(([map, h]) => [h, ite(is(flow[0]), m.step.maps[map].key, x(h))])) } },
|
|
496
|
+
assume: all(...(m.assume ? [m.assume] : []), atMost(plus(stage, n(1)), n(k)), any(...flow.map((f, j) => all(same(stage, n(j)), is(f))))) };
|
|
497
|
+
// (an argument of one name, kept from the first method of the flow that takes it, its later methods given the same)
|
|
498
|
+
const named = new Map();
|
|
499
|
+
for (const a of o.args ?? [])
|
|
500
|
+
if (flow.includes(a.method) && m.inputs.includes(a.rule))
|
|
501
|
+
named.set(a.code, [...(named.get(a.code) ?? []), a]);
|
|
502
|
+
const keeps = [];
|
|
503
|
+
for (const [code, as] of named) {
|
|
504
|
+
const sorted = [...as].sort((a, b) => flow.indexOf(a.method) - flow.indexOf(b.method)), first = sorted[0], kept = `arg$${code}`;
|
|
505
|
+
if (sorted.length < 2 || kept in m.state)
|
|
506
|
+
continue;
|
|
507
|
+
keeps.push(kept);
|
|
508
|
+
m = { ...m, state: { ...m.state, [kept]: n(0) }, step: { ...m.step, state: { ...m.step.state, [kept]: ite(is(first.method), x(first.rule), x(kept)) } },
|
|
509
|
+
assume: all(m.assume, ...sorted.slice(1).map(a => any(not(is(a.method)), same(x(a.rule), x(kept))))) };
|
|
510
|
+
}
|
|
511
|
+
own.push('stage$', 'held$', ...Object.values(hk), ...keeps);
|
|
512
|
+
// (atomic: the calls holding each key, counted in the step that takes or gives it up, so the law is about every key)
|
|
513
|
+
const rk = Object.values(m.step.maps ?? {}).find((w) => 'key' in w)?.key;
|
|
514
|
+
if (!split && rk) {
|
|
515
|
+
const d = get('done$', rk), took = all(is(flow[0]), ...(done ? [done] : [])), gave = k > 1 ? all(is(flow[k - 1]), same(x('held$'), n(1))) : same(n(0), n(1));
|
|
516
|
+
m = { ...m, maps: { ...m.maps, 'done$': 0 }, step: { ...m.step, maps: { ...m.step.maps, 'done$': { key: rk, value: ite(took, plus(d, n(1)), ite(gave, { op: 'sub', a: d, b: n(1) }, d)) } } } };
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
// (an object per call: the fields its methods write are the call's own, those it only reads the object's as made)
|
|
520
|
+
if (env.apart)
|
|
521
|
+
own.push(...Object.keys(m.state).filter(s => !own.includes(s) && m.step.state?.[s] && JSON.stringify(m.step.state[s]) !== JSON.stringify(x(s))));
|
|
522
|
+
// (a field a call writes is read where the call commits, not where the code reads it: refused at a split level)
|
|
523
|
+
const fields = Object.keys(m.state).filter(s => !own.includes(s)), written = fields.filter(s => m.step.state?.[s] && JSON.stringify(m.step.state[s]) !== JSON.stringify(x(s)));
|
|
524
|
+
if (split && written.length)
|
|
525
|
+
throw new Error(`a call writes the object's ${written.join(', ')}, which it reads at its commit only here: not modelled at ${level}`);
|
|
526
|
+
const h = isolation(m, level);
|
|
527
|
+
const commit = split ? (level === 'snapshot' ? 1 : readsOf.get(h).length + 1) : undefined;
|
|
528
|
+
// (a flow's call begins its next method after a commit)
|
|
529
|
+
if (flow && split)
|
|
530
|
+
h.step.state['pc$'] = ite(same(x('pc$'), n(commit)), n(0), h.step.state['pc$']);
|
|
531
|
+
const parts = { [P]: lifted ? { rule: h, id, shared: fields } : h };
|
|
532
|
+
if (env.expiry)
|
|
533
|
+
stores.forEach((cells, i) => {
|
|
534
|
+
const e = expiry(Object.fromEntries(cells.map(c => [c, m.maps[c]])), 'key$'), mine = cells.filter(c => hk[c]);
|
|
535
|
+
// (a lease runs out: the calls holding by the key expired hold no longer; a call's done work, a flow of one method, stays done)
|
|
536
|
+
if (mine.length && flow.length > 1) {
|
|
537
|
+
e.maps = { ...e.maps, 'held$': 0, ...Object.fromEntries(mine.map(c => [hk[c], 0])) };
|
|
538
|
+
e.step.maps['held$'] = { each: 'q$', value: ite(any(...mine.map(c => same(get(hk[c], x('q$')), x('key$')))), n(0), get('held$', x('q$'))) };
|
|
539
|
+
if ('done$' in (m.maps ?? {})) {
|
|
540
|
+
e.maps['done$'] = 0;
|
|
541
|
+
e.step.maps['done$'] = { key: x('key$'), value: n(0) };
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
parts[`expiry${stores.length > 1 ? i : ''}`] = e;
|
|
545
|
+
});
|
|
546
|
+
const sys = system(`${machineOf(r).name} (${envText(env) || 'atomic'})`, parts, { act });
|
|
547
|
+
const ms = [...modelsOf(sys), ...(env.retries ? [RETRIES] : [])];
|
|
548
|
+
models.set(sys, ms);
|
|
549
|
+
const locals = Object.keys(m.state).filter(s => own.includes(s)), on = same(x(act), n(0));
|
|
550
|
+
const flags = () => Object.fromEntries(Object.keys(m.step.flags ?? {}).map(g => [g, { op: 'flag', name: `${P}$${g}` }]));
|
|
551
|
+
// (a call's own: its locals at its process `at`, before and after; its request as the call kept it)
|
|
552
|
+
const mine = (at, before) => {
|
|
553
|
+
const vs = [...locals.flatMap((s) => [[s, get(s, at)], [`${s}'`, get(`${s}'`, at)]]), ...(before && split ? m.inputs.map((i) => [i, get(`in$${i}`, at)]) : [])];
|
|
554
|
+
return { vars: lifted ? Object.fromEntries(vs) : {}, maps: {}, flags: flags() };
|
|
555
|
+
};
|
|
556
|
+
const law = (l) => {
|
|
557
|
+
if (!lifted || !locals.some(s => JSON.stringify(l.holds).includes(`"name":"${s}"`)))
|
|
558
|
+
return l;
|
|
559
|
+
const k = 'p$k', holds = substC(l.holds, mine(x(k), false));
|
|
560
|
+
return l.forall ? { ...l, holds, keys: [...(l.keys ?? []), k] } : { ...l, holds, forall: k };
|
|
561
|
+
};
|
|
562
|
+
const step = (s) => {
|
|
563
|
+
if ((s.steps ?? 1) !== 1)
|
|
564
|
+
throw new Error(`env: a law of ${s.steps} steps is not lifted to every call at once`);
|
|
565
|
+
const sub = mine(x(id), true), whens = s.when === undefined ? [] : Array.isArray(s.when) ? s.when : [s.when];
|
|
566
|
+
const then = substC(s.then, sub);
|
|
567
|
+
return { ...s, then: level === 'snapshot' ? any(same(get("aborted$'", x(id)), n(1)), then) : then,
|
|
568
|
+
when: all(on, ...(split ? [same(get('pc$', x(id)), n(commit))] : []), ...whens.map(w => substC(w, sub))) };
|
|
569
|
+
};
|
|
570
|
+
const between = (name, a, b) => {
|
|
571
|
+
if (!flow || flow[0] !== a || flow.at(-1) !== b)
|
|
572
|
+
throw new Error(`between ${a} and ${b}: the call's flow is ${flow ? flow.join(' then ') : 'not stated'} (env: ${a} then ${b})`);
|
|
573
|
+
if (!split && 'done$' in (m.maps ?? {}))
|
|
574
|
+
return { name, holds: atMost(get('done$', x('k$d')), n(1)), forall: 'k$d' };
|
|
575
|
+
const held = (p) => same(get('held$', x(p)), n(1));
|
|
576
|
+
// (per lock: two calls holding by different keys hold different things)
|
|
577
|
+
return { name, holds: any(not(held('p$a')), not(held('p$b')), same(x('p$a'), x('p$b')), ...Object.values(hk).map(k => not(same(get(k, x('p$a')), get(k, x('p$b')))))), forall: 'p$a', keys: ['p$b'] };
|
|
578
|
+
};
|
|
579
|
+
return { rule: sys, models: ms, reads: split && level !== 'snapshot' ? readsOf.get(h) : [], part: P, act, ...(lifted ? { id } : {}), ...(split ? { commit } : {}), level, ...(flow ? { flow } : {}), ...(o.method ? { method: o.method.name, methods: o.method.values.length } : {}), law, step, between };
|
|
580
|
+
}
|
|
581
|
+
// A run that breaks a law, shortened: steps dropped one at a time while the rest still breaks it (replayed on the
|
|
582
|
+
// interpreter, each request allowed where it is taken, the law read as the search reads it), cut at the first break.
|
|
583
|
+
export function shrinkRun(r, w, run) {
|
|
584
|
+
const m = machineOf(r), rt = interpret(m), params = run.params;
|
|
585
|
+
const bound = 2 + Math.max(0, ...[...Object.values(params), ...run.trace.flatMap(q => Object.values(q))].filter((v) => typeof v === 'number'));
|
|
586
|
+
// (the length of the prefix that breaks it, or 0)
|
|
587
|
+
const breaks = (trace) => {
|
|
588
|
+
try {
|
|
589
|
+
const on = watch(m, rt, w, params, bound);
|
|
590
|
+
let st = rt.init(params);
|
|
591
|
+
if (!on.start(st))
|
|
592
|
+
return 0;
|
|
593
|
+
for (const [i, q] of trace.entries()) {
|
|
594
|
+
if (!allowed(m, rt, params, st, q))
|
|
595
|
+
return 0;
|
|
596
|
+
const nx = rt.step(params, st, q);
|
|
597
|
+
if (!on.step(st, q, nx))
|
|
598
|
+
return i + 1;
|
|
599
|
+
st = nx;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
catch {
|
|
603
|
+
return 0;
|
|
604
|
+
}
|
|
605
|
+
return 0;
|
|
606
|
+
};
|
|
607
|
+
let trace = run.trace, at = breaks(trace);
|
|
608
|
+
if (!at)
|
|
609
|
+
return run;
|
|
610
|
+
trace = trace.slice(0, at);
|
|
611
|
+
for (let changed = true; changed;) {
|
|
612
|
+
changed = false;
|
|
613
|
+
for (let i = 0; i < trace.length; i++) {
|
|
614
|
+
const t = [...trace.slice(0, i), ...trace.slice(i + 1)], b = breaks(t);
|
|
615
|
+
if (b) {
|
|
616
|
+
trace = t.slice(0, b);
|
|
617
|
+
changed = true;
|
|
618
|
+
i--;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
return { ...run, trace };
|
|
623
|
+
}
|
|
624
|
+
// Contention: runs of a system where every call passes one request, so the calls contend for one key; only which
|
|
625
|
+
// part steps, which of three calls, its method and the expiring key vary, searched breadth first (states seen once) to
|
|
626
|
+
// a depth, for each of a few requests drawn. A run found breaks the law on the interpreter, as the search's do. (The
|
|
627
|
+
// search's own runs draw each request apart: three calls on one lock are rare among them.)
|
|
628
|
+
export function contend(e, w, opts = {}) {
|
|
629
|
+
const m = e.rule.machine, rt = interpret(m), bound = opts.bound ?? 2, until = performance.now() + (opts.ms ?? 3000), calls = opts.calls ?? 3;
|
|
630
|
+
let seed = opts.seed ?? 7;
|
|
631
|
+
const rand = (k) => { seed = (seed * 1103515245 + 12345) & 0x7fffffff; return seed % k; };
|
|
632
|
+
const free = new Set([e.act, ...(e.id ? [e.id] : []), ...(e.method ? [e.method] : []), 'key$']);
|
|
633
|
+
const acts = (e.rule.parts?.inputs.find(([i]) => i === e.act)?.[1].values ?? ['calls']).length;
|
|
634
|
+
const choices = [];
|
|
635
|
+
for (let a = 0; a < acts; a++) {
|
|
636
|
+
if (a > 0) {
|
|
637
|
+
for (let k = 0; k <= bound; k++)
|
|
638
|
+
choices.push({ [e.act]: a, 'key$': k });
|
|
639
|
+
continue;
|
|
640
|
+
}
|
|
641
|
+
for (let p = 1; p <= (e.id ? calls : 1); p++)
|
|
642
|
+
for (let mt = 0; mt < (e.method ? e.methods ?? 1 : 1); mt++)
|
|
643
|
+
choices.push({ [e.act]: 0, ...(e.id ? { [e.id]: p } : {}), ...(e.method ? { [e.method]: mt } : {}) });
|
|
644
|
+
}
|
|
645
|
+
const key = (st) => JSON.stringify([st.scalars, Object.entries(st.maps).map(([k, v]) => [k, [...v].filter(([, x]) => x !== 0).sort((a, b) => a[0] - b[0])])]);
|
|
646
|
+
for (let b = 0, tried = 0; b < (opts.bases ?? 12) && tried < 400 && performance.now() < until; tried++) {
|
|
647
|
+
const params = Object.fromEntries(m.params.map(p => [p, rand(bound + 1)]));
|
|
648
|
+
// (the request's values from 0 and 1: two arguments a flow keeps equal, two strings of one length, agree often)
|
|
649
|
+
const base = Object.fromEntries(m.inputs.filter(i => !free.has(i)).map(i => [i, rand(2)]));
|
|
650
|
+
let st0;
|
|
651
|
+
try {
|
|
652
|
+
st0 = rt.init(params);
|
|
653
|
+
}
|
|
654
|
+
catch {
|
|
655
|
+
continue;
|
|
656
|
+
}
|
|
657
|
+
const req = (c) => ({ ...base, ...Object.fromEntries(m.inputs.filter(i => !(i in base)).map(i => [i, 0])), ...c });
|
|
658
|
+
if (!choices.some(c => { try {
|
|
659
|
+
return allowed(m, rt, params, st0, req(c));
|
|
660
|
+
}
|
|
661
|
+
catch {
|
|
662
|
+
return false;
|
|
663
|
+
} }))
|
|
664
|
+
continue;
|
|
665
|
+
b++;
|
|
666
|
+
const seen = new Set([key(st0)]);
|
|
667
|
+
let frontier = [{ st: st0, trace: [] }];
|
|
668
|
+
for (let d = 0; d < (opts.depth ?? 7) && frontier.length && performance.now() < until; d++) {
|
|
669
|
+
const next = [];
|
|
670
|
+
for (const { st, trace } of frontier)
|
|
671
|
+
for (const c of choices) {
|
|
672
|
+
const q = req(c);
|
|
673
|
+
let nx;
|
|
674
|
+
try {
|
|
675
|
+
if (!allowed(m, rt, params, st, q))
|
|
676
|
+
continue;
|
|
677
|
+
nx = rt.step(params, st, q);
|
|
678
|
+
}
|
|
679
|
+
catch {
|
|
680
|
+
continue;
|
|
681
|
+
}
|
|
682
|
+
if (!watch(m, rt, w, params, bound + 2).step(st, q, nx))
|
|
683
|
+
return { params, trace: [...trace, q] };
|
|
684
|
+
const k = key(nx);
|
|
685
|
+
if (seen.has(k) || seen.size > 200_000)
|
|
686
|
+
continue;
|
|
687
|
+
seen.add(k);
|
|
688
|
+
next.push({ st: nx, trace: [...trace, q] });
|
|
689
|
+
}
|
|
690
|
+
frontier = next;
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
return undefined;
|
|
694
|
+
}
|
package/dist/core/transfer.js
CHANGED
|
@@ -225,6 +225,7 @@ function rewriter(bridges, copies, unfold, ren = new Map()) {
|
|
|
225
225
|
const valueOf = (s, x) => (s === 'nat' ? new Nat(x) : s === 'bool' ? new Bool(x.op === 'bool' ? x.c : { op: 'holds', x }) : s === 'int' ? new Integer(x) : new Val(s, x));
|
|
226
226
|
// The copies made, by function and bridges (a law proven again reads the same copies).
|
|
227
227
|
const made = new WeakMap();
|
|
228
|
+
const refused = new Set();
|
|
228
229
|
const freshName = (base) => { let n = base; for (let i = 2; fnNamed(n); i++)
|
|
229
230
|
n = `${base}${i}`; return n; };
|
|
230
231
|
// The law through the bridges `bridged`: the copies (made once), the law said with them, the bridge and copy laws, and
|
|
@@ -246,6 +247,8 @@ function build(l, bridged, unfold) {
|
|
|
246
247
|
const key = `${unfold}|${[...bridged].map(([f, op]) => `${f}:${op.name}`).sort().join(',')}`, copies = new Map();
|
|
247
248
|
for (const n of reach) {
|
|
248
249
|
const f = fnOf(n), had = made.get(f)?.get(key);
|
|
250
|
+
if (had && refused.has(had))
|
|
251
|
+
return undefined;
|
|
249
252
|
if (had && fnNamed(had))
|
|
250
253
|
copies.set(n, had);
|
|
251
254
|
}
|
|
@@ -274,6 +277,20 @@ function build(l, bridged, unfold) {
|
|
|
274
277
|
}
|
|
275
278
|
define(name, Object.fromEntries(f.params.map(q => [q.name, q.sort])), f.ret, () => valueOf(f.ret, body));
|
|
276
279
|
}
|
|
280
|
+
// (a copy whose recursion isn't taken where the original's is, a well-founded call left nested in the match of an
|
|
281
|
+
// unfolded definition, bmerge's in stitch's: no copies of these)
|
|
282
|
+
for (const n of reach) {
|
|
283
|
+
const name = copies.get(n);
|
|
284
|
+
try {
|
|
285
|
+
void fnOf(name).ring;
|
|
286
|
+
}
|
|
287
|
+
catch (e) {
|
|
288
|
+
if (!/not structural recursion/.test(e.message))
|
|
289
|
+
throw e;
|
|
290
|
+
refused.add(name);
|
|
291
|
+
return undefined;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
277
294
|
let holds;
|
|
278
295
|
try {
|
|
279
296
|
holds = rewriter(bridged, copies, unfold).ry(l.holds);
|
package/dist/core/watch.js
CHANGED
|
@@ -102,7 +102,7 @@ export function watch(m, run, w, params, bound) {
|
|
|
102
102
|
if (!isStepLaw(w)) {
|
|
103
103
|
// A law with "there exists" (core/exists.ts): broken only where no value can be a witness, as far as that is decided
|
|
104
104
|
// (one natural or integer read linearly); undecided, it is kept.
|
|
105
|
-
const at = (env, st) => (w.some?.length ? someHolds(w.holds, w.some, { ...env }, st, m)?.holds ?? true : evalC(w.holds, env, st, m));
|
|
105
|
+
const at = (env, st) => (w.some?.length ? someHolds(w.holds, w.some, { ...env }, st, m, true)?.holds ?? true : evalC(w.holds, env, st, m));
|
|
106
106
|
const holds = (st) => atKeys(per(bound, st, () => keysOf(bound, st)), { ...params }, env => at(env, st));
|
|
107
107
|
return { start: holds, step: (_before, _input, after) => holds(after) };
|
|
108
108
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Certificate, type Json } from './format.js';
|
|
1
|
+
import { type Certificate, type Document, type Json, fromInterchange, toInterchange } from './format.js';
|
|
2
2
|
export type Claim = {
|
|
3
3
|
name: string;
|
|
4
4
|
accepted: boolean;
|
|
@@ -10,7 +10,24 @@ export type Report = {
|
|
|
10
10
|
claims: Claim[];
|
|
11
11
|
malformed?: string;
|
|
12
12
|
};
|
|
13
|
+
export declare const decidedBy: {
|
|
14
|
+
goals: string;
|
|
15
|
+
qgoals: string;
|
|
16
|
+
laws: string;
|
|
17
|
+
stepLaws: string;
|
|
18
|
+
kInduction: string;
|
|
19
|
+
progress: string;
|
|
20
|
+
liveness: string;
|
|
21
|
+
loop: string;
|
|
22
|
+
recur: string;
|
|
23
|
+
fold: string;
|
|
24
|
+
cyclic: string;
|
|
25
|
+
qmachine: string;
|
|
26
|
+
termination: string;
|
|
27
|
+
};
|
|
13
28
|
export declare function checkCertificate(c: Certificate): Claim[];
|
|
14
29
|
export declare function checkDocument(doc: unknown): Report;
|
|
15
30
|
export declare function goalsOf(c: Certificate): Certificate;
|
|
16
31
|
export type { Json };
|
|
32
|
+
export { fromInterchange, toInterchange };
|
|
33
|
+
export type { Certificate, Document };
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// loops (loopObligations), folds (foldObligations), progress (progressObligations), liveness (livenessParts, then
|
|
6
6
|
// checkStepLaws). Around them, untrusted: reading the document (format.ts) and the guard that it was read faithfully
|
|
7
7
|
// (written again, it must be the document read).
|
|
8
|
-
import { check, checkKInduction, checkLaws, checkQMachine, checkQTree, checkRecur, checkStepLaws, foldObligations, kInductionStart, kInductionSteps, livenessParts, loopObligations, obligations, progressObligations, qObligations, recurGoal, stepLawObligations } from "../kernel/kernel.js";
|
|
8
|
+
import { check, checkKInduction, checkLaws, checkQMachine, checkQTree, checkRecur, checkStepLaws, foldObligations, kInductionStart, kInductionSteps, livenessParts, loopObligations, obligations, own, progressObligations, qObligations, recurGoal, stepLawObligations } from "../kernel/kernel.js";
|
|
9
9
|
import { descentGoal, mainGoal, premiseGoal, refuseCyclic } from "../kernel/cyclic.js";
|
|
10
10
|
import { FormatError, fromInterchange, resolved, sameJson, toInterchange } from "./format.js";
|
|
11
11
|
const attempt = (f) => { try {
|
|
@@ -14,11 +14,11 @@ const attempt = (f) => { try {
|
|
|
14
14
|
catch (e) {
|
|
15
15
|
return { ok: false, why: e instanceof Error ? e.message : String(e) };
|
|
16
16
|
} };
|
|
17
|
-
const treeOk = (g, trees) => trees
|
|
17
|
+
const treeOk = (g, trees) => { const t = own(trees, g.name); return t !== undefined && check(g, t); };
|
|
18
18
|
// Each goal's own answer, for a refusal's why (never the verdict: that is the kernel's entry point's).
|
|
19
19
|
const failing = (goals, trees) => {
|
|
20
20
|
try {
|
|
21
|
-
const bad = goals().filter(g => !treeOk(g, trees)).map(g => (trees
|
|
21
|
+
const bad = goals().filter(g => !treeOk(g, trees)).map(g => (own(trees, g.name) ? `${g.name}: its tree doesn't refute it` : `${g.name}: no tree`));
|
|
22
22
|
return bad.length ? bad.slice(0, 3).join('; ') + (bad.length > 3 ? `; and ${bad.length - 3} more` : '') : undefined;
|
|
23
23
|
}
|
|
24
24
|
catch (e) {
|
|
@@ -27,6 +27,10 @@ const failing = (goals, trees) => {
|
|
|
27
27
|
};
|
|
28
28
|
// (A certificate of no claims, an empty set of laws, is the kernel's answer on it all the same: a claim of its own.)
|
|
29
29
|
const all = (names, r, why) => (names.length ? names : ['(no claims)']).map(name => ({ name, accepted: r.ok, ...(r.ok ? {} : { why: r.why ?? why?.() ?? 'refused' }) }));
|
|
30
|
+
// The kernel's entry point that decides each kind (docs/interchange.md's table), named in the CLI's verdict.
|
|
31
|
+
export const decidedBy = { goals: 'kernel.ts check', qgoals: 'kernel.ts checkQTree', laws: 'kernel.ts checkLaws', stepLaws: 'kernel.ts checkStepLaws', kInduction: 'kernel.ts checkKInduction',
|
|
32
|
+
progress: 'kernel.ts checkLaws, progressObligations', liveness: 'kernel.ts livenessParts, checkStepLaws', loop: 'kernel.ts loopObligations', recur: 'kernel.ts checkRecur',
|
|
33
|
+
fold: 'kernel.ts foldObligations', cyclic: 'cyclic.ts refuseCyclic', qmachine: 'kernel.ts checkQMachine', termination: 'cyclic.ts refuseCyclic' };
|
|
30
34
|
// The kernel's verdict on a certificate, for each thing it claims.
|
|
31
35
|
export function checkCertificate(c) {
|
|
32
36
|
switch (c.kind) {
|
|
@@ -34,13 +38,13 @@ export function checkCertificate(c) {
|
|
|
34
38
|
case 'qgoals': return c.goals.map(g => { const r = attempt(() => checkQTree(g.goal, g.tree)); return { name: g.goal.name, accepted: r.ok, ...(r.ok ? {} : { why: r.why ?? 'the tree doesn\'t refute the goal' }) }; });
|
|
35
39
|
// A set of laws is proven together (each step assumes them all), so each is accepted exactly when the set is.
|
|
36
40
|
case 'laws': return all(c.laws.map(l => l.name), attempt(() => checkLaws(c.machine, c.laws, c.proof)), () => failing(() => obligations(c.machine, c.laws, c.proof.instances), c.proof.trees));
|
|
37
|
-
case 'stepLaws': return all([...c.laws.map(l => l.name), ...c.stepLaws.map(s => s.name)], attempt(() => checkStepLaws(c.machine, c.laws, c.stepLaws, c.proof)), () => failing(() => [...obligations(c.machine, c.laws, c.proof.laws.instances), ...c.stepLaws.flatMap(s => stepLawObligations(c.machine, c.laws, c.proof.perStep
|
|
41
|
+
case 'stepLaws': return all([...c.laws.map(l => l.name), ...c.stepLaws.map(s => s.name)], attempt(() => checkStepLaws(c.machine, c.laws, c.stepLaws, c.proof)), () => failing(() => [...obligations(c.machine, c.laws, c.proof.laws.instances), ...c.stepLaws.flatMap(s => stepLawObligations(c.machine, c.laws, own(c.proof.perStep ?? {}, s.name) ?? c.proof.instances, s))], { ...c.proof.laws.trees, ...c.proof.trees })
|
|
38
42
|
?? 'a later step\'s names read before it (the zone condition)');
|
|
39
|
-
case 'kInduction': return all([c.kInduction.law.name], attempt(() => checkKInduction(c.machine, c.laws, c.kInduction, c.proof)), () => failing(() => [kInductionStart(c.machine, c.kInduction, c.proof.perStep
|
|
43
|
+
case 'kInduction': return all([c.kInduction.law.name], attempt(() => checkKInduction(c.machine, c.laws, c.kInduction, c.proof)), () => failing(() => [kInductionStart(c.machine, c.kInduction, own(c.proof.perStep ?? {}, `${c.kInduction.law.name} @start`) ?? c.proof.instances), ...kInductionSteps(c.machine, c.kInduction).flatMap(s => stepLawObligations(c.machine, c.laws, own(c.proof.perStep ?? {}, s.name) ?? c.proof.instances, s))], c.proof.trees)
|
|
40
44
|
?? failing(() => obligations(c.machine, c.laws, c.proof.laws.instances), c.proof.laws.trees));
|
|
41
45
|
case 'liveness': {
|
|
42
46
|
const r = attempt(() => { const { stay, cover, helps } = livenessParts(c.machine, c.liveness); return checkStepLaws(c.machine, c.laws, [stay, cover, ...helps], c.proof); });
|
|
43
|
-
return all([c.liveness.name], r, () => failing(() => { const { stay, cover, helps } = livenessParts(c.machine, c.liveness); return [stay, cover, ...helps].flatMap(s => stepLawObligations(c.machine, c.laws, c.proof.perStep
|
|
47
|
+
return all([c.liveness.name], r, () => failing(() => { const { stay, cover, helps } = livenessParts(c.machine, c.liveness); return [stay, cover, ...helps].flatMap(s => stepLawObligations(c.machine, c.laws, own(c.proof.perStep ?? {}, s.name) ?? c.proof.instances, s)); }, c.proof.trees));
|
|
44
48
|
}
|
|
45
49
|
// Progress assumes the laws: proven here by their own trees where the document has them, else not accepted.
|
|
46
50
|
case 'progress': {
|
|
@@ -67,8 +71,9 @@ export function checkDocument(doc) {
|
|
|
67
71
|
let c;
|
|
68
72
|
try {
|
|
69
73
|
c = fromInterchange(doc);
|
|
70
|
-
// The guard: the certificate read, written again, is the document (its columns in any order
|
|
71
|
-
|
|
74
|
+
// The guard: the certificate read, written again, is the document (its columns in any order; at its version, which
|
|
75
|
+
// the reader checked holds what it read).
|
|
76
|
+
if (!sameJson({ ...resolved(toInterchange(c, doc.meta)), version: doc.version }, resolved(doc)))
|
|
72
77
|
return { accepted: false, claims: [], malformed: 'read back, the document is not the same (a field the format drops, or a value it changes)' };
|
|
73
78
|
}
|
|
74
79
|
catch (e) {
|
|
@@ -81,16 +86,16 @@ export function checkDocument(doc) {
|
|
|
81
86
|
// check, as a `goals` (or `qgoals`) certificate a second checker reads (interchange/py/check.py checks trees alone).
|
|
82
87
|
// (The checks past trees stay the kernel's: a stem evaluated, a cyclic proof's ranks of one length, the step laws' zone.)
|
|
83
88
|
export function goalsOf(c) {
|
|
84
|
-
const pick = (goals, trees) => goals.flatMap(goal => (trees
|
|
89
|
+
const pick = (goals, trees) => goals.flatMap(goal => { const tree = own(trees, goal.name); return tree ? [{ goal, tree }] : []; });
|
|
85
90
|
const cyclic = (p) => p.nodes.flatMap(n => [{ goal: mainGoal(p.facts, p.nodes, n), tree: n.main }, ...n.uses.flatMap(u => {
|
|
86
91
|
const m = p.nodes[u.node];
|
|
87
92
|
return m ? [...m.hyps.flatMap((h, i) => (u.premises[i] ? [{ goal: premiseGoal(p.facts, n, u, h, i), tree: u.premises[i] }] : [])), ...(m.rank.length === n.rank.length ? [{ goal: descentGoal(p.facts, n, u, m), tree: u.descent }] : [])] : [];
|
|
88
93
|
})]);
|
|
89
|
-
const steps = (m, sls) => [...pick(obligations(m.machine, m.laws, m.proof.laws.instances), m.proof.laws.trees), ...pick(sls.flatMap(s => stepLawObligations(m.machine, m.laws, m.proof.perStep
|
|
94
|
+
const steps = (m, sls) => [...pick(obligations(m.machine, m.laws, m.proof.laws.instances), m.proof.laws.trees), ...pick(sls.flatMap(s => stepLawObligations(m.machine, m.laws, own(m.proof.perStep ?? {}, s.name) ?? m.proof.instances, s)), m.proof.trees)];
|
|
90
95
|
switch (c.kind) {
|
|
91
96
|
case 'goals':
|
|
92
97
|
case 'qgoals': return c;
|
|
93
|
-
case 'qmachine': return { kind: 'qgoals', goals: c.laws.flatMap(l => { const g = qObligations(c.machine, c.laws, l), t = c.trees
|
|
98
|
+
case 'qmachine': return { kind: 'qgoals', goals: c.laws.flatMap(l => { const g = qObligations(c.machine, c.laws, l), t = own(c.trees, l.name); return t ? [{ goal: g.start, tree: t.start }, { goal: g.step, tree: t.step }] : []; }) };
|
|
94
99
|
case 'laws': return { kind: 'goals', goals: pick(obligations(c.machine, c.laws, c.proof.instances), c.proof.trees) };
|
|
95
100
|
case 'stepLaws': return { kind: 'goals', goals: steps(c, c.stepLaws) };
|
|
96
101
|
case 'liveness': {
|
|
@@ -98,7 +103,7 @@ export function goalsOf(c) {
|
|
|
98
103
|
return { kind: 'goals', goals: steps(c, [stay, cover, ...helps]) };
|
|
99
104
|
}
|
|
100
105
|
case 'kInduction': {
|
|
101
|
-
const start = kInductionStart(c.machine, c.kInduction, c.proof.perStep
|
|
106
|
+
const start = kInductionStart(c.machine, c.kInduction, own(c.proof.perStep ?? {}, `${c.kInduction.law.name} @start`) ?? c.proof.instances);
|
|
102
107
|
return { kind: 'goals', goals: [...pick([start], c.proof.trees), ...steps(c, kInductionSteps(c.machine, c.kInduction))] };
|
|
103
108
|
}
|
|
104
109
|
case 'progress': return { kind: 'goals', goals: [...(c.lawsProof ? pick(obligations(c.machine, c.laws, c.lawsProof.instances), c.lawsProof.trees) : []), ...pick(progressObligations(c.machine, c.laws, c.instances, c.progress), c.trees)] };
|
|
@@ -109,3 +114,5 @@ export function goalsOf(c) {
|
|
|
109
114
|
case 'termination': return { kind: 'goals', goals: c.obligations.flatMap(o => cyclic(o.cyclic)) };
|
|
110
115
|
}
|
|
111
116
|
}
|
|
117
|
+
// (the format's reader and writer, beside the checker, for `gdp-wired/interchange`)
|
|
118
|
+
export { fromInterchange, toInterchange };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// gdp-wired-check: interchange documents in, the kernel's verdict on each claim out.
|
|
3
|
+
// gdp-wired-check [--json] [--goals <out.json>] <file.json>... (or - for standard input)
|
|
4
|
+
// Each file: `accepted` or `refused` with the kind and the kernel's entry point that decided it, then each claim (a
|
|
5
|
+
// law, a step law, a node, a goal) and why a refused one is. Exit 0 when every claim of every file is accepted, 1 when
|
|
6
|
+
// one is refused (or a file isn't a document), 2 on bad use.
|
|
7
|
+
// --goals: the first file's goals, each with its tree, written as a `goals` document (the tree part of the check, for a
|
|
8
|
+
// second checker: interchange/py/check.py).
|
|
9
|
+
// Shipped as the package's `gdp-wired-check` bin; built alone (interchange/build.ts) as one file, an executable and a
|
|
10
|
+
// WebAssembly module. Node's modules are reached at run time (as core/cli.ts reaches them), so the library's build
|
|
11
|
+
// carries no Node types.
|
|
12
|
+
import { checkDocument, decidedBy, goalsOf } from "./check.js";
|
|
13
|
+
import { fromInterchange, toInterchange } from "./format.js";
|
|
14
|
+
const proc = globalThis.process;
|
|
15
|
+
const fs = proc.getBuiltinModule('node:fs');
|
|
16
|
+
const args = proc.argv.slice(2), json = args.includes('--json'), gi = args.indexOf('--goals'), goalsOut = gi >= 0 ? args[gi + 1] : undefined;
|
|
17
|
+
const files = args.filter((a, i) => !a.startsWith('--') && (gi < 0 || i !== gi + 1));
|
|
18
|
+
if (!files.length || (gi >= 0 && !goalsOut)) {
|
|
19
|
+
proc.stderr.write('usage: gdp-wired-check [--json] [--goals <out.json>] <file.json>... (- reads standard input)\n');
|
|
20
|
+
proc.exit(2);
|
|
21
|
+
}
|
|
22
|
+
const read = (f) => JSON.parse(f === '-' ? fs.readFileSync(0, 'utf8') : fs.readFileSync(f, 'utf8'));
|
|
23
|
+
const out = [];
|
|
24
|
+
for (const file of files) {
|
|
25
|
+
let report;
|
|
26
|
+
try {
|
|
27
|
+
report = checkDocument(read(file));
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
report = { accepted: false, claims: [], malformed: `not JSON: ${e instanceof Error ? e.message : String(e)}` };
|
|
31
|
+
}
|
|
32
|
+
out.push({ file, report });
|
|
33
|
+
}
|
|
34
|
+
if (goalsOut)
|
|
35
|
+
fs.writeFileSync(goalsOut, JSON.stringify(toInterchange(goalsOf(fromInterchange(read(files[0]))))));
|
|
36
|
+
const say = (s) => proc.stdout.write(`${s}\n`);
|
|
37
|
+
if (json)
|
|
38
|
+
say(JSON.stringify(out.length === 1 ? out[0].report : out));
|
|
39
|
+
else
|
|
40
|
+
for (const { file, report } of out) {
|
|
41
|
+
say(`${file}: ${report.accepted ? 'accepted' : 'refused'}${report.kind ? ` (${report.kind}, by ${decidedBy[report.kind] ?? 'the kernel'})` : ''}${report.malformed ? `: ${report.malformed}` : ''}`);
|
|
42
|
+
for (const c of report.claims)
|
|
43
|
+
say(` ${c.accepted ? 'accepted' : 'refused '} ${c.name}${c.why ? `: ${c.why}` : ''}`);
|
|
44
|
+
}
|
|
45
|
+
proc.exit(out.every(o => o.report.accepted) ? 0 : 1);
|
|
@@ -2,7 +2,7 @@ import type { C, E, Law, Machine } from '../core/machine.js';
|
|
|
2
2
|
import type { Fold, Goal, Instances, KInduction, Liveness, Loop, QC, QE, QGoal, QLaw, QMachine, Recur, StepLaw, Tree } from '../kernel/kernel.js';
|
|
3
3
|
import type { Cyclic } from '../kernel/cyclic.js';
|
|
4
4
|
import type { Lin } from '../core/solver.js';
|
|
5
|
-
export declare const FORMAT = "gdp-wired-interchange", VERSION = "1.
|
|
5
|
+
export declare const FORMAT = "gdp-wired-interchange", VERSION = "1.1", VERSIONS: string[];
|
|
6
6
|
export type LawsProof = {
|
|
7
7
|
instances: Record<string, Instances>;
|
|
8
8
|
trees: Record<string, Tree>;
|
|
@@ -23,6 +23,10 @@ export type Measure = {
|
|
|
23
23
|
comps: {
|
|
24
24
|
coef: number[];
|
|
25
25
|
c: number;
|
|
26
|
+
fold?: {
|
|
27
|
+
fn: string;
|
|
28
|
+
of: number;
|
|
29
|
+
};
|
|
26
30
|
}[];
|
|
27
31
|
};
|
|
28
32
|
export type Obligation = {
|