tla-ts 0.0.3-dev.c949d82 → 0.0.3-dev.ccbff8c

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 (81) hide show
  1. package/dist/cli.cjs +1 -1
  2. package/dist/cli.js +1 -1
  3. package/dist/index.cjs +1 -1
  4. package/dist/index.d.cts +167 -36
  5. package/dist/index.d.ts +167 -36
  6. package/dist/index.js +1 -1
  7. package/dist/parallel-worker.cjs +1 -1
  8. package/dist/parallel-worker.js +2 -2
  9. package/dist/parallel.cjs +1 -1
  10. package/dist/parallel.js +2 -2
  11. package/dist/run-cli.cjs +1351 -21
  12. package/dist/run-cli.js +1351 -21
  13. package/dist/transfer.cjs +83 -34
  14. package/dist/transfer.js +83 -34
  15. package/package.json +5 -1
  16. package/src/ast.ts +55 -7
  17. package/src/bags.ts +4 -7
  18. package/src/builtins.ts +29 -11
  19. package/src/bundled-modules.ts +3 -3
  20. package/src/canonical.ts +4 -3
  21. package/src/check.ts +1344 -285
  22. package/src/cli.ts +8 -1
  23. package/src/codegen.ts +68 -21
  24. package/src/config.ts +225 -206
  25. package/src/environment.ts +423 -127
  26. package/src/errors.ts +168 -9
  27. package/src/evaluate.ts +722 -146
  28. package/src/exit-codes.ts +6 -24
  29. package/src/index.ts +1 -0
  30. package/src/instances.ts +4 -2
  31. package/src/java-overrides.ts +104 -25
  32. package/src/levels.ts +183 -37
  33. package/src/lexer.ts +32 -4
  34. package/src/live-check.ts +204 -148
  35. package/src/liveness.ts +190 -117
  36. package/src/obligation-expression.ts +2 -2
  37. package/src/obligation-source.ts +2 -0
  38. package/src/parallel-worker.ts +6 -1
  39. package/src/parallel.ts +57 -6
  40. package/src/parser.ts +412 -139
  41. package/src/pcal-ast.ts +770 -0
  42. package/src/pcal-parse.ts +1523 -0
  43. package/src/pcal-tokenize.ts +516 -0
  44. package/src/pcal-translate.ts +1230 -0
  45. package/src/pcal-validate.ts +454 -0
  46. package/src/randomization.ts +24 -7
  47. package/src/resolve.ts +1405 -416
  48. package/src/run-cli.ts +1167 -174
  49. package/src/runtime.ts +16 -0
  50. package/src/sany-builtins.ts +147 -0
  51. package/src/sany-generator.ts +3112 -0
  52. package/src/sany-levels.ts +1208 -0
  53. package/src/sany-lexer.ts +545 -0
  54. package/src/sany-linter.ts +122 -0
  55. package/src/sany-modules.ts +1398 -0
  56. package/src/sany-nodes.ts +463 -0
  57. package/src/sany-parse-error.ts +2161 -0
  58. package/src/sany-report.ts +354 -0
  59. package/src/sany-selectors.ts +738 -0
  60. package/src/sany-source.ts +248 -0
  61. package/src/sany-xml.ts +1017 -0
  62. package/src/spec-description.ts +25 -5
  63. package/src/standard-modules.ts +203 -146
  64. package/src/standard-ranges.ts +116 -0
  65. package/src/state-graph.ts +29 -6
  66. package/src/subexpressions.ts +221 -161
  67. package/src/substitution-levels.ts +38 -17
  68. package/src/successors.ts +158 -120
  69. package/src/symmetry.ts +168 -50
  70. package/src/tableau.ts +3 -1
  71. package/src/tlc-ext.ts +13 -17
  72. package/src/tlc-messages.ts +329 -0
  73. package/src/tlc-module.ts +49 -21
  74. package/src/tlc-modules.ts +0 -4
  75. package/src/tlc-order.ts +55 -9
  76. package/src/tlc-random.ts +28 -3
  77. package/src/tlc-replay.ts +655 -0
  78. package/src/tlc-version.ts +18 -0
  79. package/src/transfer.ts +15 -3
  80. package/src/value-sources.ts +29 -0
  81. package/src/values.ts +683 -256
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
+ };