gdp-wired 0.38.0 → 0.40.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/counts.d.ts +6 -0
- package/dist/core/counts.js +321 -100
- package/dist/core/cyclic.js +1 -1
- package/dist/core/dsl.js +64 -3
- package/dist/core/exists.d.ts +2 -1
- package/dist/core/exists.js +68 -4
- package/dist/core/extract-step.d.ts +42 -0
- package/dist/core/extract-step.js +509 -49
- package/dist/core/extract.js +7 -2
- package/dist/core/infer.d.ts +4 -0
- package/dist/core/infer.js +8 -2
- package/dist/core/py/harness.py +75 -12
- package/dist/core/py/reader.py +67 -11
- package/dist/kernel/prove.js +1 -1
- 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,7 +201,8 @@ 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.
|
|
@@ -239,8 +242,9 @@ export class Stepper {
|
|
|
239
242
|
sel = I.T;
|
|
240
243
|
// The clock: one input a step.
|
|
241
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)
|
|
242
246
|
if (p.called.includes('$now'))
|
|
243
|
-
|
|
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)`);
|
|
244
248
|
// (in the constructor, the time the object is made: a param)
|
|
245
249
|
if (this.init) {
|
|
246
250
|
this.madeAt ??= this.newVar('made_at', { k: 'num' }, 'param', 'Date.now() (here time.time()): the time the object is made');
|
|
@@ -321,11 +325,15 @@ export class Stepper {
|
|
|
321
325
|
raise(p, c, w, [t, i], k, at) {
|
|
322
326
|
if (this.cms.some(b => this.tries.indexOf(t) < b))
|
|
323
327
|
refuse(at, 'a raise through a context manager of other code (which may suppress it) to a handler around it');
|
|
324
|
-
|
|
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]);
|
|
325
331
|
t.ws.push(w);
|
|
326
332
|
}
|
|
333
|
+
// (each inlined frame's caller's locals at its call, outermost first)
|
|
334
|
+
frameLocals = [];
|
|
327
335
|
tryStmt(s, p) {
|
|
328
|
-
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);
|
|
329
337
|
this.tries.push(t);
|
|
330
338
|
let body;
|
|
331
339
|
try {
|
|
@@ -640,14 +648,17 @@ export class Stepper {
|
|
|
640
648
|
}
|
|
641
649
|
}
|
|
642
650
|
}
|
|
651
|
+
// (an object one path has not touched yet, a store's map made where first used: as it starts, on that path)
|
|
643
652
|
const heap = new Map();
|
|
644
653
|
for (const [id, x] of a.heap) {
|
|
645
|
-
const y = b.heap.get(id);
|
|
654
|
+
const y = b.heap.get(id) ?? this.initHeap.get(id);
|
|
646
655
|
heap.set(id, y ? this.mergeObj(c, x, y, at) : x);
|
|
647
656
|
}
|
|
648
657
|
for (const [id, y] of b.heap)
|
|
649
|
-
if (!heap.has(id))
|
|
650
|
-
|
|
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
|
+
}
|
|
651
662
|
return { pc, locals, heap, called: [...new Set([...a.called, ...b.called])], locks: a.locks, defers: [...new Set([...a.defers, ...b.defers])] };
|
|
652
663
|
}
|
|
653
664
|
mergeObj(c, a, b, at) {
|
|
@@ -727,6 +738,18 @@ export class Stepper {
|
|
|
727
738
|
}
|
|
728
739
|
if (a.t === 'tuple' && b.t === 'tuple' && a.xs.length === b.xs.length)
|
|
729
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
|
+
}
|
|
730
753
|
// (a list the request carries on one path, another value on another: kept only where nothing reads it)
|
|
731
754
|
if ([a, b].some(x => x.t === 'ref' && this.seqs.some(d => x.id === `in:${d.name}`)))
|
|
732
755
|
return { t: 'opaque', why: 'a list the request carries on one path, another value on another' };
|
|
@@ -787,6 +810,8 @@ export class Stepper {
|
|
|
787
810
|
case 'choice': return lvalues(v.e).includes('') ? I.not(I.is(v.e, '')) : I.T;
|
|
788
811
|
case 'none': return I.F;
|
|
789
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)}`);
|
|
790
815
|
case 'ref': {
|
|
791
816
|
// (a list the request carries: whether it has an item)
|
|
792
817
|
const cl = p && this.listOf(v, p, at, true);
|
|
@@ -908,6 +933,7 @@ export class Stepper {
|
|
|
908
933
|
}
|
|
909
934
|
const saved = q.locals;
|
|
910
935
|
this.frames.push(f.id);
|
|
936
|
+
this.frameLocals.push(saved);
|
|
911
937
|
let flow;
|
|
912
938
|
try {
|
|
913
939
|
flow = this.block(f.body, { ...q, locals });
|
|
@@ -919,6 +945,7 @@ export class Stepper {
|
|
|
919
945
|
}
|
|
920
946
|
finally {
|
|
921
947
|
this.frames.pop();
|
|
948
|
+
this.frameLocals.pop();
|
|
922
949
|
}
|
|
923
950
|
const rets = [...flow.rets, ...(flow.live ? [[flow.live, { t: 'none' }]] : [])];
|
|
924
951
|
if (!rets.length)
|
|
@@ -944,6 +971,11 @@ export class Stepper {
|
|
|
944
971
|
for (const s of ss) {
|
|
945
972
|
if (!live)
|
|
946
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
|
+
}
|
|
947
979
|
if (s.s === 'fallthrough') {
|
|
948
980
|
ft = live;
|
|
949
981
|
live = undefined;
|
|
@@ -978,14 +1010,16 @@ export class Stepper {
|
|
|
978
1010
|
return { live: this.assign(s.to, r[0], s, r[1], s.t), rets: [] };
|
|
979
1011
|
}
|
|
980
1012
|
case 'if': {
|
|
981
|
-
const
|
|
982
|
-
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));
|
|
983
1017
|
if (!(c.op === 'const' && !c.v))
|
|
984
1018
|
this.arm(s.then);
|
|
985
1019
|
if (!(c.op === 'const' && c.v))
|
|
986
1020
|
this.arm(s.else);
|
|
987
|
-
const t = c.op === 'const' && !c.v ? undefined : this.block(s.then, this.assume(
|
|
988
|
-
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)));
|
|
989
1023
|
const lives = [t?.live, e?.live].filter((x) => !!x);
|
|
990
1024
|
const live = this.join(lives, s), brk = [...(t?.brk ?? []), ...(e?.brk ?? [])];
|
|
991
1025
|
return { ...(live ? { live } : {}), rets: [...(t?.rets ?? []), ...(e?.rets ?? [])], ...(brk.length ? { brk } : {}) };
|
|
@@ -1036,7 +1070,29 @@ export class Stepper {
|
|
|
1036
1070
|
return { rets: [] };
|
|
1037
1071
|
}
|
|
1038
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
|
+
}
|
|
1039
1092
|
case 'with': {
|
|
1093
|
+
const cm = this.generatorCM(s, p);
|
|
1094
|
+
if (cm)
|
|
1095
|
+
return cm;
|
|
1040
1096
|
// (a context manager of other code, taken as transparent: a raise inside it may be suppressed by it, so none
|
|
1041
1097
|
// goes through it to a handler around it)
|
|
1042
1098
|
let q = p, other = false;
|
|
@@ -1152,6 +1208,15 @@ export class Stepper {
|
|
|
1152
1208
|
}
|
|
1153
1209
|
case 'idx': {
|
|
1154
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
|
+
}
|
|
1155
1220
|
return this.mapSet(m, this.keyOf(k, to.i), v, to, q2);
|
|
1156
1221
|
}
|
|
1157
1222
|
}
|
|
@@ -1184,7 +1249,7 @@ export class Stepper {
|
|
|
1184
1249
|
if (old?.t === 'opaque' && obj.origin === 'state' && !this.init)
|
|
1185
1250
|
return refuse(at, `${at.text}: writes ${old.why}`);
|
|
1186
1251
|
if (o.id === 'this' && this.frozen.has(f) && !this.init)
|
|
1187
|
-
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)`);
|
|
1188
1253
|
if (this.init && t)
|
|
1189
1254
|
this.declared.set(`${o.id}.${f}`, t);
|
|
1190
1255
|
// (a literal written to a field of a choice is the choice's)
|
|
@@ -1202,6 +1267,15 @@ export class Stepper {
|
|
|
1202
1267
|
refuse(at, `${JSON.stringify(v.e.value)} is not one of ${f.name}'s literals`);
|
|
1203
1268
|
return { t: 'choice', e: I.llit(v.e.value, f.sort.values) };
|
|
1204
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
|
+
}
|
|
1205
1279
|
if (f.sort.k === 'choice' && v.t !== 'choice')
|
|
1206
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`);
|
|
1207
1281
|
if (f.sort.k === 'num' && v.t !== 'num')
|
|
@@ -1500,15 +1574,41 @@ export class Stepper {
|
|
|
1500
1574
|
const key = `${store}\u0000${tpl}`;
|
|
1501
1575
|
let sm = this.storeMaps.get(key);
|
|
1502
1576
|
if (!sm) {
|
|
1503
|
-
for (const other of [...this.storeMaps.values()].filter(x => x.store === store))
|
|
1504
|
-
if (!disjoint(other.tpl, tpl))
|
|
1505
|
-
refuse(at, `${store}: the key templates ${JSON.stringify(other.tpl)} and ${JSON.stringify(tpl)} may name one key`);
|
|
1506
1577
|
const decl = this.storeDecl(store);
|
|
1507
|
-
|
|
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' };
|
|
1508
1586
|
const name = `${store}_${tpl.replace(/\{\}/g, '').replace(/[^A-Za-z0-9]+/g, '_').replace(/^_|_$/g, '')}`;
|
|
1509
|
-
|
|
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);
|
|
1510
1610
|
const id = `store:${key}`;
|
|
1511
|
-
sm = { store, tpl, id, decl: d };
|
|
1611
|
+
sm = { store, tpl, id, decl: d, ...(json ? { json } : {}), ...(Array.isArray(sv) ? { choice: true } : {}) };
|
|
1512
1612
|
this.storeMaps.set(key, sm);
|
|
1513
1613
|
this.initHeap.set(id, { k: 'map', decl: d, val, origin: 'state' });
|
|
1514
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`);
|
|
@@ -1535,12 +1635,13 @@ export class Stepper {
|
|
|
1535
1635
|
// (the injected dependencies and stores: their type, whether the rule holds keys of theirs, whether the caller stated them)
|
|
1536
1636
|
deps = [];
|
|
1537
1637
|
// A constructor argument held as an injected dependency (a store): one its reader marks so, or one of no scalar type
|
|
1538
|
-
// (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).
|
|
1539
1640
|
injected(pa, init, r) {
|
|
1540
1641
|
if (!this.inf)
|
|
1541
1642
|
return undefined;
|
|
1542
1643
|
const t = pa.t.k === 'opt' ? pa.t.of : pa.t;
|
|
1543
|
-
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'))))
|
|
1544
1645
|
return undefined;
|
|
1545
1646
|
const fields = [];
|
|
1546
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)
|
|
@@ -1574,16 +1675,18 @@ export class Stepper {
|
|
|
1574
1675
|
return d;
|
|
1575
1676
|
}
|
|
1576
1677
|
storeCall(store, m, args, kw, at, p, awaited) {
|
|
1678
|
+
if (dead(p))
|
|
1679
|
+
return [{ t: 'opaque', why: 'unreachable' }, p];
|
|
1577
1680
|
const d = this.storeDecl(store), all = [...args, ...kw.map(([, v]) => v)];
|
|
1578
1681
|
// (other code given the rule's state may change it: refused unless the caller states it, the tag on its line)
|
|
1579
1682
|
const given = (vs) => { if (!this.tagAt(at.p) && vs.some(v => this.stateRef(v, p)))
|
|
1580
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)`); };
|
|
1581
|
-
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`);
|
|
1582
1685
|
const has = (n, i) => kw.some(([k]) => k === n) || args.length > i;
|
|
1583
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;
|
|
1584
1687
|
if (!kind && this.inf) {
|
|
1585
1688
|
// (inferred: a method named as a key's get, set or delete, given a key that is a string or a format)
|
|
1586
|
-
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];
|
|
1587
1690
|
if (k && key && (key.t === 'str' || key.t === 'fmt') && (k !== 'set' || has('value', 1))) {
|
|
1588
1691
|
kind = k;
|
|
1589
1692
|
(d[k] ??= []).push(m);
|
|
@@ -1615,22 +1718,222 @@ export class Stepper {
|
|
|
1615
1718
|
this.storeAsync[store][m] = awaited;
|
|
1616
1719
|
// (a key's operation takes its key, and a set its value: any other argument given the rule's state is refused)
|
|
1617
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
|
+
}
|
|
1618
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' : ''}`);
|
|
1619
1747
|
const { tpl, k, kn } = this.storeKey(keyV, at);
|
|
1620
|
-
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);
|
|
1621
1749
|
// (inside a try that may catch it: the store's operation may raise, as other code's may, before it acts)
|
|
1622
|
-
if (this.tries.length)
|
|
1750
|
+
if (this.tries.length && !d.nothrow)
|
|
1623
1751
|
p = this.passing(`${store}.${m}`, `${store}.${m}`, { store, path: [m] }, at, p, awaited);
|
|
1624
|
-
if (kind === 'get')
|
|
1625
|
-
|
|
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
|
+
}
|
|
1626
1766
|
if (kind === 'delete')
|
|
1627
1767
|
return [{ t: 'none' }, this.mapDel({ t: 'ref', id }, k, at, p, false)];
|
|
1628
1768
|
const v = arg('value', 1);
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
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('$', '')}`);
|
|
1634
1937
|
}
|
|
1635
1938
|
// --- the boundary the caller states ---------------------------------------------------------------------------------
|
|
1636
1939
|
calleeNames(x) {
|
|
@@ -1693,10 +1996,16 @@ export class Stepper {
|
|
|
1693
1996
|
}
|
|
1694
1997
|
// A call left out inside a try (its value unread): stubbed only to raise where the request says, else run as it is.
|
|
1695
1998
|
passing(key, name, patch, at, p, awaited) {
|
|
1696
|
-
if (this.hidden)
|
|
1697
|
-
return refuse(at, `${at.text ?? name}: other code called in a loop inside a try (whether it raises would be one input a pass)`);
|
|
1698
1999
|
if (!this.tries.length)
|
|
1699
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)`);
|
|
1700
2009
|
if (!patch && !at.end)
|
|
1701
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`);
|
|
1702
2011
|
let a = this.answers.get(key);
|
|
@@ -1704,9 +2013,11 @@ export class Stepper {
|
|
|
1704
2013
|
this.answers.set(key, a = { key, patch: patch ?? {}, async: awaited, inputs: { name: '' }, sort: '', pass: true, at: [] });
|
|
1705
2014
|
if (!a.pass)
|
|
1706
2015
|
return refuse(at, `${at.text ?? name}: ${key} answered at one call and left out at another`);
|
|
1707
|
-
|
|
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))
|
|
1708
2019
|
a.at.push({ p: at.p, ...(at.end ? { end: at.end } : {}), ...(at.span ? { span: at.span } : {}) });
|
|
1709
|
-
return
|
|
2020
|
+
return q;
|
|
1710
2021
|
}
|
|
1711
2022
|
// --- the boundary inferred ---------------------------------------------------------------------------------------
|
|
1712
2023
|
// A call of code the subset doesn't read (another module's, an injected dependency's, or the module's own function
|
|
@@ -2027,6 +2338,12 @@ export class Stepper {
|
|
|
2027
2338
|
case 'none': return [{ t: 'none' }, p];
|
|
2028
2339
|
case 'var': {
|
|
2029
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
|
+
}
|
|
2030
2347
|
if (!v)
|
|
2031
2348
|
return refuse(x, x.why ?? `${String(x.n)}: a variable read before it is set`);
|
|
2032
2349
|
return [this.narrow(v, p), p];
|
|
@@ -2035,7 +2352,7 @@ export class Stepper {
|
|
|
2035
2352
|
case 'cls': return [{ t: 'cls', rec: String(x.rec), ...(x.patch ? { patch: x.patch } : {}) }, p];
|
|
2036
2353
|
case 'builtin': return [{ t: 'builtin', n: String(x.n) }, p];
|
|
2037
2354
|
case 'lib': return [{ t: 'lib', q: String(x.q) }, p];
|
|
2038
|
-
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];
|
|
2039
2356
|
case 'no': {
|
|
2040
2357
|
// (a call of other code a reader doesn't lower, `ext` its name: at the boundary, where it is inferred)
|
|
2041
2358
|
if (x.ext && !x.pre && !x.prepl) {
|
|
@@ -2245,6 +2562,8 @@ export class Stepper {
|
|
|
2245
2562
|
const [m, q] = this.ev(x.x, p), [k, q2] = this.ev(x.i, q);
|
|
2246
2563
|
if (m.t === 'opaque')
|
|
2247
2564
|
return [m, q2];
|
|
2565
|
+
if (m.t === 'val')
|
|
2566
|
+
return this.valItem(m, k, x, q2);
|
|
2248
2567
|
const ord = this.orderedObj(m, q2);
|
|
2249
2568
|
if (ord) {
|
|
2250
2569
|
const i = constOf(k);
|
|
@@ -2297,9 +2616,20 @@ export class Stepper {
|
|
|
2297
2616
|
}
|
|
2298
2617
|
case 'fstr': return this.fstr(x, p);
|
|
2299
2618
|
case 'dict': {
|
|
2300
|
-
if (x.keys.length)
|
|
2301
|
-
return
|
|
2302
|
-
|
|
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];
|
|
2303
2633
|
}
|
|
2304
2634
|
// (an empty list: an ordered collection where a field of the state declares a list of records or numbers)
|
|
2305
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];
|
|
@@ -2399,7 +2729,7 @@ export class Stepper {
|
|
|
2399
2729
|
if (o.sattr)
|
|
2400
2730
|
return this.storeAttr(o.sattr.store, `${o.sattr.path}.${f}`, x, q);
|
|
2401
2731
|
return [{ t: 'opaque', why: o.why, ...(o.ask ? { ask: o.ask } : {}) }, q];
|
|
2402
|
-
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];
|
|
2403
2733
|
case 'none':
|
|
2404
2734
|
this.fail(q, I.T, x, `${x.text}: a field of None (an AttributeError)`);
|
|
2405
2735
|
return [{ t: 'opaque', why: 'unreachable' }, { ...q, pc: [...q.pc, I.F] }];
|
|
@@ -2438,7 +2768,8 @@ export class Stepper {
|
|
|
2438
2768
|
case 'map':
|
|
2439
2769
|
case 'list':
|
|
2440
2770
|
case 'push':
|
|
2441
|
-
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}`);
|
|
2442
2773
|
}
|
|
2443
2774
|
if (o.t === 'sattr')
|
|
2444
2775
|
return this.storeAttr(o.store, o.path ? `${o.path}.${f}` : f, x, q);
|
|
@@ -2448,6 +2779,9 @@ export class Stepper {
|
|
|
2448
2779
|
if (obj?.k !== 'rec')
|
|
2449
2780
|
return refuse(x, `${x.text}: a field of other than an object`);
|
|
2450
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];
|
|
2451
2785
|
const v = obj.f.get(f);
|
|
2452
2786
|
if (v)
|
|
2453
2787
|
return [v, q];
|
|
@@ -2497,6 +2831,8 @@ export class Stepper {
|
|
|
2497
2831
|
if (x.ovf)
|
|
2498
2832
|
return this.fixed(x, p);
|
|
2499
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];
|
|
2500
2836
|
// A true division: a float, kept only where nothing the rule keeps reads it (refused there); its divisor 0 fails.
|
|
2501
2837
|
if (op === '/') {
|
|
2502
2838
|
if (b.t === 'num' || b.t === 'bool') {
|
|
@@ -2683,6 +3019,34 @@ export class Stepper {
|
|
|
2683
3019
|
return I.F;
|
|
2684
3020
|
return refuse(at, `${at.text}: ${a.t} == ${b.t}`);
|
|
2685
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
|
+
}
|
|
2686
3050
|
// and / or: Python's give one of their operands (the first falsy, or the last; the first truthy, or the last).
|
|
2687
3051
|
boolOp(x, p) {
|
|
2688
3052
|
const xs = x.xs, isAnd = x.e === 'and';
|
|
@@ -2732,6 +3096,8 @@ export class Stepper {
|
|
|
2732
3096
|
return [{ t: 'fmt', tpl, k: hole }, q];
|
|
2733
3097
|
}
|
|
2734
3098
|
call(x, p, awaited) {
|
|
3099
|
+
if (dead(p))
|
|
3100
|
+
return [{ t: 'opaque', why: 'unreachable' }, p];
|
|
2735
3101
|
const fx = x.f, names = this.calleeNames(x), args0 = x.args, kw0 = x.kw;
|
|
2736
3102
|
// The boundary first: an answered call, then a skipped one (neither's arguments read).
|
|
2737
3103
|
const ans = this.match(Object.keys(this.opts.answers ?? {}), names), skip = !ans && this.skipped(names);
|
|
@@ -2770,6 +3136,8 @@ export class Stepper {
|
|
|
2770
3136
|
if (fx.e === 'get') {
|
|
2771
3137
|
const [o, q1] = this.ev(fx.x, q);
|
|
2772
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));
|
|
2773
3141
|
const ord = this.orderedObj(o, q);
|
|
2774
3142
|
if (ord)
|
|
2775
3143
|
return this.listCall(ord[0], ord[1], String(fx.f), x, q);
|
|
@@ -2806,13 +3174,15 @@ export class Stepper {
|
|
|
2806
3174
|
case 'cls': {
|
|
2807
3175
|
// (another module's class made: other code, at the boundary)
|
|
2808
3176
|
const r = this.inf ? this.mod.recs[f.rec] : undefined;
|
|
2809
|
-
if (r && !r.own)
|
|
3177
|
+
if (r && !r.own && !madeByInit(r))
|
|
2810
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);
|
|
2811
3179
|
return this.evArgs(x, q, (args, kw, q2) => this.construct(f.rec, args, kw, x, q2));
|
|
2812
3180
|
}
|
|
2813
3181
|
case 'builtin': return this.builtin(f.n, x, q);
|
|
2814
3182
|
case 'lib': return this.lib(f.q, x, q);
|
|
2815
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));
|
|
2816
3186
|
const refusal = `${x.text}: ${f.q}, other code (answer it, skip it, or read that module)`;
|
|
2817
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);
|
|
2818
3188
|
}
|
|
@@ -2837,7 +3207,8 @@ export class Stepper {
|
|
|
2837
3207
|
case 'map':
|
|
2838
3208
|
case 'list':
|
|
2839
3209
|
case 'push':
|
|
2840
|
-
case 'pop':
|
|
3210
|
+
case 'pop':
|
|
3211
|
+
case 'val': break;
|
|
2841
3212
|
}
|
|
2842
3213
|
void args0;
|
|
2843
3214
|
void kw0;
|
|
@@ -2895,6 +3266,12 @@ export class Stepper {
|
|
|
2895
3266
|
}
|
|
2896
3267
|
construct(rec, args, kw, x, p) {
|
|
2897
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
|
+
}
|
|
2898
3275
|
if (!r.kinds.includes('dataclass') || !r.own)
|
|
2899
3276
|
return refuse(x, `${x.text}: ${r.short} made (the subset makes the module's own dataclasses)`);
|
|
2900
3277
|
if (r.methods.__init__ || r.methods.__post_init__)
|
|
@@ -2930,9 +3307,16 @@ export class Stepper {
|
|
|
2930
3307
|
return this.quotient(a0, p, 'trunc');
|
|
2931
3308
|
if (n === 'round' && a0?.e === 'bin' && a0.op === '/' && x.args.length === 1 && !x.kw.length)
|
|
2932
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
|
+
}
|
|
2933
3314
|
return this.evArgs(x, p, (args, kw, q) => {
|
|
2934
3315
|
if (kw.length)
|
|
2935
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)}`);
|
|
2936
3320
|
if (args.some(a => a.t === 'opaque') && ['str', 'repr', 'len', 'isinstance', 'round', 'int', 'float', 'bool'].includes(n)) {
|
|
2937
3321
|
const ask = args.find(a => a.t === 'opaque' && a.ask);
|
|
2938
3322
|
return [{ t: 'opaque', why: `${x.text}: of a value outside the subset${ask ? ` (${ask.why})` : ''}`, ...(ask ? { ask: ask.ask } : {}) }, q];
|
|
@@ -3006,6 +3390,28 @@ export class Stepper {
|
|
|
3006
3390
|
}
|
|
3007
3391
|
if (q0 === 'threading.Lock' || q0 === 'threading.RLock' || q0 === 'asyncio.Lock')
|
|
3008
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
|
+
});
|
|
3009
3415
|
return this.evArgs(x, p, (args, _kw, q) => {
|
|
3010
3416
|
const v = args[0];
|
|
3011
3417
|
if (v?.t === 'opaque')
|
|
@@ -3893,6 +4299,13 @@ const assigned = (ss) => {
|
|
|
3893
4299
|
// A pointer by a condition (one case where both are the same).
|
|
3894
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 });
|
|
3895
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'));
|
|
3896
4309
|
const firm = (v) => ['ptr', 'struct', 'err', 'nil', 'map', 'list', 'push', 'pop'].includes(v.t) || (v.t === 'opaque' && !!v.firm);
|
|
3897
4310
|
// An expression that calls nothing (so evaluating it changes nothing).
|
|
3898
4311
|
// Whether some node of an IR tree (an object, depth first) is one f says yes to.
|
|
@@ -4122,6 +4535,8 @@ function readOnce(mod, opts, g) {
|
|
|
4122
4535
|
g.storeTypes.set(pa.name, dep.ty);
|
|
4123
4536
|
if (dep)
|
|
4124
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)`);
|
|
4125
4540
|
continue;
|
|
4126
4541
|
}
|
|
4127
4542
|
if (pa.dflt && !g.scalar(pa.t.k === 'opt' ? pa.t.of : pa.t)) {
|
|
@@ -4131,6 +4546,15 @@ function readOnce(mod, opts, g) {
|
|
|
4131
4546
|
p = p2;
|
|
4132
4547
|
continue;
|
|
4133
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
|
+
}
|
|
4134
4558
|
const [v, a] = g.input(pa.name, pa.t, fn, p, 'param');
|
|
4135
4559
|
if (a.k === 'inert')
|
|
4136
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)`);
|
|
@@ -4196,6 +4620,14 @@ function readOnce(mod, opts, g) {
|
|
|
4196
4620
|
if (g.deps.length > 1)
|
|
4197
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)`);
|
|
4198
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
|
+
}
|
|
4199
4631
|
for (const [f, v] of self.f) {
|
|
4200
4632
|
const t = g.declared.get(`this.${f}`) ?? r.fields.find(x => x.name === f)?.t;
|
|
4201
4633
|
tree.push({ path: [f], v, ...(t && t.k !== 'any' ? { t } : {}) });
|
|
@@ -4211,9 +4643,17 @@ function readOnce(mod, opts, g) {
|
|
|
4211
4643
|
const scalarT = decl && decl.k !== 'opt' ? decl : undefined;
|
|
4212
4644
|
const leaf = (kind, vr, float) => { leaves.push({ name: vr.name, path, kind, ...(float ? { float: true } : {}) }); return vr; };
|
|
4213
4645
|
const isFloat = (decl?.k === 'float') || (decl?.k === 'opt' && decl.of.k === 'float');
|
|
4214
|
-
if (
|
|
4215
|
-
|
|
4216
|
-
|
|
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`);
|
|
4217
4657
|
if (v.t === 'str' && sort.k === 'choice' && v.e.op === 'slit')
|
|
4218
4658
|
v = { t: 'choice', e: I.llit(v.e.value, sort.values) };
|
|
4219
4659
|
const optional = v.t === 'none' || v.t === 'opt' || decl?.k === 'opt';
|
|
@@ -4276,6 +4716,13 @@ function readOnce(mod, opts, g) {
|
|
|
4276
4716
|
into.set(f, v);
|
|
4277
4717
|
return;
|
|
4278
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
|
+
}
|
|
4279
4726
|
// A field the constructor sets to None, of no declared type: a constant (a method setting it is refused).
|
|
4280
4727
|
if (v.t === 'none') {
|
|
4281
4728
|
into.set(f, v);
|
|
@@ -4333,7 +4780,9 @@ function readOnce(mod, opts, g) {
|
|
|
4333
4780
|
q = g.assume(q, out.ok);
|
|
4334
4781
|
out = out.v;
|
|
4335
4782
|
}
|
|
4336
|
-
|
|
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;
|
|
4337
4786
|
finals.push({ sel, path: p, out, fails: g.fails });
|
|
4338
4787
|
argsOf[fn.name] = pargs;
|
|
4339
4788
|
}
|
|
@@ -4510,7 +4959,7 @@ function readOnce(mod, opts, g) {
|
|
|
4510
4959
|
const maps = g.maps.filter(d => [...g.initHeap.values()].some(o => o.k === 'map' && o.decl === d));
|
|
4511
4960
|
const stores = Object.fromEntries([...new Set([...Object.keys(opts.stores ?? {}), ...g.storeDecls.keys()])].map(n => [n, { ...g.storeDecl(n), async: g.storeAsync[n] ?? {} }]));
|
|
4512
4961
|
for (const sm of g.storeMaps.values())
|
|
4513
|
-
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 } : {}) });
|
|
4514
4963
|
const layout = { k: 'rec', fields: state.filter(v => !outputs.includes(v.name)).map(v => [v.name, { k: 'scalar', name: v.name }]) };
|
|
4515
4964
|
for (const fn of chosen) {
|
|
4516
4965
|
const used = new Set();
|
|
@@ -4545,6 +4994,12 @@ function readOnce(mod, opts, g) {
|
|
|
4545
4994
|
if (g.vars.get(base)?.sort.k === 'num')
|
|
4546
4995
|
laws.push(`r.law(${JSON.stringify(`${base}: a None one holds 0`)}, ({${base}, ${l.name}}) => any(${l.name}.not(), ${base}.eq(0)))`);
|
|
4547
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
|
+
}
|
|
4548
5003
|
if (g.now) {
|
|
4549
5004
|
const n = g.vars.get(g.now.name);
|
|
4550
5005
|
n.note = 'Date.now() (here time.time()): the time of the request, an input';
|
|
@@ -4737,7 +5192,7 @@ export function checkStep(h, read, r, sorts, opts) {
|
|
|
4737
5192
|
};
|
|
4738
5193
|
const j = (x) => (typeof x === 'number' ? String(x) : x);
|
|
4739
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)]))]))])) });
|
|
4740
|
-
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 }
|
|
4741
5196
|
: a.k === 'list' ? { list: (inputs[a.name] ?? []).map(it => build(a.item, it)) } : { dflt: true });
|
|
4742
5197
|
const ctorArgs = (params) => read.ctor.map(([n, a]) => [n, build(a, params)]);
|
|
4743
5198
|
let now = 0, inputsNow = {};
|
|
@@ -4820,6 +5275,11 @@ export function checkStep(h, read, r, sorts, opts) {
|
|
|
4820
5275
|
const key = d.key === 'str' ? strs[rand(3)] : String(rand(4));
|
|
4821
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')
|
|
4822
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;
|
|
4823
5283
|
}
|
|
4824
5284
|
maps[d.name] = cells;
|
|
4825
5285
|
}
|