tla-ts 0.0.3-dev.b1578d0 → 0.0.3-dev.b4e335d

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 +150 -8
  5. package/dist/index.d.ts +150 -8
  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 -20
  12. package/dist/run-cli.js +1351 -20
  13. package/dist/transfer.cjs +86 -28
  14. package/dist/transfer.js +86 -28
  15. package/package.json +5 -1
  16. package/src/ast.ts +57 -6
  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 +1396 -227
  22. package/src/cli.ts +8 -1
  23. package/src/codegen.ts +68 -18
  24. package/src/config.ts +252 -179
  25. package/src/environment.ts +514 -130
  26. package/src/errors.ts +217 -3
  27. package/src/evaluate.ts +722 -112
  28. package/src/exit-codes.ts +5 -4
  29. package/src/index.ts +1 -0
  30. package/src/instances.ts +7 -5
  31. package/src/java-overrides.ts +104 -25
  32. package/src/levels.ts +183 -37
  33. package/src/lexer.ts +112 -29
  34. package/src/live-check.ts +220 -102
  35. package/src/liveness.ts +216 -52
  36. package/src/obligation-expression.ts +2 -2
  37. package/src/obligation-source.ts +2 -0
  38. package/src/parallel-worker.ts +8 -3
  39. package/src/parallel.ts +56 -5
  40. package/src/parser.ts +445 -147
  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 +1465 -411
  48. package/src/run-cli.ts +1167 -155
  49. package/src/runtime.ts +18 -0
  50. package/src/sany-builtins.ts +147 -0
  51. package/src/sany-generator.ts +3128 -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 +26 -7
  63. package/src/standard-modules.ts +200 -148
  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 +207 -103
  69. package/src/symmetry.ts +180 -52
  70. package/src/tableau.ts +54 -25
  71. package/src/tlc-ext.ts +13 -17
  72. package/src/tlc-messages.ts +329 -0
  73. package/src/tlc-module.ts +49 -15
  74. package/src/tlc-order.ts +56 -6
  75. package/src/tlc-random.ts +37 -9
  76. package/src/tlc-replay.ts +655 -0
  77. package/src/tlc-summary.ts +20 -5
  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 +697 -180
package/src/errors.ts CHANGED
@@ -1,9 +1,20 @@
1
+ import type { SourceRange } from "./ast";
1
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: `;
2
9
 
3
10
  // How TLC reports a RuntimeException it did not expect, such as one raised while computing next
4
11
  // states.
5
- export const UNEXPECTED_EXCEPTION =
6
- "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: ";
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";
7
18
 
8
19
  export class TlaError extends Error {
9
20
  constructor(message: string, cause?: unknown) {
@@ -19,16 +30,104 @@ export interface SyntaxFailure {
19
30
  isEnd: boolean;
20
31
  }
21
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
+
22
49
  export class TlaSyntaxError extends TlaError {
23
50
  failure: SyntaxFailure | undefined;
51
+ sany: SanyReport | undefined;
24
52
 
25
- constructor(message: string, cause?: unknown, failure?: SyntaxFailure) {
53
+ constructor(message: string, cause?: unknown, failure?: SyntaxFailure, sany?: SanyReport) {
26
54
  super(message, cause);
27
55
  this.name = "TlaSyntaxError";
28
56
  this.failure = failure;
57
+ this.sany = sany;
58
+ }
59
+ }
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";
29
122
  }
30
123
  }
31
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
+
32
131
  export class TlaConfigError extends TlaError {
33
132
  constructor(message: string, cause?: unknown) {
34
133
  super(message, cause);
@@ -43,6 +142,48 @@ export class TlaEvaluationError extends TlaError {
43
142
  }
44
143
  }
45
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
+
46
187
  // An evaluation error that TLC raises as an EvalException from a standard module's Java code. It
47
188
  // keeps the name TlaEvaluationError, and index.ts doesn't export it.
48
189
  export class TlaModuleError extends TlaEvaluationError {
@@ -55,6 +196,35 @@ export class TlaModuleError extends TlaEvaluationError {
55
196
  }
56
197
  }
57
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;
225
+ }
226
+ }
227
+
58
228
  export interface TlapmReport {
59
229
  failure?: string;
60
230
  exception?: string;
@@ -88,6 +258,18 @@ export class TlaUnsupportedError extends TlaError {
88
258
  }
89
259
  }
90
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
+
91
273
  export const getErrorExitCode = (error: TlaError) =>
92
274
  getExitCode(error) ??
93
275
  (error instanceof TlaSyntaxError
@@ -97,3 +279,35 @@ export const getErrorExitCode = (error: TlaError) =>
97
279
  : error instanceof TlaEvaluationError
98
280
  ? EXIT_STATUS.specEvaluationFailure
99
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
+ }