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
1
|
import { Outside, constantsOf, draw, drive, evalTerm } from "./extract-check.js";
|
|
2
|
-
import { openHarness, stubbed } from "./extract-step.js";
|
|
2
|
+
import { buildCheck, builtEvidence, compileLimit, openHarness, stopped, stubbed } from "./extract-step.js";
|
|
3
3
|
import { node } from "./extract-go.js";
|
|
4
4
|
// --- the harness ------------------------------------------------------------------------------------------------------
|
|
5
5
|
// Go source beside the package: a state set from JSON and read back as JSON, leaf by leaf; each method called with its
|
|
@@ -61,7 +61,8 @@ function harness(pkg, read, m, discard) {
|
|
|
61
61
|
// A big.Int's nil flag and a map's are set with their values; a left-out field is compared, not set.
|
|
62
62
|
case 'bignil':
|
|
63
63
|
case 'mapnil':
|
|
64
|
-
case 'frame':
|
|
64
|
+
case 'frame':
|
|
65
|
+
case 'sink': break;
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
const frames = read.leaves.filter(l => l.kind === 'frame');
|
|
@@ -338,15 +339,12 @@ export function checkGo(dir, pkg, read, r, sorts, gopts) {
|
|
|
338
339
|
}
|
|
339
340
|
if (Object.keys(over).length)
|
|
340
341
|
fs.writeFileSync(`${work}/overlay.json`, JSON.stringify({ Replace: over }));
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
const err = String(x.stderr ?? x.message);
|
|
348
|
-
return { ...empty, mismatch: `the package doesn't build with the check's harness: ${err.split('\n').filter(Boolean).slice(0, 6).join(' | ')}` };
|
|
349
|
-
}
|
|
342
|
+
// The harness's own package in -coverpkg too: the counters are written only where main is instrumented.
|
|
343
|
+
// (a rewritten copy isn't instrumented with -cover, which reads the files as they are: no arms counted then)
|
|
344
|
+
// (go's errors, file:line:col: ..., the code's own files the source's; the harness's file and main the check's)
|
|
345
|
+
const built = buildCheck('go build', () => cp.execFileSync('go', ['build', ...(fs.existsSync(`${work}/overlay.json`) ? [`-overlay=${work}/overlay.json`] : ['-cover', `-coverpkg=${importPath},${mod.module}/${mainDir.split('/').pop()}`]), '-o', `${work}/harness`, `./${mainDir.split('/').pop()}`], { cwd: mod.root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], env: goEnv(), maxBuffer: 1 << 26, timeout: compileLimit(), killSignal: 'SIGKILL' }), x => String(x.stderr ?? '').split('\n').filter(l => /\.go:\d+(:\d+)?: /.test(l)), l => !/zz_gdp_harness_gen\.go:|gdpharness_\w+\/main\.go:/.test(l));
|
|
346
|
+
if (!('ok' in built))
|
|
347
|
+
return { ...empty, ...builtEvidence(built) };
|
|
350
348
|
const buildMs = Math.round(performance.now() - b0);
|
|
351
349
|
fs.mkdirSync(`${work}/cov`, { recursive: true });
|
|
352
350
|
// The blocks of the code the step reads that the requests reached (the harness's counters, written as it exits).
|
|
@@ -418,7 +416,7 @@ export function speak(work, bin, env, pkg, read, r, sorts, opts, count) {
|
|
|
418
416
|
const l = line();
|
|
419
417
|
if (l === undefined)
|
|
420
418
|
throw new Error('the harness stopped');
|
|
421
|
-
return JSON.parse(l);
|
|
419
|
+
return stopped(JSON.parse(l));
|
|
422
420
|
};
|
|
423
421
|
// A state from the harness as a snapshot (a number past the safe integers: the code leaves the rule's numbers).
|
|
424
422
|
const toSnap = (s) => {
|
|
@@ -552,7 +550,17 @@ export function speak(work, bin, env, pkg, read, r, sorts, opts, count) {
|
|
|
552
550
|
ro = -1;
|
|
553
551
|
return count();
|
|
554
552
|
}
|
|
555
|
-
|
|
553
|
+
let ev;
|
|
554
|
+
// (the harness gone, or stopped at its time limit: the check refuses, as checkStep's does)
|
|
555
|
+
try {
|
|
556
|
+
ev = drive(m, r, sorts, side, opts);
|
|
557
|
+
}
|
|
558
|
+
catch (e) {
|
|
559
|
+
if (!/^(the harness stopped|the code did not answer)/.test(e?.message ?? ''))
|
|
560
|
+
throw e;
|
|
561
|
+
ev = { runs: 0, requests: 0, fromStates: 0, probes: { conditions: 0, witnesses: 0, steps: 0 }, refusedBoth: 0, outside: 0, edge: 0, compiledAgreed: 0, coverage: { arms: 0, hit: 0, missed: [] }, ms: 0,
|
|
562
|
+
mismatch: `the check's harness: ${e.message}` };
|
|
563
|
+
}
|
|
556
564
|
return { ...ev, runMs: Math.round(performance.now() - r0) };
|
|
557
565
|
}
|
|
558
566
|
finally {
|
package/dist/core/extract-go.js
CHANGED
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
// two of the state's places or a pointer the caller gave kept in the state, a map replaced whole, two keys of one map
|
|
36
36
|
// or two writes of one list in one step.
|
|
37
37
|
import * as I from "./extract-ir.js";
|
|
38
|
-
import { Refusal, pathOf } from "./extract-read.js";
|
|
38
|
+
import { Refusal, pathOf, readerRun, statedRefusal } from "./extract-read.js";
|
|
39
39
|
import { fromModel } from "./extract.js";
|
|
40
40
|
import { asset, Stepper, iteTerm, mapWritesOf, phiP, rangeLaws, rangeOf, varTerm } from "./extract-step.js";
|
|
41
41
|
import { checkGo } from "./extract-go-check.js";
|
|
@@ -141,13 +141,18 @@ class Go {
|
|
|
141
141
|
if (tt.k === 'struct') {
|
|
142
142
|
return { e: 'struct', p: at.p, ty: String(t), fields: (tt.fields ?? []).map(g => {
|
|
143
143
|
const s = this.scalar(g.t);
|
|
144
|
-
return [g.name, typeof s === 'string' && !['ptr', 'struct', 'error'].includes(this.T(g.t).k) ? { e: 'opaque', p: at.p, why: `${g.name}: ${s}`, firm: true } : this.zero(g.t, at)];
|
|
144
|
+
return [g.name, typeof s === 'string' && !['ptr', 'struct', 'error'].includes(this.T(g.t).k) ? { e: 'opaque', p: at.p, why: `${g.name}: ${s}`, ...(this.floaty(g.t) ? { sink: true } : { firm: true }) } : this.zero(g.t, at)];
|
|
145
145
|
}) };
|
|
146
146
|
}
|
|
147
|
-
return { e: 'opaque', p: at.p, why: `a value of type ${this.tname(t)} (outside the subset)`, firm: true };
|
|
147
|
+
return { e: 'opaque', p: at.p, why: `a value of type ${this.tname(t)} (outside the subset)`, ...(this.floaty(t) ? { sink: true } : { firm: true }) };
|
|
148
148
|
}
|
|
149
|
+
// A float, or a fixed array of them: C's measurements, left out of the rule where they are only written (a value
|
|
150
|
+
// that is one, read into what the rule keeps, is refused there).
|
|
151
|
+
floaty(t) { const x = this.T(t); return x.k === 'float' || (x.k === 'array' && !!x.fixed && this.T(x.elem).k === 'float'); }
|
|
149
152
|
x(x) {
|
|
150
153
|
const at = this.at(x), c = x.c;
|
|
154
|
+
if (x.e === 'opaque')
|
|
155
|
+
return { e: 'opaque', ...at, why: x.why };
|
|
151
156
|
if (c) {
|
|
152
157
|
if (c.int !== undefined) {
|
|
153
158
|
const ty = this.intTy(x.t);
|
|
@@ -173,7 +178,7 @@ class Go {
|
|
|
173
178
|
if (!x.id?.startsWith('pkg:'))
|
|
174
179
|
return { e: 'var', ...at, n: x.id, why: `${x.n}: a variable the step doesn't set before reading` };
|
|
175
180
|
const v = this.pkg.vars.find(y => `pkg:${y.name}` === x.id), f = v?.init?.f;
|
|
176
|
-
if (v && this.T(v.t).k === 'error' && v.init?.e === 'call' && f?.e === 'sel' && ((f.pkg === 'errors' && f.n === 'New') || (f.pkg === 'fmt' && f.n === 'Errorf')))
|
|
181
|
+
if (v && this.T(v.t).k === 'error' && v.init?.e === 'call' && f?.e === 'sel' && ((f.pkg === 'errors' && f.n === 'New') || (f.pkg === 'fmt' && f.n === 'Errorf') || (f.pkg === 'github.com/pkg/errors' && (f.n === 'New' || f.n === 'Errorf'))))
|
|
177
182
|
return { e: 'errv', ...at, is: true, note: `${x.n}: an error the package makes once (errors.New): read as an error that isn't nil` };
|
|
178
183
|
return this.no(x, `${x.n}: a package variable (state every object shares)`);
|
|
179
184
|
}
|
|
@@ -329,6 +334,10 @@ class Go {
|
|
|
329
334
|
args(a, decl) { return a.map((y, i) => (decl.params[i] ? this.as(this.x(y), decl.params[i].t) : this.x(y))); }
|
|
330
335
|
builtin(x) {
|
|
331
336
|
const b = x.builtin, a = x.a ?? [], at = this.at(x);
|
|
337
|
+
// (fewer arguments than the builtin takes: a package the type checker refused, which the reader reads on)
|
|
338
|
+
const takes = { len: 1, delete: 2, min: 1, max: 1, panic: 1 }[b] ?? 0;
|
|
339
|
+
if (a.length < takes)
|
|
340
|
+
return this.no(x, `${b} with ${a.length} argument${a.length === 1 ? '' : 's'} (it takes ${takes})`);
|
|
332
341
|
switch (b) {
|
|
333
342
|
case 'len': {
|
|
334
343
|
const k = this.T(a[0].t).k;
|
|
@@ -362,7 +371,8 @@ class Go {
|
|
|
362
371
|
const f = x.f, path = f.pkg ?? '', n = f.n, at = this.at(x);
|
|
363
372
|
if (f.why)
|
|
364
373
|
return this.ext(x, f.why, n);
|
|
365
|
-
|
|
374
|
+
// (github.com/pkg/errors's New and Errorf too: always an error, as the standard library's)
|
|
375
|
+
if ((path === 'errors' && n === 'New') || (path === 'fmt' && n === 'Errorf') || (path === 'github.com/pkg/errors' && (n === 'New' || n === 'Errorf'))) {
|
|
366
376
|
// An error: not nil. Its arguments are evaluated (they may panic), its text is not compared.
|
|
367
377
|
const pre = (x.a ?? []).flatMap(a => (a.e === 'call' && a.f?.e === 'sel' && a.f.n === 'String' && a.f.k === 'method' && (this.isBigPtr(a.f.x.t) || this.isBig(a.f.x.t)) ? [this.x(a.f.x)] : a.c ? [] : [this.x(a)]));
|
|
368
378
|
return { e: 'errv', ...at, is: true, pre };
|
|
@@ -421,6 +431,8 @@ class Go {
|
|
|
421
431
|
return [{ s: 'ret', p: s.p, one: this.x(r[0]), why: 'a return of one value from a function of several' }];
|
|
422
432
|
if (!r.length && fn.results.length)
|
|
423
433
|
return [{ s: 'ret', p: s.p, bare: fn.results.map(x => x.id ?? null) }];
|
|
434
|
+
if (r.length !== fn.results.length)
|
|
435
|
+
return no(`return has ${r.length} values, but the function declares ${fn.results.length} results`);
|
|
424
436
|
return [{ s: 'ret', p: s.p, xs: r.map((e, i) => this.as(this.x(e), fn.results[i].t)) }];
|
|
425
437
|
}
|
|
426
438
|
case 'branch':
|
|
@@ -537,6 +549,12 @@ class Go {
|
|
|
537
549
|
heap.set(id, { k: 'list', decl, ops: [], origin: 'state' });
|
|
538
550
|
out.set(f.name, { t: 'list', id });
|
|
539
551
|
}
|
|
552
|
+
else if (this.floaty(f.t)) {
|
|
553
|
+
// (a float field: left out, written as the code writes it, never compared; a read of it is a float's)
|
|
554
|
+
out.set(f.name, { t: 'opaque', why: `${fp.join('.')}: a ${this.tname(f.t)} (a float, left out of the rule: nothing it keeps may read one)`, sink: true });
|
|
555
|
+
this.leaves.push({ name: '', path: fp, kind: 'sink', t: f.t, go: this.tname(f.t) });
|
|
556
|
+
g.notes.add(`${fp.join('.')}: a ${this.tname(f.t)}, a float, left out (the rule keeps nothing read from it; a float read into what it keeps is refused)`);
|
|
557
|
+
}
|
|
540
558
|
else {
|
|
541
559
|
out.set(f.name, { t: 'opaque', why: `${fp.join('.')} is a ${this.tname(f.t)}, a field outside the subset (left out of the rule)`, firm: true });
|
|
542
560
|
this.leaves.push({ name: '', path: fp, kind: 'frame', t: f.t, go: this.tname(f.t) });
|
|
@@ -634,6 +652,13 @@ class Go {
|
|
|
634
652
|
arg = { k: 'lit', value: 'context' };
|
|
635
653
|
g.notes.add(`${fn.name}(${pa.name ?? '_'}): a context.Context, passed on to the package's own functions only (the claim is for any context, the step never reading it)`);
|
|
636
654
|
}
|
|
655
|
+
else if (this.pkg.lang === 'c' || this.pkg.lang === 'cpp') {
|
|
656
|
+
// (C, C++: an argument outside the subset, a handle the code passes on to other code: the check gives a zeroed
|
|
657
|
+
// one; read here, it is refused where it is)
|
|
658
|
+
v = { t: 'opaque', why: `${fn.name}(${pa.name}): an argument of type ${pa.ts ?? this.tname(pa.t)} (${this.whyType(pa.t)}), only passed on` };
|
|
659
|
+
arg = { k: 'rec', fields: [] };
|
|
660
|
+
g.notes.add(`${fn.name}(${pa.name ?? '_'}): a ${pa.ts ?? this.tname(pa.t)}, outside the subset, only passed on to other code (the check gives a zeroed one)`);
|
|
661
|
+
}
|
|
637
662
|
else
|
|
638
663
|
return refuse(fn, `${fn.name}(${pa.name}): an argument of type ${pa.ts ?? this.tname(pa.t)} (${this.whyType(pa.t)})`);
|
|
639
664
|
if (pa.id)
|
|
@@ -735,12 +760,21 @@ function readGo1(pkg, o, go) {
|
|
|
735
760
|
const evL = { op: 'var', name: ev.name, values: names };
|
|
736
761
|
const outputs = [], results = {};
|
|
737
762
|
const finals = [], events = [], methods = [];
|
|
763
|
+
const lowered0 = (fn) => go.funcs[`${fn.recv?.type ?? ''}.${fn.name}`];
|
|
764
|
+
// (an out-parameter some path of the function returns without writing: not every statement writes *p)
|
|
765
|
+
const boxKept = (f, id) => !!id && !writesAll(f.body, id);
|
|
738
766
|
for (const fn of chosen) {
|
|
739
767
|
g.method = fn.name;
|
|
740
768
|
const sel = I.is(evL, fn.name);
|
|
741
769
|
let p = { pc: [sel], locals: new Map(), heap: new Map(heap), called: [], locks: [], defers: [] };
|
|
742
770
|
const bound = go.bindParams(fn, sel, p), args = bound.args, params = bound.params;
|
|
743
771
|
p = bound.p;
|
|
772
|
+
// (an out-parameter a path leaves as the caller gave it: what the caller gave, an input, read at the start)
|
|
773
|
+
for (const pa of fn.params) {
|
|
774
|
+
const pt = go.T(pa.t);
|
|
775
|
+
if (pt.k === 'ptr' && go.T(pt.elem).box && (go.T(pt.elem).fields ?? []).length === 1 && boxKept(lowered0(fn), pa.id))
|
|
776
|
+
g.lazyFieldIn(`in:${fn.name}_${pa.name ?? 'arg'}`, 'value', p, fn);
|
|
777
|
+
}
|
|
744
778
|
// The receiver.
|
|
745
779
|
if (fn.recv?.id)
|
|
746
780
|
p = g.bindLocal(fn.recv.id, fn.recv.ptr ? { t: 'ptr', to: { k: 'obj', id: 'this', path: [] } } : { t: 'struct', ty: String(td.t), f: fields }, fn, p);
|
|
@@ -748,7 +782,7 @@ function readGo1(pkg, o, go) {
|
|
|
748
782
|
const kept = fn.results.filter((_, i) => i !== errAt);
|
|
749
783
|
if (kept.length > 1)
|
|
750
784
|
refuse(fn, `${fn.name} returns ${kept.length} values (a result kept is one value)`);
|
|
751
|
-
const lowered =
|
|
785
|
+
const lowered = lowered0(fn);
|
|
752
786
|
g.spans.set(`${opts.entry}.${fn.name}`, [fn.p.split(':')[0], fn.span[0], fn.span[1]]);
|
|
753
787
|
const flow = g.block(lowered.body, p);
|
|
754
788
|
if (flow.brk?.length)
|
|
@@ -954,6 +988,9 @@ function readGo1(pkg, o, go) {
|
|
|
954
988
|
return { ...(pkg.ctor ? { ctor: ctorArgs } : {}), ...(g.leftOut.size ? { leftOut: [...g.leftOut] } : {}), model, edges: g.edges, unsigned, leaves: go.leaves.filter(l => l.kind === 'frame' || state.some(v => v.name === l.name) || maps.some(d => d.name === l.name) || lists.some(d => d.name === l.name)), spans: [...g.spans.values()], entry: opts.entry, methods, ...(answers.length ? { answers } : {}) };
|
|
955
989
|
}
|
|
956
990
|
function termOf(v, at) {
|
|
991
|
+
// (none: a path that ends without the value, which a reader of malformed source may join in)
|
|
992
|
+
if (!v)
|
|
993
|
+
return refuse(at, 'a path that returns no value');
|
|
957
994
|
if (v.t === 'num')
|
|
958
995
|
return { s: 'num', e: v.e };
|
|
959
996
|
if (v.t === 'bool')
|
|
@@ -969,7 +1006,7 @@ function materialize(go, p, at) {
|
|
|
969
1006
|
const self = p.heap.get('this');
|
|
970
1007
|
const seen = new Map();
|
|
971
1008
|
for (const l of go.leaves) {
|
|
972
|
-
if (l.kind === 'frame' || l.kind === 'bignil' || l.kind === 'mapnil')
|
|
1009
|
+
if (l.kind === 'frame' || l.kind === 'sink' || l.kind === 'bignil' || l.kind === 'mapnil')
|
|
973
1010
|
continue;
|
|
974
1011
|
let v = { t: 'struct', ty: self.ty, f: self.f };
|
|
975
1012
|
for (const s of l.path)
|
|
@@ -1037,12 +1074,19 @@ export function readerBinary() {
|
|
|
1037
1074
|
}
|
|
1038
1075
|
export function readGoPackage(dir) {
|
|
1039
1076
|
const cp = node('node:child_process');
|
|
1077
|
+
let pkg;
|
|
1040
1078
|
try {
|
|
1041
|
-
|
|
1079
|
+
pkg = JSON.parse(cp.execFileSync(readerBinary(), [dir], { encoding: 'utf8', maxBuffer: 1 << 29, stdio: ['ignore', 'pipe', 'pipe'], ...readerRun() }));
|
|
1042
1080
|
}
|
|
1043
1081
|
catch (e) {
|
|
1044
|
-
throw new Refusal(dir, `the Go reader didn't run (${String(e.stderr || e.message).split('\n').filter(Boolean).slice(-2).join(' | ')}): go is needed to extract Go`);
|
|
1082
|
+
throw new Refusal(dir, statedRefusal(e) ?? `the Go reader didn't run (${String(e.stderr || e.message).split('\n').filter(Boolean).slice(-2).join(' | ')}): go is needed to extract Go`);
|
|
1045
1083
|
}
|
|
1084
|
+
// (Go writes an empty slice as null: a file with no function, no type or no import)
|
|
1085
|
+
for (const k of ['files', 'funcs', 'types', 'consts', 'vars', 'errors', 'ttab'])
|
|
1086
|
+
pkg[k] ??= [];
|
|
1087
|
+
for (const f of pkg.files)
|
|
1088
|
+
f.imports ??= [];
|
|
1089
|
+
return pkg;
|
|
1046
1090
|
}
|
|
1047
1091
|
export function extractGo(at, opts = {}) {
|
|
1048
1092
|
const p = pathOf(at), dir = /\.go$/.test(p) ? p.replace(/\/[^/]*$/, '') || '.' : p;
|
|
@@ -1164,3 +1208,8 @@ function probe(pkg, name) {
|
|
|
1164
1208
|
const writes = fn.params.some(x => go.T(x.t).k === 'ptr');
|
|
1165
1209
|
return { where: fn.p, what: `${name}: a function of its arguments${writes ? ' (the objects its pointers give are the caller\'s)' : ''}, not a step of a state the subset reads (a struct and its methods)` };
|
|
1166
1210
|
}
|
|
1211
|
+
// (whether a body's first statement sets *p, the out-parameter whose id is given: then no path leaves the caller's value)
|
|
1212
|
+
function writesAll(body, id) {
|
|
1213
|
+
const first = body[0];
|
|
1214
|
+
return !!first && first.s === 'assign' && JSON.stringify(first.l ?? []).includes(JSON.stringify(id));
|
|
1215
|
+
}
|
package/dist/core/extract-ir.js
CHANGED
|
@@ -198,3 +198,18 @@ export function varsOf(x, out = new Set(), maps = new Set()) {
|
|
|
198
198
|
go(x);
|
|
199
199
|
return { vars: out, maps };
|
|
200
200
|
}
|
|
201
|
+
// A numeric variable (a bound name: a pass i$, a key k$ or kl$, which no boolean or choice shares) replaced by a term
|
|
202
|
+
// everywhere in a term, structurally.
|
|
203
|
+
export function substN(x, name, by) {
|
|
204
|
+
const go = (o) => {
|
|
205
|
+
if (Array.isArray(o))
|
|
206
|
+
return o.map(go);
|
|
207
|
+
if (!o || typeof o !== 'object')
|
|
208
|
+
return o;
|
|
209
|
+
const r = o;
|
|
210
|
+
if (r.op === 'var' && r.name === name && !('values' in r))
|
|
211
|
+
return by;
|
|
212
|
+
return Object.fromEntries(Object.entries(r).map(([k, v]) => [k, go(v)]));
|
|
213
|
+
};
|
|
214
|
+
return go(x);
|
|
215
|
+
}
|
package/dist/core/extract-jvm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Refusal, pathOf } from "./extract-read.js";
|
|
2
|
-
import { asset, entryNames, extractStep, node } from "./extract-step.js";
|
|
1
|
+
import { Refusal, pathOf, readerRun, statedRefusal } from "./extract-read.js";
|
|
2
|
+
import { asset, compileLimit, entryNames, extractStep, node } from "./extract-step.js";
|
|
3
3
|
export { proveRule, proveSteps } from "./dsl.js";
|
|
4
4
|
const here = (f) => asset(`jvm/${f}`);
|
|
5
5
|
const TOOLS = ['Jvm.java', 'JavaReader.java', 'Harness.java', 'Rt.java'];
|
|
@@ -104,10 +104,10 @@ export function readJvm(lang, file, names, o = {}) {
|
|
|
104
104
|
const t = tools(o), cpath = kt ? [t, tools(o, kt), `${kt}/kotlin-compiler.jar`, `${kt}/kotlin-stdlib.jar`, ...(o.classpath ?? [])].join(':') : t;
|
|
105
105
|
let out;
|
|
106
106
|
try {
|
|
107
|
-
out = cp.execFileSync(jdk(o).java, ['-cp', cpath, `gdp.jvm.${kt ? 'KtReader' : 'JavaReader'}`, JSON.stringify({ root, file: abs, names, classpath: (o.classpath ?? []).join(':'), sources: o.sources ?? [], ctor: o.ctor ?? null })], { encoding: 'utf8', maxBuffer: 1 << 29, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
107
|
+
out = cp.execFileSync(jdk(o).java, ['-cp', cpath, `gdp.jvm.${kt ? 'KtReader' : 'JavaReader'}`, JSON.stringify({ root, file: abs, names, classpath: (o.classpath ?? []).join(':'), sources: o.sources ?? [], ctor: o.ctor ?? null })], { encoding: 'utf8', maxBuffer: 1 << 29, stdio: ['ignore', 'pipe', 'pipe'], ...readerRun() });
|
|
108
108
|
}
|
|
109
109
|
catch (e) {
|
|
110
|
-
throw new Refusal(file, `the ${kt ? 'Kotlin' : 'Java'} reader didn't run (${errText(e)}${kt ? `; found ${found(o, kt)}` : ''}): a JDK 17 or later${kt ? ` and kotlinc ${KOTLIN} (the compiler the Kotlin reader is built against)` : ''} is needed to extract ${kt ? 'Kotlin' : 'Java'}`);
|
|
110
|
+
throw new Refusal(file, statedRefusal(e) ?? `the ${kt ? 'Kotlin' : 'Java'} reader didn't run (${errText(e)}${kt ? `; found ${found(o, kt)}` : ''}): a JDK 17 or later${kt ? ` and kotlinc ${KOTLIN} (the compiler the Kotlin reader is built against)` : ''} is needed to extract ${kt ? 'Kotlin' : 'Java'}`);
|
|
111
111
|
}
|
|
112
112
|
return JSON.parse(out);
|
|
113
113
|
}
|
|
@@ -161,26 +161,77 @@ function compiled(lang, mod, read, o, made) {
|
|
|
161
161
|
const copy = `${work}/src/${rel}`;
|
|
162
162
|
fs.mkdirSync(path.dirname(copy), { recursive: true });
|
|
163
163
|
fs.writeFileSync(copy, text);
|
|
164
|
-
const
|
|
165
|
-
|
|
164
|
+
const t = tools(o), extra = (o.classpath ?? []).join(':');
|
|
165
|
+
// (each compile within GDP_COMPILE_S seconds: past them killed, the compiler's failure)
|
|
166
|
+
const limit = compileLimit();
|
|
167
|
+
const build = (file, out, srcDir) => {
|
|
166
168
|
if (kotlin) {
|
|
167
169
|
const kt = kotlinLib(o);
|
|
168
|
-
cp.execFileSync(jdk(o).java, ['-Xss8m', '-cp', `${kt}/kotlin-compiler.jar`, 'org.jetbrains.kotlin.cli.jvm.K2JVMCompiler', '-kotlin-home', path.dirname(kt), '-nowarn', '-no-reflect', '-d', out, '-cp', [t, extra].filter(Boolean).join(':'),
|
|
169
|
-
return
|
|
170
|
+
cp.execFileSync(jdk(o).java, ['-Xss8m', '-cp', `${kt}/kotlin-compiler.jar`, 'org.jetbrains.kotlin.cli.jvm.K2JVMCompiler', '-kotlin-home', path.dirname(kt), '-nowarn', '-no-reflect', '-d', out, '-cp', [t, extra].filter(Boolean).join(':'), file, ...(o.sources ?? []).map(f => path.resolve(f))], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 1 << 26, timeout: limit, killSignal: 'SIGKILL' });
|
|
171
|
+
return [out, `${kt}/kotlin-stdlib.jar`];
|
|
170
172
|
}
|
|
171
|
-
cp.execFileSync(jdk(o).javac, ['-nowarn', '-Xlint:none', '-proc:none', '-implicit:class', '-d', out, '-sourcepath', `${
|
|
172
|
-
return
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
173
|
+
cp.execFileSync(jdk(o).javac, ['-nowarn', '-Xlint:none', '-proc:none', '-implicit:class', '-d', out, '-sourcepath', `${srcDir}:${mod.root}`, '-cp', [t, extra].filter(Boolean).join(':'), file], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 1 << 26, timeout: limit, killSignal: 'SIGKILL' });
|
|
174
|
+
return [out];
|
|
175
|
+
};
|
|
176
|
+
// What the compiler says is wrong with the code (its error lines), none where it crashed, was killed or timed out.
|
|
177
|
+
const diag = (e) => e.signal ? '' : String(e.stderr ?? '').split('\n').filter(l => /\berror:/.test(l) && !/exception|internal error|OutOfMemory/i.test(l)).slice(0, 3).join(' | ').slice(0, 900);
|
|
178
|
+
const tool = kotlin ? 'kotlinc' : 'javac';
|
|
179
|
+
// A compile: its classes, the compiler's errors about the code, or its own failure (nothing said of the code: once
|
|
180
|
+
// more, then the check's failure, not the code's).
|
|
181
|
+
const attempt = (file, out, srcDir) => {
|
|
182
|
+
let last;
|
|
183
|
+
for (let i = 0; i < 2; i++) {
|
|
184
|
+
try {
|
|
185
|
+
return { dirs: build(file, out, srcDir) };
|
|
186
|
+
}
|
|
187
|
+
catch (e) {
|
|
188
|
+
last = e;
|
|
189
|
+
if (diag(e))
|
|
190
|
+
return { diag: diag(e) };
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return { crash: `${tool} failed twice with nothing to say of the code (${errText(last)})` };
|
|
194
|
+
};
|
|
195
|
+
const c = attempt(copy, `${work}/classes`, `${work}/src`);
|
|
196
|
+
if ('crash' in c)
|
|
197
|
+
return { dirs: [], error: c.crash, kind: 'harness' };
|
|
198
|
+
// The source as it is, where the check's copy rewrote its answered calls (a call of nothing defined, rewritten, would
|
|
199
|
+
// compile): the compiler's errors in it are the source's, refused; the copy's alone, the check's rewrite's.
|
|
200
|
+
if (sites.length) {
|
|
201
|
+
const orig = `${work}/orig/${rel}`;
|
|
202
|
+
fs.mkdirSync(path.dirname(orig), { recursive: true });
|
|
203
|
+
fs.writeFileSync(orig, src);
|
|
204
|
+
const o0 = attempt(orig, `${work}/orig-classes`, `${work}/orig`);
|
|
205
|
+
if ('crash' in o0)
|
|
206
|
+
return { dirs: [], error: o0.crash, kind: 'harness' };
|
|
207
|
+
if ('diag' in o0)
|
|
208
|
+
return { dirs: [], error: `the source doesn't compile (${tool}): ${o0.diag}`, kind: 'source' };
|
|
209
|
+
if ('diag' in c)
|
|
210
|
+
return { dirs: [], error: `the check's copy of the code (its answered calls rewritten) doesn't compile (${tool}): ${c.diag}`, kind: 'harness' };
|
|
211
|
+
return { dirs: c.dirs };
|
|
176
212
|
}
|
|
213
|
+
if ('diag' in c)
|
|
214
|
+
return { dirs: [], error: `the source doesn't compile (${tool}): ${c.diag}`, kind: 'source' };
|
|
215
|
+
return { dirs: c.dirs };
|
|
177
216
|
}
|
|
178
217
|
export function extractJvm(lang, at, opts = {}) {
|
|
179
218
|
const file = pathOf(at);
|
|
180
219
|
let mod;
|
|
181
220
|
try {
|
|
221
|
+
if (lang === 'kotlin' && typeof opts.ctor === 'string')
|
|
222
|
+
throw new Refusal(file, 'Kotlin ctor selection uses an arity, not a Java signature');
|
|
182
223
|
if (opts.stores && Object.keys(opts.stores).length)
|
|
183
224
|
throw new Refusal(file, `stores: not in the ${lang === 'java' ? 'Java' : 'Kotlin'} front end yet`);
|
|
225
|
+
// (a name or a string past the class file's 65,535 bytes: no compiler makes a class of it, javac and kotlinc throw)
|
|
226
|
+
// (a missing file is the reader's to refuse, with its reason: no JDK, or the file)
|
|
227
|
+
let text = '';
|
|
228
|
+
try {
|
|
229
|
+
text = node('node:fs').readFileSync(file, 'utf8');
|
|
230
|
+
}
|
|
231
|
+
catch { /* read by the reader, which says so */ }
|
|
232
|
+
const big = /[\p{L}_$][\p{L}\p{N}_$]{21845,}|"[^"\n]{21845,}"/u.exec(text);
|
|
233
|
+
if (big && new TextEncoder().encode(big[0]).length > 65535)
|
|
234
|
+
throw new Refusal(file, `${big[0].slice(0, 20)}…: a name or a string of ${new TextEncoder().encode(big[0]).length} bytes, past the class file's 65,535 (no class can hold it)`);
|
|
184
235
|
mod = readJvm(lang, file, entryNames(opts), opts);
|
|
185
236
|
// (the shipped classes can't be rewritten: an answer, other than an injected dependency's, can't be stubbed)
|
|
186
237
|
if (opts.prebuilt)
|
|
@@ -207,7 +258,7 @@ export function extractJvm(lang, at, opts = {}) {
|
|
|
207
258
|
throw e;
|
|
208
259
|
}
|
|
209
260
|
if (c.error)
|
|
210
|
-
return { cmd: 'false', args: [], hello: {}, error: c.error };
|
|
261
|
+
return { cmd: 'false', args: [], hello: {}, error: c.error, ...(c.kind ? { kind: c.kind } : {}) };
|
|
211
262
|
const t = tools(opts);
|
|
212
263
|
return { cmd: jdk(opts).java, args: ['-cp', t, 'gdp.jvm.Harness'], hello: { jcls: j.cls, cp: [...c.dirs, ...(opts.classpath ?? [])], jctor: { params: j.ctor }, methods: j.methods, reducers: j.reducers } };
|
|
213
264
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type StepOptions } from './extract-step.js';
|
|
2
|
+
/** Explicit boundary: the first argument is the injected Prisma client or TypeORM repository. */
|
|
3
|
+
export type OrmOptions = {
|
|
4
|
+
schema: string;
|
|
5
|
+
model: string;
|
|
6
|
+
kind?: 'prisma' | 'typeorm';
|
|
7
|
+
};
|
|
8
|
+
export declare function extractOrm(file: string, code: string, opts: StepOptions & {
|
|
9
|
+
orm: OrmOptions;
|
|
10
|
+
}): import("./extract.ts").Extraction & {
|
|
11
|
+
read?: import("./extract-step.ts").StepRead;
|
|
12
|
+
};
|