tla-ts 0.0.3-dev.598a74f → 0.0.3-dev.5e999f2
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 +22 -22
- package/dist/index.d.ts +22 -22
- package/dist/transfer.cjs +21 -18
- package/dist/transfer.js +21 -18
- package/package.json +1 -1
- package/src/check.ts +59 -8
- package/src/environment.ts +11 -9
- package/src/errors.ts +19 -2
- package/src/evaluate.ts +5 -0
- package/src/liveness.ts +3 -5
- package/src/successors.ts +3 -1
- package/src/tlc-module.ts +6 -6
- package/src/tlc-modules.ts +4 -0
package/package.json
CHANGED
package/src/check.ts
CHANGED
|
@@ -11,6 +11,8 @@ import { getReadVariables } from "./dependencies";
|
|
|
11
11
|
import { createEnvironment } from "./environment";
|
|
12
12
|
import {
|
|
13
13
|
getErrorExitCode,
|
|
14
|
+
isStackOverflow,
|
|
15
|
+
STACK_OVERFLOW,
|
|
14
16
|
TlaConfigError,
|
|
15
17
|
TlaEvaluationError,
|
|
16
18
|
TlaIncompleteStateError,
|
|
@@ -68,6 +70,7 @@ import { createCounterExample } from "./tlc-ext";
|
|
|
68
70
|
import { getFingerprintDistance, OUT_DEGREE_BUCKETS } from "./tlc-summary";
|
|
69
71
|
import {
|
|
70
72
|
combineHash,
|
|
73
|
+
createModelValue,
|
|
71
74
|
formatState,
|
|
72
75
|
formatValue,
|
|
73
76
|
getValueHash,
|
|
@@ -248,7 +251,7 @@ const getConstantValue = (name: string, definition: Definition, environment: Env
|
|
|
248
251
|
try {
|
|
249
252
|
return evaluate(createIdentifier(name), getContext(environment, undefined, undefined));
|
|
250
253
|
} catch (error) {
|
|
251
|
-
if (error instanceof TlaEvaluationError) return undefined;
|
|
254
|
+
if (error instanceof TlaEvaluationError || isStackOverflow(error)) return undefined;
|
|
252
255
|
throw error;
|
|
253
256
|
}
|
|
254
257
|
};
|
|
@@ -379,8 +382,11 @@ const getSpecification = (config: ModelConfig, environment: Environment): Specif
|
|
|
379
382
|
conjunct.kind === "Always" &&
|
|
380
383
|
getLevel(conjunct.expression, item.scope, environment) < ACTION_LEVEL
|
|
381
384
|
) {
|
|
382
|
-
throw
|
|
383
|
-
|
|
385
|
+
throw setExitCode(
|
|
386
|
+
new TlaConfigError(
|
|
387
|
+
`TLC cannot handle the temporal formula ${describeRange(conjunct.expression)}`,
|
|
388
|
+
),
|
|
389
|
+
EXIT_STATUS.error,
|
|
384
390
|
);
|
|
385
391
|
}
|
|
386
392
|
const level = getLevel(conjunct, item.scope, environment);
|
|
@@ -926,9 +932,16 @@ const withHeadline = (error: unknown, headline: string) =>
|
|
|
926
932
|
// TLC finishes the -dump file whether or not the search finds a violation.
|
|
927
933
|
export const checkSequentially = (options: CheckOptions): CheckResult => {
|
|
928
934
|
const stateWriter = options.dump && createStateWriter(options.dump, options.writeFile);
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
935
|
+
try {
|
|
936
|
+
return searchStates(options, stateWriter);
|
|
937
|
+
} catch (error) {
|
|
938
|
+
// TLC reports a stack overflow outside the search as a failure of its own, with exit code 255.
|
|
939
|
+
throw isStackOverflow(error)
|
|
940
|
+
? setExitCode(new TlaEvaluationError(STACK_OVERFLOW), EXIT_STATUS.error)
|
|
941
|
+
: error;
|
|
942
|
+
} finally {
|
|
943
|
+
stateWriter?.close();
|
|
944
|
+
}
|
|
932
945
|
};
|
|
933
946
|
|
|
934
947
|
const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefined): CheckResult => {
|
|
@@ -1191,7 +1204,17 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1191
1204
|
trace: TraceStep[],
|
|
1192
1205
|
initialState?: Value[],
|
|
1193
1206
|
failureOutDegrees?: number[],
|
|
1194
|
-
) => {
|
|
1207
|
+
): CheckResult => {
|
|
1208
|
+
// TLC exits with 255 on a stack overflow while it computes next states, and prints the
|
|
1209
|
+
// behavior up to the state it was expanding.
|
|
1210
|
+
if (isStackOverflow(error)) {
|
|
1211
|
+
return current.isExpanding
|
|
1212
|
+
? toFailure(
|
|
1213
|
+
setExitCode(new TlaEvaluationError(STACK_OVERFLOW), EXIT_STATUS.error),
|
|
1214
|
+
getStateTrace(current.index),
|
|
1215
|
+
)
|
|
1216
|
+
: toFailure(new TlaEvaluationError(STACK_OVERFLOW), trace, initialState);
|
|
1217
|
+
}
|
|
1195
1218
|
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
1196
1219
|
return {
|
|
1197
1220
|
...createResult("error", undefined, {
|
|
@@ -1525,6 +1548,31 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1525
1548
|
return toFailure(error, getStateTrace(index), undefined, getPartialOutDegrees());
|
|
1526
1549
|
}
|
|
1527
1550
|
};
|
|
1551
|
+
// TLC names the action when the next-state relation has more than one, and prints the
|
|
1552
|
+
// incomplete successor with null for each variable it leaves undefined.
|
|
1553
|
+
const reportIncompleteSuccessor = (error: TlaIncompleteStateError, index: number) => {
|
|
1554
|
+
nextActions.value ??= getNextActions(config, environment, specification.instanceActions);
|
|
1555
|
+
const actions = nextActions.value;
|
|
1556
|
+
const action =
|
|
1557
|
+
actions.length === 1 ? actions[0] : actions.find((item) => item.name === error.action);
|
|
1558
|
+
const variables = `variable${error.missing.length > 1 ? "s are" : " is"} not defined: ${error.missing.join(", ")}.\n`;
|
|
1559
|
+
runtime.generatedStates++;
|
|
1560
|
+
return toFailure(
|
|
1561
|
+
actions.length === 1
|
|
1562
|
+
? error
|
|
1563
|
+
: new TlaEvaluationError(
|
|
1564
|
+
`Successor state is not completely specified by action ${error.action} of the next-state relation. The following ${variables}`,
|
|
1565
|
+
),
|
|
1566
|
+
[
|
|
1567
|
+
...getStateTrace(index),
|
|
1568
|
+
{
|
|
1569
|
+
action: error.action,
|
|
1570
|
+
label: action && getActionLabel(action),
|
|
1571
|
+
state: toRecord(error.state.map((value) => value ?? createModelValue("null"))),
|
|
1572
|
+
},
|
|
1573
|
+
],
|
|
1574
|
+
);
|
|
1575
|
+
};
|
|
1528
1576
|
// TLC names the properties and the step back into the cycle from the states it prints.
|
|
1529
1577
|
const reportLasso = (checker: LivenessChecker, lasso: Lasso) => {
|
|
1530
1578
|
const path = [...lasso.prefix, ...lasso.cycle];
|
|
@@ -1570,7 +1618,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1570
1618
|
try {
|
|
1571
1619
|
outcome.result = expandState(index);
|
|
1572
1620
|
} catch (error) {
|
|
1573
|
-
outcome.result =
|
|
1621
|
+
outcome.result =
|
|
1622
|
+
error instanceof TlaIncompleteStateError
|
|
1623
|
+
? reportIncompleteSuccessor(error, index)
|
|
1624
|
+
: toFailure(toNextStateError(error), getStateTrace(index));
|
|
1574
1625
|
}
|
|
1575
1626
|
if (outcome.result) return outcome.result;
|
|
1576
1627
|
outDegrees[getOutDegreeBucket()]++;
|
package/src/environment.ts
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
import { BUNDLED_MODULES } from "./bundled-modules";
|
|
13
13
|
import type { ConfigValue, ModelConfig } from "./config";
|
|
14
14
|
import type { FileSystem } from "./json";
|
|
15
|
-
import { TlaConfigError, TlaEvaluationError, TlaSyntaxError } from "./errors";
|
|
15
|
+
import { TlaConfigError, TlaEvaluationError, TlaModuleError, TlaSyntaxError } from "./errors";
|
|
16
16
|
import { EXIT_STATUS, setExitCode } from "./exit-codes";
|
|
17
17
|
import {
|
|
18
18
|
createBigNumberError,
|
|
@@ -963,26 +963,28 @@ export const createEnvironment = (
|
|
|
963
963
|
]),
|
|
964
964
|
getDefinition: (name) => getDefinition(name, environment),
|
|
965
965
|
});
|
|
966
|
-
const
|
|
966
|
+
const getEvaluationError = (body: Expression) => {
|
|
967
967
|
try {
|
|
968
968
|
evaluate(body, { environment, scope: undefined, state: undefined, next: undefined });
|
|
969
|
-
return
|
|
969
|
+
return undefined;
|
|
970
970
|
} catch (error) {
|
|
971
|
-
if (error instanceof TlaEvaluationError) return
|
|
971
|
+
if (error instanceof TlaEvaluationError) return error;
|
|
972
972
|
throw error;
|
|
973
973
|
}
|
|
974
974
|
};
|
|
975
975
|
substitutions.forEach((target, name) => {
|
|
976
976
|
const definition = definitions.get(target);
|
|
977
|
-
|
|
977
|
+
const error =
|
|
978
978
|
declaredConstants.includes(name) &&
|
|
979
979
|
definition?.kind === "Operator" &&
|
|
980
980
|
definition.params.length === 0 &&
|
|
981
|
-
analyzer.analyzeDefinition(definition, new Map()).level > 0
|
|
982
|
-
|
|
983
|
-
|
|
981
|
+
analyzer.analyzeDefinition(definition, new Map()).level > 0
|
|
982
|
+
? getEvaluationError(definition.body)
|
|
983
|
+
: undefined;
|
|
984
|
+
// TLC adds the reason unless a standard module's Java code failed.
|
|
985
|
+
if (error) {
|
|
984
986
|
throw new TlaConfigError(
|
|
985
|
-
`The configuration file substitutes constant ${name} with non-constant ${target}`,
|
|
987
|
+
`The configuration file substitutes constant ${name} with non-constant ${target}${error instanceof TlaModuleError ? "" : ` - specifically: ${error.message}`}`,
|
|
986
988
|
);
|
|
987
989
|
}
|
|
988
990
|
});
|
package/src/errors.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { EXIT_STATUS, getExitCode } from "./exit-codes";
|
|
2
|
+
import type { Value } from "./values";
|
|
2
3
|
|
|
3
4
|
// How TLC reports a RuntimeException it did not expect, such as one raised while computing next
|
|
4
5
|
// states.
|
|
5
6
|
export const UNEXPECTED_EXCEPTION =
|
|
6
7
|
"TLC threw an unexpected exception.\nThis was probably caused by an error in the spec or model.\nSee the User Output or TLC Console for clues to what happened.\nThe exception was a java.lang.RuntimeException\n: ";
|
|
7
8
|
|
|
9
|
+
// How TLC reports a Java StackOverflowError, which V8 raises as this RangeError.
|
|
10
|
+
export const STACK_OVERFLOW =
|
|
11
|
+
"This was a Java StackOverflowError. It was probably the result\nof an incorrect recursive function definition that caused TLC to enter\nan infinite loop when trying to compute the function or its application\nto an element in its putative domain.";
|
|
12
|
+
|
|
13
|
+
export const isStackOverflow = (error: unknown) =>
|
|
14
|
+
error instanceof RangeError && error.message === "Maximum call stack size exceeded";
|
|
15
|
+
|
|
8
16
|
export class TlaError extends Error {
|
|
9
17
|
constructor(message: string, cause?: unknown) {
|
|
10
18
|
super(message, { cause });
|
|
@@ -58,9 +66,18 @@ export class TlaModuleError extends TlaEvaluationError {
|
|
|
58
66
|
// TLC reports a successor state that the next-state relation leaves incomplete as an error of its
|
|
59
67
|
// own, not as an exception. It keeps the name TlaEvaluationError, and index.ts doesn't export it.
|
|
60
68
|
export class TlaIncompleteStateError extends TlaEvaluationError {
|
|
61
|
-
|
|
62
|
-
|
|
69
|
+
state: (Value | undefined)[];
|
|
70
|
+
action: string | undefined;
|
|
71
|
+
missing: string[];
|
|
72
|
+
|
|
73
|
+
constructor(state: (Value | undefined)[], action: string | undefined, missing: string[]) {
|
|
74
|
+
super(
|
|
75
|
+
`Successor state is not completely specified by the next-state action. The following variable${missing.length > 1 ? "s are" : " is"} not defined: ${missing.join(", ")}.\n`,
|
|
76
|
+
);
|
|
63
77
|
this.name = "TlaEvaluationError";
|
|
78
|
+
this.state = state;
|
|
79
|
+
this.action = action;
|
|
80
|
+
this.missing = missing;
|
|
64
81
|
}
|
|
65
82
|
}
|
|
66
83
|
|
package/src/evaluate.ts
CHANGED
|
@@ -1337,6 +1337,11 @@ const compileApply = (
|
|
|
1337
1337
|
if (definition?.kind === "Function") {
|
|
1338
1338
|
throw new TlaEvaluationError(`${expression.operator} is a function; apply it with brackets`);
|
|
1339
1339
|
}
|
|
1340
|
+
if (expression.operator === "\\cdot") {
|
|
1341
|
+
throw new TlaEvaluationError(
|
|
1342
|
+
"The current version of TLC does not support action composition. An incomplete implementation can be enabled via the tlc2.tool.impl.Tool.cdot=true java property.",
|
|
1343
|
+
);
|
|
1344
|
+
}
|
|
1340
1345
|
throw new TlaEvaluationError(
|
|
1341
1346
|
`Unknown operator ${expression.operator} at ${describeLocation(expression)}`,
|
|
1342
1347
|
);
|
package/src/liveness.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isLocallyResolved, type Definition, type Expression } from "./ast";
|
|
2
|
-
import {
|
|
2
|
+
import { STACK_OVERFLOW, TlaEvaluationError } from "./errors";
|
|
3
3
|
import { EXIT_STATUS, setExitCode } from "./exit-codes";
|
|
4
4
|
import {
|
|
5
5
|
describeLocation,
|
|
@@ -191,7 +191,7 @@ export const expandTemporal = (
|
|
|
191
191
|
getDefinitionLevel(definition, environment) > 0
|
|
192
192
|
) {
|
|
193
193
|
if (expanding.has(definition)) {
|
|
194
|
-
throw new
|
|
194
|
+
throw setExitCode(new TlaEvaluationError(STACK_OVERFLOW), EXIT_STATUS.error);
|
|
195
195
|
}
|
|
196
196
|
return expand(
|
|
197
197
|
definition.body,
|
|
@@ -299,9 +299,7 @@ export const toLiveExpression = (
|
|
|
299
299
|
scope: Scope | undefined,
|
|
300
300
|
) => {
|
|
301
301
|
if (expansion.depth >= MAXIMUM_EXPANSION_DEPTH) {
|
|
302
|
-
throw new TlaEvaluationError(
|
|
303
|
-
`TLC overflowed the stack while expanding the temporal formula at ${describeLocation(expression)}`,
|
|
304
|
-
);
|
|
302
|
+
throw setExitCode(new TlaEvaluationError(STACK_OVERFLOW), EXIT_STATUS.error);
|
|
305
303
|
}
|
|
306
304
|
expansion.depth++;
|
|
307
305
|
const result = convert(body, bodyScope);
|
package/src/successors.ts
CHANGED
|
@@ -1058,7 +1058,9 @@ export const forEachSuccessor = (
|
|
|
1058
1058
|
if (run.isStopped) return;
|
|
1059
1059
|
if (!isComplete(partial)) {
|
|
1060
1060
|
throw new TlaIncompleteStateError(
|
|
1061
|
-
|
|
1061
|
+
partial,
|
|
1062
|
+
action,
|
|
1063
|
+
getMissingVariables(partial, environment).sort(),
|
|
1062
1064
|
);
|
|
1063
1065
|
}
|
|
1064
1066
|
counter.successors++;
|
package/src/tlc-module.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TlaModuleError } from "./errors";
|
|
1
|
+
import { TlaEvaluationError, TlaModuleError } from "./errors";
|
|
2
2
|
import { EXIT_STATUS } from "./exit-codes";
|
|
3
3
|
import type { Builtin } from "./evaluate";
|
|
4
4
|
import { prettyPrint } from "./pretty-print";
|
|
@@ -48,7 +48,7 @@ const getRuntimeValue = (
|
|
|
48
48
|
state: (Value | undefined)[] | undefined,
|
|
49
49
|
) => {
|
|
50
50
|
if (!runtime.isStarted && CHECKER_KEYS.has(key)) {
|
|
51
|
-
throw new
|
|
51
|
+
throw new TlaEvaluationError(`TLCGet(${key}) was undefined.`);
|
|
52
52
|
}
|
|
53
53
|
const duration = Math.floor((Date.now() - runtime.startedAt) / 1000);
|
|
54
54
|
switch (key) {
|
|
@@ -104,11 +104,11 @@ const getRuntimeValue = (
|
|
|
104
104
|
}
|
|
105
105
|
if (key.startsWith(NAMED_REGISTER_PREFIX)) {
|
|
106
106
|
const value = getNamedRegisters(runtime).get(key);
|
|
107
|
-
if (value === undefined) throw new
|
|
107
|
+
if (value === undefined) throw new TlaEvaluationError(`TLCGet(${key}) was undefined.`);
|
|
108
108
|
return value;
|
|
109
109
|
}
|
|
110
110
|
if (key.startsWith("-D")) return rankString(runtime.properties.get(key.slice(2)) ?? key);
|
|
111
|
-
throw new
|
|
111
|
+
throw new TlaEvaluationError(`TLCGet(${key}) was undefined.`);
|
|
112
112
|
};
|
|
113
113
|
|
|
114
114
|
const getPermutations = (elements: Value[]): Value[][] =>
|
|
@@ -197,11 +197,11 @@ export const createTlcOperators = (
|
|
|
197
197
|
const key = getValue(args, 0, "TLCGet");
|
|
198
198
|
if (typeof key === "number" && key >= 0) {
|
|
199
199
|
const value = runtime.registers.get(key);
|
|
200
|
-
if (value === undefined) throw new
|
|
200
|
+
if (value === undefined) throw new TlaEvaluationError(`TLCGet(${key}) was undefined.`);
|
|
201
201
|
return value;
|
|
202
202
|
}
|
|
203
203
|
if (typeof key !== "string") {
|
|
204
|
-
throw new
|
|
204
|
+
throw new TlaEvaluationError(
|
|
205
205
|
`The argument of TLCGet should be a nonnegative integer, but instead it is:\n${formatValue(key)}`,
|
|
206
206
|
);
|
|
207
207
|
}
|
package/src/tlc-modules.ts
CHANGED
|
@@ -1013,6 +1013,10 @@ export const TLC_JAVA_METHODS = new Map([
|
|
|
1013
1013
|
"RandomElement",
|
|
1014
1014
|
"public static tlc2.value.impl.Value tlc2.module.TLC.RandomElement(tlc2.value.impl.Value)",
|
|
1015
1015
|
],
|
|
1016
|
+
[
|
|
1017
|
+
"TLCGet",
|
|
1018
|
+
"public static tlc2.value.impl.Value tlc2.module.TLCGetSet.TLCGetEval(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel)",
|
|
1019
|
+
],
|
|
1016
1020
|
[
|
|
1017
1021
|
"TLCEval",
|
|
1018
1022
|
"public static tlc2.value.impl.Value tlc2.module.TLCEval.tlcEval(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel)",
|