tla-ts 0.0.8-dev.d9bffda → 0.0.9-dev.0dd11f695

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 (119) hide show
  1. package/README.md +30 -0
  2. package/dist/compile.cjs +23 -0
  3. package/dist/compile.js +23 -0
  4. package/dist/deciders.cjs +15 -15
  5. package/dist/deciders.js +40 -40
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +80 -10
  8. package/dist/index.d.ts +80 -10
  9. package/dist/index.js +1 -1
  10. package/dist/parallel-worker.cjs +1 -1
  11. package/dist/parallel-worker.js +1 -1
  12. package/dist/prove-worker.cjs +1 -1
  13. package/dist/prove-worker.js +1 -1
  14. package/dist/prove.cjs +116 -36
  15. package/dist/prove.js +116 -36
  16. package/dist/run.cjs +143 -31
  17. package/dist/run.js +143 -31
  18. package/dist/tlapm.cjs +2 -2
  19. package/dist/tlapm.js +1 -1
  20. package/dist/transfer.cjs +128 -103
  21. package/dist/transfer.js +128 -103
  22. package/dist/worker.cjs +7 -7
  23. package/dist/worker.js +7 -7
  24. package/package.json +3 -1
  25. package/src/ast.ts +7 -21
  26. package/src/bags.ts +99 -99
  27. package/src/builtins.ts +44 -75
  28. package/src/bundled-modules.ts +1 -8
  29. package/src/check.ts +605 -311
  30. package/src/cli/options.ts +12 -3
  31. package/src/cli/run.ts +2 -2
  32. package/src/cli/runtime-invariants.ts +135 -0
  33. package/src/cli/shared.ts +20 -9
  34. package/src/cli/tlc-arguments.ts +646 -0
  35. package/src/cli/tlc-usage.ts +362 -0
  36. package/src/cli/tlc.ts +571 -185
  37. package/src/cli/typescript.ts +26 -0
  38. package/src/cli/xml-exporter.ts +4 -10
  39. package/src/codegen.ts +190 -46
  40. package/src/config.ts +101 -68
  41. package/src/coverage.ts +855 -0
  42. package/src/dependencies.ts +20 -28
  43. package/src/dfid.ts +636 -0
  44. package/src/environment.ts +266 -98
  45. package/src/errors.ts +142 -45
  46. package/src/evaluate.ts +632 -298
  47. package/src/exit-codes.ts +37 -1
  48. package/src/index.ts +3 -0
  49. package/src/instances.ts +85 -9
  50. package/src/java-overrides.ts +2 -12
  51. package/src/json-reader.ts +456 -0
  52. package/src/json.ts +262 -139
  53. package/src/levels.ts +2 -3
  54. package/src/lexer.ts +17 -26
  55. package/src/liveness-checker.ts +10 -18
  56. package/src/liveness.ts +121 -49
  57. package/src/parallel-worker.ts +14 -10
  58. package/src/parallel.ts +41 -17
  59. package/src/parser.ts +436 -90
  60. package/src/pcal/ast.ts +7 -28
  61. package/src/pcal/parse.ts +11 -39
  62. package/src/pcal/tokenize.ts +4 -20
  63. package/src/pcal/translate.ts +10 -42
  64. package/src/pcal/validate.ts +3 -21
  65. package/src/pretty-print.ts +1 -2
  66. package/src/prover/smt/solver/solver.ts +31 -27
  67. package/src/randomization.ts +84 -35
  68. package/src/resolve.ts +18 -60
  69. package/src/runtime.ts +11 -4
  70. package/src/sany/builtins.ts +3 -4
  71. package/src/sany/generator.ts +128 -176
  72. package/src/sany/levels.ts +6 -30
  73. package/src/sany/lexer.ts +7 -23
  74. package/src/sany/linter.ts +31 -29
  75. package/src/sany/modules.ts +1 -5
  76. package/src/sany/nodes.ts +4 -28
  77. package/src/sany/parse-error.ts +44 -100
  78. package/src/sany/report.ts +25 -40
  79. package/src/sany/selectors.ts +8 -22
  80. package/src/sany/source.ts +8 -15
  81. package/src/sany/xml.ts +11 -42
  82. package/src/search.ts +547 -144
  83. package/src/simulate.ts +694 -0
  84. package/src/spec-description.ts +166 -48
  85. package/src/standard-definitions.ts +2 -3
  86. package/src/standard-modules.ts +264 -68
  87. package/src/state-graph.ts +51 -18
  88. package/src/subexpressions.ts +31 -5
  89. package/src/successors.ts +267 -77
  90. package/src/symmetry.ts +31 -8
  91. package/src/tableau.ts +1 -2
  92. package/src/tlc/fingerprint.ts +183 -61
  93. package/src/tlc/jar-data.ts +113 -6
  94. package/src/tlc/messages.ts +122 -37
  95. package/src/tlc/order.ts +33 -38
  96. package/src/tlc/random.ts +16 -16
  97. package/src/tlc/replay.ts +563 -211
  98. package/src/tlc/summary.ts +2 -4
  99. package/src/tlc/tlc-operators.ts +81 -36
  100. package/src/tlc/tlcext-operators.ts +138 -117
  101. package/src/tlc/trace-spec.ts +273 -0
  102. package/src/tlc/value-stream.ts +143 -0
  103. package/src/tlc/version.ts +2 -4
  104. package/src/typescript/actions.ts +494 -0
  105. package/src/typescript/collections.ts +615 -0
  106. package/src/typescript/compile.ts +70 -0
  107. package/src/typescript/context.ts +106 -0
  108. package/src/typescript/emit.ts +122 -0
  109. package/src/typescript/expressions.ts +508 -0
  110. package/src/typescript/formula.ts +160 -0
  111. package/src/typescript/functions.ts +295 -0
  112. package/src/typescript/model.ts +164 -0
  113. package/src/typescript/names.ts +116 -0
  114. package/src/typescript/program.ts +51 -0
  115. package/src/typescript/properties.ts +148 -0
  116. package/src/typescript/scope.ts +117 -0
  117. package/src/typescript/steps.ts +175 -0
  118. package/src/typescript/types.ts +178 -0
  119. package/src/values.ts +832 -255
