tla-ts 0.0.3-dev.c8c988d → 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 +163 -46
  5. package/dist/index.d.ts +163 -46
  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 -22
  12. package/dist/run-cli.js +1351 -22
  13. package/dist/transfer.cjs +83 -33
  14. package/dist/transfer.js +83 -33
  15. package/package.json +5 -1
  16. package/src/ast.ts +51 -6
  17. package/src/bags.ts +4 -7
  18. package/src/builtins.ts +29 -17
  19. package/src/bundled-modules.ts +3 -3
  20. package/src/canonical.ts +4 -3
  21. package/src/check.ts +1317 -428
  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 +417 -129
  26. package/src/errors.ts +155 -18
  27. package/src/evaluate.ts +713 -259
  28. package/src/exit-codes.ts +6 -24
  29. package/src/fingerprints.ts +1 -2
  30. package/src/index.ts +1 -0
  31. package/src/instances.ts +3 -1
  32. package/src/java-overrides.ts +104 -25
  33. package/src/levels.ts +44 -28
  34. package/src/lexer.ts +32 -4
  35. package/src/live-check.ts +204 -148
  36. package/src/liveness.ts +191 -122
  37. package/src/obligation-expression.ts +2 -2
  38. package/src/obligation-source.ts +2 -0
  39. package/src/parallel-worker.ts +6 -1
  40. package/src/parallel.ts +57 -6
  41. package/src/parser.ts +405 -167
  42. package/src/pcal-ast.ts +770 -0
  43. package/src/pcal-parse.ts +1523 -0
  44. package/src/pcal-tokenize.ts +516 -0
  45. package/src/pcal-translate.ts +1230 -0
  46. package/src/pcal-validate.ts +454 -0
  47. package/src/randomization.ts +24 -7
  48. package/src/resolve.ts +1397 -457
  49. package/src/run-cli.ts +1161 -196
  50. package/src/runtime.ts +16 -0
  51. package/src/sany-builtins.ts +147 -0
  52. package/src/sany-generator.ts +3112 -0
  53. package/src/sany-levels.ts +1208 -0
  54. package/src/sany-lexer.ts +545 -0
  55. package/src/sany-linter.ts +122 -0
  56. package/src/sany-modules.ts +1398 -0
  57. package/src/sany-nodes.ts +463 -0
  58. package/src/sany-parse-error.ts +2161 -0
  59. package/src/sany-report.ts +354 -0
  60. package/src/sany-selectors.ts +738 -0
  61. package/src/sany-source.ts +248 -0
  62. package/src/sany-xml.ts +1017 -0
  63. package/src/spec-description.ts +25 -5
  64. package/src/standard-modules.ts +172 -129
  65. package/src/standard-ranges.ts +116 -0
  66. package/src/state-graph.ts +29 -6
  67. package/src/subexpressions.ts +221 -161
  68. package/src/substitution-levels.ts +5 -8
  69. package/src/successors.ts +141 -173
  70. package/src/symmetry.ts +168 -50
  71. package/src/tableau.ts +3 -1
  72. package/src/tlc-ext.ts +13 -17
  73. package/src/tlc-messages.ts +329 -0
  74. package/src/tlc-module.ts +49 -21
  75. package/src/tlc-modules.ts +0 -4
  76. package/src/tlc-order.ts +55 -9
  77. package/src/tlc-random.ts +28 -3
  78. package/src/tlc-replay.ts +655 -0
  79. package/src/tlc-version.ts +18 -0
  80. package/src/transfer.ts +15 -3
  81. package/src/values.ts +664 -317
package/src/errors.ts CHANGED
@@ -1,16 +1,18 @@
1
1
  import type { SourceRange } from "./ast";
2
2
  import { EXIT_STATUS, getExitCode } from "./exit-codes";
3
+ import type { PcalNode } from "./pcal-ast";
3
4
  import type { Value } from "./values";
4
5
 
6
+ // The start of TLC's message for an exception of a Java class it didn't expect.
7
+ export const getUnexpectedException = (exceptionClass: string) =>
8
+ `TLC threw an unexpected exception.\nThis was probably caused by an error in the spec or model.\nSee the User Output or TLC Console for clues to what happened.\nThe exception was a ${exceptionClass}\n: `;
9
+
5
10
  // How TLC reports a RuntimeException it did not expect, such as one raised while computing next
6
11
  // states.
7
- export const UNEXPECTED_EXCEPTION =
8
- "TLC threw an unexpected exception.\nThis was probably caused by an error in the spec or model.\nSee the User Output or TLC Console for clues to what happened.\nThe exception was a java.lang.RuntimeException\n: ";
9
-
10
- // How TLC reports a Java StackOverflowError, which V8 raises as this RangeError.
11
- export const STACK_OVERFLOW =
12
- "This was a Java StackOverflowError. It was probably the result\nof an incorrect recursive function definition that caused TLC to enter\nan infinite loop when trying to compute the function or its application\nto an element in its putative domain.";
12
+ export const UNEXPECTED_EXCEPTION = getUnexpectedException("java.lang.RuntimeException");
13
13
 
