tla-ts 0.0.3-dev.b74f28c → 0.0.3-dev.baa5e34

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 (84) hide show
  1. package/README.md +16 -2
  2. package/dist/cli.cjs +1 -1
  3. package/dist/cli.js +1 -1
  4. package/dist/index.cjs +1 -1
  5. package/dist/index.d.cts +159 -8
  6. package/dist/index.d.ts +159 -8
  7. package/dist/index.js +1 -1
  8. package/dist/parallel-worker.cjs +1 -1
  9. package/dist/parallel-worker.js +2 -2
  10. package/dist/parallel.cjs +1 -1
  11. package/dist/parallel.js +2 -2
  12. package/dist/run-cli.cjs +1351 -19
  13. package/dist/run-cli.js +1351 -19
  14. package/dist/transfer.cjs +88 -18
  15. package/dist/transfer.js +88 -18
  16. package/package.json +5 -1
  17. package/src/ast.ts +147 -6
  18. package/src/bags.ts +4 -7
  19. package/src/builtins.ts +29 -11
  20. package/src/bundled-modules.ts +3 -3
  21. package/src/canonical.ts +4 -3
  22. package/src/check.ts +1539 -235
  23. package/src/cli-options.ts +11 -5
  24. package/src/cli.ts +8 -1
  25. package/src/codegen.ts +77 -37
  26. package/src/config.ts +254 -181
  27. package/src/dependencies.ts +2 -2
  28. package/src/environment.ts +524 -140
  29. package/src/errors.ts +224 -3
  30. package/src/evaluate.ts +796 -246
  31. package/src/exit-codes.ts +22 -43
  32. package/src/index.ts +1 -0
  33. package/src/instances.ts +19 -16
  34. package/src/java-overrides.ts +104 -25
  35. package/src/levels.ts +191 -45
  36. package/src/lexer.ts +127 -30
  37. package/src/live-check.ts +828 -0
  38. package/src/liveness.ts +218 -572
  39. package/src/obligation-expression.ts +2 -2
  40. package/src/obligation-source.ts +2 -0
  41. package/src/parallel-worker.ts +13 -4
  42. package/src/parallel.ts +73 -6
  43. package/src/parser.ts +456 -147
  44. package/src/pcal-ast.ts +770 -0
  45. package/src/pcal-parse.ts +1523 -0
  46. package/src/pcal-tokenize.ts +516 -0
  47. package/src/pcal-translate.ts +1230 -0
  48. package/src/pcal-validate.ts +454 -0
  49. package/src/randomization.ts +24 -7
  50. package/src/resolve.ts +1481 -426
  51. package/src/run-cli.ts +1200 -143
  52. package/src/runtime.ts +19 -1
  53. package/src/sany-builtins.ts +147 -0
  54. package/src/sany-generator.ts +3128 -0
  55. package/src/sany-levels.ts +1208 -0
  56. package/src/sany-lexer.ts +545 -0
  57. package/src/sany-linter.ts +122 -0
  58. package/src/sany-modules.ts +1398 -0
  59. package/src/sany-nodes.ts +463 -0
  60. package/src/sany-parse-error.ts +2161 -0
  61. package/src/sany-report.ts +356 -0
  62. package/src/sany-selectors.ts +738 -0
  63. package/src/sany-source.ts +248 -0
  64. package/src/sany-xml.ts +1017 -0
  65. package/src/spec-description.ts +42 -11
  66. package/src/standard-modules.ts +200 -148
  67. package/src/standard-ranges.ts +116 -0
  68. package/src/state-graph.ts +180 -0
  69. package/src/subexpressions.ts +231 -171
  70. package/src/substitution-levels.ts +38 -17
  71. package/src/successors.ts +219 -107
  72. package/src/symmetry.ts +180 -52
  73. package/src/tableau.ts +54 -25
  74. package/src/tlc-ext.ts +42 -29
  75. package/src/tlc-messages.ts +329 -0
  76. package/src/tlc-module.ts +52 -43
  77. package/src/tlc-order.ts +73 -9
  78. package/src/tlc-random.ts +37 -9
  79. package/src/tlc-replay.ts +655 -0
  80. package/src/tlc-summary.ts +20 -5
  81. package/src/tlc-version.ts +18 -0
  82. package/src/transfer.ts +15 -3
  83. package/src/value-sources.ts +29 -0
  84. package/src/values.ts +724 -180