package/src/config.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { TlaConfigError } from "./errors";
2
- import { matchOperator, matchUnicodeToken } from "./lexer";
1
+ import { getUnexpectedException, TlaConfigError } from "./errors";
2
+ import { EXIT_STATUS, setExitCode } from "./exit-codes";
3
+ import { matchBasedNumber, matchOperator, matchUnicodeToken } from "./lexer";
3
4
  import { formatLexicalError } from "./sany/lexer";
4
5
  import type { TlcVersion } from "./tlc/version";
5
6
 
@@ -33,6 +34,7 @@ export interface ModelConfig {
33
34
  actionConstraints: string[];
34
35
  constants: ConstantAssignment[];
35
36
  substitutions: Substitution[];
37
+ rawConstants: string[];
36
38
  checkDeadlock: boolean;
37
39
  symmetry: string | undefined;
38
40
  view: string | undefined;
@@ -78,15 +80,25 @@ const KEYWORDS = new Set([
78
80
  "_RL_REWARD",
79
81
  ]);
80
82
 
81
- // TLC 1.7.4 reads a TYPE and a TYPE_CONSTRAINT, which it doesn't check, and none of the keywords
82
- // that came after it.
83
+ // TLC 1.7.4 reads TYPE and TYPE_CONSTRAINT without checking them, and none of the later keywords.
83
84
  const TYPE_KEYWORDS = ["TYPE", "TYPE_CONSTRAINT"];
84
85
  const KEYWORDS_174 = new Set([...SHARED_KEYWORDS, ...TYPE_KEYWORDS]);
85
86
 
86
87
  const SYMBOLS = ["<-", "<<", ">>", "=", "{", "}", ",", "[", "]", "(", ")", "!"];
87
88
 
88
- // TLC reads a configuration file with the TLA+ lexer. A lexical error ends the tokens; TLC reports
89
- // it only when it reads that far.
89
+ const getCommentLength = (text: string) => {
90
+ const cursor = { index: 0, depth: 0 };
91
+ do {
92
+ if (cursor.index >= text.length) return undefined;
93
+ const pair = text.slice(cursor.index, cursor.index + 2);
94
+ const step = pair === "(*" ? 1 : pair === "*)" ? -1 : 0;
95
+ cursor.depth += step;
96
+ cursor.index += step === 0 ? 1 : 2;
97
+ } while (cursor.depth > 0);
98
+ return cursor.index;
99
+ };
100
+
101
+ // A lexical error ends the tokens, and TLC reports it only when it reads that far.
90
102
  const tokenizeConfig = (source: string) => {
91
103
  const tokens: ConfigToken[] = [];
92
104
  const cursor = { index: 0, line: 1, lineStart: 0 };
@@ -97,8 +109,7 @@ const tokenizeConfig = (source: string) => {
97
109
  line: cursor.line,
98
110
  });
99
111
  };
