gdp-wired 0.44.0 → 0.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/c/reader.js +22 -7
- package/dist/core/check.js +3 -2
- package/dist/core/cli.d.ts +1 -0
- package/dist/core/cli.js +136 -6
- package/dist/core/counts.d.ts +1 -1
- package/dist/core/counts.js +30 -12
- package/dist/core/data.d.ts +6 -1
- package/dist/core/data.js +894 -152
- package/dist/core/dsl.d.ts +2 -0
- package/dist/core/dsl.js +88 -10
- package/dist/core/effect-prims.js +2 -2
- package/dist/core/ex/reader.exs +17 -1
- package/dist/core/exists.d.ts +15 -1
- package/dist/core/exists.js +263 -41
- package/dist/core/extract-c.js +19 -12
- package/dist/core/extract-check.d.ts +6 -0
- package/dist/core/extract-check.js +49 -3
- package/dist/core/extract-ex.js +3 -3
- package/dist/core/extract-go-check.js +19 -12
- package/dist/core/extract-go.js +20 -5
- package/dist/core/extract-jvm.js +63 -14
- package/dist/core/extract-print.js +3 -0
- package/dist/core/extract-py.js +3 -3
- package/dist/core/extract-rb.js +3 -3
- package/dist/core/extract-read.d.ts +8 -0
- package/dist/core/extract-read.js +55 -0
- package/dist/core/extract-rs.js +17 -19
- package/dist/core/extract-shapes.js +20 -0
- package/dist/core/extract-sol.js +19 -8
- package/dist/core/extract-step.d.ts +50 -3
- package/dist/core/extract-step.js +289 -58
- package/dist/core/extract-swift.js +20 -13
- package/dist/core/extract.d.ts +1 -0
- package/dist/core/extract.js +27 -2
- package/dist/core/fresh.d.ts +2 -2
- package/dist/core/fresh.js +7 -3
- package/dist/core/go/reader.go +7 -1
- package/dist/core/infer.js +115 -42
- package/dist/core/jvm/JavaReader.java +10 -2
- package/dist/core/jvm/Jvm.java +17 -1
- package/dist/core/jvm/KtReader.java +57 -5
- package/dist/core/machine.d.ts +1 -2
- package/dist/core/machine.js +27 -15
- package/dist/core/py/harness.py +77 -11
- package/dist/core/py/reader.py +50 -5
- package/dist/core/rb/reader.rb +52 -5
- package/dist/core/rs/src/main.rs +10 -0
- package/dist/core/sol/harness.py +6 -3
- package/dist/core/solver.js +5 -4
- package/dist/core/system.d.ts +62 -1
- package/dist/core/system.js +262 -3
- package/dist/core/transfer.js +17 -0
- package/dist/core/watch.js +1 -1
- package/dist/interchange/check.js +10 -10
- package/dist/interchange/format.d.ts +4 -0
- package/dist/interchange/format.js +13 -5
- package/dist/kernel/cdcl.js +33 -2
- package/dist/kernel/epr.js +35 -5
- package/dist/kernel/kernel.d.ts +2 -0
- package/dist/kernel/kernel.js +67 -40
- package/dist/kernel/prove.d.ts +22 -0
- package/dist/kernel/prove.js +156 -7
- package/dist/lean-kernel/emit.d.ts +9 -3
- package/dist/lean-kernel/emit.js +170 -29
- package/dist/lean-kernel/library.js +1 -1
- package/package.json +2 -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
|
|
@@ -338,15 +338,12 @@ export function checkGo(dir, pkg, read, r, sorts, gopts) {
|
|
|
338
338
|
}
|
|
339
339
|
if (Object.keys(over).length)
|
|
340
340
|
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
|
-
}
|
|
341
|
+
// The harness's own package in -coverpkg too: the counters are written only where main is instrumented.
|
|
342
|
+
// (a rewritten copy isn't instrumented with -cover, which reads the files as they are: no arms counted then)
|
|
343
|
+
// (go's errors, file:line:col: ..., the code's own files the source's; the harness's file and main the check's)
|
|
344
|
+
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));
|
|
345
|
+
if (!('ok' in built))
|
|
346
|
+
return { ...empty, ...builtEvidence(built) };
|
|
350
347
|
const buildMs = Math.round(performance.now() - b0);
|
|
351
348
|
fs.mkdirSync(`${work}/cov`, { recursive: true });
|
|
352
349
|
// The blocks of the code the step reads that the requests reached (the harness's counters, written as it exits).
|
|
@@ -418,7 +415,7 @@ export function speak(work, bin, env, pkg, read, r, sorts, opts, count) {
|
|
|
418
415
|
const l = line();
|
|
419
416
|
if (l === undefined)
|
|
420
417
|
throw new Error('the harness stopped');
|
|
421
|
-
return JSON.parse(l);
|
|
418
|
+
return stopped(JSON.parse(l));
|
|
422
419
|
};
|
|
423
420
|
// A state from the harness as a snapshot (a number past the safe integers: the code leaves the rule's numbers).
|
|
424
421
|
const toSnap = (s) => {
|
|
@@ -552,7 +549,17 @@ export function speak(work, bin, env, pkg, read, r, sorts, opts, count) {
|
|
|
552
549
|
ro = -1;
|
|
553
550
|
return count();
|
|
554
551
|
}
|
|
555
|
-
|
|
552
|
+
let ev;
|
|
553
|
+
// (the harness gone, or stopped at its time limit: the check refuses, as checkStep's does)
|
|
554
|
+
try {
|
|
555
|
+
ev = drive(m, r, sorts, side, opts);
|
|
556
|
+
}
|
|
557
|
+
catch (e) {
|
|
558
|
+
if (!/^(the harness stopped|the code did not answer)/.test(e?.message ?? ''))
|
|
559
|
+
throw e;
|
|
560
|
+
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,
|
|
561
|
+
mismatch: `the check's harness: ${e.message}` };
|
|
562
|
+
}
|
|
556
563
|
return { ...ev, runMs: Math.round(performance.now() - r0) };
|
|
557
564
|
}
|
|
558
565
|
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";
|
|
@@ -173,7 +173,7 @@ class Go {
|
|
|
173
173
|
if (!x.id?.startsWith('pkg:'))
|
|
174
174
|
return { e: 'var', ...at, n: x.id, why: `${x.n}: a variable the step doesn't set before reading` };
|
|
175
175
|
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')))
|
|
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') || (f.pkg === 'github.com/pkg/errors' && (f.n === 'New' || f.n === 'Errorf'))))
|
|
177
177
|
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
178
|
return this.no(x, `${x.n}: a package variable (state every object shares)`);
|
|
179
179
|
}
|
|
@@ -329,6 +329,10 @@ class Go {
|
|
|
329
329
|
args(a, decl) { return a.map((y, i) => (decl.params[i] ? this.as(this.x(y), decl.params[i].t) : this.x(y))); }
|
|
330
330
|
builtin(x) {
|
|
331
331
|
const b = x.builtin, a = x.a ?? [], at = this.at(x);
|
|
332
|
+
// (fewer arguments than the builtin takes: a package the type checker refused, which the reader reads on)
|
|
333
|
+
const takes = { len: 1, delete: 2, min: 1, max: 1, panic: 1 }[b] ?? 0;
|
|
334
|
+
if (a.length < takes)
|
|
335
|
+
return this.no(x, `${b} with ${a.length} argument${a.length === 1 ? '' : 's'} (it takes ${takes})`);
|
|
332
336
|
switch (b) {
|
|
333
337
|
case 'len': {
|
|
334
338
|
const k = this.T(a[0].t).k;
|
|
@@ -362,7 +366,8 @@ class Go {
|
|
|
362
366
|
const f = x.f, path = f.pkg ?? '', n = f.n, at = this.at(x);
|
|
363
367
|
if (f.why)
|
|
364
368
|
return this.ext(x, f.why, n);
|
|
365
|
-
|
|
369
|
+
// (github.com/pkg/errors's New and Errorf too: always an error, as the standard library's)
|
|
370
|
+
if ((path === 'errors' && n === 'New') || (path === 'fmt' && n === 'Errorf') || (path === 'github.com/pkg/errors' && (n === 'New' || n === 'Errorf'))) {
|
|
366
371
|
// An error: not nil. Its arguments are evaluated (they may panic), its text is not compared.
|
|
367
372
|
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
373
|
return { e: 'errv', ...at, is: true, pre };
|
|
@@ -954,6 +959,9 @@ function readGo1(pkg, o, go) {
|
|
|
954
959
|
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
960
|
}
|
|
956
961
|
function termOf(v, at) {
|
|
962
|
+
// (none: a path that ends without the value, which a reader of malformed source may join in)
|
|
963
|
+
if (!v)
|
|
964
|
+
return refuse(at, 'a path that returns no value');
|
|
957
965
|
if (v.t === 'num')
|
|
958
966
|
return { s: 'num', e: v.e };
|
|
959
967
|
if (v.t === 'bool')
|
|
@@ -1037,12 +1045,19 @@ export function readerBinary() {
|
|
|
1037
1045
|
}
|
|
1038
1046
|
export function readGoPackage(dir) {
|
|
1039
1047
|
const cp = node('node:child_process');
|
|
1048
|
+
let pkg;
|
|
1040
1049
|
try {
|
|
1041
|
-
|
|
1050
|
+
pkg = JSON.parse(cp.execFileSync(readerBinary(), [dir], { encoding: 'utf8', maxBuffer: 1 << 29, stdio: ['ignore', 'pipe', 'pipe'], ...readerRun() }));
|
|
1042
1051
|
}
|
|
1043
1052
|
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`);
|
|
1053
|
+
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
1054
|
}
|
|
1055
|
+
// (Go writes an empty slice as null: a file with no function, no type or no import)
|
|
1056
|
+
for (const k of ['files', 'funcs', 'types', 'consts', 'vars', 'errors', 'ttab'])
|
|
1057
|
+
pkg[k] ??= [];
|
|
1058
|
+
for (const f of pkg.files)
|
|
1059
|
+
f.imports ??= [];
|
|
1060
|
+
return pkg;
|
|
1046
1061
|
}
|
|
1047
1062
|
export function extractGo(at, opts = {}) {
|
|
1048
1063
|
const p = pathOf(at), dir = /\.go$/.test(p) ? p.replace(/\/[^/]*$/, '') || '.' : p;
|
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,19 +161,58 @@ 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);
|
|
@@ -181,6 +220,16 @@ export function extractJvm(lang, at, opts = {}) {
|
|
|
181
220
|
try {
|
|
182
221
|
if (opts.stores && Object.keys(opts.stores).length)
|
|
183
222
|
throw new Refusal(file, `stores: not in the ${lang === 'java' ? 'Java' : 'Kotlin'} front end yet`);
|
|
223
|
+
// (a name or a string past the class file's 65,535 bytes: no compiler makes a class of it, javac and kotlinc throw)
|
|
224
|
+
// (a missing file is the reader's to refuse, with its reason: no JDK, or the file)
|
|
225
|
+
let text = '';
|
|
226
|
+
try {
|
|
227
|
+
text = node('node:fs').readFileSync(file, 'utf8');
|
|
228
|
+
}
|
|
229
|
+
catch { /* read by the reader, which says so */ }
|
|
230
|
+
const big = /[\p{L}_$][\p{L}\p{N}_$]{21845,}|"[^"\n]{21845,}"/u.exec(text);
|
|
231
|
+
if (big && new TextEncoder().encode(big[0]).length > 65535)
|
|
232
|
+
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
233
|
mod = readJvm(lang, file, entryNames(opts), opts);
|
|
185
234
|
// (the shipped classes can't be rewritten: an answer, other than an injected dependency's, can't be stubbed)
|
|
186
235
|
if (opts.prebuilt)
|
|
@@ -207,7 +256,7 @@ export function extractJvm(lang, at, opts = {}) {
|
|
|
207
256
|
throw e;
|
|
208
257
|
}
|
|
209
258
|
if (c.error)
|
|
210
|
-
return { cmd: 'false', args: [], hello: {}, error: c.error };
|
|
259
|
+
return { cmd: 'false', args: [], hello: {}, error: c.error, ...(c.kind ? { kind: c.kind } : {}) };
|
|
211
260
|
const t = tools(opts);
|
|
212
261
|
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
262
|
};
|
|
@@ -375,6 +375,9 @@ function pn(e, P, ctx, mode, recv = false) {
|
|
|
375
375
|
const d = decided(e.c, ctx);
|
|
376
376
|
if (d !== undefined)
|
|
377
377
|
return pn(d ? e.a : e.b, P, ctx, mode, recv);
|
|
378
|
+
// (a natural by cases read as an integer's receiver: its when(...) a natural's, made an integer, or minus stops at 0)
|
|
379
|
+
if (!nat && recv && natOK(e, ctx))
|
|
380
|
+
return `Int.of(${pn(e, P, ctx, 'nat')})`;
|
|
378
381
|
const ca = withAtom(ctx, e.c), cb = withAtom(ctx, I.not(e.c));
|
|
379
382
|
const side = (x, c) => pn(x, P, c, nat ? 'nat' : natOK(x, c) ? 'nat' : 'int');
|
|
380
383
|
return `when(${pb(e.c, P, ctx)}, ${side(e.a, ca)}, ${side(e.b, cb)})`;
|
package/dist/core/extract-py.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Refusal, pathOf } from "./extract-read.js";
|
|
1
|
+
import { Refusal, pathOf, readerRun, statedRefusal } from "./extract-read.js";
|
|
2
2
|
import { asset, entryNames, extractStep, node } from "./extract-step.js";
|
|
3
3
|
export { proveRule, proveSteps } from "./dsl.js";
|
|
4
4
|
const here = (f) => asset(`py/${f}`);
|
|
@@ -8,10 +8,10 @@ export function readPython(file, names, opts = {}) {
|
|
|
8
8
|
const abs = path.resolve(file), root = path.resolve(opts.root ?? path.dirname(abs));
|
|
9
9
|
let out;
|
|
10
10
|
try {
|
|
11
|
-
out = cp.execFileSync(opts.python ?? 'python3', ['-I', here('reader.py'), JSON.stringify({ root, file: abs, names })], { encoding: 'utf8', maxBuffer: 1 << 29, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
11
|
+
out = cp.execFileSync(opts.python ?? 'python3', ['-I', here('reader.py'), JSON.stringify({ root, file: abs, names })], { encoding: 'utf8', maxBuffer: 1 << 29, stdio: ['ignore', 'pipe', 'pipe'], ...readerRun() });
|
|
12
12
|
}
|
|
13
13
|
catch (e) {
|
|
14
|
-
throw new Refusal(file, `the Python reader didn't run (${String(e.stderr ?? e.message).split('\n').filter(Boolean).slice(-2).join(' | ')}): python3 is needed to extract Python`);
|
|
14
|
+
throw new Refusal(file, statedRefusal(e) ?? `the Python reader didn't run (${String(e.stderr ?? e.message).split('\n').filter(Boolean).slice(-2).join(' | ')}): python3 is needed to extract Python`);
|
|
15
15
|
}
|
|
16
16
|
return JSON.parse(out);
|
|
17
17
|
}
|
package/dist/core/extract-rb.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Refusal, pathOf } from "./extract-read.js";
|
|
1
|
+
import { Refusal, pathOf, readerRun, statedRefusal } from "./extract-read.js";
|
|
2
2
|
import { asset, entryNames, extractStep, node } from "./extract-step.js";
|
|
3
3
|
export { proveRule, proveSteps } from "./dsl.js";
|
|
4
4
|
const here = (f) => asset(`rb/${f}`);
|
|
@@ -8,10 +8,10 @@ export function readRuby(file, names, opts = {}) {
|
|
|
8
8
|
const abs = path.resolve(file), root = path.resolve(opts.root ?? path.dirname(abs));
|
|
9
9
|
let out;
|
|
10
10
|
try {
|
|
11
|
-
out = cp.execFileSync(opts.ruby ?? 'ruby', [here('reader.rb'), JSON.stringify({ root, file: abs, names, clocks: opts.clocks ?? [] })], { encoding: 'utf8', maxBuffer: 1 << 29, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
11
|
+
out = cp.execFileSync(opts.ruby ?? 'ruby', [here('reader.rb'), JSON.stringify({ root, file: abs, names, clocks: opts.clocks ?? [] })], { encoding: 'utf8', maxBuffer: 1 << 29, stdio: ['ignore', 'pipe', 'pipe'], ...readerRun() });
|
|
12
12
|
}
|
|
13
13
|
catch (e) {
|
|
14
|
-
throw new Refusal(file, `the Ruby reader didn't run (${String(e.stderr ?? e.message).split('\n').filter(Boolean).slice(-2).join(' | ')}): ruby 3.3 or later (with Prism) is needed to extract Ruby`);
|
|
14
|
+
throw new Refusal(file, statedRefusal(e) ?? `the Ruby reader didn't run (${String(e.stderr ?? e.message).split('\n').filter(Boolean).slice(-2).join(' | ')}): ruby 3.3 or later (with Prism) is needed to extract Ruby`);
|
|
15
15
|
}
|
|
16
16
|
return JSON.parse(out);
|
|
17
17
|
}
|
|
@@ -321,12 +321,19 @@ export type Source = string | FileURL | {
|
|
|
321
321
|
code: string;
|
|
322
322
|
file?: string;
|
|
323
323
|
};
|
|
324
|
+
export declare const readerRun: () => {
|
|
325
|
+
timeout: number;
|
|
326
|
+
killSignal: string;
|
|
327
|
+
};
|
|
328
|
+
export declare const statedRefusal: (e: unknown) => string | undefined;
|
|
329
|
+
export declare const tooDeep: (e: unknown) => boolean;
|
|
324
330
|
export declare const pathOf: (at: string | FileURL) => string;
|
|
325
331
|
export declare function sourceOf(at: Source, file: string | undefined, dflt: string): {
|
|
326
332
|
code: string;
|
|
327
333
|
file: string;
|
|
328
334
|
};
|
|
329
335
|
export declare function beside<T>(file: string, spec: string): T | undefined;
|
|
336
|
+
export declare function syntaxError(code: string, file: string): string | undefined;
|
|
330
337
|
export declare const scriptKind: (file: string) => ts.ScriptKind;
|
|
331
338
|
export declare function shapeOf(t: ts.Type, checker: ts.TypeChecker, at: ts.Node, inner?: string): Shape;
|
|
332
339
|
type Callable = {
|
|
@@ -427,6 +434,7 @@ export declare class Exec {
|
|
|
427
434
|
vals: Map<string, V>;
|
|
428
435
|
};
|
|
429
436
|
private access;
|
|
437
|
+
private absent;
|
|
430
438
|
private mapGet;
|
|
431
439
|
private mapId;
|
|
432
440
|
mapSet(id: string, key: K, v: V | undefined, at: ts.Node, p: Path, track?: boolean): Path;
|
|
@@ -71,6 +71,20 @@ export function placed(file) {
|
|
|
71
71
|
return (/^([A-Za-z]:)?[\\/]/.test(file) ? file : `${cwd}/${file}`).replace(/\\/g, '/');
|
|
72
72
|
}
|
|
73
73
|
const builtin = (id) => globalThis.process?.getBuiltinModule?.(id);
|
|
74
|
+
// A reader process's time on one source: GDP_READER_S seconds (300), past which it is killed and the source refused (a
|
|
75
|
+
// parser recovering from deep unclosed nesting, the Kotlin compiler's, took 23 minutes on one).
|
|
76
|
+
export const readerRun = () => ({ timeout: Number(globalThis.process?.env?.GDP_READER_S ?? 300) * 1000, killSignal: 'SIGKILL' });
|
|
77
|
+
// What a reader process that failed said it refuses: a line `gdp: refused: …` on its stderr (source it can't read: a
|
|
78
|
+
// syntax error, nesting past its stack), or that it ran past its time; undefined where it said none (it didn't run:
|
|
79
|
+
// the tool is missing).
|
|
80
|
+
export const statedRefusal = (e) => {
|
|
81
|
+
const x = e, text = typeof x.stderr === 'string' ? x.stderr : x.stderr ? new TextDecoder().decode(x.stderr) : '';
|
|
82
|
+
if (x.code === 'ETIMEDOUT' || x.signal === 'SIGKILL')
|
|
83
|
+
return `the reader didn't finish within ${readerRun().timeout / 1000} s on this source`;
|
|
84
|
+
return /^gdp: refused: (.*)$/m.exec(text)?.[1];
|
|
85
|
+
};
|
|
86
|
+
// Source nested past what a reader's recursion holds (a stack overflow in TypeScript's parser): refused where it is.
|
|
87
|
+
export const tooDeep = (e) => e instanceof RangeError && /call stack/i.test(e.message);
|
|
74
88
|
export const pathOf = (at) => (typeof at === 'string' ? at : builtin('node:url').fileURLToPath(at.href));
|
|
75
89
|
// A TypeScript front end's source. A string is the code where it can't be a path (a line break, or no script's
|
|
76
90
|
// extension): the code-first call, as it was.
|
|
@@ -97,6 +111,28 @@ export function beside(file, spec) {
|
|
|
97
111
|
return undefined;
|
|
98
112
|
}
|
|
99
113
|
}
|
|
114
|
+
// The first syntax error TypeScript's parser reports in a module, where it is, or undefined: its parser recovers from
|
|
115
|
+
// each, and the tree it leaves is not the code that runs (which then doesn't load).
|
|
116
|
+
export function syntaxError(code, file) {
|
|
117
|
+
const sf = ts.createSourceFile(file, code, ts.ScriptTarget.ES2022, true, scriptKind(file));
|
|
118
|
+
const d = sf.parseDiagnostics?.[0];
|
|
119
|
+
// (two declarations of one name at the module's top level: TypeScript refuses it, JavaScript keeps the last)
|
|
120
|
+
const seen = new Set();
|
|
121
|
+
for (const st of sf.statements) {
|
|
122
|
+
const names = (ts.isFunctionDeclaration(st) && st.body) || ts.isClassDeclaration(st) ? (st.name ? [st.name.text] : []) : ts.isVariableStatement(st) && st.declarationList.flags & ts.NodeFlags.BlockScoped ? st.declarationList.declarations.flatMap(x => (ts.isIdentifier(x.name) ? [x.name.text] : [])) : [];
|
|
123
|
+
for (const n of names) {
|
|
124
|
+
if (seen.has(n)) {
|
|
125
|
+
const { line, character } = sf.getLineAndCharacterOfPosition(st.getStart());
|
|
126
|
+
return `the source declares ${n} twice at its top level: ${line + 1}:${character + 1} (TypeScript refuses it; JavaScript keeps the last)`;
|
|
127
|
+
}
|
|
128
|
+
seen.add(n);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (!d)
|
|
132
|
+
return undefined;
|
|
133
|
+
const { line, character } = sf.getLineAndCharacterOfPosition(d.start ?? 0);
|
|
134
|
+
return `the source doesn't parse: ${line + 1}:${character + 1}: ${ts.flattenDiagnosticMessageText(d.messageText, ' ')}`;
|
|
135
|
+
}
|
|
100
136
|
export const scriptKind = (file) => (/\.jsx$/.test(file) ? ts.ScriptKind.JSX : /\.tsx$/.test(file) ? ts.ScriptKind.TSX : /\.[cm]?js$/.test(file) ? ts.ScriptKind.JS : ts.ScriptKind.TS);
|
|
101
137
|
// The shape a type has in the subset.
|
|
102
138
|
// (`inner`: the field path inside the value at `at` that t is the type of, for where a refusal says it is)
|
|
@@ -695,6 +731,10 @@ export class Exec {
|
|
|
695
731
|
return refuse(e, `${e.text}: a module-level let (state outside the step)`);
|
|
696
732
|
if (ts.isArrowFunction(decl.initializer) || ts.isFunctionExpression(decl.initializer))
|
|
697
733
|
return refuse(e, `${e.text}: a function used as a value`);
|
|
734
|
+
// (the clock read where the module loads: that time, once, never a request's)
|
|
735
|
+
const clock = (n) => ((ts.isCallExpression(n) && /^(Date\.now|performance\.now)$/.test(n.expression.getText())) || (ts.isNewExpression(n) && n.expression.getText() === 'Date' && !n.arguments?.length)) || ts.forEachChild(n, x => clock(x) || undefined) === true;
|
|
736
|
+
if (clock(decl.initializer))
|
|
737
|
+
return refuse(e, `${e.text}: a module-level const that reads the clock (the time the module loaded, not the request's)`);
|
|
698
738
|
// A module-level const: its value, an object read-only (every call shares it).
|
|
699
739
|
const id = `shared.${decl.getSourceFile().fileName}:${e.text}`;
|
|
700
740
|
if (p.heap.has(id))
|
|
@@ -1086,6 +1126,8 @@ export class Exec {
|
|
|
1086
1126
|
}
|
|
1087
1127
|
if (f === 'length')
|
|
1088
1128
|
return refuse(e, 'length of a string (strings are compared and set in the subset)');
|
|
1129
|
+
if (this.absent(e))
|
|
1130
|
+
return refuse(e, `${text(e)}: ${f}, a property its type doesn't have there (undefined where it runs)`);
|
|
1089
1131
|
return this.field(base, f, e, q);
|
|
1090
1132
|
}
|
|
1091
1133
|
const arg = e.argumentExpression;
|
|
@@ -1108,6 +1150,19 @@ export class Exec {
|
|
|
1108
1150
|
return this.field(base, arg.text, e, q);
|
|
1109
1151
|
return refuse(e, 'an index into other than a record keyed by strings or numbers');
|
|
1110
1152
|
}
|
|
1153
|
+
// (TypeScript's: a property the type of what it is read of, narrowed there, doesn't have, where the files read declare it)
|
|
1154
|
+
absent(e) {
|
|
1155
|
+
const c = this.s.checker, sf = e.getSourceFile();
|
|
1156
|
+
if (!/\.[cm]?tsx?$/.test(sf.fileName) || sf.isDeclarationFile)
|
|
1157
|
+
return false;
|
|
1158
|
+
const t = c.getApparentType(c.getTypeAtLocation(e.expression));
|
|
1159
|
+
// (only a type the files read declare: one of a library's declarations may not be what runs, another version's)
|
|
1160
|
+
const own = (x) => !!(x.aliasSymbol ?? x.getSymbol())?.declarations?.some(d => !d.getSourceFile().isDeclarationFile);
|
|
1161
|
+
if (!(t.isUnion() ? t.types : [t]).every(own))
|
|
1162
|
+
return false;
|
|
1163
|
+
return !(t.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown | ts.TypeFlags.Never)) && !!(t.flags & (ts.TypeFlags.Object | ts.TypeFlags.Union | ts.TypeFlags.Intersection)) &&
|
|
1164
|
+
!c.getPropertyOfType(t, memberName(e.name)) && !c.getIndexInfosOfType(t).length;
|
|
1165
|
+
}
|
|
1111
1166
|
mapGet(id, key, p) {
|
|
1112
1167
|
const m = this.obj(p, id), cell = this.readCell(m, key);
|
|
1113
1168
|
if (m.decl.scalar)
|
package/dist/core/extract-rs.js
CHANGED
|
@@ -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 proc = globalThis.process;
|
|
5
5
|
// The reader, built once per version of its source (into the system's temporary directory).
|
|
@@ -16,10 +16,10 @@ export function readRust(dir, names, cargo) {
|
|
|
16
16
|
const cp = node('node:child_process');
|
|
17
17
|
let out;
|
|
18
18
|
try {
|
|
19
|
-
out = cp.execFileSync(rsReader(cargo), [JSON.stringify({ root: dir, names })], { encoding: 'utf8', maxBuffer: 1 << 29, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
19
|
+
out = cp.execFileSync(rsReader(cargo), [JSON.stringify({ root: dir, names })], { encoding: 'utf8', maxBuffer: 1 << 29, stdio: ['ignore', 'pipe', 'pipe'], ...readerRun() });
|
|
20
20
|
}
|
|
21
21
|
catch (e) {
|
|
22
|
-
throw new Refusal(dir, `the Rust reader didn't run (${String(e.stderr ?? e.message).split('\n').filter(Boolean).slice(-2).join(' | ')}): cargo is needed to extract Rust`);
|
|
22
|
+
throw new Refusal(dir, statedRefusal(e) ?? `the Rust reader didn't run (${String(e.stderr ?? e.message).split('\n').filter(Boolean).slice(-2).join(' | ')}): cargo is needed to extract Rust`);
|
|
23
23
|
}
|
|
24
24
|
return JSON.parse(out);
|
|
25
25
|
}
|
|
@@ -271,24 +271,22 @@ function harnessFor(dir, mod, read, opts) {
|
|
|
271
271
|
if (t !== s)
|
|
272
272
|
fs.writeFileSync(f, t);
|
|
273
273
|
}
|
|
274
|
+
// (the lines of the code itself in the files the harness is appended to: an error past them is the harness's)
|
|
275
|
+
const own = new Map([file, lib].map(f => [f, fs.readFileSync(`${work}/${f}`, 'utf8').split('\n').length]));
|
|
274
276
|
fs.writeFileSync(`${work}/${file}`, fs.readFileSync(`${work}/${file}`, 'utf8') + harnessCode(mod, read, cls));
|
|
275
277
|
fs.writeFileSync(`${work}/${lib}`, `${fs.readFileSync(`${work}/${lib}`, 'utf8')}\n#[cfg(test)]\n#[allow(unused)]\npub(crate) fn __gdp_now() -> std::time::Instant { ${modPath}::__gdp_harness::now() }\n#[cfg(test)]\n#[allow(unused)]\npub(crate) fn __gdp_answer<T: ${modPath}::__gdp_harness::GdpAns>(k: &str) -> T { ${modPath}::__gdp_harness::answer(k) }\n`);
|
|
276
278
|
const target = `${os.tmpdir()}/gdp-rscheck-target`;
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
}
|
|
281
|
-
catch (e) {
|
|
282
|
-
const out = String(e.stdout ?? '');
|
|
283
|
-
const errs = out.split('\n').flatMap(l => { try {
|
|
284
|
-
const j = JSON.parse(l);
|
|
285
|
-
return j.reason === 'compiler-message' && j.message?.level === 'error' ? [j.message.rendered ?? ''] : [];
|
|
286
|
-
}
|
|
287
|
-
catch {
|
|
288
|
-
return [];
|
|
289
|
-
} });
|
|
290
|
-
return { cmd: 'false', args: [], hello: {}, error: `the crate doesn't build with the check's harness: ${(errs.join(' | ') || String(e.stderr ?? '')).replace(/\s+/g, ' ').slice(0, 600)}` };
|
|
279
|
+
const built = buildCheck('cargo', () => cp.execFileSync(opts.cargo ?? 'cargo', ['test', '--lib', '--no-run', '--message-format=json', '--target-dir', target], { cwd: work, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 1 << 28, env: { ...proc?.env }, timeout: compileLimit(), killSignal: 'SIGKILL' }), e => String(e.stdout ?? '').split('\n').flatMap(l => { try {
|
|
280
|
+
const j = JSON.parse(l);
|
|
281
|
+
return j.reason === 'compiler-message' && j.message?.level === 'error' ? [(j.message.rendered ?? '').replace(/\s+/g, ' ')] : [];
|
|
291
282
|
}
|
|
283
|
+
catch {
|
|
284
|
+
return [];
|
|
285
|
+
} }), l => { const m = /--> ([^\s:]+\.rs):(\d+):\d+/.exec(l); if (!m)
|
|
286
|
+
return false; const n = own.get(m[1]); return n === undefined || Number(m[2]) <= n; });
|
|
287
|
+
if (!('ok' in built))
|
|
288
|
+
return { cmd: 'false', args: [], hello: {}, error: built.why, kind: built.kind };
|
|
289
|
+
const msgs = built.ok;
|
|
292
290
|
const exe = msgs.split('\n').flatMap(l => { try {
|
|
293
291
|
const j = JSON.parse(l);
|
|
294
292
|
return j.reason === 'compiler-artifact' && j.executable && j.target?.kind?.includes('lib') ? [j.executable] : [];
|
|
@@ -297,7 +295,7 @@ function harnessFor(dir, mod, read, opts) {
|
|
|
297
295
|
return [];
|
|
298
296
|
} })[0];
|
|
299
297
|
if (!exe)
|
|
300
|
-
return { cmd: 'false', args: [], hello: {}, error: 'the test build gave no executable' };
|
|
298
|
+
return { cmd: 'false', args: [], hello: {}, error: 'the test build gave no executable', kind: 'harness' };
|
|
301
299
|
read.model.notes.push('Rust: the code is checked in a debug build (overflow checks on); its branch arms are not counted (no instrumentation yet)');
|
|
302
300
|
read.arms.length = 0;
|
|
303
301
|
const test = `${modPath === 'crate' ? '' : `${modPath.replace(/^crate::/, '')}::`}__gdp_harness::__gdp_harness_main`;
|
|
@@ -950,6 +950,17 @@ function attempt(code, file, opts, written) {
|
|
|
950
950
|
// The methods: each public one an event (the nearest of each name, through the classes it extends), run from the
|
|
951
951
|
// state as variables.
|
|
952
952
|
const seenNames = new Set(), methods = [];
|
|
953
|
+
// (two bodies of one name in one class: JavaScript keeps the last, TypeScript refuses it)
|
|
954
|
+
for (const c of chain) {
|
|
955
|
+
const bodies = new Set();
|
|
956
|
+
for (const m of c.members)
|
|
957
|
+
if (ts.isMethodDeclaration(m) && m.body) {
|
|
958
|
+
const k = `${has(m, ts.SyntaxKind.StaticKeyword) ? 'static ' : ''}${memberName(m.name)}`;
|
|
959
|
+
if (bodies.has(k))
|
|
960
|
+
refuse(m, `${memberName(m.name)}: a second body of it in one class (JavaScript keeps the last; TypeScript refuses it)`);
|
|
961
|
+
bodies.add(k);
|
|
962
|
+
}
|
|
963
|
+
}
|
|
953
964
|
for (const c of chain)
|
|
954
965
|
for (const m of c.members) {
|
|
955
966
|
if (!ts.isMethodDeclaration(m) || seenNames.has(memberName(m.name)))
|
|
@@ -1294,6 +1305,15 @@ function factoryAttempt(code, file, opts, written, fxOf) {
|
|
|
1294
1305
|
for (const [id, o] of fx?.start ?? [])
|
|
1295
1306
|
stateHeap.set(id, o);
|
|
1296
1307
|
const strip0 = (e) => (ts.isParenthesizedExpression(e) || ts.isAsExpression(e) ? strip0(e.expression) : e);
|
|
1308
|
+
// (two members of one name: JavaScript keeps the last, TypeScript refuses it)
|
|
1309
|
+
const names = new Set();
|
|
1310
|
+
for (const p of obj.properties)
|
|
1311
|
+
if (p.name && !ts.isComputedPropertyName(p.name)) {
|
|
1312
|
+
const n = memberName(p.name);
|
|
1313
|
+
if (names.has(n))
|
|
1314
|
+
refuse(p, `${n}: a second member of it in the object returned (JavaScript keeps the last; TypeScript refuses it)`);
|
|
1315
|
+
names.add(n);
|
|
1316
|
+
}
|
|
1297
1317
|
const fns = obj.properties.map(p => {
|
|
1298
1318
|
if (ts.isMethodDeclaration(p))
|
|
1299
1319
|
return { name: memberName(p.name), decl: p };
|
package/dist/core/extract-sol.js
CHANGED
|
@@ -27,7 +27,7 @@ import { fromModel } from "./extract.js";
|
|
|
27
27
|
import { evalC, interpret, seeded } from "./machine.js";
|
|
28
28
|
import { allowed, watch } from "./watch.js";
|
|
29
29
|
import { kindOfVar } from "./extract-check.js";
|
|
30
|
-
import { Refusal, pathOf } from "./extract-read.js";
|
|
30
|
+
import { Refusal, pathOf, readerRun, statedRefusal } from "./extract-read.js";
|
|
31
31
|
const refuse = (where, what) => { throw new Refusal(where, what); };
|
|
32
32
|
import { asset, checkStep, node, readStep, stepNames } from "./extract-step.js";
|
|
33
33
|
export { proveRule, proveSteps } from "./dsl.js";
|
|
@@ -44,10 +44,10 @@ export function compile(file, o) {
|
|
|
44
44
|
let out;
|
|
45
45
|
const solc = o.solc ?? env().GDP_SOLC ?? 'solc';
|
|
46
46
|
try {
|
|
47
|
-
out = cp.execFileSync(solc, ['--standard-json', '--base-path', root, '--include-path', `${root}/node_modules`, '--allow-paths', root], { input: JSON.stringify(input), encoding: 'utf8', maxBuffer: 1 << 29, stdio: ['pipe', 'pipe', 'pipe'] });
|
|
47
|
+
out = cp.execFileSync(solc, ['--standard-json', '--base-path', root, '--include-path', `${root}/node_modules`, '--allow-paths', root], { input: JSON.stringify(input), encoding: 'utf8', maxBuffer: 1 << 29, stdio: ['pipe', 'pipe', 'pipe'], ...readerRun() });
|
|
48
48
|
}
|
|
49
49
|
catch (e) {
|
|
50
|
-
throw new Refusal(file, `solc didn't run (${String(e.message).slice(0, 300)}): solc 0.8 is needed to extract Solidity (on the PATH, or $GDP_SOLC)`);
|
|
50
|
+
throw new Refusal(file, statedRefusal(e) ?? `solc didn't run (${String(e.message).slice(0, 300)}): solc 0.8 is needed to extract Solidity (on the PATH, or $GDP_SOLC)`);
|
|
51
51
|
}
|
|
52
52
|
const j = JSON.parse(out);
|
|
53
53
|
const errs = (j.errors ?? []).filter(e => e.severity === 'error');
|
|
@@ -293,6 +293,12 @@ class Lower {
|
|
|
293
293
|
const mk = body[i], pre = body.slice(0, i), rest = body.slice(i + 1);
|
|
294
294
|
if (callsOut(rest))
|
|
295
295
|
refuse(p, `${name}: two calls into other code (the subset splits at one)`);
|
|
296
|
+
// (a failed call must revert the caller, as transfer and require(ok) do: the EVM undoes what the callee did, the
|
|
297
|
+
// contract's calls back included, which the steps between the two the rule holds can't undo)
|
|
298
|
+
const okv = String(mk.ok), r0 = rest[0], x0 = r0?.c;
|
|
299
|
+
const reverts = mk.how === 'transfer' || (r0?.s === 'if' && x0?.e === 'not' && x0.x?.e === 'var' && x0.x.n === okv && (r0.then[0]?.s === 'fail'));
|
|
300
|
+
if (!reverts)
|
|
301
|
+
refuse(p, `${name}: a call into other code whose failure the function goes on past (the EVM undoes what the callee did, its calls back included; the subset reads a failed call that reverts the caller: require(ok) right after it)`);
|
|
296
302
|
// The locals the rest may read: the parameters, and every local the part before sets.
|
|
297
303
|
const locals = new Map();
|
|
298
304
|
for (const pa of params)
|
|
@@ -880,7 +886,12 @@ export function extractSolidity(at, opts = {}) {
|
|
|
880
886
|
const run = randomRun(rule, rread.model, rand);
|
|
881
887
|
if (!run.trace.length)
|
|
882
888
|
continue;
|
|
883
|
-
|
|
889
|
+
// (the replay's harness failing: once more, then the check's failure, no verdict)
|
|
890
|
+
let r = replays(run);
|
|
891
|
+
if (!r.ok && r.harness)
|
|
892
|
+
r = replays(run);
|
|
893
|
+
if (!r.ok && r.harness)
|
|
894
|
+
return { ...ev, harness: r.what };
|
|
884
895
|
if (!r.ok)
|
|
885
896
|
return { ...ev, mismatch: `re-entrancy: a run of the rule replayed on the code: ${r.what}` };
|
|
886
897
|
runs.runs++;
|
|
@@ -948,7 +959,7 @@ function randomRun(rule, model, rand) {
|
|
|
948
959
|
// rule's, every call made. With a law, the law broken by the run at that width too.
|
|
949
960
|
function replayer(c) {
|
|
950
961
|
return (run, law) => {
|
|
951
|
-
const no = (what) => ({ ok: false, what, txs: 0, nested: 0 });
|
|
962
|
+
const no = (what, harness = false) => ({ ok: false, what, txs: 0, nested: 0, ...(harness ? { harness: true } : {}) });
|
|
952
963
|
const isLaw = !!law && typeof law === 'object' && 'holds' in law;
|
|
953
964
|
let R = c.rule;
|
|
954
965
|
try {
|
|
@@ -1016,14 +1027,14 @@ function replayer(c) {
|
|
|
1016
1027
|
out = JSON.parse(cp.execFileSync(c.opts.python ?? 'python3', [asset('sol/harness.py'), '--replay', `${dir}/run.json`], { encoding: 'utf8', maxBuffer: 1 << 26, stdio: ['ignore', 'pipe', 'pipe'], env: { ...env(), ...(c.opts.anvil ? { GDP_ANVIL: c.opts.anvil } : {}) } }));
|
|
1017
1028
|
}
|
|
1018
1029
|
catch (e) {
|
|
1019
|
-
return no(`the replay didn't run (${String(e.message).slice(0, 300)})
|
|
1030
|
+
return no(`the replay didn't run (${String(e.message).slice(0, 300)})`, true);
|
|
1020
1031
|
}
|
|
1021
1032
|
finally {
|
|
1022
1033
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
1023
1034
|
}
|
|
1024
|
-
if (out.error)
|
|
1025
|
-
return no(`the code: ${out.error}`);
|
|
1026
1035
|
const shown = (g) => groups[g].map(e => (e.kind === 'ret' ? `return(${e.ok})` : `${e.m}(${e.a.map(([n, v]) => `${n}=${String(v.in)}`).join(', ')})`)).join(' ');
|
|
1036
|
+
if (out.error)
|
|
1037
|
+
return no(out.transport ? `the replay's harness: ${out.error}` : `the code: ${out.error} (the run: ${groups.map((_, g) => shown(g)).join('; ')})`, !!out.transport);
|
|
1027
1038
|
for (const [g, ok] of (out.oks ?? []).entries())
|
|
1028
1039
|
if (ok.some(x => !x))
|
|
1029
1040
|
return no(`transaction ${g + 1} (${shown(g)}): a call the rule takes reverts in the code`);
|