tla-ts 0.0.3-dev.6a30eee → 0.0.3-dev.6d0aeb6
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 +5 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +58 -22
- package/dist/index.d.ts +58 -22
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +2 -2
- package/dist/parallel.cjs +1 -1
- package/dist/parallel.js +2 -2
- package/dist/run-cli.cjs +20 -18
- package/dist/run-cli.js +22 -20
- package/dist/transfer.cjs +40 -15
- package/dist/transfer.js +40 -15
- package/package.json +1 -1
- package/src/ast.ts +101 -1
- package/src/builtins.ts +9 -3
- package/src/check.ts +473 -100
- package/src/cli-options.ts +11 -5
- package/src/codegen.ts +15 -22
- package/src/config.ts +224 -170
- package/src/dependencies.ts +2 -2
- package/src/environment.ts +158 -49
- package/src/errors.ts +93 -3
- package/src/evaluate.ts +214 -147
- package/src/exit-codes.ts +21 -14
- package/src/fingerprints.ts +2 -1
- package/src/instances.ts +16 -15
- package/src/levels.ts +181 -45
- package/src/live-check.ts +132 -70
- package/src/liveness.ts +118 -24
- package/src/parallel-worker.ts +2 -2
- package/src/parallel.ts +5 -2
- package/src/parser.ts +71 -19
- package/src/resolve.ts +490 -95
- package/src/run-cli.ts +104 -18
- package/src/runtime.ts +2 -0
- package/src/sany-lexer.ts +615 -0
- package/src/sany-parse-error.ts +3143 -0
- package/src/spec-description.ts +19 -8
- package/src/standard-modules.ts +54 -45
- package/src/state-graph.ts +157 -0
- package/src/subexpressions.ts +35 -23
- package/src/substitution-levels.ts +38 -17
- package/src/successors.ts +176 -36
- package/src/symmetry.ts +16 -6
- package/src/tableau.ts +51 -24
- package/src/tlc-ext.ts +29 -12
- package/src/tlc-module.ts +14 -33
- package/src/tlc-modules.ts +4 -0
- package/src/tlc-order.ts +8 -4
- package/src/tlc-random.ts +9 -6
- package/src/tlc-summary.ts +20 -5
- package/src/value-sources.ts +29 -0
- package/src/values.ts +242 -61
package/src/run-cli.ts
CHANGED
|
@@ -10,29 +10,33 @@ import {
|
|
|
10
10
|
import { spawnSync } from "node:child_process";
|
|
11
11
|
import { basename, delimiter, dirname, join, resolve } from "node:path";
|
|
12
12
|
import { availableParallelism } from "node:os";
|
|
13
|
-
import type { CheckResult, CheckStatus, TraceStep } from "./check";
|
|
13
|
+
import type { CheckResult, CheckStatus, Replay, TraceStep } from "./check";
|
|
14
14
|
import { defineCommand, type ParsedArgs } from "./cli-options";
|
|
15
15
|
import { parseConfig } from "./config";
|
|
16
16
|
import {
|
|
17
|
+
createSanyError,
|
|
17
18
|
getErrorExitCode,
|
|
18
19
|
TlaConfigError,
|
|
19
20
|
TlaError,
|
|
20
21
|
TlaEvaluationError,
|
|
21
22
|
TlaProofError,
|
|
23
|
+
TlaSyntaxError,
|
|
24
|
+
type SanyReport,
|
|
22
25
|
} from "./errors";
|
|
23
26
|
import { EXIT_STATUS } from "./exit-codes";
|
|
24
27
|
import type { LineRange } from "./obligation-generate";
|
|
25
28
|
import { getAtPrefix, getLocusText } from "./obligation-expression";
|
|
26
29
|
import { formatSummary, getObligations, WHOLE_MODULE, type ModuleObligations } from "./obligations";
|
|
27
30
|
import { check } from "./parallel";
|
|
28
|
-
import {
|
|
31
|
+
import { parseModuleFile } from "./sany-parse-error";
|
|
32
|
+
import type { StateDump } from "./state-graph";
|
|
29
33
|
import {
|
|
30
34
|
formatProbability,
|
|
31
35
|
getActualProbability,
|
|
32
36
|
getOptimisticProbability,
|
|
33
37
|
getOutDegreeSummary,
|
|
34
38
|
} from "./tlc-summary";
|
|
35
|
-
import {
|
|
39
|
+
import { formatState, type Value } from "./values";
|
|
36
40
|
|
|
37
41
|
const EXIT_CODES: Record<CheckStatus, number> = {
|
|
38
42
|
success: EXIT_STATUS.success,
|
|
@@ -48,6 +52,11 @@ const EXIT_CODES: Record<CheckStatus, number> = {
|
|
|
48
52
|
const CHECK_COMMAND = defineCommand("tla-ts <Spec.tla|Spec.cfg|glob>... {options}", [
|
|
49
53
|
{ flag: "-config <Spec.cfg>" },
|
|
50
54
|
{ flag: "-deadlock" },
|
|
55
|
+
// Like TLC, -dump takes a format only when the next argument starts with dot and a file follows.
|
|
56
|
+
{
|
|
57
|
+
flag: "-dump [<format>] <file>",
|
|
58
|
+
getArity: (rest) => (rest.length > 1 && rest[0].startsWith("dot") ? 2 : 1),
|
|
59
|
+
},
|
|
51
60
|
{ flag: "-lncheck <final|default>" },
|
|
52
61
|
{ flag: "-seed <num>" },
|
|
53
62
|
{ flag: "-workers <count|auto>" },
|
|
@@ -95,14 +104,24 @@ const getWorkerCount = (values: string[] | undefined) => {
|
|
|
95
104
|
: Math.max(1, Number.parseInt(values[0], 10) || 1);
|
|
96
105
|
};
|
|
97
106
|
|
|
98
|
-
const printState = (state: Record<string, Value>) =>
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
)
|
|
105
|
-
|
|
107
|
+
const printState = (state: Record<string, Value>) => console.log(formatState(state));
|
|
108
|
+
|
|
109
|
+
const UNSUPPORTED_DUMP_FORMATS = ["constrained", "stuttering", "strict"];
|
|
110
|
+
|
|
111
|
+
// TLC names the file of a -dump by its format unless the name already ends that way.
|
|
112
|
+
const getDumpPath = (path: string, extension: string) =>
|
|
113
|
+
path.endsWith(extension) ? path : `${path}${extension}`;
|
|
114
|
+
|
|
115
|
+
const getDump = (values: string[]): StateDump => {
|
|
116
|
+
if (values.length === 1) return { path: getDumpPath(values[0], ".dump") };
|
|
117
|
+
const format = values[0].toLowerCase();
|
|
118
|
+
return {
|
|
119
|
+
path: getDumpPath(values[1], ".dot"),
|
|
120
|
+
dot: true,
|
|
121
|
+
colorize: format.includes("colorize"),
|
|
122
|
+
actionLabels: format.includes("actionlabels"),
|
|
123
|
+
snapshot: format.includes("snapshot"),
|
|
124
|
+
};
|
|
106
125
|
};
|
|
107
126
|
|
|
108
127
|
const printTrace = (trace: TraceStep[], heading = "Error: The behavior up to this point is:") => {
|
|
@@ -118,14 +137,42 @@ const getTemporalHeadline = (names: string[]) =>
|
|
|
118
137
|
? `Error: Temporal property ${names[0]} was violated.\n`
|
|
119
138
|
: `Error: Temporal properties ${names.slice(0, -1).join(", ")}${names.length > 2 ? "," : ""} and ${names[names.length - 1]} were violated.\n`;
|
|
120
139
|
|
|
140
|
+
const getFrames = (callStack: string[]) =>
|
|
141
|
+
callStack.map((frame, index) => `${index}. ${frame}\n`).join("");
|
|
142
|
+
|
|
143
|
+
const printCallStack = (frames: string) =>
|
|
144
|
+
console.log(
|
|
145
|
+
`Error: The error occurred when TLC was evaluating the nested\nexpressions at the following positions:\n${frames ? `${frames}\n` : " The error call stack is empty.\n"}`,
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
const printReplay = (replay: Replay) => {
|
|
149
|
+
replay.output.forEach((line) => console.log(line));
|
|
150
|
+
const frames = getFrames(replay.callStack ?? []);
|
|
151
|
+
const fingerprint = replay.fingerprint;
|
|
152
|
+
if (replay.isBeforeError) {
|
|
153
|
+
if (frames) printCallStack(frames);
|
|
154
|
+
} else if (replay.callStack && fingerprint) {
|
|
155
|
+
const sources = fingerprint.sources.map((source) => `${source}\n`).join("");
|
|
156
|
+
console.log(
|
|
157
|
+
`Error: TLC was unable to fingerprint.\n\nFingerprint Stack Trace:\n${frames ? `${frames}\n` : sources}\nReason:\n${fingerprint.reason}`,
|
|
158
|
+
);
|
|
159
|
+
} else if (replay.callStack) {
|
|
160
|
+
printCallStack(frames);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
121
164
|
const printResult = (result: CheckResult) => {
|
|
122
165
|
if (result.failure) {
|
|
166
|
+
const replay = result.failure.replay;
|
|
167
|
+
if (replay?.isBeforeError) printReplay(replay);
|
|
123
168
|
console.log(`Error: ${result.failure.message}`);
|
|
124
169
|
if (result.failure.initialState) {
|
|
125
170
|
console.log("While working on the initial state:");
|
|
126
171
|
printState(result.failure.initialState);
|
|
127
172
|
}
|
|
128
173
|
printTrace(result.failure.trace);
|
|
174
|
+
if (replay && !replay.isBeforeError) printReplay(replay);
|
|
175
|
+
if (result.failure.isWithoutStatistics) return;
|
|
129
176
|
} else if (result.violation) {
|
|
130
177
|
const violation = result.violation;
|
|
131
178
|
const name = violation.name;
|
|
@@ -198,6 +245,20 @@ const checkSpec = async (specPath: string, args: ParsedArgs) => {
|
|
|
198
245
|
console.error(`Cannot find the specification file ${specPath}`);
|
|
199
246
|
return EXIT_STATUS.configParseError;
|
|
200
247
|
}
|
|
248
|
+
const source = readFileSync(specPath, "utf8");
|
|
249
|
+
const fileName = basename(specPath, ".tla");
|
|
250
|
+
const moduleName = parseModuleFile(source, fileName).name;
|
|
251
|
+
if (moduleName !== fileName) {
|
|
252
|
+
throw createSanyError(
|
|
253
|
+
[
|
|
254
|
+
{
|
|
255
|
+
location: "Unknown location",
|
|
256
|
+
message: `File name '${fileName}' does not match the name '${moduleName}' of the top level module it contains.`,
|
|
257
|
+
},
|
|
258
|
+
],
|
|
259
|
+
true,
|
|
260
|
+
);
|
|
261
|
+
}
|
|
201
262
|
const configPath =
|
|
202
263
|
args.get("-config")?.[0] ??
|
|
203
264
|
(args.has("-config") ? undefined : specPath.replace(/\.tla$/, ".cfg"));
|
|
@@ -221,13 +282,26 @@ const checkSpec = async (specPath: string, args: ParsedArgs) => {
|
|
|
221
282
|
console.error("Error: expect a strategy such as final for -lncheck option.");
|
|
222
283
|
return 1;
|
|
223
284
|
}
|
|
285
|
+
const dumpValues = args.get("-dump");
|
|
286
|
+
if (dumpValues?.length === 0) {
|
|
287
|
+
console.error("Error: A file name for dumping states required.");
|
|
288
|
+
return 1;
|
|
289
|
+
}
|
|
290
|
+
const unsupportedFormat =
|
|
291
|
+
dumpValues?.length === 2 &&
|
|
292
|
+
UNSUPPORTED_DUMP_FORMATS.find((format) => dumpValues[0].toLowerCase().includes(format));
|
|
293
|
+
if (unsupportedFormat) {
|
|
294
|
+
console.error(`Error: tla-ts does not support the -dump format ${unsupportedFormat}.`);
|
|
295
|
+
return 1;
|
|
296
|
+
}
|
|
224
297
|
const directory = dirname(specPath);
|
|
225
298
|
console.log(`Checking ${basename(specPath)} with ${basename(configPath)}`);
|
|
226
299
|
const result = await check({
|
|
227
300
|
workers: getWorkerCount(args.get("-workers")),
|
|
228
301
|
livenessCheck: ["final", "seqfinal", "off"].includes(livenessCheck) ? "final" : "default",
|
|
229
302
|
seed: BigInt(seed),
|
|
230
|
-
|
|
303
|
+
dump: dumpValues && getDump(dumpValues),
|
|
304
|
+
source,
|
|
231
305
|
config,
|
|
232
306
|
onPause: () => readSync(0, Buffer.alloc(1)),
|
|
233
307
|
loadModule: (name) => {
|
|
@@ -248,21 +322,33 @@ const checkSpec = async (specPath: string, args: ParsedArgs) => {
|
|
|
248
322
|
return result.failure?.exitCode ?? EXIT_CODES[result.status];
|
|
249
323
|
};
|
|
250
324
|
|
|
251
|
-
|
|
252
|
-
|
|
325
|
+
const formatSanyErrors = (report: SanyReport) =>
|
|
326
|
+
`*** Errors: ${report.errors.length}\n\n${report.errors.map((error) => `${error.location}\n\n${error.message}\n\n`).join("\n")}`;
|
|
327
|
+
|
|
328
|
+
// TLC prints the errors it raises itself, and SANY's report of a spec it rejects. tla-ts names the
|
|
329
|
+
// others, such as a module it cannot parse.
|
|
330
|
+
const printError = (error: TlaError, path?: string) => {
|
|
253
331
|
if (error instanceof TlaConfigError || error instanceof TlaEvaluationError) {
|
|
254
332
|
return console.log(`Error: ${error.message}`);
|
|
255
333
|
}
|
|
256
|
-
|
|
334
|
+
const report = error instanceof TlaSyntaxError ? error.sany : undefined;
|
|
335
|
+
if (!report || path === undefined) return console.error(`${error.name}: ${error.message}`);
|
|
336
|
+
if (report.parseError !== undefined) console.log(report.parseError);
|
|
337
|
+
console.log(
|
|
338
|
+
report.isFatal
|
|
339
|
+
? `\nFatal errors while parsing TLA+ spec in file ${basename(path, ".tla")}\n\n${report.errors.map((item) => `${item.location}\n\n${item.message}\n`).join("")}${formatSanyErrors(report)}\n`
|
|
340
|
+
: `Semantic errors:\n\n${formatSanyErrors(report)}`,
|
|
341
|
+
);
|
|
342
|
+
console.log("Error: Parsing or semantic analysis failed.");
|
|
257
343
|
};
|
|
258
344
|
|
|
259
345
|
// Prints a TlaError and returns its exit code.
|
|
260
|
-
const reportErrors = async (run: () => number | Promise<number
|
|
346
|
+
const reportErrors = async (run: () => number | Promise<number>, path?: string) => {
|
|
261
347
|
try {
|
|
262
348
|
return await run();
|
|
263
349
|
} catch (error) {
|
|
264
350
|
if (!(error instanceof TlaError)) throw error;
|
|
265
|
-
printError(error);
|
|
351
|
+
printError(error, path);
|
|
266
352
|
return getErrorExitCode(error);
|
|
267
353
|
}
|
|
268
354
|
};
|
|
@@ -273,7 +359,7 @@ const runEach = async (paths: string[], runPath: (path: string) => number | Prom
|
|
|
273
359
|
const exitCodes: number[] = [];
|
|
274
360
|
for (const [index, path] of paths.entries()) {
|
|
275
361
|
if (index > 0) console.log("");
|
|
276
|
-
exitCodes.push(await reportErrors(() => runPath(path)));
|
|
362
|
+
exitCodes.push(await reportErrors(() => runPath(path), path));
|
|
277
363
|
}
|
|
278
364
|
return exitCodes.find((exitCode) => exitCode !== EXIT_STATUS.success) ?? EXIT_STATUS.success;
|
|
279
365
|
};
|
package/src/runtime.ts
CHANGED
|
@@ -24,6 +24,7 @@ export interface CheckerRuntime {
|
|
|
24
24
|
properties: Map<string, string>;
|
|
25
25
|
possibleCounts: Map<string, number>;
|
|
26
26
|
isStopped: boolean;
|
|
27
|
+
isStarted: boolean;
|
|
27
28
|
checkDeadlock: boolean;
|
|
28
29
|
startedAt: number;
|
|
29
30
|
}
|
|
@@ -75,6 +76,7 @@ export const createRuntime = (checkDeadlock: boolean, seed = 0n): CheckerRuntime
|
|
|
75
76
|
properties: new Map(),
|
|
76
77
|
possibleCounts: new Map(),
|
|
77
78
|
isStopped: false,
|
|
79
|
+
isStarted: false,
|
|
78
80
|
checkDeadlock,
|
|
79
81
|
startedAt: Date.now(),
|
|
80
82
|
};
|