gdp-wired 0.45.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.
- package/README.md +58 -7
- package/dist/core/bitsets.d.ts +2 -0
- package/dist/core/bitsets.js +23 -0
- package/dist/core/bmc.js +6 -2
- package/dist/core/c/reader.d.ts +9 -1
- package/dist/core/c/reader.js +423 -31
- package/dist/core/calendar.d.ts +29 -0
- package/dist/core/calendar.js +82 -0
- package/dist/core/cli.d.ts +3 -0
- package/dist/core/cli.js +204 -38
- package/dist/core/compose.js +3 -1
- package/dist/core/counts.d.ts +4 -1
- package/dist/core/counts.js +314 -85
- package/dist/core/cycles.js +8 -1
- package/dist/core/cyclic.d.ts +1 -0
- package/dist/core/cyclic.js +13 -7
- package/dist/core/data-synth.d.ts +3 -0
- package/dist/core/data-synth.js +252 -0
- package/dist/core/data.d.ts +2 -1
- package/dist/core/data.js +223 -24
- package/dist/core/discover.js +3 -1
- package/dist/core/draft.d.ts +19 -0
- package/dist/core/draft.js +53 -0
- package/dist/core/dsl.d.ts +37 -3
- package/dist/core/dsl.js +167 -26
- package/dist/core/effect.d.ts +1 -4
- package/dist/core/effect.js +1 -15
- package/dist/core/exists.d.ts +1 -0
- package/dist/core/exists.js +191 -16
- package/dist/core/extract-c.d.ts +2 -0
- package/dist/core/extract-c.js +169 -22
- package/dist/core/extract-check.d.ts +1 -0
- package/dist/core/extract-check.js +66 -0
- package/dist/core/extract-go-check.d.ts +1 -1
- package/dist/core/extract-go-check.js +2 -1
- package/dist/core/extract-go.d.ts +1 -0
- package/dist/core/extract-go.js +38 -4
- package/dist/core/extract-ir.d.ts +1 -0
- package/dist/core/extract-ir.js +15 -0
- package/dist/core/extract-jvm.d.ts +1 -1
- package/dist/core/extract-jvm.js +2 -0
- package/dist/core/extract-orm.d.ts +12 -0
- package/dist/core/extract-orm.js +244 -0
- package/dist/core/extract-print.js +20 -1
- package/dist/core/extract-py.d.ts +1 -0
- package/dist/core/extract-py.js +1 -1
- package/dist/core/extract-read.d.ts +17 -0
- package/dist/core/extract-read.js +5 -5
- package/dist/core/extract-rs.js +5 -1
- package/dist/core/extract-shapes.js +2 -0
- package/dist/core/extract-sol.d.ts +10 -1
- package/dist/core/extract-sol.js +70 -22
- package/dist/core/extract-step.d.ts +151 -1
- package/dist/core/extract-step.js +1232 -60
- package/dist/core/extract-swift.js +6 -2
- package/dist/core/extract.d.ts +8 -0
- package/dist/core/extract.js +61 -5
- package/dist/core/fiber-run.d.ts +5 -0
- package/dist/core/fiber-run.js +18 -0
- package/dist/core/infer.d.ts +4 -1
- package/dist/core/infer.js +918 -217
- package/dist/core/jvm/JavaReader.java +23 -6
- package/dist/core/jvm/Jvm.java +3 -0
- package/dist/core/jvm/KtReader.java +6 -5
- package/dist/core/laws.d.ts +10 -3
- package/dist/core/laws.js +193 -14
- package/dist/core/machine.d.ts +15 -1
- package/dist/core/machine.js +187 -15
- package/dist/core/nonterm.js +14 -1
- package/dist/core/orm/harness.js +61 -0
- package/dist/core/orm-fixtures/schema.prisma +5 -0
- package/dist/core/py/harness.py +183 -10
- package/dist/core/py/reader.py +234 -40
- package/dist/core/reader-fixtures/README.md +28 -0
- package/dist/core/reader-fixtures/c-693042.cpp +8 -0
- package/dist/core/reader-fixtures/go-685506.go +14 -0
- package/dist/core/reader-fixtures/jvm-724362.kt +8 -0
- package/dist/core/reader-fixtures/jvm-737430.kt +7 -0
- package/dist/core/reader-fixtures/jvm-765282.kt +3 -0
- package/dist/core/reader-fixtures/swift-735726.swift +15 -0
- package/dist/core/reader-fixtures/swift-735990.swift +15 -0
- package/dist/core/reader-fixtures/swift-739158.swift +4 -0
- package/dist/core/reader-fixtures/swift-744834.swift +15 -0
- package/dist/core/reader-fixtures/swift-746946.swift +31 -0
- package/dist/core/reader-fixtures/typescript-673062.ts.txt +2 -0
- package/dist/core/relation.d.ts +1 -1
- package/dist/core/relation.js +29 -2
- package/dist/core/relational.js +4 -2
- package/dist/core/rs/src/main.rs +8 -2
- package/dist/core/sample-cache.d.ts +8 -0
- package/dist/core/sample-cache.js +46 -0
- package/dist/core/security.d.ts +38 -0
- package/dist/core/security.js +88 -0
- package/dist/core/sol/harness.py +57 -4
- package/dist/core/sol-concrete.d.ts +23 -0
- package/dist/core/sol-concrete.js +195 -0
- package/dist/core/solver.js +3 -1
- package/dist/core/swift/Sources/gdp-swiftreader/main.swift +50 -7
- package/dist/core/system.js +1 -1
- package/dist/core/transfer.js +22 -9
- package/dist/core/translate.js +39 -10
- package/dist/core/watch.js +50 -5
- package/dist/interchange/format.js +11 -1
- package/dist/kernel/cdcl.d.ts +5 -0
- package/dist/kernel/cdcl.js +56 -9
- package/dist/kernel/epr.js +108 -26
- package/dist/kernel/kernel.d.ts +29 -1
- package/dist/kernel/kernel.js +325 -62
- package/dist/kernel/model-sequence.d.ts +3 -0
- package/dist/kernel/model-sequence.js +34 -0
- package/dist/kernel/prove.d.ts +10 -3
- package/dist/kernel/prove.js +332 -71
- package/dist/kernel/reader.d.ts +3 -0
- package/dist/kernel/reader.js +101 -14
- package/dist/kernel/share.d.ts +1 -0
- package/dist/kernel/share.js +27 -0
- package/dist/lean-kernel/emit.js +30 -37
- package/dist/lean-kernel/lean-terms.js +5 -0
- package/dist/lean-kernel/library.js +10 -10
- package/package.json +6 -1
package/dist/core/exists.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// value before, shifts of it, the request's values and the state before; each is chosen to satisfy P at every
|
|
15
15
|
// counterexample so far, per case of the step (the conditions its updates split on: the request's clause, say).
|
|
16
16
|
// A law under a `forall` key takes witness terms only (a ghost per key would be a map).
|
|
17
|
-
import { carriedView, evalC, evalE, fastStep, interpret, n as k, walk, x as v } from "./machine.js";
|
|
17
|
+
import { carriedView, compileC, evalC, evalE, fastStep, interpret, n as k, walk, x as v } from "./machine.js";
|
|
18
18
|
import { clock, proveLaw, proveLaws, withDeadline, withinDeadline } from "../kernel/prove.js";
|
|
19
19
|
import { env } from "./solver.js";
|
|
20
20
|
import { ghostedMachine, ghostedOk, substC } from "../kernel/kernel.js";
|
|
@@ -40,14 +40,16 @@ export function substVarsE(e, s) {
|
|
|
40
40
|
switch (e.op) {
|
|
41
41
|
case 'var': return s[e.name] ?? e;
|
|
42
42
|
case 'const': return e;
|
|
43
|
-
case 'mul':
|
|
43
|
+
case 'mul':
|
|
44
|
+
case 'proj': return { ...e, a: substVarsE(e.a, s) };
|
|
44
45
|
case 'if': return { op: 'if', c: substVars(e.c, s), then: substVarsE(e.then, s), else: substVarsE(e.else, s) };
|
|
45
46
|
case 'get': return { ...e, key: substVarsE(e.key, s) };
|
|
46
47
|
case 'add':
|
|
47
48
|
case 'sub':
|
|
48
49
|
case 'min':
|
|
49
50
|
case 'max':
|
|
50
|
-
case 'prod':
|
|
51
|
+
case 'prod':
|
|
52
|
+
case 'tup': return { ...e, a: substVarsE(e.a, s), b: substVarsE(e.b, s) };
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
export function substVars(c, s) {
|
|
@@ -91,7 +93,9 @@ function lin(e, bound) {
|
|
|
91
93
|
case 'max':
|
|
92
94
|
case 'prod':
|
|
93
95
|
case 'if':
|
|
94
|
-
case 'get':
|
|
96
|
+
case 'get':
|
|
97
|
+
case 'tup':
|
|
98
|
+
case 'proj': return free ? { k: {}, pos: [e], neg: [] } : undefined;
|
|
95
99
|
}
|
|
96
100
|
}
|
|
97
101
|
function atomsOf(c, bound, out = []) {
|
|
@@ -253,12 +257,13 @@ export function ghostOf(m, law) {
|
|
|
253
257
|
}
|
|
254
258
|
// The small instances, the one filter of every candidate (core/counts.ts's laws, the witnesses and ghosts here): each
|
|
255
259
|
// param 2 and 3, every input and carried set below 3, every state the BFS reaches in 300,000 steps (3,000 at most) and
|
|
256
|
-
// the walks past it in a third as many; an instance whose params the machine refuses has no states.
|
|
260
|
+
// the walks past it in a third as many; an instance whose params the machine refuses has no states. With no params,
|
|
261
|
+
// 2 and 3 denote the same instance, so sample it only once. Read once a machine.
|
|
257
262
|
const smalls = new WeakMap();
|
|
258
263
|
export function smallOf(m) {
|
|
259
264
|
let out = smalls.get(m);
|
|
260
265
|
if (!out)
|
|
261
|
-
smalls.set(m, (out = [2, 3].map(x => { const p = Object.fromEntries(m.params.map(q => [q, x])); try {
|
|
266
|
+
smalls.set(m, (out = (m.params.length ? [2, 3] : [2]).map(x => { const p = Object.fromEntries(m.params.map(q => [q, x])); try {
|
|
262
267
|
return { p, sts: small(m, p, 3, 3000, 300_000, 100_000) };
|
|
263
268
|
}
|
|
264
269
|
catch {
|
|
@@ -271,14 +276,18 @@ export function smallOf(m) {
|
|
|
271
276
|
// one instance a machine, however many ghosts are asked of it.
|
|
272
277
|
export function trueSmall(m, laws, ghosted) {
|
|
273
278
|
const g = ghosted ?? m, run = ghosted && interpret(ghosted);
|
|
279
|
+
const native = Object.values(g.step.maps ?? {}).some(w => !('each' in w) && w.key.op === 'tup');
|
|
280
|
+
let steps = 0, step = run?.step;
|
|
274
281
|
return smallOf(m).every(({ p, sts }) => {
|
|
275
282
|
const at = new Map();
|
|
276
283
|
return sts.every(st => {
|
|
277
284
|
let s = st;
|
|
278
285
|
if (run) {
|
|
286
|
+
if (native && ++steps === 1000)
|
|
287
|
+
step = fastStep(g) ?? run.step;
|
|
279
288
|
const from = pathTo.get(st);
|
|
280
289
|
try {
|
|
281
|
-
s = from ?
|
|
290
|
+
s = from ? step(p, at.get(from[0]), from[1]) : run.init(p);
|
|
282
291
|
}
|
|
283
292
|
catch {
|
|
284
293
|
return false;
|
|
@@ -292,14 +301,46 @@ export function trueSmall(m, laws, ghosted) {
|
|
|
292
301
|
// A law at a state, its counts the state's, at every key below b.
|
|
293
302
|
// (a state's view once: a law is read at every state, and every law at each)
|
|
294
303
|
const views = new WeakMap();
|
|
304
|
+
const sampleTests = new WeakMap();
|
|
295
305
|
export function holdsAt(m, law, p, st, b) {
|
|
296
|
-
const empty = Object.fromEntries((m.inputMaps ?? []).map(c => [c, new Map()]));
|
|
297
306
|
let view = views.get(st);
|
|
298
|
-
if (!view)
|
|
307
|
+
if (!view) {
|
|
308
|
+
const empty = Object.fromEntries((m.inputMaps ?? []).map(c => [c, new Map()]));
|
|
299
309
|
views.set(st, (view = carriedView(m, st, empty, undefined, p)));
|
|
310
|
+
}
|
|
311
|
+
let tests = sampleTests.get(m);
|
|
312
|
+
if (!tests)
|
|
313
|
+
sampleTests.set(m, (tests = new WeakMap()));
|
|
314
|
+
let test = tests.get(law.holds);
|
|
315
|
+
if (!test)
|
|
316
|
+
tests.set(law.holds, (test = compileC(law.holds, m)));
|
|
300
317
|
const keys = [law.forall, ...(law.keys ?? [])].filter((x) => !!x);
|
|
301
|
-
const
|
|
302
|
-
|
|
318
|
+
const env = { ...p, ...st.scalars }, fixed = new Set(Object.keys(st.scalars));
|
|
319
|
+
// One environment, not an object/array copy at every tuple prefix. Scalars still
|
|
320
|
+
// shadow binders, as in the interpreter path; restore duplicate binder names.
|
|
321
|
+
for (const name of keys)
|
|
322
|
+
if (!fixed.has(name))
|
|
323
|
+
Object.defineProperty(env, name, { value: env[name], writable: true, enumerable: true, configurable: true });
|
|
324
|
+
const values = keys.length ? Array.from({ length: b }, (_, x) => x) : [];
|
|
325
|
+
const go = (depth) => {
|
|
326
|
+
if (depth === keys.length)
|
|
327
|
+
return test(env, view);
|
|
328
|
+
const name = keys[depth], was = env[name];
|
|
329
|
+
try {
|
|
330
|
+
for (const value of values) {
|
|
331
|
+
if (!fixed.has(name))
|
|
332
|
+
env[name] = value;
|
|
333
|
+
if (!go(depth + 1))
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
return true;
|
|
337
|
+
}
|
|
338
|
+
finally {
|
|
339
|
+
if (!fixed.has(name))
|
|
340
|
+
env[name] = was;
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
return go(0);
|
|
303
344
|
}
|
|
304
345
|
// --- evaluating ∃ on a state ----------------------------------------------------------------------------------------
|
|
305
346
|
// Whether ∃ vars. P holds where env and st give every other value, with a witness: exact when the bound values are one
|
|
@@ -435,7 +476,9 @@ function onlyKeys(e, bound) {
|
|
|
435
476
|
case 'max':
|
|
436
477
|
case 'prod': return onlyKeys(e.a, bound) && onlyKeys(e.b, bound);
|
|
437
478
|
case 'mul': return onlyKeys(e.a, bound);
|
|
438
|
-
case 'if':
|
|
479
|
+
case 'if':
|
|
480
|
+
case 'tup':
|
|
481
|
+
case 'proj': return false;
|
|
439
482
|
case 'get': return false;
|
|
440
483
|
}
|
|
441
484
|
}
|
|
@@ -570,6 +613,8 @@ function provenanceOf(m, mp2, val2, taken, keyed = keyedOf(m)) {
|
|
|
570
613
|
says.push({ op: '<=', a: k(1), b: { op: 'get', map: mp3, key: substVarsE(w3.key, sub) } });
|
|
571
614
|
if (!says.length)
|
|
572
615
|
return undefined;
|
|
616
|
+
if (w2.key.op === 'tup')
|
|
617
|
+
says.push(...(m.assume ? atomsOf2(m.assume) : []).filter(c => mine(namesOf(c))).map(c => substVars(c, sub)));
|
|
573
618
|
const inv = { name: `${gname} where ${mp2} is set`, forall: ks[0], ...(ks.length > 1 ? { keys: ks.slice(1) } : {}), holds: { op: 'or', xs: [{ op: 'not', x: { op: '<=', a: k(1), b: { op: 'get', map: mp2, key: K2 } } }, says.length === 1 ? says[0] : { op: 'and', xs: says }] } };
|
|
574
619
|
return { name: gname, write: { key: w2.key, value: { op: 'if', c: set2, then: v(val2), else: G(w2.key) } }, inv };
|
|
575
620
|
}
|
|
@@ -664,6 +709,89 @@ function binderGhostsOf(m, law, taken) {
|
|
|
664
709
|
xs.forEach((x, j) => { combos = combos.flatMap(c => options[j].map(o => ({ maps: { ...c.maps, ...o.maps }, sub: { ...c.sub, [x]: o.term } }))).slice(0, 64); });
|
|
665
710
|
return combos;
|
|
666
711
|
}
|
|
712
|
+
// A witness's local proof need not instantiate unrelated provenance functions.
|
|
713
|
+
// Keep supports over the target's dependency maps, including reads by their
|
|
714
|
+
// updates and flags. Excluded supports can still prove other
|
|
715
|
+
// members of the final set; no proof/assumption is reused without that check.
|
|
716
|
+
export function witnessSupport(m, laws, law, ghosts = []) {
|
|
717
|
+
const maps = new Set(), flags = new Set();
|
|
718
|
+
const read = (t) => walk(t, o => {
|
|
719
|
+
if (o.op === 'get')
|
|
720
|
+
maps.add(o.map);
|
|
721
|
+
if (o.op === 'flag' && !flags.has(o.name)) {
|
|
722
|
+
flags.add(o.name);
|
|
723
|
+
read(m.step.flags?.[o.name]);
|
|
724
|
+
}
|
|
725
|
+
});
|
|
726
|
+
read(law.holds);
|
|
727
|
+
const plain = ghosts.every(g => !maps.has(g)), ghostSet = new Set(ghosts);
|
|
728
|
+
for (const mp of maps)
|
|
729
|
+
read(m.step.maps?.[mp]);
|
|
730
|
+
return laws.filter(l => {
|
|
731
|
+
if (l === law)
|
|
732
|
+
return true;
|
|
733
|
+
let relevant = true;
|
|
734
|
+
walk(l.holds, o => { if (o.op === 'get' && !maps.has(o.map) && !(plain && ghostSet.has(o.map)))
|
|
735
|
+
relevant = false; });
|
|
736
|
+
return relevant;
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
// Candidate closure of row provenance: facts about a write's key, its co-written
|
|
740
|
+
// rows joined at shared inputs, and functional dependencies of each key place.
|
|
741
|
+
// No dependency is presumed to hold: runs discard false ones, the prover checks
|
|
742
|
+
// the remaining simultaneous induction obligations.
|
|
743
|
+
function rowSupports(m) {
|
|
744
|
+
const out = [], seen = new Set();
|
|
745
|
+
const and = (xs) => ({ op: 'and', xs });
|
|
746
|
+
const has = (map, at) => ({ op: '<=', a: k(1), b: { op: 'get', map, key: at } });
|
|
747
|
+
const expand = (c, depth = 0) => c.op === 'and' ? c.xs.flatMap(q => expand(q, depth)) : c.op === 'flag' && depth < 8 && m.step.flags?.[c.name] ? expand(m.step.flags[c.name], depth + 1) : [c];
|
|
748
|
+
const assumptions = m.assume ? expand(m.assume) : [];
|
|
749
|
+
const writes = Object.entries(m.step.maps ?? {}).flatMap(([map, w]) => {
|
|
750
|
+
if ('each' in w || w.key.op !== 'tup')
|
|
751
|
+
return [];
|
|
752
|
+
const names = namesOf(w.key);
|
|
753
|
+
if (!names.length || !names.every(n => m.inputs.includes(n)))
|
|
754
|
+
return [];
|
|
755
|
+
const flags = new Set();
|
|
756
|
+
walk(w.value, o => { if (o.op === 'flag')
|
|
757
|
+
flags.add(o.name); });
|
|
758
|
+
return [{ map, w, names, guards: [...flags].flatMap(name => expand({ op: 'flag', name })), setter: settersOf(m, map)[0]?.set }];
|
|
759
|
+
});
|
|
760
|
+
const emit = (names, pre, post, label) => {
|
|
761
|
+
const ren = Object.fromEntries(names.map((n, i) => [n, v(`row${i}$key`)]));
|
|
762
|
+
const holds = substVars({ op: 'or', xs: [{ op: 'not', x: and(pre) }, post] }, ren);
|
|
763
|
+
// Quantifier order and conjunction order do not distinguish a proposal.
|
|
764
|
+
// Keep the first spelling, rather than burdening later goals with both.
|
|
765
|
+
const id = key([names.slice().sort(), pre.map(key).sort(), post]);
|
|
766
|
+
if (seen.has(id))
|
|
767
|
+
return;
|
|
768
|
+
seen.add(id);
|
|
769
|
+
out.push({ name: `${label} (${out.length})`, forall: `row0$key`, ...(names.length > 1 ? { keys: names.slice(1).map((_, i) => `row${i + 1}$key`) } : {}), holds });
|
|
770
|
+
};
|
|
771
|
+
const usable = (c, names) => c.op !== 'flag' && c.op !== 'all' && namesOf(c).every(n => names.includes(n) || Object.hasOwn(m.state, n) || m.params.includes(n));
|
|
772
|
+
for (const a of writes) {
|
|
773
|
+
for (const c of [...a.guards, ...assumptions].filter(c => usable(c, a.names)))
|
|
774
|
+
emit(a.names, [has(a.map, a.w.key)], c, `${a.map} row guard`);
|
|
775
|
+
const freshRow = a.guards.some(c => c.op === 'all' && JSON.stringify(c).includes(`"map":${JSON.stringify(a.map)}`));
|
|
776
|
+
for (const n of freshRow ? a.names : []) {
|
|
777
|
+
let other = 'other$row';
|
|
778
|
+
while (m.inputs.includes(other) || a.names.includes(other))
|
|
779
|
+
other += '$';
|
|
780
|
+
const bounds = assumptions.filter(c => usable(c, a.names) && !readsMaps(c));
|
|
781
|
+
emit([...a.names, other], [...bounds, ...bounds.map(c => substVars(c, { [n]: v(other) })), has(a.map, a.w.key), has(a.map, substVarsE(a.w.key, { [n]: v(other) }))], { op: '=', a: v(n), b: v(other) }, `${a.map} functional ${n}`);
|
|
782
|
+
}
|
|
783
|
+
for (const b of writes) {
|
|
784
|
+
if (a.map === b.map || !a.setter || key(a.setter) !== key(b.setter) || !a.names.some(n => b.names.includes(n)))
|
|
785
|
+
continue;
|
|
786
|
+
const names = [...new Set([...a.names, ...b.names])];
|
|
787
|
+
if (names.length > 4)
|
|
788
|
+
continue;
|
|
789
|
+
for (const c of a.guards.filter(c => usable(c, names) && readsMaps(c)))
|
|
790
|
+
emit(names, [has(a.map, a.w.key), has(b.map, b.w.key)], c, `${a.map} / ${b.map} joined guard`);
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
return out;
|
|
794
|
+
}
|
|
667
795
|
function mapGhostsOf(m, law, taken) {
|
|
668
796
|
const x = law.some[0], names = [law.forall, ...(law.keys ?? [])];
|
|
669
797
|
const xs = law.holds.op === 'or' ? law.holds.xs : [law.holds], P = xs.filter(d => namesOf(d).includes(x)), rest = xs.filter(d => !namesOf(d).includes(x));
|
|
@@ -700,17 +828,39 @@ function mapGhostsOf(m, law, taken) {
|
|
|
700
828
|
// (a ghost of a ghost, after those: the value another write's ghost holds, read at that write's key in this step's
|
|
701
829
|
// request: G[i·N + p] := r where DbResponseSent[i·N + p] is set, W[n·N + p] := G[i·N + p] where ResponseSent is.
|
|
702
830
|
// G's own law: where its write's cell is set, what the write's guard says of r, at G's cell)
|
|
831
|
+
const inner = [];
|
|
703
832
|
for (const mp2 of Object.keys(m.step.maps ?? {})) {
|
|
704
833
|
if (mp2 === mp)
|
|
705
834
|
continue;
|
|
706
835
|
const w2 = m.step.maps[mp2];
|
|
707
|
-
if (
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
836
|
+
if ('each' in w2)
|
|
837
|
+
continue;
|
|
838
|
+
// A witness whose writer needs a universal freshness guard has a more
|
|
839
|
+
// expensive support obligation than one selected by positive row reads.
|
|
840
|
+
// On native relations prefer the latter, independently of map order.
|
|
841
|
+
let cost = 0;
|
|
842
|
+
const seen = new Set(), inspect = (t) => walk(t, o => {
|
|
843
|
+
if (o.op === 'all')
|
|
844
|
+
cost++;
|
|
845
|
+
if (o.op === 'flag' && !seen.has(o.name)) {
|
|
846
|
+
seen.add(o.name);
|
|
847
|
+
inspect(m.step.flags?.[o.name]);
|
|
848
|
+
}
|
|
849
|
+
});
|
|
850
|
+
if (w.key.op === 'tup')
|
|
851
|
+
inspect(w2.value);
|
|
852
|
+
for (const val2 of m.inputs) {
|
|
853
|
+
const g = provenanceOf(m, mp2, val2, taken, keyed);
|
|
854
|
+
if (g) {
|
|
855
|
+
if (w.key.op === 'tup')
|
|
856
|
+
inner.push({ g, at: w2.key, cost });
|
|
857
|
+
else
|
|
711
858
|
ghost({ op: 'get', map: g.name, key: w2.key }, g);
|
|
712
859
|
}
|
|
860
|
+
}
|
|
713
861
|
}
|
|
862
|
+
for (const { g, at } of inner.sort((a, b) => a.cost - b.cost))
|
|
863
|
+
ghost({ op: 'get', map: g.name, key: at }, g);
|
|
714
864
|
}
|
|
715
865
|
return out;
|
|
716
866
|
}
|
|
@@ -785,6 +935,29 @@ export function skolemOf(m, laws) {
|
|
|
785
935
|
plains[l.name] = { plain: pl, sub: { [l.some[0]]: { op: 'get', map: g.name, key: g.at } } };
|
|
786
936
|
witnesses[l.name] = `w = ${g.name}[${showE(g.at)}], ${g.name}[${showE(g.write.key)}] := ${showE(g.write.value)}`;
|
|
787
937
|
}
|
|
938
|
+
// Native relations have independent key components. For a relation read by a
|
|
939
|
+
// witness support, retain the input forgotten by its key as another candidate
|
|
940
|
+
// ghost. In particular, co-written rows then have converse provenance, rather
|
|
941
|
+
// than permitting old orphan rows in induction pre-states. These are proposed
|
|
942
|
+
// laws, filtered on runs and subsequently proved, never admitted assumptions.
|
|
943
|
+
if (gs.some(g => g.inner) && Object.values(m.step.maps ?? {}).some(w => !('each' in w) && w.key.op === 'tup')) {
|
|
944
|
+
cands.push(...rowSupports(m).filter(l => trueSmall(m, [l])));
|
|
945
|
+
const needed = new Set();
|
|
946
|
+
walk(out, o => { if (o.op === 'get')
|
|
947
|
+
needed.add(o.map); });
|
|
948
|
+
for (const mp of needed)
|
|
949
|
+
for (const input of m.inputs) {
|
|
950
|
+
const q = provenanceOf(m, mp, input, taken);
|
|
951
|
+
if (!q || parts.some(p => p.write.value.op === 'if' && q.write.value.op === 'if' && key([p.write.key, p.write.value.c]) === key([q.write.key, q.write.value.c])))
|
|
952
|
+
continue;
|
|
953
|
+
const mm = ghost(m, [q]);
|
|
954
|
+
if (!trueSmall(m, [q.inv], mm))
|
|
955
|
+
continue;
|
|
956
|
+
parts.push(q);
|
|
957
|
+
taken.add(q.name);
|
|
958
|
+
cands.push(q.inv);
|
|
959
|
+
}
|
|
960
|
+
}
|
|
788
961
|
// (each ghost one of the machine it is added to, as kernel.ts's ghostedOk reads it)
|
|
789
962
|
const ok = (m2) => { let at = m2; for (const q of parts) {
|
|
790
963
|
const o = one(at, q);
|
|
@@ -1142,6 +1315,8 @@ export function showE(e) {
|
|
|
1142
1315
|
case 'max': return `${e.op}(${showE(e.a)}, ${showE(e.b)})`;
|
|
1143
1316
|
case 'if': return `(${showC(e.c)} ? ${showE(e.then)} : ${showE(e.else)})`;
|
|
1144
1317
|
case 'get': return `${e.map}[${showE(e.key)}]`;
|
|
1318
|
+
case 'tup': return `⟨${showE(e.a)}, ${showE(e.b)}⟩`;
|
|
1319
|
+
case 'proj': return `${e.k === 0 ? 'fst' : 'snd'}(${showE(e.a)})`;
|
|
1145
1320
|
}
|
|
1146
1321
|
}
|
|
1147
1322
|
export function showC(c) {
|
package/dist/core/extract-c.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ export type COptions = {
|
|
|
19
19
|
fails?: Record<string, string>;
|
|
20
20
|
answers?: Record<string, string>;
|
|
21
21
|
skip?: string[];
|
|
22
|
+
leave?: string[];
|
|
23
|
+
cut?: string[];
|
|
22
24
|
onError?: 'refuse' | 'discard';
|
|
23
25
|
domains?: Record<string, 'nat' | 'int'>;
|
|
24
26
|
check?: GoCheckOptions;
|