gdp-wired 0.43.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/README.md +8 -3
- package/dist/core/c/reader.js +22 -7
- package/dist/core/check.js +3 -2
- package/dist/core/cli.d.ts +7 -0
- package/dist/core/cli.js +184 -12
- 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.d.ts +60 -0
- package/dist/core/effect-prims.js +625 -0
- package/dist/core/effect.d.ts +17 -1
- package/dist/core/effect.js +108 -4
- package/dist/core/ex/harness.exs +2 -0
- 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.d.ts +2 -0
- package/dist/core/extract-c.js +22 -13
- package/dist/core/extract-check.d.ts +7 -0
- package/dist/core/extract-check.js +57 -4
- package/dist/core/extract-ex.js +5 -5
- package/dist/core/extract-go-check.js +22 -17
- package/dist/core/extract-go.d.ts +3 -0
- package/dist/core/extract-go.js +24 -9
- package/dist/core/extract-jvm.js +68 -16
- package/dist/core/extract-print.js +3 -0
- package/dist/core/extract-py.js +5 -5
- package/dist/core/extract-rb.js +5 -5
- package/dist/core/extract-read.d.ts +8 -0
- package/dist/core/extract-read.js +55 -0
- package/dist/core/extract-rs.js +28 -25
- package/dist/core/extract-shapes.js +20 -0
- package/dist/core/extract-sol.js +23 -12
- package/dist/core/extract-step.d.ts +59 -3
- package/dist/core/extract-step.js +334 -64
- package/dist/core/extract-swift.js +22 -15
- 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 +113 -40
- package/dist/core/jvm/Harness.java +8 -1
- package/dist/core/jvm/JavaReader.java +10 -2
- package/dist/core/jvm/Jvm.java +18 -2
- package/dist/core/jvm/KtReader.java +60 -5
- package/dist/core/machine.d.ts +2 -0
- package/dist/core/machine.js +32 -6
- package/dist/core/py/harness.py +128 -24
- 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/Replay.sol +52 -0
- package/dist/core/sol/harness.py +511 -0
- package/dist/core/solver.js +5 -4
- package/dist/core/system.d.ts +62 -1
- package/dist/core/system.js +274 -6
- package/dist/core/transfer.js +17 -0
- package/dist/core/watch.js +1 -1
- package/dist/interchange/check.d.ts +18 -1
- package/dist/interchange/check.js +19 -12
- package/dist/interchange/cli.d.ts +2 -0
- package/dist/interchange/cli.js +45 -0
- package/dist/interchange/format.d.ts +5 -1
- package/dist/interchange/format.js +25 -9
- package/dist/kernel/cdcl.js +65 -14
- 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/kernel/reader.js +3 -2
- 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 +12 -3
package/dist/core/extract-ex.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { Refusal, pathOf } from "./extract-read.js";
|
|
2
|
-
import { extractStep, node } from "./extract-step.js";
|
|
1
|
+
import { Refusal, pathOf, readerRun, statedRefusal } from "./extract-read.js";
|
|
2
|
+
import { asset, extractStep, node } from "./extract-step.js";
|
|
3
3
|
export { proveRule, proveSteps } from "./dsl.js";
|
|
4
|
-
const here = (f) =>
|
|
4
|
+
const here = (f) => asset(`ex/${f}`);
|
|
5
5
|
export function readElixir(file, module, elixir = 'elixir') {
|
|
6
6
|
const cp = node('node:child_process'), path = node('node:path');
|
|
7
7
|
let out;
|
|
8
8
|
try {
|
|
9
|
-
out = cp.execFileSync(elixir, [here('reader.exs'), JSON.stringify({ file: path.resolve(file), module: module ?? null })], { encoding: 'utf8', maxBuffer: 1 << 29, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
9
|
+
out = cp.execFileSync(elixir, [here('reader.exs'), JSON.stringify({ file: path.resolve(file), module: module ?? null })], { encoding: 'utf8', maxBuffer: 1 << 29, stdio: ['ignore', 'pipe', 'pipe'], ...readerRun() });
|
|
10
10
|
}
|
|
11
11
|
catch (e) {
|
|
12
|
-
throw new Refusal(file, `the Elixir reader didn't run (${String(e.stderr ?? e.message).split('\n').filter(Boolean).slice(0, 2).join(' | ')}): elixir is needed to extract Elixir`);
|
|
12
|
+
throw new Refusal(file, statedRefusal(e) ?? `the Elixir reader didn't run (${String(e.stderr ?? e.message).split('\n').filter(Boolean).slice(0, 2).join(' | ')}): elixir is needed to extract Elixir`);
|
|
13
13
|
}
|
|
14
14
|
return JSON.parse(out);
|
|
15
15
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Outside, constantsOf, draw, drive, evalTerm } from "./extract-check.js";
|
|
2
|
-
import { 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).
|
|
@@ -392,13 +389,11 @@ export function checkGo(dir, pkg, read, r, sorts, gopts) {
|
|
|
392
389
|
// it, call a method on it), every state compared; `count` reads the coverage after the harness exits.
|
|
393
390
|
export function speak(work, bin, env, pkg, read, r, sorts, opts, count) {
|
|
394
391
|
const m = read.model, bound = opts.bound ?? 12;
|
|
395
|
-
const fs = node('node:fs')
|
|
392
|
+
const fs = node('node:fs');
|
|
396
393
|
let child, wi = -1, ro = -1;
|
|
397
394
|
try {
|
|
398
|
-
|
|
399
|
-
child =
|
|
400
|
-
wi = fs.openSync(`${work}/in`, 'w');
|
|
401
|
-
ro = fs.openSync(`${work}/out`, 'r');
|
|
395
|
+
;
|
|
396
|
+
({ child, wi, ro } = openHarness(work, bin, [], { stdio: 'ignore', env }));
|
|
402
397
|
const buf = new Uint8Array(1 << 20), dec = new TextDecoder();
|
|
403
398
|
let pend = '';
|
|
404
399
|
const line = () => {
|
|
@@ -420,7 +415,7 @@ export function speak(work, bin, env, pkg, read, r, sorts, opts, count) {
|
|
|
420
415
|
const l = line();
|
|
421
416
|
if (l === undefined)
|
|
422
417
|
throw new Error('the harness stopped');
|
|
423
|
-
return JSON.parse(l);
|
|
418
|
+
return stopped(JSON.parse(l));
|
|
424
419
|
};
|
|
425
420
|
// A state from the harness as a snapshot (a number past the safe integers: the code leaves the rule's numbers).
|
|
426
421
|
const toSnap = (s) => {
|
|
@@ -554,7 +549,17 @@ export function speak(work, bin, env, pkg, read, r, sorts, opts, count) {
|
|
|
554
549
|
ro = -1;
|
|
555
550
|
return count();
|
|
556
551
|
}
|
|
557
|
-
|
|
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
|
+
}
|
|
558
563
|
return { ...ev, runMs: Math.round(performance.now() - r0) };
|
|
559
564
|
}
|
|
560
565
|
finally {
|
|
@@ -187,11 +187,14 @@ export type GoOptions = {
|
|
|
187
187
|
check?: GoCheckOptions;
|
|
188
188
|
fails?: Record<string, string>;
|
|
189
189
|
strict?: boolean;
|
|
190
|
+
answers?: Record<string, string>;
|
|
191
|
+
skip?: string[];
|
|
190
192
|
};
|
|
191
193
|
export type GoRead = {
|
|
192
194
|
answers?: (Answer & {
|
|
193
195
|
range?: [number, number];
|
|
194
196
|
})[];
|
|
197
|
+
leftOut?: string[];
|
|
195
198
|
ctor?: {
|
|
196
199
|
name: string;
|
|
197
200
|
t: number;
|
package/dist/core/extract-go.js
CHANGED
|
@@ -35,9 +35,9 @@
|
|
|
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
|
-
import { Stepper, iteTerm, mapWritesOf, phiP, rangeLaws, rangeOf, varTerm } from "./extract-step.js";
|
|
40
|
+
import { asset, Stepper, iteTerm, mapWritesOf, phiP, rangeLaws, rangeOf, varTerm } from "./extract-step.js";
|
|
41
41
|
import { checkGo } from "./extract-go-check.js";
|
|
42
42
|
export { proveRule, proveSteps } from "./dsl.js";
|
|
43
43
|
const refuse = (x, what) => { throw new Refusal(typeof x === 'string' ? x : x.p || '?', what); };
|
|
@@ -52,7 +52,7 @@ class Go {
|
|
|
52
52
|
this.pkg = pkg;
|
|
53
53
|
this.opts = opts;
|
|
54
54
|
const mod = { lang: pkg.lang ?? 'go', file: pkg.files[0]?.name ?? 'go', path: pkg.dir ? `${pkg.dir}/${pkg.files[0]?.name ?? ''}` : '', module: pkg.package, root: pkg.dir ?? '', entries: [], recs: {}, funcs: this.funcs, split: false };
|
|
55
|
-
this.g = new Stepper(mod, { entry: opts.entry, ...(opts.onError ? { onError: opts.onError } : {}) }, inf);
|
|
55
|
+
this.g = new Stepper(mod, { entry: opts.entry, ...(opts.onError ? { onError: opts.onError } : {}), ...(opts.answers ? { answers: opts.answers } : {}), ...(opts.skip ? { skip: opts.skip } : {}) }, inf);
|
|
56
56
|
for (const f of pkg.funcs)
|
|
57
57
|
this.funcs[`${f.recv?.type ?? ''}.${f.name}`] = this.fn(f);
|
|
58
58
|
}
|
|
@@ -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 };
|
|
@@ -951,9 +956,12 @@ function readGo1(pkg, o, go) {
|
|
|
951
956
|
// Unsigned inputs are naturals (the input's kind); a state variable's sort is the printer's to decide (a natural where
|
|
952
957
|
// every write is proven one: a wrap by cases may not be, though it stays within the type, which its law says).
|
|
953
958
|
const unsigned = [...g.ints].filter(([n, ty]) => { const [lo, hi] = rangeOf(ty); return lo === 0 && hi > 0 && (g.inputs.some(v => v.name === n) || cparams.some(v => v.name === n)); }).map(([n]) => n);
|
|
954
|
-
return { ...(pkg.ctor ? { ctor: ctorArgs } : {}), 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 } : {}) };
|
|
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')
|
|
@@ -1028,7 +1036,7 @@ export const node = (id) => { const m = proc?.getBuiltinModule?.(id); if (!m)
|
|
|
1028
1036
|
// The reader, built once per version of its source (into the system's temporary directory).
|
|
1029
1037
|
export function readerBinary() {
|
|
1030
1038
|
const fs = node('node:fs'), cp = node('node:child_process'), os = node('node:os'), crypto = node('node:crypto');
|
|
1031
|
-
const dir =
|
|
1039
|
+
const dir = asset('go/');
|
|
1032
1040
|
const src = fs.readFileSync(`${dir}reader.go`, 'utf8'), h = crypto.createHash('sha256').update(src).digest('hex').slice(0, 12);
|
|
1033
1041
|
const bin = `${os.tmpdir()}/gdp-goreader-${h}`;
|
|
1034
1042
|
if (!fs.existsSync(bin))
|
|
@@ -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,7 +1,7 @@
|
|
|
1
|
-
import { Refusal, pathOf } from "./extract-read.js";
|
|
2
|
-
import { 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
|
-
const here = (f) =>
|
|
4
|
+
const here = (f) => asset(`jvm/${f}`);
|
|
5
5
|
const TOOLS = ['Jvm.java', 'JavaReader.java', 'Harness.java', 'Rt.java'];
|
|
6
6
|
// (a JVM's stack trace: its exception's line first)
|
|
7
7
|
const errText = (e) => { const ls = String(e.stderr || e.stdout || e.message).split('\n').filter(l => l.trim() && !/^\s+at /.test(l)); return ls.slice(-3).join(' | ').slice(0, 600); };
|
|
@@ -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
|
}
|
|
@@ -137,13 +137,16 @@ function answerSites(mod, keys) {
|
|
|
137
137
|
return out;
|
|
138
138
|
}
|
|
139
139
|
const BOXES = { int: 'java.lang.Integer', long: 'java.lang.Long', short: 'java.lang.Short', byte: 'java.lang.Byte', char: 'java.lang.Character', boolean: 'java.lang.Boolean', float: 'java.lang.Float', double: 'java.lang.Double' };
|
|
140
|
+
const STATED = { int: 'int', long: 'long', short: 'short', byte: 'byte', char: 'char', float: 'double', double: 'double', bool: 'boolean', boolean: 'boolean', str: 'java.lang.String', String: 'java.lang.String', i32: 'int', i64: 'long' };
|
|
140
141
|
const KT = { int: 'Int', long: 'Long', short: 'Short', byte: 'Byte', char: 'Char', boolean: 'Boolean', float: 'Float', double: 'Double', 'java.lang.String': 'String' };
|
|
141
142
|
// The code compiled for the check: a copy of the file with the clock's and the answered calls' sites rewritten.
|
|
142
143
|
function compiled(lang, mod, read, o, made) {
|
|
143
144
|
const fs = node('node:fs'), cp = node('node:child_process'), os = node('node:os'), path = node('node:path');
|
|
144
145
|
const j = jvmOf(mod), kotlin = lang === 'kotlin';
|
|
146
|
+
// (a call of a generic result, a type variable's: the answer given in the type it is stated in)
|
|
147
|
+
const sortOf = new Map(read.answers.map(a => [a.key, STATED[a.sort.replace(/\s*\|\s*None$|\?$/, '')]]));
|
|
145
148
|
const sites = [...j.rewrites.map(r => ({ span: r.span, text: 'gdp.Rt.now()' })), ...answerSites(mod, read.answers.filter(a => !a.patch.store).map(a => a.key)).map(s => {
|
|
146
|
-
const
|
|
149
|
+
const t0 = s.jt.replace(/\?$/, '').replace(/<.*$/, ''), t = (t0 === 'java.lang.Object' || !(t0 in BOXES || t0.includes('.'))) ? sortOf.get(s.key) ?? t0 : t0, box = BOXES[t] ?? t;
|
|
147
150
|
return { span: s.span, text: kotlin ? `(gdp.Rt.answer(${JSON.stringify(s.key)}, ${box}::class.java) as ${KT[t] ?? t.split('.').pop()}${s.jt.endsWith('?') ? '?' : ''})` : `((${box}) gdp.Rt.answer(${JSON.stringify(s.key)}, ${box}.class))` };
|
|
148
151
|
})];
|
|
149
152
|
if (o.prebuilt)
|
|
@@ -158,19 +161,58 @@ function compiled(lang, mod, read, o, made) {
|
|
|
158
161
|
const copy = `${work}/src/${rel}`;
|
|
159
162
|
fs.mkdirSync(path.dirname(copy), { recursive: true });
|
|
160
163
|
fs.writeFileSync(copy, text);
|
|
161
|
-
const
|
|
162
|
-
|
|
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) => {
|
|
163
168
|
if (kotlin) {
|
|
164
169
|
const kt = kotlinLib(o);
|
|
165
|
-
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(':'),
|
|
166
|
-
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`];
|
|
167
172
|
}
|
|
168
|
-
cp.execFileSync(jdk(o).javac, ['-nowarn', '-Xlint:none', '-proc:none', '-implicit:class', '-d', out, '-sourcepath', `${
|
|
169
|
-
return
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
|
|
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 };
|
|
173
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 };
|
|
174
216
|
}
|
|
175
217
|
export function extractJvm(lang, at, opts = {}) {
|
|
176
218
|
const file = pathOf(at);
|
|
@@ -178,6 +220,16 @@ export function extractJvm(lang, at, opts = {}) {
|
|
|
178
220
|
try {
|
|
179
221
|
if (opts.stores && Object.keys(opts.stores).length)
|
|
180
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)`);
|
|
181
233
|
mod = readJvm(lang, file, entryNames(opts), opts);
|
|
182
234
|
// (the shipped classes can't be rewritten: an answer, other than an injected dependency's, can't be stubbed)
|
|
183
235
|
if (opts.prebuilt)
|
|
@@ -204,7 +256,7 @@ export function extractJvm(lang, at, opts = {}) {
|
|
|
204
256
|
throw e;
|
|
205
257
|
}
|
|
206
258
|
if (c.error)
|
|
207
|
-
return { cmd: 'false', args: [], hello: {}, error: c.error };
|
|
259
|
+
return { cmd: 'false', args: [], hello: {}, error: c.error, ...(c.kind ? { kind: c.kind } : {}) };
|
|
208
260
|
const t = tools(opts);
|
|
209
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 } };
|
|
210
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,17 +1,17 @@
|
|
|
1
|
-
import { Refusal, pathOf } from "./extract-read.js";
|
|
2
|
-
import { entryNames, extractStep, node } from "./extract-step.js";
|
|
1
|
+
import { Refusal, pathOf, readerRun, statedRefusal } from "./extract-read.js";
|
|
2
|
+
import { asset, entryNames, extractStep, node } from "./extract-step.js";
|
|
3
3
|
export { proveRule, proveSteps } from "./dsl.js";
|
|
4
|
-
const here = (f) =>
|
|
4
|
+
const here = (f) => asset(`py/${f}`);
|
|
5
5
|
// The module as the reader lowers it (the names given and the module's functions).
|
|
6
6
|
export function readPython(file, names, opts = {}) {
|
|
7
7
|
const cp = node('node:child_process'), path = node('node:path');
|
|
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,17 +1,17 @@
|
|
|
1
|
-
import { Refusal, pathOf } from "./extract-read.js";
|
|
2
|
-
import { entryNames, extractStep, node } from "./extract-step.js";
|
|
1
|
+
import { Refusal, pathOf, readerRun, statedRefusal } from "./extract-read.js";
|
|
2
|
+
import { asset, entryNames, extractStep, node } from "./extract-step.js";
|
|
3
3
|
export { proveRule, proveSteps } from "./dsl.js";
|
|
4
|
-
const here = (f) =>
|
|
4
|
+
const here = (f) => asset(`rb/${f}`);
|
|
5
5
|
// The file as the reader lowers it (the class named).
|
|
6
6
|
export function readRuby(file, names, opts = {}) {
|
|
7
7
|
const cp = node('node:child_process'), path = node('node:path');
|
|
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)
|