14
+ // Whether an error is V8's RangeError for a stack overflow, which TLC raises as a Java
15
+ // StackOverflowError.
14
16
  export const isStackOverflow = (error: unknown) =>
15
17
  error instanceof RangeError && error.message === "Maximum call stack size exceeded";
16
18
 
@@ -34,10 +36,14 @@ export interface SanyError {
34
36
  message: string;
35
37
  }
36
38
 
37
- // The errors SANY reports for a spec. A fatal error stops it before semantic analysis.
39
+ // The errors SANY reports for a spec, and the warnings it prints before them. A fatal error stops it
40
+ // before semantic analysis. SANY's parser prints its message for a module it rejects before the
41
+ // report.
38
42
  export interface SanyReport {
39
43
  errors: SanyError[];
44
+ warnings: SanyError[];
40
45
  isFatal: boolean;
46
+ parseError?: string;
41
47
  }
42
48
 
43
49
  export class TlaSyntaxError extends TlaError {
@@ -52,14 +58,70 @@ export class TlaSyntaxError extends TlaError {
52
58
  }
53
59
  }
54
60
 
55
- export const createSanyError = (errors: SanyError[], isFatal = false) =>
61
+ // A fatal error of SANY's parsing phase: a module SANY can't find or parse, a file whose name
62
+ // doesn't match its module's, or a circular dependency. SANY reports it in the module that imports
63
+ // or holds the failed one, or without a location, after its JavaCC parser's report of a module it
64
+ // failed to parse. It keeps the name TlaSyntaxError, and index.ts doesn't export it.
65
+ export class TlaSanyFatalError extends TlaSyntaxError {
66
+ location: string | undefined;
67
+ parseError: string | undefined;
68
+
69
+ constructor(message: string, location: string | undefined, parseError?: string) {
70
+ super(message);
71
+ this.location = location;
72
+ this.parseError = parseError;
73
+ }
74
+ }
75
+
76
+ // A module that another imports and SANY can't find, which SANY reports in the importer, except
77
+ // TLC 1.7.4's SANY, which gives it no location.
78
+ export class TlaMissingModuleError extends TlaSanyFatalError {
79
+ constructor(name: string, importer: string | undefined, isLocated = true) {
80
+ super(
81
+ `Cannot find source file for module ${name} imported in module ${importer}.`,
82
+ isLocated ? importer : undefined,
83
+ );
84
+ }
85
+ }
86
+
87
+ export const createSanyError = (
88
+ errors: SanyError[],
89
+ isFatal = false,
90
+ parseError?: string,
91
+ warnings: SanyError[] = [],
92
+ ) =>
56
93
  new TlaSyntaxError(
57
94
  errors.map((error) => `${error.location}\n\n${error.message}`).join("\n\n"),
58
95
  undefined,
59
96
  undefined,
60
- { errors, isFatal },
97
+ { errors, warnings, isFatal, parseError },
61
98
  );
62
99
 
100
+ // SANY reports a module it can't find in the module that imports it.
101
+ export const createMissingModuleError = (name: string, importer: string | undefined) =>
102
+ createSanyError(
103
+ [
104
+ {
105
+ location: `In module ${importer}`,
106
+ message: `Cannot find source file for module ${name} imported in module ${importer}.`,
107
+ },
108
+ ],
109
+ true,
110
+ );
111
+
112
+ // How SANY prints the warnings it reports, which do not stop TLC.
113
+ export const formatSanyWarnings = (warnings: SanyError[]) =>
114
+ `*** Warnings: ${warnings.length}\n\n${warnings.map((warning) => `${warning.location}\n\n${warning.message}\n\n\n`).join("\n")}`;
115
+
116
+ // SANY's message for a module its parser rejects, such as a "***Parse Error***" with the
117
+ // productions it was in.
118
+ export class TlaParseError extends TlaError {
119
+ constructor(message: string) {
120
+ super(message);
121
+ this.name = "TlaParseError";
122
+ }
123
+ }
124
+
63
125
  export const formatRange = (range: SourceRange) =>
64
126
  `line ${range.start.line}, col ${range.start.column} to line ${range.end.line}, col ${range.end.column} of module ${range.module}`;
65
127
 
@@ -80,29 +142,60 @@ export class TlaEvaluationError extends TlaError {
80
142
  }
81
143
  }
82
144
 
