gdp-wired 0.25.0 → 0.27.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 (52) hide show
  1. package/README.md +14 -9
  2. package/dist/core/accel.d.ts +20 -1
  3. package/dist/core/accel.js +797 -220
  4. package/dist/core/bmc.d.ts +12 -1
  5. package/dist/core/bmc.js +275 -106
  6. package/dist/core/cycles.d.ts +2 -3
  7. package/dist/core/cycles.js +35 -131
  8. package/dist/core/cyclic.d.ts +4 -1
  9. package/dist/core/cyclic.js +103 -74
  10. package/dist/core/data.d.ts +1 -1
  11. package/dist/core/data.js +89 -118
  12. package/dist/core/discover.js +65 -27
  13. package/dist/core/dsl.d.ts +3 -2
  14. package/dist/core/dsl.js +29 -25
  15. package/dist/core/exists.js +7 -14
  16. package/dist/core/extract-check.d.ts +55 -4
  17. package/dist/core/extract-check.js +248 -122
  18. package/dist/core/extract-print.d.ts +1 -0
  19. package/dist/core/extract-print.js +26 -3
  20. package/dist/core/extract-read.d.ts +98 -4
  21. package/dist/core/extract-read.js +306 -43
  22. package/dist/core/extract-shapes.d.ts +14 -0
  23. package/dist/core/extract-shapes.js +609 -79
  24. package/dist/core/extract-xstate.d.ts +5 -1
  25. package/dist/core/extract-xstate.js +618 -184
  26. package/dist/core/extract.d.ts +1 -0
  27. package/dist/core/extract.js +81 -30
  28. package/dist/core/infer.d.ts +1 -0
  29. package/dist/core/infer.js +126 -64
  30. package/dist/core/machine.d.ts +6 -0
  31. package/dist/core/machine.js +35 -4
  32. package/dist/core/nonterm.d.ts +5 -1
  33. package/dist/core/nonterm.js +133 -45
  34. package/dist/core/q.d.ts +1 -0
  35. package/dist/core/q.js +2 -2
  36. package/dist/core/relation.d.ts +1 -0
  37. package/dist/core/relation.js +20 -36
  38. package/dist/core/solver.d.ts +33 -0
  39. package/dist/core/solver.js +84 -30
  40. package/dist/core/transfer.js +22 -13
  41. package/dist/core/translate.d.ts +1 -1
  42. package/dist/core/translate.js +88 -65
  43. package/dist/core/xstate.d.ts +6 -1
  44. package/dist/core/xstate.js +336 -55
  45. package/dist/kernel/cdcl.js +212 -79
  46. package/dist/kernel/prove.d.ts +36 -5
  47. package/dist/kernel/prove.js +212 -104
  48. package/dist/kernel/reader.d.ts +75 -5
  49. package/dist/kernel/reader.js +533 -76
  50. package/dist/kernel/simplex.d.ts +27 -2
  51. package/dist/kernel/simplex.js +160 -14
  52. package/package.json +3 -2
@@ -21,6 +21,7 @@ export type Printer = {
21
21
  };
22
22
  export declare const pnum: (e: N, P: Printer, ctx: Ctx, recv?: boolean) => string;
23
23
  export declare function pb(c: B, P: Printer, ctx: Ctx): string;
24
+ export declare const pidx: (i: N, P: Printer, ctx: Ctx) => string;
24
25
  export declare function pl(l: L, P: Printer, ctx: Ctx, bare?: boolean): string;
25
26
  export declare function pk(k: K, P: Printer, ctx: Ctx): string;
26
27
  export declare function pterm(t: Term, P: Printer, ctx: Ctx, target?: string): string;
