tla-ts 0.0.3-dev.a85c0bd → 0.0.3-dev.ab42bab
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.d.cts +18 -1
- package/dist/index.d.ts +18 -1
- package/dist/run-cli.cjs +5 -3
- package/dist/run-cli.js +20 -18
- package/dist/transfer.cjs +23 -17
- package/dist/transfer.js +23 -17
- package/package.json +1 -1
- package/src/ast.ts +3 -0
- package/src/check.ts +142 -22
- package/src/config.ts +224 -170
- package/src/environment.ts +23 -5
- package/src/errors.ts +41 -1
- package/src/evaluate.ts +38 -9
- package/src/instances.ts +1 -1
- package/src/levels.ts +55 -27
- package/src/liveness.ts +5 -1
- package/src/parser.ts +21 -10
- package/src/resolve.ts +106 -29
- package/src/run-cli.ts +36 -8
- package/src/spec-description.ts +1 -2
- package/src/successors.ts +49 -12
- package/src/values.ts +3 -1
package/src/run-cli.ts
CHANGED
|
@@ -14,12 +14,14 @@ import type { CheckResult, CheckStatus, 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,
|
|
22
23
|
TlaSyntaxError,
|
|
24
|
+
type SanyReport,
|
|
23
25
|
} from "./errors";
|
|
24
26
|
import { EXIT_STATUS } from "./exit-codes";
|
|
25
27
|
import type { LineRange } from "./obligation-generate";
|
|
@@ -143,6 +145,15 @@ const printResult = (result: CheckResult) => {
|
|
|
143
145
|
printState(result.failure.initialState);
|
|
144
146
|
}
|
|
145
147
|
printTrace(result.failure.trace);
|
|
148
|
+
const replay = result.failure.replay;
|
|
149
|
+
replay?.output.forEach((line) => console.log(line));
|
|
150
|
+
if (replay?.callStack) {
|
|
151
|
+
const frames = replay.callStack.map((frame, index) => `${index}. ${frame}\n`).join("");
|
|
152
|
+
console.log(
|
|
153
|
+
`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"}`,
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
if (result.failure.isWithoutStatistics) return;
|
|
146
157
|
} else if (result.violation) {
|
|
147
158
|
const violation = result.violation;
|
|
148
159
|
const name = violation.name;
|
|
@@ -219,8 +230,14 @@ const checkSpec = async (specPath: string, args: ParsedArgs) => {
|
|
|
219
230
|
const fileName = basename(specPath, ".tla");
|
|
220
231
|
const moduleName = parseModule(source).name;
|
|
221
232
|
if (moduleName !== fileName) {
|
|
222
|
-
throw
|
|
223
|
-
|
|
233
|
+
throw createSanyError(
|
|
234
|
+
[
|
|
235
|
+
{
|
|
236
|
+
location: "Unknown location",
|
|
237
|
+
message: `File name '${fileName}' does not match the name '${moduleName}' of the top level module it contains.`,
|
|
238
|
+
},
|
|
239
|
+
],
|
|
240
|
+
true,
|
|
224
241
|
);
|
|
225
242
|
}
|
|
226
243
|
const configPath =
|
|
@@ -286,21 +303,32 @@ const checkSpec = async (specPath: string, args: ParsedArgs) => {
|
|
|
286
303
|
return result.failure?.exitCode ?? EXIT_CODES[result.status];
|
|
287
304
|
};
|
|
288
305
|
|
|
289
|
-
|
|
290
|
-
|
|
306
|
+
const formatSanyErrors = (report: SanyReport) =>
|
|
307
|
+
`*** Errors: ${report.errors.length}\n\n${report.errors.map((error) => `${error.location}\n\n${error.message}\n\n`).join("\n")}`;
|
|
308
|
+
|
|
309
|
+
// TLC prints the errors it raises itself, and SANY's report of a spec it rejects. tla-ts names the
|
|
310
|
+
// others, such as a module it cannot parse.
|
|
311
|
+
const printError = (error: TlaError, path?: string) => {
|
|
291
312
|
if (error instanceof TlaConfigError || error instanceof TlaEvaluationError) {
|
|
292
313
|
return console.log(`Error: ${error.message}`);
|
|
293
314
|
}
|
|
294
|
-
|
|
315
|
+
const report = error instanceof TlaSyntaxError ? error.sany : undefined;
|
|
316
|
+
if (!report || path === undefined) return console.error(`${error.name}: ${error.message}`);
|
|
317
|
+
console.log(
|
|
318
|
+
report.isFatal
|
|
319
|
+
? `\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`
|
|
320
|
+
: `Semantic errors:\n\n${formatSanyErrors(report)}`,
|
|
321
|
+
);
|
|
322
|
+
console.log("Error: Parsing or semantic analysis failed.");
|
|
295
323
|
};
|
|
296
324
|
|
|
297
325
|
// Prints a TlaError and returns its exit code.
|
|
298
|
-
const reportErrors = async (run: () => number | Promise<number
|
|
326
|
+
const reportErrors = async (run: () => number | Promise<number>, path?: string) => {
|
|
299
327
|
try {
|
|
300
328
|
return await run();
|
|
301
329
|
} catch (error) {
|
|
302
330
|
if (!(error instanceof TlaError)) throw error;
|
|
303
|
-
printError(error);
|
|
331
|
+
printError(error, path);
|
|
304
332
|
return getErrorExitCode(error);
|
|
305
333
|
}
|
|
306
334
|
};
|
|
@@ -311,7 +339,7 @@ const runEach = async (paths: string[], runPath: (path: string) => number | Prom
|
|
|
311
339
|
const exitCodes: number[] = [];
|
|
312
340
|
for (const [index, path] of paths.entries()) {
|
|
313
341
|
if (index > 0) console.log("");
|
|
314
|
-
exitCodes.push(await reportErrors(() => runPath(path)));
|
|
342
|
+
exitCodes.push(await reportErrors(() => runPath(path), path));
|
|
315
343
|
}
|
|
316
344
|
return exitCodes.find((exitCode) => exitCode !== EXIT_STATUS.success) ?? EXIT_STATUS.success;
|
|
317
345
|
};
|
package/src/spec-description.ts
CHANGED
|
@@ -7,13 +7,12 @@ import {
|
|
|
7
7
|
} from "./ast";
|
|
8
8
|
import type { ModelConfig } from "./config";
|
|
9
9
|
import type { InstanceAction } from "./environment";
|
|
10
|
-
import { TlaError } from "./errors";
|
|
10
|
+
import { formatRange, TlaError } from "./errors";
|
|
11
11
|
import {
|
|
12
12
|
bindDefinitions,
|
|
13
13
|
bindOperatorArguments,
|
|
14
14
|
evaluate,
|
|
15
15
|
forEachBinding,
|
|
16
|
-
formatRange,
|
|
17
16
|
getDefinition,
|
|
18
17
|
isConstantLevel,
|
|
19
18
|
lookupScope,
|
package/src/successors.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
type QuantifierExpression,
|
|
8
8
|
} from "./ast";
|
|
9
9
|
import { getReadVariables } from "./dependencies";
|
|
10
|
-
import { TlaEvaluationError, TlaIncompleteStateError } from "./errors";
|
|
10
|
+
import { TlaEvaluationError, TlaIllegalStateError, TlaIncompleteStateError } from "./errors";
|
|
11
11
|
import { EXIT_STATUS, setExitCode } from "./exit-codes";
|
|
12
12
|
import {
|
|
13
13
|
describeLocation,
|
|
@@ -113,11 +113,30 @@ const holds = (expression: Expression, context: Context, value = evaluate(expres
|
|
|
113
113
|
const isAssignmentOperator = (operator: string) =>
|
|
114
114
|
operator === "=" || operator === "\\in" || operator === "\\subseteq";
|
|
115
115
|
|
|
116
|
+
const tracedRunners = new WeakMap<Environment, WeakMap<Expression, Runner>[]>();
|
|
117
|
+
|
|
118
|
+
const getRunners = (environment: Environment, isInit: boolean) => {
|
|
119
|
+
if (!environment.trace) return isInit ? initRunners : nextRunners;
|
|
120
|
+
const runners = tracedRunners.get(environment) ?? [new WeakMap(), new WeakMap()];
|
|
121
|
+
tracedRunners.set(environment, runners);
|
|
122
|
+
return runners[isInit ? 0 : 1];
|
|
123
|
+
};
|
|
124
|
+
|
|
116
125
|
const getRunner = (expression: Expression, environment: Environment, isInit: boolean): Runner => {
|
|
117
|
-
const runners = isInit
|
|
126
|
+
const runners = getRunners(environment, isInit);
|
|
118
127
|
const cached = runners.get(expression);
|
|
119
128
|
if (cached) return cached;
|
|
120
|
-
const
|
|
129
|
+
const compiled = compileAction(expression, environment, isInit);
|
|
130
|
+
const trace = environment.trace;
|
|
131
|
+
// TLC's CallStackTool keeps an action's expression on the stack while the rest of the action runs.
|
|
132
|
+
const runner: Runner = trace
|
|
133
|
+
? (run, scope, partial, action, isFixed, onComplete) => {
|
|
134
|
+
const depth = trace.length;
|
|
135
|
+
trace.push(expression);
|
|
136
|
+
compiled(run, scope, partial, action, isFixed, onComplete);
|
|
137
|
+
trace.length = depth;
|
|
138
|
+
}
|
|
139
|
+
: compiled;
|
|
121
140
|
runners.set(expression, runner);
|
|
122
141
|
return runner;
|
|
123
142
|
};
|
|
@@ -201,6 +220,23 @@ const getUnchangedIndices = (
|
|
|
201
220
|
return getUnchangedIndices(definition.body, environment, visited);
|
|
202
221
|
};
|
|
203
222
|
|
|
223
|
+
// TLC's CallStackTool keeps each expression that UNCHANGED takes apart on the stack.
|
|
224
|
+
const getUnchangedFrames = (expression: Expression, environment: Environment): Expression[] => {
|
|
225
|
+
if (expression.kind === "Tuple") {
|
|
226
|
+
return [
|
|
227
|
+
expression,
|
|
228
|
+
...expression.elements.flatMap((element) => getUnchangedFrames(element, environment)),
|
|
229
|
+
];
|
|
230
|
+
}
|
|
231
|
+
const definition =
|
|
232
|
+
expression.kind === "Identifier" && !environment.variableIndex.has(expression.name)
|
|
233
|
+
? getZeroArityBody(expression.name, environment)
|
|
234
|
+
: undefined;
|
|
235
|
+
return definition
|
|
236
|
+
? [expression, ...getUnchangedFrames(definition.body, environment)]
|
|
237
|
+
: [expression];
|
|
238
|
+
};
|
|
239
|
+
|
|
204
240
|
const ACTION_KINDS = new Set([
|
|
205
241
|
"Label",
|
|
206
242
|
"And",
|
|
@@ -333,6 +369,7 @@ const compileConjunction = (
|
|
|
333
369
|
): Runner => {
|
|
334
370
|
const conjuncts = operands.map((operand) => toConjunct(operand, environment, isInit));
|
|
335
371
|
const evaluators: (Evaluator | undefined)[] = conjuncts.map(() => undefined);
|
|
372
|
+
const trace = environment.trace;
|
|
336
373
|
const runFrom = (
|
|
337
374
|
start: number,
|
|
338
375
|
run: Run,
|
|
@@ -353,6 +390,12 @@ const compileConjunction = (
|
|
|
353
390
|
return;
|
|
354
391
|
}
|
|
355
392
|
const conjunct = conjuncts[index];
|
|
393
|
+
if (trace) {
|
|
394
|
+
trace.push(conjunct.expression);
|
|
395
|
+
if (conjunct.expression.kind === "Unchanged") {
|
|
396
|
+
trace.push(...getUnchangedFrames(conjunct.expression.expression, environment));
|
|
397
|
+
}
|
|
398
|
+
}
|
|
356
399
|
if (conjunct.kind === "Guard") {
|
|
357
400
|
context ??= getContext(run, scope, current);
|
|
358
401
|
const evaluator = (evaluators[index] ??= getEntryEvaluator(
|
|
@@ -771,7 +814,8 @@ const compileAction = (
|
|
|
771
814
|
}
|
|
772
815
|
};
|
|
773
816
|
}
|
|
774
|
-
const hoisted =
|
|
817
|
+
const hoisted =
|
|
818
|
+
isInit || environment.trace ? undefined : getHoistedGuards(expression, environment);
|
|
775
819
|
if (hoisted) {
|
|
776
820
|
const rest = compileConjunction(hoisted.rest, environment, isInit);
|
|
777
821
|
return (run, scope, partial, action, isFixed, onComplete) => {
|
|
@@ -1015,14 +1059,7 @@ export const forEachInitialState = (
|
|
|
1015
1059
|
(partial) => {
|
|
1016
1060
|
if (run.isStopped) return;
|
|
1017
1061
|
if (!isComplete(partial)) {
|
|
1018
|
-
|
|
1019
|
-
// an evaluation failure.
|
|
1020
|
-
throw setExitCode(
|
|
1021
|
-
new TlaEvaluationError(
|
|
1022
|
-
`The initial predicate does not assign ${getMissingVariables(partial, environment).join(", ")}`,
|
|
1023
|
-
),
|
|
1024
|
-
EXIT_STATUS.error,
|
|
1025
|
-
);
|
|
1062
|
+
throw setExitCode(new TlaIllegalStateError(partial), EXIT_STATUS.error);
|
|
1026
1063
|
}
|
|
1027
1064
|
run.isStopped = onState(partial);
|
|
1028
1065
|
},
|
package/src/values.ts
CHANGED
|
@@ -1635,7 +1635,9 @@ export const isElementOf = (element: Value, set: Value): boolean => {
|
|
|
1635
1635
|
case "FunctionSet": {
|
|
1636
1636
|
if (!isFunctionValue(element)) {
|
|
1637
1637
|
if (isModelValue(element)) return false;
|
|
1638
|
-
throw new TlaEvaluationError(
|
|
1638
|
+
throw new TlaEvaluationError(
|
|
1639
|
+
`Attempted to check if \n${formatValue(element)}\nwhich is not a TLC function value, is in the set of functions:\n${prettyPrint(formatValue(set))}`,
|
|
1640
|
+
);
|
|
1639
1641
|
}
|
|
1640
1642
|
const functionValue = toFiniteFunction(element);
|
|
1641
1643
|
const low = getIntervalLow(functionValue.domain);
|