tla-ts 0.0.8-dev.d9bffda → 0.0.9-dev.0dd11f695

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 (119) hide show
  1. package/README.md +30 -0
  2. package/dist/compile.cjs +23 -0
  3. package/dist/compile.js +23 -0
  4. package/dist/deciders.cjs +15 -15
  5. package/dist/deciders.js +40 -40
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +80 -10
  8. package/dist/index.d.ts +80 -10
  9. package/dist/index.js +1 -1
  10. package/dist/parallel-worker.cjs +1 -1
  11. package/dist/parallel-worker.js +1 -1
  12. package/dist/prove-worker.cjs +1 -1
  13. package/dist/prove-worker.js +1 -1
  14. package/dist/prove.cjs +116 -36
  15. package/dist/prove.js +116 -36
  16. package/dist/run.cjs +143 -31
  17. package/dist/run.js +143 -31
  18. package/dist/tlapm.cjs +2 -2
  19. package/dist/tlapm.js +1 -1
  20. package/dist/transfer.cjs +128 -103
  21. package/dist/transfer.js +128 -103
  22. package/dist/worker.cjs +7 -7
  23. package/dist/worker.js +7 -7
  24. package/package.json +3 -1
  25. package/src/ast.ts +7 -21
  26. package/src/bags.ts +99 -99
  27. package/src/builtins.ts +44 -75
  28. package/src/bundled-modules.ts +1 -8
  29. package/src/check.ts +605 -311
  30. package/src/cli/options.ts +12 -3
  31. package/src/cli/run.ts +2 -2
  32. package/src/cli/runtime-invariants.ts +135 -0
  33. package/src/cli/shared.ts +20 -9
  34. package/src/cli/tlc-arguments.ts +646 -0
  35. package/src/cli/tlc-usage.ts +362 -0
  36. package/src/cli/tlc.ts +571 -185
  37. package/src/cli/typescript.ts +26 -0
  38. package/src/cli/xml-exporter.ts +4 -10
  39. package/src/codegen.ts +190 -46
  40. package/src/config.ts +101 -68
  41. package/src/coverage.ts +855 -0
  42. package/src/dependencies.ts +20 -28
  43. package/src/dfid.ts +636 -0
  44. package/src/environment.ts +266 -98
  45. package/src/errors.ts +142 -45
  46. package/src/evaluate.ts +632 -298
  47. package/src/exit-codes.ts +37 -1
  48. package/src/index.ts +3 -0
  49. package/src/instances.ts +85 -9
  50. package/src/java-overrides.ts +2 -12
  51. package/src/json-reader.ts +456 -0
  52. package/src/json.ts +262 -139
  53. package/src/levels.ts +2 -3
  54. package/src/lexer.ts +17 -26
  55. package/src/liveness-checker.ts +10 -18
  56. package/src/liveness.ts +121 -49
  57. package/src/parallel-worker.ts +14 -10
  58. package/src/parallel.ts +41 -17
  59. package/src/parser.ts +436 -90
  60. package/src/pcal/ast.ts +7 -28
  61. package/src/pcal/parse.ts +11 -39
  62. package/src/pcal/tokenize.ts +4 -20
  63. package/src/pcal/translate.ts +10 -42
  64. package/src/pcal/validate.ts +3 -21
  65. package/src/pretty-print.ts +1 -2
  66. package/src/prover/smt/solver/solver.ts +31 -27
  67. package/src/randomization.ts +84 -35
  68. package/src/resolve.ts +18 -60
  69. package/src/runtime.ts +11 -4
  70. package/src/sany/builtins.ts +3 -4
  71. package/src/sany/generator.ts +128 -176
  72. package/src/sany/levels.ts +6 -30
  73. package/src/sany/lexer.ts +7 -23
  74. package/src/sany/linter.ts +31 -29
  75. package/src/sany/modules.ts +1 -5
  76. package/src/sany/nodes.ts +4 -28
  77. package/src/sany/parse-error.ts +44 -100
  78. package/src/sany/report.ts +25 -40
  79. package/src/sany/selectors.ts +8 -22
  80. package/src/sany/source.ts +8 -15
  81. package/src/sany/xml.ts +11 -42
  82. package/src/search.ts +547 -144
  83. package/src/simulate.ts +694 -0
  84. package/src/spec-description.ts +166 -48
  85. package/src/standard-definitions.ts +2 -3
  86. package/src/standard-modules.ts +264 -68
  87. package/src/state-graph.ts +51 -18
  88. package/src/subexpressions.ts +31 -5
  89. package/src/successors.ts +267 -77
  90. package/src/symmetry.ts +31 -8
  91. package/src/tableau.ts +1 -2
  92. package/src/tlc/fingerprint.ts +183 -61
  93. package/src/tlc/jar-data.ts +113 -6
  94. package/src/tlc/messages.ts +122 -37
  95. package/src/tlc/order.ts +33 -38
  96. package/src/tlc/random.ts +16 -16
  97. package/src/tlc/replay.ts +563 -211
  98. package/src/tlc/summary.ts +2 -4
  99. package/src/tlc/tlc-operators.ts +81 -36
  100. package/src/tlc/tlcext-operators.ts +138 -117
  101. package/src/tlc/trace-spec.ts +273 -0
  102. package/src/tlc/value-stream.ts +143 -0
  103. package/src/tlc/version.ts +2 -4
  104. package/src/typescript/actions.ts +494 -0
  105. package/src/typescript/collections.ts +615 -0
  106. package/src/typescript/compile.ts +70 -0
  107. package/src/typescript/context.ts +106 -0
  108. package/src/typescript/emit.ts +122 -0
  109. package/src/typescript/expressions.ts +508 -0
  110. package/src/typescript/formula.ts +160 -0
  111. package/src/typescript/functions.ts +295 -0
  112. package/src/typescript/model.ts +164 -0
  113. package/src/typescript/names.ts +116 -0
  114. package/src/typescript/program.ts +51 -0
  115. package/src/typescript/properties.ts +148 -0
  116. package/src/typescript/scope.ts +117 -0
  117. package/src/typescript/steps.ts +175 -0
  118. package/src/typescript/types.ts +178 -0
  119. package/src/values.ts +832 -255