83
- // An evaluation error that TLC raises as an EvalException from a standard module's Java code. It
84
- // keeps the name TlaEvaluationError, and index.ts doesn't export it.
85
- export class TlaModuleError extends TlaEvaluationError {
86
- exitCode: number;
145
+ // How TLC reports a Java StackOverflowError.
146
+ export const STACK_OVERFLOW_MESSAGE =
147
+ "This was a Java StackOverflowError. It was probably the result\nof an incorrect recursive function definition that caused TLC to enter\nan infinite loop when trying to compute the function or its application\nto an element in its putative domain.";
87
148
 
88
- constructor(message: string, exitCode: number = EXIT_STATUS.error) {
149
+ // A Java StackOverflowError, which TLC catches only at the top, unlike the exceptions of evaluation.
150
+ export class TlaStackOverflowError extends TlaEvaluationError {
151
+ constructor() {
152
+ super(STACK_OVERFLOW_MESSAGE);
153
+ }
154
+ }
155
+
156
+ // A next-state action left variables of a successor state unassigned. TLC reports the partial
157
+ // state, with null for each unassigned variable.
158
+ export class TlaIncompleteSuccessorError extends TlaEvaluationError {
159
+ state: (Value | undefined)[];
160
+ action: string | undefined;
161
+ variables: string[];
162
+
163
+ constructor(
164
+ message: string,
165
+ state: (Value | undefined)[],
166
+ action: string | undefined,
167
+ variables: string[],
168
+ ) {
89
169
  super(message);
90
- this.name = "TlaEvaluationError";
91
- this.exitCode = exitCode;
170
+ this.state = state;
171
+ this.action = action;
172
+ this.variables = variables;
92
173
  }
93
174
  }
94
175
 
95
- // A variable that a partial state leaves without a value.
176
+ // An expression read a variable that its state doesn't assign. It keeps the name
177
+ // TlaEvaluationError, and index.ts doesn't export it.
96
178
  export class TlaUnassignedError extends TlaEvaluationError {
97
179
  variable: string;
98
180
 
99
181
  constructor(message: string, variable: string) {
100
182
  super(message);
101
- this.name = "TlaEvaluationError";
102
183
  this.variable = variable;
103
184
  }
104
185
  }
105
186
 
187
+ // An evaluation error that TLC raises as an EvalException from a standard module's Java code. It
188
+ // keeps the name TlaEvaluationError, and index.ts doesn't export it.
189
+ export class TlaModuleError extends TlaEvaluationError {
190
+ exitCode: number;
191
+
192
+ constructor(message: string, exitCode: number = EXIT_STATUS.error) {
193
+ super(message);
194
+ this.name = "TlaEvaluationError";
195
+ this.exitCode = exitCode;
196
+ }
197
+ }
198
+
106
199
  // TLC reports a successor state that the next-state relation leaves incomplete as an error of its
107
200
  // own, not as an exception. It keeps the name TlaEvaluationError, and index.ts doesn't export it.
108
201
  export class TlaIncompleteStateError extends TlaEvaluationError {
@@ -165,6 +258,18 @@ export class TlaUnsupportedError extends TlaError {
165
258
  }
166
259
  }
167
260
 
261
+ // An exception that TLC's Java code throws and nothing catches, with the stack trace it prints, after
262
+ // what the frames that the exception unwinds print about it.
263
+ export class TlaJavaException extends TlaUnsupportedError {
264
+ unwound: string;
265
+
266
+ constructor(message: string, unwound: string) {
267
+ super(message);
268
+ this.name = "TlaJavaException";
269
+ this.unwound = unwound;
270
+ }
271
+ }
272
+
168
273
  export const getErrorExitCode = (error: TlaError) =>
169
274
  getExitCode(error) ??
170
275
  (error instanceof TlaSyntaxError
@@ -174,3 +279,35 @@ export const getErrorExitCode = (error: TlaError) =>
174
279
  : error instanceof TlaEvaluationError
175
280
  ? EXIT_STATUS.specEvaluationFailure
176
281
  : EXIT_STATUS.error);
282
+
283
+ // pcal.UnrecoverableException and its subclasses: an error the PlusCal translator reports as
284
+ // "Unrecoverable error". UnrecoverablePositionedException adds the statement the error is at.
285
+ export class PcalError extends TlaError {
286
+ node: PcalNode | undefined;
287
+
288
+ constructor(message: string, node?: PcalNode) {
289
+ super(message);
290
+ this.name = "PcalError";
291
+ this.node = node;
292
+ }
293
+ }
294
+
295
+ // A RuntimeException the translator's Java code throws, such as an index out of bounds, which
296
+ // ParseAlgorithm.getAlgorithm turns into a parsing error.
297
+ export class PcalRuntimeError extends TlaError {
298
+ constructor(message: string) {
299
+ super(message);
300
+ this.name = "PcalRuntimeError";
301
+ }
302
+ }
303
+
304
+ // PcalDebug.ReportBug: the translator found itself in a state it considers a bug, and throws a
305
+ // java.lang.Error that nothing in SANY catches.
306
+ export class PcalBugError extends TlaError {
307
+ constructor(message: string) {
308
+ super(
309
+ `You have discovered a bug in pcal.trans.\nSend the following information and the\ninput file to the current maintainer(s).\n\n -- ${message}.`,
310
+ );
311
+ this.name = "PcalBugError";
312
+ }
313
+ }