gdp-wired 0.44.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.
- package/README.md +58 -7
- package/dist/core/bitsets.d.ts +2 -0
- package/dist/core/bitsets.js +23 -0
- package/dist/core/bmc.js +6 -2
- package/dist/core/c/reader.d.ts +9 -1
- package/dist/core/c/reader.js +445 -38
- package/dist/core/calendar.d.ts +29 -0
- package/dist/core/calendar.js +82 -0
- package/dist/core/check.js +3 -2
- package/dist/core/cli.d.ts +4 -0
- package/dist/core/cli.js +335 -39
- package/dist/core/compose.js +3 -1
- package/dist/core/counts.d.ts +5 -2
- package/dist/core/counts.js +335 -88
- package/dist/core/cycles.js +8 -1
- package/dist/core/cyclic.d.ts +1 -0
- package/dist/core/cyclic.js +13 -7
- package/dist/core/data-synth.d.ts +3 -0
- package/dist/core/data-synth.js +252 -0
- package/dist/core/data.d.ts +8 -2
- package/dist/core/data.js +1113 -172
- package/dist/core/discover.js +3 -1
- package/dist/core/draft.d.ts +19 -0
- package/dist/core/draft.js +53 -0
- package/dist/core/dsl.d.ts +39 -3
- package/dist/core/dsl.js +250 -31
- package/dist/core/effect-prims.js +2 -2
- package/dist/core/effect.d.ts +1 -4
- package/dist/core/effect.js +1 -15
- package/dist/core/ex/reader.exs +17 -1
- package/dist/core/exists.d.ts +16 -1
- package/dist/core/exists.js +447 -50
- package/dist/core/extract-c.d.ts +2 -0
- package/dist/core/extract-c.js +185 -31
- package/dist/core/extract-check.d.ts +7 -0
- package/dist/core/extract-check.js +115 -3
- package/dist/core/extract-ex.js +3 -3
- package/dist/core/extract-go-check.d.ts +1 -1
- package/dist/core/extract-go-check.js +21 -13
- package/dist/core/extract-go.d.ts +1 -0
- package/dist/core/extract-go.js +58 -9
- package/dist/core/extract-ir.d.ts +1 -0
- package/dist/core/extract-ir.js +15 -0
- package/dist/core/extract-jvm.d.ts +1 -1
- package/dist/core/extract-jvm.js +65 -14
- package/dist/core/extract-orm.d.ts +12 -0
- package/dist/core/extract-orm.js +244 -0
- package/dist/core/extract-print.js +23 -1
- package/dist/core/extract-py.d.ts +1 -0
- package/dist/core/extract-py.js +4 -4
- package/dist/core/extract-rb.js +3 -3
- package/dist/core/extract-read.d.ts +25 -0
- package/dist/core/extract-read.js +60 -5
- package/dist/core/extract-rs.js +22 -20
- package/dist/core/extract-shapes.js +22 -0
- package/dist/core/extract-sol.d.ts +10 -1
- package/dist/core/extract-sol.js +89 -30
- package/dist/core/extract-step.d.ts +201 -4
- package/dist/core/extract-step.js +1514 -111
- package/dist/core/extract-swift.js +24 -13
- package/dist/core/extract.d.ts +9 -0
- package/dist/core/extract.js +88 -7
- package/dist/core/fiber-run.d.ts +5 -0
- package/dist/core/fiber-run.js +18 -0
- package/dist/core/fresh.d.ts +2 -2
- package/dist/core/fresh.js +7 -3
- package/dist/core/go/reader.go +7 -1
- package/dist/core/infer.d.ts +4 -1
- package/dist/core/infer.js +1020 -246
- package/dist/core/jvm/JavaReader.java +33 -8
- package/dist/core/jvm/Jvm.java +20 -1
- package/dist/core/jvm/KtReader.java +59 -6
- package/dist/core/laws.d.ts +10 -3
- package/dist/core/laws.js +193 -14
- package/dist/core/machine.d.ts +16 -3
- package/dist/core/machine.js +212 -28
- package/dist/core/nonterm.js +14 -1
- package/dist/core/orm/harness.js +61 -0
- package/dist/core/orm-fixtures/schema.prisma +5 -0
- package/dist/core/py/harness.py +260 -21
- package/dist/core/py/reader.py +278 -39
- package/dist/core/rb/reader.rb +52 -5
- package/dist/core/reader-fixtures/README.md +28 -0
- package/dist/core/reader-fixtures/c-693042.cpp +8 -0
- package/dist/core/reader-fixtures/go-685506.go +14 -0
- package/dist/core/reader-fixtures/jvm-724362.kt +8 -0
- package/dist/core/reader-fixtures/jvm-737430.kt +7 -0
- package/dist/core/reader-fixtures/jvm-765282.kt +3 -0
- package/dist/core/reader-fixtures/swift-735726.swift +15 -0
- package/dist/core/reader-fixtures/swift-735990.swift +15 -0
- package/dist/core/reader-fixtures/swift-739158.swift +4 -0
- package/dist/core/reader-fixtures/swift-744834.swift +15 -0
- package/dist/core/reader-fixtures/swift-746946.swift +31 -0
- package/dist/core/reader-fixtures/typescript-673062.ts.txt +2 -0
- package/dist/core/relation.d.ts +1 -1
- package/dist/core/relation.js +29 -2
- package/dist/core/relational.js +4 -2
- package/dist/core/rs/src/main.rs +18 -2
- package/dist/core/sample-cache.d.ts +8 -0
- package/dist/core/sample-cache.js +46 -0
- package/dist/core/security.d.ts +38 -0
- package/dist/core/security.js +88 -0
- package/dist/core/sol/harness.py +63 -7
- package/dist/core/sol-concrete.d.ts +23 -0
- package/dist/core/sol-concrete.js +195 -0
- package/dist/core/solver.js +8 -5
- package/dist/core/swift/Sources/gdp-swiftreader/main.swift +50 -7
- package/dist/core/system.d.ts +62 -1
- package/dist/core/system.js +263 -4
- package/dist/core/transfer.js +39 -9
- package/dist/core/translate.js +39 -10
- package/dist/core/watch.js +51 -6
- package/dist/interchange/check.js +10 -10
- package/dist/interchange/format.d.ts +4 -0
- package/dist/interchange/format.js +24 -6
- package/dist/kernel/cdcl.d.ts +5 -0
- package/dist/kernel/cdcl.js +88 -10
- package/dist/kernel/epr.js +141 -29
- package/dist/kernel/kernel.d.ts +31 -1
- package/dist/kernel/kernel.js +391 -101
- package/dist/kernel/model-sequence.d.ts +3 -0
- package/dist/kernel/model-sequence.js +34 -0
- package/dist/kernel/prove.d.ts +30 -1
- package/dist/kernel/prove.js +481 -71
- package/dist/kernel/reader.d.ts +3 -0
- package/dist/kernel/reader.js +101 -14
- package/dist/kernel/share.d.ts +1 -0
- package/dist/kernel/share.js +27 -0
- package/dist/lean-kernel/emit.d.ts +9 -3
- package/dist/lean-kernel/emit.js +200 -66
- package/dist/lean-kernel/lean-terms.js +5 -0
- package/dist/lean-kernel/library.js +10 -10
- package/package.json +7 -2
|
@@ -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
|
|
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
|
}
|
|
@@ -375,6 +394,9 @@ function pn(e, P, ctx, mode, recv = false) {
|
|
|
375
394
|
const d = decided(e.c, ctx);
|
|
376
395
|
if (d !== undefined)
|
|
377
396
|
return pn(d ? e.a : e.b, P, ctx, mode, recv);
|
|
397
|
+
// (a natural by cases read as an integer's receiver: its when(...) a natural's, made an integer, or minus stops at 0)
|
|
398
|
+
if (!nat && recv && natOK(e, ctx))
|
|
399
|
+
return `Int.of(${pn(e, P, ctx, 'nat')})`;
|
|
378
400
|
const ca = withAtom(ctx, e.c), cb = withAtom(ctx, I.not(e.c));
|
|
379
401
|
const side = (x, c) => pn(x, P, c, nat ? 'nat' : natOK(x, c) ? 'nat' : 'int');
|
|
380
402
|
return `when(${pb(e.c, P, ctx)}, ${side(e.a, ca)}, ${side(e.b, cb)})`;
|
package/dist/core/extract-py.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Refusal, pathOf } from "./extract-read.js";
|
|
1
|
+
import { Refusal, pathOf, readerRun, statedRefusal } from "./extract-read.js";
|
|
2
2
|
import { asset, entryNames, extractStep, node } from "./extract-step.js";
|
|
3
3
|
export { proveRule, proveSteps } from "./dsl.js";
|
|
4
4
|
const here = (f) => asset(`py/${f}`);
|
|
@@ -8,10 +8,10 @@ export function readPython(file, names, opts = {}) {
|
|
|
8
8
|
const abs = path.resolve(file), root = path.resolve(opts.root ?? path.dirname(abs));
|
|
9
9
|
let out;
|
|
10
10
|
try {
|
|
11
|
-
out = cp.execFileSync(opts.python ?? 'python3', ['-I', here('reader.py'), JSON.stringify({ root, file: abs, names })], { encoding: 'utf8', maxBuffer: 1 << 29, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
11
|
+
out = cp.execFileSync(opts.python ?? 'python3', ['-I', here('reader.py'), JSON.stringify({ root, file: abs, names })], { encoding: 'utf8', maxBuffer: 1 << 29, stdio: ['ignore', 'pipe', 'pipe'], ...readerRun() });
|
|
12
12
|
}
|
|
13
13
|
catch (e) {
|
|
14
|
-
throw new Refusal(file, `the Python reader didn't run (${String(e.stderr ?? e.message).split('\n').filter(Boolean).slice(-2).join(' | ')}): python3 is needed to extract Python`);
|
|
14
|
+
throw new Refusal(file, statedRefusal(e) ?? `the Python reader didn't run (${String(e.stderr ?? e.message).split('\n').filter(Boolean).slice(-2).join(' | ')}): python3 is needed to extract Python`);
|
|
15
15
|
}
|
|
16
16
|
return JSON.parse(out);
|
|
17
17
|
}
|
|
@@ -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
|
}
|
package/dist/core/extract-rb.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Refusal, pathOf } from "./extract-read.js";
|
|
1
|
+
import { Refusal, pathOf, readerRun, statedRefusal } from "./extract-read.js";
|
|
2
2
|
import { asset, entryNames, extractStep, node } from "./extract-step.js";
|
|
3
3
|
export { proveRule, proveSteps } from "./dsl.js";
|
|
4
4
|
const here = (f) => asset(`rb/${f}`);
|
|
@@ -8,10 +8,10 @@ export function readRuby(file, names, opts = {}) {
|
|
|
8
8
|
const abs = path.resolve(file), root = path.resolve(opts.root ?? path.dirname(abs));
|
|
9
9
|
let out;
|
|
10
10
|
try {
|
|
11
|
-
out = cp.execFileSync(opts.ruby ?? 'ruby', [here('reader.rb'), JSON.stringify({ root, file: abs, names, clocks: opts.clocks ?? [] })], { encoding: 'utf8', maxBuffer: 1 << 29, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
11
|
+
out = cp.execFileSync(opts.ruby ?? 'ruby', [here('reader.rb'), JSON.stringify({ root, file: abs, names, clocks: opts.clocks ?? [] })], { encoding: 'utf8', maxBuffer: 1 << 29, stdio: ['ignore', 'pipe', 'pipe'], ...readerRun() });
|
|
12
12
|
}
|
|
13
13
|
catch (e) {
|
|
14
|
-
throw new Refusal(file, `the Ruby reader didn't run (${String(e.stderr ?? e.message).split('\n').filter(Boolean).slice(-2).join(' | ')}): ruby 3.3 or later (with Prism) is needed to extract Ruby`);
|
|
14
|
+
throw new Refusal(file, statedRefusal(e) ?? `the Ruby reader didn't run (${String(e.stderr ?? e.message).split('\n').filter(Boolean).slice(-2).join(' | ')}): ruby 3.3 or later (with Prism) is needed to extract Ruby`);
|
|
15
15
|
}
|
|
16
16
|
return JSON.parse(out);
|
|
17
17
|
}
|
|
@@ -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';
|
|
@@ -321,12 +338,19 @@ export type Source = string | FileURL | {
|
|
|
321
338
|
code: string;
|
|
322
339
|
file?: string;
|
|
323
340
|
};
|
|
341
|
+
export declare const readerRun: () => {
|
|
342
|
+
timeout: number;
|
|
343
|
+
killSignal: string;
|
|
344
|
+
};
|
|
345
|
+
export declare const statedRefusal: (e: unknown) => string | undefined;
|
|
346
|
+
export declare const tooDeep: (e: unknown) => boolean;
|
|
324
347
|
export declare const pathOf: (at: string | FileURL) => string;
|
|
325
348
|
export declare function sourceOf(at: Source, file: string | undefined, dflt: string): {
|
|
326
349
|
code: string;
|
|
327
350
|
file: string;
|
|
328
351
|
};
|
|
329
352
|
export declare function beside<T>(file: string, spec: string): T | undefined;
|
|
353
|
+
export declare function syntaxError(code: string, file: string): string | undefined;
|
|
330
354
|
export declare const scriptKind: (file: string) => ts.ScriptKind;
|
|
331
355
|
export declare function shapeOf(t: ts.Type, checker: ts.TypeChecker, at: ts.Node, inner?: string): Shape;
|
|
332
356
|
type Callable = {
|
|
@@ -427,6 +451,7 @@ export declare class Exec {
|
|
|
427
451
|
vals: Map<string, V>;
|
|
428
452
|
};
|
|
429
453
|
private access;
|
|
454
|
+
private absent;
|
|
430
455
|
private mapGet;
|
|
431
456
|
private mapId;
|
|
432
457
|
mapSet(id: string, key: K, v: V | undefined, at: ts.Node, p: Path, track?: boolean): Path;
|
|
@@ -71,6 +71,20 @@ export function placed(file) {
|
|
|
71
71
|
return (/^([A-Za-z]:)?[\\/]/.test(file) ? file : `${cwd}/${file}`).replace(/\\/g, '/');
|
|
72
72
|
}
|
|
73
73
|
const builtin = (id) => globalThis.process?.getBuiltinModule?.(id);
|
|
74
|
+
// A reader process's time on one source: GDP_READER_S seconds (300), past which it is killed and the source refused (a
|
|
75
|
+
// parser recovering from deep unclosed nesting, the Kotlin compiler's, took 23 minutes on one).
|
|
76
|
+
export const readerRun = () => ({ timeout: Number(globalThis.process?.env?.GDP_READER_S ?? 300) * 1000, killSignal: 'SIGKILL' });
|
|
77
|
+
// What a reader process that failed said it refuses: a line `gdp: refused: …` on its stderr (source it can't read: a
|
|
78
|
+
// syntax error, nesting past its stack), or that it ran past its time; undefined where it said none (it didn't run:
|
|
79
|
+
// the tool is missing).
|
|
80
|
+
export const statedRefusal = (e) => {
|
|
81
|
+
const x = e, text = typeof x.stderr === 'string' ? x.stderr : x.stderr ? new TextDecoder().decode(x.stderr) : '';
|
|
82
|
+
if (x.code === 'ETIMEDOUT' || x.signal === 'SIGKILL')
|
|
83
|
+
return `the reader didn't finish within ${readerRun().timeout / 1000} s on this source`;
|
|
84
|
+
return /^gdp: refused: (.*)$/m.exec(text)?.[1];
|
|
85
|
+
};
|
|
86
|
+
// Source nested past what a reader's recursion holds (a stack overflow in TypeScript's parser): refused where it is.
|
|
87
|
+
export const tooDeep = (e) => e instanceof RangeError && /call stack/i.test(e.message);
|
|
74
88
|
export const pathOf = (at) => (typeof at === 'string' ? at : builtin('node:url').fileURLToPath(at.href));
|
|
75
89
|
// A TypeScript front end's source. A string is the code where it can't be a path (a line break, or no script's
|
|
76
90
|
// extension): the code-first call, as it was.
|
|
@@ -97,6 +111,28 @@ export function beside(file, spec) {
|
|
|
97
111
|
return undefined;
|
|
98
112
|
}
|
|
99
113
|
}
|
|
114
|
+
// The first syntax error TypeScript's parser reports in a module, where it is, or undefined: its parser recovers from
|
|
115
|
+
// each, and the tree it leaves is not the code that runs (which then doesn't load).
|
|
116
|
+
export function syntaxError(code, file) {
|
|
117
|
+
const sf = ts.createSourceFile(file, code, ts.ScriptTarget.ES2022, true, scriptKind(file));
|
|
118
|
+
const d = sf.parseDiagnostics?.[0];
|
|
119
|
+
// (two declarations of one name at the module's top level: TypeScript refuses it, JavaScript keeps the last)
|
|
120
|
+
const seen = new Set();
|
|
121
|
+
for (const st of sf.statements) {
|
|
122
|
+
const names = (ts.isFunctionDeclaration(st) && st.body) || ts.isClassDeclaration(st) ? (st.name ? [st.name.text] : []) : ts.isVariableStatement(st) && st.declarationList.flags & ts.NodeFlags.BlockScoped ? st.declarationList.declarations.flatMap(x => (ts.isIdentifier(x.name) ? [x.name.text] : [])) : [];
|
|
123
|
+
for (const n of names) {
|
|
124
|
+
if (seen.has(n)) {
|
|
125
|
+
const { line, character } = sf.getLineAndCharacterOfPosition(st.getStart());
|
|
126
|
+
return `the source declares ${n} twice at its top level: ${line + 1}:${character + 1} (TypeScript refuses it; JavaScript keeps the last)`;
|
|
127
|
+
}
|
|
128
|
+
seen.add(n);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (!d)
|
|
132
|
+
return undefined;
|
|
133
|
+
const { line, character } = sf.getLineAndCharacterOfPosition(d.start ?? 0);
|
|
134
|
+
return `the source doesn't parse: ${line + 1}:${character + 1}: ${ts.flattenDiagnosticMessageText(d.messageText, ' ')}`;
|
|
135
|
+
}
|
|
100
136
|
export const scriptKind = (file) => (/\.jsx$/.test(file) ? ts.ScriptKind.JSX : /\.tsx$/.test(file) ? ts.ScriptKind.TSX : /\.[cm]?js$/.test(file) ? ts.ScriptKind.JS : ts.ScriptKind.TS);
|
|
101
137
|
// The shape a type has in the subset.
|
|
102
138
|
// (`inner`: the field path inside the value at `at` that t is the type of, for where a refusal says it is)
|
|
@@ -695,6 +731,10 @@ export class Exec {
|
|
|
695
731
|
return refuse(e, `${e.text}: a module-level let (state outside the step)`);
|
|
696
732
|
if (ts.isArrowFunction(decl.initializer) || ts.isFunctionExpression(decl.initializer))
|
|
697
733
|
return refuse(e, `${e.text}: a function used as a value`);
|
|
734
|
+
// (the clock read where the module loads: that time, once, never a request's)
|
|
735
|
+
const clock = (n) => ((ts.isCallExpression(n) && /^(Date\.now|performance\.now)$/.test(n.expression.getText())) || (ts.isNewExpression(n) && n.expression.getText() === 'Date' && !n.arguments?.length)) || ts.forEachChild(n, x => clock(x) || undefined) === true;
|
|
736
|
+
if (clock(decl.initializer))
|
|
737
|
+
return refuse(e, `${e.text}: a module-level const that reads the clock (the time the module loaded, not the request's)`);
|
|
698
738
|
// A module-level const: its value, an object read-only (every call shares it).
|
|
699
739
|
const id = `shared.${decl.getSourceFile().fileName}:${e.text}`;
|
|
700
740
|
if (p.heap.has(id))
|
|
@@ -799,7 +839,7 @@ export class Exec {
|
|
|
799
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 ℚ
|
|
800
840
|
// (gdp-wired/rationals) is the code only where nothing rounds, which no check shows; refused, with what is read.
|
|
801
841
|
if (op === S.SlashToken)
|
|
802
|
-
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.
|
|
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)');
|
|
803
843
|
if (op === S.AsteriskAsteriskToken)
|
|
804
844
|
return refuse(e, 'a power');
|
|
805
845
|
if (op === S.CommaToken)
|
|
@@ -1086,6 +1126,8 @@ export class Exec {
|
|
|
1086
1126
|
}
|
|
1087
1127
|
if (f === 'length')
|
|
1088
1128
|
return refuse(e, 'length of a string (strings are compared and set in the subset)');
|
|
1129
|
+
if (this.absent(e))
|
|
1130
|
+
return refuse(e, `${text(e)}: ${f}, a property its type doesn't have there (undefined where it runs)`);
|
|
1089
1131
|
return this.field(base, f, e, q);
|
|
1090
1132
|
}
|
|
1091
1133
|
const arg = e.argumentExpression;
|
|
@@ -1108,6 +1150,19 @@ export class Exec {
|
|
|
1108
1150
|
return this.field(base, arg.text, e, q);
|
|
1109
1151
|
return refuse(e, 'an index into other than a record keyed by strings or numbers');
|
|
1110
1152
|
}
|
|
1153
|
+
// (TypeScript's: a property the type of what it is read of, narrowed there, doesn't have, where the files read declare it)
|
|
1154
|
+
absent(e) {
|
|
1155
|
+
const c = this.s.checker, sf = e.getSourceFile();
|
|
1156
|
+
if (!/\.[cm]?tsx?$/.test(sf.fileName) || sf.isDeclarationFile)
|
|
1157
|
+
return false;
|
|
1158
|
+
const t = c.getApparentType(c.getTypeAtLocation(e.expression));
|
|
1159
|
+
// (only a type the files read declare: one of a library's declarations may not be what runs, another version's)
|
|
1160
|
+
const own = (x) => !!(x.aliasSymbol ?? x.getSymbol())?.declarations?.some(d => !d.getSourceFile().isDeclarationFile);
|
|
1161
|
+
if (!(t.isUnion() ? t.types : [t]).every(own))
|
|
1162
|
+
return false;
|
|
1163
|
+
return !(t.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown | ts.TypeFlags.Never)) && !!(t.flags & (ts.TypeFlags.Object | ts.TypeFlags.Union | ts.TypeFlags.Intersection)) &&
|
|
1164
|
+
!c.getPropertyOfType(t, memberName(e.name)) && !c.getIndexInfosOfType(t).length;
|
|
1165
|
+
}
|
|
1111
1166
|
mapGet(id, key, p) {
|
|
1112
1167
|
const m = this.obj(p, id), cell = this.readCell(m, key);
|
|
1113
1168
|
if (m.decl.scalar)
|
|
@@ -1548,7 +1603,7 @@ export class Exec {
|
|
|
1548
1603
|
return undefined;
|
|
1549
1604
|
}
|
|
1550
1605
|
math(m, e, p) {
|
|
1551
|
-
if (m === 'floor' || m === 'ceil') {
|
|
1606
|
+
if (m === 'floor' || m === 'ceil' || m === 'trunc') {
|
|
1552
1607
|
const a = e.arguments[0];
|
|
1553
1608
|
const strip = (x) => (ts.isParenthesizedExpression(x) ? strip(x.expression) : x);
|
|
1554
1609
|
const d = a && strip(a);
|
|
@@ -1559,8 +1614,8 @@ export class Exec {
|
|
|
1559
1614
|
const kn = this.num(k, d.right, q2);
|
|
1560
1615
|
if (kn.op !== 'const' || kn.v < 1)
|
|
1561
1616
|
return refuse(d.right, `Math.${m}(x / k) by other than a positive constant`);
|
|
1562
|
-
const xn = this.num(x, d.left, q2);
|
|
1563
|
-
return [{ t: 'num', e: m === 'floor' ?
|
|
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];
|
|
1564
1619
|
}
|
|
1565
1620
|
// Of an integer, its value.
|
|
1566
1621
|
const [x, q] = this.ev(d, p);
|
|
@@ -1578,7 +1633,7 @@ export class Exec {
|
|
|
1578
1633
|
}
|
|
1579
1634
|
if (m === 'random')
|
|
1580
1635
|
return refuse(e, 'Math.random (a step the code takes differently each time)');
|
|
1581
|
-
return refuse(e, `Math.${m} (Math.min, Math.max, Math.abs, and Math.floor or Math.
|
|
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)`);
|
|
1582
1637
|
}
|
|
1583
1638
|
now(e, p) {
|
|
1584
1639
|
if (p.nows > 0)
|
package/dist/core/extract-rs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Refusal, pathOf } from "./extract-read.js";
|
|
2
|
-
import { asset, entryNames, extractStep, node, stubbed } from "./extract-step.js";
|
|
1
|
+
import { Refusal, pathOf, readerRun, statedRefusal } from "./extract-read.js";
|
|
2
|
+
import { asset, buildCheck, compileLimit, entryNames, extractStep, node, stubbed } from "./extract-step.js";
|
|
3
3
|
export { proveRule, proveSteps } from "./dsl.js";
|
|
4
4
|
const proc = globalThis.process;
|
|
5
5
|
// The reader, built once per version of its source (into the system's temporary directory).
|
|
@@ -16,12 +16,16 @@ export function readRust(dir, names, cargo) {
|
|
|
16
16
|
const cp = node('node:child_process');
|
|
17
17
|
let out;
|
|
18
18
|
try {
|
|
19
|
-
out = cp.execFileSync(rsReader(cargo), [JSON.stringify({ root: dir, names })], { encoding: 'utf8', maxBuffer: 1 << 29, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
19
|
+
out = cp.execFileSync(rsReader(cargo), [JSON.stringify({ root: dir, names })], { encoding: 'utf8', maxBuffer: 1 << 29, stdio: ['ignore', 'pipe', 'pipe'], ...readerRun() });
|
|
20
20
|
}
|
|
21
21
|
catch (e) {
|
|
22
|
-
throw new Refusal(dir, `the Rust reader didn't run (${String(e.stderr ?? e.message).split('\n').filter(Boolean).slice(-2).join(' | ')}): cargo is needed to extract Rust`);
|
|
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
|
-
|
|
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 = {}) {
|
|
@@ -271,24 +275,22 @@ function harnessFor(dir, mod, read, opts) {
|
|
|
271
275
|
if (t !== s)
|
|
272
276
|
fs.writeFileSync(f, t);
|
|
273
277
|
}
|
|
278
|
+
// (the lines of the code itself in the files the harness is appended to: an error past them is the harness's)
|
|
279
|
+
const own = new Map([file, lib].map(f => [f, fs.readFileSync(`${work}/${f}`, 'utf8').split('\n').length]));
|
|
274
280
|
fs.writeFileSync(`${work}/${file}`, fs.readFileSync(`${work}/${file}`, 'utf8') + harnessCode(mod, read, cls));
|
|
275
281
|
fs.writeFileSync(`${work}/${lib}`, `${fs.readFileSync(`${work}/${lib}`, 'utf8')}\n#[cfg(test)]\n#[allow(unused)]\npub(crate) fn __gdp_now() -> std::time::Instant { ${modPath}::__gdp_harness::now() }\n#[cfg(test)]\n#[allow(unused)]\npub(crate) fn __gdp_answer<T: ${modPath}::__gdp_harness::GdpAns>(k: &str) -> T { ${modPath}::__gdp_harness::answer(k) }\n`);
|
|
276
282
|
const target = `${os.tmpdir()}/gdp-rscheck-target`;
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
}
|
|
281
|
-
catch (e) {
|
|
282
|
-
const out = String(e.stdout ?? '');
|
|
283
|
-
const errs = out.split('\n').flatMap(l => { try {
|
|
284
|
-
const j = JSON.parse(l);
|
|
285
|
-
return j.reason === 'compiler-message' && j.message?.level === 'error' ? [j.message.rendered ?? ''] : [];
|
|
286
|
-
}
|
|
287
|
-
catch {
|
|
288
|
-
return [];
|
|
289
|
-
} });
|
|
290
|
-
return { cmd: 'false', args: [], hello: {}, error: `the crate doesn't build with the check's harness: ${(errs.join(' | ') || String(e.stderr ?? '')).replace(/\s+/g, ' ').slice(0, 600)}` };
|
|
283
|
+
const built = buildCheck('cargo', () => cp.execFileSync(opts.cargo ?? 'cargo', ['test', '--lib', '--no-run', '--message-format=json', '--target-dir', target], { cwd: work, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 1 << 28, env: { ...proc?.env }, timeout: compileLimit(), killSignal: 'SIGKILL' }), e => String(e.stdout ?? '').split('\n').flatMap(l => { try {
|
|
284
|
+
const j = JSON.parse(l);
|
|
285
|
+
return j.reason === 'compiler-message' && j.message?.level === 'error' ? [(j.message.rendered ?? '').replace(/\s+/g, ' ')] : [];
|
|
291
286
|
}
|
|
287
|
+
catch {
|
|
288
|
+
return [];
|
|
289
|
+
} }), l => { const m = /--> ([^\s:]+\.rs):(\d+):\d+/.exec(l); if (!m)
|
|
290
|
+
return false; const n = own.get(m[1]); return n === undefined || Number(m[2]) <= n; });
|
|
291
|
+
if (!('ok' in built))
|
|
292
|
+
return { cmd: 'false', args: [], hello: {}, error: built.why, kind: built.kind };
|
|
293
|
+
const msgs = built.ok;
|
|
292
294
|
const exe = msgs.split('\n').flatMap(l => { try {
|
|
293
295
|
const j = JSON.parse(l);
|
|
294
296
|
return j.reason === 'compiler-artifact' && j.executable && j.target?.kind?.includes('lib') ? [j.executable] : [];
|
|
@@ -297,7 +299,7 @@ function harnessFor(dir, mod, read, opts) {
|
|
|
297
299
|
return [];
|
|
298
300
|
} })[0];
|
|
299
301
|
if (!exe)
|
|
300
|
-
return { cmd: 'false', args: [], hello: {}, error: 'the test build gave no executable' };
|
|
302
|
+
return { cmd: 'false', args: [], hello: {}, error: 'the test build gave no executable', kind: 'harness' };
|
|
301
303
|
read.model.notes.push('Rust: the code is checked in a debug build (overflow checks on); its branch arms are not counted (no instrumentation yet)');
|
|
302
304
|
read.arms.length = 0;
|
|
303
305
|
const test = `${modPath === 'crate' ? '' : `${modPath.replace(/^crate::/, '')}::`}__gdp_harness::__gdp_harness_main`;
|