gdp-wired 0.45.0 → 0.46.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.
Files changed (120) hide show
  1. package/README.md +58 -7
  2. package/dist/core/bitsets.d.ts +2 -0
  3. package/dist/core/bitsets.js +23 -0
  4. package/dist/core/bmc.js +6 -2
  5. package/dist/core/c/reader.d.ts +9 -1
  6. package/dist/core/c/reader.js +423 -31
  7. package/dist/core/calendar.d.ts +29 -0
  8. package/dist/core/calendar.js +82 -0
  9. package/dist/core/cli.d.ts +3 -0
  10. package/dist/core/cli.js +204 -38
  11. package/dist/core/compose.js +3 -1
  12. package/dist/core/counts.d.ts +4 -1
  13. package/dist/core/counts.js +314 -85
  14. package/dist/core/cycles.js +8 -1
  15. package/dist/core/cyclic.d.ts +1 -0
  16. package/dist/core/cyclic.js +13 -7
  17. package/dist/core/data-synth.d.ts +3 -0
  18. package/dist/core/data-synth.js +252 -0
  19. package/dist/core/data.d.ts +2 -1
  20. package/dist/core/data.js +223 -24
  21. package/dist/core/discover.js +3 -1
  22. package/dist/core/draft.d.ts +19 -0
  23. package/dist/core/draft.js +53 -0
  24. package/dist/core/dsl.d.ts +37 -3
  25. package/dist/core/dsl.js +167 -26
  26. package/dist/core/effect.d.ts +1 -4
  27. package/dist/core/effect.js +1 -15
  28. package/dist/core/exists.d.ts +1 -0
  29. package/dist/core/exists.js +191 -16
  30. package/dist/core/extract-c.d.ts +2 -0
  31. package/dist/core/extract-c.js +169 -22
  32. package/dist/core/extract-check.d.ts +1 -0
  33. package/dist/core/extract-check.js +66 -0
  34. package/dist/core/extract-go-check.d.ts +1 -1
  35. package/dist/core/extract-go-check.js +2 -1
  36. package/dist/core/extract-go.d.ts +1 -0
  37. package/dist/core/extract-go.js +38 -4
  38. package/dist/core/extract-ir.d.ts +1 -0
  39. package/dist/core/extract-ir.js +15 -0
  40. package/dist/core/extract-jvm.d.ts +1 -1
  41. package/dist/core/extract-jvm.js +2 -0
  42. package/dist/core/extract-orm.d.ts +12 -0
  43. package/dist/core/extract-orm.js +244 -0
  44. package/dist/core/extract-print.js +20 -1
  45. package/dist/core/extract-py.d.ts +1 -0
  46. package/dist/core/extract-py.js +1 -1
  47. package/dist/core/extract-read.d.ts +17 -0
  48. package/dist/core/extract-read.js +5 -5
  49. package/dist/core/extract-rs.js +5 -1
  50. package/dist/core/extract-shapes.js +2 -0
  51. package/dist/core/extract-sol.d.ts +10 -1
  52. package/dist/core/extract-sol.js +70 -22
  53. package/dist/core/extract-step.d.ts +151 -1
  54. package/dist/core/extract-step.js +1232 -60
  55. package/dist/core/extract-swift.js +6 -2
  56. package/dist/core/extract.d.ts +8 -0
  57. package/dist/core/extract.js +61 -5
  58. package/dist/core/fiber-run.d.ts +5 -0
  59. package/dist/core/fiber-run.js +18 -0
  60. package/dist/core/infer.d.ts +4 -1
  61. package/dist/core/infer.js +918 -217
  62. package/dist/core/jvm/JavaReader.java +23 -6
  63. package/dist/core/jvm/Jvm.java +3 -0
  64. package/dist/core/jvm/KtReader.java +6 -5
  65. package/dist/core/laws.d.ts +10 -3
  66. package/dist/core/laws.js +193 -14
  67. package/dist/core/machine.d.ts +15 -1
  68. package/dist/core/machine.js +187 -15
  69. package/dist/core/nonterm.js +14 -1
  70. package/dist/core/orm/harness.js +61 -0
  71. package/dist/core/orm-fixtures/schema.prisma +5 -0
  72. package/dist/core/py/harness.py +183 -10
  73. package/dist/core/py/reader.py +234 -40
  74. package/dist/core/reader-fixtures/README.md +28 -0
  75. package/dist/core/reader-fixtures/c-693042.cpp +8 -0
  76. package/dist/core/reader-fixtures/go-685506.go +14 -0
  77. package/dist/core/reader-fixtures/jvm-724362.kt +8 -0
  78. package/dist/core/reader-fixtures/jvm-737430.kt +7 -0
  79. package/dist/core/reader-fixtures/jvm-765282.kt +3 -0
  80. package/dist/core/reader-fixtures/swift-735726.swift +15 -0
  81. package/dist/core/reader-fixtures/swift-735990.swift +15 -0
  82. package/dist/core/reader-fixtures/swift-739158.swift +4 -0
  83. package/dist/core/reader-fixtures/swift-744834.swift +15 -0
  84. package/dist/core/reader-fixtures/swift-746946.swift +31 -0
  85. package/dist/core/reader-fixtures/typescript-673062.ts.txt +2 -0
  86. package/dist/core/relation.d.ts +1 -1
  87. package/dist/core/relation.js +29 -2
  88. package/dist/core/relational.js +4 -2
  89. package/dist/core/rs/src/main.rs +8 -2
  90. package/dist/core/sample-cache.d.ts +8 -0
  91. package/dist/core/sample-cache.js +46 -0
  92. package/dist/core/security.d.ts +38 -0
  93. package/dist/core/security.js +88 -0
  94. package/dist/core/sol/harness.py +57 -4
  95. package/dist/core/sol-concrete.d.ts +23 -0
  96. package/dist/core/sol-concrete.js +195 -0
  97. package/dist/core/solver.js +3 -1
  98. package/dist/core/swift/Sources/gdp-swiftreader/main.swift +50 -7
  99. package/dist/core/system.js +1 -1
  100. package/dist/core/transfer.js +22 -9
  101. package/dist/core/translate.js +39 -10
  102. package/dist/core/watch.js +50 -5
  103. package/dist/interchange/format.js +11 -1
  104. package/dist/kernel/cdcl.d.ts +5 -0
  105. package/dist/kernel/cdcl.js +56 -9
  106. package/dist/kernel/epr.js +108 -26
  107. package/dist/kernel/kernel.d.ts +29 -1
  108. package/dist/kernel/kernel.js +325 -62
  109. package/dist/kernel/model-sequence.d.ts +3 -0
  110. package/dist/kernel/model-sequence.js +34 -0
  111. package/dist/kernel/prove.d.ts +10 -3
  112. package/dist/kernel/prove.js +332 -71
  113. package/dist/kernel/reader.d.ts +3 -0
  114. package/dist/kernel/reader.js +101 -14
  115. package/dist/kernel/share.d.ts +1 -0
  116. package/dist/kernel/share.js +27 -0
  117. package/dist/lean-kernel/emit.js +30 -37
  118. package/dist/lean-kernel/lean-terms.js +5 -0
  119. package/dist/lean-kernel/library.js +10 -10
  120. package/package.json +6 -1
