tla-ts 0.0.3 → 0.0.4-dev.5f6a4bf

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 +796 -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 +828 -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/errors.ts CHANGED
@@ -1,4 +1,20 @@
1
- import { EXIT_STATUS, getExitCode, setModuleExitCode } from "./exit-codes";
1
+ import type { SourceRange } from "./ast";
2
+ import { EXIT_STATUS, getExitCode } from "./exit-codes";
3
+ import type { PcalNode } from "./pcal-ast";
4
+ import type { Value } from "./values";
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
+
10
+ // How TLC reports a RuntimeException it did not expect, such as one raised while computing next
11
+ // states.
12
+ export const UNEXPECTED_EXCEPTION = getUnexpectedException("java.lang.RuntimeException");
13
+
14
+ // Whether an error is V8's RangeError for a stack overflow, which TLC raises as a Java
15
+ // StackOverflowError.
16
+ export const isStackOverflow = (error: unknown) =>
17
+ error instanceof RangeError && error.message === "Maximum call stack size exceeded";
2
18
 
3
19
  export class TlaError extends Error {
4
20
  constructor(message: string, cause?: unknown) {
@@ -14,16 +30,104 @@ export interface SyntaxFailure {
14
30
  isEnd: boolean;
15
31
  }
16
32
 
33
+ // An error SANY reports at a location, such as "In module M" or a range in a module.
34
+ export interface SanyError {
35
+ location: string;
36
+ message: string;
37
+ }
38
+
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.
42
+ export interface SanyReport {
43
+ errors: SanyError[];
44
+ warnings: SanyError[];
45
+ isFatal: boolean;
46
+ parseError?: string;
47
+ }
48
+
17
49
  export class TlaSyntaxError extends TlaError {
18
50
  failure: SyntaxFailure | undefined;
51
+ sany: SanyReport | undefined;
19
52
 
20
- constructor(message: string, cause?: unknown, failure?: SyntaxFailure) {
53
+ constructor(message: string, cause?: unknown, failure?: SyntaxFailure, sany?: SanyReport) {
21
54
  super(message, cause);
22
55
  this.name = "TlaSyntaxError";
23
56
  this.failure = failure;
57
+ this.sany = sany;
24
58
  }
25
59
  }
26
60
 
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
+ ) =>
93
+ new TlaSyntaxError(
94
+ errors.map((error) => `${error.location}\n\n${error.message}`).join("\n\n"),
95
+ undefined,
96
+ undefined,
97
+ { errors, warnings, isFatal, parseError },
98
+ );
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
+
125
+ export const formatRange = (range: SourceRange) =>
126
+ `line ${range.start.line}, col ${range.start.column} to line ${range.end.line}, col ${range.end.column} of module ${range.module}`;
127
+
128
+ export const createSemanticError = (message: string, range: SourceRange) =>
129
+ createSanyError([{ location: formatRange(range), message }]);
130
+
27
131
  export class TlaConfigError extends TlaError {
28
132
  constructor(message: string, cause?: unknown) {
29
133
  super(message, cause);
@@ -38,13 +142,86 @@ export class TlaEvaluationError extends TlaError {
38
142
  }
39
143
  }
40
144
 
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.";
148
+
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
+ ) {
169
+ super(message);
170
+ this.state = state;
171
+ this.action = action;
172
+ this.variables = variables;
173
+ }
174
+ }
175
+
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.
178
+ export class TlaUnassignedError extends TlaEvaluationError {
179
+ variable: string;
180
+
181
+ constructor(message: string, variable: string) {
182
+ super(message);
183
+ this.variable = variable;
184
+ }
185
+ }
186
+
41
187
  // An evaluation error that TLC raises as an EvalException from a standard module's Java code. It
42
188
  // keeps the name TlaEvaluationError, and index.ts doesn't export it.
43
189
  export class TlaModuleError extends TlaEvaluationError {
190
+ exitCode: number;
191
+
44
192
  constructor(message: string, exitCode: number = EXIT_STATUS.error) {
45
193
  super(message);
46
194
  this.name = "TlaEvaluationError";
47
- setModuleExitCode(this, exitCode);
195
+ this.exitCode = exitCode;
196
+ }
197
+ }
198
+
199
+ // TLC reports a successor state that the next-state relation leaves incomplete as an error of its
200
+ // own, not as an exception. It keeps the name TlaEvaluationError, and index.ts doesn't export it.
201
+ export class TlaIncompleteStateError extends TlaEvaluationError {
202
+ state: (Value | undefined)[];
203
+ action: string | undefined;
204
+ missing: string[];
205
+
206
+ constructor(state: (Value | undefined)[], action: string | undefined, missing: string[]) {
207
+ super(
208
+ `Successor state is not completely specified by the next-state action. The following variable${missing.length > 1 ? "s are" : " is"} not defined: ${missing.join(", ")}.\n`,
209
+ );
210
+ this.name = "TlaEvaluationError";
211
+ this.state = state;
212
+ this.action = action;
213
+ this.missing = missing;
214
+ }
215
+ }
216
+
217
+ // TLC reports an initial state that the initial predicate leaves incomplete as an illegal state.
218
+ export class TlaIllegalStateError extends TlaEvaluationError {
219
+ state: (Value | undefined)[];
220
+
221
+ constructor(state: (Value | undefined)[]) {
222
+ super("current state is not a legal state");
223
+ this.name = "TlaEvaluationError";
224
+ this.state = state;
48
225
  }
49
226
  }
50
227
 
@@ -81,6 +258,18 @@ export class TlaUnsupportedError extends TlaError {
81
258
  }
82
259
  }
83
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
+
84
273
  export const getErrorExitCode = (error: TlaError) =>
85
274
  getExitCode(error) ??
86
275
  (error instanceof TlaSyntaxError
@@ -90,3 +279,35 @@ export const getErrorExitCode = (error: TlaError) =>
90
279
  : error instanceof TlaEvaluationError
91
280
  ? EXIT_STATUS.specEvaluationFailure
92
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
+ }