gdp-wired 0.44.0 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +445 -38
- package/dist/core/calendar.d.ts +29 -0
- package/dist/core/calendar.js +82 -0
- package/dist/core/check.js +3 -2
- package/dist/core/cli.d.ts +4 -0
- package/dist/core/cli.js +335 -39
- package/dist/core/compose.js +3 -1
- package/dist/core/counts.d.ts +5 -2
- package/dist/core/counts.js +335 -88
- 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 +8 -2
- package/dist/core/data.js +1113 -172
- 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 +39 -3
- package/dist/core/dsl.js +250 -31
- package/dist/core/effect-prims.js +2 -2
- package/dist/core/effect.d.ts +1 -4
- package/dist/core/effect.js +1 -15
- package/dist/core/ex/reader.exs +17 -1
- package/dist/core/exists.d.ts +16 -1
- package/dist/core/exists.js +447 -50
- package/dist/core/extract-c.d.ts +2 -0
- package/dist/core/extract-c.js +185 -31
- package/dist/core/extract-check.d.ts +7 -0
- package/dist/core/extract-check.js +115 -3
- package/dist/core/extract-ex.js +3 -3
- package/dist/core/extract-go-check.d.ts +1 -1
- package/dist/core/extract-go-check.js +21 -13
- package/dist/core/extract-go.d.ts +1 -0
- package/dist/core/extract-go.js +58 -9
- 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 +65 -14
- package/dist/core/extract-orm.d.ts +12 -0
- package/dist/core/extract-orm.js +244 -0
- package/dist/core/extract-print.js +23 -1
- package/dist/core/extract-py.d.ts +1 -0
- package/dist/core/extract-py.js +4 -4
- package/dist/core/extract-rb.js +3 -3
- package/dist/core/extract-read.d.ts +25 -0
- package/dist/core/extract-read.js +60 -5
- package/dist/core/extract-rs.js +22 -20
- package/dist/core/extract-shapes.js +22 -0
- package/dist/core/extract-sol.d.ts +10 -1
- package/dist/core/extract-sol.js +89 -30
- package/dist/core/extract-step.d.ts +201 -4
- package/dist/core/extract-step.js +1514 -111
- package/dist/core/extract-swift.js +24 -13
- package/dist/core/extract.d.ts +9 -0
- package/dist/core/extract.js +88 -7
- package/dist/core/fiber-run.d.ts +5 -0
- package/dist/core/fiber-run.js +18 -0
- 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.d.ts +4 -1
- package/dist/core/infer.js +1020 -246
- package/dist/core/jvm/JavaReader.java +33 -8
- package/dist/core/jvm/Jvm.java +20 -1
- package/dist/core/jvm/KtReader.java +59 -6
- package/dist/core/laws.d.ts +10 -3
- package/dist/core/laws.js +193 -14
- package/dist/core/machine.d.ts +16 -3
- package/dist/core/machine.js +212 -28
- 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 +260 -21
- package/dist/core/py/reader.py +278 -39
- package/dist/core/rb/reader.rb +52 -5
- 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 +18 -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 +63 -7
- package/dist/core/sol-concrete.d.ts +23 -0
- package/dist/core/sol-concrete.js +195 -0
- package/dist/core/solver.js +8 -5
- package/dist/core/swift/Sources/gdp-swiftreader/main.swift +50 -7
- package/dist/core/system.d.ts +62 -1
- package/dist/core/system.js +263 -4
- package/dist/core/transfer.js +39 -9
- package/dist/core/translate.js +39 -10
- package/dist/core/watch.js +51 -6
- package/dist/interchange/check.js +10 -10
- package/dist/interchange/format.d.ts +4 -0
- package/dist/interchange/format.js +24 -6
- package/dist/kernel/cdcl.d.ts +5 -0
- package/dist/kernel/cdcl.js +88 -10
- package/dist/kernel/epr.js +141 -29
- package/dist/kernel/kernel.d.ts +31 -1
- package/dist/kernel/kernel.js +391 -101
- package/dist/kernel/model-sequence.d.ts +3 -0
- package/dist/kernel/model-sequence.js +34 -0
- package/dist/kernel/prove.d.ts +30 -1
- package/dist/kernel/prove.js +481 -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.d.ts +9 -3
- package/dist/lean-kernel/emit.js +200 -66
- package/dist/lean-kernel/lean-terms.js +5 -0
- package/dist/lean-kernel/library.js +10 -10
- package/package.json +7 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Refusal, pathOf } from "./extract-read.js";
|
|
2
|
-
import { asset, entryNames, extractStep, node, stubbed } from "./extract-step.js";
|
|
1
|
+
import { Refusal, pathOf, readerRun, statedRefusal } from "./extract-read.js";
|
|
2
|
+
import { asset, buildCheck, compileLimit, entryNames, extractStep, node, stubbed } from "./extract-step.js";
|
|
3
3
|
export { proveRule, proveSteps } from "./dsl.js";
|
|
4
4
|
const env = () => globalThis.process?.env ?? {};
|
|
5
5
|
const errText = (e) => { const ls = `${e.stdout ?? ''}\n${e.stderr ?? ''}`.split('\n'); return (ls.filter(l => /\berror:/.test(l)).length ? ls.filter(l => /\berror:/.test(l)) : ls.filter(l => /error|fatal/i.test(l))).slice(0, 4).join(' | ').slice(0, 900) || String(e.message).slice(0, 300); };
|
|
@@ -97,10 +97,10 @@ export function readSwift(at, names, o = {}) {
|
|
|
97
97
|
const pkg = swiftPackage(at, o);
|
|
98
98
|
let out;
|
|
99
99
|
try {
|
|
100
|
-
out = cp.execFileSync(swiftReader(o), [pkg.root, pkg.file ?? '-', names.length ? names.join(',') : '-', o.ctor === undefined ? '-' : String(o.ctor), ...pkg.files], { encoding: 'utf8', maxBuffer: 1 << 29, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
100
|
+
out = cp.execFileSync(swiftReader(o), [pkg.root, pkg.file ?? '-', names.length ? names.join(',') : '-', o.ctor === undefined ? '-' : String(o.ctor), ...pkg.files], { encoding: 'utf8', maxBuffer: 1 << 29, stdio: ['ignore', 'pipe', 'pipe'], ...readerRun() });
|
|
101
101
|
}
|
|
102
102
|
catch (e) {
|
|
103
|
-
throw new Refusal(at, `the Swift reader didn't run (${errText(e)})`);
|
|
103
|
+
throw new Refusal(at, statedRefusal(e) ?? `the Swift reader didn't run (${errText(e)})`);
|
|
104
104
|
}
|
|
105
105
|
const mod = JSON.parse(out);
|
|
106
106
|
mod.module = pkg.target;
|
|
@@ -257,10 +257,13 @@ function harnessCode(g, mod, read, cls) {
|
|
|
257
257
|
// the request; those left out doing nothing; any other one a crash, which the check reports).
|
|
258
258
|
const fakes = [], fakeOf = new Map();
|
|
259
259
|
const init = mod.funcs[cls.methods.__init__ ?? ''], ctorParams = init?.params.filter(p => !p.self) ?? [];
|
|
260
|
+
// (an argument of a protocol of the files read that nothing the rule keeps reads: a fake as a store's, doing nothing)
|
|
261
|
+
const protoOf = (n) => { const pa = ctorParams.find(p => p.name === n), pt = pa?.t.k === 'opt' ? pa.t.of : pa?.t; return pt?.k === 'rec' ? mod.recs[pt.name] : undefined; };
|
|
262
|
+
const faked = (n, a) => a?.k === 'store' || (a?.k === 'inert' && !!protoOf(n)?.swift?.reqs);
|
|
260
263
|
for (const [name, a] of read.ctor) {
|
|
261
|
-
if (a
|
|
264
|
+
if (!faked(name, a))
|
|
262
265
|
continue;
|
|
263
|
-
const
|
|
266
|
+
const pr = protoOf(name);
|
|
264
267
|
if (!pr?.swift?.reqs)
|
|
265
268
|
throw new Refusal(cls.p, `${cls.short}(${name}): an injected dependency of a protocol outside the files read (the check can't make one)`);
|
|
266
269
|
if (pr.swift.assoc)
|
|
@@ -297,7 +300,7 @@ function harnessCode(g, mod, read, cls) {
|
|
|
297
300
|
const ctor = sw.ctor ?? { labels: [], throws: false, types: [] };
|
|
298
301
|
const made = ctorParams.map((pa, i) => {
|
|
299
302
|
const a = read.ctor.find(([n]) => n === pa.name)?.[1], lab = ctor.labels[i] ?? '_', arg = (x) => (lab === '_' ? x : `${lab}: ${x}`);
|
|
300
|
-
if (a
|
|
303
|
+
if (faked(pa.name, a))
|
|
301
304
|
return arg(`${fakeOf.get(pa.name)}({ let __s = __GdpStore(); __gdpS.cur[${JSON.stringify(pa.name)}] = __s; return __s }())`);
|
|
302
305
|
return arg(conv(pa.t, `a?[${i}]?[1]`, mod));
|
|
303
306
|
});
|
|
@@ -435,6 +438,11 @@ function harnessFor(pkg, mod, read, opts) {
|
|
|
435
438
|
let et = changed.get(ef) ?? text(ef);
|
|
436
439
|
if (cls.swift.kind === 'actor')
|
|
437
440
|
et = et.replace(new RegExp(`\\bactor(\\s+${cls.short}\\b)`), 'final class$1').replace(/\bnonisolated(\(unsafe\))?\s+/g, '');
|
|
441
|
+
// (the lines of the code itself in each file the check appends to: an error past them is the harness's)
|
|
442
|
+
const own = new Map();
|
|
443
|
+
own.set(rel(ef), et.split('\n').length);
|
|
444
|
+
for (const f of g.edits.keys())
|
|
445
|
+
own.set(rel(f), (changed.get(f) ?? text(f)).split('\n').length);
|
|
438
446
|
changed.set(ef, `${et}\n${code.entry}`);
|
|
439
447
|
for (const [f, exts] of g.edits)
|
|
440
448
|
changed.set(f, `${changed.get(f) ?? text(f)}\n${exts.join('\n')}\n`);
|
|
@@ -466,12 +474,15 @@ function harnessFor(pkg, mod, read, opts) {
|
|
|
466
474
|
fs.mkdirSync(path.dirname(path.join(work, l)), { recursive: true });
|
|
467
475
|
node('node:fs').symlinkSync(to, path.join(work, l));
|
|
468
476
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
return
|
|
474
|
-
|
|
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)
|
|
481
|
+
return false; const r = path.relative(work, m[1]); if (r.startsWith('GdpHarness/'))
|
|
482
|
+
return false; const n = own.get(r); return n === undefined || Number(m[2]) <= n; });
|
|
483
|
+
if (!('ok' in built))
|
|
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 };
|
|
475
486
|
const bin = cp.execFileSync(swiftOf(opts), ['build', '--package-path', work, '--show-bin-path'], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
|
|
476
487
|
return { cmd: `${bin}/GdpHarness`, args: [], hello: {} };
|
|
477
488
|
}
|
package/dist/core/extract.d.ts
CHANGED
|
@@ -4,18 +4,26 @@ 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';
|
|
14
17
|
domains?: Record<string, 'nat' | 'int'>;
|
|
15
18
|
check?: CheckOptions;
|
|
16
19
|
};
|
|
17
20
|
export type Extraction = {
|
|
18
21
|
ok: boolean;
|
|
22
|
+
initializers?: {
|
|
23
|
+
entry: string;
|
|
24
|
+
name: string;
|
|
25
|
+
selectors: string[];
|
|
26
|
+
};
|
|
19
27
|
quiet?: string;
|
|
20
28
|
replay?: (run: {
|
|
21
29
|
params: Record<string, number>;
|
|
@@ -62,6 +70,7 @@ export type Name = {
|
|
|
62
70
|
export declare function namesOf(m: Model): Name[];
|
|
63
71
|
export declare function extract(at: Source, opts?: ExtractOptions): Extraction;
|
|
64
72
|
export declare function fromModel(model: Model, file: string, domains: Record<string, 'nat' | 'int'> | undefined, notes: string[], run: (rule: Rule, sorts: Sorts) => Evidence): Extraction;
|
|
73
|
+
export declare const HARNESS_FAILED = "the check's harness failed, twice (a request past its time or its transport, not the code): ";
|
|
65
74
|
export declare const toSource: (x: Extraction) => string;
|
|
66
75
|
export type { Evidence, Model, Term };
|
|
67
76
|
export { Refusal };
|
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,
|
|
@@ -41,10 +41,11 @@ import * as dsl from "./dsl.js";
|
|
|
41
41
|
import { compileFunction, walk } from "./machine.js";
|
|
42
42
|
import * as I from "./extract-ir.js";
|
|
43
43
|
import { PASS } from "./extract-ir.js";
|
|
44
|
-
import { Refusal, placed, sourceOf } from "./extract-read.js";
|
|
44
|
+
import { Refusal, placed, sourceOf, syntaxError, tooDeep } from "./extract-read.js";
|
|
45
45
|
import { isFactory, isSlice, readClass, readFactory, readFunctions, readSlice } 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).
|
|
@@ -97,6 +98,14 @@ export function extract(at, opts = {}) {
|
|
|
97
98
|
try {
|
|
98
99
|
;
|
|
99
100
|
({ code, file } = sourceOf(at, opts.file, 'input.ts'));
|
|
101
|
+
const bad = syntaxError(code, file);
|
|
102
|
+
if (bad)
|
|
103
|
+
throw new Refusal(file, bad);
|
|
104
|
+
if (opts.orm) {
|
|
105
|
+
if (typeof at !== 'string' || at.includes('\n') || !/\.[cm]?[jt]sx?$/.test(at))
|
|
106
|
+
throw new Refusal(file, 'ORM checking requires the original module on disk');
|
|
107
|
+
return extractOrm(file, code, { ...opts, orm: opts.orm });
|
|
108
|
+
}
|
|
100
109
|
const fns = Array.isArray(opts.entry) ? opts.entry : opts.functions;
|
|
101
110
|
const o = { ...opts, entry: (Array.isArray(opts.entry) ? opts.entry[0] : opts.entry) ?? fns?.[0] ?? '', ...(fns ? { functions: fns } : {}) };
|
|
102
111
|
model = o.entry ? readModel(code, file, o, opts.shape) : inferred(code, file, o, opts.shape);
|
|
@@ -105,6 +114,8 @@ export function extract(at, opts = {}) {
|
|
|
105
114
|
catch (e) {
|
|
106
115
|
if (e instanceof Refusal)
|
|
107
116
|
return { ok: false, refusals: [{ where: e.where, what: e.what }], notes };
|
|
117
|
+
if (tooDeep(e))
|
|
118
|
+
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 };
|
|
108
119
|
throw e;
|
|
109
120
|
}
|
|
110
121
|
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) };
|
|
@@ -163,10 +174,16 @@ export function fromModel(model, file, domains, notes, run) {
|
|
|
163
174
|
if (invariants.length)
|
|
164
175
|
source = `${source}\n// What every state of the code is: a law about every state is about the code's with these beside it.\nexport const ${identOf(model)}Invariants = [${invariantsOf(model, sorts).map(x => x.replace(/^r\./, `${identOf(model)}Rule.`)).join(', ')}]\n`;
|
|
165
176
|
const evidence = run(rule, sorts);
|
|
177
|
+
if (evidence.source)
|
|
178
|
+
return { ok: false, source, model, sorts, evidence, refusals: [{ where: file, what: evidence.source }], notes };
|
|
179
|
+
if (evidence.harness)
|
|
180
|
+
return { ok: false, source, model, sorts, evidence, refusals: [{ where: file, what: `${HARNESS_FAILED}${evidence.harness}` }], notes };
|
|
166
181
|
if (evidence.mismatch)
|
|
167
182
|
return { ok: false, source, model, sorts, evidence, refusals: [{ where: file, what: `the rule and the code differ: ${evidence.mismatch}` }], notes };
|
|
168
183
|
return { ok: true, rule, ...(invariants.length ? { invariants } : {}), source, model, sorts, evidence, refusals: [], notes };
|
|
169
184
|
}
|
|
185
|
+
// The check's own failure (twice): no verdict on the code, neither a difference nor a pass.
|
|
186
|
+
export const HARNESS_FAILED = 'the check\'s harness failed, twice (a request past its time or its transport, not the code): ';
|
|
170
187
|
// A Date holds a time within ±8.64e15 ms; past it the code's Date is invalid (NaN). The rule refuses a step that would
|
|
171
188
|
// set one there (as it refuses a sum past 2^53), and a start there: its claim stops at the Date's range.
|
|
172
189
|
const DATE_MAX = 8_640_000_000_000_000;
|
|
@@ -198,7 +215,7 @@ function datesInRange(m, sorts) {
|
|
|
198
215
|
// The module a user keeps: the rule, with what it was read from and how it was checked.
|
|
199
216
|
export const toSource = (x) => x.source ?? '';
|
|
200
217
|
// The source is the rule: it is evaluated with the builders, so what is checked is what is printed.
|
|
201
|
-
const NAMES = ['rule', 'nat', 'int', 'bool', 'oneOf', 'str', 'record', 'when', 'min', 'max', 'all', 'any', 'not', 'yes', 'no', 'lit', 'intern', 'Int', 'desc'];
|
|
218
|
+
const NAMES = ['rule', 'nat', 'int', 'bool', 'oneOf', 'str', 'record', 'when', 'min', 'max', 'all', 'any', 'not', 'yes', 'no', 'lit', 'intern', 'Int', 'desc', 'everyKey'];
|
|
202
219
|
function evaluate(body) {
|
|
203
220
|
const f = compileFunction([...NAMES], `return ${body}`);
|
|
204
221
|
const r = f(...NAMES.map(n => dsl[n]));
|
|
@@ -255,6 +272,10 @@ function builderOf(m, sorts) {
|
|
|
255
272
|
const params = (t) => [...I.varsOf(t).vars].filter(n => m.params.some(p => p.name === n));
|
|
256
273
|
const start = (v) => {
|
|
257
274
|
const t = m.init[v.name], ps = params(t.e), fn = (x) => (ps.length ? `({${ps.join(', ')}}) => ${x}` : x);
|
|
275
|
+
// The kernel's start expressions read parameters only, not functions (including div/mod).
|
|
276
|
+
// A narrowing cast can introduce one even when the source spells no division.
|
|
277
|
+
walk(t.e, o => { if (o.op === 'divk' || o.op === 'modk')
|
|
278
|
+
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`); });
|
|
258
279
|
const at = pterm(t, P, ctx(), v.name);
|
|
259
280
|
if (v.sort.k === 'num')
|
|
260
281
|
return sorts.get(v.name) === 'nat' ? (ps.length ? fn(at) : at) : `int.from(${ps.length ? fn(at) : at})`;
|
|
@@ -276,7 +297,7 @@ function builderOf(m, sorts) {
|
|
|
276
297
|
const vars = new Set(), maps = new Set();
|
|
277
298
|
for (const x of xs)
|
|
278
299
|
I.varsOf(x, vars, maps);
|
|
279
|
-
return `{${[...new Set([...vars].filter(n => !m.leasts?.some(l => l.key === n)).map(leastOf)), ...maps].filter(n => n !== PASS).join(', ')}}`;
|
|
300
|
+
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(', ')}}`;
|
|
280
301
|
};
|
|
281
302
|
// The least keys: each where it holds, by what, read at the state before the step.
|
|
282
303
|
if (m.leasts?.length) {
|
|
@@ -288,10 +309,53 @@ function builderOf(m, sorts) {
|
|
|
288
309
|
const rec = (name, fs) => `record({${fs.map(f => `${f.name}: ${kindOf(f, sorts, `${name}.${f.name}`)}`).join(', ')}})`;
|
|
289
310
|
for (const q of [...(m.seqs ?? []), ...(m.folds ?? []).map(d => ({ name: d.run, fields: d.fields }))])
|
|
290
311
|
lines.push(` .carriesList(${JSON.stringify(q.name)}, ${rec(q.name, q.fields)})`);
|
|
312
|
+
// (a while loop's lists taken by an order: each one's held keys in it, and each key's place there)
|
|
313
|
+
for (const g of (m.folds ?? []).flatMap(d => d.loop?.drains ?? []))
|
|
314
|
+
lines.push(` .carriesList(${JSON.stringify(g.ord)}, record({k: nat}))`, ` .carries(${JSON.stringify(g.rk)})`);
|
|
291
315
|
for (const d of m.folds ?? []) {
|
|
292
316
|
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 } : {}) });
|
|
293
317
|
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));
|
|
294
|
-
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])));
|
|
318
|
+
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])));
|
|
319
|
+
if (d.loop?.cond && d.loop.drains) {
|
|
320
|
+
// A while loop's over lists by an order: its passes, each where its condition holds and none ended the loop, then
|
|
321
|
+
// the first where not; each list's held keys in the order (increasing, each held, every held one at its place,
|
|
322
|
+
// tying it), and no two that tie where the loop runs.
|
|
323
|
+
const l = d.loop, cond = l.cond, len = d.len, endC = I.substN(cond, PASS, len);
|
|
324
|
+
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())})`;
|
|
325
|
+
const env = envOf(start, step, cond, endC).slice(1, -1).split(', ').filter(Boolean);
|
|
326
|
+
lines.push(` .assume((${withChoices(`{${[...new Set([...env, d.run, `${d.run}_len`])].join(', ')}}`, text, P)}) => ${text})`);
|
|
327
|
+
for (const g of l.drains) {
|
|
328
|
+
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) }));
|
|
329
|
+
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);
|
|
330
|
+
const same = (a, b) => I.and(...a.map((x, j) => I.cmp('=', x.e, b[j].e)));
|
|
331
|
+
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' };
|
|
332
|
+
const heldAt = (x) => I.substN(g.held, 'kl$', x);
|
|
333
|
+
const inc = I.or(I.not(I.and(I.cmp('<', iv, jv), I.cmp('<', jv, cnt))), lt(byAt(ordAt(iv)), byAt(ordAt(jv))));
|
|
334
|
+
const held = I.or(I.not(I.cmp('<', iv, cnt)), heldAt(ordAt(iv)));
|
|
335
|
+
const all = I.or(I.not(g.held), I.and(I.cmp('<', place, cnt), same(byAt(ordAt(place)), g.by)));
|
|
336
|
+
sorts.set('j$', 'nat');
|
|
337
|
+
// (two held keys at one place are one: with the list increasing, every held key is at the place of its own, and
|
|
338
|
+
// two items that tie under the order have no list, so the rule refuses there, an edge the check counts apart)
|
|
339
|
+
const rkAt = (x) => ({ op: 'cell', map: g.rk, key: { op: 'num', e: x }, field: '$item' });
|
|
340
|
+
const one = I.or(I.not(I.and(g.held, heldAt(jv), I.cmp('=', rkAt(kv), rkAt(jv)))), I.cmp('=', kv, jv));
|
|
341
|
+
// (all of it only where the loop runs: the request its method's, on its branch)
|
|
342
|
+
const gate = l.entry && !(l.entry.op === 'const' && l.entry.v) ? l.entry : undefined;
|
|
343
|
+
for (const [vs, c] of [['i$, j$', inc], ['i$', held], ['kl$', all], ['kl$, j$', one]]) {
|
|
344
|
+
const t0 = `everyKey((${vs}) => ${pb(c, P, ctx())})`, t = gate ? `any(${pb(I.not(gate), P, ctx())}, ${t0})` : t0;
|
|
345
|
+
const e = envOf(c, ...(gate ? [gate] : [])).slice(1, -1).split(', ').filter(n => Boolean(n) && n !== 'j$');
|
|
346
|
+
lines.push(` .assume((${withChoices(`{${[...new Set([...e, g.ord, `${g.ord}_len`])].join(', ')}}`, t, P)}) => ${t})`);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
if (d.back) {
|
|
352
|
+
// (from the last place down: the start at the length, each pass's output at its own place)
|
|
353
|
+
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])));
|
|
354
|
+
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())})))`;
|
|
355
|
+
const env = envOf(start2, step2, d.len).slice(1, -1).split(', ').filter(Boolean);
|
|
356
|
+
lines.push(` .assume((${withChoices(`{${[...new Set([...env, d.run, `${d.run}_len`])].join(', ')}}`, text, P)}) => ${text})`);
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
295
359
|
// (the passes over the run's places: one past the list's length, a carried list's or one of the state's)
|
|
296
360
|
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())})))`;
|
|
297
361
|
const env = envOf(start, step, d.len).slice(1, -1).split(', ').filter(Boolean);
|
|
@@ -326,7 +390,7 @@ function builderOf(m, sorts) {
|
|
|
326
390
|
// Several keys written: every key at once, each cell the last write at it (k$, the key, a natural).
|
|
327
391
|
const k = { op: 'num', e: I.nvar('k$') }, ws = allW(w);
|
|
328
392
|
sorts.set('k$', 'nat');
|
|
329
|
-
const at = (x) => I.and(x.when ?? I.T, I.keq(k, x.key));
|
|
393
|
+
const at = (x) => I.and(x.when ?? I.T, x.each ? I.T : I.keq(k, x.key));
|
|
330
394
|
const has = ws.reduce((acc, x) => I.bite(at(x), x.has, acc), { op: 'cell', map: n, key: k, field: 'has' });
|
|
331
395
|
const vals = d.fields.map(f => {
|
|
332
396
|
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 } };
|
|
@@ -337,7 +401,21 @@ function builderOf(m, sorts) {
|
|
|
337
401
|
sorts.delete('k$');
|
|
338
402
|
continue;
|
|
339
403
|
}
|
|
340
|
-
|
|
404
|
+
// (a field printed where the key is held; where that reading differs from the term itself, by cases, so a key the
|
|
405
|
+
// step leaves unheld holds what it writes there: a delete's defaults)
|
|
406
|
+
const vals = d.fields.map(f => {
|
|
407
|
+
const t = w.vals[f.name], at = `${n}.${f.name}`, yes = pterm(t, P, { m, sorts, atoms: [w.has] }, at);
|
|
408
|
+
if (w.has.op === 'const' || yes === pterm(t, P, ctx(), at))
|
|
409
|
+
return `${f.name}: ${yes}`;
|
|
410
|
+
let no;
|
|
411
|
+
try {
|
|
412
|
+
no = pterm(t, P, { m, sorts, atoms: [I.not(w.has)] }, at);
|
|
413
|
+
}
|
|
414
|
+
catch {
|
|
415
|
+
return `${f.name}: ${pterm(t, P, ctx(), at)}`;
|
|
416
|
+
}
|
|
417
|
+
return `${f.name}: when(${pb(w.has, P, ctx())}, ${yes}, ${no})`;
|
|
418
|
+
});
|
|
341
419
|
outs.push([n, `${n}.set(${pk(w.key, P, ctx())}, {${[`has: ${pb(w.has, P, ctx())}`, ...vals].join(', ')}})`]);
|
|
342
420
|
}
|
|
343
421
|
// A list's write: its apply over the operations by cases (each under its condition).
|
|
@@ -419,6 +497,9 @@ function hoist(m, P, roots) {
|
|
|
419
497
|
const node = hoistNodes.get(k), size = k.length;
|
|
420
498
|
if ((count.get(k) ?? 0) < 2 || size < 60 || isChoice(node))
|
|
421
499
|
continue;
|
|
500
|
+
// (a term over a bound name (a key every key is written at, a pass) is printed where that name is bound)
|
|
501
|
+
if (/"name":"(k\$|kl\$|i\$)"/.test(k))
|
|
502
|
+
continue;
|
|
422
503
|
// (a product of integers kept at 0 or above only by the conditions the path is under: printed where it is read,
|
|
423
504
|
// under them, never hoisted out of them)
|
|
424
505
|
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/fresh.d.ts
CHANGED
|
@@ -4,6 +4,6 @@ export type FreshLaw = {
|
|
|
4
4
|
law: Law;
|
|
5
5
|
text: string;
|
|
6
6
|
};
|
|
7
|
-
export declare
|
|
7
|
+
export declare const freshLaws: (m: Machine, kinds: Law[], draws: Draws, opts?: {
|
|
8
8
|
ms?: number;
|
|
9
|
-
})
|
|
9
|
+
}) => FreshLaw[];
|
package/dist/core/fresh.js
CHANGED
|
@@ -9,10 +9,14 @@
|
|
|
9
9
|
// (Houdini: a candidate whose goal fails is dropped, the rest proven again). Nothing new is trusted: what is kept is
|
|
10
10
|
// laws the kernel proves.
|
|
11
11
|
import { evalC, interpret, seeded } from "./machine.js";
|
|
12
|
-
import { clock,
|
|
12
|
+
import { clock, counted, fullRate, proveSetFast, withDeadline } from "../kernel/prove.js";
|
|
13
13
|
import { allowed, watch } from "./watch.js";
|
|
14
14
|
const v = (name) => ({ op: 'var', name }), get = (map, key) => ({ op: 'get', map, key });
|
|
15
|
-
|
|
15
|
+
// The budget is counted (kernel/prove.ts's cost model), as the invariant search's is: what is found is the same on any
|
|
16
|
+
// machine. Houdini's set proofs are proveSetFast's, each round reusing the goals the last one settled.
|
|
17
|
+
// (the deadline too, so a round's goals stop at the budget's end)
|
|
18
|
+
export const freshLaws = (m, kinds, draws, opts = {}) => counted(fullRate, () => withDeadline(clock() + (opts.ms ?? 5000), () => fresh(m, kinds, draws, opts)), true);
|
|
19
|
+
function fresh(m, kinds, draws, opts) {
|
|
16
20
|
const maps = Object.entries(m.maps ?? {}).filter(([n]) => !(m.inputMaps ?? []).includes(n));
|
|
17
21
|
if (!maps.length || m.history)
|
|
18
22
|
return [];
|
|
@@ -90,7 +94,7 @@ export function freshLaws(m, kinds, draws, opts = {}) {
|
|
|
90
94
|
while (alive.length && clock() < until) {
|
|
91
95
|
let out;
|
|
92
96
|
try {
|
|
93
|
-
out =
|
|
97
|
+
out = proveSetFast(m, [...kinds, ...alive.map(f => f.law)]);
|
|
94
98
|
}
|
|
95
99
|
catch {
|
|
96
100
|
return [];
|
package/dist/core/go/reader.go
CHANGED
|
@@ -56,7 +56,7 @@ func main() {
|
|
|
56
56
|
for _, f := range files {
|
|
57
57
|
a, err := parser.ParseFile(fset, f, nil, parser.SkipObjectResolution)
|
|
58
58
|
if err != nil {
|
|
59
|
-
|
|
59
|
+
refuse("the source doesn't parse: " + strings.SplitN(err.Error(), "\n", 2)[0])
|
|
60
60
|
}
|
|
61
61
|
asts = append(asts, a)
|
|
62
62
|
}
|
|
@@ -283,6 +283,12 @@ func fail(err error) {
|
|
|
283
283
|
os.Exit(1)
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
+
// A source the reader can't read, said so (core/extract-read.ts's statedRefusal).
|
|
287
|
+
func refuse(why string) {
|
|
288
|
+
fmt.Fprintln(os.Stderr, "gdp: refused: "+why)
|
|
289
|
+
os.Exit(3)
|
|
290
|
+
}
|
|
291
|
+
|
|
286
292
|
// --- positions ------------------------------------------------------------------------------------------------------
|
|
287
293
|
func pos(p token.Pos) string {
|
|
288
294
|
if !p.IsValid() {
|
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 {};
|