tla-ts 0.0.3 → 0.0.4-dev.2be6058

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 (86) hide show
  1. package/README.md +32 -12
  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 +160 -8
  6. package/dist/index.d.ts +160 -8
  7. package/dist/index.js +1 -1
  8. package/dist/parallel-worker.cjs +2 -2
  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 +45 -18
  13. package/dist/run-cli.js +45 -18
  14. package/dist/transfer.cjs +1393 -18
  15. package/dist/transfer.js +1393 -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 +540 -140
  29. package/src/errors.ts +224 -3
  30. package/src/evaluate.ts +797 -246
  31. package/src/exit-codes.ts +22 -43
  32. package/src/fingerprints.ts +46 -11
  33. package/src/index.ts +1 -0
  34. package/src/instances.ts +19 -16
  35. package/src/java-overrides.ts +104 -25
  36. package/src/levels.ts +191 -45
  37. package/src/lexer.ts +127 -30
  38. package/src/live-check.ts +867 -0
  39. package/src/liveness.ts +218 -572
  40. package/src/obligation-expression.ts +2 -2
  41. package/src/obligation-source.ts +2 -0
  42. package/src/parallel-worker.ts +174 -213
  43. package/src/parallel.ts +131 -39
  44. package/src/parser.ts +456 -147
  45. package/src/pcal-ast.ts +770 -0
  46. package/src/pcal-parse.ts +1523 -0
  47. package/src/pcal-tokenize.ts +516 -0
  48. package/src/pcal-translate.ts +1230 -0
  49. package/src/pcal-validate.ts +454 -0
  50. package/src/randomization.ts +24 -7
  51. package/src/resolve.ts +1481 -426
  52. package/src/run-cli.ts +1212 -143
  53. package/src/runtime.ts +19 -1
  54. package/src/sany-builtins.ts +147 -0
  55. package/src/sany-generator.ts +3128 -0
  56. package/src/sany-levels.ts +1208 -0
  57. package/src/sany-lexer.ts +545 -0
  58. package/src/sany-linter.ts +122 -0
  59. package/src/sany-modules.ts +1398 -0
  60. package/src/sany-nodes.ts +463 -0
  61. package/src/sany-parse-error.ts +2161 -0
  62. package/src/sany-report.ts +356 -0
  63. package/src/sany-selectors.ts +738 -0
  64. package/src/sany-source.ts +248 -0
  65. package/src/sany-xml.ts +1017 -0
  66. package/src/spec-description.ts +42 -11
  67. package/src/standard-modules.ts +200 -148
  68. package/src/standard-ranges.ts +116 -0
  69. package/src/state-graph.ts +180 -0
  70. package/src/subexpressions.ts +231 -171
  71. package/src/substitution-levels.ts +38 -17
  72. package/src/successors.ts +219 -107
  73. package/src/symmetry.ts +194 -54
  74. package/src/tableau.ts +54 -25
  75. package/src/tlc-ext.ts +42 -29
  76. package/src/tlc-messages.ts +329 -0
  77. package/src/tlc-module.ts +52 -43
  78. package/src/tlc-modules.ts +4 -0
  79. package/src/tlc-order.ts +78 -10
  80. package/src/tlc-random.ts +37 -9
  81. package/src/tlc-replay.ts +655 -0
  82. package/src/tlc-summary.ts +20 -5
  83. package/src/tlc-version.ts +18 -0
  84. package/src/transfer.ts +15 -3
  85. package/src/value-sources.ts +29 -0
  86. package/src/values.ts +731 -184
package/src/transfer.ts CHANGED
@@ -2,8 +2,11 @@ import {
2
2
  createModelValue,
3
3
  createSortedFunction,
4
4
  createSortedSet,
5
+ type FunctionClass,
5
6
  getDomainInterval,
7
+ getFunctionClass,
6
8
  getFunctionDomain,
9
+ setFunctionClass,
7
10
  type Value,
8
11
  } from "./values";
9
12
 
@@ -16,6 +19,9 @@ const SET = 5;
16
19
  const FUNCTION = 6;