package/src/tlc/random.ts CHANGED
@@ -1,9 +1,11 @@
1
+ import { toEnumeratedSet } from "../builtins";
1
2
  import { TlaEvaluationError } from "../errors";
2
3
  import type { TlcVersion } from "./version";
3
4
  import {
4
5
  createRecord,
5
6
  createSortedFunction,
6
7
  createTuple,
8
+ formatValue,
7
9
  getFunctionDomain,
8
10
  isEmptySet,
9
11
  toFiniteSet,
@@ -21,7 +23,6 @@ const MULTIPLIER = 0x5deece66dn;
21
23
  const SEED_MASK = (1n << 48n) - 1n;
22
24
  const MAXIMUM_INT = 2147483647;
23
25
 
24
- // java.util.Random, which TLC's RandomEnumerableValues extends.
25
26
  export const createJavaRandom = (seed: bigint): JavaRandom => {
26
27
  const state = { value: (BigInt.asUintN(64, seed) ^ MULTIPLIER) & SEED_MASK };
27
28
  const next = (bits: number) => {
@@ -63,7 +64,7 @@ const getPrimes = () => {
63
64
  return PRIMES;
64
65
  };
65
66
 
66
- const nextPrime = (random: JavaRandom) => {
67
+ export const nextPrime = (random: JavaRandom) => {
67
68
  const primes = getPrimes();
68
69
  const choice = { index: primes.length };
69
70
  while (choice.index === primes.length) {
@@ -101,8 +102,6 @@ const getModulusAndMultiplier = (size: number) => {
101
102
  }
102
103
  };
103
104
 
104
- // EnumerableValue.SubsetEnumerator: count indices below size from a full-period linear
105
- // congruential generator that starts at random.nextInt(size).
106
105
  const getSubsetIndicesMaster = (count: number, size: number, random: JavaRandom) => {
107
106
  if (size <= 0) return [];
108
107
  const generator = getModulusAndMultiplier(size);
@@ -130,8 +129,7 @@ const getSubsetIndices174 = (count: number, size: number, random: JavaRandom) =>
130
129
 
131
130
  const LARGE_STRIDE = (1n << 63n) - 1n - 24n;
132
131
 
133
- // SetOfFcnsOrRcdsValue.BigIntegerSubsetEnumerator, for products with more than 2^31 - 1
134
- // elements.
132
+ // For products with more than 2^31 - 1 elements.
135
133
  const getLargeSubsetIndices = (count: number, size: bigint, random: JavaRandom) => {
136
134
  const signed = random.nextLong();
137
135
  const offset = BigInt.asIntN(64, signed < 0n ? -signed : signed);
@@ -187,7 +185,6 @@ export const getEnumeratedFactors = (set: Value, version: TlcVersion) =>
187
185
  ? set.factors
188
186
  : undefined;
189
187
 
190
- // Enumerable#getRandomSubset, which Randomization's RandomSubset calls.
191
188
  export const getRandomSubset = (
192
189
  count: number,
193
190
  set: Value,
@@ -214,18 +211,12 @@ export const getRandomSubset = (
214
211
  return getSubsetIndices(count, elements.length, random).map((index) => elements[Number(index)]);
215
212
  };
216
213
 
217
- const pickElement = (elements: Value[], random: JavaRandom) => {
218
- const element = elements[Math.floor(random.nextDouble() * elements.length)];
219
- if (element === undefined) throw new TlaEvaluationError("RandomElement of the empty set");
220
- return element;
221
- };
222
-
223
214
  // TLC!RandomElement chooses each component of a set of functions, records, or tuples
224
215
  // separately, and otherwise indexes the enumerated set with nextDouble.
225
216
  export const getRandomElement = (set: Value, random: JavaRandom): Value => {
226
217
  if (typeof set === "object" && set.kind === "FunctionSet") {
227
218
  // TLC builds the chosen function without the interval its domain came from.
228
- const domain = [...getFunctionDomain(set.domain)];
219
+ const domain = [...toEnumeratedSet(set.domain, "RandomElement", set).elements];
229
220
  return createSortedFunction(
230
221
  domain,
231
222
  domain.map(() => getRandomElement(set.range, random)),
@@ -245,8 +236,17 @@ export const getRandomElement = (set: Value, random: JavaRandom): Value => {
245
236
  if (typeof set === "object" && set.kind === "Interval") {
246
237
  const size = Math.max(0, set.high - set.low + 1);
247
238
  const offset = Math.floor(random.nextDouble() * size);
248
- if (offset >= size) throw new TlaEvaluationError("RandomElement of the empty set");
239
+ if (offset >= size) {
240
+ throw new TlaEvaluationError(
241
+ `Attempted to retrieve out-of-bounds element from the interval value ${formatValue(set)}.`,
242
+ );
243
+ }
249
244
  return set.low + offset;
250
245
  }
251
- return pickElement(toFiniteSet(set).elements, random);
246
+ const elements = toEnumeratedSet(set, "RandomElement").elements;
247
+ const index = Math.floor(random.nextDouble() * elements.length);
248
+ if (index >= elements.length) {
249
+ throw new TlaEvaluationError(`Index ${index} out of bounds for length ${elements.length}`);
250
+ }
251
+ return elements[index];
252
252
  };