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
@@ -0,0 +1,12 @@
1
+ import { type StepOptions } from './extract-step.js';
2
+ /** Explicit boundary: the first argument is the injected Prisma client or TypeORM repository. */
3
+ export type OrmOptions = {
4
+ schema: string;
5
+ model: string;
6
+ kind?: 'prisma' | 'typeorm';
7
+ };
8
+ export declare function extractOrm(file: string, code: string, opts: StepOptions & {
9
+ orm: OrmOptions;
10
+ }): import("./extract.ts").Extraction & {
11
+ read?: import("./extract-step.ts").StepRead;
12
+ };
@@ -0,0 +1,244 @@
1
+ import ts from 'typescript';
2
+ import { Refusal } from "./extract-read.js";
3
+ import { asset, extractStep, node } from "./extract-step.js";
4
+ export function extractOrm(file, code, opts) {
5
+ const { readFileSync } = node('node:fs');
6
+ const { resolve, dirname, basename } = node('node:path');
7
+ const sf = ts.createSourceFile(file, code, ts.ScriptTarget.Latest, true);
8
+ const fail = (n, why) => { const p = sf.getLineAndCharacterOfPosition(n.getStart(sf)); throw new Refusal(`${file}:${p.line + 1}:${p.character + 1}`, why); };
9
+ try {
10
+ const names = typeof opts.entry === 'string' ? [opts.entry] : opts.entry;
11
+ if (!names?.length || new Set(names).size !== names.length)
12
+ throw new Refusal(file, 'ORM extraction requires distinct explicit entries');
13
+ const model = opts.orm.model, kind = opts.orm.kind ?? 'prisma';
14
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(model))
15
+ throw new Refusal(file, 'invalid ORM model name');
16
+ let schema;
17
+ try {
18
+ schema = readFileSync(resolve(dirname(file), opts.orm.schema), 'utf8');
19
+ }
20
+ catch {
21
+ throw new Refusal(file, 'ORM schema file cannot be read');
22
+ }
23
+ const fields = [], keys = [];
24
+ if (kind === 'prisma') {
25
+ // Mask comments and strings before locating a model; neither can declare one.
26
+ const masked = schema.replace(/\/\*[\s\S]*?\*\/|\/\/[^\n]*|"(?:\\.|[^"\\])*"/g, s => s.replace(/[^\n]/g, ' '));
27
+ const blocks = [...masked.matchAll(new RegExp(`\\bmodel\\s+${model}\\s*\\{([^{}]*)\\}`, 'g'))];
28
+ if (blocks.length !== 1)
29
+ throw new Refusal(file, `expected exactly one Prisma model ${model} in schema`);
30
+ const originalBlock = schema.slice(blocks[0].index, blocks[0].index + blocks[0][0].length).replace(/\/\*[\s\S]*?\*\/|\/\/[^\n]*/g, '');
31
+ if (originalBlock.includes('"') || originalBlock.includes("'"))
32
+ throw new Refusal(file, `${model}: string syntax in model is unsupported`);
33
+ for (const raw of blocks[0][1].split('\n')) {
34
+ const line = raw.replace(/\/\/.*$/, '').trim();
35
+ if (!line)
36
+ continue;
37
+ const m = /^(\w+)\s+(Int|Boolean|String)\s*(.*)$/.exec(line);
38
+ if (!m || /@(?!id\b)/.test(m[3]) || /[^\s]/.test(m[3].replace('@id', '')))
39
+ throw new Refusal(file, `${model}: unsupported schema field ${line}`);
40
+ fields.push({ name: m[1], t: { k: m[2] === 'Int' ? 'int' : m[2] === 'Boolean' ? 'bool' : 'str' } });
41
+ if (m[3].includes('@id'))
42
+ keys.push(m[1]);
43
+ }
44
+ }
45
+ else {
46
+ const entity = ts.createSourceFile(opts.orm.schema, schema, ts.ScriptTarget.Latest, true);
47
+ const imports = entity.statements.filter(ts.isImportDeclaration).filter(s => ts.isStringLiteral(s.moduleSpecifier) && s.moduleSpecifier.text === 'typeorm');
48
+ const imported = new Set(imports.flatMap(s => { const b = s.importClause?.namedBindings; return b && ts.isNamedImports(b) && !s.importClause?.isTypeOnly ? b.elements.filter(e => !e.isTypeOnly && !e.propertyName).map(e => e.name.text) : []; }));
49
+ if (!['Entity', 'Column', 'PrimaryColumn'].every(n => imported.has(n)))
50
+ throw new Refusal(file, `${model}: decorators must be direct named imports from typeorm`);
51
+ if (entity.statements.some(s => !ts.isImportDeclaration(s) && !(ts.isClassDeclaration(s) && s.name?.text === model)))
52
+ throw new Refusal(file, `${model}: unsupported entity module declaration`);
53
+ for (const s of entity.statements.filter(ts.isImportDeclaration)) {
54
+ const b = s.importClause?.namedBindings;
55
+ if (b && ts.isNamedImports(b) && b.elements.some(e => ['Entity', 'Column', 'PrimaryColumn'].includes(e.name.text) && (!ts.isStringLiteral(s.moduleSpecifier) || s.moduleSpecifier.text !== 'typeorm' || e.propertyName || e.isTypeOnly || s.importClause?.isTypeOnly)))
56
+ throw new Refusal(file, `${model}: ambiguous decorator binding`);
57
+ }
58
+ const classes = entity.statements.filter((s) => ts.isClassDeclaration(s) && s.name?.text === model);
59
+ const cls = classes.length === 1 ? classes[0] : undefined;
60
+ const decorators = (n) => ts.canHaveDecorators(n) ? ts.getDecorators(n) ?? [] : [];
61
+ const plain = (d, name) => ts.isCallExpression(d.expression) && ts.isIdentifier(d.expression.expression) && d.expression.expression.text === name && d.expression.arguments.length === 0;
62
+ if (entity.parseDiagnostics.length || !cls || cls.heritageClauses?.length || decorators(cls).length !== 1 || !plain(decorators(cls)[0], 'Entity'))
63
+ throw new Refusal(file, `${model}: expected a plain @Entity() class`);
64
+ for (const member of cls.members) {
65
+ if (!ts.isPropertyDeclaration(member) || !ts.isIdentifier(member.name) || member.initializer || member.questionToken || !member.type || member.modifiers?.some(m => m.kind !== ts.SyntaxKind.Decorator && m.kind !== ts.SyntaxKind.DeclareKeyword))
66
+ throw new Refusal(file, `${model}: unsupported entity member`);
67
+ const ds = decorators(member), primary = ds.length === 1 && plain(ds[0], 'PrimaryColumn');
68
+ if (!primary && !(ds.length === 1 && plain(ds[0], 'Column')))
69
+ throw new Refusal(file, `${model}.${member.name.text}: unsupported column decorator`);
70
+ const k = member.type.kind === ts.SyntaxKind.NumberKeyword ? 'int' : member.type.kind === ts.SyntaxKind.StringKeyword ? 'str' : member.type.kind === ts.SyntaxKind.BooleanKeyword ? 'bool' : undefined;
71
+ if (!k)
72
+ throw new Refusal(file, `${model}.${member.name.text}: unsupported column type`);
73
+ fields.push({ name: member.name.text, t: { k } });
74
+ if (primary)
75
+ keys.push(member.name.text);
76
+ }
77
+ }
78
+ if (new Set(fields.map(f => f.name)).size !== fields.length || fields.some(f => ['__proto__', 'prototype', 'constructor'].includes(f.name)))
79
+ throw new Refusal(file, `${model}: duplicate or reserved column name`);
80
+ if (keys.length !== 1 || !fields.some(f => f.name !== keys[0]))
81
+ throw new Refusal(file, `${model}: requires one explicit primary key and a value column`);
82
+ const key = keys[0], rec = `orm.${model}`, funcs = {};
83
+ const loc = (n) => { const p = sf.getLineAndCharacterOfPosition(n.getStart(sf)); return `${basename(file)}:${p.line + 1}:${p.character + 1}`; };
84
+ const v = (n, p) => ({ e: 'var', n, p });
85
+ const get = (x, f, p) => ({ e: 'get', x, f, p });
86
+ const call = (x, f, kw, p) => ({ e: 'call', f: get(x, f, p), args: [], kw, p, text: f });
87
+ const manager = (p) => get({ e: 'cls', rec, p }, 'objects', p);
88
+ const object = (n) => {
89
+ if (!ts.isObjectLiteralExpression(n))
90
+ return fail(n, 'ORM arguments must be explicit object literals');
91
+ const out = new Map();
92
+ for (const prop of n.properties) {
93
+ if (ts.isShorthandPropertyAssignment(prop)) {
94
+ if (out.has(prop.name.text))
95
+ fail(prop, 'duplicate property');
96
+ out.set(prop.name.text, prop.name);
97
+ continue;
98
+ }
99
+ if (!ts.isPropertyAssignment(prop) || !ts.isIdentifier(prop.name))
100
+ return fail(prop, 'ORM properties must be explicit names');
101
+ if (out.has(prop.name.text))
102
+ fail(prop, 'duplicate property');
103
+ out.set(prop.name.text, prop.initializer);
104
+ }
105
+ return out;
106
+ };
107
+ let scalarNames = new Set(), rowName;
108
+ const expr = (n) => {
109
+ const p = loc(n);
110
+ if (ts.isIdentifier(n)) {
111
+ if (!scalarNames.has(n.text))
112
+ fail(n, 'only scalar inputs may be used as values');
113
+ return v(n.text, p);
114
+ }
115
+ if (ts.isNumericLiteral(n) && Number.isSafeInteger(Number(n.text)))
116
+ return { e: 'int', v: n.text, p };
117
+ if (ts.isStringLiteral(n))
118
+ return { e: 'str', v: n.text, p };
119
+ if (n.kind === ts.SyntaxKind.TrueKeyword || n.kind === ts.SyntaxKind.FalseKeyword)
120
+ return { e: 'bool', v: n.kind === ts.SyntaxKind.TrueKeyword, p };
121
+ if (ts.isPropertyAccessExpression(n) && !n.questionDotToken && ts.isIdentifier(n.expression) && n.expression.text === rowName && fields.some(f => f.name === n.name.text))
122
+ return get(v(rowName, p), n.name.text, p);
123
+ if (ts.isParenthesizedExpression(n))
124
+ return expr(n.expression);
125
+ return fail(n, 'expression outside the ORM subset');
126
+ };
127
+ for (const name of names) {
128
+ const parts = name.split('.');
129
+ let fn;
130
+ if (parts.length === 1) {
131
+ const found = sf.statements.filter((s) => ts.isFunctionDeclaration(s) && s.name?.text === name);
132
+ if (found.length === 1 && found[0].modifiers?.some(m => m.kind === ts.SyntaxKind.ExportKeyword))
133
+ fn = found[0];
134
+ }
135
+ else if (parts.length === 2) {
136
+ const classes = sf.statements.filter((s) => ts.isClassDeclaration(s) && s.name?.text === parts[0]);
137
+ const cls = classes.length === 1 ? classes[0] : undefined;
138
+ if (!cls || !cls.modifiers?.some(m => m.kind === ts.SyntaxKind.ExportKeyword) || cls.heritageClauses?.length || cls.members.some(m => !ts.isMethodDeclaration(m)) || (ts.canHaveDecorators(cls) && ts.getDecorators(cls)?.length))
139
+ throw new Refusal(file, `${name}: expected an exported plain class without constructor or fields`);
140
+ const methods = cls.members.filter((m) => ts.isMethodDeclaration(m) && ts.isIdentifier(m.name) && m.name.text === parts[1]);
141
+ if (methods.length === 1 && !methods[0].modifiers?.some(m => m.kind !== ts.SyntaxKind.AsyncKeyword && m.kind !== ts.SyntaxKind.PublicKeyword))
142
+ fn = methods[0];
143
+ }
144
+ if (!fn?.body || fn.asteriskToken || fn.modifiers?.some(m => m.kind === ts.SyntaxKind.DefaultKeyword || m.kind === ts.SyntaxKind.DeclareKeyword))
145
+ throw new Refusal(file, `${name}: expected an exported non-generator function or plain service method`);
146
+ const dep = fn.parameters[0];
147
+ if (!dep || !ts.isIdentifier(dep.name) || dep.dotDotDotToken || dep.initializer)
148
+ fail(fn, 'first argument must be the injected ORM client');
149
+ const client = dep.name.text;
150
+ if (dep.questionToken || client === 'this' || client.startsWith('__orm_'))
151
+ fail(dep, 'invalid ORM client binding');
152
+ const bindings = new Set([client]);
153
+ rowName = undefined;
154
+ const params = fn.parameters.slice(1).map(pa => {
155
+ if (!ts.isIdentifier(pa.name) || pa.initializer || pa.questionToken || pa.dotDotDotToken || !pa.type || (pa.name.text === 'this' || pa.name.text.startsWith('__orm_')) || bindings.has(pa.name.text))
156
+ return fail(pa, 'ORM inputs require distinct scalar type annotations');
157
+ bindings.add(pa.name.text);
158
+ const k = pa.type.kind === ts.SyntaxKind.NumberKeyword ? 'int' : pa.type.kind === ts.SyntaxKind.StringKeyword ? 'str' : pa.type.kind === ts.SyntaxKind.BooleanKeyword ? 'bool' : undefined;
159
+ if (!k)
160
+ return fail(pa, 'ORM inputs require number, string or boolean');
161
+ return { name: pa.name.text, t: { k } };
162
+ });
163
+ scalarNames = new Set([...bindings].filter(n => n !== client));
164
+ const body = [];
165
+ for (const [index, st] of fn.body.statements.entries()) {
166
+ if (ts.isReturnStatement(st)) {
167
+ body.push({ s: 'ret', p: loc(st), ...(st.expression ? { x: expr(st.expression) } : {}) });
168
+ continue;
169
+ }
170
+ let a, target;
171
+ if (ts.isVariableStatement(st) && st.declarationList.declarations.length === 1) {
172
+ const d = st.declarationList.declarations[0];
173
+ if (!ts.isIdentifier(d.name))
174
+ fail(d, 'expected a row variable');
175
+ target = d.name.text;
176
+ if (bindings.has(target) || target.startsWith('__orm_'))
177
+ fail(d, 'ORM row binding shadows another binding');
178
+ bindings.add(target);
179
+ a = d.initializer;
180
+ }
181
+ else if (ts.isExpressionStatement(st))
182
+ a = st.expression;
183
+ if (!a || !ts.isAwaitExpression(a) || !ts.isCallExpression(a.expression))
184
+ fail(st, 'only awaited ORM operations and scalar returns are supported');
185
+ const c = a.expression, p = loc(st);
186
+ if (!ts.isPropertyAccessExpression(c.expression) || c.questionDotToken || c.expression.questionDotToken || c.arguments.length !== 1)
187
+ fail(c, 'unsupported ORM call');
188
+ const access = c.expression, op = access.name.text;
189
+ const receiver = access.expression.getText(sf);
190
+ if (receiver !== (kind === 'prisma' ? `${client}.${model[0].toLowerCase()}${model.slice(1)}` : client))
191
+ fail(c, 'ORM receiver must be the injected client and selected model');
192
+ const args = object(c.arguments[0]);
193
+ const pair = (map) => [...map].map(([k, x]) => [k, expr(x)]);
194
+ if (kind === 'prisma' && op === 'create') {
195
+ if (target || args.size !== 1 || !args.has('data'))
196
+ fail(c, 'create result must be unused and only data supplied');
197
+ body.push({ s: 'expr', p, x: call(manager(p), 'create', pair(object(args.get('data'))), p) });
198
+ }
199
+ else if ((kind === 'prisma' && op === 'findUnique') || (kind === 'typeorm' && op === 'findOneBy')) {
200
+ const where = kind === 'prisma' ? (args.size === 1 && args.has('where') ? object(args.get('where')) : fail(c, 'findUnique requires only where')) : args;
201
+ if (!target || where.size !== 1 || !where.has(key))
202
+ fail(c, `read requires an assigned row and exactly its primary key ${JSON.stringify(key)}; received where fields: ${[...where.keys()].map(k => JSON.stringify(k)).join(', ') || '(none)'}`);
203
+ // findUnique/findOneBy return null, whereas the step IR's get fails on absence.
204
+ // This equivalence holds only when the very next operation dereferences the row.
205
+ const next = fn.body.statements[index + 1];
206
+ if (!next || !ts.isReturnStatement(next) || !next.expression || !ts.isPropertyAccessExpression(next.expression) || !ts.isIdentifier(next.expression.expression) || next.expression.expression.text !== target || index + 2 !== fn.body.statements.length)
207
+ fail(c, 'nullable ORM read must be immediately returned as a row field');
208
+ rowName = target;
209
+ body.push({ s: 'set', p, to: v(target, p), x: call(manager(p), 'get', pair(where), p) });
210
+ }
211
+ else if (kind === 'prisma' && op === 'update') {
212
+ if (target || args.size !== 2 || !args.has('where') || !args.has('data'))
213
+ fail(c, 'update requires where and data; its result must be unused');
214
+ const where = object(args.get('where')), data = object(args.get('data')), row = `__orm_row_${body.length}`;
215
+ if (where.size !== 1 || !where.has(key) || data.has(key) || !data.size || [...data.keys()].some(k => !fields.some(f => f.name === k)))
216
+ fail(c, `update requires primary key ${JSON.stringify(key)} and known non-key columns; received where fields: ${[...where.keys()].map(k => JSON.stringify(k)).join(', ') || '(none)'}; received data fields: ${[...data.keys()].map(k => JSON.stringify(k)).join(', ') || '(none)'}`);
217
+ body.push({ s: 'set', p, to: v(row, p), x: call(manager(p), 'get', pair(where), p) });
218
+ for (const [f, x] of data)
219
+ body.push({ s: 'set', p, to: get(v(row, p), f, p), x: expr(x) });
220
+ body.push({ s: 'expr', p, x: call(v(row, p), 'save', [], p) });
221
+ }
222
+ else if (kind === 'typeorm' && op === 'save') {
223
+ if (target)
224
+ fail(c, 'save result must be unused');
225
+ const row = `__orm_row_${body.length}`;
226
+ body.push({ s: 'set', p, to: v(row, p), x: { e: 'call', f: { e: 'cls', rec, p }, args: [], kw: pair(args), p } });
227
+ body.push({ s: 'expr', p, x: call(v(row, p), 'save', [], p) });
228
+ }
229
+ else
230
+ fail(c, `unsupported ORM operation ${op}`);
231
+ }
232
+ funcs[name] = { id: name, name, p: loc(fn), span: [basename(file), sf.getLineAndCharacterOfPosition(fn.getStart()).line + 1, sf.getLineAndCharacterOfPosition(fn.end).line + 1], params, ret: { k: 'any' }, body, decorators: [] };
233
+ }
234
+ const mod = { lang: 'TypeScript', file, path: resolve(file), root: resolve(dirname(file)), module: basename(file), entries: names.map(id => ({ k: 'func', id })), funcs, recs: { [rec]: { name: rec, short: model, fields, methods: {}, kinds: [], own: true, module: basename(file), p: file, orm: { framework: kind, key } } } };
235
+ const x = extractStep(mod, () => ({ cmd: 'bun', args: [asset('orm/harness.js')], hello: { path: resolve(file), model, kind } }), { ...opts, strict: true });
236
+ x.notes.push(`${kind}: injected client, explicit primary keys; database constraints, defaults and triggers are outside the boundary. Importing the original module executes its initialization and imported code with the checker's privileges; the check is not a sandbox and cannot prove absence of external side effects.`);
237
+ return x;
238
+ }
239
+ catch (e) {
240
+ if (e instanceof Refusal)
241
+ return { ok: false, refusals: [{ where: e.where, what: e.what }], notes: [] };
242
+ throw e;
243
+ }
244
+ }
@@ -211,6 +211,11 @@ export function sortsOf(m, given = {}) {
211
211
  const nums = (vs) => vs.filter(v => v.sort.k === 'num');
212
212
  const ctx0 = () => ({ m, sorts, atoms: [] });
213
213
  for (const v of [...nums(m.params), ...nums(m.inputs)]) {
214
+ // (a while loop's passes: a count)
215
+ if (m.folds?.some(d => d.loop?.cond && d.len.op === 'var' && d.len.name === v.name)) {
216
+ sorts.set(v.name, 'nat');
217
+ continue;
218
+ }
214
219
  if (given[v.name]) {
215
220
  sorts.set(v.name, given[v.name]);
216
221
  notes.push(`${v.name}: ${given[v.name] === 'nat' ? 'a natural' : 'an integer'}, as given`);
@@ -258,13 +263,27 @@ export function sortsOf(m, given = {}) {
258
263
  }
259
264
  if (m.folds?.length)
260
265
  sorts.set(I.PASS, 'nat');
266
+ for (const g of (m.folds ?? []).flatMap(d => d.loop?.drains ?? [])) {
267
+ sorts.set('kl$', 'nat');
268
+ sorts.set('j$', 'nat');
269
+ sorts.set(`${g.ord}_len`, 'nat');
270
+ sorts.set(`${g.ord}.k`, 'nat');
271
+ sorts.set(`${g.rk}.$item`, 'nat');
272
+ }
261
273
  for (let changed = true; changed;) {
262
274
  changed = false;
263
275
  for (const d of m.folds ?? [])
264
276
  for (const f of d.fields) {
265
277
  const n = `${d.run}.${f.name}`, a = d.init[f.name], b = d.step[f.name];
266
- if (f.sort.k === 'num' && sorts.get(n) === 'nat' && ((a.s === 'num' && !natOK(a.e, ctx0())) || (b.s === 'num' && !natOK(b.e, ctx0())))) {
278
+ if (f.sort.k === 'num' && sorts.get(n) === 'nat' && ((a?.s === 'num' && !natOK(a.e, ctx0())) || (b?.s === 'num' && !natOK(b.e, ctx0())))) {
279
+ sorts.set(n, 'int');
280
+ changed = true;
281
+ }
282
+ // (an item's field the run holds: the collection's field's sort, both ways)
283
+ const lk = d.loop?.like.find(x => x[0] === f.name)?.[1];
284
+ if (lk && f.sort.k === 'num' && sorts.get(n) !== sorts.get(lk) && (sorts.get(n) === 'int' || sorts.get(lk) === 'int')) {
267
285
  sorts.set(n, 'int');
286
+ sorts.set(lk, 'int');
268
287
  changed = true;
269
288
  }
270
289
  }
@@ -5,6 +5,7 @@ export { proveRule, proveSteps } from './dsl.js';
5
5
  export type PyOptions = StepOptions & {
6
6
  root?: string;
7
7
  python?: string;
8
+ djangoSettings?: string;
8
9
  };
9
10
  export declare function readPython(file: string, names: string[], opts?: {
10
11
  root?: string;
@@ -26,6 +26,6 @@ export function extractPython(at, opts = {}) {
26
26
  return { ok: false, refusals: [{ where: e.where, what: e.what }], notes: [] };
27
27
  throw e;
28
28
  }
29
- const harness = () => ({ cmd: opts.python ?? 'python3', args: [here('harness.py')], env: { PYTHONDONTWRITEBYTECODE: '1' }, hello: { root: mod.root, path: mod.path, module: mod.module } });
29
+ const harness = () => ({ cmd: opts.python ?? 'python3', args: [here('harness.py')], env: { PYTHONDONTWRITEBYTECODE: '1', ...(opts.djangoSettings ? { DJANGO_SETTINGS_MODULE: opts.djangoSettings } : {}) }, hello: { root: mod.root, path: mod.path, module: mod.module } });
30
30
  return extractStep(mod, harness, opts);
31
31
  }
@@ -117,6 +117,7 @@ export type MapWrite = {
117
117
  vals: Record<string, Term>;
118
118
  pre?: MapWrite[];
119
119
  when?: B;
120
+ each?: true;
120
121
  };
121
122
  export type ListOp = {
122
123
  op: 'push';
@@ -208,6 +209,22 @@ export type Fold = {
208
209
  step: Record<string, Term>;
209
210
  len: N;
210
211
  state?: true;
212
+ back?: true;
213
+ loop?: {
214
+ like: [string, string][];
215
+ cond?: B;
216
+ entry?: B;
217
+ drains?: {
218
+ map: string;
219
+ ord: string;
220
+ rk: string;
221
+ held: B;
222
+ by: {
223
+ e: N;
224
+ desc?: boolean;
225
+ }[];
226
+ }[];
227
+ };
211
228
  };
212
229
  type V = {
213
230
  t: 'num';
@@ -839,7 +839,7 @@ export class Exec {
839
839
  // A fraction is a binary float in the code: each operation on it rounds (0.1 + 0.2 is not 0.3), so a rule over ℚ
840
840
  // (gdp-wired/rationals) is the code only where nothing rounds, which no check shows; refused, with what is read.
841
841
  if (op === S.SlashToken)
842
- return refuse(e, 'a division whose result may be a fraction (a binary float in the code: each operation on it rounds, where a rule over the rationals would not; Math.floor or Math.ceil of x / k for a constant k is in the subset)');
842
+ return refuse(e, 'a division whose result may be a fraction (a binary float in the code: each operation on it rounds, where a rule over the rationals would not; Math.floor, Math.ceil or Math.trunc of x / k for a constant k is in the subset; Math.round is not: past 2^52 it isn\'t exact and this reader keeps no edge)');
843
843
  if (op === S.AsteriskAsteriskToken)
844
844
  return refuse(e, 'a power');
845
845
  if (op === S.CommaToken)
@@ -1603,7 +1603,7 @@ export class Exec {
1603
1603
  return undefined;
1604
1604
  }
1605
1605
  math(m, e, p) {
1606
- if (m === 'floor' || m === 'ceil') {
1606
+ if (m === 'floor' || m === 'ceil' || m === 'trunc') {
1607
1607
  const a = e.arguments[0];
1608
1608
  const strip = (x) => (ts.isParenthesizedExpression(x) ? strip(x.expression) : x);
1609
1609
  const d = a && strip(a);
@@ -1614,8 +1614,8 @@ export class Exec {
1614
1614
  const kn = this.num(k, d.right, q2);
1615
1615
  if (kn.op !== 'const' || kn.v < 1)
1616
1616
  return refuse(d.right, `Math.${m}(x / k) by other than a positive constant`);
1617
- const xn = this.num(x, d.left, q2);
1618
- return [{ t: 'num', e: m === 'floor' ? I.divk(kn.v, xn) : I.neg(I.divk(kn.v, I.neg(xn))) }, q2];
1617
+ const xn = this.num(x, d.left, q2), kv = kn.v, fl = I.divk(kv, xn), ce = I.neg(I.divk(kv, I.neg(xn)));
1618
+ return [{ t: 'num', e: m === 'floor' ? fl : m === 'ceil' ? ce : I.nite(I.cmp('<', xn, I.num(0)), ce, fl) }, q2];
1619
1619
  }
1620
1620
  // Of an integer, its value.
1621
1621
  const [x, q] = this.ev(d, p);
@@ -1633,7 +1633,7 @@ export class Exec {
1633
1633
  }
1634
1634
  if (m === 'random')
1635
1635
  return refuse(e, 'Math.random (a step the code takes differently each time)');
1636
- return refuse(e, `Math.${m} (Math.min, Math.max, Math.abs, and Math.floor or Math.ceil of x / k are in the subset)`);
1636
+ return refuse(e, `Math.${m} (Math.min, Math.max, Math.abs, and Math.floor, Math.ceil or Math.trunc of x / k are in the subset)`);
1637
1637
  }
1638
1638
  now(e, p) {
1639
1639
  if (p.nows > 0)
@@ -21,7 +21,11 @@ export function readRust(dir, names, cargo) {
21
21
  catch (e) {
22
22
  throw new Refusal(dir, statedRefusal(e) ?? `the Rust reader didn't run (${String(e.stderr ?? e.message).split('\n').filter(Boolean).slice(-2).join(' | ')}): cargo is needed to extract Rust`);
23
23
  }
24
- return JSON.parse(out);
24
+ const m = JSON.parse(out);
25
+ // (the crate's files not parsing: the reader's error, the source refused with it)
26
+ if (m.error !== undefined)
27
+ throw new Refusal(dir, `the crate doesn't parse: ${typeof m.error === 'string' ? m.error : JSON.stringify(m.error)}`);
28
+ return m;
25
29
  }
26
30
  // `at`: the crate's directory, or a file in it (a path or a URL).
27
31
  export function extractRust(at, opts = {}) {
@@ -632,6 +632,8 @@ function chainOf(s, cls) {
632
632
  const h = c.heritageClauses?.find(x => x.token === ts.SyntaxKind.ExtendsKeyword);
633
633
  if (!h)
634
634
  return chain;
635
+ if (h.types.length !== 1)
636
+ return refuse(h, 'extends must name exactly one base class');
635
637
  c = base(h.types[0].expression, h);
636
638
  }
637
639
  }
@@ -1,10 +1,16 @@
1
1
  import { type Extraction } from './extract.js';
2
2
  import { type FileURL } from './extract-read.js';
3
+ import { type SolidityHarness } from './sol-concrete.js';
4
+ export type { SolidityHarness } from './sol-concrete.js';
3
5
  import { type SModule, type SType, type StepOptions, type StepRead } from './extract-step.js';
4
6
  export { proveRule, proveSteps } from './dsl.js';
5
7
  export type SolOptions = StepOptions & {
6
8
  root?: string;
7
9
  remappings?: string[];
10
+ harness?: 'auto' | false | {
11
+ file: string;
12
+ entry?: string;
13
+ };
8
14
  reentrant?: boolean;
9
15
  solc?: string;
10
16
  anvil?: string;
@@ -18,6 +24,8 @@ type Ast = {
18
24
  };
19
25
  export declare const MOD = "W256$";
20
26
  export type Compiled = {
27
+ harness?: SolidityHarness;
28
+ harnessMethods?: string[];
21
29
  main: number;
22
30
  ast: Map<number, Ast>;
23
31
  text: Map<number, string>;
@@ -50,7 +58,7 @@ export type Compiled = {
50
58
  };
51
59
  }>>;
52
60
  };
53
- export declare function compile(file: string, o: SolOptions): Compiled;
61
+ export declare function compile(file: string, o: SolOptions, extra?: Record<string, string>): Compiled;
54
62
  type Field = {
55
63
  name: string;
56
64
  t: SType;
@@ -88,4 +96,5 @@ export declare function readSolidity(file: string, o?: SolOptions, reenter?: boo
88
96
  };
89
97
  export declare function extractSolidity(at: string | FileURL, opts?: SolOptions): Extraction & {
90
98
  read?: StepRead;
99
+ harness?: SolidityHarness;
91
100
  };