gdp-wired 0.42.0 → 0.43.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 +7 -1
- package/dist/core/cli.d.ts +2 -1
- package/dist/core/cli.js +226 -27
- package/dist/core/counts.d.ts +8 -1
- package/dist/core/counts.js +171 -302
- package/dist/core/dsl.js +26 -30
- package/dist/core/effect-schedule.d.ts +103 -0
- package/dist/core/effect-schedule.js +817 -0
- package/dist/core/effect.d.ts +19 -0
- package/dist/core/effect.js +551 -28
- package/dist/core/exists.d.ts +5 -0
- package/dist/core/exists.js +98 -34
- package/dist/core/extract-check.d.ts +1 -0
- package/dist/core/extract-check.js +37 -3
- package/dist/core/extract-print.js +9 -2
- package/dist/core/extract-read.js +2 -1
- package/dist/core/extract-step.d.ts +9 -0
- package/dist/core/extract-step.js +87 -22
- package/dist/core/extract.d.ts +8 -0
- package/dist/core/extract.js +13 -1
- package/dist/core/infer.d.ts +1 -0
- package/dist/core/infer.js +7 -4
- package/dist/core/laws.d.ts +4 -0
- package/dist/core/laws.js +176 -9
- package/dist/core/machine.js +2 -2
- package/dist/core/py/harness.py +13 -6
- package/dist/core/py/reader.py +51 -1
- package/dist/core/system.d.ts +44 -0
- package/dist/core/system.js +426 -0
- package/dist/kernel/kernel.js +3 -2
- package/dist/kernel/prove.d.ts +1 -0
- package/dist/kernel/prove.js +69 -8
- package/dist/lean-kernel/emit.js +3 -3
- package/dist/lean-kernel/lean-terms.d.ts +1 -0
- package/dist/lean-kernel/lean-terms.js +8 -4
- package/package.json +2 -2
package/dist/core/exists.d.ts
CHANGED
|
@@ -8,6 +8,11 @@ export declare function substVarsE(e: E, s: Record<string, E>): E;
|
|
|
8
8
|
export declare function substVars(c: C, s: Record<string, E>): C;
|
|
9
9
|
export declare function small(m: Machine, p: Env, b: number, cap?: number, work?: number, walks?: number): State[];
|
|
10
10
|
export declare function ghostOf(m: Machine, law: Law): SomeWitness | undefined;
|
|
11
|
+
export declare function smallOf(m: Machine): {
|
|
12
|
+
p: Env;
|
|
13
|
+
sts: State[];
|
|
14
|
+
}[];
|
|
15
|
+
export declare function trueSmall(m: Machine, laws: Law[], ghosted?: Machine): boolean;
|
|
11
16
|
export declare function holdsAt(m: Machine, law: Law, p: Env, st: State, b: number): boolean;
|
|
12
17
|
export declare function someHolds(body: C, vars: string[], env: Env, st: State, m: Machine): {
|
|
13
18
|
holds: boolean;
|
package/dist/core/exists.js
CHANGED
|
@@ -154,12 +154,13 @@ function solved(atoms, g) {
|
|
|
154
154
|
return out;
|
|
155
155
|
}
|
|
156
156
|
const atomsOf2 = (c) => (c.op === 'and' || c.op === 'or' ? c.xs.flatMap(atomsOf2) : c.op === 'not' ? atomsOf2(c.x) : [c]);
|
|
157
|
-
// --- the small instances
|
|
157
|
+
// --- the small instances ---------------------------------------------------------------------------------------------
|
|
158
158
|
// Every state reached from the start with the params at `p`, each input below `b`, each carried map a subset of 0 .. b − 1.
|
|
159
159
|
// (at most `cap` states, and `work` steps tried: a wide request space ends the BFS early, its states still reachable;
|
|
160
160
|
// then, with `walks` steps more, random walks past it, each step a change of a kind (the variables it writes) chosen
|
|
161
161
|
// alike among those a few requests make: an action the BFS's levels never reach, a leader past a majority's votes, is
|
|
162
|
-
// taken as often as any other)
|
|
162
|
+
// taken as often as any other. Each state's step from the state it was first reached from is kept: `pathTo`.)
|
|
163
|
+
const pathTo = new WeakMap();
|
|
163
164
|
export function small(m, p, b, cap = 3000, work = 300_000, walks = 0) {
|
|
164
165
|
const run = interpret(m), start = run.init(p);
|
|
165
166
|
const subsets = Array.from({ length: 1 << b }, (_, s) => new Map(Array.from({ length: b }, (_, i) => i).filter(i => (s >> i) & 1).map(i => [i, 1])));
|
|
@@ -172,6 +173,8 @@ export function small(m, p, b, cap = 3000, work = 300_000, walks = 0) {
|
|
|
172
173
|
reqs = reqs.flatMap(r => subsets.map(s => ({ ...r, [c]: s })));
|
|
173
174
|
const idOf = (s) => key([s.scalars, Object.entries(s.maps).map(([n, cs]) => [n, [...cs].filter(([, x]) => x).sort((a, c) => a[0] - c[0])])]);
|
|
174
175
|
const seen = new Map([[idOf(start), start]]), queue = [start];
|
|
176
|
+
const reached = (next, from, r) => { const id = idOf(next), had = seen.get(id); if (had)
|
|
177
|
+
return had; seen.set(id, next); pathTo.set(next, [from, r]); return next; };
|
|
175
178
|
while (queue.length && seen.size < cap && work > 0) {
|
|
176
179
|
const st = queue.shift();
|
|
177
180
|
for (const r of reqs) {
|
|
@@ -184,11 +187,9 @@ export function small(m, p, b, cap = 3000, work = 300_000, walks = 0) {
|
|
|
184
187
|
catch {
|
|
185
188
|
continue;
|
|
186
189
|
}
|
|
187
|
-
const
|
|
188
|
-
if (
|
|
189
|
-
seen.set(id, next);
|
|
190
|
+
const n0 = seen.size;
|
|
191
|
+
if (reached(next, st, r) && seen.size > n0)
|
|
190
192
|
queue.push(next);
|
|
191
|
-
}
|
|
192
193
|
}
|
|
193
194
|
}
|
|
194
195
|
if (!queue.length)
|
|
@@ -203,24 +204,22 @@ export function small(m, p, b, cap = 3000, work = 300_000, walks = 0) {
|
|
|
203
204
|
for (let d = 0; d < 40 && walks > 0; d++) {
|
|
204
205
|
const by = new Map();
|
|
205
206
|
for (let i = 0; i < 48; i++, walks--) {
|
|
207
|
+
const r = reqs[rnd(reqs.length)];
|
|
206
208
|
let next;
|
|
207
209
|
try {
|
|
208
|
-
next = run.step(p, st,
|
|
210
|
+
next = run.step(p, st, r);
|
|
209
211
|
}
|
|
210
212
|
catch {
|
|
211
213
|
continue;
|
|
212
214
|
}
|
|
213
215
|
const kd = kindOf(st, next);
|
|
214
216
|
if (kd)
|
|
215
|
-
by.set(kd, [...by.get(kd) ?? [], next]);
|
|
217
|
+
by.set(kd, [...by.get(kd) ?? [], [next, r]]);
|
|
216
218
|
}
|
|
217
219
|
if (!by.size)
|
|
218
220
|
break;
|
|
219
|
-
const ks = [...by.values()], at = ks[rnd(ks.length)];
|
|
220
|
-
st =
|
|
221
|
-
const id = idOf(st);
|
|
222
|
-
if (!seen.has(id))
|
|
223
|
-
seen.set(id, st);
|
|
221
|
+
const ks = [...by.values()], at = ks[rnd(ks.length)], [next, r] = at[rnd(at.length)];
|
|
222
|
+
st = reached(next, st, r);
|
|
224
223
|
}
|
|
225
224
|
}
|
|
226
225
|
return [...seen.values()];
|
|
@@ -242,17 +241,49 @@ export function ghostOf(m, law) {
|
|
|
242
241
|
for (const t of ts.values())
|
|
243
242
|
for (const start of starts) {
|
|
244
243
|
const step = { op: 'if', c: keep, then: v(x), else: t }, gm = { ...m, state: { ...m.state, [x]: start }, step: { ...m.step, state: { ...m.step.state, [x]: step } } };
|
|
245
|
-
|
|
246
|
-
return small(gm, ps, 3, 3000, 100_000).every(st => holdsAt(gm, { ...law, some: undefined }, ps, st, 3));
|
|
247
|
-
}
|
|
248
|
-
catch {
|
|
249
|
-
return false;
|
|
250
|
-
} });
|
|
251
|
-
if (ok)
|
|
244
|
+
if (trueSmall(m, [{ ...law, some: undefined }], gm))
|
|
252
245
|
return { ghost: { [x]: { start, step } } };
|
|
253
246
|
}
|
|
254
247
|
return undefined;
|
|
255
248
|
}
|
|
249
|
+
// The small instances, the one filter of every candidate (core/counts.ts's laws, the witnesses and ghosts here): each
|
|
250
|
+
// param 2 and 3, every input and carried set below 3, every state the BFS reaches in 300,000 steps (3,000 at most) and
|
|
251
|
+
// the walks past it in a third as many; an instance whose params the machine refuses has no states. Read once a machine.
|
|
252
|
+
const smalls = new WeakMap();
|
|
253
|
+
export function smallOf(m) {
|
|
254
|
+
let out = smalls.get(m);
|
|
255
|
+
if (!out)
|
|
256
|
+
smalls.set(m, (out = [2, 3].map(x => { const p = Object.fromEntries(m.params.map(q => [q, x])); try {
|
|
257
|
+
return { p, sts: small(m, p, 3, 3000, 300_000, 100_000) };
|
|
258
|
+
}
|
|
259
|
+
catch {
|
|
260
|
+
return { p, sts: [] };
|
|
261
|
+
} })));
|
|
262
|
+
return out;
|
|
263
|
+
}
|
|
264
|
+
// Laws true at every small state, at every key below one past their values. With `ghosted`, the machine with ghosts
|
|
265
|
+
// (state no step of m reads), each small state of m with the ghosts' values along the steps it was first reached by:
|
|
266
|
+
// one instance a machine, however many ghosts are asked of it.
|
|
267
|
+
export function trueSmall(m, laws, ghosted) {
|
|
268
|
+
const g = ghosted ?? m, run = ghosted && interpret(ghosted);
|
|
269
|
+
return smallOf(m).every(({ p, sts }) => {
|
|
270
|
+
const at = new Map();
|
|
271
|
+
return sts.every(st => {
|
|
272
|
+
let s = st;
|
|
273
|
+
if (run) {
|
|
274
|
+
const from = pathTo.get(st);
|
|
275
|
+
try {
|
|
276
|
+
s = from ? run.step(p, at.get(from[0]), from[1]) : run.init(p);
|
|
277
|
+
}
|
|
278
|
+
catch {
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
at.set(st, s);
|
|
282
|
+
}
|
|
283
|
+
return laws.every(l => holdsAt(g, l, p, s, 4));
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
}
|
|
256
287
|
// A law at a state, its counts the state's, at every key below b.
|
|
257
288
|
// (a state's view once: a law is read at every state, and every law at each)
|
|
258
289
|
const views = new WeakMap();
|
|
@@ -500,17 +531,44 @@ function mapGhostsOf(m, law, taken) {
|
|
|
500
531
|
for (const n of namesOf(w2.key))
|
|
501
532
|
keyed.add(n);
|
|
502
533
|
const action = (i) => !keyed.has(i);
|
|
503
|
-
|
|
504
|
-
for (const
|
|
534
|
+
const ghost = (val, inner) => {
|
|
535
|
+
for (const inj of injections) {
|
|
505
536
|
let name = `${mp}$w`;
|
|
506
|
-
for (let j = 2; taken.has(name); j++)
|
|
537
|
+
for (let j = 2; taken.has(name) || name === inner?.name; j++)
|
|
507
538
|
name = `${mp}$w${j}`;
|
|
508
539
|
const at = substVarsE(w.key, Object.fromEntries(kv.map((n, j) => [n, v(inj[j])]))), atW = { op: 'get', map: name, key: at };
|
|
509
540
|
const Pw = substVars(P.length === 1 ? P[0] : { op: 'or', xs: P }, { [x]: atW }), has = { op: '<=', a: k(1), b: { op: 'get', map: mp, key: at } };
|
|
510
|
-
out.push({ name, write: { key: w.key, value: { op: 'if', c: set, then:
|
|
511
|
-
holds: substVars(law.holds, { [x]: atW }),
|
|
541
|
+
out.push({ name, write: { key: w.key, value: { op: 'if', c: set, then: val, else: { op: 'get', map: name, key: w.key } } }, at,
|
|
542
|
+
holds: substVars(law.holds, { [x]: atW }), ...(inner ? { inner } : {}),
|
|
512
543
|
inv: { name: `${law.name}: ${name} where ${mp} is set`, forall: law.forall, ...(law.keys ? { keys: law.keys } : {}), holds: { op: 'or', xs: [{ op: 'not', x: { op: 'and', xs: [...guards, has] } }, Pw] } } });
|
|
513
544
|
}
|
|
545
|
+
};
|
|
546
|
+
for (const val of m.inputs.filter(i => !kv.includes(i) && !action(i)))
|
|
547
|
+
ghost(v(val));
|
|
548
|
+
// (a ghost of a ghost, after those: the value another write's ghost holds, read at that write's key in this step's
|
|
549
|
+
// request: G[i·N + p] := r where DbResponseSent[i·N + p] is set, W[n·N + p] := G[i·N + p] where ResponseSent is.
|
|
550
|
+
// G's own law: where its write's cell is set, what the write's guard says of r, at G's cell)
|
|
551
|
+
for (const [mp2, w2] of Object.entries(m.step.maps ?? {})) {
|
|
552
|
+
if (mp2 === mp || 'each' in w2)
|
|
553
|
+
continue;
|
|
554
|
+
const kv2 = namesOf(w2.key);
|
|
555
|
+
if (!kv2.length || !kv2.every(n => m.inputs.includes(n) && keyed.has(n)))
|
|
556
|
+
continue;
|
|
557
|
+
const set2 = substC({ op: '<=', a: k(1), b: w2.value }, { vars: {}, maps: { [mp2]: () => k(0) }, flags: Object.fromEntries(Object.keys(m.step.flags ?? {}).map(f => [f, { op: 'flag', name: f }])) });
|
|
558
|
+
const conj = (c, depth = 0) => (c.op === 'and' ? c.xs.flatMap(y => conj(y, depth)) : c.op === 'flag' && depth < 3 && m.step.flags?.[c.name] && m.step.flags[c.name].op !== 'all' ? conj(m.step.flags[c.name], depth + 1) : [c]);
|
|
559
|
+
const lits = [...new Set([...JSON.stringify(w2.value).matchAll(/"op":"flag","name":"([^"]+)"/g)].map(x => x[1]))].flatMap(f => conj({ op: 'flag', name: f }));
|
|
560
|
+
for (const val2 of m.inputs.filter(i => !kv2.includes(i) && !action(i))) {
|
|
561
|
+
let gname = `${mp2}$g`;
|
|
562
|
+
for (let j = 2; taken.has(gname); j++)
|
|
563
|
+
gname = `${mp2}$g${j}`;
|
|
564
|
+
const ks = kv2.map((_, j) => `g${j}$key`), G = (t) => ({ op: 'get', map: gname, key: t }), K2 = substVarsE(w2.key, Object.fromEntries(kv2.map((n, j) => [n, v(ks[j])])));
|
|
565
|
+
const says = lits.filter(c => c.op !== 'flag' && namesOf(c).includes(val2) && namesOf(c).every(n => n === val2 || kv2.includes(n))).map(c => substVars(c, { [val2]: G(K2), ...Object.fromEntries(kv2.map((n, j) => [n, v(ks[j])])) }));
|
|
566
|
+
if (!says.length)
|
|
567
|
+
continue;
|
|
568
|
+
const inv = { name: `${gname} where ${mp2} is set`, forall: ks[0], ...(ks.length > 1 ? { keys: ks.slice(1) } : {}), holds: { op: 'or', xs: [{ op: 'not', x: { op: '<=', a: k(1), b: { op: 'get', map: mp2, key: K2 } } }, says.length === 1 ? says[0] : { op: 'and', xs: says }] } };
|
|
569
|
+
ghost(G(w2.key), { name: gname, write: { key: w2.key, value: { op: 'if', c: set2, then: v(val2), else: G(w2.key) } }, inv });
|
|
570
|
+
}
|
|
571
|
+
}
|
|
514
572
|
}
|
|
515
573
|
return out;
|
|
516
574
|
}
|
|
@@ -518,7 +576,7 @@ const takenOf = (m) => new Set([...Object.keys(m.maps ?? {}), ...(m.inputMaps ??
|
|
|
518
576
|
const firstPicks = new Map();
|
|
519
577
|
// The machine with a ghost map (kernel.ts's ghostedMachine of Ghosted, whose ghostedOk it must pass).
|
|
520
578
|
const withMap = (m, g) => {
|
|
521
|
-
const o = { orig: m, vars: {}, maps: { [g.name]: { start: 0, write: g.write } } };
|
|
579
|
+
const o = { orig: m, vars: {}, maps: { ...(g.inner ? { [g.inner.name]: { start: 0, write: g.inner.write } } : {}), [g.name]: { start: 0, write: g.write } } };
|
|
522
580
|
if (!ghostedOk(o))
|
|
523
581
|
throw new Error(`${g.name}: not a ghost of ${m.name}`);
|
|
524
582
|
return ghostedMachine(o);
|
|
@@ -531,7 +589,7 @@ function built(m0, plans, cases) {
|
|
|
531
589
|
if (p.pick.mode === 'map') {
|
|
532
590
|
const g = p.maps[p.pick.at];
|
|
533
591
|
m = withMap(m, g);
|
|
534
|
-
invs.push(g.inv);
|
|
592
|
+
invs.push(...(g.inner ? [g.inner.inv] : []), g.inv);
|
|
535
593
|
}
|
|
536
594
|
const state = { ...m.state }, step = { ...m.step.state }, ghosts = [];
|
|
537
595
|
const laws = plans.map(p => {
|
|
@@ -653,16 +711,17 @@ export function proveSome(m, laws, opts = {}) {
|
|
|
653
711
|
const rounds = opts.rounds ?? 24;
|
|
654
712
|
// (a law about every key with no witness term: the next ghost map past `from` that keeps its law and the ghost's own
|
|
655
713
|
// on every state of the small instances, each param 2 and 3)
|
|
656
|
-
|
|
714
|
+
// (a ghost map named apart from the machine's names and from the other laws' plans' maps)
|
|
715
|
+
const apart = (p) => new Set([...takenOf(m), ...[...plans.values()].flatMap(q => (q !== p ? q.maps.map(g => g.name) : []))]);
|
|
657
716
|
const toMap = (p, from) => {
|
|
658
|
-
if (from < 0)
|
|
659
|
-
p.maps = mapGhostsOf(m, p.law, takenOf(m));
|
|
660
717
|
const others = [...plans.values()].filter(q => q !== p && q.pick.mode === 'map');
|
|
718
|
+
if (from < 0)
|
|
719
|
+
p.maps = mapGhostsOf(m, p.law, apart(p));
|
|
661
720
|
for (let j = from + 1; j < p.maps.length; j++) {
|
|
662
721
|
const g = p.maps[j];
|
|
663
722
|
try {
|
|
664
723
|
const mm = withMap(others.reduce((acc, q) => withMap(acc, q.maps[q.pick.at]), m), g);
|
|
665
|
-
const ok =
|
|
724
|
+
const ok = trueSmall(m, [...(g.inner ? [g.inner.inv] : []), g.inv, { ...p.law, holds: g.holds, some: undefined }], mm);
|
|
666
725
|
if (log)
|
|
667
726
|
console.error(`exists: map ${g.name} at ${showE(g.at)} := ${showE(g.write.value)}: ${ok ? 'kept' : 'false on the small instances'}`);
|
|
668
727
|
if (ok) {
|
|
@@ -686,16 +745,21 @@ export function proveSome(m, laws, opts = {}) {
|
|
|
686
745
|
if (p.law.forall && !p.given && p.groups.length === 1 && p.groups[0].length === 1 && mapsRead(p.law) && p.pick.mode === 'term' && !first) {
|
|
687
746
|
// (the first pick a machine's law got, again: a search asks the same law with each candidate set)
|
|
688
747
|
const id = key([m.step, m.assume ?? null, m.maps ?? null, p.law.holds]), had = firstPicks.get(id);
|
|
748
|
+
// (a ghost map this machine refuses, one with sums, say, is no pick here)
|
|
689
749
|
if (had?.mode === 'map') {
|
|
690
|
-
p.maps = mapGhostsOf(m, p.law,
|
|
691
|
-
|
|
750
|
+
p.maps = mapGhostsOf(m, p.law, apart(p));
|
|
751
|
+
try {
|
|
752
|
+
withMap(m, p.maps[had.at]);
|
|
753
|
+
p.pick = { ...had };
|
|
754
|
+
}
|
|
755
|
+
catch { /* the term */ }
|
|
692
756
|
}
|
|
693
757
|
else if (had)
|
|
694
758
|
p.pick = { mode: 'term', at: [...had.at] };
|
|
695
759
|
}
|
|
696
760
|
if (p.law.forall && !p.given && p.groups.length === 1 && p.groups[0].length === 1 && mapsRead(p.law) && p.pick.mode === 'term' && !first && !firstPicks.has(key([m.step, m.assume ?? null, m.maps ?? null, p.law.holds]))) {
|
|
697
761
|
const x = p.groups[0][0], at = p.terms[0].findIndex(t => { try {
|
|
698
|
-
return
|
|
762
|
+
return trueSmall(m, [{ ...p.law, holds: substVars(p.law.holds, { [x]: t[0] }), some: undefined }]);
|
|
699
763
|
}
|
|
700
764
|
catch {
|
|
701
765
|
return false;
|
|
@@ -660,7 +660,19 @@ export function drive(m, r, sorts, code, opts = {}) {
|
|
|
660
660
|
return ruleRefuses ? {} : { problem: `new ${m.entry}(${JSON.stringify(params)}) throws (${made.error}), the rule's precondition holds` };
|
|
661
661
|
if (ruleRefuses)
|
|
662
662
|
return { problem: `new ${m.entry}(${JSON.stringify(params)}) is made, the rule's ${ps === undefined ? 'param kinds refuse' : 'precondition refuses'} it` };
|
|
663
|
-
|
|
663
|
+
// (a start whose constructor arithmetic passes 2^53 - 1: outside the rule's numbers, as a step past them is; the
|
|
664
|
+
// claim is for starts within them, and the check draws on)
|
|
665
|
+
let st;
|
|
666
|
+
try {
|
|
667
|
+
st = interp.init(ps);
|
|
668
|
+
}
|
|
669
|
+
catch (x) {
|
|
670
|
+
if (/2\^53/.test(x.message)) {
|
|
671
|
+
ev.startsOutside = (ev.startsOutside ?? 0) + 1;
|
|
672
|
+
return {};
|
|
673
|
+
}
|
|
674
|
+
throw x;
|
|
675
|
+
}
|
|
664
676
|
try {
|
|
665
677
|
const snap = code.snapOf(made.value, params);
|
|
666
678
|
const diff = sameSnap(snap, ruleSnap(r, m, st, sorts));
|
|
@@ -672,7 +684,18 @@ export function drive(m, r, sorts, code, opts = {}) {
|
|
|
672
684
|
return { problem: `new ${m.entry}: ${x.message}` };
|
|
673
685
|
}
|
|
674
686
|
}
|
|
675
|
-
|
|
687
|
+
let st;
|
|
688
|
+
try {
|
|
689
|
+
st = interp.init(ps ?? {});
|
|
690
|
+
}
|
|
691
|
+
catch (x) {
|
|
692
|
+
if (/2\^53/.test(x.message)) {
|
|
693
|
+
ev.startsOutside = (ev.startsOutside ?? 0) + 1;
|
|
694
|
+
return {};
|
|
695
|
+
}
|
|
696
|
+
throw x;
|
|
697
|
+
}
|
|
698
|
+
const snap = ruleSnap(r, m, st, sorts);
|
|
676
699
|
const problem = code.init?.(snap, params);
|
|
677
700
|
if (problem)
|
|
678
701
|
return { problem };
|
|
@@ -753,7 +776,18 @@ export function drive(m, r, sorts, code, opts = {}) {
|
|
|
753
776
|
}
|
|
754
777
|
if (evalTerm(m.pre, params) !== true)
|
|
755
778
|
return undefined;
|
|
756
|
-
|
|
779
|
+
let st0;
|
|
780
|
+
try {
|
|
781
|
+
st0 = interp.init(ps);
|
|
782
|
+
}
|
|
783
|
+
catch (x) {
|
|
784
|
+
if (/2\^53/.test(x.message)) {
|
|
785
|
+
ev.startsOutside = (ev.startsOutside ?? 0) + 1;
|
|
786
|
+
return undefined;
|
|
787
|
+
}
|
|
788
|
+
throw x;
|
|
789
|
+
}
|
|
790
|
+
const st = ruleState(st0, snap, m, sorts);
|
|
757
791
|
// A state the code can't hold (a value outside its type, Go's): no state of the code is that one.
|
|
758
792
|
const self = isClass ? code.at(snap, params) : undefined;
|
|
759
793
|
if (isClass && self === undefined)
|
|
@@ -342,8 +342,15 @@ function pn(e, P, ctx, mode, recv = false) {
|
|
|
342
342
|
case 'neg': return `${pn(e.a, P, ctx, 'int', true)}.negate()`;
|
|
343
343
|
case 'mulk': return `${R(e.a)}.times(${e.k})`;
|
|
344
344
|
case 'mul':
|
|
345
|
-
if (!(natOK(e.a, ctx) && natOK(e.b, ctx)))
|
|
346
|
-
|
|
345
|
+
if (!(natOK(e.a, ctx) && natOK(e.b, ctx))) {
|
|
346
|
+
// (each factor at least 0 where the product is read, the path's conditions say so: their product over the
|
|
347
|
+
// naturals, each factor clamped at 0, which is itself there)
|
|
348
|
+
if (!(nonneg(e.a, ctx) && nonneg(e.b, ctx)))
|
|
349
|
+
throw new Refusal(P.m.file, 'a product of two numbers that may be negative (Int multiplies only by constants)');
|
|
350
|
+
const f = (x, recv) => (natOK(x, ctx) ? pn(x, P, ctx, 'nat', recv) : `${pn(x, P, ctx, 'int', true)}.clamped`);
|
|
351
|
+
const prod = `${f(e.a, true)}.mul(${f(e.b, false)})`;
|
|
352
|
+
return nat ? prod : `Int.of(${prod})`;
|
|
353
|
+
}
|
|
347
354
|
return `${pn(e.a, P, ctx, 'nat', true)}.mul(${pn(e.b, P, ctx, 'nat')})`;
|
|
348
355
|
case 'min': return nat ? `min(${A(e.a)}, ${A(e.b)})` : `${R(e.a)}.min(${A(e.b)})`;
|
|
349
356
|
case 'max':
|
|
@@ -1649,7 +1649,8 @@ export class Exec {
|
|
|
1649
1649
|
return [v, { ...q2, locals: p.locals }];
|
|
1650
1650
|
}
|
|
1651
1651
|
const flow = this.block(d.body.statements, q);
|
|
1652
|
-
|
|
1652
|
+
// (the paths that return or fall off the end; those no run takes, a failure's, left out)
|
|
1653
|
+
const outs = [...flow.rets, ...(flow.live ? [[flow.live, { t: 'undef' }]] : [])].filter(([q2]) => this.feasible(q2));
|
|
1653
1654
|
if (!outs.length)
|
|
1654
1655
|
return [{ t: 'undef' }, { ...p, pc: [...p.pc, I.F] }];
|
|
1655
1656
|
const [first, ...rest] = outs;
|
|
@@ -18,6 +18,7 @@ export type SType = {
|
|
|
18
18
|
k: 'float' | 'bool' | 'str' | 'none' | 'any' | 'lock';
|
|
19
19
|
atomic?: string;
|
|
20
20
|
lock?: string;
|
|
21
|
+
bytes?: boolean;
|
|
21
22
|
} | {
|
|
22
23
|
k: 'choice';
|
|
23
24
|
values: string[];
|
|
@@ -37,6 +38,7 @@ export type SType = {
|
|
|
37
38
|
k: 'map';
|
|
38
39
|
key: SType;
|
|
39
40
|
val: SType;
|
|
41
|
+
set?: boolean;
|
|
40
42
|
} | {
|
|
41
43
|
k: 'list';
|
|
42
44
|
of: SType;
|
|
@@ -113,6 +115,7 @@ export type SModule = {
|
|
|
113
115
|
path: string;
|
|
114
116
|
module: string;
|
|
115
117
|
root: string;
|
|
118
|
+
consts?: Record<string, number | string | boolean>;
|
|
116
119
|
entries: ({
|
|
117
120
|
k: 'class';
|
|
118
121
|
rec: string;
|
|
@@ -193,6 +196,7 @@ export type StepOptions = {
|
|
|
193
196
|
failures?: 'refuse' | 'kept';
|
|
194
197
|
onError?: 'refuse' | 'discard';
|
|
195
198
|
domains?: Record<string, 'nat' | 'int'>;
|
|
199
|
+
keep?: string[];
|
|
196
200
|
defaults?: string[];
|
|
197
201
|
fields?: Record<string, null | boolean | number | string>;
|
|
198
202
|
share?: boolean;
|
|
@@ -422,6 +426,7 @@ export type Leaf = {
|
|
|
422
426
|
path: string[];
|
|
423
427
|
kind: 'num' | 'bool' | 'str' | 'choice' | 'none' | 'map' | 'frame';
|
|
424
428
|
float?: boolean;
|
|
429
|
+
set?: boolean;
|
|
425
430
|
cls?: string;
|
|
426
431
|
fields?: {
|
|
427
432
|
name: string;
|
|
@@ -440,6 +445,7 @@ export type PArg = {
|
|
|
440
445
|
name: string;
|
|
441
446
|
float?: boolean;
|
|
442
447
|
sym?: boolean;
|
|
448
|
+
bytes?: boolean;
|
|
443
449
|
z?: Raw;
|
|
444
450
|
} | {
|
|
445
451
|
k: 'opt';
|
|
@@ -585,6 +591,8 @@ export declare class Stepper {
|
|
|
585
591
|
p: string;
|
|
586
592
|
}, p: Path, role?: Var['role']): [V, PArg];
|
|
587
593
|
intTy(t: SType): IntTy | undefined;
|
|
594
|
+
bytesVars: Set<string>;
|
|
595
|
+
kept: Set<string>;
|
|
588
596
|
typed(v: Var, t: SType | IntTy, role: Var['role'], sel?: I.B): void;
|
|
589
597
|
sel: B;
|
|
590
598
|
shared: Map<string, [V, PArg]>;
|
|
@@ -812,6 +820,7 @@ export declare class Stepper {
|
|
|
812
820
|
argsRead(x: SX, p: Path): Path;
|
|
813
821
|
evArgs<T>(x: SX, p: Path, k: (args: V[], kw: [string, V][], p: Path) => T): T;
|
|
814
822
|
dictCall(m: V, name: string, x: SX, p: Path): [V, Path];
|
|
823
|
+
setCall(m: V, name: string, x: SX, p: Path): [V, Path];
|
|
815
824
|
construct(rec: string, args: V[], kw: [string, V][], x: SX, p: Path): [V, Path];
|
|
816
825
|
builtin(n: string, x: SX, p: Path): [V, Path];
|
|
817
826
|
quotient(d: SX, p: Path, round: 'floor' | 'ceil' | 'trunc' | 'even'): [V, Path];
|