@@ -27,7 +27,9 @@ import { fromModel } from "./extract.js";
27
27
  import { evalC, interpret, seeded } from "./machine.js";
28
28
  import { allowed, watch } from "./watch.js";
29
29
  import { kindOfVar } from "./extract-check.js";
30
+ import { substN } from "./extract-ir.js";
30
31
  import { Refusal, pathOf, readerRun, statedRefusal } from "./extract-read.js";
32
+ import { concreteSolidity, SolidityHarnessRefusal } from "./sol-concrete.js";
31
33
  const refuse = (where, what) => { throw new Refusal(where, what); };
32
34
  import { asset, checkStep, node, readStep, stepNames } from "./extract-step.js";
33
35
  export { proveRule, proveSteps } from "./dsl.js";
@@ -36,10 +38,10 @@ export const MOD = 'W256$';
36
38
  const CHECK_W = 2 ** 52;
37
39
  const U256 = { k: 'int', bits: 256, signed: false, mod: MOD };
38
40
  const env = () => globalThis.process?.env ?? {};
39
- export function compile(file, o) {
41
+ export function compile(file, o, extra = {}) {
40
42
  const cp = node('node:child_process'), fs = node('node:fs'), path = node('node:path');
41
43
  const root = path.resolve(o.root ?? path.dirname(file)), rel = path.relative(root, path.resolve(file));
42
- const input = { language: 'Solidity', sources: { [rel]: { content: fs.readFileSync(file, 'utf8') } },
44
+ const input = { language: 'Solidity', sources: { ...Object.fromEntries(Object.entries(extra).map(([p, content]) => [p, { content }])), [rel]: { content: fs.readFileSync(file, 'utf8') } },
43
45
  settings: { remappings: o.remappings ?? [], optimizer: { enabled: false }, outputSelection: { '*': { '': ['ast'], '*': ['abi', 'evm.bytecode.object', 'evm.deployedBytecode.object', 'evm.methodIdentifiers', 'storageLayout'] } } } };
44
46
  let out;
45
47
  const solc = o.solc ?? env().GDP_SOLC ?? 'solc';
@@ -61,7 +63,7 @@ export function compile(file, o) {
61
63
  ast.set(s.id, s.ast);
62
64
  paths.set(s.id, p);
63
65
  const abs = p === rel ? path.resolve(file) : [path.resolve(root, p), path.resolve(root, 'node_modules', p)].find(x => fs.existsSync(x));
64
- text.set(s.id, abs ? fs.readFileSync(abs, 'utf8') : '');
66
+ text.set(s.id, extra[p] ?? (abs ? fs.readFileSync(abs, 'utf8') : ''));
65
67
  }
66
68
  return { main, ast, text, paths, contracts: j.contracts };
67
69
  }
@@ -73,6 +75,7 @@ class Lower {
73
75
  funcs = {};
74
76
  fields = [];
75
77
  consts = new Map();
78
+ ctorParams = new Map();
76
79
  minW = 2;
77
80
  addrBits = 0;
78
81
  get ADDR() { return { k: 'int', bits: this.addrBits, signed: false }; }
@@ -161,7 +164,7 @@ class Lower {
161
164
  return { k: 'map', key: k.k === 'int' && k.mod ? { k: 'int' } : k, val };
162
165
  }
163
166
  // The contract: its linearized bases, state, functions.
164
- module(name) {
167
+ module(name, selected) {
165
168
  const contracts = [...this.defs.values()].filter(d => d.nodeType === 'ContractDefinition');
166
169
  const main = this.c.ast.get(this.c.main);
167
170
  const own = contracts.filter(d => main && main.nodes.includes(d));
@@ -201,11 +204,11 @@ class Lower {
201
204
  if (f.kind === 'constructor')
202
205
  continue;
203
206
  const id = this.fnId(f);
204
- if (this.funcs[id])
207
+ if (fns[id])
205
208
  continue;
206
209
  const pub = f.visibility === 'public' || f.visibility === 'external';
207
210
  const name = f.kind === 'receive' ? 'receive' : f.kind === 'fallback' ? 'fallback' : f.name;
208
- if (pub && f.stateMutability !== 'view' && f.stateMutability !== 'pure') {
211
+ if (pub && (selected ? selected.includes(name) : f.stateMutability !== 'view' && f.stateMutability !== 'pure')) {
209
212
  if (methods[name])
210
213
  this.no(f, `${name}: an overloaded external function (the subset reads one of a name)`);
211
214
  methods[name] = `entry:${id}`;
@@ -392,6 +395,35 @@ class Lower {
392
395
  this.cur = { entry: true, payable: top?.stateMutability === 'payable', rets: [], tmp: 0 };
393
396
  if (this.cur.payable)
394
397
  this.ether = true;
398
+ // Bind constructor arguments derived-first, then execute bodies base-first. Each parameter has a fresh local:
399
+ // a base's `n` must neither read an unbound derived `n` nor overwrite it when the base mutates its own argument.
400
+ const used = new Set([...this.defs.values()].map(d => d.name).filter((n) => typeof n === 'string'));
401
+ const callsCode = (a) => {
402
+ if (Array.isArray(a))
403
+ return a.some(callsCode);
404
+ if (!a || typeof a !== 'object')
405
+ return false;
406
+ const n = a;
407
+ return n.nodeType === 'FunctionCall' && n.kind !== 'typeConversion' || Object.values(n).some(v => v && typeof v === 'object' && callsCode(v));
408
+ };
409
+ for (const c of this.lin) {
410
+ const cf = ctorOf(c);
411
+ for (const [i, pa] of (cf?.parameters.parameters ?? []).entries()) {
412
+ const a = c === k ? undefined : given.get(c.id)?.[i];
413
+ if (c !== k && !a)
414
+ this.no(cf, `${c.name}'s constructor given no ${pa.name}`);
415
+ if (a && callsCode(a))
416
+ this.no(a, 'a constructor argument calling code (its initialization order is not supported)');
417
+ const x = a ? this.ex(a) : { e: 'var', n: pa.name, p: this.at(pa) };
418
+ let name = `gdp$ctor$${pa.id}`;
419
+ while (used.has(name))
420
+ name += '_';
421
+ used.add(name);
422
+ const to = { e: 'var', n: name, p: this.at(pa) };
423
+ body.push({ s: 'set', p: this.at(pa), to, x, t: this.ty(pa.typeDescriptions.typeString, pa) });
424
+ this.ctorParams.set(pa.id, to);
425
+ }
426
+ }
395
427
  for (const c of [...this.lin].reverse()) {
396
428
  for (const n of c.nodes) {
397
429
  if (n.nodeType !== 'VariableDeclaration' || n.constant)
@@ -404,9 +436,6 @@ class Lower {
404
436
  const cf = ctorOf(c);
405
437
  if (!cf)
406
438
  continue;
407
- if (c !== k)
408
- cf.parameters.parameters.forEach((pa, i) => { const a = given.get(c.id)?.[i]; if (!a)
409
- this.no(cf, `${c.name}'s constructor given no ${pa.name}`); body.push({ s: 'set', p: this.at(cf), to: { e: 'var', n: pa.name, p: this.at(cf) }, x: this.ex(a) }); });
410
439
  body.push(...this.withModifiers(cf, (cf.modifiers ?? []).filter(m => this.defs.get(m.modifierName.referencedDeclaration)?.nodeType === 'ModifierDefinition'), 0));
411
440
  }
412
441
  if (this.ether)
@@ -421,6 +450,7 @@ class Lower {
421
450
  const params = [{ name: 'self', t: { k: 'rec', name: k.name }, self: true }, { name: MOD, t: { k: 'int' } }, { name: 'msg.sender', t: this.ADDR }, ...(this.cur.payable ? [{ name: 'msg.value', t: U256 }] : [])];
422
451
  for (const pa of (top?.parameters.parameters ?? []))
423
452
  params.push({ name: pa.name, t: this.ty(pa.typeDescriptions.typeString, pa) });
453
+ this.ctorParams.clear();
424
454
  return { id: '__init__', name: '__init__', p, span: [p, 0, 0], params, ret: { k: 'none' }, body, decorators: [] };
425
455
  }
426
456
  // --- statements ------------------------------------------------------------------------------------------------------
@@ -539,7 +569,7 @@ class Lower {
539
569
  const f = this.fieldOf(n);
540
570
  if (f)
541
571
  return f.t.k === 'opaque' ? (/string|bytes/.test(f.sol) ? undefined : this.no(n, f.t.why)) : self(f.name, p);
542
- return { e: 'var', n: n.name, p };
572
+ return this.ctorParams.get(n.referencedDeclaration) ?? { e: 'var', n: n.name, p };
543
573
  }
544
574
  if (n.nodeType === 'IndexAccess') {
545
575
  if (this.nestedOf(n)) {
@@ -602,6 +632,8 @@ class Lower {
602
632
  return this.no(n, `${n.name} alone`);
603
633
  if (this.consts.has(n.referencedDeclaration))
604
634
  return this.consts.get(n.referencedDeclaration);
635
+ if (this.ctorParams.has(n.referencedDeclaration))
636
+ return this.ctorParams.get(n.referencedDeclaration);
605
637
  const f = this.fieldOf(n);
606
638
  if (f)
607
639
  return f.t.k === 'opaque' ? { e: 'opaque', p, why: `${n.name}: ${f.t.why}` } : self(f.name, p);
@@ -793,11 +825,18 @@ const hasReturn = (ss) => ss.some(s => s.s === 'ret' || (s.s === 'if' && (hasRet
793
825
  const abiType = (ts) => (ts.startsWith('address') ? 'address' : ts.startsWith('enum ') ? 'uint8' : ts.startsWith('contract ') ? 'address' : ts.replace(/ (storage|memory|calldata).*$/, ''));
794
826
  // --- the front end ---------------------------------------------------------------------------------------------------
795
827
  export function readSolidity(file, o = {}, reenter = false, compiled) {
796
- const c = compiled ?? compile(file, o);
828
+ const c = compiled ?? concreteSolidity(file, o, compile(file, o), compile);
797
829
  const L = new Lower(c, file, reenter);
798
- const entry = typeof o.entry === 'string' ? o.entry : undefined;
799
- const { mod, meta } = L.module(entry);
800
- return { mod, meta, c };
830
+ const entry = c.harness?.entry ?? (typeof o.entry === 'string' ? o.entry : undefined);
831
+ try {
832
+ const { mod, meta } = L.module(entry, o.methods ?? c.harnessMethods);
833
+ return { mod, meta, c };
834
+ }
835
+ catch (e) {
836
+ if (e instanceof Refusal && c.harness)
837
+ throw new SolidityHarnessRefusal(e, c.harness);
838
+ throw e;
839
+ }
801
840
  }
802
841
  export function extractSolidity(at, opts = {}) {
803
842
  const file = pathOf(at);
@@ -807,10 +846,11 @@ export function extractSolidity(at, opts = {}) {
807
846
  }
808
847
  catch (e) {
809
848
  if (e instanceof Refusal)
810
- return { ok: false, refusals: [{ where: e.where, what: e.what }], notes: [] };
849
+ return { ok: false, refusals: [{ where: e.where, what: e.what }], notes: e instanceof SolidityHarnessRefusal ? e.harness.notes : [], ...(e instanceof SolidityHarnessRefusal ? { harness: e.harness } : {}) };
811
850
  throw e;
812
851
  }
813
852
  const { mod, meta, c } = r;
853
+ const info = c.harness ? { harness: c.harness } : {};
814
854
  const out = c.contracts[meta.source]?.[meta.contract];
815
855
  const harness = (read) => {
816
856
  read.arms.length = 0;
@@ -831,16 +871,21 @@ export function extractSolidity(at, opts = {}) {
831
871
  const havoc = Object.fromEntries(meta.fields.filter(f => meta.nested.includes(f.name)).map(f => [f.name, f.t.val.k === 'bool' ? 'bool' : 'int']));
832
872
  const o = { ...opts, methods, share: opts.share ?? true, strict: true, onError: 'discard', entry: meta.contract, check: { probes: 'writes', ...opts.check }, answers: { ...havoc, ...opts.answers } };
833
873
  // extractStep's run, the width's param fixed for the check's own draws (2^52: the proof is for every width)
834
- const notes = [];
874
+ const notes = [...c.harness?.notes ?? []];
835
875
  let read;
836
876
  try {
837
877
  read = readStep(mod, o);
838
878
  }
839
879
  catch (e) {
840
880
  if (e instanceof Refusal)
841
- return { ok: false, refusals: [{ where: e.where, what: e.what }], notes };
881
+ return { ok: false, refusals: [{ where: e.where, what: e.what }], notes, ...info };
842
882
  throw e;
843
883
  }
884
+ // Constructor argument bounds name the state width; before an object exists that is its initial parameter.
885
+ // Keep the bound, but bind it in the parameter-only precondition rather than leaving a state reference there.
886
+ const widthInit = read.model.init[MOD];
887
+ if (widthInit?.s === 'num')
888
+ read.model.pre = substN(read.model.pre, MOD, widthInit.e);
844
889
  const w = read.model.params.find(v => v.name.startsWith(MOD));
845
890
  if (w)
846
891
  w.derived = { op: 'const', v: CHECK_W };
@@ -852,11 +897,11 @@ export function extractSolidity(at, opts = {}) {
852
897
  const unsigned = Object.fromEntries([...read.model.inputs, ...read.model.params].filter(v => read.ints[v.name] && !read.ints[v.name].signed).map(v => [v.name, 'nat']));
853
898
  const x = fromModel(read.model, mod.file, { ...unsigned, ...o.domains }, notes, (rule, sorts) => checkStep(harness(read), read, rule, sorts, o));
854
899
  if (!x.ok)
855
- return { ...x, read, names: stepNames(read) };
900
+ return { ...x, ...info, read, names: stepNames(read) };
856
901
  // (a run that breaks a law, from the prover at any width: replayed on the code at the check's before it is shown)
857
902
  if (!meta.calls || opts.reentrant === false) {
858
903
  const rp = replayer({ rule: x.rule, sorts: x.sorts, model: read.model, names: stepNames(read), leaves: read.leaves, hello: harness(read).hello.sol, ctor: read.ctor, replay: compileReplay(opts), opts });
859
- return { ...x, read, names: stepNames(read), replay: (run, law) => rp(run, law) };
904
+ return { ...x, ...info, read, names: stepNames(read), replay: (run, law) => rp(run, law) };
860
905
  }
861
906
  // The rule the laws are proven of: every call into other code a point where any of the contract's calls may run.
862
907
  let re, rread;
@@ -866,14 +911,17 @@ export function extractSolidity(at, opts = {}) {
866
911
  }
867
912
  catch (e) {
868
913
  if (e instanceof Refusal)
869
- return { ok: false, refusals: [{ where: e.where, what: `re-entrancy: ${e.what}` }], notes: [...x.notes] };
914
+ return { ok: false, refusals: [{ where: e.where, what: `re-entrancy: ${e.what}` }], notes: [...x.notes], ...info };
870
915
  throw e;
871
916
  }
917
+ const reWidthInit = rread.model.init[MOD];
918
+ if (reWidthInit?.s === 'num')
919
+ rread.model.pre = substN(rread.model.pre, MOD, reWidthInit.e);
872
920
  const rw = rread.model.params.find(v => v.name.startsWith(MOD));
873
921
  if (rw)
874
922
  rw.derived = { op: 'const', v: CHECK_W };
875
923
  rread.model.notes.push(...boundaryNotes(meta), `re-entrancy: each call into other code (${re.meta.resumes.map(r => r.replace(/\$resume$/, '')).join(', ')}) is two steps, any of the contract's calls between them (a callee that calls back); a law about the state holds where no call is pending (pending$ == 0)`);
876
- const rnotes = [];
924
+ const rnotes = [...c.harness?.notes ?? []];
877
925
  // The check of the re-entrant rule: its own random runs (calls inside calls, by any address) replayed on the code,
878
926
  // every address an Agent that makes the run's calls from inside the call it receives.
879
927
  let replays;
@@ -903,7 +951,7 @@ export function extractSolidity(at, opts = {}) {
903
951
  });
904
952
  if (rx.ok)
905
953
  rx.notes.push(`re-entrancy: checked by ${runs.runs} runs of the rule replayed on the code (${runs.txs} transactions, ${runs.nested} calls made from inside another, ${runs.steps} steps), an Agent at every address making each call from inside the one it receives`);
906
- return { ...rx, read: rread, names: stepNames(rread), quiet: 'pending$', ...(replays ? { replay: (run, law) => replays(run, law) } : {}) };
954
+ return { ...rx, ...info, read: rread, names: stepNames(rread), quiet: 'pending$', ...(replays ? { replay: (run, law) => replays(run, law) } : {}) };
907
955
  }
908
956
  function compileReplay(o) {
909
957
  const c = compile(asset('sol/Replay.sol'), { ...o, root: asset('sol/') });
@@ -94,6 +94,12 @@ export type SFunc = {
94
94
  late?: string;
95
95
  };
96
96
  export type SRec = {
97
+ initializers?: string[];
98
+ orm?: {
99
+ framework: 'django' | 'sqlalchemy' | 'prisma' | 'typeorm';
100
+ key: string;
101
+ why?: string;
102
+ };
97
103
  name: string;
98
104
  short: string;
99
105
  fields: {
@@ -109,6 +115,9 @@ export type SRec = {
109
115
  p: string;
110
116
  rets?: Record<string, SType>;
111
117
  cattrs?: Record<string, number | string | boolean | null>;
118
+ mro?: string[] | null;
119
+ declared?: string[];
120
+ classCollections?: Record<string, string>;
112
121
  };
113
122
  export type SModule = {
114
123
  lang: string;
@@ -169,6 +178,7 @@ export type StoreVal = 'int' | 'float' | 'str' | string[] | {
169
178
  json: Record<string, string | string[]>;
170
179
  };
171
180
  export type StoreDecl = {
181
+ ormSession?: boolean;
172
182
  get?: string[];
173
183
  set?: string[];
174
184
  delete?: string[];
@@ -223,12 +233,19 @@ export type IntTy = {
223
233
  ub?: boolean;
224
234
  mod?: string;
225
235
  };
236
+ type Bits = {
237
+ x: N;
238
+ A: number;
239
+ B: number;
240
+ w: number;
241
+ };
226
242
  type V = {
227
243
  t: 'num';
228
244
  e: N;
229
245
  ty?: IntTy;
230
246
  cmp?: [N, N];
231
247
  slen?: K;
248
+ bits?: Bits;
232
249
  } | {
233
250
  t: 'bool';
234
251
  e: B;
@@ -264,6 +281,7 @@ type V = {
264
281
  store: string;
265
282
  path: string;
266
283
  };
284
+ sink?: boolean;
267
285
  } | {
268
286
  t: 'ext';
269
287
  q: string;
@@ -337,6 +355,29 @@ type CellWrite = {
337
355
  vals: Map<string, V>;
338
356
  on?: B;
339
357
  };
358
+ type Ranking = {
359
+ name: string;
360
+ id: string;
361
+ decl: MapDecl;
362
+ K: {
363
+ op: 'num';
364
+ e: N;
365
+ };
366
+ exists: B;
367
+ view: Map<string, V>;
368
+ cur: Map<string, V>;
369
+ a: N;
370
+ ld: B;
371
+ ord: string;
372
+ rk: string;
373
+ order?: {
374
+ by: (k: K) => {
375
+ e: N;
376
+ desc?: boolean;
377
+ }[];
378
+ sig: string;
379
+ };
380
+ };
340
381
  type Ptr = {
341
382
  k: 'nil';
342
383
  } | {
@@ -390,6 +431,13 @@ type Obj = {
390
431
  origin: Origin;
391
432
  lazy?: string;
392
433
  moved?: boolean;
434
+ orm?: {
435
+ table: string;
436
+ key: K;
437
+ session?: string;
438
+ loaded?: boolean;
439
+ deleted?: boolean;
440
+ };
393
441
  } | {
394
442
  k: 'map';
395
443
  decl: MapDecl;
@@ -397,6 +445,7 @@ type Obj = {
397
445
  nil?: B;
398
446
  w?: CellWrite;
399
447
  pre?: CellWrite[];
448
+ ew?: CellWrite;
400
449
  origin: Origin;
401
450
  } | {
402
451
  k: 'store';
@@ -429,6 +478,15 @@ type Flow = {
429
478
  };
430
479
  export type { V as StepValue, Path as StepPath, Obj as StepObj, Ptr as StepPtr };
431
480
  export type Leaf = {
481
+ orm?: {
482
+ rec: string;
483
+ key: string;
484
+ framework: string;
485
+ fields: {
486
+ name: string;
487
+ t: SType;
488
+ }[];
489
+ };
432
490
  t?: SType;
433
491
  name: string;
434
492
  path: string[];
@@ -451,6 +509,7 @@ export type Leaf = {
451
509
  };
452
510
  export type PArg = {
453
511
  k: 'in';
512
+ time?: string;
454
513
  name: string;
455
514
  float?: boolean;
456
515
  sym?: boolean;
@@ -485,6 +544,7 @@ export type Answer = {
485
544
  name: string;
486
545
  none?: string;
487
546
  float?: boolean;
547
+ time?: string;
488
548
  };
489
549
  sort: string;
490
550
  how?: string;
@@ -507,6 +567,7 @@ export type Answer = {
507
567
  export type StepRead = {
508
568
  ints: Record<string, IntTy>;
509
569
  madeAt?: string;
570
+ naiveUtc?: boolean;
510
571
  model: Model;
511
572
  leaves: Leaf[];
512
573
  args: Record<string, [string, PArg][]>;
@@ -527,6 +588,7 @@ export type StepRead = {
527
588
  store: string;
528
589
  path: string;
529
590
  }[];
591
+ edges?: B[];
530
592
  };
531
593
  export type Inferred = {
532
594
  answers: Map<string, SType>;
@@ -578,6 +640,21 @@ export declare class Stepper {
578
640
  readonly folds: Fold[];
579
641
  hidden: number;
580
642
  inFold: number;
643
+ drain?: {
644
+ i: N;
645
+ back: boolean;
646
+ entry: Path;
647
+ map?: {
648
+ name: string;
649
+ id: string;
650
+ };
651
+ dir?: boolean;
652
+ empty?: string;
653
+ rank?: Map<string, Ranking>;
654
+ run?: string;
655
+ };
656
+ drainSetup: number;
657
+ drainAgain: boolean;
581
658
  readonly initHeap: Map<string, Obj>;
582
659
  readonly storeMaps: Map<string, {
583
660
  store: string;
@@ -647,6 +724,37 @@ export declare class Stepper {
647
724
  held: (k: K) => B;
648
725
  } | undefined;
649
726
  forStmt(s: SS, p: Path): Flow;
727
+ whileStmt(s: SS, p: Path, back?: boolean): Flow;
728
+ whileRank(s: SS, p: Path): Flow;
729
+ rankOrder(d: Ranking): (k: K) => {
730
+ e: N;
731
+ desc?: boolean;
732
+ }[];
733
+ rankOf(o: Extract<Obj, {
734
+ k: 'map';
735
+ }>, at: SX): Ranking;
736
+ rankLeast(o: Extract<Obj, {
737
+ k: 'map';
738
+ }>, at: SX, where: (k: K) => B, by: (k: K) => {
739
+ e: N;
740
+ desc?: boolean;
741
+ }[]): {
742
+ key: N;
743
+ some: B;
744
+ held: B;
745
+ where: (k: K) => B;
746
+ };
747
+ drainLeast(o: Extract<Obj, {
748
+ k: 'map';
749
+ }>, at: SX, where: (k: K) => B, by: (k: K) => {
750
+ e: N;
751
+ desc?: boolean;
752
+ }[]): {
753
+ key: N;
754
+ some: B;
755
+ held: B;
756
+ where: (k: K) => B;
757
+ };
650
758
  foldExpr(x: SX, p: Path): [V, Path];
651
759
  changedFrom(e: Path, p: Path): boolean;
652
760
  joinSome(ps: Path[], at: {
@@ -754,6 +862,23 @@ export declare class Stepper {
754
862
  some: B;
755
863
  held: B;
756
864
  }, d: V | undefined, x: SX, p: Path): [V, Path];
865
+ timeField(v: V, t: SType | undefined, read: boolean, at: {
866
+ p: string;
867
+ text?: string;
868
+ }): V;
869
+ naiveUtc: boolean;
870
+ readonly ormTables: Map<string, {
871
+ id: string;
872
+ decl: MapDecl;
873
+ }>;
874
+ ormTable(rec: string, at: SX, p: Path): {
875
+ id: string;
876
+ decl: MapDecl;
877
+ };
878
+ ormRow(rec: string, key: K, vals: Map<string, V>, at: SX, p: Path): [V, Path];
879
+ ormCall(rec: string, op: string, args: V[], kw: [string, V][], at: SX, p: Path): [V, Path];
880
+ ormSession(name: string, op: string, args: V[], kw: [string, V][], at: SX, p: Path): [V, Path];
881
+ ormPersist(v: V, op: string, args: V[], kw: [string, V][], at: SX, p: Path): [V, Path];
757
882
  storeMap(store: string, tpl: string, kn: boolean, at: SX, p: Path): [string, Extract<Obj, {
758
883
  k: 'map';
759
884
  }>];
@@ -830,6 +955,8 @@ export declare class Stepper {
830
955
  isOf(v: V, k: string, at: SX): B;
831
956
  inner(v: V, k: string, at: SX): V;
832
957
  rmw(x: SX, p: Path): [V, Path];
958
+ classConstant(value: number | string | boolean | null, at: SX): V;
959
+ classCollection(owner: string, name: string): V;
833
960
  get(x: SX, p: Path): [V, Path];
834
961
  lazyField(id: string, obj: Extract<Obj, {
835
962
  k: 'rec';
@@ -844,15 +971,20 @@ export declare class Stepper {
844
971
  equal(a: V, b: V, at: SX, p: Path): B;
845
972
  truth(x: SX, p: Path): [B, Path];
846
973
  boolOp(x: SX, p: Path): [V, Path];
974
+ checkOrmDisplay(v: V, at: SX): void;
847
975
  fstr(x: SX, p: Path, given?: (string | V)[]): [V, Path];
848
976
  call(x: SX, p: Path, awaited: boolean): [V, Path];
849
977
  argsRead(x: SX, p: Path): Path;
850
978
  evArgs<T>(x: SX, p: Path, k: (args: V[], kw: [string, V][], p: Path) => T): T;
851
979
  dictCall(m: V, name: string, x: SX, p: Path): [V, Path];
852
980
  setCall(m: V, name: string, x: SX, p: Path): [V, Path];
981
+ hasAttribute(v: V, name: string, at: SX, p: Path): boolean;
982
+ initMethod(r: SRec, at: {
983
+ p: string;
984
+ }): string | null | undefined;
853
985
  construct(rec: string, args: V[], kw: [string, V][], x: SX, p: Path): [V, Path];
854
986
  builtin(n: string, x: SX, p: Path): [V, Path];
855
- quotient(d: SX, p: Path, round: 'floor' | 'ceil' | 'trunc' | 'even'): [V, Path];
987
+ quotient(d: SX, p: Path, round: 'floor' | 'ceil' | 'trunc' | 'even' | 'up' | 'away'): [V, Path];
856
988
  lib(q0: string, x: SX, p: Path): [V, Path];
857
989
  readonly edges: B[];
858
990
  readonly lists: MapDecl[];
@@ -922,6 +1054,23 @@ export declare class Stepper {
922
1054
  binop(op: string, a: V, b: V, x: {
923
1055
  p: string;
924
1056
  }, p: Path): V;
1057
+ bitop(op: string, a: Extract<V, {
1058
+ t: 'num';
1059
+ }>, b: Extract<V, {
1060
+ t: 'num';
1061
+ }>, x: {
1062
+ p: string;
1063
+ }): V;
1064
+ ofBits(f: Bits, at: {
1065
+ p: string;
1066
+ }): N;
1067
+ andRuns(v: N, k: number, at: {
1068
+ p: string;
1069
+ }): N;
1070
+ bitsOf(v: N): Bits | undefined;
1071
+ bitGeneric(op: string, v: N, w: N, first: boolean, ty: IntTy, x: {
1072
+ p: string;
1073
+ }): V;
925
1074
  eq(a: V, b: V, x: {
926
1075
  p: string;
927
1076
  }, p?: Path): B;
@@ -987,6 +1136,7 @@ type CellW = {
987
1136
  key: K;
988
1137
  has: B;
989
1138
  vals: Record<string, Term>;
1139
+ each?: true;
990
1140
  };
991
1141
  export declare function padWrites<W extends {
992
1142
  key: K;