tla-ts 0.0.3-dev.037ac3b → 0.0.3-dev.0e500e5
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 +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 +14 -12
- package/dist/run-cli.js +22 -20
- package/dist/transfer.cjs +39 -21
- package/dist/transfer.js +39 -21
- package/package.json +1 -1
- package/src/ast.ts +26 -4
- package/src/builtins.ts +9 -3
- package/src/check.ts +309 -61
- package/src/codegen.ts +6 -3
- package/src/config.ts +224 -170
- package/src/environment.ts +223 -84
- package/src/errors.ts +100 -1
- package/src/evaluate.ts +172 -19
- package/src/exit-codes.ts +22 -3
- package/src/fingerprints.ts +2 -1
- package/src/instances.ts +1 -1
- package/src/levels.ts +176 -36
- package/src/live-check.ts +129 -49
- package/src/liveness.ts +68 -10
- package/src/parallel-worker.ts +2 -2
- package/src/parallel.ts +2 -2
- package/src/parser.ts +152 -48
- package/src/resolve.ts +878 -338
- package/src/run-cli.ts +61 -11
- package/src/sany-lexer.ts +615 -0
- package/src/sany-parse-error.ts +3143 -0
- package/src/spec-description.ts +1 -2
- package/src/standard-modules.ts +52 -38
- package/src/standard-ranges.ts +116 -0
- package/src/subexpressions.ts +25 -13
- package/src/substitution-levels.ts +38 -17
- package/src/successors.ts +111 -31
- package/src/symmetry.ts +16 -6
- package/src/tableau.ts +1 -1
- package/src/tlc-module.ts +6 -6
- package/src/tlc-modules.ts +4 -0
- package/src/tlc-order.ts +8 -4
- package/src/value-sources.ts +29 -0
- package/src/values.ts +184 -51
package/src/run-cli.ts
CHANGED
|
@@ -10,23 +10,26 @@ 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,
|
|
18
|
+
formatSanyWarnings,
|
|
17
19
|
getErrorExitCode,
|
|
18
20
|
TlaConfigError,
|
|
19
21
|
TlaError,
|
|
20
22
|
TlaEvaluationError,
|
|
21
23
|
TlaProofError,
|
|
22
24
|
TlaSyntaxError,
|
|
25
|
+
type SanyReport,
|
|
23
26
|
} from "./errors";
|
|
24
27
|
import { EXIT_STATUS } from "./exit-codes";
|
|
25
28
|
import type { LineRange } from "./obligation-generate";
|
|
26
29
|
import { getAtPrefix, getLocusText } from "./obligation-expression";
|
|
27
30
|
import { formatSummary, getObligations, WHOLE_MODULE, type ModuleObligations } from "./obligations";
|
|
28
31
|
import { check } from "./parallel";
|
|
29
|
-
import {
|
|
32
|
+
import { parseModuleFile } from "./sany-parse-error";
|
|
30
33
|
import type { StateDump } from "./state-graph";
|
|
31
34
|
import {
|
|
32
35
|
formatProbability,
|
|
@@ -135,14 +138,42 @@ const getTemporalHeadline = (names: string[]) =>
|
|
|
135
138
|
? `Error: Temporal property ${names[0]} was violated.\n`
|
|
136
139
|
: `Error: Temporal properties ${names.slice(0, -1).join(", ")}${names.length > 2 ? "," : ""} and ${names[names.length - 1]} were violated.\n`;
|
|
137
140
|
|
|
141
|
+
const getFrames = (callStack: string[]) =>
|
|
142
|
+
callStack.map((frame, index) => `${index}. ${frame}\n`).join("");
|
|
143
|
+
|
|
144
|
+
const printCallStack = (frames: string) =>
|
|
145
|
+
console.log(
|
|
146
|
+
`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"}`,
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
const printReplay = (replay: Replay) => {
|
|
150
|
+
replay.output.forEach((line) => console.log(line));
|
|
151
|
+
const frames = getFrames(replay.callStack ?? []);
|
|
152
|
+
const fingerprint = replay.fingerprint;
|
|
153
|
+
if (replay.isBeforeError) {
|
|
154
|
+
if (frames) printCallStack(frames);
|
|
155
|
+
} else if (replay.callStack && fingerprint) {
|
|
156
|
+
const sources = fingerprint.sources.map((source) => `${source}\n`).join("");
|
|
157
|
+
console.log(
|
|
158
|
+
`Error: TLC was unable to fingerprint.\n\nFingerprint Stack Trace:\n${frames ? `${frames}\n` : sources}\nReason:\n${fingerprint.reason}`,
|
|
159
|
+
);
|
|
160
|
+
} else if (replay.callStack) {
|
|
161
|
+
printCallStack(frames);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
138
165
|
const printResult = (result: CheckResult) => {
|
|
139
166
|
if (result.failure) {
|
|
167
|
+
const replay = result.failure.replay;
|
|
168
|
+
if (replay?.isBeforeError) printReplay(replay);
|
|
140
169
|
console.log(`Error: ${result.failure.message}`);
|
|
141
170
|
if (result.failure.initialState) {
|
|
142
171
|
console.log("While working on the initial state:");
|
|
143
172
|
printState(result.failure.initialState);
|
|
144
173
|
}
|
|
145
174
|
printTrace(result.failure.trace);
|
|
175
|
+
if (replay && !replay.isBeforeError) printReplay(replay);
|
|
176
|
+
if (result.failure.isWithoutStatistics) return;
|
|
146
177
|
} else if (result.violation) {
|
|
147
178
|
const violation = result.violation;
|
|
148
179
|
const name = violation.name;
|
|
@@ -217,10 +248,16 @@ const checkSpec = async (specPath: string, args: ParsedArgs) => {
|
|
|
217
248
|
}
|
|
218
249
|
const source = readFileSync(specPath, "utf8");
|
|
219
250
|
const fileName = basename(specPath, ".tla");
|
|
220
|
-
const moduleName =
|
|
251
|
+
const moduleName = parseModuleFile(source, fileName).name;
|
|
221
252
|
if (moduleName !== fileName) {
|
|
222
|
-
throw
|
|
223
|
-
|
|
253
|
+
throw createSanyError(
|
|
254
|
+
[
|
|
255
|
+
{
|
|
256
|
+
location: "Unknown location",
|
|
257
|
+
message: `File name '${fileName}' does not match the name '${moduleName}' of the top level module it contains.`,
|
|
258
|
+
},
|
|
259
|
+
],
|
|
260
|
+
true,
|
|
224
261
|
);
|
|
225
262
|
}
|
|
226
263
|
const configPath =
|
|
@@ -286,21 +323,34 @@ const checkSpec = async (specPath: string, args: ParsedArgs) => {
|
|
|
286
323
|
return result.failure?.exitCode ?? EXIT_CODES[result.status];
|
|
287
324
|
};
|
|
288
325
|
|
|
289
|
-
|
|
290
|
-
|
|
326
|
+
const formatSanyErrors = (report: SanyReport) =>
|
|
327
|
+
`*** Errors: ${report.errors.length}\n\n${report.errors.map((error) => `${error.location}\n\n${error.message}\n\n`).join("\n")}`;
|
|
328
|
+
|
|
329
|
+
// TLC prints the errors it raises itself, and SANY's report of a spec it rejects. tla-ts names the
|
|
330
|
+
// others, such as a module it cannot parse.
|
|
331
|
+
const printError = (error: TlaError, path?: string) => {
|
|
291
332
|
if (error instanceof TlaConfigError || error instanceof TlaEvaluationError) {
|
|
292
333
|
return console.log(`Error: ${error.message}`);
|
|
293
334
|
}
|
|
294
|
-
|
|
335
|
+
const report = error instanceof TlaSyntaxError ? error.sany : undefined;
|
|
336
|
+
if (!report || path === undefined) return console.error(`${error.name}: ${error.message}`);
|
|
337
|
+
if (report.parseError !== undefined) console.log(report.parseError);
|
|
338
|
+
if (report.warnings.length > 0) console.log(formatSanyWarnings(report.warnings));
|
|
339
|
+
console.log(
|
|
340
|
+
report.isFatal
|
|
341
|
+
? `\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`
|
|
342
|
+
: `Semantic errors:\n\n${formatSanyErrors(report)}`,
|
|
343
|
+
);
|
|
344
|
+
console.log("Error: Parsing or semantic analysis failed.");
|
|
295
345
|
};
|
|
296
346
|
|
|
297
347
|
// Prints a TlaError and returns its exit code.
|
|
298
|
-
const reportErrors = async (run: () => number | Promise<number
|
|
348
|
+
const reportErrors = async (run: () => number | Promise<number>, path?: string) => {
|
|
299
349
|
try {
|
|
300
350
|
return await run();
|
|
301
351
|
} catch (error) {
|
|
302
352
|
if (!(error instanceof TlaError)) throw error;
|
|
303
|
-
printError(error);
|
|
353
|
+
printError(error, path);
|
|
304
354
|
return getErrorExitCode(error);
|
|
305
355
|
}
|
|
306
356
|
};
|
|
@@ -311,7 +361,7 @@ const runEach = async (paths: string[], runPath: (path: string) => number | Prom
|
|
|
311
361
|
const exitCodes: number[] = [];
|
|
312
362
|
for (const [index, path] of paths.entries()) {
|
|
313
363
|
if (index > 0) console.log("");
|
|
314
|
-
exitCodes.push(await reportErrors(() => runPath(path)));
|
|
364
|
+
exitCodes.push(await reportErrors(() => runPath(path), path));
|
|
315
365
|
}
|
|
316
366
|
return exitCodes.find((exitCode) => exitCode !== EXIT_STATUS.success) ?? EXIT_STATUS.success;
|
|
317
367
|
};
|