gdp-wired 0.45.0 → 0.47.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 +61 -8
- 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 +4 -0
- package/dist/core/cli.js +206 -40
- 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-schema.d.ts +90 -0
- package/dist/core/effect-schema.js +500 -0
- package/dist/core/effect.d.ts +4 -11
- package/dist/core/effect.js +3 -79
- 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 +97 -6
- package/dist/core/extract-go-check.d.ts +1 -1
- package/dist/core/extract-go-check.js +26 -5
- package/dist/core/extract-go.d.ts +8 -0
- package/dist/core/extract-go.js +67 -6
- 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 +26 -1
- package/dist/core/extract-read.js +14 -7
- package/dist/core/extract-rs.js +63 -15
- package/dist/core/extract-shapes.d.ts +1 -0
- package/dist/core/extract-shapes.js +84 -0
- package/dist/core/extract-sol.d.ts +10 -1
- package/dist/core/extract-sol.js +70 -22
- package/dist/core/extract-standalone.d.ts +3 -0
- package/dist/core/extract-standalone.js +221 -0
- 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 +9 -0
- package/dist/core/extract.js +77 -7
- 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 +226 -23
- 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/Cargo.toml +1 -1
- package/dist/core/rs/src/main.rs +466 -11
- 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
|
@@ -474,11 +474,15 @@ function harnessFor(pkg, mod, read, opts) {
|
|
|
474
474
|
fs.mkdirSync(path.dirname(path.join(work, l)), { recursive: true });
|
|
475
475
|
node('node:fs').symlinkSync(to, path.join(work, l));
|
|
476
476
|
}
|
|
477
|
-
|
|
477
|
+
// A source the reader can parse can still send swiftc into expensive type checking.
|
|
478
|
+
// Two buildCheck attempts must leave ample room below the reader fuzz's 300 s line.
|
|
479
|
+
const limit = Math.min(compileLimit(), 60_000);
|
|
480
|
+
const built = buildCheck('swift build', () => cp.execFileSync(swiftOf(opts), ['build', '--product', 'GdpHarness', '--package-path', work], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 1 << 28, timeout: limit, killSignal: 'SIGKILL' }), e => `${e.stdout ?? ''}\n${e.stderr ?? ''}`.split('\n').filter(l => /\.swift:\d+:\d+: error:/.test(l)), l => { const m = /([^\s]+\.swift):(\d+):\d+: error:/.exec(l); if (!m)
|
|
478
481
|
return false; const r = path.relative(work, m[1]); if (r.startsWith('GdpHarness/'))
|
|
479
482
|
return false; const n = own.get(r); return n === undefined || Number(m[2]) <= n; });
|
|
480
483
|
if (!('ok' in built))
|
|
481
|
-
return { cmd: 'false', args: [], hello: {},
|
|
484
|
+
return { cmd: 'false', args: [], hello: {},
|
|
485
|
+
error: built.why + (built.kind === 'harness' ? `; Swift compiler build-check limit ${limit / 1000} s per attempt (source not verified)` : ''), kind: built.kind };
|
|
482
486
|
const bin = cp.execFileSync(swiftOf(opts), ['build', '--package-path', work, '--show-bin-path'], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
|
|
483
487
|
return { cmd: `${bin}/GdpHarness`, args: [], hello: {} };
|
|
484
488
|
}
|
package/dist/core/extract.d.ts
CHANGED
|
@@ -4,18 +4,27 @@ import { type Model, Refusal, type Source, type Term } from './extract-read.js';
|
|
|
4
4
|
import { type ReadOptions } from './extract-shapes.js';
|
|
5
5
|
import { type Sorts } from './extract-print.js';
|
|
6
6
|
import { type CheckOptions, type Evidence } from './extract-check.js';
|
|
7
|
+
import { type OrmOptions } from './extract-orm.js';
|
|
8
|
+
export type { OrmOptions } from './extract-orm.js';
|
|
7
9
|
export { proveRule, proveSteps } from './dsl.js';
|
|
8
10
|
export type ExtractOptions = Omit<ReadOptions, 'entry' | 'functions'> & {
|
|
9
11
|
entry?: string | string[];
|
|
10
12
|
/** @deprecated entry: [...] (the same: several functions over one record, the entry the first) */
|
|
11
13
|
functions?: string[];
|
|
12
14
|
file?: string;
|
|
15
|
+
orm?: OrmOptions;
|
|
13
16
|
shape?: 'class' | 'functions';
|
|
17
|
+
mode?: 'standalone';
|
|
14
18
|
domains?: Record<string, 'nat' | 'int'>;
|
|
15
19
|
check?: CheckOptions;
|
|
16
20
|
};
|
|
17
21
|
export type Extraction = {
|
|
18
22
|
ok: boolean;
|
|
23
|
+
initializers?: {
|
|
24
|
+
entry: string;
|
|
25
|
+
name: string;
|
|
26
|
+
selectors: string[];
|
|
27
|
+
};
|
|
19
28
|
quiet?: string;
|
|
20
29
|
replay?: (run: {
|
|
21
30
|
params: Record<string, number>;
|
package/dist/core/extract.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
// read the same way (`extractXState`, a machine or a function that makes one, its actors, timers and eventless
|
|
19
19
|
// transitions included).
|
|
20
20
|
//
|
|
21
|
-
// The subset: numbers (integers: a literal that isn't one is refused; division only as Math.floor or
|
|
21
|
+
// The subset: numbers (integers: a literal that isn't one is refused; division only as Math.floor, ceil or trunc of
|
|
22
22
|
// x / k for a constant k, a fraction being a binary float the code rounds; % by a constant of a natural), booleans,
|
|
23
23
|
// string-literal unions, strings (set, compared, truthy where not empty), null and undefined where a value may be
|
|
24
24
|
// missing, records and nested records (spreads, shorthand), Map and Record state keyed by numbers or strings (get,
|
|
@@ -42,9 +42,10 @@ import { compileFunction, walk } from "./machine.js";
|
|
|
42
42
|
import * as I from "./extract-ir.js";
|
|
43
43
|
import { PASS } from "./extract-ir.js";
|
|
44
44
|
import { Refusal, placed, sourceOf, syntaxError, tooDeep } from "./extract-read.js";
|
|
45
|
-
import { isFactory, isSlice, readClass, readFactory, readFunctions, readSlice } from "./extract-shapes.js";
|
|
45
|
+
import { isFactory, isSlice, readClass, readFactory, readFunctions, readSlice, readStandalone } from "./extract-shapes.js";
|
|
46
46
|
import { kindOf, mapEmpty, mapKind, natOK, pb, pidx, pk, pnum, pterm, sortsOf } from "./extract-print.js";
|
|
47
47
|
import { check } from "./extract-check.js";
|
|
48
|
+
import { extractOrm } from "./extract-orm.js";
|
|
48
49
|
// (a rule read is proven from the same import: proveRule(x.rule!, [x.rule!.law(...)]))
|
|
49
50
|
export { proveRule, proveSteps } from "./dsl.js";
|
|
50
51
|
// The names of a model read from TypeScript (the state's layout, each request's arguments, each method's result).
|
|
@@ -71,6 +72,8 @@ export function namesOf(m) {
|
|
|
71
72
|
const arg = (a, at, method) => {
|
|
72
73
|
if (a.k === 'input')
|
|
73
74
|
out.push({ code: at, rule: a.name, role: 'input', method });
|
|
75
|
+
else if (a.k === 'maybe-bool')
|
|
76
|
+
out.push({ code: at, rule: a.name, none: a.missing, role: 'input', method });
|
|
74
77
|
else if (a.k === 'rec')
|
|
75
78
|
for (const [f, x] of a.fields)
|
|
76
79
|
arg(x, `${at}.${f}`, method);
|
|
@@ -97,12 +100,27 @@ export function extract(at, opts = {}) {
|
|
|
97
100
|
try {
|
|
98
101
|
;
|
|
99
102
|
({ code, file } = sourceOf(at, opts.file, 'input.ts'));
|
|
103
|
+
if (opts.mode !== undefined && opts.mode !== 'standalone')
|
|
104
|
+
throw new Refusal(file, `unsupported extraction mode: ${String(opts.mode)}`);
|
|
100
105
|
const bad = syntaxError(code, file);
|
|
101
106
|
if (bad)
|
|
102
107
|
throw new Refusal(file, bad);
|
|
108
|
+
if (opts.orm) {
|
|
109
|
+
if (opts.mode === 'standalone')
|
|
110
|
+
throw new Refusal(file, 'standalone mode cannot use ORM');
|
|
111
|
+
if (typeof at !== 'string' || at.includes('\n') || !/\.[cm]?[jt]sx?$/.test(at))
|
|
112
|
+
throw new Refusal(file, 'ORM checking requires the original module on disk');
|
|
113
|
+
return extractOrm(file, code, { ...opts, orm: opts.orm });
|
|
114
|
+
}
|
|
103
115
|
const fns = Array.isArray(opts.entry) ? opts.entry : opts.functions;
|
|
104
116
|
const o = { ...opts, entry: (Array.isArray(opts.entry) ? opts.entry[0] : opts.entry) ?? fns?.[0] ?? '', ...(fns ? { functions: fns } : {}) };
|
|
105
|
-
|
|
117
|
+
if (opts.mode === 'standalone') {
|
|
118
|
+
if (!o.entry || Array.isArray(opts.entry) || opts.functions || opts.shape || opts.orm)
|
|
119
|
+
throw new Refusal(file, 'standalone mode needs exactly one named function and no other shape');
|
|
120
|
+
model = readStandalone(code, placed(file), o);
|
|
121
|
+
}
|
|
122
|
+
else
|
|
123
|
+
model = o.entry ? readModel(code, file, o, opts.shape) : inferred(code, file, o, opts.shape);
|
|
106
124
|
model.file = file;
|
|
107
125
|
}
|
|
108
126
|
catch (e) {
|
|
@@ -112,6 +130,8 @@ export function extract(at, opts = {}) {
|
|
|
112
130
|
return { ok: false, refusals: [{ where: opts.file ?? (typeof at === 'string' && !at.includes('\n') ? at : 'input.ts'), what: 'the source nests too deeply to read' }], notes };
|
|
113
131
|
throw e;
|
|
114
132
|
}
|
|
133
|
+
if (model.standalone && Object.entries(model.standaloneDomains ?? {}).some(([n, xs]) => opts.domains?.[n] === 'nat' && xs.some(x => x < 0)))
|
|
134
|
+
return { ok: false, refusals: [{ where: file, what: 'standalone: a natural domain contradicts the declared negative numeric literals' }], notes, model };
|
|
115
135
|
return { ...fromModel(model, file, opts.domains, notes, (rule, sorts) => check(code, file, model, rule, sorts, { ...opts.check, ...(opts.files ? { files: opts.files } : {}), ...(opts.domains ? { given: opts.domains } : {}) })), names: namesOf(model) };
|
|
116
136
|
}
|
|
117
137
|
function readModel(code, file, opts, shape) {
|
|
@@ -209,7 +229,7 @@ function datesInRange(m, sorts) {
|
|
|
209
229
|
// The module a user keeps: the rule, with what it was read from and how it was checked.
|
|
210
230
|
export const toSource = (x) => x.source ?? '';
|
|
211
231
|
// The source is the rule: it is evaluated with the builders, so what is checked is what is printed.
|
|
212
|
-
const NAMES = ['rule', 'nat', 'int', 'bool', 'oneOf', 'str', 'record', 'when', 'min', 'max', 'all', 'any', 'not', 'yes', 'no', 'lit', 'intern', 'Int', 'desc'];
|
|
232
|
+
const NAMES = ['rule', 'nat', 'int', 'bool', 'oneOf', 'str', 'record', 'when', 'min', 'max', 'all', 'any', 'not', 'yes', 'no', 'lit', 'intern', 'Int', 'desc', 'everyKey'];
|
|
213
233
|
function evaluate(body) {
|
|
214
234
|
const f = compileFunction([...NAMES], `return ${body}`);
|
|
215
235
|
const r = f(...NAMES.map(n => dsl[n]));
|
|
@@ -266,6 +286,10 @@ function builderOf(m, sorts) {
|
|
|
266
286
|
const params = (t) => [...I.varsOf(t).vars].filter(n => m.params.some(p => p.name === n));
|
|
267
287
|
const start = (v) => {
|
|
268
288
|
const t = m.init[v.name], ps = params(t.e), fn = (x) => (ps.length ? `({${ps.join(', ')}}) => ${x}` : x);
|
|
289
|
+
// The kernel's start expressions read parameters only, not functions (including div/mod).
|
|
290
|
+
// A narrowing cast can introduce one even when the source spells no division.
|
|
291
|
+
walk(t.e, o => { if (o.op === 'divk' || o.op === 'modk')
|
|
292
|
+
throw new Refusal(m.file ?? m.entry, `${v.name}: division or remainder in an initializer (including a wrapping conversion) is outside the reader's start-expression subset`); });
|
|
269
293
|
const at = pterm(t, P, ctx(), v.name);
|
|
270
294
|
if (v.sort.k === 'num')
|
|
271
295
|
return sorts.get(v.name) === 'nat' ? (ps.length ? fn(at) : at) : `int.from(${ps.length ? fn(at) : at})`;
|
|
@@ -287,7 +311,7 @@ function builderOf(m, sorts) {
|
|
|
287
311
|
const vars = new Set(), maps = new Set();
|
|
288
312
|
for (const x of xs)
|
|
289
313
|
I.varsOf(x, vars, maps);
|
|
290
|
-
return `{${[...new Set([...vars].filter(n => !m.leasts?.some(l => l.key === n)).map(leastOf)), ...maps].filter(n => n !== PASS).join(', ')}}`;
|
|
314
|
+
return `{${[...new Set([...vars].filter(n => !m.leasts?.some(l => l.key === n)).map(leastOf)), ...maps].filter(n => n !== PASS && n !== 'kl$' && n !== 'k$' && n !== 'j$').join(', ')}}`;
|
|
291
315
|
};
|
|
292
316
|
// The least keys: each where it holds, by what, read at the state before the step.
|
|
293
317
|
if (m.leasts?.length) {
|
|
@@ -299,10 +323,53 @@ function builderOf(m, sorts) {
|
|
|
299
323
|
const rec = (name, fs) => `record({${fs.map(f => `${f.name}: ${kindOf(f, sorts, `${name}.${f.name}`)}`).join(', ')}})`;
|
|
300
324
|
for (const q of [...(m.seqs ?? []), ...(m.folds ?? []).map(d => ({ name: d.run, fields: d.fields }))])
|
|
301
325
|
lines.push(` .carriesList(${JSON.stringify(q.name)}, ${rec(q.name, q.fields)})`);
|
|
326
|
+
// (a while loop's lists taken by an order: each one's held keys in it, and each key's place there)
|
|
327
|
+
for (const g of (m.folds ?? []).flatMap(d => d.loop?.drains ?? []))
|
|
328
|
+
lines.push(` .carriesList(${JSON.stringify(g.ord)}, record({k: nat}))`, ` .carries(${JSON.stringify(g.rk)})`);
|
|
302
329
|
for (const d of m.folds ?? []) {
|
|
303
330
|
const cell = (i, f) => ({ op: 'cell', map: d.run, key: { op: 'num', e: i }, field: f.name, ...(f.sort.k === 'choice' ? { values: f.sort.values } : {}) });
|
|
304
331
|
const eq = (i, f, t) => (t.s === 'num' ? I.cmp('=', cell(i, f), t.e) : t.s === 'bool' ? I.and(I.or(I.not(cell(i, f)), t.e), I.or(cell(i, f), I.not(t.e))) : t.s === 'str' ? I.keq(cell(i, f), t.e) : I.leq(cell(i, f), t.e));
|
|
305
|
-
const start = I.and(...d.fields.map(f => eq(I.num(0), f, d.init[f.name]))), step = I.and(...d.fields.map(f => eq(I.add(I.nvar(PASS), I.num(1)), f, d.step[f.name])));
|
|
332
|
+
const start = I.and(...d.fields.filter(f => d.init[f.name]).map(f => eq(I.num(0), f, d.init[f.name]))), step = I.and(...d.fields.filter(f => d.step[f.name]).map(f => eq(I.add(I.nvar(PASS), I.num(1)), f, d.step[f.name])));
|
|
333
|
+
if (d.loop?.cond && d.loop.drains) {
|
|
334
|
+
// A while loop's over lists by an order: its passes, each where its condition holds and none ended the loop, then
|
|
335
|
+
// the first where not; each list's held keys in the order (increasing, each held, every held one at its place,
|
|
336
|
+
// tying it), and no two that tie where the loop runs.
|
|
337
|
+
const l = d.loop, cond = l.cond, len = d.len, endC = I.substN(cond, PASS, len);
|
|
338
|
+
const text = `all(${d.run}_len.eq(${pnum(I.add(len, I.num(1)), P, ctx())}), ${pb(start, P, ctx())}, ${d.run}.every((_x, ${PASS}) => ${PASS}.lt(${pnum(len, P, ctx())}).implies(${pb(I.and(step, cond), P, ctx())})), ${pb(I.not(endC), P, ctx())})`;
|
|
339
|
+
const env = envOf(start, step, cond, endC).slice(1, -1).split(', ').filter(Boolean);
|
|
340
|
+
lines.push(` .assume((${withChoices(`{${[...new Set([...env, d.run, `${d.run}_len`])].join(', ')}}`, text, P)}) => ${text})`);
|
|
341
|
+
for (const g of l.drains) {
|
|
342
|
+
const ordAt = (x) => ({ op: 'cell', map: g.ord, key: { op: 'num', e: x }, field: 'k' }), byAt = (x) => g.by.map(b => ({ ...b, e: I.substN(b.e, 'kl$', x) }));
|
|
343
|
+
const lt = (a, b) => a.reduceRight((acc, x, j) => { const y = b[j]; return I.or(x.desc ? I.cmp('<', y.e, x.e) : I.cmp('<', x.e, y.e), I.and(I.cmp('=', x.e, y.e), acc)); }, I.F);
|
|
344
|
+
const same = (a, b) => I.and(...a.map((x, j) => I.cmp('=', x.e, b[j].e)));
|
|
345
|
+
const iv = I.nvar('i$'), jv = I.nvar('j$'), kv = I.nvar('kl$'), cnt = I.nvar(`${g.ord}_len`), place = { op: 'cell', map: g.rk, key: { op: 'num', e: kv }, field: '$item' };
|
|
346
|
+
const heldAt = (x) => I.substN(g.held, 'kl$', x);
|
|
347
|
+
const inc = I.or(I.not(I.and(I.cmp('<', iv, jv), I.cmp('<', jv, cnt))), lt(byAt(ordAt(iv)), byAt(ordAt(jv))));
|
|
348
|
+
const held = I.or(I.not(I.cmp('<', iv, cnt)), heldAt(ordAt(iv)));
|
|
349
|
+
const all = I.or(I.not(g.held), I.and(I.cmp('<', place, cnt), same(byAt(ordAt(place)), g.by)));
|
|
350
|
+
sorts.set('j$', 'nat');
|
|
351
|
+
// (two held keys at one place are one: with the list increasing, every held key is at the place of its own, and
|
|
352
|
+
// two items that tie under the order have no list, so the rule refuses there, an edge the check counts apart)
|
|
353
|
+
const rkAt = (x) => ({ op: 'cell', map: g.rk, key: { op: 'num', e: x }, field: '$item' });
|
|
354
|
+
const one = I.or(I.not(I.and(g.held, heldAt(jv), I.cmp('=', rkAt(kv), rkAt(jv)))), I.cmp('=', kv, jv));
|
|
355
|
+
// (all of it only where the loop runs: the request its method's, on its branch)
|
|
356
|
+
const gate = l.entry && !(l.entry.op === 'const' && l.entry.v) ? l.entry : undefined;
|
|
357
|
+
for (const [vs, c] of [['i$, j$', inc], ['i$', held], ['kl$', all], ['kl$, j$', one]]) {
|
|
358
|
+
const t0 = `everyKey((${vs}) => ${pb(c, P, ctx())})`, t = gate ? `any(${pb(I.not(gate), P, ctx())}, ${t0})` : t0;
|
|
359
|
+
const e = envOf(c, ...(gate ? [gate] : [])).slice(1, -1).split(', ').filter(n => Boolean(n) && n !== 'j$');
|
|
360
|
+
lines.push(` .assume((${withChoices(`{${[...new Set([...e, g.ord, `${g.ord}_len`])].join(', ')}}`, t, P)}) => ${t})`);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
if (d.back) {
|
|
366
|
+
// (from the last place down: the start at the length, each pass's output at its own place)
|
|
367
|
+
const step2 = I.and(...d.fields.filter(f => d.step[f.name]).map(f => eq(I.nvar(PASS), f, d.step[f.name]))), start2 = I.and(...d.fields.filter(f => d.init[f.name]).map(f => eq(d.len, f, d.init[f.name])));
|
|
368
|
+
const text = `all(${d.run}_len.eq(${pnum(I.add(d.len, I.num(1)), P, ctx())}), ${pb(start2, P, ctx())}, ${d.run}.every((_x, ${PASS}) => ${PASS}.lt(${pnum(d.len, P, ctx())}).implies(${pb(step2, P, ctx())})))`;
|
|
369
|
+
const env = envOf(start2, step2, d.len).slice(1, -1).split(', ').filter(Boolean);
|
|
370
|
+
lines.push(` .assume((${withChoices(`{${[...new Set([...env, d.run, `${d.run}_len`])].join(', ')}}`, text, P)}) => ${text})`);
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
306
373
|
// (the passes over the run's places: one past the list's length, a carried list's or one of the state's)
|
|
307
374
|
const len = I.add(d.len, I.num(1)), text = `all(${d.run}_len.eq(${pnum(len, P, ctx())}), ${pb(start, P, ctx())}, ${d.run}.every((_x, ${PASS}) => ${PASS}.lt(${pnum(d.len, P, ctx())}).implies(${pb(step, P, ctx())})))`;
|
|
308
375
|
const env = envOf(start, step, d.len).slice(1, -1).split(', ').filter(Boolean);
|
|
@@ -337,7 +404,7 @@ function builderOf(m, sorts) {
|
|
|
337
404
|
// Several keys written: every key at once, each cell the last write at it (k$, the key, a natural).
|
|
338
405
|
const k = { op: 'num', e: I.nvar('k$') }, ws = allW(w);
|
|
339
406
|
sorts.set('k$', 'nat');
|
|
340
|
-
const at = (x) => I.and(x.when ?? I.T, I.keq(k, x.key));
|
|
407
|
+
const at = (x) => I.and(x.when ?? I.T, x.each ? I.T : I.keq(k, x.key));
|
|
341
408
|
const has = ws.reduce((acc, x) => I.bite(at(x), x.has, acc), { op: 'cell', map: n, key: k, field: 'has' });
|
|
342
409
|
const vals = d.fields.map(f => {
|
|
343
410
|
const base = f.sort.k === 'num' ? { s: 'num', e: { op: 'cell', map: n, key: k, field: f.name } } : f.sort.k === 'choice' ? { s: 'choice', e: { op: 'cell', map: n, key: k, field: f.name, values: f.sort.values } } : { s: 'bool', e: { op: 'cell', map: n, key: k, field: f.name } };
|
|
@@ -444,6 +511,9 @@ function hoist(m, P, roots) {
|
|
|
444
511
|
const node = hoistNodes.get(k), size = k.length;
|
|
445
512
|
if ((count.get(k) ?? 0) < 2 || size < 60 || isChoice(node))
|
|
446
513
|
continue;
|
|
514
|
+
// (a term over a bound name (a key every key is written at, a pass) is printed where that name is bound)
|
|
515
|
+
if (/"name":"(k\$|kl\$|i\$)"/.test(k))
|
|
516
|
+
continue;
|
|
447
517
|
// (a product of integers kept at 0 or above only by the conditions the path is under: printed where it is read,
|
|
448
518
|
// under them, never hoisted out of them)
|
|
449
519
|
let guarded = false;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Display a concurrent source witness without losing fiber identities or operation boundaries.
|
|
2
|
+
// Kept separate from the TypeScript reader so other CLI frontends do not acquire its optional dependency.
|
|
3
|
+
import { interpret } from "./machine.js";
|
|
4
|
+
export function fiberRun(x, run, renderCall) {
|
|
5
|
+
const fibers = x.fibers ?? [], r = x.rule;
|
|
6
|
+
const go = interpret(r.machine), ps = r.encodeParams(run.params), method = new Map(r.parts.inputs).get('method');
|
|
7
|
+
let st = go.init(ps);
|
|
8
|
+
return run.trace.map(q => {
|
|
9
|
+
const f = Number(q.fiber), pc = st.maps.__gdp_pc?.get(f) ?? 0, m = method ? method.decode('method', q) : x.model?.events[0]?.call ?? 'step';
|
|
10
|
+
st = go.step(ps, st, q);
|
|
11
|
+
if (pc === 0) {
|
|
12
|
+
const sp = fibers.find(s2 => s2.name === m), args = (x.names ?? []).filter(n => n.role === 'input' && n.method === m && n.rule in q).map(n => `${n.code.split('.').pop()} = ${String(q[n.rule])}`);
|
|
13
|
+
return `fiber ${f}: ${renderCall ? renderCall(q) : `${m}(${args.join(', ')})`}${sp ? `, its step 1 of ${sp.steps}` : ''}`;
|
|
14
|
+
}
|
|
15
|
+
const sp = fibers.find(s2 => pc > s2.base && pc <= s2.base + s2.steps);
|
|
16
|
+
return `fiber ${f}: ${sp.name}, its step ${pc - sp.base} of ${sp.steps}`;
|
|
17
|
+
});
|
|
18
|
+
}
|
package/dist/core/infer.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { type Law, type Machine, type State } from './machine.js';
|
|
1
|
+
import { type Law, type Machine, type Request, type State } from './machine.js';
|
|
2
2
|
import { type StepLaw, type Verdict, proveRule } from './dsl.js';
|
|
3
3
|
type AnyRule = Parameters<typeof proveRule>[0];
|
|
4
|
+
type Env = Record<string, number>;
|
|
4
5
|
export type InferOptions = {
|
|
5
6
|
ms?: number;
|
|
6
7
|
runs?: number;
|
|
@@ -50,5 +51,7 @@ export declare const inferRates: {
|
|
|
50
51
|
efull: number;
|
|
51
52
|
};
|
|
52
53
|
export declare const inferRuns = 16000;
|
|
54
|
+
export declare function constantsOf(m: Machine, laws: Law[]): number[];
|
|
55
|
+
export declare function domainStep(m: Machine, most?: number): ((params: Env, st: State, input: Request) => State | undefined) | undefined;
|
|
53
56
|
export declare function inferLaws(target: AnyRule | Machine, laws: Law[], stepLaws?: StepLaw[], opts?: InferOptions): Inferred;
|
|
54
57
|
export {};
|