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.
- package/README.md +30 -0
- package/dist/compile.cjs +23 -0
- package/dist/compile.js +23 -0
- package/dist/deciders.cjs +15 -15
- package/dist/deciders.js +40 -40
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +80 -10
- package/dist/index.d.ts +80 -10
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove-worker.cjs +1 -1
- package/dist/prove-worker.js +1 -1
- package/dist/prove.cjs +116 -36
- package/dist/prove.js +116 -36
- package/dist/run.cjs +143 -31
- package/dist/run.js +143 -31
- package/dist/tlapm.cjs +2 -2
- package/dist/tlapm.js +1 -1
- package/dist/transfer.cjs +128 -103
- package/dist/transfer.js +128 -103
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +3 -1
- package/src/ast.ts +7 -21
- package/src/bags.ts +99 -99
- package/src/builtins.ts +44 -75
- package/src/bundled-modules.ts +1 -8
- package/src/check.ts +605 -311
- package/src/cli/options.ts +12 -3
- package/src/cli/run.ts +2 -2
- package/src/cli/runtime-invariants.ts +135 -0
- package/src/cli/shared.ts +20 -9
- package/src/cli/tlc-arguments.ts +646 -0
- package/src/cli/tlc-usage.ts +362 -0
- package/src/cli/tlc.ts +571 -185
- package/src/cli/typescript.ts +26 -0
- package/src/cli/xml-exporter.ts +4 -10
- package/src/codegen.ts +190 -46
- package/src/config.ts +101 -68
- package/src/coverage.ts +855 -0
- package/src/dependencies.ts +20 -28
- package/src/dfid.ts +636 -0
- package/src/environment.ts +266 -98
- package/src/errors.ts +142 -45
- package/src/evaluate.ts +632 -298
- package/src/exit-codes.ts +37 -1
- package/src/index.ts +3 -0
- package/src/instances.ts +85 -9
- package/src/java-overrides.ts +2 -12
- package/src/json-reader.ts +456 -0
- package/src/json.ts +262 -139
- package/src/levels.ts +2 -3
- package/src/lexer.ts +17 -26
- package/src/liveness-checker.ts +10 -18
- package/src/liveness.ts +121 -49
- package/src/parallel-worker.ts +14 -10
- package/src/parallel.ts +41 -17
- package/src/parser.ts +436 -90
- package/src/pcal/ast.ts +7 -28
- package/src/pcal/parse.ts +11 -39
- package/src/pcal/tokenize.ts +4 -20
- package/src/pcal/translate.ts +10 -42
- package/src/pcal/validate.ts +3 -21
- package/src/pretty-print.ts +1 -2
- package/src/prover/smt/solver/solver.ts +31 -27
- package/src/randomization.ts +84 -35
- package/src/resolve.ts +18 -60
- package/src/runtime.ts +11 -4
- package/src/sany/builtins.ts +3 -4
- package/src/sany/generator.ts +128 -176
- package/src/sany/levels.ts +6 -30
- package/src/sany/lexer.ts +7 -23
- package/src/sany/linter.ts +31 -29
- package/src/sany/modules.ts +1 -5
- package/src/sany/nodes.ts +4 -28
- package/src/sany/parse-error.ts +44 -100
- package/src/sany/report.ts +25 -40
- package/src/sany/selectors.ts +8 -22
- package/src/sany/source.ts +8 -15
- package/src/sany/xml.ts +11 -42
- package/src/search.ts +547 -144
- package/src/simulate.ts +694 -0
- package/src/spec-description.ts +166 -48
- package/src/standard-definitions.ts +2 -3
- package/src/standard-modules.ts +264 -68
- package/src/state-graph.ts +51 -18
- package/src/subexpressions.ts +31 -5
- package/src/successors.ts +267 -77
- package/src/symmetry.ts +31 -8
- package/src/tableau.ts +1 -2
- package/src/tlc/fingerprint.ts +183 -61
- package/src/tlc/jar-data.ts +113 -6
- package/src/tlc/messages.ts +122 -37
- package/src/tlc/order.ts +33 -38
- package/src/tlc/random.ts +16 -16
- package/src/tlc/replay.ts +563 -211
- package/src/tlc/summary.ts +2 -4
- package/src/tlc/tlc-operators.ts +81 -36
- package/src/tlc/tlcext-operators.ts +138 -117
- package/src/tlc/trace-spec.ts +273 -0
- package/src/tlc/value-stream.ts +143 -0
- package/src/tlc/version.ts +2 -4
- package/src/typescript/actions.ts +494 -0
- package/src/typescript/collections.ts +615 -0
- package/src/typescript/compile.ts +70 -0
- package/src/typescript/context.ts +106 -0
- package/src/typescript/emit.ts +122 -0
- package/src/typescript/expressions.ts +508 -0
- package/src/typescript/formula.ts +160 -0
- package/src/typescript/functions.ts +295 -0
- package/src/typescript/model.ts +164 -0
- package/src/typescript/names.ts +116 -0
- package/src/typescript/program.ts +51 -0
- package/src/typescript/properties.ts +148 -0
- package/src/typescript/scope.ts +117 -0
- package/src/typescript/steps.ts +175 -0
- package/src/typescript/types.ts +178 -0
- package/src/values.ts +832 -255
package/src/config.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { TlaConfigError } from "./errors";
|
|
2
|
-
import {
|
|
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
|
|
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
|
-
|
|
89
|
-
|
|
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
|
|
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
|
|
131
|
-
if (
|
|
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,
|
|
147
|
+
skip(rest.slice(0, length));
|
|
137
148
|
continue;
|
|
138
149
|
}
|
|
139
150
|
const line = cursor.line;
|
|
140
|
-
const
|
|
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
|
|
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
|
-
//
|
|
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"
|
|
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
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
if (
|
|
307
|
-
|
|
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:
|
|
319
|
-
|
|
334
|
+
config.substitutions.push({ name, target: target.text, module });
|
|
335
|
+
return;
|
|
320
336
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
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
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
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
|
|