gdp-wired 0.43.0 → 0.44.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/cli.d.ts +6 -0
- package/dist/core/cli.js +48 -6
- package/dist/core/data.js +2 -2
- 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/extract-c.d.ts +2 -0
- package/dist/core/extract-c.js +5 -3
- package/dist/core/extract-check.d.ts +1 -0
- package/dist/core/extract-check.js +8 -1
- package/dist/core/extract-ex.js +2 -2
- package/dist/core/extract-go-check.js +4 -6
- package/dist/core/extract-go.d.ts +3 -0
- package/dist/core/extract-go.js +4 -4
- package/dist/core/extract-jvm.js +6 -3
- package/dist/core/extract-py.js +2 -2
- package/dist/core/extract-rb.js +2 -2
- package/dist/core/extract-rs.js +12 -7
- package/dist/core/extract-sol.js +4 -4
- package/dist/core/extract-step.d.ts +9 -0
- package/dist/core/extract-step.js +48 -9
- package/dist/core/extract-swift.js +3 -3
- package/dist/core/infer.js +3 -3
- package/dist/core/jvm/Harness.java +8 -1
- package/dist/core/jvm/Jvm.java +1 -1
- package/dist/core/jvm/KtReader.java +3 -0
- package/dist/core/machine.d.ts +3 -0
- package/dist/core/machine.js +15 -1
- package/dist/core/py/harness.py +51 -13
- package/dist/core/sol/Replay.sol +52 -0
- package/dist/core/sol/harness.py +508 -0
- package/dist/core/system.js +12 -3
- package/dist/interchange/check.d.ts +18 -1
- package/dist/interchange/check.js +9 -2
- package/dist/interchange/cli.d.ts +2 -0
- package/dist/interchange/cli.js +45 -0
- package/dist/interchange/format.d.ts +1 -1
- package/dist/interchange/format.js +15 -7
- package/dist/kernel/cdcl.js +32 -12
- package/dist/kernel/reader.js +3 -2
- package/package.json +12 -3
|
@@ -1664,8 +1664,12 @@ export class Stepper {
|
|
|
1664
1664
|
if (!pa.inject && (this.scalar(t) || ['lock', 'none', 'map', 'list'].includes(t.k) || (t.k === 'rec' && this.mod.recs[t.name]?.own && !this.mod.recs[t.name].kinds.includes('protocol')) || (pa.dflt && !(pa.t.k === 'opt' && pa.dflt.e === 'none'))))
|
|
1665
1665
|
return undefined;
|
|
1666
1666
|
const fields = [];
|
|
1667
|
-
|
|
1668
|
-
|
|
1667
|
+
// (self.f = arg, or one place of a tuple's, self.a, self.f = a, arg)
|
|
1668
|
+
const pairs = (to, v) => (to?.e === 'tuple' && v?.e === 'tuple' && to.xs.length === v.xs.length ? to.xs.flatMap((t, i) => pairs(t, v.xs[i])) : [[to, v]]);
|
|
1669
|
+
deep(init.body, st => { if (st.s === 'set')
|
|
1670
|
+
for (const [to, v] of pairs(st.to, st.x))
|
|
1671
|
+
if (to?.e === 'get' && to.x.e === 'var' && to.x.n === 'self' && v?.e === 'var' && v.n === pa.name)
|
|
1672
|
+
fields.push(String(to.f)); });
|
|
1669
1673
|
const ms = this.callsOn(r, fields);
|
|
1670
1674
|
if (!pa.inject && !ms.length)
|
|
1671
1675
|
return undefined;
|
|
@@ -1759,7 +1763,13 @@ export class Stepper {
|
|
|
1759
1763
|
}
|
|
1760
1764
|
continue;
|
|
1761
1765
|
}
|
|
1762
|
-
|
|
1766
|
+
// (another option given a constant, None or a flag, as a tracing span or which tier to use: the store is read as
|
|
1767
|
+
// one map whatever it says, the check's too, and the note says so; one given a value of the request is refused)
|
|
1768
|
+
if (v.t === 'none' || (v.t === 'bool' && v.e.op === 'const') || (v.t === 'num' && v.e.op === 'const') || (v.t === 'str' && v.e.op === 'slit')) {
|
|
1769
|
+
this.notes.add(`${store}.${m}: its ${n} (${v.t === 'none' ? 'None' : v.t === 'str' ? JSON.stringify(v.e.value) : String(v.e.v)}) left out: the store read as one map whatever it says`);
|
|
1770
|
+
continue;
|
|
1771
|
+
}
|
|
1772
|
+
return refuse(at, `${at.text}: the store's ${m} given ${n}, a value the request decides (the subset reads a key, a value, nx, xx, the expiry and options given a constant)`);
|
|
1763
1773
|
}
|
|
1764
1774
|
given(all.filter(v => v !== keyV && v !== valV));
|
|
1765
1775
|
if (args.length > (kind === 'set' ? 2 : 1))
|
|
@@ -2045,6 +2055,8 @@ export class Stepper {
|
|
|
2045
2055
|
// other code may change it: refused unless the caller states it. Its value read (a run refused where it is): the next
|
|
2046
2056
|
// run answers it by the request, over its declared type; else it is left out, kept only where nothing reads it.
|
|
2047
2057
|
pend = new Map();
|
|
2058
|
+
// (the calls of other code left out, by the callee's names: a check that can't run them, C's, makes them no-ops)
|
|
2059
|
+
leftOut = new Set();
|
|
2048
2060
|
returnedBy = new Map();
|
|
2049
2061
|
entryIds = new Set();
|
|
2050
2062
|
boundary(x, b, p, awaited) {
|
|
@@ -2061,6 +2073,7 @@ export class Stepper {
|
|
|
2061
2073
|
return this.answer(b.key, [b.name], b.patch, x, q, awaited, t, tag ? 'tagged' : 'inferred');
|
|
2062
2074
|
const why = `${x.text ?? b.name}: the value of ${b.name}, other code left out`;
|
|
2063
2075
|
this.pend.set(why, { ...b, why, at: x.p, ...(x.end ? { end: x.end } : {}) });
|
|
2076
|
+
this.leftOut.add(b.name).add(b.key);
|
|
2064
2077
|
this.notes.add(`${b.name} (${x.p}): left out (${tag ? 'tagged: gdp: skip' : 'inferred: nothing the rule keeps reads its value'}), run as it is by the check`);
|
|
2065
2078
|
return [{ t: 'opaque', why, ask: b.key }, this.passing(b.key, b.name, b.patch, x, q, awaited)];
|
|
2066
2079
|
}
|
|
@@ -2380,6 +2393,8 @@ export class Stepper {
|
|
|
2380
2393
|
if (ans)
|
|
2381
2394
|
return this.answer(ans, names, patch, x, x.args ? this.argsRead(x, p) : p, false);
|
|
2382
2395
|
if (this.skipped(names)) {
|
|
2396
|
+
for (const n of names)
|
|
2397
|
+
this.leftOut.add(n);
|
|
2383
2398
|
this.notes.add(`${names[0]} (${x.p}): left out (stated: skip), run as it is by the check`);
|
|
2384
2399
|
return [{ t: 'opaque', why: `${names[0]}: the value of a call left out (skip)` }, this.passing(names[0], names[0], patch, x, x.args ? this.argsRead(x, p) : p, false)];
|
|
2385
2400
|
}
|
|
@@ -3137,6 +3152,9 @@ export class Stepper {
|
|
|
3137
3152
|
const r = this.rec(obj.ty, x);
|
|
3138
3153
|
patch = { mod: r.module, path: [r.short, String(fx.f)] };
|
|
3139
3154
|
}
|
|
3155
|
+
// (a method of a store or an injected dependency: stubbed on the one the check gives)
|
|
3156
|
+
else if (obj?.k === 'store')
|
|
3157
|
+
patch = { store: obj.name, path: [String(fx.f)] };
|
|
3140
3158
|
else {
|
|
3141
3159
|
const [v] = this.ev(fx, p);
|
|
3142
3160
|
if (v.t === 'ext' || v.t === 'cls')
|
|
@@ -3150,6 +3168,8 @@ export class Stepper {
|
|
|
3150
3168
|
}
|
|
3151
3169
|
if (ans)
|
|
3152
3170
|
return this.answer(ans, names, patch, x, this.argsRead(x, p), awaited);
|
|
3171
|
+
for (const n of names)
|
|
3172
|
+
this.leftOut.add(n);
|
|
3153
3173
|
this.notes.add(`${names[0]} (${x.p}): left out (stated: skip), run as it is by the check`);
|
|
3154
3174
|
return [{ t: 'opaque', why: `${x.text}: the value of a call left out (skip)` }, this.passing(names[0], names[0], patch, x, this.argsRead(x, p), awaited)];
|
|
3155
3175
|
}
|
|
@@ -4789,7 +4809,8 @@ function readOnce(mod, opts, g) {
|
|
|
4789
4809
|
// --- the requests: each method (or function) one -------------------------------------------------------------------
|
|
4790
4810
|
const r = cls ? g.rec(cls, at) : undefined;
|
|
4791
4811
|
const chosen = cls
|
|
4792
|
-
|
|
4812
|
+
// (by default its public methods but the one it is made by, Rust's new, which takes no object)
|
|
4813
|
+
? (opts.methods ?? writing ?? Object.keys(r.methods).filter(m => !m.startsWith('_') && r.methods[m] && !(mod.lang === 'rust' && m === 'new'))).map(m => (r.methods[m] ? g.func(r.methods[m], at) : refuse(at, `no method ${r.short}.${m} in ${mod.file}`)))
|
|
4793
4814
|
: entries.map(e => g.func(e.id, at));
|
|
4794
4815
|
if (!chosen.length)
|
|
4795
4816
|
refuse(at, `${cls ? r.short : 'the entry'} has no methods to read`);
|
|
@@ -5223,19 +5244,35 @@ export function iteTerm(c, a, b) {
|
|
|
5223
5244
|
const proc = globalThis.process;
|
|
5224
5245
|
export const node = (id) => { const m = proc?.getBuiltinModule?.(id); if (!m)
|
|
5225
5246
|
throw new Error(`the extractor runs the code's toolchain through ${id} (Node 20.16 or later, or Bun)`); return m; };
|
|
5247
|
+
// A file gdp-wired runs beside its modules (a front end's reader or harness, core/<lang>/...): its path, or a clear
|
|
5248
|
+
// error when the install lacks it.
|
|
5249
|
+
export function asset(rel) {
|
|
5250
|
+
const p = node('node:url').fileURLToPath(new URL(`./${rel}`, import.meta.url));
|
|
5251
|
+
if (!node('node:fs').existsSync(p))
|
|
5252
|
+
throw new Error(`gdp-wired's ${rel} is missing from its install (${p}): reinstall gdp-wired`);
|
|
5253
|
+
return p;
|
|
5254
|
+
}
|
|
5255
|
+
// A harness started on the two named pipes in `work` and both opened. It runs under sh, which, if the harness exits
|
|
5256
|
+
// before it answered (it couldn't start: a file missing, an interpreter absent, the code not loading), opens the
|
|
5257
|
+
// pipes itself and answers the first request with the error, so nothing here waits on a harness that is gone.
|
|
5258
|
+
const GUARD = 'i=$1 o=$2; shift 2; trap \'kill $p 2>/dev/null; exit 143\' TERM; "$@" "$i" "$o" & p=$!; wait $p; e=$?; [ "$e" = 0 ] && exit 0; trap - TERM; exec 3<"$i" 4>"$o"; read -r _ <&3; printf \'{"error": "the harness exited (status %s) before it answered"}\\n\' "$e" >&4';
|
|
5259
|
+
export function openHarness(work, cmd, args, o) {
|
|
5260
|
+
const fs = node('node:fs'), cp = node('node:child_process');
|
|
5261
|
+
cp.execFileSync('mkfifo', [`${work}/in`, `${work}/out`], {});
|
|
5262
|
+
const child = cp.spawn('sh', ['-c', GUARD, 'gdp-harness', `${work}/in`, `${work}/out`, cmd, ...args], o);
|
|
5263
|
+
const wi = fs.openSync(`${work}/in`, 'w'), ro = fs.openSync(`${work}/out`, 'r');
|
|
5264
|
+
return { child, wi, ro };
|
|
5265
|
+
}
|
|
5226
5266
|
export function checkStep(h, read, r, sorts, opts) {
|
|
5227
5267
|
const o = opts.check ?? {}, m = read.model, bound = o.bound ?? 12;
|
|
5228
|
-
const fs = node('node:fs'),
|
|
5268
|
+
const fs = node('node:fs'), os = node('node:os');
|
|
5229
5269
|
const work = fs.mkdtempSync(`${os.tmpdir()}/gdp-stepcheck-`);
|
|
5230
5270
|
let child, wi = -1, ro = -1;
|
|
5231
5271
|
const empty = { 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, runMs: 0 };
|
|
5232
5272
|
try {
|
|
5233
5273
|
if (h.error)
|
|
5234
5274
|
return { ...empty, mismatch: h.error };
|
|
5235
|
-
|
|
5236
|
-
child = cp.spawn(h.cmd, [...h.args, `${work}/in`, `${work}/out`], { stdio: ['ignore', 'ignore', 'inherit'], env: { ...proc?.env, ...h.env } });
|
|
5237
|
-
wi = fs.openSync(`${work}/in`, 'w');
|
|
5238
|
-
ro = fs.openSync(`${work}/out`, 'r');
|
|
5275
|
+
({ child, wi, ro } = openHarness(work, h.cmd, h.args, { stdio: ['ignore', 'ignore', 'inherit'], env: { ...proc?.env, ...h.env } }));
|
|
5239
5276
|
const buf = new Uint8Array(1 << 20), dec = new TextDecoder();
|
|
5240
5277
|
let pend = '';
|
|
5241
5278
|
const line = () => {
|
|
@@ -5300,6 +5337,8 @@ export function checkStep(h, read, r, sorts, opts) {
|
|
|
5300
5337
|
throw new Error(JSON.stringify(res.error)); return toSnap(res.state); },
|
|
5301
5338
|
call: (self, e, args) => {
|
|
5302
5339
|
const res = ask({ op: 'call', id: self, m: e.call, a: args, now, answers: answersOf(e.call) });
|
|
5340
|
+
if (res.outside !== undefined)
|
|
5341
|
+
return { ok: false, outside: true, error: res.outside };
|
|
5303
5342
|
if (res.frame)
|
|
5304
5343
|
throw new Error(`the code changes ${res.frame}, a field the rule leaves out`);
|
|
5305
5344
|
if (res.bad !== undefined)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Refusal, pathOf } from "./extract-read.js";
|
|
2
|
-
import { entryNames, extractStep, node, stubbed } from "./extract-step.js";
|
|
2
|
+
import { asset, entryNames, extractStep, node, stubbed } from "./extract-step.js";
|
|
3
3
|
export { proveRule, proveSteps } from "./dsl.js";
|
|
4
4
|
const env = () => globalThis.process?.env ?? {};
|
|
5
5
|
const errText = (e) => { const ls = `${e.stdout ?? ''}\n${e.stderr ?? ''}`.split('\n'); return (ls.filter(l => /\berror:/.test(l)).length ? ls.filter(l => /\berror:/.test(l)) : ls.filter(l => /error|fatal/i.test(l))).slice(0, 4).join(' | ').slice(0, 900) || String(e.message).slice(0, 300); };
|
|
@@ -10,7 +10,7 @@ const swiftOf = (o) => o.swift ?? env().GDP_SWIFT ?? 'swift';
|
|
|
10
10
|
// Else the reader's package, swift-syntax pinned, built by SwiftPM: minutes, once.
|
|
11
11
|
export function swiftReader(o = {}) {
|
|
12
12
|
const fs = node('node:fs'), cp = node('node:child_process'), os = node('node:os'), path = node('node:path');
|
|
13
|
-
const dir =
|
|
13
|
+
const dir = asset('swift/'), main = `${dir}Sources/gdp-swiftreader/main.swift`;
|
|
14
14
|
let version;
|
|
15
15
|
try {
|
|
16
16
|
version = cp.execFileSync(swiftOf(o), ['--version'], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] });
|
|
@@ -130,7 +130,7 @@ export function extractSwift(where, opts = {}) {
|
|
|
130
130
|
}
|
|
131
131
|
// --- the harness: Swift beside the code, generated per reading ----------------------------------------------------------
|
|
132
132
|
// (its fixed parts, Swift files shipped beside the reader)
|
|
133
|
-
const resource = (f) => node('node:fs').readFileSync(
|
|
133
|
+
const resource = (f) => node('node:fs').readFileSync(asset(`swift/${f}`), 'utf8');
|
|
134
134
|
// The Swift name of an integer type, and of an answer's type.
|
|
135
135
|
const intName = (t) => { const x = t; return x.sw ?? (x.bits === 64 || !x.bits ? (x.signed === false ? 'UInt' : 'Int') : `${x.signed === false ? 'UInt' : 'Int'}${x.bits}`); };
|
|
136
136
|
function answerType(a, read) {
|
package/dist/core/infer.js
CHANGED
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
// rules it out (and the most of those seen) is added; a chosen candidate that nothing supports, or that makes a proof slow, is dropped; the set proven as a whole
|
|
33
33
|
// is the answer, after each chosen candidate the proof doesn't need is taken out again
|
|
34
34
|
import { quietly } from "./cyclic.js";
|
|
35
|
-
import { all, any, atMost, carriedView, compileC, compileE, loadJs, divisorsIn, evalC, evalE, get, interpret, machineTerms, fnValue, modName, n, not, plus, same,
|
|
35
|
+
import { all, any, atMost, carriedView, compileC, compileE, loadJs, divisorsIn, evalC, evalE, get, interpret, machineTerms, fnValue, modName, n, not, plus, same, searchSeeded, times, walk, withArithmetic, x } from "./machine.js";
|
|
36
36
|
import { bool, proveRule, proveSteps, verdictOf } from "./dsl.js";
|
|
37
37
|
import { allowed, keysOf, linKey, watch } from "./watch.js";
|
|
38
38
|
import { clock, counted, fullWork, decideLaw, decideNote, machineKey, memoHits, withStrict, fullRate, grow, keyValue, lawInstances, proveLaw, proveLaws, proveSetFast, proveStepLaws, stepLawInstances, usedHyps, withDeadline, withModels, withTrees, withWall, withWork } from "../kernel/prove.js";
|
|
@@ -767,7 +767,7 @@ function inferLawsSearch(target, laws, stepLaws = [], opts = {}) {
|
|
|
767
767
|
if ((first.proven && first.checked) || first.run)
|
|
768
768
|
return { ...first, found: [], stats: stats(0, 0, 0) };
|
|
769
769
|
// --- runs ------------------------------------------------------------------------------------------------------------
|
|
770
|
-
const run = interpret(m), rand =
|
|
770
|
+
const run = interpret(m), rand = searchSeeded(17), kinds = rule ? rule.kindsOfState() : [];
|
|
771
771
|
const given = rule ? [...rule.kindLaws().filter(k => !laws.some(l => l.name === k.name)), ...laws] : laws;
|
|
772
772
|
const randomParams = (bound, r = rand) => (rule ? rule.randomParams(r, bound) : Object.fromEntries(m.params.map(p => [p, r(bound + 1)])));
|
|
773
773
|
const randomInput = (params, bound, r = rand) => (rule ? rule.randomInput(r, bound, params)
|
|
@@ -3126,7 +3126,7 @@ function inferLawsSearch(target, laws, stepLaws = [], opts = {}) {
|
|
|
3126
3126
|
for (const f of live)
|
|
3127
3127
|
byView.set(f.view, [...(byView.get(f.view) ?? []), f]);
|
|
3128
3128
|
let read = 0, still = 0, lastKill = 0;
|
|
3129
|
-
const r = instance(grow, share,
|
|
3129
|
+
const r = instance(grow, share, searchSeeded(29 + k), most5, q => {
|
|
3130
3130
|
if (read >= most5 || (read >= (k ? 0 : least5) && still >= quiet) || stop())
|
|
3131
3131
|
return false;
|
|
3132
3132
|
states++;
|
|
@@ -46,7 +46,7 @@ public final class Harness {
|
|
|
46
46
|
if (dels.contains(n) && a != null && a.length >= 1) { st.data.remove(String.valueOf(a[0])); return m.getReturnType() == void.class || m.getReturnType().isPrimitive() ? conv(null, m.getReturnType(), null) : null; }
|
|
47
47
|
for (Object a0 : list(S.get("answers"))) {
|
|
48
48
|
Map<?, ?> an = (Map<?, ?>) a0, pt = (Map<?, ?>) an.get("patch");
|
|
49
|
-
if (pt != null && name.equals(pt.get("store")) && n.equals(list(pt.get("path")).get(list(pt.get("path")).size() - 1))) { Object v = CUR.get(an.get("key")); return v == null || ((Map<?, ?>) v).containsKey("none") ? conv(null,
|
|
49
|
+
if (pt != null && name.equals(pt.get("store")) && n.equals(list(pt.get("path")).get(list(pt.get("path")).size() - 1))) { Object v = CUR.get(an.get("key")); Class<?> rc = stated(m.getReturnType(), an.get("sort")); return v == null || ((Map<?, ?>) v).containsKey("none") ? conv(null, rc, m.getGenericReturnType()) : conv(((Map<?, ?>) v).get("in"), rc, m.getGenericReturnType()); }
|
|
50
50
|
}
|
|
51
51
|
// (a method the rule leaves out runs as nothing, as the rule takes it; any other fails: the check reports it)
|
|
52
52
|
if (d == null || !list(d.get("skip")).contains(n)) throw new UnsupportedOperationException(name + "." + n + ": a method of the injected dependency the rule doesn't read");
|
|
@@ -119,6 +119,13 @@ public final class Harness {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
// --- values ---------------------------------------------------------------------------------------------------------
|
|
122
|
+
// The class an answer is given as: the method's declared one, or where that is a type variable's erasure (a generic
|
|
123
|
+
// result, Object), the type the answer is stated in.
|
|
124
|
+
static Class<?> stated(Class<?> c, Object sort) {
|
|
125
|
+
if (c != Object.class || !(sort instanceof String s)) return c;
|
|
126
|
+
return switch (s.replaceAll("\\s*\\|\\s*None$|\\?$", "")) { case "int", "Integer", "Int", "i32" -> Integer.class; case "long", "Long", "i64" -> Long.class; case "short", "Short" -> Short.class; case "byte", "Byte" -> Byte.class;
|
|
127
|
+
case "float", "double", "Double" -> Double.class; case "Float" -> Float.class; case "bool", "boolean", "Boolean" -> Boolean.class; case "str", "String" -> String.class; default -> c; };
|
|
128
|
+
}
|
|
122
129
|
static Object conv(Object v, Class<?> c, Type g) {
|
|
123
130
|
if (c == Optional.class) return v == null ? Optional.empty() : Optional.of(conv(v, g instanceof ParameterizedType pt ? raw(pt.getActualTypeArguments()[0]) : Object.class, null));
|
|
124
131
|
if (v == null) return c.isPrimitive() ? conv(0L, c, null) : null;
|
package/dist/core/jvm/Jvm.java
CHANGED
|
@@ -111,7 +111,7 @@ public final class Jvm {
|
|
|
111
111
|
static boolean integral(JT t) { String q = prim(t); return q != null && Set.of("int", "long", "short", "byte", "char").contains(q); }
|
|
112
112
|
static boolean floating(JT t) { String q = prim(t); return "float".equals(q) || "double".equals(q); }
|
|
113
113
|
static boolean map(JT t) { return t != null && MAPS.contains(t.n); }
|
|
114
|
-
static boolean atomic(JT t) { return t != null && t.n.startsWith("java.util.concurrent.atomic.Atomic") || t.n.startsWith("kotlinx.atomicfu.Atomic"); }
|
|
114
|
+
static boolean atomic(JT t) { return t != null && (t.n.startsWith("java.util.concurrent.atomic.Atomic") || t.n.startsWith("kotlinx.atomicfu.Atomic")); }
|
|
115
115
|
// The type an atomic holds.
|
|
116
116
|
static JT held(JT t) {
|
|
117
117
|
return switch (t.simple()) { case "AtomicInteger", "AtomicInt" -> new JT("int"); case "AtomicLong" -> new JT("long"); case "AtomicBoolean" -> new JT("boolean"); default -> t.arg(0); };
|
|
@@ -863,6 +863,9 @@ public final class KtReader implements Jvm.Env {
|
|
|
863
863
|
X body = inline(lam, null, recv, c, stmt && n.equals("let"), p);
|
|
864
864
|
return n.equals("also") ? recv : body;
|
|
865
865
|
}
|
|
866
|
+
// (any other call given a lambda: other code runs it, any number of times; repeat(n) { } a loop. require's and
|
|
867
|
+
// check's lambda is their failure's message, read as they are)
|
|
868
|
+
if (lam != null && !(recv == null && Set.of("require", "check", "requireNotNull", "checkNotNull").contains(n))) return no1(ce, recv == null && n.equals("repeat") ? "a loop (repeat)" : "a lambda given to " + n + " (a closure other code runs)");
|
|
866
869
|
List<Map<String, Object>> args = new ArrayList<>();
|
|
867
870
|
List<JT> argT = new ArrayList<>();
|
|
868
871
|
List<Object> kw = new ArrayList<>();
|
package/dist/core/machine.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { type Constraint, type Verdict } from './solver.js';
|
|
2
|
+
export declare const lcg: (x: number) => number;
|
|
2
3
|
export type Rand = (k: number) => number;
|
|
3
4
|
export declare const seeded: (seed: number) => Rand;
|
|
5
|
+
export declare const lcgFloat: (x: number) => number;
|
|
6
|
+
export declare const searchSeeded: (seed: number) => Rand;
|
|
4
7
|
export declare const walk: (t: unknown, f: (o: Record<string, unknown>) => void) => void;
|
|
5
8
|
export declare const walkOnce: (t: unknown, f: (o: object) => void) => void;
|
|
6
9
|
export type E = {
|
package/dist/core/machine.js
CHANGED
|
@@ -7,7 +7,21 @@
|
|
|
7
7
|
// every other key the step reads).
|
|
8
8
|
import { boundOf, crossFree, historyMachine, keyTerm, plainKey, scope, sumRuntime } from "../kernel/kernel.js";
|
|
9
9
|
import { add, env, eq, k, le, lt, nat, scale, show, solve, sub, v } from "./solver.js";
|
|
10
|
-
|
|
10
|
+
// The one generator of the repo's random draws: x' = (1103515245 x + 12345) mod 2^31, exact (Math.imul). In doubles
|
|
11
|
+
// the product passes 2^53 and rounds, which folds every seed into one of six short cycles (61 to 10,466 steps; 98.8% of
|
|
12
|
+
// seeds into the same one). Its period is 2^31 (core/rand.test.ts). Draws are its high bits (the low ones repeat with a
|
|
13
|
+
// short period). Every test, harness and fuzz draws from it.
|
|
14
|
+
export const lcg = (x) => (Math.imul(x, 1103515245) + 12345) & 0x7fffffff;
|
|
15
|
+
export const seeded = (seed) => { let x = seed; return k => { x = lcg(x); return Math.floor(x / 2 ** 31 * k); }; };
|
|
16
|
+
// The searches still on the float form's stream (one 10,466-step cycle whatever the seed): infer.ts's runs and
|
|
17
|
+
// candidates, data.ts's rng, and the CHC and ITS runners' own runs (which feed infer). Under exact draws their results
|
|
18
|
+
// hinge on the draw: over 20 seed shifts, the system test's lease 1, the infer test's in-flight bound 15, the CHC task
|
|
19
|
+
// s_split_22 2, frontier2's break_safe 18, and bstInsert 9 (data.ts: which 240 random models its search compares terms
|
|
20
|
+
// in decides it, 0 of 8 shifts with the models fixed, the same 01001101 with only the models shifted). The rest of the
|
|
21
|
+
// searches (dsl's walks, nonterm, effect's runs, discover, live, cycles, fresh, xstate, the extractors' checks) draw
|
|
22
|
+
// from `seeded`. One moves to `seeded` once its result no longer turns on the draw.
|
|
23
|
+
export const lcgFloat = (x) => (x * 1103515245 + 12345) % 2 ** 31;
|
|
24
|
+
export const searchSeeded = (seed) => { let x = seed; return k => { x = lcgFloat(x); return Math.floor(x / 2 ** 31 * k); }; };
|
|
11
25
|
// Every object in a term, the term first.
|
|
12
26
|
export const walk = (t, f) => {
|
|
13
27
|
if (Array.isArray(t)) {
|
package/dist/core/py/harness.py
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
# one that keeps what is set, the clock read as the request's time. Line events count the branch arms reached.
|
|
5
5
|
#
|
|
6
6
|
# python3 core/py/harness.py <in-fifo> <out-fifo>
|
|
7
|
-
import asyncio, dataclasses, datetime, importlib, inspect, json, os, sys, types
|
|
7
|
+
import asyncio, builtins, dataclasses, datetime, importlib, inspect, json, os, sys, types
|
|
8
8
|
import time as time_module
|
|
9
9
|
|
|
10
10
|
NOW = [0]
|
|
@@ -260,19 +260,56 @@ class _Now(datetime.datetime):
|
|
|
260
260
|
"""datetime.datetime with now() the request's time (local, naive, as the code's own now())."""
|
|
261
261
|
@classmethod
|
|
262
262
|
def now(cls, tz=None): return datetime.datetime.fromtimestamp(NOW[0], tz)
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
263
|
+
# (where it is seen anyway, a type read while the clock is pinned, pydantic's: a datetime)
|
|
264
|
+
@classmethod
|
|
265
|
+
def __get_pydantic_core_schema__(cls, source, handler): return handler(datetime.datetime)
|
|
266
|
+
|
|
267
|
+
# The clock the repository's modules read (time.time(), datetime.now()) made the request's time, only while the code
|
|
268
|
+
# runs (making the object, a call): a module's names are its own again between, so a framework that reads them, an
|
|
269
|
+
# annotation or a route's types, sees the real datetime; a module made while the clock was pinned put back too.
|
|
270
|
+
CLOCKS = {'root': None, 'n': -1, 'pins': [], 'depth': 0}
|
|
271
|
+
def scan_clocks():
|
|
272
|
+
if len(sys.modules) == CLOCKS['n']: return
|
|
273
|
+
CLOCKS['n'] = len(sys.modules)
|
|
274
|
+
dtm = CLOCKS.get('dtm')
|
|
275
|
+
if dtm is None:
|
|
276
|
+
dtm = CLOCKS['dtm'] = types.SimpleNamespace(**{k: getattr(datetime, k) for k in dir(datetime) if not k.startswith('__')})
|
|
277
|
+
dtm.datetime = _Now
|
|
278
|
+
pins = []
|
|
269
279
|
for m in list(sys.modules.values()):
|
|
270
280
|
f = getattr(m, '__file__', None)
|
|
271
|
-
if not f or not os.path.realpath(f).startswith(root + os.sep): continue
|
|
281
|
+
if not f or not os.path.realpath(f).startswith(CLOCKS['root'] + os.sep): continue
|
|
272
282
|
for n, v in list(vars(m).items()):
|
|
273
|
-
if v is time_module:
|
|
274
|
-
elif v is datetime:
|
|
275
|
-
elif v is datetime.datetime:
|
|
283
|
+
if v is time_module or isinstance(v, Clock): pins.append((m, n, time_module, Clock(time_module)))
|
|
284
|
+
elif v is datetime or v is dtm: pins.append((m, n, datetime, dtm))
|
|
285
|
+
elif v is datetime.datetime or v is _Now: pins.append((m, n, datetime.datetime, _Now))
|
|
286
|
+
CLOCKS['pins'] = pins
|
|
287
|
+
|
|
288
|
+
def put_clocks(fake):
|
|
289
|
+
for m, n, real, f in CLOCKS['pins']: setattr(m, n, f if fake else real)
|
|
290
|
+
|
|
291
|
+
# (an import the code makes while it runs, a module of the repository first loaded then: run with the real clock, so
|
|
292
|
+
# what it copies or builds from the module's names is the real datetime, imports inside it too; the clock pinned
|
|
293
|
+
# again after the outermost, the new modules' names too)
|
|
294
|
+
REAL_IMPORT = builtins.__import__
|
|
295
|
+
def clock_import(*a, **k):
|
|
296
|
+
if CLOCKS['depth'] == 0: put_clocks(False)
|
|
297
|
+
CLOCKS['depth'] += 1
|
|
298
|
+
try: return REAL_IMPORT(*a, **k)
|
|
299
|
+
finally:
|
|
300
|
+
CLOCKS['depth'] -= 1
|
|
301
|
+
if CLOCKS['depth'] == 0: scan_clocks(); put_clocks(True)
|
|
302
|
+
|
|
303
|
+
class pinned:
|
|
304
|
+
def __enter__(self):
|
|
305
|
+
scan_clocks(); put_clocks(True)
|
|
306
|
+
builtins.__import__ = clock_import
|
|
307
|
+
def __exit__(self, *a):
|
|
308
|
+
builtins.__import__ = REAL_IMPORT
|
|
309
|
+
put_clocks(False); scan_clocks(); put_clocks(False)
|
|
310
|
+
|
|
311
|
+
def pin_clocks(root):
|
|
312
|
+
CLOCKS['root'] = os.path.realpath(root)
|
|
276
313
|
|
|
277
314
|
def raises_here(key):
|
|
278
315
|
"""Whether a call left out raises here, as the request says: only at the sites the rule read it may raise (a call of
|
|
@@ -347,7 +384,8 @@ def make(args):
|
|
|
347
384
|
else:
|
|
348
385
|
kw = fixed_args(args, {})
|
|
349
386
|
sys.settrace(tracer)
|
|
350
|
-
try:
|
|
387
|
+
try:
|
|
388
|
+
with pinned(): obj = run(S['cls'](**kw))
|
|
351
389
|
finally: sys.settrace(None)
|
|
352
390
|
for name, a in S['self_stubs']: obj.__dict__[name] = stub(a['key'], a['async'], getattr(obj, name) if a.get('pass') else None)
|
|
353
391
|
for name in S.get('inject') or []: setattr(obj, name, build({'store': name}, OBJ_STORES))
|
|
@@ -370,7 +408,7 @@ def call(req):
|
|
|
370
408
|
snap = state_of(obj, stores) if S.get('discard') and S['cls'] is not None else None
|
|
371
409
|
sys.settrace(tracer)
|
|
372
410
|
try:
|
|
373
|
-
out = run(fn(**kwargs))
|
|
411
|
+
with pinned(): out = run(fn(**kwargs))
|
|
374
412
|
err = None
|
|
375
413
|
except Exception as e:
|
|
376
414
|
out, err = None, f"{type(e).__name__}: {e}"[:300]
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.20;
|
|
3
|
+
|
|
4
|
+
// The re-entrant runs of core/extract-sol.ts replayed on the code: every address a run names is an Agent (its code set
|
|
5
|
+
// there), and one Director holds the run's script. A call of the script is made by its Agent; a call into an Agent (the
|
|
6
|
+
// contract sending it a value) runs the script's next calls from inside it, up to a return (the Agent's call returns, or
|
|
7
|
+
// reverts). The Director records whether each call of the script succeeded.
|
|
8
|
+
interface IDirector { function onCall() external returns (bool); }
|
|
9
|
+
|
|
10
|
+
contract Agent {
|
|
11
|
+
address constant DIRECTOR = address(uint160(0xD1EC70));
|
|
12
|
+
function act(address t, uint256 v, bytes calldata d) external returns (bool ok) {
|
|
13
|
+
require(msg.sender == DIRECTOR, "agent: the director only");
|
|
14
|
+
(ok, ) = t.call{value: v}(d);
|
|
15
|
+
}
|
|
16
|
+
receive() external payable { if (!IDirector(DIRECTOR).onCall()) revert("agent: the callee reverts"); }
|
|
17
|
+
fallback() external payable { if (!IDirector(DIRECTOR).onCall()) revert("agent: the callee reverts"); }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
contract Director {
|
|
21
|
+
uint8[] kinds;
|
|
22
|
+
address[] froms;
|
|
23
|
+
uint256[] values;
|
|
24
|
+
bool[] rets;
|
|
25
|
+
bytes[] datas;
|
|
26
|
+
uint256 at;
|
|
27
|
+
address target;
|
|
28
|
+
bool[] public oks;
|
|
29
|
+
|
|
30
|
+
// One transaction of the run: its first call, and inside it every call and return the script holds.
|
|
31
|
+
function run(address t, uint8[] calldata k, address[] calldata f, uint256[] calldata v, bool[] calldata r, bytes[] calldata d) external {
|
|
32
|
+
target = t; kinds = k; froms = f; values = v; rets = r; at = 0;
|
|
33
|
+
delete datas;
|
|
34
|
+
delete oks;
|
|
35
|
+
for (uint256 i; i < d.length; i++) datas.push(d[i]);
|
|
36
|
+
step();
|
|
37
|
+
require(at == kinds.length, "director: the script is left over");
|
|
38
|
+
}
|
|
39
|
+
function step() internal {
|
|
40
|
+
uint256 i = at++;
|
|
41
|
+
require(kinds[i] == 0, "director: a return outside a call");
|
|
42
|
+
oks.push(Agent(payable(froms[i])).act(target, values[i], datas[i]));
|
|
43
|
+
}
|
|
44
|
+
function onCall() external returns (bool) {
|
|
45
|
+
while (at < kinds.length) {
|
|
46
|
+
if (kinds[at] == 1) return rets[at++];
|
|
47
|
+
step();
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
function count() external view returns (uint256) { return oks.length; }
|
|
52
|
+
}
|