100
- // TLC appends a newline to the file. JavaCC reports a token that the end of the input cuts off,
101
- // that newline included, at the start of the line after it.
112
+ // TLC appends a newline, and JavaCC reports a token it cuts off at the start of the next line.
102
113
  const addEndOfInputError = (after: string) => {
103
114
  tokens.push({
104
115
  kind: "Error",
@@ -127,17 +138,19 @@ const tokenizeConfig = (source: string) => {
127
138
  continue;
128
139
  }
129
140
  if (rest.startsWith("(*")) {
130
- const end = rest.indexOf("*)");
131
- if (end === -1) {
141
+ const length = getCommentLength(rest);
142
+ if (length === undefined) {
132
143
  skip(rest);
133
144
  addEndOfInputError("");
134
145
  return tokens;
135
146
  }
136
- skip(rest.slice(0, end + 2));
147
+ skip(rest.slice(0, length));
137
148
  continue;
138
149
  }
139
150
  const line = cursor.line;
140
- const number = /^\d+(?![A-Za-z_])/.exec(rest)?.[0];
151
+ const basedLength = matchBasedNumber(source, cursor.index);
152
+ const number =
153
+ basedLength > 0 ? rest.slice(0, basedLength) : /^\d+(?![A-Za-z_])/.exec(rest)?.[0];
141
154
  if (number) {
142
155
  tokens.push({ kind: "Number", text: number, line });
143
156
  skip(number);
@@ -158,17 +171,17 @@ const tokenizeConfig = (source: string) => {
158
171
  else addLexicalError(cursor.index, text);
159
172
  return tokens;
160
173
  }
161
- tokens.push({ kind: "String", text: string[1], line });
174
+ tokens.push({ kind: "String", text, line });
162
175
  skip(text);
163
176
  continue;
164
177
  }
178
+ const operator = matchUnicodeToken(source, cursor.index) ?? matchOperator(source, cursor.index);
165
179
  const symbol = SYMBOLS.find((candidate) => rest.startsWith(candidate));
166
- if (symbol) {
180
+ if (symbol && symbol.length >= (operator?.length ?? 0)) {
167
181
  tokens.push({ kind: "Symbol", text: symbol, line });
168
182
  skip(symbol);
169
183
  continue;
170
184
  }
171
- const operator = matchUnicodeToken(source, cursor.index) ?? matchOperator(source, cursor.index);
172
185
  if (!operator) {
173
186
  addLexicalError(cursor.index, "");
174
187
  return tokens;
@@ -180,7 +193,6 @@ const tokenizeConfig = (source: string) => {
180
193
  return tokens;
181
194
  };
182
195
 
183
- // TLC's messages for a configuration file it can't read, from ModelConfig.parse.
184
196
  const createSyntaxError = (line: number, problem: string) =>
185
197
  new TlaConfigError(`TLC found an error in the configuration file at line ${line}\n${problem}`);
186
198
 
@@ -218,7 +230,7 @@ const LIST_KEYWORDS = new Map<
218
230
  ["_POSSIBLE", "possible"],
219
231
  ]);
220
232
 
221
- // A port of TLC's ModelConfig.parse, which takes any token where it expects a name or a value.
233
+ // Like TLC, take any token where a name or a value is expected.
222
234
  export const parseConfig = (source: string, version: TlcVersion = "master"): ModelConfig => {
223
235
  const keywords = version === "1.7.4" ? KEYWORDS_174 : KEYWORDS;
224
236
  const tokens = tokenizeConfig(source);
@@ -233,6 +245,7 @@ export const parseConfig = (source: string, version: TlcVersion = "master"): Mod
233
245
  actionConstraints: [],
234
246
  constants: [],
235
247
  substitutions: [],
248
+ rawConstants: [],
236
249
  checkDeadlock: true,
237
250
  symmetry: undefined,
238
251
  view: undefined,
@@ -253,8 +266,21 @@ export const parseConfig = (source: string, version: TlcVersion = "master"): Mod
253
266
  };
254
267
 
255
268
  const parseValue = (token: ConfigToken): ConfigValue => {
269
+ if (token.kind === "Number" && token.text.startsWith("\\")) {
270
+ throw setExitCode(
271
+ new TlaConfigError(
272
+ `${getUnexpectedException("java.lang.NumberFormatException")}For input string: "${token.text}"`,
273
+ ),
274
+ EXIT_STATUS.error,
275
+ );
276
+ }
256
277
  if (token.kind === "Number") return { kind: "Number", value: Number(token.text) };
257
- if (token.kind === "String") return { kind: "String", value: token.text };
278
+ if (token.kind === "String" && token.text.includes("\\")) {
279
+ throw new TlaConfigError(
280
+ `TLC found an error in the configuration file:\nescape sequences are not supported in strings at line ${token.line}`,
281
+ );
282
+ }
283
+ if (token.kind === "String") return { kind: "String", value: token.text.slice(1, -1) };
258
284
  if (token.text === "TRUE" || token.text === "FALSE")
259
285
  return { kind: "Boolean", value: token.text === "TRUE" };
260
286
  if (token.text === "{") {
@@ -277,7 +303,6 @@ export const parseConfig = (source: string, version: TlcVersion = "master"): Mod
277
303
  throw createSyntaxError(token.line, "It was expecting a value, but did not find it.");
278
304
  };
279
305
 
280
- // A module name in brackets after = or <-, which applies the assignment in that module.
281
306
  const parseModuleScope = (operator: string) => {
282
307
  const name = advance();
283
308
  if (name.kind === "End") {
@@ -291,61 +316,69 @@ export const parseConfig = (source: string, version: TlcVersion = "master"): Mod
291
316
  };
292
317
 
293
318
  // TLC reports a malformed argument list at the line of the CONSTANT keyword.
294
- const parseConstants = (keywordLine: number) => {
295
- while (true) {
296
- const first = advance();
297
- if (first.kind === "End" || keywords.has(first.text)) return first;
298
- const current = { token: advance(), name: first.text };
299
- while (current.token.text === "!") {
300
- current.name = `${current.name}!${advance().text}`;
301
- current.token = advance();
302
- }
303
- const name = current.name;
304
- if (current.token.text === "<-") {
305
- current.token = advance();
306
- if (current.token.text === "[") {
307
- const module = parseModuleScope("<-");
308
- const target = advance();
309
- if (target.kind === "End") {
310
- throw createSyntaxError(target.line, "Expected an identifier after <-[mod].");
311
- }
312
- config.substitutions.push({ name, target: target.text, module });
313
- continue;
314
- }
315
- if (current.token.kind === "End") {
316
- throw createSyntaxError(current.token.line, "Expected an identifier after <-.");
319
+ const parseConstant = (first: ConfigToken, keywordLine: number) => {
320
+ const current = { token: advance(), name: first.text };
321
+ while (current.token.text === "!") {
322
+ current.name = `${current.name}!${advance().text}`;
323
+ current.token = advance();
324
+ }
325
+ const name = current.name;
326
+ if (current.token.text === "<-") {
327
+ current.token = advance();
328
+ if (current.token.text === "[") {
329
+ const module = parseModuleScope("<-");
330
+ const target = advance();
331
+ if (target.kind === "End") {
332
+ throw createSyntaxError(target.line, "Expected an identifier after <-[mod].");
317
333
  }
318
- config.substitutions.push({ name, target: current.token.text });
319
- continue;
334
+ config.substitutions.push({ name, target: target.text, module });
335
+ return;
320
336
  }
321
- const args: ConfigValue[] = [];
322
- const hasArgs = current.token.text === "(";
323
- if (hasArgs) {
324
- while (true) {
325
- args.push(parseValue(advance()));
326
- current.token = advance();
327
- if (current.token.text !== ",") break;
328
- }
329
- if (current.token.text !== ")") {
330
- throw createSyntaxError(keywordLine, "");
331
- }
337
+ if (current.token.kind === "End") {
338
+ throw createSyntaxError(current.token.line, "Expected an identifier after <-.");
339
+ }
340
+ config.substitutions.push({ name, target: current.token.text });
341
+ return;
342
+ }
343
+ const args: ConfigValue[] = [];
344
+ const hasArgs = current.token.text === "(";
345
+ if (hasArgs) {
346
+ while (true) {
347
+ args.push(parseValue(advance()));
332
348
  current.token = advance();
349
+ if (current.token.text !== ",") break;
333
350
  }
334
- if (current.token.text !== "=") {
335
- throw createSyntaxError(
336
- current.token.line,
337
- "It was expecting = or <-, but did not find it.",
338
- );
351
+ if (current.token.text !== ")") {
352
+ throw createSyntaxError(keywordLine, "");
339
353
  }
340
354
  current.token = advance();
341
- const module = current.token.text === "[" ? parseModuleScope("=") : undefined;
342
- const value = parseValue(module === undefined ? current.token : advance());
343
- config.constants.push({
344
- name,
345
- value,
346
- ...(hasArgs && { args }),
347
- ...(module !== undefined && { module }),
348
- });
355
+ }
356
+ if (current.token.text !== "=") {
357
+ throw createSyntaxError(current.token.line, "It was expecting = or <-, but did not find it.");
358
+ }
359
+ current.token = advance();
360
+ const module = current.token.text === "[" ? parseModuleScope("=") : undefined;
361
+ const value = parseValue(module === undefined ? current.token : advance());
362
+ config.constants.push({
363
+ name,
364
+ value,
365
+ ...(hasArgs && { args }),
366
+ ...(module !== undefined && { module }),
367
+ });
368
+ };
369
+
370
+ const parseConstants = (keywordLine: number) => {
371
+ while (true) {
372
+ const first = advance();
373
+ if (first.kind === "End" || keywords.has(first.text)) return first;
374
+ const start = cursor.index - 1;
375
+ parseConstant(first, keywordLine);
376
+ config.rawConstants.push(
377
+ tokens
378
+ .slice(start, cursor.index)
379
+ .map((token) => token.text)
380
+ .join(" "),
381
+ );
349
382
  }
350
383
  };
351
384