tla-ts 0.0.10-dev.28c823e4b → 0.0.10-dev.b4a856304
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/dist/index.cjs +1 -1
- package/dist/index.d.cts +0 -34
- package/dist/index.d.ts +0 -34
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +43 -43
- package/dist/prove.js +47 -47
- package/dist/run.cjs +30 -30
- package/dist/run.js +33 -33
- package/dist/transfer.cjs +38 -38
- package/dist/transfer.js +39 -39
- package/package.json +1 -1
- package/src/ast.ts +5 -0
- package/src/bags.ts +5 -2
- package/src/builtins.ts +8 -1
- package/src/check.ts +193 -128
- package/src/cli/run.ts +2 -0
- package/src/cli/runtime-invariants.ts +7 -8
- package/src/cli/shared.ts +4 -0
- package/src/cli/tlc-arguments.ts +30 -24
- package/src/cli/tlc-usage.ts +3 -2
- package/src/evaluate.ts +102 -26
- package/src/java-overrides.ts +9 -4
- package/src/json-reader.ts +2 -1
- package/src/json.ts +11 -4
- package/src/levels.ts +15 -7
- package/src/lexer.ts +83 -72
- package/src/liveness-checker.ts +106 -77
- package/src/liveness.ts +34 -10
- package/src/parallel.ts +33 -26
- package/src/parser.ts +226 -163
- package/src/pcal/ast.ts +65 -53
- package/src/pcal/parse.ts +191 -144
- package/src/pcal/tokenize.ts +115 -91
- package/src/pcal/translate.ts +98 -83
- package/src/pcal/validate.ts +50 -48
- package/src/pretty-print.ts +6 -6
- package/src/randomization.ts +4 -1
- package/src/resolve.ts +70 -12
- package/src/runtime.ts +18 -11
- package/src/sany/builtins.ts +3 -1
- package/src/sany/generator.ts +127 -74
- package/src/sany/levels.ts +9 -5
- package/src/sany/lexer.ts +44 -40
- package/src/sany/linter.ts +1 -0
- package/src/search.ts +1 -1
- package/src/simulate.ts +59 -50
- package/src/spec-description.ts +34 -23
- package/src/standard-definitions.ts +3 -0
- package/src/standard-modules.ts +12 -1
- package/src/state-graph.ts +8 -1
- package/src/subexpressions.ts +47 -38
- package/src/successors.ts +35 -14
- package/src/symmetry.ts +19 -4
- package/src/tlc/fingerprint.ts +21 -15
- package/src/tlc/jar-data.ts +1 -0
- package/src/tlc/messages.ts +21 -2
- package/src/tlc/order.ts +38 -20
- package/src/tlc/random.ts +30 -18
- package/src/tlc/replay.ts +33 -13
- package/src/tlc/summary.ts +45 -36
- package/src/tlc/tlc-operators.ts +14 -4
- package/src/tlc/tlcext-operators.ts +15 -11
- package/src/tlc/trace-spec.ts +4 -0
- package/src/tlc/value-stream.ts +13 -9
- package/src/tlc/version.ts +1 -0
- package/src/values.ts +181 -74
package/src/cli/run.ts
CHANGED
|
@@ -5,6 +5,8 @@ import { runTlapm } from "./tlapm";
|
|
|
5
5
|
import { checkSpecs } from "./tlc";
|
|
6
6
|
import { exportXml, exportXml174 } from "./xml-exporter";
|
|
7
7
|
|
|
8
|
+
// Tools that run TLC with Java can run tla-ts in place of java, as in
|
|
9
|
+
// `tla-ts -DTLA-Library=lib -cp tla2tools.jar tlc2.TLC Spec`. Other JVM options are ignored.
|
|
8
10
|
const JAVA_MAIN_CLASSES = ["tlc2.TLC", "tla2sany.xml.XMLExporter"];
|
|
9
11
|
|
|
10
12
|
const TLA_LIBRARY_PROPERTY = "-DTLA-Library=";
|
|
@@ -50,8 +50,7 @@ const getDebuggerExpressionLevel = (
|
|
|
50
50
|
if (!(error instanceof TlaSyntaxError)) throw error;
|
|
51
51
|
throw createParsingFailure(`Syntax error while parsing breakpoint expression "${expression}"`);
|
|
52
52
|
}
|
|
53
|
-
|
|
54
|
-
let isLevelCorrect = false;
|
|
53
|
+
const result = { isSemanticCorrect: false, isLevelCorrect: false };
|
|
55
54
|
const specification = (() => {
|
|
56
55
|
try {
|
|
57
56
|
return generateSanySpecification(text, loadModule, {
|
|
@@ -59,13 +58,13 @@ const getDebuggerExpressionLevel = (
|
|
|
59
58
|
onModule: (module, messages) => {
|
|
60
59
|
const isCorrect = () => messages.every((message) => message.isWarning);
|
|
61
60
|
if (!isCorrect()) return;
|
|
62
|
-
const
|
|
61
|
+
const isLevelCorrect = checkModuleLevels(module, {
|
|
63
62
|
messages,
|
|
64
63
|
isTlc174: version === "1.7.4",
|
|
65
64
|
});
|
|
66
65
|
if (module.name !== moduleName) return;
|
|
67
|
-
isSemanticCorrect = true;
|
|
68
|
-
isLevelCorrect =
|
|
66
|
+
result.isSemanticCorrect = true;
|
|
67
|
+
result.isLevelCorrect = isLevelCorrect && isCorrect();
|
|
69
68
|
},
|
|
70
69
|
});
|
|
71
70
|
} catch (error) {
|
|
@@ -73,8 +72,8 @@ const getDebuggerExpressionLevel = (
|
|
|
73
72
|
throw createFailure("Semantic error");
|
|
74
73
|
}
|
|
75
74
|
})();
|
|
76
|
-
if (!isSemanticCorrect) throw createFailure("Semantic error");
|
|
77
|
-
if (!isLevelCorrect) throw createFailure("Level-checking error");
|
|
75
|
+
if (!result.isSemanticCorrect) throw createFailure("Semantic error");
|
|
76
|
+
if (!result.isLevelCorrect) throw createFailure("Level-checking error");
|
|
78
77
|
const level = findDefinition(specification.root, name)?.level ?? CONSTANT_LEVEL;
|
|
79
78
|
if (level === TEMPORAL_LEVEL) {
|
|
80
79
|
throw createParsingFailure(
|
|
@@ -84,7 +83,7 @@ const getDebuggerExpressionLevel = (
|
|
|
84
83
|
return level;
|
|
85
84
|
};
|
|
86
85
|
|
|
87
|
-
//
|
|
86
|
+
// TLC puts a generated operator in a module that extends the root module; tla-ts appends it instead.
|
|
88
87
|
export const addRuntimeInvariants = (
|
|
89
88
|
source: string,
|
|
90
89
|
root: ModuleNode,
|
package/src/cli/shared.ts
CHANGED
|
@@ -86,14 +86,18 @@ export const reportErrors = async (
|
|
|
86
86
|
}
|
|
87
87
|
};
|
|
88
88
|
|
|
89
|
+
// TLC 1.7.4 names the last file SimpleFilenameToStream looked for, and the directories it looked
|
|
90
|
+
// in, the jar's standard modules last.
|
|
89
91
|
export const printMissingFile174 = (path: string, libraries: string[], jar: string | undefined) =>
|
|
90
92
|
console.error(
|
|
91
93
|
`File does not exist: ${isAbsolute(path) ? path : `${process.cwd()}/${path}`} while looking in these directories: ${[...libraries, ...(jar === undefined ? [] : [getStandardModulesUrl(jar)])].join(", ")}`,
|
|
92
94
|
);
|
|
93
95
|
|
|
96
|
+
// SimpleFilenameToStream ends a library directory with a separator.
|
|
94
97
|
export const toLibraryPath = (directory: string) =>
|
|
95
98
|
directory.endsWith("/") ? directory : `${directory}/`;
|
|
96
99
|
|
|
100
|
+
// TLC 1.7.4's SANY reports each module it can't find as it looks for it.
|
|
97
101
|
export const reportMissingModules174 =
|
|
98
102
|
(loadModule: (name: string) => string | undefined, onMissing: (fileName: string) => void) =>
|
|
99
103
|
(name: string) => {
|
package/src/cli/tlc-arguments.ts
CHANGED
|
@@ -44,6 +44,8 @@ export interface RuntimeInvariant {
|
|
|
44
44
|
expression: string;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
// TLC prints a command line error as -tool asks only if -tool came first. An argument TLC reads
|
|
48
|
+
// past the end, or can't parse without catching the exception, ends TLC with that exception.
|
|
47
49
|
export interface TlcArgumentsError {
|
|
48
50
|
error: string;
|
|
49
51
|
isTool: boolean;
|
|
@@ -145,9 +147,10 @@ const LOADED_TRACES: Record<string, TraceFormat> = {
|
|
|
145
147
|
const isInRanges = (ranges: number[][], code: number) =>
|
|
146
148
|
ranges.some((range) => code >= range[0] && code <= range[1]);
|
|
147
149
|
|
|
148
|
-
|
|
150
|
+
// String#split drops the empty strings at the end.
|
|
151
|
+
const splitLikeJava = (text: string) => {
|
|
149
152
|
if (text === "") return [text];
|
|
150
|
-
const parts = text.split(
|
|
153
|
+
const parts = text.split(",");
|
|
151
154
|
while (parts.at(-1) === "") parts.pop();
|
|
152
155
|
return parts;
|
|
153
156
|
};
|
|
@@ -235,7 +238,7 @@ const SWITCHES: Record<string, (parsed: TlcArguments) => void> = {
|
|
|
235
238
|
|
|
236
239
|
export const parseTlcArguments = (args: string[]): TlcArguments | TlcArgumentsError => {
|
|
237
240
|
const parsed = createDefaults();
|
|
238
|
-
|
|
241
|
+
const cursor = { index: 0 };
|
|
239
242
|
const reject = (error: string): TlcArgumentsError => ({ error, isTool: parsed.isTool });
|
|
240
243
|
const getMissing = (): TlcArgumentsError => ({
|
|
241
244
|
error: `java.lang.ArrayIndexOutOfBoundsException: Index ${args.length} out of bounds for length ${args.length}`,
|
|
@@ -244,19 +247,20 @@ export const parseTlcArguments = (args: string[]): TlcArguments | TlcArgumentsEr
|
|
|
244
247
|
});
|
|
245
248
|
const suppressedCodes: MessageCodes = { tlc: [], sany: [] };
|
|
246
249
|
const errorCodes: MessageCodes = { tlc: [], sany: [] };
|
|
247
|
-
const peek = () => args[
|
|
248
|
-
const take = () => args[
|
|
250
|
+
const peek = () => args[cursor.index];
|
|
251
|
+
const take = () => args[cursor.index++];
|
|
249
252
|
const readInteger = (bits: 32 | 64, missing: string, malformed: string) => {
|
|
250
253
|
const text = peek();
|
|
251
254
|
if (text === undefined) return reject(missing);
|
|
252
255
|
const value = parseJavaInteger(text, bits);
|
|
253
256
|
if (value === undefined) return reject(`${malformed} But encountered ${text}`);
|
|
254
|
-
|
|
257
|
+
cursor.index++;
|
|
255
258
|
return value;
|
|
256
259
|
};
|
|
257
|
-
while (
|
|
260
|
+
while (cursor.index < args.length) {
|
|
258
261
|
const flag = take();
|
|
259
|
-
|
|
262
|
+
const isSwitch = Object.hasOwn(SWITCHES, flag);
|
|
263
|
+
if (isSwitch) {
|
|
260
264
|
SWITCHES[flag](parsed);
|
|
261
265
|
continue;
|
|
262
266
|
}
|
|
@@ -269,7 +273,7 @@ export const parseTlcArguments = (args: string[]): TlcArguments | TlcArgumentsEr
|
|
|
269
273
|
) {
|
|
270
274
|
continue;
|
|
271
275
|
}
|
|
272
|
-
|
|
276
|
+
cursor.index++;
|
|
273
277
|
const hasFile = options.split(",").some((option) => option.startsWith("file="));
|
|
274
278
|
parsed.scheduler = options.split(",").includes("sched=rl")
|
|
275
279
|
? "rl"
|
|
@@ -300,22 +304,21 @@ export const parseTlcArguments = (args: string[]): TlcArguments | TlcArgumentsEr
|
|
|
300
304
|
return reject(`Error: ${flag} requires a comma-separated list of message codes.`);
|
|
301
305
|
}
|
|
302
306
|
const codes = flag === "-suppressMessages" ? suppressedCodes : errorCodes;
|
|
303
|
-
for (const item of splitLikeJava(text
|
|
307
|
+
for (const item of splitLikeJava(text)) {
|
|
304
308
|
const trimmed = item.replace(/^[^!-\uffff]+|[^!-\uffff]+$/g, "");
|
|
305
309
|
const parsedCode = parseJavaInteger(trimmed, 32);
|
|
306
310
|
if (parsedCode === undefined) return reject(`Error: For input string: "${trimmed}"`);
|
|
307
311
|
const code = Number(parsedCode);
|
|
308
312
|
if (isInRanges(TLC_MESSAGE_CODES, code)) {
|
|
309
313
|
codes.tlc.push(code);
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
314
|
+
} else if (SANY_WARNING_CODES.has(code) || isInRanges(SANY_ERROR_CODES, code)) {
|
|
315
|
+
if (codes === suppressedCodes && !SANY_WARNING_CODES.has(code)) {
|
|
316
|
+
return reject(`Error: code ${code} is an error and cannot be suppressed.`);
|
|
317
|
+
}
|
|
318
|
+
codes.sany.push(code);
|
|
319
|
+
} else {
|
|
313
320
|
return reject(`Error: unknown message code: ${code}`);
|
|
314
321
|
}
|
|
315
|
-
if (codes === suppressedCodes && !SANY_WARNING_CODES.has(code)) {
|
|
316
|
-
return reject(`Error: code ${code} is an error and cannot be suppressed.`);
|
|
317
|
-
}
|
|
318
|
-
codes.sany.push(code);
|
|
319
322
|
}
|
|
320
323
|
continue;
|
|
321
324
|
}
|
|
@@ -367,13 +370,13 @@ export const parseTlcArguments = (args: string[]): TlcArguments | TlcArgumentsEr
|
|
|
367
370
|
options.includes(option),
|
|
368
371
|
)
|
|
369
372
|
) {
|
|
370
|
-
|
|
373
|
+
cursor.index++;
|
|
371
374
|
}
|
|
372
375
|
continue;
|
|
373
376
|
}
|
|
374
377
|
if (flag === "-generateSpecTE") {
|
|
375
378
|
parsed.isTraceSpecForced = true;
|
|
376
|
-
if (peek() === "nomonolith")
|
|
379
|
+
if (peek() === "nomonolith") cursor.index++;
|
|
377
380
|
continue;
|
|
378
381
|
}
|
|
379
382
|
if (flag === "-noGenerateSpecTE" || flag.toLowerCase() === "-note") {
|
|
@@ -407,16 +410,17 @@ export const parseTlcArguments = (args: string[]): TlcArguments | TlcArgumentsEr
|
|
|
407
410
|
`Trying to instantiate a custom IStateWriter implementation ${format.replaceAll("class,", "")}.`,
|
|
408
411
|
);
|
|
409
412
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
+
// Like TLC, -dump takes a format only when it starts with dot and a file follows.
|
|
414
|
+
const arity = format?.startsWith("dot") && cursor.index + 1 < args.length ? 2 : 1;
|
|
415
|
+
parsed.dump = args.slice(cursor.index, cursor.index + arity);
|
|
416
|
+
cursor.index += arity;
|
|
413
417
|
if (parsed.dump.length === 0)
|
|
414
418
|
return reject("Error: A file name for dumping states required.");
|
|
415
419
|
continue;
|
|
416
420
|
}
|
|
417
421
|
if (flag.toLowerCase() === "-loadtrace" || flag.toLowerCase() === "-dumptrace") {
|
|
418
422
|
const name = flag.toLowerCase() === "-loadtrace" ? "-loadTrace" : "-dumpTrace";
|
|
419
|
-
if (
|
|
423
|
+
if (cursor.index + 1 >= args.length) {
|
|
420
424
|
return reject(
|
|
421
425
|
name === "-loadTrace"
|
|
422
426
|
? "Error: A format and a file name for loading traces required."
|
|
@@ -445,7 +449,9 @@ export const parseTlcArguments = (args: string[]): TlcArguments | TlcArgumentsEr
|
|
|
445
449
|
if (!target.includes("!")) {
|
|
446
450
|
return reject(`Module!Operator for postCondition required. Encountered: ${target}`);
|
|
447
451
|
}
|
|
448
|
-
|
|
452
|
+
// String#split drops the empty strings at the end.
|
|
453
|
+
const parts = target.split("!");
|
|
454
|
+
while (parts.length > 0 && parts[parts.length - 1] === "") parts.pop();
|
|
449
455
|
if (parts.length !== 2) {
|
|
450
456
|
return reject(
|
|
451
457
|
`Module!Operator for postCondition must be of the form module!operator. Encountered: ${target}`,
|
package/src/cli/tlc-usage.ts
CHANGED
|
@@ -322,6 +322,7 @@ const getVariantSynopsis = (variant: UsageArgument[]) => {
|
|
|
322
322
|
].join(" ");
|
|
323
323
|
};
|
|
324
324
|
|
|
325
|
+
// TLC names its build by its UTC timestamp, or by the current time when it has no manifest.
|
|
325
326
|
const getBuildVersion = () =>
|
|
326
327
|
new Date()
|
|
327
328
|
.toISOString()
|
|
@@ -329,8 +330,8 @@ const getBuildVersion = () =>
|
|
|
329
330
|
|
|
330
331
|
export const getTlcUsage = () => {
|
|
331
332
|
const options = [
|
|
332
|
-
...new Map
|
|
333
|
-
COMMAND_VARIANTS.flat().map((argument) => [argument.name, argument]),
|
|
333
|
+
...new Map(
|
|
334
|
+
COMMAND_VARIANTS.flat().map((argument) => [argument.name, argument] as const),
|
|
334
335
|
).values(),
|
|
335
336
|
]
|
|
336
337
|
.sort(compareNames)
|