gdp-wired 0.37.0 → 0.39.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 +2 -2
- package/dist/core/cli.d.ts +2 -1
- package/dist/core/cli.js +25 -6
- package/dist/core/cyclic.js +1 -1
- package/dist/core/dsl.js +64 -3
- package/dist/core/exists.d.ts +1 -0
- package/dist/core/exists.js +28 -0
- package/dist/core/extract-check.d.ts +2 -2
- package/dist/core/extract-check.js +7 -4
- package/dist/core/extract-print.js +5 -3
- package/dist/core/extract-read.d.ts +2 -0
- package/dist/core/extract-sol.d.ts +91 -0
- package/dist/core/extract-sol.js +1106 -0
- package/dist/core/extract-step.d.ts +56 -6
- package/dist/core/extract-step.js +588 -67
- package/dist/core/extract.d.ts +8 -0
- package/dist/core/extract.js +25 -4
- package/dist/core/infer.js +48 -13
- package/dist/core/laws.js +16 -2
- package/dist/core/live.js +158 -63
- package/dist/core/machine.js +7 -4
- package/dist/core/py/harness.py +75 -12
- package/dist/core/py/reader.py +67 -11
- package/package.json +1 -1
|
@@ -100,6 +100,8 @@ export class Stepper {
|
|
|
100
100
|
frames = [];
|
|
101
101
|
fieldNames = new Set();
|
|
102
102
|
frozen = new Set();
|
|
103
|
+
// (the values of constructor arguments taken at their defaults: a field holding one is a constant)
|
|
104
|
+
atDefault = new Set();
|
|
103
105
|
// Each fixed-width variable's type (a number read from it overflows as the type does), and its range.
|
|
104
106
|
ints = new Map();
|
|
105
107
|
paramsOut = [];
|
|
@@ -199,11 +201,12 @@ export class Stepper {
|
|
|
199
201
|
return [{ t: 'ref', id }, { k: 'rec', cls: t.name, f: args }];
|
|
200
202
|
}
|
|
201
203
|
// A value of another type: kept only where nothing the rule keeps reads it (the harness gives an inert one).
|
|
202
|
-
|
|
204
|
+
// (a dict of no stated types: an empty one, as JSON takes it, where the code serializes it)
|
|
205
|
+
return [{ t: 'opaque', why: `${name}: ${this.why(t)}` }, t.k === 'opaque' && /^dict\b/.test(t.why) ? { k: 'inert', dict: true } : { k: 'inert' }];
|
|
203
206
|
}
|
|
204
207
|
// A fixed-width integer variable: its type, and (for a request) a value outside it refused: the claim is for the
|
|
205
208
|
// type's values.
|
|
206
|
-
intTy(t) { return t.k === 'int' && t.bits !== undefined ? { bits: t.bits, signed: t.signed ?? true } : undefined; }
|
|
209
|
+
intTy(t) { return t.k === 'int' && t.bits !== undefined ? { bits: t.bits, signed: t.signed ?? true, ...(t.mod ? { mod: t.mod } : {}) } : undefined; }
|
|
207
210
|
typed(v, t, role, sel = this.sel) {
|
|
208
211
|
const ty = 'k' in t ? this.intTy(t) : t;
|
|
209
212
|
if (!ty)
|
|
@@ -213,6 +216,15 @@ export class Stepper {
|
|
|
213
216
|
if (role === 'state')
|
|
214
217
|
return;
|
|
215
218
|
const x = I.nvar(v.name);
|
|
219
|
+
// (a value of a symbolic width: an input at or past it refused, a param's the precondition's)
|
|
220
|
+
if (ty.mod) {
|
|
221
|
+
const out = I.or(I.cmp('<', x, I.num(0)), I.cmp('<=', I.nvar(ty.mod), x));
|
|
222
|
+
if (role === 'param')
|
|
223
|
+
this.paramsOut.push(out);
|
|
224
|
+
else
|
|
225
|
+
this.refusals.push(I.and(sel, out));
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
216
228
|
// (a constructor's argument outside its type: no object is made with one, the rule's precondition says so)
|
|
217
229
|
if (role === 'param') {
|
|
218
230
|
const out = I.or(...(Number.isFinite(lo) ? [I.cmp('<', x, I.num(lo))] : []), ...(Number.isFinite(hi) ? [I.cmp('<', I.num(hi), x)] : []));
|
|
@@ -230,8 +242,9 @@ export class Stepper {
|
|
|
230
242
|
sel = I.T;
|
|
231
243
|
// The clock: one input a step.
|
|
232
244
|
clock(at, p) {
|
|
245
|
+
// (read again in the step: the same time, as the check's clock gives it; the step taken to run within one tick)
|
|
233
246
|
if (p.called.includes('$now'))
|
|
234
|
-
|
|
247
|
+
this.notes.add(`the clock read more than once in a step (${at.p}): each read is the request's one time (assumes a step runs within one tick of the clock)`);
|
|
235
248
|
// (in the constructor, the time the object is made: a param)
|
|
236
249
|
if (this.init) {
|
|
237
250
|
this.madeAt ??= this.newVar('made_at', { k: 'num' }, 'param', 'Date.now() (here time.time()): the time the object is made');
|
|
@@ -312,11 +325,15 @@ export class Stepper {
|
|
|
312
325
|
raise(p, c, w, [t, i], k, at) {
|
|
313
326
|
if (this.cms.some(b => this.tries.indexOf(t) < b))
|
|
314
327
|
refuse(at, 'a raise through a context manager of other code (which may suppress it) to a handler around it');
|
|
315
|
-
|
|
328
|
+
// (raised in a function the try's frame called: the handler runs in that frame, with its locals at the call)
|
|
329
|
+
const locals = this.frameLocals.length > t.depth ? this.frameLocals[t.depth] : p.locals;
|
|
330
|
+
t.to.push([{ ...this.assume(p, c), locals, pc: [...p.pc, ...this.tries.flatMap(x => x.ws.map(I.not)), c] }, i, k]);
|
|
316
331
|
t.ws.push(w);
|
|
317
332
|
}
|
|
333
|
+
// (each inlined frame's caller's locals at its call, outermost first)
|
|
334
|
+
frameLocals = [];
|
|
318
335
|
tryStmt(s, p) {
|
|
319
|
-
const hs = s.handlers, fin = s.fin ?? [], t = { hs, to: [], ws: [] }, f0 = this.fails.length, outer = this.tries.map(x => x.ws.length);
|
|
336
|
+
const hs = s.handlers, fin = s.fin ?? [], t = { hs, to: [], ws: [], depth: this.frameLocals.length }, f0 = this.fails.length, outer = this.tries.map(x => x.ws.length);
|
|
320
337
|
this.tries.push(t);
|
|
321
338
|
let body;
|
|
322
339
|
try {
|
|
@@ -631,14 +648,17 @@ export class Stepper {
|
|
|
631
648
|
}
|
|
632
649
|
}
|
|
633
650
|
}
|
|
651
|
+
// (an object one path has not touched yet, a store's map made where first used: as it starts, on that path)
|
|
634
652
|
const heap = new Map();
|
|
635
653
|
for (const [id, x] of a.heap) {
|
|
636
|
-
const y = b.heap.get(id);
|
|
654
|
+
const y = b.heap.get(id) ?? this.initHeap.get(id);
|
|
637
655
|
heap.set(id, y ? this.mergeObj(c, x, y, at) : x);
|
|
638
656
|
}
|
|
639
657
|
for (const [id, y] of b.heap)
|
|
640
|
-
if (!heap.has(id))
|
|
641
|
-
|
|
658
|
+
if (!heap.has(id)) {
|
|
659
|
+
const x = this.initHeap.get(id);
|
|
660
|
+
heap.set(id, x ? this.mergeObj(c, x, y, at) : y);
|
|
661
|
+
}
|
|
642
662
|
return { pc, locals, heap, called: [...new Set([...a.called, ...b.called])], locks: a.locks, defers: [...new Set([...a.defers, ...b.defers])] };
|
|
643
663
|
}
|
|
644
664
|
mergeObj(c, a, b, at) {
|
|
@@ -658,7 +678,14 @@ export class Stepper {
|
|
|
658
678
|
return { ...a, f, moved: a.moved || b.moved };
|
|
659
679
|
}
|
|
660
680
|
if (a.k === 'map' && b.k === 'map') {
|
|
661
|
-
const
|
|
681
|
+
const base = (key) => this.baseCell(a.decl, key), ite = (c2, x, y) => this.ite(c2, x, y, at);
|
|
682
|
+
// (several keys written: both paths' writes padded to one length, each place by the condition)
|
|
683
|
+
const [la, lb] = padWrites([[...(a.pre ?? []), ...(a.w ? [a.w] : [])], [...(b.pre ?? []), ...(b.w ? [b.w] : [])]], base);
|
|
684
|
+
if (la.length > 1) {
|
|
685
|
+
const ws = la.map((x, i) => mergeWrites(c, x, lb[i], base, ite));
|
|
686
|
+
return { ...a, ...(a.nil ? { nil: I.bite(c, a.nil, b.nil) } : {}), w: ws.at(-1), pre: ws.slice(0, -1) };
|
|
687
|
+
}
|
|
688
|
+
const w = mergeWrites(c, a.w, b.w, base, ite);
|
|
662
689
|
return { ...a, ...(a.nil ? { nil: I.bite(c, a.nil, b.nil) } : {}), ...(w ? { w } : {}) };
|
|
663
690
|
}
|
|
664
691
|
if (a.k === 'list' && b.k === 'list')
|
|
@@ -711,6 +738,18 @@ export class Stepper {
|
|
|
711
738
|
}
|
|
712
739
|
if (a.t === 'tuple' && b.t === 'tuple' && a.xs.length === b.xs.length)
|
|
713
740
|
return { t: 'tuple', xs: a.xs.map((x, i) => this.ite(c, x, b.xs[i], at)) };
|
|
741
|
+
if (a.t === 'val' && b.t === 'val' && a.ty === b.ty) {
|
|
742
|
+
// (a key on one path only: present where that path is taken)
|
|
743
|
+
const f = new Map(), absent = (x, has) => (x.t === 'opt' ? { t: 'opt', has: I.and(has, x.has), v: x.v } : { t: 'opt', has, v: x });
|
|
744
|
+
for (const [n, x] of a.f) {
|
|
745
|
+
const y = b.f.get(n);
|
|
746
|
+
f.set(n, y ? this.ite(c, x, y, at) : absent(x, c));
|
|
747
|
+
}
|
|
748
|
+
for (const [n, y] of b.f)
|
|
749
|
+
if (!a.f.has(n))
|
|
750
|
+
f.set(n, absent(y, I.not(c)));
|
|
751
|
+
return { t: 'val', ty: a.ty, f };
|
|
752
|
+
}
|
|
714
753
|
// (a list the request carries on one path, another value on another: kept only where nothing reads it)
|
|
715
754
|
if ([a, b].some(x => x.t === 'ref' && this.seqs.some(d => x.id === `in:${d.name}`)))
|
|
716
755
|
return { t: 'opaque', why: 'a list the request carries on one path, another value on another' };
|
|
@@ -771,6 +810,8 @@ export class Stepper {
|
|
|
771
810
|
case 'choice': return lvalues(v.e).includes('') ? I.not(I.is(v.e, '')) : I.T;
|
|
772
811
|
case 'none': return I.F;
|
|
773
812
|
case 'opt': return I.and(v.has, this.truthy(v.v, at, p));
|
|
813
|
+
// (a JSON text is never empty; a dict literal is as its keys)
|
|
814
|
+
case 'val': return v.ty === '$dict' ? (v.f.size ? I.T : I.F) : v.ty === '$json' || v.ty === '$dt' ? I.T : refuse(at, `${at.text ?? ''}: the truth of a ${v.ty.slice(1)}`);
|
|
774
815
|
case 'ref': {
|
|
775
816
|
// (a list the request carries: whether it has an item)
|
|
776
817
|
const cl = p && this.listOf(v, p, at, true);
|
|
@@ -892,6 +933,7 @@ export class Stepper {
|
|
|
892
933
|
}
|
|
893
934
|
const saved = q.locals;
|
|
894
935
|
this.frames.push(f.id);
|
|
936
|
+
this.frameLocals.push(saved);
|
|
895
937
|
let flow;
|
|
896
938
|
try {
|
|
897
939
|
flow = this.block(f.body, { ...q, locals });
|
|
@@ -903,6 +945,7 @@ export class Stepper {
|
|
|
903
945
|
}
|
|
904
946
|
finally {
|
|
905
947
|
this.frames.pop();
|
|
948
|
+
this.frameLocals.pop();
|
|
906
949
|
}
|
|
907
950
|
const rets = [...flow.rets, ...(flow.live ? [[flow.live, { t: 'none' }]] : [])];
|
|
908
951
|
if (!rets.length)
|
|
@@ -928,6 +971,11 @@ export class Stepper {
|
|
|
928
971
|
for (const s of ss) {
|
|
929
972
|
if (!live)
|
|
930
973
|
break;
|
|
974
|
+
// (a path a failure ended inside an expression: nothing after it runs)
|
|
975
|
+
if (dead(live)) {
|
|
976
|
+
live = undefined;
|
|
977
|
+
break;
|
|
978
|
+
}
|
|
931
979
|
if (s.s === 'fallthrough') {
|
|
932
980
|
ft = live;
|
|
933
981
|
live = undefined;
|
|
@@ -962,14 +1010,16 @@ export class Stepper {
|
|
|
962
1010
|
return { live: this.assign(s.to, r[0], s, r[1], s.t), rets: [] };
|
|
963
1011
|
}
|
|
964
1012
|
case 'if': {
|
|
965
|
-
const
|
|
966
|
-
const
|
|
1013
|
+
const sc = s.c, both = !s.strict && (sc.e === 'and' || sc.e === 'or');
|
|
1014
|
+
const [cv, q] = both ? [undefined, p] : this.ev(sc, p);
|
|
1015
|
+
const [c0, q0] = both ? this.truth(sc, p) : [undefined, q];
|
|
1016
|
+
const c = c0 ?? (s.strict ? (cv.t === 'bool' ? cv.e : refuse({ p: s.cp }, s.strict)) : this.truthy(cv, sc, q));
|
|
967
1017
|
if (!(c.op === 'const' && !c.v))
|
|
968
1018
|
this.arm(s.then);
|
|
969
1019
|
if (!(c.op === 'const' && c.v))
|
|
970
1020
|
this.arm(s.else);
|
|
971
|
-
const t = c.op === 'const' && !c.v ? undefined : this.block(s.then, this.assume(
|
|
972
|
-
const e = c.op === 'const' && c.v ? undefined : this.block(s.else, this.assume(
|
|
1021
|
+
const t = c.op === 'const' && !c.v ? undefined : this.block(s.then, this.assume(q0, c));
|
|
1022
|
+
const e = c.op === 'const' && c.v ? undefined : this.block(s.else, this.assume(q0, I.not(c)));
|
|
973
1023
|
const lives = [t?.live, e?.live].filter((x) => !!x);
|
|
974
1024
|
const live = this.join(lives, s), brk = [...(t?.brk ?? []), ...(e?.brk ?? [])];
|
|
975
1025
|
return { ...(live ? { live } : {}), rets: [...(t?.rets ?? []), ...(e?.rets ?? [])], ...(brk.length ? { brk } : {}) };
|
|
@@ -1020,7 +1070,29 @@ export class Stepper {
|
|
|
1020
1070
|
return { rets: [] };
|
|
1021
1071
|
}
|
|
1022
1072
|
case 'try': return this.tryStmt(s, p);
|
|
1073
|
+
case 'yield': {
|
|
1074
|
+
// (where a @contextmanager generator yields: the with's body, run in the frame of the with)
|
|
1075
|
+
const w = this.withBodies.at(-1);
|
|
1076
|
+
if (!w)
|
|
1077
|
+
return refuse(s, 'a yield (a generator, read only as a @contextmanager\'s)');
|
|
1078
|
+
this.withBodies.pop();
|
|
1079
|
+
let flow;
|
|
1080
|
+
this.frameLocals.push(p.locals);
|
|
1081
|
+
try {
|
|
1082
|
+
flow = this.block(w.body, { ...p, locals: w.locals });
|
|
1083
|
+
}
|
|
1084
|
+
finally {
|
|
1085
|
+
this.withBodies.push(w);
|
|
1086
|
+
this.frameLocals.pop();
|
|
1087
|
+
}
|
|
1088
|
+
if (!flow.live)
|
|
1089
|
+
return { rets: [] };
|
|
1090
|
+
return { live: { ...flow.live, locals: p.locals, heap: new Map(flow.live.heap).set('$yielded', { k: 'rec', ty: '$yielded', f: new Map([['n', { t: 'bool', e: I.T }]]), origin: 'fresh' }) }, rets: [] };
|
|
1091
|
+
}
|
|
1023
1092
|
case 'with': {
|
|
1093
|
+
const cm = this.generatorCM(s, p);
|
|
1094
|
+
if (cm)
|
|
1095
|
+
return cm;
|
|
1024
1096
|
// (a context manager of other code, taken as transparent: a raise inside it may be suppressed by it, so none
|
|
1025
1097
|
// goes through it to a handler around it)
|
|
1026
1098
|
let q = p, other = false;
|
|
@@ -1136,6 +1208,15 @@ export class Stepper {
|
|
|
1136
1208
|
}
|
|
1137
1209
|
case 'idx': {
|
|
1138
1210
|
const [m, q] = this.ev(to.x, p), [k, q2] = this.ev(to.i, q);
|
|
1211
|
+
if (m.t === 'val') {
|
|
1212
|
+
// (a record by value held in a local, or in one of its fields: the local made anew; a dict's key added)
|
|
1213
|
+
const ks = strLit(k);
|
|
1214
|
+
if (m.ty !== '$dict' || ks === undefined)
|
|
1215
|
+
return refuse(at, `${to.text}: a key set in ${m.ty === '$dict' ? 'a dict by a key not known here' : 'a value that is no dict'}`);
|
|
1216
|
+
if (!deep(to.x, o => o.e !== 'var' && o.e !== 'idx' && o.e !== 'str' && o.e !== 'get'))
|
|
1217
|
+
return this.assign(to.x, { ...m, f: new Map(m.f).set(ks, v) }, at, q2, undefined);
|
|
1218
|
+
return refuse(at, `${to.text}: a key set in a dict reached through a call`);
|
|
1219
|
+
}
|
|
1139
1220
|
return this.mapSet(m, this.keyOf(k, to.i), v, to, q2);
|
|
1140
1221
|
}
|
|
1141
1222
|
}
|
|
@@ -1168,7 +1249,7 @@ export class Stepper {
|
|
|
1168
1249
|
if (old?.t === 'opaque' && obj.origin === 'state' && !this.init)
|
|
1169
1250
|
return refuse(at, `${at.text}: writes ${old.why}`);
|
|
1170
1251
|
if (o.id === 'this' && this.frozen.has(f) && !this.init)
|
|
1171
|
-
return refuse(at, `${at.text}: writes a field the constructor sets to None
|
|
1252
|
+
return refuse(at, `${at.text}: writes a field the constructor sets to a constant (None of no type the code states, or other code's function)`);
|
|
1172
1253
|
if (this.init && t)
|
|
1173
1254
|
this.declared.set(`${o.id}.${f}`, t);
|
|
1174
1255
|
// (a literal written to a field of a choice is the choice's)
|
|
@@ -1186,6 +1267,15 @@ export class Stepper {
|
|
|
1186
1267
|
refuse(at, `${JSON.stringify(v.e.value)} is not one of ${f.name}'s literals`);
|
|
1187
1268
|
return { t: 'choice', e: I.llit(v.e.value, f.sort.values) };
|
|
1188
1269
|
}
|
|
1270
|
+
// (a string that is a literal of the choice on every path)
|
|
1271
|
+
if (f.sort.k === 'choice' && v.t === 'str') {
|
|
1272
|
+
const vs = f.sort.values, conv = (k) => { if (k.op === 'slit')
|
|
1273
|
+
return vs.includes(k.value) ? I.llit(k.value, vs) : undefined; if (k.op !== 'kite')
|
|
1274
|
+
return undefined; const a = conv(k.a), b = conv(k.b); return a && b ? I.lite(k.c, a, b) : undefined; };
|
|
1275
|
+
const l = conv(v.e);
|
|
1276
|
+
if (l)
|
|
1277
|
+
return { t: 'choice', e: l };
|
|
1278
|
+
}
|
|
1189
1279
|
if (f.sort.k === 'choice' && v.t !== 'choice')
|
|
1190
1280
|
return refuse(at, `${at.text}: a ${v.t === 'opaque' ? v.why : v.t} set where one of ${f.sort.values.map(x => JSON.stringify(x)).join(', ')} is held`);
|
|
1191
1281
|
if (f.sort.k === 'num' && v.t !== 'num')
|
|
@@ -1206,15 +1296,21 @@ export class Stepper {
|
|
|
1206
1296
|
return [m.id, o];
|
|
1207
1297
|
}
|
|
1208
1298
|
cellOf(o, key, _p, _at) {
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1299
|
+
let acc = this.baseCell(o.decl, key);
|
|
1300
|
+
for (const w of [...(o.pre ?? []), ...(o.w ? [o.w] : [])]) {
|
|
1301
|
+
const same = I.keq(key, w.key), a = acc;
|
|
1302
|
+
acc = { has: I.bite(same, w.has, a.has), vals: new Map([...a.vals].map(([f, v]) => [f, this.ite(same, w.vals.get(f), v, _at)])) };
|
|
1303
|
+
}
|
|
1304
|
+
return acc;
|
|
1214
1305
|
}
|
|
1306
|
+
// A cell written: a second key of a scalar map keyed by numbers (a transfer's two accounts) after the first, any
|
|
1307
|
+
// earlier write of the same key dropped (this one is read through it).
|
|
1215
1308
|
writeCell(id, o, key, has, vals, at, p) {
|
|
1216
|
-
if (o.w && !I.same(o.w.key, key))
|
|
1217
|
-
|
|
1309
|
+
if (o.w && !I.same(o.w.key, key)) {
|
|
1310
|
+
if (!o.decl.scalar || o.decl.key !== 'num')
|
|
1311
|
+
return refuse(at, `${at.text}: a second key of one map written in one step (the subset writes one a step, or several of a map of numbers or booleans keyed by numbers)`);
|
|
1312
|
+
return { ...p, heap: new Map(p.heap).set(id, { ...o, pre: [...(o.pre ?? []).filter(x => !I.same(x.key, key)), o.w], w: { key, has, vals } }) };
|
|
1313
|
+
}
|
|
1218
1314
|
return { ...p, heap: new Map(p.heap).set(id, { ...o, w: { key, has, vals } }) };
|
|
1219
1315
|
}
|
|
1220
1316
|
mapGet(m, k, at, p, missing) {
|
|
@@ -1232,8 +1328,11 @@ export class Stepper {
|
|
|
1232
1328
|
}
|
|
1233
1329
|
mapSet(m, k, v, at, p) {
|
|
1234
1330
|
const [id, o] = this.mapObj(m, at, p);
|
|
1235
|
-
|
|
1236
|
-
|
|
1331
|
+
// (nz: a cell is held where it isn't zero, Solidity's mapping: a zero written is no cell)
|
|
1332
|
+
if (o.decl.scalar) {
|
|
1333
|
+
const x = this.fit(v, o.decl.fields[0], at);
|
|
1334
|
+
return this.writeCell(id, o, k, !at.nz ? I.T : x.t === 'num' ? I.not(I.cmp('=', x.e, I.num(0))) : x.t === 'bool' ? x.e : refuse(at, `${at.text}: a zero of a ${x.t}`), new Map([['value', x]]), at, p);
|
|
1335
|
+
}
|
|
1237
1336
|
// A record put in: a fresh one (made here), its fields copied into the cell, the object no longer written apart.
|
|
1238
1337
|
if (v.t === 'cell' && v.map === id && I.same(v.key, k))
|
|
1239
1338
|
return p;
|
|
@@ -1475,15 +1574,41 @@ export class Stepper {
|
|
|
1475
1574
|
const key = `${store}\u0000${tpl}`;
|
|
1476
1575
|
let sm = this.storeMaps.get(key);
|
|
1477
1576
|
if (!sm) {
|
|
1478
|
-
for (const other of [...this.storeMaps.values()].filter(x => x.store === store))
|
|
1479
|
-
if (!disjoint(other.tpl, tpl))
|
|
1480
|
-
refuse(at, `${store}: the key templates ${JSON.stringify(other.tpl)} and ${JSON.stringify(tpl)} may name one key`);
|
|
1481
1577
|
const decl = this.storeDecl(store);
|
|
1482
|
-
|
|
1578
|
+
if (decl.apart)
|
|
1579
|
+
this.notes.add(`${store}: its key templates name distinct keys (stated: apart)`);
|
|
1580
|
+
else
|
|
1581
|
+
for (const other of [...this.storeMaps.values()].filter(x => x.store === store))
|
|
1582
|
+
if (!disjoint(other.tpl, tpl))
|
|
1583
|
+
refuse(at, `${store}: the key templates ${JSON.stringify(other.tpl)} and ${JSON.stringify(tpl)} may name one key`);
|
|
1584
|
+
const sv = decl.values?.[tpl];
|
|
1585
|
+
const val = Array.isArray(sv) ? { k: 'choice', values: sv } : sv === 'int' || (!sv && decl.value === 'int') ? { k: 'int' } : !sv && decl.value === 'str' ? { k: 'str' } : { k: 'float' };
|
|
1483
1586
|
const name = `${store}_${tpl.replace(/\{\}/g, '').replace(/[^A-Za-z0-9]+/g, '_').replace(/^_|_$/g, '')}`;
|
|
1484
|
-
|
|
1587
|
+
let d, json;
|
|
1588
|
+
if (sv && typeof sv === 'object' && !Array.isArray(sv)) {
|
|
1589
|
+
// (a JSON record: a cell of its fields, an optional one beside whether the key holds a value, a str one left out)
|
|
1590
|
+
json = [];
|
|
1591
|
+
const fields = [];
|
|
1592
|
+
for (const [f, t] of Object.entries(sv.json)) {
|
|
1593
|
+
if (t === 'str' || t === 'str | None') {
|
|
1594
|
+
json.push({ name: f, out: true });
|
|
1595
|
+
continue;
|
|
1596
|
+
}
|
|
1597
|
+
const st = Array.isArray(t) ? { t: { k: 'choice', values: t } } : sortOfText(t, at.p), opt = st.t.k === 'opt', inner = st.t.k === 'opt' ? st.t.of : st.t;
|
|
1598
|
+
fields.push({ name: f, sort: this.scalar(inner), role: 'state' });
|
|
1599
|
+
if (opt)
|
|
1600
|
+
fields.push({ name: `${f}_has`, sort: { k: 'bool' }, role: 'state' });
|
|
1601
|
+
json.push({ name: f, ...(opt ? { opt } : {}), ...(inner.k === 'choice' ? { choice: true, vals: inner.values } : {}) });
|
|
1602
|
+
}
|
|
1603
|
+
const v = this.newVar(name, { k: 'num' }, 'state');
|
|
1604
|
+
d = { name: v.name, key: kn ? 'num' : 'str', fields, scalar: false, js: 'Map' };
|
|
1605
|
+
this.maps.push(d);
|
|
1606
|
+
this.notes.add(`${store}: ${JSON.stringify(tpl)} keys hold JSON records (stated): ${json.map(f => `${f.name}${f.out ? ' (a string, left out)' : f.opt ? ' (maybe absent)' : ''}`).join(', ')}`);
|
|
1607
|
+
}
|
|
1608
|
+
else
|
|
1609
|
+
d = this.mapDeclOf(name, { k: 'map', key: { k: kn ? 'int' : 'str' }, val }, at);
|
|
1485
1610
|
const id = `store:${key}`;
|
|
1486
|
-
sm = { store, tpl, id, decl: d };
|
|
1611
|
+
sm = { store, tpl, id, decl: d, ...(json ? { json } : {}), ...(Array.isArray(sv) ? { choice: true } : {}) };
|
|
1487
1612
|
this.storeMaps.set(key, sm);
|
|
1488
1613
|
this.initHeap.set(id, { k: 'map', decl: d, val, origin: 'state' });
|
|
1489
1614
|
this.notes.add(`${store}: a store (${this.opts.stores?.[store] ? 'stated' : 'inferred: an injected dependency, read and written by a key'}): ${JSON.stringify(tpl)} keys held as ${d.name}, its expiry and eviction left out`);
|
|
@@ -1510,12 +1635,13 @@ export class Stepper {
|
|
|
1510
1635
|
// (the injected dependencies and stores: their type, whether the rule holds keys of theirs, whether the caller stated them)
|
|
1511
1636
|
deps = [];
|
|
1512
1637
|
// A constructor argument held as an injected dependency (a store): one its reader marks so, or one of no scalar type
|
|
1513
|
-
// (another module's class, a protocol, none stated) the class keeps in a field and calls methods on
|
|
1638
|
+
// (another module's class, a protocol, none stated) the class keeps in a field and calls methods on; one defaulting
|
|
1639
|
+
// to None too (the check gives one: the claim is for objects given one, the code's fallback for None not read).
|
|
1514
1640
|
injected(pa, init, r) {
|
|
1515
1641
|
if (!this.inf)
|
|
1516
1642
|
return undefined;
|
|
1517
1643
|
const t = pa.t.k === 'opt' ? pa.t.of : pa.t;
|
|
1518
|
-
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))
|
|
1644
|
+
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'))))
|
|
1519
1645
|
return undefined;
|
|
1520
1646
|
const fields = [];
|
|
1521
1647
|
deep(init.body, st => { const to = st.to, v = st.x; if (st.s === 'set' && to?.e === 'get' && to.x.e === 'var' && to.x.n === 'self' && v?.e === 'var' && v.n === pa.name)
|
|
@@ -1549,16 +1675,18 @@ export class Stepper {
|
|
|
1549
1675
|
return d;
|
|
1550
1676
|
}
|
|
1551
1677
|
storeCall(store, m, args, kw, at, p, awaited) {
|
|
1678
|
+
if (dead(p))
|
|
1679
|
+
return [{ t: 'opaque', why: 'unreachable' }, p];
|
|
1552
1680
|
const d = this.storeDecl(store), all = [...args, ...kw.map(([, v]) => v)];
|
|
1553
1681
|
// (other code given the rule's state may change it: refused unless the caller states it, the tag on its line)
|
|
1554
1682
|
const given = (vs) => { if (!this.tagAt(at.p) && vs.some(v => this.stateRef(v, p)))
|
|
1555
1683
|
refuse(at, `${at.text}: ${store}.${m} is given the rule's state, which other code may change (if it doesn't, a \`gdp: skip\` comment on its line says so)`); };
|
|
1556
|
-
const arg = (n, i) => kw.find(([k]) => k === n)?.[1] ?? args[i] ?? refuse(at, `${at.text}: the store's ${n} not given`);
|
|
1684
|
+
const arg = (n, i) => kw.find(([k]) => k === n || (n === 'key' && k === 'name'))?.[1] ?? args[i] ?? refuse(at, `${at.text}: the store's ${n} not given`);
|
|
1557
1685
|
const has = (n, i) => kw.some(([k]) => k === n) || args.length > i;
|
|
1558
1686
|
let kind = (d.get ?? ['get', 'async_get_cache', 'get_cache']).includes(m) ? 'get' : (d.set ?? ['set', 'async_set_cache', 'set_cache']).includes(m) ? 'set' : (d.delete ?? ['delete', 'delete_cache', 'async_delete_cache']).includes(m) ? 'delete' : undefined;
|
|
1559
1687
|
if (!kind && this.inf) {
|
|
1560
1688
|
// (inferred: a method named as a key's get, set or delete, given a key that is a string or a format)
|
|
1561
|
-
const k = keyShape(m), key = kw.find(([n]) => n === 'key')?.[1] ?? args[0];
|
|
1689
|
+
const k = keyShape(m), key = kw.find(([n]) => n === 'key' || n === 'name')?.[1] ?? args[0];
|
|
1562
1690
|
if (k && key && (key.t === 'str' || key.t === 'fmt') && (k !== 'set' || has('value', 1))) {
|
|
1563
1691
|
kind = k;
|
|
1564
1692
|
(d[k] ??= []).push(m);
|
|
@@ -1590,22 +1718,222 @@ export class Stepper {
|
|
|
1590
1718
|
this.storeAsync[store][m] = awaited;
|
|
1591
1719
|
// (a key's operation takes its key, and a set its value: any other argument given the rule's state is refused)
|
|
1592
1720
|
const keyV = arg('key', 0), valV = kind === 'set' ? arg('value', 1) : undefined;
|
|
1721
|
+
// (a set's options: nx and xx make it conditional, its result whether it set (True, else None, as redis-py's); its
|
|
1722
|
+
// expiry is left out, as every store's is; any other option is refused)
|
|
1723
|
+
const TTL = ['ex', 'px', 'exat', 'pxat', 'ttl', 'timeout', 'expire', 'expiry'];
|
|
1724
|
+
let only;
|
|
1725
|
+
for (const [n, v] of kw) {
|
|
1726
|
+
if (n === 'key' || n === 'name' || n === 'value')
|
|
1727
|
+
continue;
|
|
1728
|
+
if (kind === 'set' && TTL.includes(n)) {
|
|
1729
|
+
this.notes.add(`${store}.${m}: its ${n} (the key's expiry) left out, as the store's expiry is`);
|
|
1730
|
+
continue;
|
|
1731
|
+
}
|
|
1732
|
+
if (kind === 'set' && (n === 'nx' || n === 'xx')) {
|
|
1733
|
+
if (v.t !== 'bool' || v.e.op !== 'const')
|
|
1734
|
+
return refuse(at, `${at.text}: ${n} given a value not known here`);
|
|
1735
|
+
if (v.e.v) {
|
|
1736
|
+
if (only)
|
|
1737
|
+
return refuse(at, `${at.text}: nx and xx both`);
|
|
1738
|
+
only = n;
|
|
1739
|
+
}
|
|
1740
|
+
continue;
|
|
1741
|
+
}
|
|
1742
|
+
return refuse(at, `${at.text}: the store's ${m} given ${n} (the subset reads a key, a value, nx, xx and the expiry)`);
|
|
1743
|
+
}
|
|
1593
1744
|
given(all.filter(v => v !== keyV && v !== valV));
|
|
1745
|
+
if (args.length > (kind === 'set' ? 2 : 1))
|
|
1746
|
+
return refuse(at, `${at.text}: the store's ${m} given more than its key${kind === 'set' ? ' and value' : ''}`);
|
|
1594
1747
|
const { tpl, k, kn } = this.storeKey(keyV, at);
|
|
1595
|
-
const [id, o] = this.storeMap(store, tpl, kn, at, p);
|
|
1748
|
+
const [id, o] = this.storeMap(store, tpl, kn, at, p), sm = [...this.storeMaps.values()].find(x => x.id === id);
|
|
1596
1749
|
// (inside a try that may catch it: the store's operation may raise, as other code's may, before it acts)
|
|
1597
|
-
if (this.tries.length)
|
|
1750
|
+
if (this.tries.length && !d.nothrow)
|
|
1598
1751
|
p = this.passing(`${store}.${m}`, `${store}.${m}`, { store, path: [m] }, at, p, awaited);
|
|
1599
|
-
if (kind === 'get')
|
|
1600
|
-
|
|
1752
|
+
if (kind === 'get') {
|
|
1753
|
+
if (!sm.json)
|
|
1754
|
+
return this.mapGet({ t: 'ref', id }, k, at, p, 'none');
|
|
1755
|
+
const c = this.cellOf(o, k, p, at), f = new Map();
|
|
1756
|
+
for (const jf of sm.json) {
|
|
1757
|
+
if (jf.out) {
|
|
1758
|
+
f.set(jf.name, { t: 'opaque', why: `${at.text}: ${jf.name}, a string of a stored record (left out)` });
|
|
1759
|
+
continue;
|
|
1760
|
+
}
|
|
1761
|
+
const x = c.vals.get(jf.name);
|
|
1762
|
+
f.set(jf.name, jf.opt ? { t: 'opt', has: c.vals.get(`${jf.name}_has`).e, v: x } : x);
|
|
1763
|
+
}
|
|
1764
|
+
return [{ t: 'opt', has: c.has, v: { t: 'val', ty: '$json', f } }, p];
|
|
1765
|
+
}
|
|
1601
1766
|
if (kind === 'delete')
|
|
1602
1767
|
return [{ t: 'none' }, this.mapDel({ t: 'ref', id }, k, at, p, false)];
|
|
1603
1768
|
const v = arg('value', 1);
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1769
|
+
let vals;
|
|
1770
|
+
if (sm.json) {
|
|
1771
|
+
if (v.t !== 'val' || v.ty !== '$json')
|
|
1772
|
+
return refuse(at, `${at.text}: a ${v.t === 'opaque' ? v.why : v.t === 'val' ? v.ty.slice(1) : v.t} set where JSON records are held (stated)`);
|
|
1773
|
+
for (const n of v.f.keys())
|
|
1774
|
+
if (!sm.json.some(jf => jf.name === n))
|
|
1775
|
+
return refuse(at, `${at.text}: ${n}, a field the stated record doesn't have`);
|
|
1776
|
+
vals = new Map();
|
|
1777
|
+
for (const jf of sm.json) {
|
|
1778
|
+
if (jf.out)
|
|
1779
|
+
continue;
|
|
1780
|
+
const fv = o.decl.fields.find(x => x.name === jf.name), x = v.f.get(jf.name);
|
|
1781
|
+
if (!jf.opt && (!x || x.t === 'opt' || x.t === 'none'))
|
|
1782
|
+
return refuse(at, `${at.text}: ${jf.name}, a field the stated record always holds, ${x ? 'maybe None' : 'not set'}`);
|
|
1783
|
+
const has = !x || x.t === 'none' ? I.F : x.t === 'opt' ? x.has : I.T, inner = x?.t === 'opt' ? x.v : x;
|
|
1784
|
+
const zero = fv.sort.k === 'choice' ? { t: 'choice', e: I.llit(fv.sort.values[0], fv.sort.values) } : fv.sort.k === 'bool' ? { t: 'bool', e: I.F } : { t: 'num', e: I.num(0) };
|
|
1785
|
+
// (absent, or None: the default, as the text holds nothing there)
|
|
1786
|
+
vals.set(jf.name, inner && inner.t !== 'none' ? this.ite(has, this.fit(inner, fv, at), zero, at) : zero);
|
|
1787
|
+
if (jf.opt)
|
|
1788
|
+
vals.set(`${jf.name}_has`, { t: 'bool', e: has });
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
else {
|
|
1792
|
+
const v2 = sm.choice ? this.fit(v, o.decl.fields[0], at) : v;
|
|
1793
|
+
if (sm.choice ? v2.t !== 'choice' : o.val.k === 'str' ? v.t !== 'str' : v.t !== 'num')
|
|
1794
|
+
return refuse(at, `${at.text}: a ${v.t === 'opaque' ? v.why : v.t} set in a store of ${o.val.k === 'float' ? 'numbers' : o.val.k}`);
|
|
1795
|
+
if (!sm.choice && o.val.k === 'str')
|
|
1796
|
+
return refuse(at, `${at.text}: a store of strings (its cells hold numbers)`);
|
|
1797
|
+
vals = new Map([['value', v2]]);
|
|
1798
|
+
}
|
|
1799
|
+
if (!only)
|
|
1800
|
+
return [{ t: 'none' }, this.writeCell(id, o, k, I.T, vals, at, p)];
|
|
1801
|
+
// (nx: where the key holds nothing; xx: where it holds a value)
|
|
1802
|
+
const c = this.cellOf(o, k, p, at), when = only === 'nx' ? I.not(c.has) : c.has;
|
|
1803
|
+
const merged = new Map([...vals].map(([n, x]) => [n, this.ite(when, x, c.vals.get(n), at)]));
|
|
1804
|
+
return [{ t: 'opt', has: when, v: { t: 'bool', e: I.T } }, this.writeCell(id, o, k, I.bite(when, I.T, c.has), merged, at, p)];
|
|
1805
|
+
}
|
|
1806
|
+
// --- context managers of the module's, made by @contextmanager ---------------------------------------------------------
|
|
1807
|
+
// with self.cm(...): body, where cm is a generator the module reads, decorated @contextmanager: the generator run,
|
|
1808
|
+
// the with's body where it yields (in the with's frame), so a raise in the body goes through the generator's
|
|
1809
|
+
// handlers and finally first, as contextmanager throws it there. The body may not return, break or set a local (not
|
|
1810
|
+
// read here); the generator yields once (a path that ends without yielding fails, as contextmanager's RuntimeError).
|
|
1811
|
+
withBodies = [];
|
|
1812
|
+
generatorCM(s, p) {
|
|
1813
|
+
const items = s.items;
|
|
1814
|
+
if (items.length !== 1 || items[0].x.e !== 'call')
|
|
1815
|
+
return undefined;
|
|
1816
|
+
const it = items[0], fx = it.x.f;
|
|
1817
|
+
let f, q = p;
|
|
1818
|
+
try {
|
|
1819
|
+
[f, q] = fx.e === 'get' ? this.get(fx, p) : this.ev(fx, p);
|
|
1820
|
+
}
|
|
1821
|
+
catch {
|
|
1822
|
+
return undefined;
|
|
1823
|
+
}
|
|
1824
|
+
if (f.t !== 'fn')
|
|
1825
|
+
return undefined;
|
|
1826
|
+
const fn = this.mod.funcs[f.id];
|
|
1827
|
+
if (!fn?.decorators.some(d => /(?:^|\.)contextmanager$/.test(d.name)))
|
|
1828
|
+
return undefined;
|
|
1829
|
+
if (it.as)
|
|
1830
|
+
return refuse(s, `with ${it.x.text} as ...: a generator context manager's value`);
|
|
1831
|
+
const yields = [];
|
|
1832
|
+
let bad = '';
|
|
1833
|
+
deep(fn.body, o => { if (o.s === 'yield')
|
|
1834
|
+
yields.push(o); if (o.s === 'ret' || o.s === 'for')
|
|
1835
|
+
bad ||= o.s === 'ret' ? 'returns' : 'loops'; return false; });
|
|
1836
|
+
if (bad || yields.length !== 1)
|
|
1837
|
+
return refuse(s, `${fn.name}: a @contextmanager generator that ${bad || `yields ${yields.length} times`} (the subset reads one that yields once)`);
|
|
1838
|
+
if (deep(s.body, o => ['ret', 'break', 'continue'].includes(o.s) || (o.s === 'set' && o.to?.e === 'var')))
|
|
1839
|
+
return refuse(s, `with ${it.x.text}: a body that returns, breaks or sets a local, inside a generator context manager (not read)`);
|
|
1840
|
+
this.notes.add(`with ${it.x.text} (${it.x.p}): ${fn.name}, a @contextmanager generator, run around the with's body`);
|
|
1841
|
+
this.withBodies.push({ body: s.body, locals: q.locals });
|
|
1842
|
+
const start = { ...q, heap: new Map(q.heap).set('$yielded', { k: 'rec', ty: '$yielded', f: new Map([['n', { t: 'bool', e: I.F }]]), origin: 'fresh' }) };
|
|
1843
|
+
let out;
|
|
1844
|
+
try {
|
|
1845
|
+
out = this.evArgs(it.x, start, (args, kw, q2) => this.callFunc(fn, f.self, args, kw, it.x, q2, false))[1];
|
|
1846
|
+
}
|
|
1847
|
+
finally {
|
|
1848
|
+
this.withBodies.pop();
|
|
1849
|
+
}
|
|
1850
|
+
const y = out.heap.get('$yielded')?.f.get('n');
|
|
1851
|
+
const did = y?.t === 'bool' ? y.e : I.T, heap = new Map(out.heap);
|
|
1852
|
+
heap.delete('$yielded');
|
|
1853
|
+
this.fail(out, I.not(did), s, `${fn.name}: the generator didn't yield (a RuntimeError)`);
|
|
1854
|
+
return { live: this.assume({ ...out, heap }, did), rets: [] };
|
|
1855
|
+
}
|
|
1856
|
+
// --- values by their fields: dict literals, JSON, datetimes ----------------------------------------------------------
|
|
1857
|
+
// d[k]: a key the dict holds (one it may not hold is read with get); a timestamp has no items.
|
|
1858
|
+
valItem(m, k, x, p) {
|
|
1859
|
+
const ks = strLit(k);
|
|
1860
|
+
if (m.ty !== '$dict' || ks === undefined)
|
|
1861
|
+
return refuse(x, `${x.text}: an item of a ${m.ty.slice(1)}${m.ty === '$dict' ? ' by a key not known here' : ''}`);
|
|
1862
|
+
const v = m.f.get(ks);
|
|
1863
|
+
if (!v) {
|
|
1864
|
+
this.fail(p, I.T, x, `${x.text}: a key the dict doesn't hold (a KeyError)`);
|
|
1865
|
+
return [{ t: 'opaque', why: 'unreachable' }, { ...p, pc: [...p.pc, I.F] }];
|
|
1866
|
+
}
|
|
1867
|
+
// (a key on some paths only, or a stored record's optional field: absent and None are one there, read by get)
|
|
1868
|
+
if (v.t === 'opt' && !(v.has.op === 'const' && v.has.v))
|
|
1869
|
+
return refuse(x, `${x.text}: a key the dict may not hold, read by [] (the subset reads it with get)`);
|
|
1870
|
+
return [v, p];
|
|
1871
|
+
}
|
|
1872
|
+
valCall(o, m, args, kw, x, p) {
|
|
1873
|
+
if (o.ty === '$dt' && m === 'timestamp' && !args.length && !kw.length)
|
|
1874
|
+
return [{ t: 'val', ty: '$ts', f: o.f }, p];
|
|
1875
|
+
if (o.ty === '$dict' && m === 'get' && !kw.length && args.length >= 1 && args.length <= 2) {
|
|
1876
|
+
const ks = strLit(args[0]), d = args[1] ?? { t: 'none' };
|
|
1877
|
+
if (ks === undefined)
|
|
1878
|
+
return refuse(x, `${x.text}: a dict's get by a key not known here`);
|
|
1879
|
+
const v = o.f.get(ks);
|
|
1880
|
+
if (!v)
|
|
1881
|
+
return [d, p];
|
|
1882
|
+
return [v.t === 'opt' ? this.ite(v.has, v.v, d, x) : v, p];
|
|
1883
|
+
}
|
|
1884
|
+
if (o.ty === '$dict' && (m === 'values' || m === 'keys') && !args.length && !kw.length) {
|
|
1885
|
+
if ([...o.f.values()].some(v => v.t === 'opt'))
|
|
1886
|
+
return refuse(x, `${x.text}: the ${m} of a dict whose keys depend on the path`);
|
|
1887
|
+
return [{ t: 'tuple', xs: m === 'values' ? [...o.f.values()] : [...o.f.keys()].map(k => ({ t: 'str', e: { op: 'slit', value: k } })) }, p];
|
|
1888
|
+
}
|
|
1889
|
+
return refuse(x, `${x.text}: ${m} of a ${o.ty.slice(1)}`);
|
|
1890
|
+
}
|
|
1891
|
+
// json.dumps of a dict literal: its text, kept by its fields (json.loads gives the dict back); of anything else, a
|
|
1892
|
+
// text outside the subset. Only keyword options that change no key or value (sort_keys, separators, indent).
|
|
1893
|
+
json(q0, args, kw, x, p) {
|
|
1894
|
+
const v = args[0];
|
|
1895
|
+
if (args.length !== 1 || kw.some(([n]) => !['sort_keys', 'separators', 'indent', 'cls', 'ensure_ascii'].includes(n)))
|
|
1896
|
+
return refuse(x, `${x.text}: ${q0} given more than its value`);
|
|
1897
|
+
if (q0 === 'json.dumps') {
|
|
1898
|
+
if (v?.t === 'val' && v.ty === '$dict' && !kw.some(([n]) => n === 'cls')) {
|
|
1899
|
+
for (const [k, y] of v.f) {
|
|
1900
|
+
const z = y.t === 'opt' ? y.v : y;
|
|
1901
|
+
if (!['num', 'bool', 'str', 'choice', 'none', 'opaque'].includes(z.t))
|
|
1902
|
+
return refuse(x, `${x.text}: ${k}, a ${z.t === 'val' ? z.ty.slice(1) : z.t} put in a JSON text (the subset reads one of scalars)`);
|
|
1903
|
+
}
|
|
1904
|
+
this.notes.add(`${x.text} (${x.p}): JSON of a dict of scalars, read back by json.loads as the same dict`);
|
|
1905
|
+
return [{ t: 'val', ty: '$json', f: v.f }, p];
|
|
1906
|
+
}
|
|
1907
|
+
return [{ t: 'opaque', why: `${x.text}: a JSON text of a value outside the subset` }, p];
|
|
1908
|
+
}
|
|
1909
|
+
if (v?.t === 'val' && v.ty === '$json')
|
|
1910
|
+
return [{ t: 'val', ty: '$dict', f: v.f }, p];
|
|
1911
|
+
if (v?.t === 'opaque')
|
|
1912
|
+
return [v, p];
|
|
1913
|
+
return refuse(x, `${x.text}: json.loads of a ${v?.t === 'val' ? v.ty.slice(1) : v?.t ?? 'nothing'} (the subset reads back a text json.dumps made)`);
|
|
1914
|
+
}
|
|
1915
|
+
// A datetime plus or minus a timedelta, two datetimes apart, a timestamp in milliseconds (ts * 1000).
|
|
1916
|
+
valBin(op, a, b, x, p) {
|
|
1917
|
+
const ms = (v) => this.numOf(v.f.get('ms'), x, p), ty = (v) => (v.t === 'val' ? v.ty : v.t);
|
|
1918
|
+
// (a datetime past year 9999 or before year 1: Python's OverflowError, the step's failure there)
|
|
1919
|
+
const mk = (t, e) => {
|
|
1920
|
+
if (t === '$dt')
|
|
1921
|
+
this.fail(p, I.or(I.cmp('<', e, I.num(-62_135_596_800_000)), I.cmp('<', I.num(253_402_300_799_999), e)), x, `${x.text}: a datetime out of its range (an OverflowError)`);
|
|
1922
|
+
return { t: 'val', ty: t, f: new Map([['ms', { t: 'num', e }]]) };
|
|
1923
|
+
};
|
|
1924
|
+
if (op === '+' && ty(a) === '$dt' && ty(b) === '$td')
|
|
1925
|
+
return mk('$dt', I.add(ms(a), ms(b)));
|
|
1926
|
+
if (op === '+' && ty(a) === '$td' && ty(b) === '$dt')
|
|
1927
|
+
return mk('$dt', I.add(ms(a), ms(b)));
|
|
1928
|
+
if (op === '-' && ty(a) === '$dt' && ty(b) === '$td')
|
|
1929
|
+
return mk('$dt', I.sub(ms(a), ms(b)));
|
|
1930
|
+
if (op === '-' && ty(a) === '$dt' && ty(b) === '$dt')
|
|
1931
|
+
return mk('$td', I.sub(ms(a), ms(b)));
|
|
1932
|
+
if ((op === '+' || op === '-') && ty(a) === '$td' && ty(b) === '$td')
|
|
1933
|
+
return mk('$td', op === '+' ? I.add(ms(a), ms(b)) : I.sub(ms(a), ms(b)));
|
|
1934
|
+
if (op === '*' && ty(a) === '$ts' && constOf(b) === 1000)
|
|
1935
|
+
return { t: 'num', e: ms(a) };
|
|
1936
|
+
return refuse(x, `${x.text}: ${ty(a).replace('$', '')} ${op} ${ty(b).replace('$', '')}`);
|
|
1609
1937
|
}
|
|
1610
1938
|
// --- the boundary the caller states ---------------------------------------------------------------------------------
|
|
1611
1939
|
calleeNames(x) {
|
|
@@ -1668,10 +1996,16 @@ export class Stepper {
|
|
|
1668
1996
|
}
|
|
1669
1997
|
// A call left out inside a try (its value unread): stubbed only to raise where the request says, else run as it is.
|
|
1670
1998
|
passing(key, name, patch, at, p, awaited) {
|
|
1671
|
-
if (this.hidden)
|
|
1672
|
-
return refuse(at, `${at.text ?? name}: other code called in a loop inside a try (whether it raises would be one input a pass)`);
|
|
1673
1999
|
if (!this.tries.length)
|
|
1674
2000
|
return p;
|
|
2001
|
+
// (a logger's call: it never raises, logging handles its own errors)
|
|
2002
|
+
const fx = at.f;
|
|
2003
|
+
if (fx?.e === 'get' && fx.x?.nothrow) {
|
|
2004
|
+
this.notes.add(`${at.text ?? name} (${at.p}): a logger's call, which never raises (logging handles its handlers' errors)`);
|
|
2005
|
+
return p;
|
|
2006
|
+
}
|
|
2007
|
+
if (this.hidden)
|
|
2008
|
+
return refuse(at, `${at.text ?? name}: other code called in a loop inside a try (whether it raises would be one input a pass)`);
|
|
1675
2009
|
if (!patch && !at.end)
|
|
1676
2010
|
return refuse(at, `${at.text ?? name}: other code left out inside a try that may catch what it raises, and the check can't stub it`);
|
|
1677
2011
|
let a = this.answers.get(key);
|
|
@@ -1679,9 +2013,11 @@ export class Stepper {
|
|
|
1679
2013
|
this.answers.set(key, a = { key, patch: patch ?? {}, async: awaited, inputs: { name: '' }, sort: '', pass: true, at: [] });
|
|
1680
2014
|
if (!a.pass)
|
|
1681
2015
|
return refuse(at, `${at.text ?? name}: ${key} answered at one call and left out at another`);
|
|
1682
|
-
|
|
2016
|
+
// (the sites where it may raise, which the check's stub raises at: those inside a try with a handler for it)
|
|
2017
|
+
const q = this.mayRaise(a, name, at, p);
|
|
2018
|
+
if (q !== p && !a.at.some(x => x.p === at.p))
|
|
1683
2019
|
a.at.push({ p: at.p, ...(at.end ? { end: at.end } : {}), ...(at.span ? { span: at.span } : {}) });
|
|
1684
|
-
return
|
|
2020
|
+
return q;
|
|
1685
2021
|
}
|
|
1686
2022
|
// --- the boundary inferred ---------------------------------------------------------------------------------------
|
|
1687
2023
|
// A call of code the subset doesn't read (another module's, an injected dependency's, or the module's own function
|
|
@@ -2002,6 +2338,12 @@ export class Stepper {
|
|
|
2002
2338
|
case 'none': return [{ t: 'none' }, p];
|
|
2003
2339
|
case 'var': {
|
|
2004
2340
|
const v = p.locals.get(String(x.n));
|
|
2341
|
+
// (Python's local read on a path that never set it, past a raise caught before its assignment: an
|
|
2342
|
+
// UnboundLocalError on that path)
|
|
2343
|
+
if (!v && !x.why && this.mod.lang === 'python') {
|
|
2344
|
+
this.fail(p, I.T, x, `${String(x.n)}: a local read before it is set (an UnboundLocalError)`);
|
|
2345
|
+
return [{ t: 'opaque', why: 'unreachable' }, { ...p, pc: [...p.pc, I.F] }];
|
|
2346
|
+
}
|
|
2005
2347
|
if (!v)
|
|
2006
2348
|
return refuse(x, x.why ?? `${String(x.n)}: a variable read before it is set`);
|
|
2007
2349
|
return [this.narrow(v, p), p];
|
|
@@ -2010,7 +2352,7 @@ export class Stepper {
|
|
|
2010
2352
|
case 'cls': return [{ t: 'cls', rec: String(x.rec), ...(x.patch ? { patch: x.patch } : {}) }, p];
|
|
2011
2353
|
case 'builtin': return [{ t: 'builtin', n: String(x.n) }, p];
|
|
2012
2354
|
case 'lib': return [{ t: 'lib', q: String(x.q) }, p];
|
|
2013
|
-
case 'ext': return [{ t: 'ext', q: String(x.q), text: String(x.text), ...(x.patch ? { patch: x.patch } : {}), ...(x.ret ? { ret: x.ret } : {}) }, p];
|
|
2355
|
+
case 'ext': return [{ t: 'ext', q: String(x.q), text: String(x.text), ...(x.patch ? { patch: x.patch } : {}), ...(x.ret ? { ret: x.ret } : {}), ...(x.nothrow ? { nothrow: true } : {}) }, p];
|
|
2014
2356
|
case 'no': {
|
|
2015
2357
|
// (a call of other code a reader doesn't lower, `ext` its name: at the boundary, where it is inferred)
|
|
2016
2358
|
if (x.ext && !x.pre && !x.prepl) {
|
|
@@ -2220,6 +2562,8 @@ export class Stepper {
|
|
|
2220
2562
|
const [m, q] = this.ev(x.x, p), [k, q2] = this.ev(x.i, q);
|
|
2221
2563
|
if (m.t === 'opaque')
|
|
2222
2564
|
return [m, q2];
|
|
2565
|
+
if (m.t === 'val')
|
|
2566
|
+
return this.valItem(m, k, x, q2);
|
|
2223
2567
|
const ord = this.orderedObj(m, q2);
|
|
2224
2568
|
if (ord) {
|
|
2225
2569
|
const i = constOf(k);
|
|
@@ -2272,9 +2616,20 @@ export class Stepper {
|
|
|
2272
2616
|
}
|
|
2273
2617
|
case 'fstr': return this.fstr(x, p);
|
|
2274
2618
|
case 'dict': {
|
|
2275
|
-
if (x.keys.length)
|
|
2276
|
-
return
|
|
2277
|
-
|
|
2619
|
+
if (!x.keys.length)
|
|
2620
|
+
return [{ t: 'opaque', why: '{} (an empty dict, a map only where a field declares its type)' }, p];
|
|
2621
|
+
// (string keys known here, a record by value: its keys its fields)
|
|
2622
|
+
let q = p;
|
|
2623
|
+
const f = new Map();
|
|
2624
|
+
for (const [i, kx] of x.keys.entries()) {
|
|
2625
|
+
const [k, q1] = this.ev(kx, q), ks = strLit(k);
|
|
2626
|
+
if (ks === undefined)
|
|
2627
|
+
return refuse(x, `${x.text ?? 'a dict literal'}: a dict literal whose keys aren't strings known where it is made (a record is made by its class)`);
|
|
2628
|
+
const [v, q2] = this.ev(x.vals[i], q1);
|
|
2629
|
+
f.set(ks, v);
|
|
2630
|
+
q = q2;
|
|
2631
|
+
}
|
|
2632
|
+
return [{ t: 'val', ty: '$dict', f }, q];
|
|
2278
2633
|
}
|
|
2279
2634
|
// (an empty list: an ordered collection where a field of the state declares a list of records or numbers)
|
|
2280
2635
|
case 'list': return x.xs.length ? refuse(x, 'a list literal with items (the subset keeps a list of the state, made empty)') : [{ t: 'opaque', why: '[] (an empty list, a collection only where a field declares its type)' }, p];
|
|
@@ -2374,7 +2729,7 @@ export class Stepper {
|
|
|
2374
2729
|
if (o.sattr)
|
|
2375
2730
|
return this.storeAttr(o.sattr.store, `${o.sattr.path}.${f}`, x, q);
|
|
2376
2731
|
return [{ t: 'opaque', why: o.why, ...(o.ask ? { ask: o.ask } : {}) }, q];
|
|
2377
|
-
case 'ext': return [{ t: 'ext', q: `${o.q}.${f}`, text: `${o.text}.${f}`, ...(o.patch?.path ? { patch: { ...o.patch, path: [...o.patch.path, f] } } : {}) }, q];
|
|
2732
|
+
case 'ext': return [{ t: 'ext', q: `${o.q}.${f}`, text: `${o.text}.${f}`, ...(o.patch?.path ? { patch: { ...o.patch, path: [...o.patch.path, f] } } : {}), ...(o.nothrow ? { nothrow: true } : {}) }, q];
|
|
2378
2733
|
case 'none':
|
|
2379
2734
|
this.fail(q, I.T, x, `${x.text}: a field of None (an AttributeError)`);
|
|
2380
2735
|
return [{ t: 'opaque', why: 'unreachable' }, { ...q, pc: [...q.pc, I.F] }];
|
|
@@ -2413,7 +2768,8 @@ export class Stepper {
|
|
|
2413
2768
|
case 'map':
|
|
2414
2769
|
case 'list':
|
|
2415
2770
|
case 'push':
|
|
2416
|
-
case 'pop':
|
|
2771
|
+
case 'pop':
|
|
2772
|
+
case 'val': return refuse(x, `${x.text}: a field of a ${o.t === 'val' ? o.ty.slice(1) : o.t}`);
|
|
2417
2773
|
}
|
|
2418
2774
|
if (o.t === 'sattr')
|
|
2419
2775
|
return this.storeAttr(o.store, o.path ? `${o.path}.${f}` : f, x, q);
|
|
@@ -2423,6 +2779,9 @@ export class Stepper {
|
|
|
2423
2779
|
if (obj?.k !== 'rec')
|
|
2424
2780
|
return refuse(x, `${x.text}: a field of other than an object`);
|
|
2425
2781
|
const r = this.rec(obj.ty, x);
|
|
2782
|
+
// (super().f: the base's method the reader resolved, on this object)
|
|
2783
|
+
if (typeof x.sup === 'string')
|
|
2784
|
+
return [{ t: 'fn', id: x.sup, self: o }, q];
|
|
2426
2785
|
const v = obj.f.get(f);
|
|
2427
2786
|
if (v)
|
|
2428
2787
|
return [v, q];
|
|
@@ -2472,6 +2831,8 @@ export class Stepper {
|
|
|
2472
2831
|
if (x.ovf)
|
|
2473
2832
|
return this.fixed(x, p);
|
|
2474
2833
|
const [a, q] = this.ev(x.x, p), [b, q2] = this.ev(x.y, q);
|
|
2834
|
+
if (a.t === 'val' || b.t === 'val')
|
|
2835
|
+
return [this.valBin(op, a, b, x, q2), q2];
|
|
2475
2836
|
// A true division: a float, kept only where nothing the rule keeps reads it (refused there); its divisor 0 fails.
|
|
2476
2837
|
if (op === '/') {
|
|
2477
2838
|
if (b.t === 'num' || b.t === 'bool') {
|
|
@@ -2516,7 +2877,7 @@ export class Stepper {
|
|
|
2516
2877
|
if (a.t === 'opaque' || b.t === 'opaque')
|
|
2517
2878
|
return [a.t === 'opaque' ? a : b, q2];
|
|
2518
2879
|
const na = this.numOf(a, x, q2), nb = this.numOf(b, x, q2);
|
|
2519
|
-
const ty = (a.t === 'num' ? a.ty : undefined) ?? (b.t === 'num' ? b.ty : undefined) ?? (ovf === 'sat0' || ovf === 'checked0' ? { bits: 0, signed: false } : undefined);
|
|
2880
|
+
const ty = x.ity ?? (a.t === 'num' ? a.ty : undefined) ?? (b.t === 'num' ? b.ty : undefined) ?? (ovf === 'sat0' || ovf === 'checked0' ? { bits: 0, signed: false } : undefined);
|
|
2520
2881
|
let e;
|
|
2521
2882
|
if (op === '+')
|
|
2522
2883
|
e = I.add(na, nb);
|
|
@@ -2537,7 +2898,12 @@ export class Stepper {
|
|
|
2537
2898
|
else
|
|
2538
2899
|
return refuse(x, `${x.text}: ${op}`);
|
|
2539
2900
|
const out = (n) => ({ t: 'num', e: n, ...(ty ? { ty } : {}) });
|
|
2540
|
-
const [lo, hi] = ty ? rangeOf(ty) : [-Infinity, Infinity], [
|
|
2901
|
+
const [lo, hi] = ty ? rangeOf(ty) : [-Infinity, Infinity], [below0, above0] = this.past(e, lo, hi, q2);
|
|
2902
|
+
// (a symbolic width: past it where the result may be at least its 2^bits; of two values below it, a difference is
|
|
2903
|
+
// never at or past it and a sum or a product never below 0)
|
|
2904
|
+
const above = ty?.mod ? (op === '-' ? I.F : this.pastMod(e, ty.mod)) : above0, below = ty?.mod && op !== '-' ? I.F : below0;
|
|
2905
|
+
if (ty?.mod && ovf !== 'trap' && ovf !== 'checked' && ovf !== 'wrap')
|
|
2906
|
+
return refuse(x, `${x.text}: ${ovf} at ${tyName(ty)}`);
|
|
2541
2907
|
switch (ovf) {
|
|
2542
2908
|
case 'trap':
|
|
2543
2909
|
this.fail(q2, I.or(below, above), x, `${x.text}: past ${tyName(ty)}'s range (${typeof x.trap === 'string' ? x.trap : `a panic: attempt to ${op === '+' ? 'add' : op === '-' ? 'subtract' : op === '*' ? 'multiply' : 'divide'} with overflow`})`);
|
|
@@ -2653,6 +3019,34 @@ export class Stepper {
|
|
|
2653
3019
|
return I.F;
|
|
2654
3020
|
return refuse(at, `${at.text}: ${a.t} == ${b.t}`);
|
|
2655
3021
|
}
|
|
3022
|
+
// The truth of a condition: of and / or, its operands' truths (short-circuited), whatever kinds their values are
|
|
3023
|
+
// (bool(n and t > n), where `and`'s value would be a number on one path and a boolean on another).
|
|
3024
|
+
truth(x, p) {
|
|
3025
|
+
if (x.e === 'and' || x.e === 'or') {
|
|
3026
|
+
const xs = x.xs, isAnd = x.e === 'and';
|
|
3027
|
+
const go = (i, q) => {
|
|
3028
|
+
const [c, q1] = this.truth(xs[i], q);
|
|
3029
|
+
if (i === xs.length - 1)
|
|
3030
|
+
return [c, q1];
|
|
3031
|
+
const stop = isAnd ? I.not(c) : c;
|
|
3032
|
+
if (stop.op === 'const' && stop.v)
|
|
3033
|
+
return [isAnd ? I.F : I.T, q1];
|
|
3034
|
+
const [rest, q2] = go(i + 1, this.assume(q1, I.not(stop)));
|
|
3035
|
+
if (stop.op === 'const')
|
|
3036
|
+
return [rest, q2];
|
|
3037
|
+
return [isAnd ? I.and(c, rest) : I.or(c, rest), this.merge(this.assume(q1, stop), q2, x)];
|
|
3038
|
+
};
|
|
3039
|
+
return go(0, p);
|
|
3040
|
+
}
|
|
3041
|
+
if (x.e === 'not' && !x.strict) {
|
|
3042
|
+
const [c, q] = this.truth(x.x, p);
|
|
3043
|
+
return [I.not(c), q];
|
|
3044
|
+
}
|
|
3045
|
+
const [v, q] = this.ev(x, p);
|
|
3046
|
+
if (v.t === 'opaque')
|
|
3047
|
+
return refuse(x, `${x.text ?? ''}: the truth of ${v.why}`);
|
|
3048
|
+
return [this.truthy(v, x, q), q];
|
|
3049
|
+
}
|
|
2656
3050
|
// and / or: Python's give one of their operands (the first falsy, or the last; the first truthy, or the last).
|
|
2657
3051
|
boolOp(x, p) {
|
|
2658
3052
|
const xs = x.xs, isAnd = x.e === 'and';
|
|
@@ -2702,6 +3096,8 @@ export class Stepper {
|
|
|
2702
3096
|
return [{ t: 'fmt', tpl, k: hole }, q];
|
|
2703
3097
|
}
|
|
2704
3098
|
call(x, p, awaited) {
|
|
3099
|
+
if (dead(p))
|
|
3100
|
+
return [{ t: 'opaque', why: 'unreachable' }, p];
|
|
2705
3101
|
const fx = x.f, names = this.calleeNames(x), args0 = x.args, kw0 = x.kw;
|
|
2706
3102
|
// The boundary first: an answered call, then a skipped one (neither's arguments read).
|
|
2707
3103
|
const ans = this.match(Object.keys(this.opts.answers ?? {}), names), skip = !ans && this.skipped(names);
|
|
@@ -2740,6 +3136,8 @@ export class Stepper {
|
|
|
2740
3136
|
if (fx.e === 'get') {
|
|
2741
3137
|
const [o, q1] = this.ev(fx.x, q);
|
|
2742
3138
|
q = q1;
|
|
3139
|
+
if (o.t === 'val')
|
|
3140
|
+
return this.evArgs(x, q, (args, kw, q2) => this.valCall(o, String(fx.f), args, kw, x, q2));
|
|
2743
3141
|
const ord = this.orderedObj(o, q);
|
|
2744
3142
|
if (ord)
|
|
2745
3143
|
return this.listCall(ord[0], ord[1], String(fx.f), x, q);
|
|
@@ -2776,13 +3174,15 @@ export class Stepper {
|
|
|
2776
3174
|
case 'cls': {
|
|
2777
3175
|
// (another module's class made: other code, at the boundary)
|
|
2778
3176
|
const r = this.inf ? this.mod.recs[f.rec] : undefined;
|
|
2779
|
-
if (r && !r.own)
|
|
3177
|
+
if (r && !r.own && !madeByInit(r))
|
|
2780
3178
|
return this.boundary(x, { key: f.rec, name: names[0] ?? r.short, ...(f.patch ? { patch: f.patch } : {}), ret: { k: 'rec', name: f.rec }, refusal: `${x.text}: ${r.short} made (the subset makes the module's own dataclasses)` }, q, awaited);
|
|
2781
3179
|
return this.evArgs(x, q, (args, kw, q2) => this.construct(f.rec, args, kw, x, q2));
|
|
2782
3180
|
}
|
|
2783
3181
|
case 'builtin': return this.builtin(f.n, x, q);
|
|
2784
3182
|
case 'lib': return this.lib(f.q, x, q);
|
|
2785
3183
|
case 'ext': {
|
|
3184
|
+
if (f.q === 'json.dumps' || f.q === 'json.loads')
|
|
3185
|
+
return this.evArgs(x, q, (args, kw, q2) => this.json(f.q, args, kw, x, q2));
|
|
2786
3186
|
const refusal = `${x.text}: ${f.q}, other code (answer it, skip it, or read that module)`;
|
|
2787
3187
|
return this.inf ? this.boundary(x, { key: f.q, name: /\s/.test(names[0] ?? ' ') ? f.q : names[0], ...(f.patch ? { patch: f.patch } : {}), ...(f.ret ? { ret: f.ret } : {}), ...(f.recv ? { recv: f.recv } : {}), refusal }, q, awaited) : refuse(x, refusal);
|
|
2788
3188
|
}
|
|
@@ -2807,7 +3207,8 @@ export class Stepper {
|
|
|
2807
3207
|
case 'map':
|
|
2808
3208
|
case 'list':
|
|
2809
3209
|
case 'push':
|
|
2810
|
-
case 'pop':
|
|
3210
|
+
case 'pop':
|
|
3211
|
+
case 'val': break;
|
|
2811
3212
|
}
|
|
2812
3213
|
void args0;
|
|
2813
3214
|
void kw0;
|
|
@@ -2865,6 +3266,12 @@ export class Stepper {
|
|
|
2865
3266
|
}
|
|
2866
3267
|
construct(rec, args, kw, x, p) {
|
|
2867
3268
|
const r = this.rec(rec, x);
|
|
3269
|
+
// (a plain class of the repository whose __init__ the reader read: made by running it on a fresh object)
|
|
3270
|
+
if (madeByInit(r)) {
|
|
3271
|
+
const id = `fresh:${this.fresh++}`, q1 = { ...p, heap: new Map(p.heap).set(id, { k: 'rec', ty: rec, f: new Map(), origin: 'fresh' }) };
|
|
3272
|
+
this.notes.add(`${r.short}(...) (${x.p}): made by its __init__, read`);
|
|
3273
|
+
return [{ t: 'ref', id }, this.callFunc(this.func(r.methods.__init__, x), { t: 'ref', id }, args, kw, x, q1, false)[1]];
|
|
3274
|
+
}
|
|
2868
3275
|
if (!r.kinds.includes('dataclass') || !r.own)
|
|
2869
3276
|
return refuse(x, `${x.text}: ${r.short} made (the subset makes the module's own dataclasses)`);
|
|
2870
3277
|
if (r.methods.__init__ || r.methods.__post_init__)
|
|
@@ -2900,9 +3307,16 @@ export class Stepper {
|
|
|
2900
3307
|
return this.quotient(a0, p, 'trunc');
|
|
2901
3308
|
if (n === 'round' && a0?.e === 'bin' && a0.op === '/' && x.args.length === 1 && !x.kw.length)
|
|
2902
3309
|
return this.quotient(a0, p, 'even');
|
|
3310
|
+
if (n === 'bool' && (a0?.e === 'and' || a0?.e === 'or') && x.args.length === 1) {
|
|
3311
|
+
const [c, q] = this.truth(a0, p);
|
|
3312
|
+
return [{ t: 'bool', e: c }, q];
|
|
3313
|
+
}
|
|
2903
3314
|
return this.evArgs(x, p, (args, kw, q) => {
|
|
2904
3315
|
if (kw.length)
|
|
2905
3316
|
return refuse(x, `${x.text}: ${n} given keywords`);
|
|
3317
|
+
// (int of a timestamp: its whole seconds)
|
|
3318
|
+
if (n === 'int' && args[0]?.t === 'val')
|
|
3319
|
+
return args[0].ty === '$ts' ? [{ t: 'num', e: I.divk(1000, this.numOf(args[0].f.get('ms'), x, q)) }, q] : refuse(x, `${x.text}: int of a ${args[0].ty.slice(1)}`);
|
|
2906
3320
|
if (args.some(a => a.t === 'opaque') && ['str', 'repr', 'len', 'isinstance', 'round', 'int', 'float', 'bool'].includes(n)) {
|
|
2907
3321
|
const ask = args.find(a => a.t === 'opaque' && a.ask);
|
|
2908
3322
|
return [{ t: 'opaque', why: `${x.text}: of a value outside the subset${ask ? ` (${ask.why})` : ''}`, ...(ask ? { ask: ask.ask } : {}) }, q];
|
|
@@ -2976,6 +3390,28 @@ export class Stepper {
|
|
|
2976
3390
|
}
|
|
2977
3391
|
if (q0 === 'threading.Lock' || q0 === 'threading.RLock' || q0 === 'asyncio.Lock')
|
|
2978
3392
|
return [{ t: 'lock' }, p];
|
|
3393
|
+
// A datetime: the request's time (in whole seconds, as time.time()), in milliseconds; a timedelta by its parts.
|
|
3394
|
+
if (q0 === 'datetime.datetime.now') {
|
|
3395
|
+
if (x.args.length || x.kw.length)
|
|
3396
|
+
return refuse(x, `${x.text}: now() given a time zone`);
|
|
3397
|
+
this.notes.add(`${q0}() is the request's time (an input, at whole seconds: the claim is for those)`);
|
|
3398
|
+
const [t, q] = this.clock(x, p);
|
|
3399
|
+
return [{ t: 'val', ty: '$dt', f: new Map([['ms', { t: 'num', e: I.mulk(1000, t.e) }]]) }, q];
|
|
3400
|
+
}
|
|
3401
|
+
if (q0 === 'datetime.timedelta')
|
|
3402
|
+
return this.evArgs(x, p, (args, kw, q) => {
|
|
3403
|
+
const unit = { days: 86_400_000, seconds: 1000, milliseconds: 1, minutes: 60_000, hours: 3_600_000, weeks: 604_800_000 };
|
|
3404
|
+
if (args.length > 1)
|
|
3405
|
+
return refuse(x, `${x.text}: a timedelta of positional parts past its days`);
|
|
3406
|
+
const parts = [...(args.length ? [['days', args[0]]] : []), ...kw];
|
|
3407
|
+
let ms = I.num(0);
|
|
3408
|
+
for (const [n, v] of parts) {
|
|
3409
|
+
if (!(n in unit))
|
|
3410
|
+
return refuse(x, `${x.text}: a timedelta's ${n}`);
|
|
3411
|
+
ms = I.add(ms, I.mulk(unit[n], this.numOf(v, x, q)));
|
|
3412
|
+
}
|
|
3413
|
+
return [{ t: 'val', ty: '$td', f: new Map([['ms', { t: 'num', e: ms }]]) }, q];
|
|
3414
|
+
});
|
|
2979
3415
|
return this.evArgs(x, p, (args, _kw, q) => {
|
|
2980
3416
|
const v = args[0];
|
|
2981
3417
|
if (v?.t === 'opaque')
|
|
@@ -3392,6 +3828,17 @@ export class Stepper {
|
|
|
3392
3828
|
wrap(e, ty, x, p) {
|
|
3393
3829
|
if (ty.bits === 0)
|
|
3394
3830
|
return e;
|
|
3831
|
+
if (ty.mod) {
|
|
3832
|
+
// Modulo a symbolic 2^bits: a sum or a difference of two values below it is at most once past it, by cases (a
|
|
3833
|
+
// product may be many times past: refused).
|
|
3834
|
+
if (hasProduct(e))
|
|
3835
|
+
return refuse(x, `${x.text ? `${x.text}: ` : ''}a product wrapped modulo 2^${ty.bits} (the subset wraps sums and differences at that width)`);
|
|
3836
|
+
// (two values below 2^n: a sum is never below 0, a difference never at or past 2^n)
|
|
3837
|
+
const below = e.op === 'add' ? I.F : this.past(e, 0, Infinity, p)[0], above = e.op === 'sub' ? I.F : this.pastMod(e, ty.mod), m = I.nvar(ty.mod);
|
|
3838
|
+
this.notes.add(`${ty.name ?? tyName(ty)}: a result past its range wraps modulo 2^${ty.bits} (${ty.mod}, any width at least 2 in the rule: a law proven is proven at 2^${ty.bits})`);
|
|
3839
|
+
// (a − b below 0 is (2^n − b) + a: each part a natural, b being below 2^n)
|
|
3840
|
+
return I.nite(below, e.op === 'sub' ? I.add(I.sub(m, e.b), e.a) : I.add(e, m), I.nite(above, I.sub(e, m), e));
|
|
3841
|
+
}
|
|
3395
3842
|
if (ty.ub) {
|
|
3396
3843
|
const out = I.or(...this.past(e, ...rangeOf(ty), p));
|
|
3397
3844
|
if (!(out.op === 'const' && !out.v)) {
|
|
@@ -3427,6 +3874,8 @@ export class Stepper {
|
|
|
3427
3874
|
// Many times over (a conversion from a wider type, a product): e − 2^n·⌊(e − lo)/2^n⌋.
|
|
3428
3875
|
return I.sub(e, I.mulk(m, I.divk(m, I.add(e, I.num(-lo)))));
|
|
3429
3876
|
}
|
|
3877
|
+
// Where e may be at or past a symbolic 2^bits (false where e is a constant below 2, the least width).
|
|
3878
|
+
pastMod(e, mod) { return e.op === 'const' && e.v < 2 ? I.F : I.cmp('<=', I.nvar(mod), e); }
|
|
3430
3879
|
// Where e may be past [lo, hi] on the path: below and above, each false where the term's bounds or the path's facts
|
|
3431
3880
|
// keep it within.
|
|
3432
3881
|
past(e, lo, hi, p) {
|
|
@@ -3850,6 +4299,13 @@ const assigned = (ss) => {
|
|
|
3850
4299
|
// A pointer by a condition (one case where both are the same).
|
|
3851
4300
|
export const phiP = (c, a, b) => (c.op === 'const' ? (c.v ? a : b) : JSON.stringify(a) === JSON.stringify(b) ? a : { k: 'phi', c, a, b });
|
|
3852
4301
|
// The values a merge keeps exact (Go's): refused, not made opaque, where two paths make them different.
|
|
4302
|
+
// A path a failure ended (its condition false): what follows on it is never run.
|
|
4303
|
+
const dead = (p) => p.pc.some(c => c.op === 'const' && !c.v);
|
|
4304
|
+
// A string known where it is read (a literal; a choice's one value).
|
|
4305
|
+
const strLit = (v) => (v.t === 'str' && v.e.op === 'slit' ? v.e.value : v.t === 'choice' && v.e.op === 'lit' ? v.e.value : undefined);
|
|
4306
|
+
// A class made by running its __init__: one the reader read (a class of the file, or of the repository the code makes),
|
|
4307
|
+
// not a dataclass, a model or a protocol, every base known.
|
|
4308
|
+
const madeByInit = (r) => typeof r.methods.__init__ === 'string' && !r.kinds.some(k => ['dataclass', 'pydantic', 'typeddict', 'protocol'].includes(k) || k.startsWith('outside-base'));
|
|
3853
4309
|
const firm = (v) => ['ptr', 'struct', 'err', 'nil', 'map', 'list', 'push', 'pop'].includes(v.t) || (v.t === 'opaque' && !!v.firm);
|
|
3854
4310
|
// An expression that calls nothing (so evaluating it changes nothing).
|
|
3855
4311
|
// Whether some node of an IR tree (an object, depth first) is one f says yes to.
|
|
@@ -4079,6 +4535,8 @@ function readOnce(mod, opts, g) {
|
|
|
4079
4535
|
g.storeTypes.set(pa.name, dep.ty);
|
|
4080
4536
|
if (dep)
|
|
4081
4537
|
g.notes.add(`${r.short}(${pa.name}): an injected dependency (inferred: ${pa.inject ? 'marked so' : `of ${dep.ty ? g.mod.recs[dep.ty]?.short ?? dep.ty : 'no stated type'}, its methods called`}), the check giving one that ${dep.keyed ? 'keeps what is set' : 'answers its calls'}`);
|
|
4538
|
+
if (pa.dflt?.e === 'none')
|
|
4539
|
+
g.notes.add(`${r.short}(${pa.name}): given one, never its default None (the claim is for objects made with one)`);
|
|
4082
4540
|
continue;
|
|
4083
4541
|
}
|
|
4084
4542
|
if (pa.dflt && !g.scalar(pa.t.k === 'opt' ? pa.t.of : pa.t)) {
|
|
@@ -4088,6 +4546,15 @@ function readOnce(mod, opts, g) {
|
|
|
4088
4546
|
p = p2;
|
|
4089
4547
|
continue;
|
|
4090
4548
|
}
|
|
4549
|
+
if (pa.dflt && opts.defaults?.includes(pa.name)) {
|
|
4550
|
+
ctor.push([pa.name, { k: 'dflt' }]);
|
|
4551
|
+
const [d, p2] = g.ev(pa.dflt, p);
|
|
4552
|
+
give(pa, d);
|
|
4553
|
+
p = p2;
|
|
4554
|
+
g.atDefault.add(d);
|
|
4555
|
+
g.notes.add(`${r.short}(${pa.name}): at its default (stated: defaults), the fields set to it constants`);
|
|
4556
|
+
continue;
|
|
4557
|
+
}
|
|
4091
4558
|
const [v, a] = g.input(pa.name, pa.t, fn, p, 'param');
|
|
4092
4559
|
if (a.k === 'inert')
|
|
4093
4560
|
refuse(fn, `${r.short}(${pa.name}): a constructor argument of ${g.why(pa.t)} (state it as a store, or give it a default)`);
|
|
@@ -4153,6 +4620,14 @@ function readOnce(mod, opts, g) {
|
|
|
4153
4620
|
if (g.deps.length > 1)
|
|
4154
4621
|
g.notes.add(`${r.short}: assumes its injected dependencies ${g.deps.map(d => d.name).join(', ')} are distinct objects (each with what it holds)`);
|
|
4155
4622
|
const self = made.heap.get('this');
|
|
4623
|
+
for (const [f, c] of Object.entries(opts.fields ?? {})) {
|
|
4624
|
+
if (!self.f.has(f))
|
|
4625
|
+
refuse(r, `${r.short}.${f}: a field stated (fields) that the constructor doesn't set`);
|
|
4626
|
+
const v = c === null ? { t: 'none' } : typeof c === 'boolean' ? { t: 'bool', e: c ? I.T : I.F } : typeof c === 'number' ? { t: 'num', e: I.num(c) } : { t: 'str', e: { op: 'slit', value: c } };
|
|
4627
|
+
self.f.set(f, v);
|
|
4628
|
+
g.atDefault.add(v);
|
|
4629
|
+
g.notes.add(`${r.short}.${f}: held at ${JSON.stringify(c)} (stated: fields; the claim is for objects so configured)`);
|
|
4630
|
+
}
|
|
4156
4631
|
for (const [f, v] of self.f) {
|
|
4157
4632
|
const t = g.declared.get(`this.${f}`) ?? r.fields.find(x => x.name === f)?.t;
|
|
4158
4633
|
tree.push({ path: [f], v, ...(t && t.k !== 'any' ? { t } : {}) });
|
|
@@ -4168,9 +4643,17 @@ function readOnce(mod, opts, g) {
|
|
|
4168
4643
|
const scalarT = decl && decl.k !== 'opt' ? decl : undefined;
|
|
4169
4644
|
const leaf = (kind, vr, float) => { leaves.push({ name: vr.name, path, kind, ...(float ? { float: true } : {}) }); return vr; };
|
|
4170
4645
|
const isFloat = (decl?.k === 'float') || (decl?.k === 'opt' && decl.of.k === 'float');
|
|
4171
|
-
if (
|
|
4172
|
-
|
|
4173
|
-
|
|
4646
|
+
if (g.atDefault.has(v)) {
|
|
4647
|
+
into.set(f, v);
|
|
4648
|
+
g.frozen.add(path.join('.'));
|
|
4649
|
+
leaves.push({ name: '', path, kind: 'frame' });
|
|
4650
|
+
return;
|
|
4651
|
+
}
|
|
4652
|
+
const inner = decl?.k === 'opt' ? decl.of : scalarT;
|
|
4653
|
+
// (None, of an optional type of no scalar inside, a dict's or another class's: as a field set to None, below)
|
|
4654
|
+
const sort0 = inner && g.scalar(inner) ? g.scalar(inner) : v.t === 'num' ? { k: 'num' } : v.t === 'bool' ? { k: 'bool' } : v.t === 'str' ? { k: 'str' } : v.t === 'choice' ? { k: 'choice', values: lvalues(v.e) } : v.t === 'opt' && g.scalar({ k: v.v.t === 'num' ? 'int' : v.v.t === 'bool' ? 'bool' : 'str' }) ? (v.v.t === 'num' ? { k: 'num' } : v.v.t === 'bool' ? { k: 'bool' } : { k: 'str' }) : undefined;
|
|
4655
|
+
if (v.t === 'num' || v.t === 'bool' || v.t === 'str' || v.t === 'choice' || (v.t === 'none' && decl?.k === 'opt' && sort0) || v.t === 'opt') {
|
|
4656
|
+
const sort = sort0 ?? refuse(at, `${path.join('.')}: a field of no scalar type`);
|
|
4174
4657
|
if (v.t === 'str' && sort.k === 'choice' && v.e.op === 'slit')
|
|
4175
4658
|
v = { t: 'choice', e: I.llit(v.e.value, sort.values) };
|
|
4176
4659
|
const optional = v.t === 'none' || v.t === 'opt' || decl?.k === 'opt';
|
|
@@ -4233,6 +4716,13 @@ function readOnce(mod, opts, g) {
|
|
|
4233
4716
|
into.set(f, v);
|
|
4234
4717
|
return;
|
|
4235
4718
|
}
|
|
4719
|
+
// (a function of other code, json.dumps: a constant of the object, its calls other code's; a method rebinding it refused)
|
|
4720
|
+
if (v.t === 'ext' && !v.recv) {
|
|
4721
|
+
into.set(f, v);
|
|
4722
|
+
g.frozen.add(path.join('.'));
|
|
4723
|
+
leaves.push({ name: '', path, kind: 'frame' });
|
|
4724
|
+
return;
|
|
4725
|
+
}
|
|
4236
4726
|
// A field the constructor sets to None, of no declared type: a constant (a method setting it is refused).
|
|
4237
4727
|
if (v.t === 'none') {
|
|
4238
4728
|
into.set(f, v);
|
|
@@ -4290,7 +4780,9 @@ function readOnce(mod, opts, g) {
|
|
|
4290
4780
|
q = g.assume(q, out.ok);
|
|
4291
4781
|
out = out.v;
|
|
4292
4782
|
}
|
|
4293
|
-
|
|
4783
|
+
// (the failures first, the step's end the else: its conditions may be only what its returns share, which a merge
|
|
4784
|
+
// would read as holding on every path)
|
|
4785
|
+
p = g.failPaths.length ? g.join([...g.failPaths, q], fn) : q;
|
|
4294
4786
|
finals.push({ sel, path: p, out, fails: g.fails });
|
|
4295
4787
|
argsOf[fn.name] = pargs;
|
|
4296
4788
|
}
|
|
@@ -4365,12 +4857,18 @@ function readOnce(mod, opts, g) {
|
|
|
4365
4857
|
const id = [...g.initHeap].find(([, o]) => o.k === 'map' && o.decl === d)?.[0];
|
|
4366
4858
|
if (!id)
|
|
4367
4859
|
continue;
|
|
4368
|
-
const
|
|
4860
|
+
const cw = (w0) => ({ key: w0.key, has: w0.has, vals: Object.fromEntries([...w0.vals].map(([f2, v]) => [f2, termOf(v, at)])) });
|
|
4861
|
+
const lists = finals.map(f => { const o = f.path.heap.get(id); return [...(o?.pre ?? []), ...(o?.w ? [o.w] : [])].map(cw); });
|
|
4369
4862
|
// (a failure kept, the cell as it was there)
|
|
4370
|
-
const
|
|
4371
|
-
return w2; const fl = failedOf(finals[i]), b = base(w2.key); return { key: w2.key, has: I.bite(fl, b.has, w2.has), vals: Object.fromEntries(Object.entries(w2.vals).map(([f, t]) => [f, iteTerm(fl, b.vals[f], t)])) }; }
|
|
4863
|
+
const fix = (i, w2, base) => { if (!kept || carried)
|
|
4864
|
+
return w2; const fl = failedOf(finals[i]), b = base(w2.key); return { key: w2.key, has: I.bite(fl, b.has, w2.has), vals: Object.fromEntries(Object.entries(w2.vals).map(([f, t]) => [f, iteTerm(fl, b.vals[f], t)])) }; };
|
|
4865
|
+
// (several keys written by some method: each method's writes under its own selector, so a key compared is the
|
|
4866
|
+
// request's, never one of two by the method)
|
|
4867
|
+
const base = (k) => { const c = g.baseCell(d, k); return { key: k, has: c.has, vals: Object.fromEntries([...c.vals].map(([f2, v]) => [f2, termOf(v, at)])) }; };
|
|
4868
|
+
const ws = lists.some(l => l.length > 1) ? finals.flatMap((f, i) => lists[i].map(w2 => ({ ...fix(i, w2, base), when: f.sel }))) : [];
|
|
4869
|
+
const w = ws.length ? ws.at(-1) : mapWritesOf(g, d, finals.map(f => f.sel), lists.map(l => l[0]), fix);
|
|
4372
4870
|
if (w)
|
|
4373
|
-
mapWrites[d.name] = w;
|
|
4871
|
+
mapWrites[d.name] = ws.length > 1 ? { ...w, pre: ws.slice(0, -1) } : w;
|
|
4374
4872
|
}
|
|
4375
4873
|
// What each method returns, and whether it failed: the step's result.
|
|
4376
4874
|
const results = {}, resultKinds = {};
|
|
@@ -4461,7 +4959,7 @@ function readOnce(mod, opts, g) {
|
|
|
4461
4959
|
const maps = g.maps.filter(d => [...g.initHeap.values()].some(o => o.k === 'map' && o.decl === d));
|
|
4462
4960
|
const stores = Object.fromEntries([...new Set([...Object.keys(opts.stores ?? {}), ...g.storeDecls.keys()])].map(n => [n, { ...g.storeDecl(n), async: g.storeAsync[n] ?? {} }]));
|
|
4463
4961
|
for (const sm of g.storeMaps.values())
|
|
4464
|
-
leaves.push({ name: sm.decl.name, path: [], kind: 'map', key: sm.decl.key, store: sm.store, tpl: sm.tpl, ...(stores[sm.store]?.value !== 'int' ? { float: true } : {}) });
|
|
4962
|
+
leaves.push({ name: sm.decl.name, path: [], kind: 'map', key: sm.decl.key, store: sm.store, tpl: sm.tpl, ...(stores[sm.store]?.value !== 'int' && stores[sm.store]?.values?.[sm.tpl] !== 'int' && !sm.json && !sm.choice ? { float: true } : {}), ...(sm.json ? { json: sm.json } : {}), ...(sm.choice ? { choice: true } : {}) });
|
|
4465
4963
|
const layout = { k: 'rec', fields: state.filter(v => !outputs.includes(v.name)).map(v => [v.name, { k: 'scalar', name: v.name }]) };
|
|
4466
4964
|
for (const fn of chosen) {
|
|
4467
4965
|
const used = new Set();
|
|
@@ -4496,6 +4994,12 @@ function readOnce(mod, opts, g) {
|
|
|
4496
4994
|
if (g.vars.get(base)?.sort.k === 'num')
|
|
4497
4995
|
laws.push(`r.law(${JSON.stringify(`${base}: a None one holds 0`)}, ({${base}, ${l.name}}) => any(${l.name}.not(), ${base}.eq(0)))`);
|
|
4498
4996
|
}
|
|
4997
|
+
// (a stored JSON record's optional field: absent, its cell holds the default, as the text holds nothing there)
|
|
4998
|
+
for (const sm of g.storeMaps.values()) {
|
|
4999
|
+
const opts = (sm.json ?? []).filter(f => f.opt), n = sm.decl.name;
|
|
5000
|
+
if (opts.length)
|
|
5001
|
+
laws.push(`r.law(${JSON.stringify(`${n}: a field a record lacks holds the default`)}, ({${n}}) => forall(k => all(${opts.map(f => `any(${n}.at(k).${f.name}_has, ${n}.at(k).${f.name}${f.choice ? `.is(${JSON.stringify(f.vals[0])})` : '.eq(0)'})`).join(', ')})))`);
|
|
5002
|
+
}
|
|
4499
5003
|
if (g.now) {
|
|
4500
5004
|
const n = g.vars.get(g.now.name);
|
|
4501
5005
|
n.note = 'Date.now() (here time.time()): the time of the request, an input';
|
|
@@ -4509,9 +5013,11 @@ function readOnce(mod, opts, g) {
|
|
|
4509
5013
|
read.add(n); };
|
|
4510
5014
|
for (const t of [...Object.values(writes), ...Object.values(init)])
|
|
4511
5015
|
mention(t.e);
|
|
4512
|
-
for (const w of Object.values(mapWrites)) {
|
|
5016
|
+
for (const w of Object.values(mapWrites).flatMap(x => [x, ...(x.pre ?? [])])) {
|
|
4513
5017
|
mention(w.has);
|
|
4514
5018
|
mention(w.key);
|
|
5019
|
+
if (w.when)
|
|
5020
|
+
mention(w.when);
|
|
4515
5021
|
for (const t of Object.values(w.vals))
|
|
4516
5022
|
mention(t.e);
|
|
4517
5023
|
}
|
|
@@ -4590,6 +5096,12 @@ const defaultOf = (t, at) => {
|
|
|
4590
5096
|
const lvalues = (e) => (e.op === 'ite' ? lvalues(e.a) : e.values);
|
|
4591
5097
|
const zeroRaw = (s) => (s.k === 'num' ? 0 : s.k === 'bool' ? false : s.k === 'choice' ? s.values[0] : '');
|
|
4592
5098
|
const zeroOf = (s) => (s.k === 'num' ? { t: 'num', e: I.num(0) } : s.k === 'bool' ? { t: 'bool', e: I.F } : s.k === 'choice' ? { t: 'choice', e: I.llit(s.values[0], s.values) } : { t: 'str', e: { op: 'slit', value: '' } });
|
|
5099
|
+
// Lists of writes of one map made one length: the shorter ones led by writes that change nothing (a cell as it is,
|
|
5100
|
+
// at the key the longest list writes there), so place by place they merge as one write each.
|
|
5101
|
+
export function padWrites(lists, base) {
|
|
5102
|
+
const n = Math.max(0, ...lists.map(l => l.length)), long = lists.find(l => l.length === n) ?? [];
|
|
5103
|
+
return lists.map(l => [...long.slice(0, n - l.length).map(w => ({ key: w.key, ...base(w.key) })), ...l]);
|
|
5104
|
+
}
|
|
4593
5105
|
export function mapWritesOf(g, d, sels, ws, fix = (_, w) => w) {
|
|
4594
5106
|
if (!ws.some(Boolean))
|
|
4595
5107
|
return undefined;
|
|
@@ -4606,9 +5118,13 @@ export const rangeLaws = (state, ints) => state.flatMap(v => {
|
|
|
4606
5118
|
const ty = ints.get(v.name), law = (b) => [`r.law(${JSON.stringify(`${v.name} within its type's range`)}, ({${v.name}}) => ${v.name}.${b})`];
|
|
4607
5119
|
if (!ty || v.sort.k !== 'num')
|
|
4608
5120
|
return [];
|
|
5121
|
+
if (ty.mod)
|
|
5122
|
+
return [`r.law(${JSON.stringify(`${v.name} within its type's range`)}, ({${v.name}, ${ty.mod}}) => ${v.name}.lt(${ty.mod}))`];
|
|
4609
5123
|
const [lo, hi] = rangeOf(ty);
|
|
4610
5124
|
return Number.isFinite(hi) ? law(`atMost(${hi}).and(${v.name}.atLeast(${lo}))`) : lo === 0 ? law('atLeast(0)') : [];
|
|
4611
5125
|
});
|
|
5126
|
+
// Whether a term multiplies (by a variable, or by a constant other than 0 and ±1): past a width more than once.
|
|
5127
|
+
const hasProduct = (e) => e.op === 'mul' || (e.op === 'mulk' && Math.abs(e.k) > 1) || ((e.op === 'add' || e.op === 'sub' || e.op === 'min' || e.op === 'max' || e.op === 'ite') && (hasProduct(e.a) || hasProduct(e.b))) || ((e.op === 'neg' || e.op === 'mulk') && hasProduct(e.a));
|
|
4612
5128
|
export const varTerm = (v) => (v.sort.k === 'num' ? { s: 'num', e: I.nvar(v.name) } : v.sort.k === 'bool' ? { s: 'bool', e: I.bvar(v.name) } : v.sort.k === 'choice' ? { s: 'choice', e: { op: 'var', name: v.name, values: v.sort.values } } : { s: 'str', e: { op: 'svar', name: v.name } });
|
|
4613
5129
|
export function iteTerm(c, a, b) {
|
|
4614
5130
|
if (a.s === 'num' && b.s === 'num')
|
|
@@ -4676,7 +5192,7 @@ export function checkStep(h, read, r, sorts, opts) {
|
|
|
4676
5192
|
};
|
|
4677
5193
|
const j = (x) => (typeof x === 'number' ? String(x) : x);
|
|
4678
5194
|
const snapJson = (s) => ({ ...Object.fromEntries(Object.entries(s.leaves).map(([k, v]) => [k, j(v)])), ...Object.fromEntries(Object.entries(s.maps).map(([k, cells]) => [k, Object.fromEntries(Object.entries(cells).map(([key, c]) => [key, Object.fromEntries(Object.entries(c).map(([f, x]) => [f, j(x)]))]))])) });
|
|
4679
|
-
const build = (a, inputs) => (a.k === 'in' ? { in: inputs[a.name] ?? a.z ?? 0, ...(a.float ? { float: true } : {}), ...(a.sym ? { sym: true } : {}) } : a.k === 'opt' ? (inputs[a.none] === true ? { none: true } : build(a.v, inputs)) : a.k === 'rec' ? (a.f.length ? { rec: a.cls, f: Object.fromEntries(a.f.map(([f, x]) => [f, build(x, inputs)])) } : { inert: true }) : a.k === 'inert' ? { inert: true } : a.k === 'store' ? { store: a.name }
|
|
5195
|
+
const build = (a, inputs) => (a.k === 'in' ? { in: inputs[a.name] ?? a.z ?? 0, ...(a.float ? { float: true } : {}), ...(a.sym ? { sym: true } : {}) } : a.k === 'opt' ? (inputs[a.none] === true ? { none: true } : build(a.v, inputs)) : a.k === 'rec' ? (a.f.length ? { rec: a.cls, f: Object.fromEntries(a.f.map(([f, x]) => [f, build(x, inputs)])) } : { inert: true }) : a.k === 'inert' ? { inert: true, ...(a.dict ? { dict: true } : {}) } : a.k === 'store' ? { store: a.name }
|
|
4680
5196
|
: a.k === 'list' ? { list: (inputs[a.name] ?? []).map(it => build(a.item, it)) } : { dflt: true });
|
|
4681
5197
|
const ctorArgs = (params) => read.ctor.map(([n, a]) => [n, build(a, params)]);
|
|
4682
5198
|
let now = 0, inputsNow = {};
|
|
@@ -4759,6 +5275,11 @@ export function checkStep(h, read, r, sorts, opts) {
|
|
|
4759
5275
|
const key = d.key === 'str' ? strs[rand(3)] : String(rand(4));
|
|
4760
5276
|
cells[key] = Object.fromEntries(d.fields.map(f => { let x = draw(f.sort, sorts, `${d.name}.${f.name}`, rand, consts, bound, strs); if (typeof x === 'number' && sorts.get(`${d.name}.${f.name}`) === 'nat')
|
|
4761
5277
|
x = Math.abs(x); return [f.name, x]; }));
|
|
5278
|
+
// (a stored JSON record's absent optional field: its default, as the text holds nothing there)
|
|
5279
|
+
const jl = read.leaves.find(l => l.name === d.name)?.json;
|
|
5280
|
+
for (const f of jl ?? [])
|
|
5281
|
+
if (f.opt && cells[key][`${f.name}_has`] === false)
|
|
5282
|
+
cells[key][f.name] = f.choice ? f.vals[0] : 0;
|
|
4762
5283
|
}
|
|
4763
5284
|
maps[d.name] = cells;
|
|
4764
5285
|
}
|