@@ -221,6 +221,12 @@ export function sortsOf(m, given = {}) {
221
221
  sorts.set(v.name, given[v.name] ?? 'nat');
222
222
  for (const c of cellNums)
223
223
  sorts.set(c, given[c] ?? 'nat');
224
+ // A list's length is a natural; its items naturals until one written may be below 0.
225
+ for (const d of m.lists ?? []) {
226
+ sorts.set(`${d.name}_len`, 'nat');
227
+ if (d.fields[0].sort.k === 'num')
228
+ sorts.set(`${d.name}.$item`, given[`${d.name}.$item`] ?? 'nat');
229
+ }
224
230
  for (let changed = true; changed;) {
225
231
  changed = false;
226
232
  for (const v of nums(m.state)) {
@@ -242,6 +248,15 @@ export function sortsOf(m, given = {}) {
242
248
  changed = true;
243
249
  }
244
250
  }
251
+ for (const d of m.lists ?? []) {
252
+ const n = `${d.name}.$item`;
253
+ if (d.fields[0].sort.k !== 'num' || sorts.get(n) === 'int' || given[n])
254
+ continue;
255
+ if ((m.listWrites?.[d.name] ?? []).some(o => o.op !== 'pop' && o.x.s === 'num' && !natOK(o.x.e, withAtom(ctx0(), o.when)))) {
256
+ sorts.set(n, 'int');
257
+ changed = true;
258
+ }
259
+ }
245
260
  }
246
261
  for (const v of nums(m.state))
247
262
  if (sorts.get(v.name) === 'int')
@@ -310,7 +325,7 @@ function pn(e, P, ctx, mode, recv = false) {
310
325
  return `when(${pb(e.c, P, ctx)}, ${side(e.a, ca)}, ${side(e.b, cb)})`;
311
326
  }
312
327
  case 'cell': {
313
- const v = `${e.map}.at(${pk(e.key, P, ctx)}).${e.field}`;
328
+ const v = cellText(e, P, ctx);
314
329
  return !nat && recv && P.sorts.get(`${e.map}.${e.field}`) === 'nat' ? `Int.of(${v})` : v;
315
330
  }
316
331
  }
@@ -355,9 +370,17 @@ export function pb(c, P, ctx) {
355
370
  const s = (k) => (k.op === 'svar' ? k.name : k.op === 'slit' ? q(k.value) : pk(k, P, ctx));
356
371
  return c.a.op === 'svar' ? `${c.a.name}.eq(${s(c.b)})` : c.b.op === 'svar' ? `${c.b.name}.eq(${s(c.a)})` : `${pk(c.a, P, ctx)}.eq(${pk(c.b, P, ctx)})`;
357
372
  }
358
- case 'cell': return `${c.map}.at(${pk(c.key, P, ctx)}).${c.field}`;
373
+ case 'cell': return cellText(c, P, ctx);
359
374
  }
360
375
  }
376
+ // A map's cell field, or a list's item (read where the index is within it: an integer index is at least 0 there).
377
+ function cellText(c, P, ctx) {
378
+ if (c.field !== '$item')
379
+ return `${c.map}.at(${pk(c.key, P, ctx)}).${c.field}`;
380
+ return `${c.map}.at(${c.key.op === 'num' ? pidx(c.key.e, P, ctx) : pk(c.key, P, ctx)})`;
381
+ }
382
+ // A list's index, where it is read or set within the list: a natural, or an integer clamped at 0 (the same there).
383
+ export const pidx = (i, P, ctx) => (natOK(i, ctx) ? pn(i, P, ctx, 'nat') : `${pn(i, P, ctx, 'int', true)}.clamped`);
361
384
  // A choice: a literal is written as the choice's own value where nothing else gives the choice (`status.of('open')`).
362
385
  export function pl(l, P, ctx, bare = false) {
363
386
  switch (l.op) {
@@ -371,7 +394,7 @@ export function pl(l, P, ctx, bare = false) {
371
394
  return `${w}.of(${q(l.value)})`;
372
395
  }
373
396
  case 'ite': return `when(${pb(l.c, P, ctx)}, ${pl(l.a, P, ctx, l.b.op !== 'lit')}, ${pl(l.b, P, ctx, l.a.op !== 'lit' || l.b.op !== 'lit' ? l.a.op !== 'lit' : false)})`;
374
- case 'cell': return `${l.map}.at(${pk(l.key, P, ctx)}).${l.field}`;
397
+ case 'cell': return cellText(l, P, ctx);
375
398
  }
376
399
  }