17
20
  const INTERVAL_FUNCTION = 7;
18
21
 
22
+ // A function's TLC class follows its tag, so a worker words errors about it as TLC does.
23
+ const FUNCTION_CLASSES: (FunctionClass | undefined)[] = [undefined, "lambda", "tuple", "record"];
24
+
19
25
  export interface EncodedStates {
20
26
  words: Int32Array;
21
27
  strings: string[];
@@ -76,11 +82,13 @@ export const createStateEncoder = (): StateEncoder => {
76
82
  const interval = getDomainInterval(value.domain);
77
83
  if (interval) {
78
84
  push(INTERVAL_FUNCTION);
85
+ push(FUNCTION_CLASSES.indexOf(getFunctionClass(value)));
79
86
  push(interval.low);
80
87
  push(value.range.length);
81
88
  return value.range.every(encodeValue);
82
89
  }
83
90
  push(FUNCTION);
91
+ push(FUNCTION_CLASSES.indexOf(getFunctionClass(value)));
84
92
  push(value.domain.length);
85
93
  return value.domain.every(encodeValue) && value.range.every(encodeValue);
86
94
  }
@@ -117,16 +125,20 @@ export const createStateDecoder =
117
125
  if (tag === INTEGER) return words[cursor.index++];
118
126
  if (tag === STRING) return encoded.strings[words[cursor.index++]];
119
127
  if (tag === MODEL_VALUE) return createModelValue(encoded.strings[words[cursor.index++]]);
128
+ if (tag === SET) return createSortedSet(decodeElements(words[cursor.index++]));
129
+ const functionClass = FUNCTION_CLASSES[words[cursor.index++]];
120
130
  if (tag === INTERVAL_FUNCTION) {
121
131
  const low = words[cursor.index++];
122
132
  const length = words[cursor.index++];
123
133
  const domain = getFunctionDomain({ kind: "Interval", low, high: low + length - 1 });
124
- return createSortedFunction(domain, decodeElements(length));
134
+ return setFunctionClass(
135
+ createSortedFunction(domain, decodeElements(length)),
136
+ functionClass,
137
+ );
125
138
  }
126
139
  const length = words[cursor.index++];
127
- if (tag === SET) return createSortedSet(decodeElements(length));
128
140
  const domain = decodeElements(length);
129
- return createSortedFunction(domain, decodeElements(length));
141
+ return setFunctionClass(createSortedFunction(domain, decodeElements(length)), functionClass);
130
142
  };
131
143
  return Array.from({ length: encoded.count }, () =>
132
144
  Array.from({ length: width }, () => decodeValue()),
@@ -0,0 +1,29 @@
1
+ import type { Expression } from "./ast";
2
+ import { TlaEvaluationError } from "./errors";
3
+ import type { Value } from "./values";
4
+
5
+ // While TLC replays a failure, it gives each set, tuple or record it builds the expression that
6
+ // built it. A method of such a value that fails prepends that expression to the error's trace, and
7
+ // TLC reports the error as one it was unable to fingerprint.
8
+ export const valueSources: { current: WeakMap<object, Expression> | undefined } = {
9
+ current: undefined,
10
+ };
11
+
12
+ const fingerprintTraces = new WeakMap<TlaEvaluationError, Expression[]>();
13
+
14
+ export const getFingerprintTrace = (error: unknown) =>
15
+ error instanceof TlaEvaluationError ? fingerprintTraces.get(error) : undefined;
16
+
17
+ export const withSource = <T>(value: Value, run: () => T): T => {
18
+ const sources = valueSources.current;
19
+ if (!sources || typeof value !== "object") return run();
20
+ try {
21
+ return run();
22
+ } catch (error) {
23
+ const source = sources.get(value);
24
+ if (source && error instanceof TlaEvaluationError) {
25
+ fingerprintTraces.set(error, [source, ...(fingerprintTraces.get(error) ?? [])]);
26
+ }
27
+ throw error;
28
+ }
29
+ };