package/src/tlc-random.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { TlaEvaluationError } from "./errors";
2
+ import type { TlcVersion } from "./tlc-version";
2
3
  import {
3
4
  createRecord,
4
5
  createSortedFunction,
@@ -181,8 +182,10 @@ const createShiftTable = (length: number) => {
181
182
 
182
183
  // Extending a fingerprint by a byte is linear over GF(2), so extending it by a value's bytes
183
184
  // XORs the value's own fingerprint from zero into the fingerprint shifted by their length.
184
- // The fingerprinter caches each distinct variable value for one pass over the stored states.
185
- export const createTlcFingerprinter = () => {
185
+ // The fingerprinter caches each distinct variable value for one pass over the stored states. It
186
+ // reads a state's variables in `order` and writes each fingerprint's low and high words into
187
+ // `words`, an Int32Array over a little-endian BigInt64Array.
188
+ export const createTlcFingerprinter = (order: number[], words: Int32Array) => {
186
189
  const shiftTables = new Map<number, Int32Array>();
187
190
  const indices = new Map<Value, number>();
188
191
  const contributions: number[] = [];
@@ -204,11 +207,11 @@ export const createTlcFingerprinter = () => {
204
207
  shiftTables.set(length, table);
205
208
  return table;
206
209
  };
207
- return (state: Value[]) => {
210
+ return (state: Value[], position: number) => {
208
211
  const outer = { high, low };
209
212
  const fingerprint = { high: INITIAL_HIGH, low: INITIAL_LOW };
210
- for (const value of state) {
211
- const contribution = getContribution(value);
213
+ for (const index of order) {
214
+ const contribution = getContribution(state[index]);
212
215
  const table = getShiftTable(contributions[contribution]);
213
216
  const extended = {
214
217
  high: contributions[contribution + 1],
@@ -225,7 +228,8 @@ export const createTlcFingerprinter = () => {
225
228
  }
226
229
  high = outer.high;
227
230
  low = outer.low;
228
- return (BigInt(fingerprint.high >>> 0) << 32n) | BigInt(fingerprint.low >>> 0);
231
+ words[2 * position] = fingerprint.low;
232
+ words[2 * position + 1] = fingerprint.high;
229
233
  };
230
234
  };
231
235
 
@@ -286,7 +290,7 @@ const getModulusAndMultiplier = (size: number) => {
286
290
 
287
291
  // EnumerableValue.SubsetEnumerator: count indices below size from a full-period linear
288
292
  // congruential generator that starts at random.nextInt(size).
289
- const getSubsetIndices = (count: number, size: number, random: JavaRandom) => {
293
+ const getSubsetIndicesMaster = (count: number, size: number, random: JavaRandom) => {
290
294
  if (size <= 0) return [];
291
295
  const generator = getModulusAndMultiplier(size);
292
296
  const state = { index: BigInt(random.nextInt(size)) };
@@ -299,6 +303,18 @@ const getSubsetIndices = (count: number, size: number, random: JavaRandom) => {
299
303
  });
300
304
  };
301
305
 
306
+ // TLC 1.7.4's EnumerableValue.SubsetEnumerator: the i-th index is (x * i + a) mod size, for a
307
+ // prime x above size and a = random.nextInt(size), so the first size indices are distinct.
308
+ const getSubsetIndices174 = (count: number, size: number, random: JavaRandom) => {
309
+ if (size <= 0) return [];
310
+ const stride = BigInt(size < 191 ? 191 : MAXIMUM_INT);
311
+ const offset = BigInt(random.nextInt(size));
312
+ return Array.from(
313
+ { length: Math.min(count, size) },
314
+ (_, index) => (stride * BigInt(index) + offset) % BigInt(size),
315
+ );
316
+ };
317
+
302
318
  const LARGE_STRIDE = (1n << 63n) - 1n - 24n;
303
319
 
304
320
  // SetOfFcnsOrRcdsValue.BigIntegerSubsetEnumerator, for products with more than 2^31 - 1
@@ -352,15 +368,27 @@ const getProduct = (set: Value): Product | undefined => {
352
368
  return undefined;
353
369
  };
354
370
 
371
+ // TLC 1.7.4 enumerates a set of tuples to draw from it.
372
+ export const getEnumeratedFactors = (set: Value, version: TlcVersion) =>
373
+ version === "1.7.4" && typeof set === "object" && set.kind === "ProductSet"
374
+ ? set.factors
375
+ : undefined;
376
+
355
377
  // Enumerable#getRandomSubset, which Randomization's RandomSubset calls.
356
- export const getRandomSubset = (count: number, set: Value, random: JavaRandom): Value[] => {
378
+ export const getRandomSubset = (
379
+ count: number,
380
+ set: Value,
381
+ random: JavaRandom,
382
+ version: TlcVersion,
383
+ ): Value[] => {
357
384
  if (isEmptySet(set)) return [];
385
+ const getSubsetIndices = version === "1.7.4" ? getSubsetIndices174 : getSubsetIndicesMaster;
358
386
  if (typeof set === "object" && set.kind === "Interval") {
359
387
  return getSubsetIndices(count, Math.max(0, set.high - set.low + 1), random).map(
360
388
  (index) => set.low + Number(index),
361
389
  );
362
390
  }
363
- const product = getProduct(set);
391
+ const product = getEnumeratedFactors(set, version) ? undefined : getProduct(set);
364
392
  if (product) {
365
393
  const size = product.lists.reduce((total, list) => total * BigInt(list.length), 1n);
366
394
  const indices =