377
400
  export function pk(k, P, ctx) {
@@ -12,6 +12,7 @@ export declare class Retype extends Error {
12
12
  }
13
13
  export type Sort = {
14
14
  k: 'num';
15
+ date?: true;
15
16
  } | {
16
17
  k: 'bool';
17
18
  } | {
@@ -28,6 +29,9 @@ export type Shape = Sort | {
28
29
  key: 'num' | 'str';
29
30
  val: Shape;
30
31
  js: 'Map' | 'record';
32
+ } | {
33
+ k: 'list';
34
+ of: Sort;
31
35
  };
32
36
  export type Var = {
33
37
  name: string;
@@ -52,6 +56,9 @@ export type Layout = {
52
56
  } | {
53
57
  k: 'map';
54
58
  name: string;
59
+ } | {
60
+ k: 'list';
61
+ name: string;
55
62
  } | {
56
63
  k: 'const';
57
64
  value: Term;
@@ -94,6 +101,32 @@ export type MapWrite = {
94
101
  has: B;
95
102
  vals: Record<string, Term>;
96
103
  };
104
+ export type ListOp = {
105
+ op: 'push';
106
+ x: V;
107
+ when: B;
108
+ } | {
109
+ op: 'pop';
110
+ when: B;
111
+ } | {
112
+ op: 'set';
113
+ i: N;
114
+ x: V;
115
+ when: B;
116
+ };
117
+ export type ListWrite = ({
118
+ op: 'push';
119
+ x: Term;
120
+ when: B;
121
+ } | {
122
+ op: 'pop';
123
+ when: B;
124
+ } | {
125
+ op: 'set';
126
+ i: N;
127
+ x: Term;
128
+ when: B;
129
+ })[];
97
130
  export type Model = {
98
131
  name: string;
99
132
  shape: 'reducer' | 'functions' | 'class';
@@ -108,6 +141,8 @@ export type Model = {
108
141
  writes: Record<string, Term>;
109
142
  mapWrites: Record<string, MapWrite>;
110
143
  outputs: string[];
144
+ lists?: MapDecl[];
145
+ listWrites?: Record<string, ListWrite>;
111
146
  refuse: B;
112
147
  pre: B;
113
148
  layout: Layout;
@@ -121,6 +156,23 @@ export type Model = {
121
156
  }>;
122
157
  initSource?: string;
123
158
  spans?: [number, number][];
159
+ factory?: {
160
+ at: number;
161
+ text: string;
162
+ };
163
+ results?: Record<string, {
164
+ k: 'scalar';
165
+ name: string;
166
+ } | {
167
+ k: 'rec';
168
+ fields: [string, string][];
169
+ } | {
170
+ k: 'maybe';
171
+ name: string;
172
+ missing: string;
173
+ null: boolean;
174
+ }>;
175
+ laws?: string[];
124
176
  };
125
177
  type V = {
126
178
  t: 'num';
@@ -147,8 +199,16 @@ type V = {
147
199
  t: 'opt';
148
200
  has: B;
149
201
  v: V;
202
+ null?: true;
150
203
  } | {
151
204
  t: 'undef';
205
+ null?: true;
206
+ } | {
207
+ t: 'outside';
208
+ path: string;
209
+ } | {
210
+ t: 'opaque';
211
+ what: string;
152
212
  } | {
153
213
  t: 'phi';
154
214
  c: B;
@@ -175,7 +235,14 @@ type MapObj = {
175
235
  origin: 'fresh' | 'input' | 'this' | 'shared';
176
236
  gen: number;
177
237
  };
178
- type Obj = Rec | MapObj | {
238
+ type ListObj = {
239
+ k: 'list';
240
+ base: string;
241
+ decl: MapDecl;
242
+ ops: ListOp[];
243
+ origin: 'fresh' | 'input' | 'this' | 'shared';
244
+ };
245
+ type Obj = Rec | MapObj | ListObj | {
179
246
  k: 'alias';
180
247
  to: V;
181
248
  };
@@ -210,8 +277,11 @@ export type Setup = {
210
277
  names: Set<string>;
211
278
  vars: Map<string, Var>;
212
279
  maps: Map<string, MapDecl>;
280
+ lists?: Map<string, MapDecl>;
213
281
  lazySorts: Map<string, Sort>;
214
282
  cls?: ts.ClassLikeDeclaration;
283
+ chain?: ts.ClassLikeDeclaration[];
284
+ closure?: Set<ts.Node>;
215
285
  now?: string;
216
286
  nowRole: 'input' | 'param';
217
287
  hints: WeakMap<object, string>;
@@ -223,6 +293,12 @@ export type Setup = {
223
293
  ctor?: boolean;
224
294
  ours: (sf: ts.SourceFile) => boolean;
225
295
  spans?: [number, number][];
296
+ xstate?: {
297
+ outside: Map<string, {
298
+ path: string;
299
+ sort: Sort;
300
+ }>;
301
+ };
226
302
  };
227
303
  export declare class Exec {
228
304
  readonly s: Setup;
@@ -262,7 +338,7 @@ export declare class Exec {
262
338
  truthy(v: V, at: ts.Node): B;
263
339
  num(v: V, at: ts.Node, p: Path): N;
264
340
  private bool;
265
- equal(a: V, b: V, at: ts.Node): B;
341
+ equal(a: V, b: V, at: ts.Node, loose?: boolean): B;
266
342
  ev(e: ts.Expression, p: Path): [V, Path];
267
343
  private joinValues;
268
344
  private name;
@@ -283,16 +359,34 @@ export declare class Exec {
283
359
  private mapId;
284
360
  mapSet(id: string, key: K, v: V | undefined, at: ts.Node, p: Path, track?: boolean): Path;
285
361
  private cellValue;
286
- assign(target: ts.Expression, v: V, p: Path): Path;
362
+ assign(target: ts.Expression, v: V, p: Path, setTime?: boolean): Path;
287
363
  private writeField;
288
364
  resolved(e: ts.Node): ts.Symbol | undefined;
289
365
  private args;
290
366
  private call;
367
+ private outside;
368
+ private listLen;
369
+ private listOp;
370
+ private array;
371
+ member(name: string, from?: number): ts.ClassElement | undefined;
291
372
  private math;
292
373
  private now;
293
374
  private newExpr;
294
375
  inline(f: Callable, args: V[], at: ts.Node, p: Path): [V, Path];
295
376
  }
377
+ export declare const isDate: (t: ts.Type) => boolean;
378
+ export declare function mergeWrites<V>(c: B, wa: Write<V> | undefined, wb: Write<V> | undefined, base: (key: K) => {
379
+ has: B;
380
+ vals: Map<string, V>;
381
+ }, scalar: (c: B, a: V, b: V) => V): Write<V> | undefined;
382
+ type Write<V> = {
383
+ key: K;
384
+ has: B;
385
+ vals: Map<string, V>;
386
+ };
387
+ export declare const mergeOps: <O extends {
388
+ when: B;
389
+ }>(c: B, a: O[], b: O[]) => O[];
296
390
  export declare const memberName: (n: ts.PropertyName | ts.MemberName) => string;
297
391
  export declare function impure(e: ts.Node): boolean;
298
- export type { V, Path, Rec, MapObj, Heap, Flow };
392
+ export type { V, Path, Rec, MapObj, ListObj, Heap, Flow };