gdp-wired 0.54.0 → 0.54.2

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.
@@ -143,10 +143,16 @@ function locate(root) {
143
143
  }
144
144
  // (doc comments, FullComment and its parts, are no code)
145
145
  // (a for's absent parts are empty objects, kind-less)
146
- else if (k === 'inner') {
147
- n.inner = n.inner.filter(c => !(c.kind ?? '').endsWith('Comment'));
148
- for (const c of n.inner)
149
- walk(c);
146
+ else if (k === 'inner' || k === 'array_filler') {
147
+ const val = n[k];
148
+ if (Array.isArray(val)) {
149
+ const filtered = val.filter(c => !(c.kind ?? '').endsWith('Comment'));
150
+ n[k] = filtered;
151
+ for (const c of filtered)
152
+ walk(c);
153
+ }
154
+ else if (val && typeof val === 'object')
155
+ walk(val);
150
156
  }
151
157
  }
152
158
  n.$at ??= n.$b;
@@ -680,6 +686,42 @@ export function readC(file, entry, tu, target, cpp = false, root, picks = {}, pi
680
686
  // (a float's value: left out, a value nothing the rule keeps may read; one read into an integer, a condition or a
681
687
  // comparison is refused there. Its operands are the code's measurements: an assignment or a call of the file's own
682
688
  // inside it is refused, its effect would be lost.)
689
+ // Clang's JSON AST emits array_filler as [filler, ...semanticInits] with no inner key when an
690
+ // InitListExpr has an array filler (partial or designated initializers). Handle both that form
691
+ // and a separated array_filler + inner form, and refuse unknown/union shapes.
692
+ const initListChildren = (n) => {
693
+ if (n.kind !== 'InitListExpr' || 'field' in n)
694
+ return undefined;
695
+ const rawFiller = n.array_filler;
696
+ if (rawFiller === undefined)
697
+ return { elems: n.inner ?? [] };
698
+ if (Array.isArray(rawFiller)) {
699
+ if (!rawFiller.length)
700
+ return undefined;
701
+ if (n.inner === undefined)
702
+ return { filler: rawFiller[0], elems: rawFiller.slice(1) };
703
+ if (rawFiller.length === 1)
704
+ return { filler: rawFiller[0], elems: n.inner };
705
+ return undefined;
706
+ }
707
+ if (typeof rawFiller === 'object' && rawFiller !== null && 'kind' in rawFiller && n.inner !== undefined)
708
+ return { filler: rawFiller, elems: n.inner };
709
+ return undefined;
710
+ };
711
+ const isAllZeroInit = (n0) => {
712
+ const n = strip(n0);
713
+ if (n.kind === 'ImplicitValueInitExpr')
714
+ return true;
715
+ if (n.kind === 'InitListExpr') {
716
+ const il = initListChildren(n);
717
+ if (!il)
718
+ return false;
719
+ if (il.filler && strip(il.filler).kind !== 'ImplicitValueInitExpr')
720
+ return false;
721
+ return il.elems.every(isAllZeroInit);
722
+ }
723
+ return fold(n) === 0;
724
+ };
683
725
  // A constant table read at indices (a transition table, a lookup; a const or constexpr array, a class's static one):
684
726
  // its entry by cases on the indices, each index outside its dimension undefined behavior, the step's failure (checked
685
727
  // before the statement, so the index must be free of side effects and read where the statement surely reads it).
@@ -707,12 +749,27 @@ export function readC(file, entry, tu, target, cpp = false, root, picks = {}, pi
707
749
  if (dims.length !== idx.length || !['int', 'bool'].includes(T(t).k))
708
750
  return no(n, `${text(n)}: a table read other than at every one of its dimensions`);
709
751
  const val = (v, path, k) => {
752
+ if (!v)
753
+ return NaN;
754
+ const s0 = strip(v);
755
+ if (s0.kind === 'ImplicitValueInitExpr')
756
+ return 0;
710
757
  if (k === dims.length) {
711
- const f = v ? fold(v) : 0;
758
+ const f = fold(s0);
712
759
  return f ?? NaN;
713
760
  }
714
- const s0 = v ? strip(v) : undefined, kids = s0?.kind === 'InitListExpr' ? (s0.inner ?? []) : [];
715
- return val(kids[path[k]], path, k + 1);
761
+ const il = initListChildren(s0);
762
+ if (!il)
763
+ return NaN;
764
+ const { elems, filler } = il;
765
+ if (elems.length > dims[k] || elems.some(c => c.kind === 'DesignatedInitExpr' || c.kind === 'DesignatedInitUpdateExpr' || c.kind === 'NoInitExpr'))
766
+ return NaN;
767
+ if (filler && strip(filler).kind !== 'ImplicitValueInitExpr')
768
+ return NaN;
769
+ if (elems.length < dims[k] && !filler)
770
+ return NaN;
771
+ const i = path[k];
772
+ return val(i < elems.length ? elems[i] : filler, path, k + 1);
716
773
  };
717
774
  if (idx.some(effects))
718
775
  return no(n, `${text(n)}: a table read at an index with a side effect`);
@@ -881,6 +938,8 @@ export function readC(file, entry, tu, target, cpp = false, root, picks = {}, pi
881
938
  case 'CompoundLiteralExpr': return x(kids[0]);
882
939
  case 'InitListExpr': {
883
940
  // A struct's initializer: clang's semantic form lists every field, one not given an implicit zero.
941
+ if (n.array_filler !== undefined)
942
+ return no(n, `${text(n)}: an array initializer of a ${n.type.qualType}`);
884
943
  const tt = T(t);
885
944
  // (a scalar's braces, C++'s {v} and {})
886
945
  if ((tt.k === 'int' || tt.k === 'bool') && kids.length <= 1)
@@ -1199,7 +1258,7 @@ export function readC(file, entry, tu, target, cpp = false, root, picks = {}, pi
1199
1258
  const pre = [];
1200
1259
  for (const g of gnodes) {
1201
1260
  const v = g.init ? (g.inner ?? []).find(c => !c.kind.endsWith('Attr')) : undefined, t = tyOf(g.type);
1202
- const empty = !v || (strip(v).kind === 'InitListExpr' && (strip(v).inner ?? []).every(c => c.kind === 'ImplicitValueInitExpr'));
1261
+ const empty = !v || isAllZeroInit(v);
1203
1262
  // (C's zero, leaf by leaf: each integer and boolean of it 0, an array a list of zeros already)
1204
1263
  const zeros = (tt, place) => {
1205
1264
  const k = T(tt).k;
@@ -1234,7 +1293,7 @@ export function readC(file, entry, tu, target, cpp = false, root, picks = {}, pi
1234
1293
  const pre = [];
1235
1294
  for (const [id, v0] of inits) {
1236
1295
  const f = fieldNode.get(id), ft = T(tyOf(f.type)), v = strip(v0);
1237
- if (ft.mutex || (v.kind === 'InitListExpr' && (v.inner ?? []).every(k => k.kind === 'ImplicitValueInitExpr')))
1296
+ if (ft.mutex || (v.kind === 'InitListExpr' && isAllZeroInit(v)))
1238
1297
  continue;
1239
1298
  if (v.kind === 'CXXConstructExpr' && !v.inner?.length)
1240
1299
  continue;
@@ -20,7 +20,7 @@
20
20
  import { checkRefutation } from "../core/check.js";
21
21
  import { observeCheckStep, observeTableCells } from "../core/meter.js";
22
22
  import { admittedLinearSub as rowSub, admittedLinearAdd as rowAdd, admittedLinearScale as rowScale, admittedLinearCopy as rowCopy, admittedLinearVariable as rowVariable, visitLinearCells } from "../core/linear-admission.js";
23
- import { parseWordDivisionName, wordDivisionArgs, wordDivisionFacts } from "./word-division.js";
23
+ import { hasWordDivision, parseWordDivisionName, wordDivisionArgs, wordDivisionFacts } from "./word-division.js";
24
24
  import { fundedAdd as add, fundedConstant as k, fundedScale as scale, fundedSub as sub, fundedVariable as v, admittedLinearProduct, everyLinearCell } from "../core/linear-admission.js";
25
25
  import { workMap, workFilter, workConcat, workStrings, workJoin, workSlice, workSetArray, workEntries, workJSON, workFlatMap, workArraySlice } from "../core/work-collections.js";
26
26
  import { completeWorkProfile } from "../core/work-profile.js";
@@ -1042,43 +1042,86 @@ const naturalC = (c) => c.op === 'flag' ? true : c.op === 'all' ? naturalC(c.c)
1042
1042
  // record the kernel reads by a name of the rule or the certificate reads it so, and every Lin is built on no prototype,
1043
1043
  // where a name __proto__ is a key like any other.)
1044
1044
  export const own = (r, k) => (Object.hasOwn(r, k) ? r[k] : undefined);
1045
- export function substE(e, s) {
1046
- switch (e.op) {
1047
- case 'var': return own(s.vars, e.name) ?? e;
1048
- case 'const': return e;
1049
- case 'mul': return { ...e, a: substE(e.a, s) };
1050
- case 'prod': return { ...e, a: substE(e.a, s), b: substE(e.b, s) };
1051
- case 'if': return { op: 'if', c: substC(e.c, s), then: substE(e.then, s), else: substE(e.else, s) };
1052
- case 'get': {
1053
- const key = substE(e.key, s), f = own(s.maps, e.map);
1054
- return f ? f(key) : { op: 'get', map: e.map, key };
1045
+ function substWith(s) {
1046
+ const me = new WeakMap(), mc = new WeakMap();
1047
+ const se = (e) => {
1048
+ const hit = me.get(e);
1049
+ if (hit !== undefined)
1050
+ return hit;
1051
+ let out;
1052
+ switch (e.op) {
1053
+ case 'var':
1054
+ out = own(s.vars, e.name) ?? e;
1055
+ break;
1056
+ case 'const':
1057
+ out = e;
1058
+ break;
1059
+ case 'mul':
1060
+ case 'proj': {
1061
+ const a = se(e.a);
1062
+ out = a === e.a ? e : { ...e, a };
1063
+ break;
1064
+ }
1065
+ case 'if': {
1066
+ const c = sc(e.c), t = se(e.then), f = se(e.else);
1067
+ out = c === e.c && t === e.then && f === e.else ? e : { op: 'if', c, then: t, else: f };
1068
+ break;
1069
+ }
1070
+ case 'get': {
1071
+ const key = se(e.key), f = own(s.maps, e.map);
1072
+ out = f ? f(key) : key === e.key ? e : { op: 'get', map: e.map, key };
1073
+ break;
1074
+ }
1075
+ case 'add':
1076
+ case 'sub':
1077
+ case 'min':
1078
+ case 'max':
1079
+ case 'prod':
1080
+ case 'tup': {
1081
+ const a = se(e.a), b = se(e.b);
1082
+ out = a === e.a && b === e.b ? e : { ...e, a, b };
1083
+ break;
1084
+ }
1085
+ default: return unreachable(e);
1055
1086
  }
1056
- case 'add':
1057
- case 'sub':
1058
- case 'min':
1059
- case 'max':
1060
- case 'tup': return { ...e, a: substE(e.a, s), b: substE(e.b, s) };
1061
- case 'proj': return { ...e, a: substE(e.a, s) };
1062
- default: return unreachable(e);
1063
- }
1064
- }
1065
- export function substC(c, s) {
1066
- if (c.op === 'flag') {
1067
- const f = own(s.flags, c.name);
1068
- if (!f)
1069
- throw new Error(`unknown flag ${c.name}`);
1070
- return f;
1071
- }
1072
- if (c.op === 'not')
1073
- return { op: 'not', x: substC(c.x, s) };
1074
- if (c.op === 'all') {
1075
- const keys = boundOf(c), vars = Object.fromEntries(Object.entries(s.vars).filter(([n]) => !keys.includes(n)));
1076
- return { ...c, c: substC(c.c, { ...s, vars }) };
1077
- }
1078
- if (c.op === 'and' || c.op === 'or')
1079
- return { op: c.op, xs: c.xs.map(y => substC(y, s)) };
1080
- return { ...c, a: substE(c.a, s), b: substE(c.b, s) };
1087
+ me.set(e, out);
1088
+ return out;
1089
+ };
1090
+ const sc = (c) => {
1091
+ const hit = mc.get(c);
1092
+ if (hit !== undefined)
1093
+ return hit;
1094
+ let out;
1095
+ if (c.op === 'flag') {
1096
+ const f = own(s.flags, c.name);
1097
+ if (!f)
1098
+ throw new Error(`unknown flag ${c.name}`);
1099
+ out = f;
1100
+ }
1101
+ else if (c.op === 'not') {
1102
+ const x = sc(c.x);
1103
+ out = x === c.x ? c : { op: 'not', x };
1104
+ }
1105
+ else if (c.op === 'all') {
1106
+ const keys = boundOf(c), vars = Object.fromEntries(Object.entries(s.vars).filter(([n]) => !keys.includes(n)));
1107
+ const cc = substWith({ ...s, vars }).sc(c.c);
1108
+ out = cc === c.c ? c : { ...c, c: cc };
1109
+ }
1110
+ else if (c.op === 'and' || c.op === 'or') {
1111
+ const xs = c.xs.map(sc);
1112
+ out = xs.every((y, i) => y === c.xs[i]) ? c : { op: c.op, xs };
1113
+ }
1114
+ else {
1115
+ const a = se(c.a), b = se(c.b);
1116
+ out = a === c.a && b === c.b ? c : { ...c, a, b };
1117
+ }
1118
+ mc.set(c, out);
1119
+ return out;
1120
+ };
1121
+ return { se, sc };
1081
1122
  }
1123
+ export function substE(e, s) { return substWith(s).se(e); }
1124
+ export function substC(c, s) { return substWith(s).sc(c); }
1082
1125
  const mentions = (c, names) => JSON.stringify(c).match(/"name":"([^"]+)"/g)?.some(m => names.includes(m.slice(8, -1))) ?? false;
1083
1126
  // A precondition reads the params and nothing else: no state, no request, no map.
1084
1127
  const aboutParams = (c, params) => !JSON.stringify(c).includes('"op":"get"') && (JSON.stringify(c).match(/"name":"([^"]+)"/g) ?? []).every(m => params.includes(m.slice(8, -1)));
@@ -1139,8 +1182,10 @@ const divisionArithmetic = (x, seen = new Set()) => {
1139
1182
  return true;
1140
1183
  return Object.values(x).some(value => divisionArithmetic(value, seen));
1141
1184
  };
1142
- const goal = (name, r, conclusion) => {
1185
+ const goal = (name, r, conclusion, checkWord = true) => {
1143
1186
  const hyps = [...r.hyps, { op: 'not', x: conclusion }];
1187
+ if (!checkWord)
1188
+ return { name, hyps };
1144
1189
  // These are kernel-generated consequences of the reserved total Nat helpers,
1145
1190
  // never caller-supplied assumptions. Domain guards preserve invalid-input cases.
1146
1191
  const facts = wordDivisionFacts(hyps);
@@ -1902,7 +1947,7 @@ export function obligations(m, laws, instances = {}, only) {
1902
1947
  // A law about every two keys keeps its second key as it is: a fresh name nothing else reads, so the goal is about every
1903
1948
  // value of it too (the Lean twin reads it so).
1904
1949
  const proven = (law) => (law.forall ? substC(law.holds, { vars: { [law.forall]: { op: 'var', name: `${law.forall}#` } }, maps: {}, flags: {} }) : law.holds);
1905
- const pre = preOf(m), u = updateOf(m), assume = m.assume ? [inlineFlags(m, m.assume)] : [];
1950
+ const pre = preOf(m), u = updateOf(m), assume = m.assume ? [inlineFlags(m, m.assume)] : [], hasWord = hasWordDivision([m, laws, instances]);
1906
1951
  return laws.flatMap((law, i) => {
1907
1952
  if (only !== undefined && i !== only)
1908
1953
  return [];
@@ -1911,7 +1956,7 @@ export function obligations(m, laws, instances = {}, only) {
1911
1956
  const inst = own(instances, law.name) ?? {};
1912
1957
  const start = given(m, holds(from(startOf(m)), pre), inst);
1913
1958
  const turn = step(holds(given(m, from(), inst), [...pre, ...assume, ...assumed(laws, inst), ...closing(m, inst)]), u);
1914
- return [goal(`${law.name} @start`, start, atEnd(start, proven(law))), goal(`${law.name} @step`, turn, atEnd(turn, proven(law)))];
1959
+ return [goal(`${law.name} @start`, start, atEnd(start, proven(law)), hasWord), goal(`${law.name} @step`, turn, atEnd(turn, proven(law)), hasWord)];
1915
1960
  });
1916
1961
  }
1917
1962
  // The whole set at once: every goal has a tree, and every tree checks.
@@ -2218,10 +2263,10 @@ export function progressObligations(m0, laws, instances, p) {
2218
2263
  // causes. Maps a request carries are left as any maps: the step is shown for all of them.
2219
2264
  const before = holds(given(m, from(), instances), [...preOf(m), ...assumed(laws, instances), p.when]);
2220
2265
  const asked = holds(reading(before, p.request), closing(m, instances));
2221
- const caused = step(asked, updateOf(m));
2266
+ const caused = step(asked, updateOf(m)), hasWord = hasWordDivision([m, laws, instances, p]);
2222
2267
  return [
2223
- ...(own ? [goal(`${p.name}: the request is allowed`, asked, substC(inlineFlags(m, own), req))] : []),
2224
- goal(`${p.name}: the step it causes`, caused, across(caused, p.then, Object.keys(m.state), Object.keys(m.maps ?? {}), { inputs: p.request, flags })),
2268
+ ...(own ? [goal(`${p.name}: the request is allowed`, asked, substC(inlineFlags(m, own), req), hasWord)] : []),
2269
+ goal(`${p.name}: the step it causes`, caused, across(caused, p.then, Object.keys(m.state), Object.keys(m.maps ?? {}), { inputs: p.request, flags }), hasWord),
2225
2270
  ];
2226
2271
  }
2227
2272
  export const strongly = (l) => l.fairness === 'strong';
@@ -2327,7 +2372,7 @@ export function stepLawObligations(machine, laws, instances, sl) {
2327
2372
  if (j < k)
2328
2373
  run = nameState(run, state, j);
2329
2374
  }
2330
- return [goal(k === 1 ? `${sl.name} @step law` : `${sl.name} @${k} steps`, run, across(run, sl.then, state, maps, { inputs: {}, flags: flagsOf(m) }))];
2375
+ return [goal(k === 1 ? `${sl.name} @step law` : `${sl.name} @${k} steps`, run, across(run, sl.then, state, maps, { inputs: {}, flags: flagsOf(m) }), hasWordDivision([m, laws, instances, sl]))];
2331
2376
  }
2332
2377
  // The laws' proof and every step law's tree: all must check.
2333
2378
  // `perStep`: a step law's own instances, where it has them (else `instances`).
@@ -2406,7 +2451,8 @@ export function foldObligations(f, laws) {
2406
2451
  const assume = [...preOf(f), ...(f.assume ? [f.assume] : [])];
2407
2452
  const leaf = holds(from({ vars: { ...f.leaf }, maps: {}, flags: {} }), assume);
2408
2453
  const node = step(holds(from(), [...assume, ...laws.flatMap(h => [substC(h.holds, side('l_')), substC(h.holds, side('r_'))])]), { vars: f.node, maps: {} });
2409
- return laws.flatMap(law => [goal(`${law.name} @leaf`, leaf, atEnd(leaf, law.holds)), goal(`${law.name} @node`, node, atEnd(node, law.holds))]);
2454
+ const hasWord = hasWordDivision([f, laws]);
2455
+ return laws.flatMap(law => [goal(`${law.name} @leaf`, leaf, atEnd(leaf, law.holds), hasWord), goal(`${law.name} @node`, node, atEnd(node, law.holds), hasWord)]);
2410
2456
  }
2411
2457
  const bgcd = (a, b) => { a = a < 0n ? -a : a; b = b < 0n ? -b : b; while (b)
2412
2458
  [a, b] = [b, a % b]; return a; };
@@ -2879,15 +2925,15 @@ export function countedObligations(m, laws, instances = {}, only) {
2879
2925
  const proven = (law) => { const h = substC(law.holds, ren); return law.forall ? substC(h, { vars: { [law.forall]: { op: 'var', name: `${law.forall}#` } }, maps: {}, flags: {} }) : h; };
2880
2926
  const all = declsOf(m), st = all.filter(d => stateOnly(m, d));
2881
2927
  const after = (at) => st.map(d => ({ ...d, map: postName(d.map), below: substE(d.below, at), body: substE(d.body, at) }));
2882
- const pre = preOf(m), u = updateOf(m), assume = m.assume ? [inlineFlags(m, m.assume)] : [];
2928
+ const pre = preOf(m), u = updateOf(m), assume = m.assume ? [inlineFlags(m, m.assume)] : [], hasWord = hasWordDivision([m, laws, instances]);
2883
2929
  return laws.flatMap((law, i) => {
2884
2930
  if (only !== undefined && i !== only)
2885
2931
  return [];
2886
2932
  const inst = own(instances, law.name) ?? {};
2887
2933
  const start = given(m, holds(from(startOf(m)), pre), inst);
2888
2934
  const turn = step(holds(given(m, from(), inst), [...pre, ...assume, ...assumed(laws, inst), ...closing(m, inst)]), u);
2889
- return [{ goal: goal(`${law.name} @start`, start, atEnd(start, proven(law))), decls: after(start.at) },
2890
- { goal: goal(`${law.name} @step`, turn, atEnd(turn, proven(law))), decls: [...all, ...after(turn.at)] }];
2935
+ return [{ goal: goal(`${law.name} @start`, start, atEnd(start, proven(law)), hasWord), decls: after(start.at) },
2936
+ { goal: goal(`${law.name} @step`, turn, atEnd(turn, proven(law)), hasWord), decls: [...all, ...after(turn.at)] }];
2891
2937
  });
2892
2938
  }
2893
2939
  // witsOk: a certificate's witnesses are names nothing of the machine or its laws reads or binds: none of its names, bound
@@ -9,4 +9,5 @@ export declare function parseWordDivisionName(name: string): WordDivisionSpec |
9
9
  export declare function wordDivisionKey(args: E[]): E;
10
10
  export declare function wordDivisionArgs(key: E, width: WordDivisionSpec['width']): E[] | undefined;
11
11
  export declare function wordDivisionValue(width: 8 | 16 | 32 | 64, part: 'q' | 'r' | 'c', index: number, values: number[]): number;
12
+ export declare function hasWordDivision(terms: unknown): boolean;
12
13
  export declare function wordDivisionFacts(terms: unknown[]): C[];
@@ -84,6 +84,24 @@ export function wordDivisionValue(width, part, index, values) {
84
84
  // optional consequences, never add a stale trusted assumption. Positive facts
85
85
  // are always rebuilt from the current syntax. Legacy shared ASTs need no rescan.
86
86
  const wordFree = new WeakSet();
87
+ export function hasWordDivision(terms) {
88
+ const seen = new WeakSet();
89
+ const visit = (value) => {
90
+ if (!value || typeof value !== 'object' || wordFree.has(value) || seen.has(value))
91
+ return false;
92
+ seen.add(value);
93
+ if (!Array.isArray(value)) {
94
+ const node = value;
95
+ if (node.op === 'get' && typeof node.map === 'string' && node.map.startsWith('worddiv$'))
96
+ return true;
97
+ }
98
+ for (const child of Object.values(value))
99
+ if (visit(child))
100
+ return true;
101
+ return false;
102
+ };
103
+ return visit(terms);
104
+ }
87
105
  export function wordDivisionFacts(terms) {
88
106
  const out = [];
89
107
  const seen = new Set();
@@ -158,8 +176,10 @@ export function wordDivisionFacts(terms) {
158
176
  }
159
177
  for (const child of Object.values(value))
160
178
  hasWord = visit(child) || hasWord;
161
- if (!hasWord)
179
+ if (!hasWord) {
162
180
  wordFree.add(value);
181
+ seen.delete(value);
182
+ }
163
183
  return hasWord;
164
184
  };
165
185
  visit(terms);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gdp-wired",
3
- "version": "0.54.0",
3
+ "version": "0.54.2",
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",