gdp-wired 0.56.0 → 0.57.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.
@@ -6,13 +6,39 @@ import { normalize, program, scriptKind } from "./extract-read.js";
6
6
  const LIMIT = 65536;
7
7
  class TooLarge extends Error {
8
8
  }
9
- function named(n) {
9
+ const unwrap = (n) => {
10
+ while (ts.isParenthesizedExpression(n) || ts.isAsExpression(n) || ts.isSatisfiesExpression(n))
11
+ n = n.expression;
12
+ return n;
13
+ };
14
+ const climb = (n) => {
15
+ let p = n.parent;
16
+ while (p && (ts.isParenthesizedExpression(p) || ts.isAsExpression(p) || ts.isSatisfiesExpression(p)))
17
+ p = p.parent;
18
+ return p;
19
+ };
20
+ // An Effect.fn / Effect.fnUntraced call wrapping a generator method body (with or without a span name).
21
+ function effectFnCall(p, n) {
22
+ if (!n.asteriskToken || !p || !ts.isCallExpression(p) || p.arguments.length !== 1 || unwrap(p.arguments[0]) !== n)
23
+ return undefined;
24
+ const callee = unwrap(p.expression);
25
+ const head = ts.isCallExpression(callee) ? unwrap(callee.expression) : callee;
26
+ if (!ts.isPropertyAccessExpression(head))
27
+ return undefined;
28
+ return (ts.isCallExpression(callee) ? head.name.text === 'fn' : head.name.text === 'fn' || head.name.text === 'fnUntraced') ? p : undefined;
29
+ }
30
+ function named(n, allowEffectFn = false) {
10
31
  if (ts.isFunctionDeclaration(n) || ts.isMethodDeclaration(n))
11
32
  return n.name && (ts.isIdentifier(n.name) || ts.isStringLiteral(n.name)) ? n.name.text : undefined;
12
33
  if (ts.isArrowFunction(n) || ts.isFunctionExpression(n)) {
13
- const p = n.parent;
14
- if ((ts.isVariableDeclaration(p) || ts.isPropertyAssignment(p)) && (ts.isIdentifier(p.name) || ts.isStringLiteral(p.name)))
34
+ const p = climb(n);
35
+ if (p && (ts.isVariableDeclaration(p) || ts.isPropertyAssignment(p)) && (ts.isIdentifier(p.name) || ts.isStringLiteral(p.name)))
15
36
  return p.name.text;
37
+ if (allowEffectFn && ts.isFunctionExpression(n)) {
38
+ const call = effectFnCall(p, n), holder = call && climb(call);
39
+ if (holder && (ts.isVariableDeclaration(holder) || ts.isPropertyAssignment(holder)) && (ts.isIdentifier(holder.name) || ts.isStringLiteral(holder.name)))
40
+ return holder.name.text;
41
+ }
16
42
  }
17
43
  return undefined;
18
44
  }
@@ -25,12 +51,15 @@ export function nativeCaptureEdits(code, file, methods) {
25
51
  return [];
26
52
  const sf = ts.createSourceFile(file, code, ts.ScriptTarget.ES2022, true, scriptKind(file)), edits = [];
27
53
  const visit = (n) => {
28
- if (callable(n) && n.body && methods.includes(named(n) ?? '')) {
29
- const names = n.parameters.flatMap(p => bindingNames(p.name)), capture = `__gdp_native_capture(${JSON.stringify(named(n))}, {${names.join(',')}})`;
30
- if (ts.isBlock(n.body))
31
- edits.push([n.body.getStart(sf) + 1, `${capture};`]);
32
- else
33
- edits.push([n.body.getStart(sf), `(${capture}, (`], [n.body.end, '))']);
54
+ if (callable(n) && n.body) {
55
+ const method = named(n, true);
56
+ if (method && methods.includes(method)) {
57
+ const names = n.parameters.flatMap(p => bindingNames(p.name)), capture = `__gdp_native_capture(${JSON.stringify(method)}, {${names.join(',')}})`;
58
+ if (ts.isBlock(n.body))
59
+ edits.push([n.body.getStart(sf) + 1, `${capture};`]);
60
+ else
61
+ edits.push([n.body.getStart(sf), `(${capture}, (`], [n.body.end, '))']);
62
+ }
34
63
  }
35
64
  ts.forEachChild(n, visit);
36
65
  };
@@ -13,10 +13,22 @@ import { checkDocument, decidedBy, goalsOf } from "./check.js";
13
13
  import { fromInterchange, toInterchange } from "./format.js";
14
14
  const proc = globalThis.process;
15
15
  const fs = proc.getBuiltinModule('node:fs');
16
+ proc.exitCode = 2;
17
+ let completed = false, reported = false;
18
+ const onUnsettled = (ev) => {
19
+ if (completed || reported)
20
+ return;
21
+ reported = true;
22
+ proc.exitCode = 2;
23
+ proc.stderr.write(`gdp-wired: the check did not complete (${ev})\n`);
24
+ };
25
+ proc.on?.('beforeExit', () => onUnsettled('beforeExit'));
26
+ proc.on?.('exit', () => onUnsettled('exit'));
16
27
  const args = proc.argv.slice(2), json = args.includes('--json'), gi = args.indexOf('--goals'), goalsOut = gi >= 0 ? args[gi + 1] : undefined;
17
28
  const files = args.filter((a, i) => !a.startsWith('--') && (gi < 0 || i !== gi + 1));
18
29
  if (!files.length || (gi >= 0 && !goalsOut)) {
19
30
  proc.stderr.write('usage: gdp-wired-check [--json] [--goals <out.json>] <file.json>... (- reads standard input)\n');
31
+ completed = true;
20
32
  proc.exit(2);
21
33
  }
22
34
  const read = (f) => JSON.parse(f === '-' ? fs.readFileSync(0, 'utf8') : fs.readFileSync(f, 'utf8'));
@@ -42,4 +54,5 @@ else
42
54
  for (const c of report.claims)
43
55
  say(` ${c.accepted ? 'accepted' : 'refused '} ${c.name}${c.why ? `: ${c.why}` : ''}`);
44
56
  }
57
+ completed = true;
45
58
  proc.exit(out.every(o => o.report.accepted) ? 0 : 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gdp-wired",
3
- "version": "0.56.0",
3
+ "version": "0.57.0",
4
4
  "description": "An automatic prover for stateful rules (budgets, caps, windows, workflows, policies): laws proven with no proof to write, checked again in Lean, counterexamples found on the GPU, the rule shipped as code",
5
5
  "keywords": [
6
6
  "verification",