tla-ts 0.0.3-dev.f362080 → 0.0.3-dev.f6f300a
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/transfer.cjs +21 -18
- package/dist/transfer.js +21 -18
- package/package.json +1 -1
- package/src/check.ts +29 -7
- package/src/errors.ts +7 -0
- package/src/evaluate.ts +5 -0
- package/src/liveness.ts +3 -5
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,
|
|
@@ -248,7 +250,7 @@ const getConstantValue = (name: string, definition: Definition, environment: Env
|
|
|
248
250
|
try {
|
|
249
251
|
return evaluate(createIdentifier(name), getContext(environment, undefined, undefined));
|
|
250
252
|
} catch (error) {
|
|
251
|
-
if (error instanceof TlaEvaluationError) return undefined;
|
|
253
|
+
if (error instanceof TlaEvaluationError || isStackOverflow(error)) return undefined;
|
|
252
254
|
throw error;
|
|
253
255
|
}
|
|
254
256
|
};
|
|
@@ -379,8 +381,11 @@ const getSpecification = (config: ModelConfig, environment: Environment): Specif
|
|
|
379
381
|
conjunct.kind === "Always" &&
|
|
380
382
|
getLevel(conjunct.expression, item.scope, environment) < ACTION_LEVEL
|
|
381
383
|
) {
|
|
382
|
-
throw
|
|
383
|
-
|
|
384
|
+
throw setExitCode(
|
|
385
|
+
new TlaConfigError(
|
|
386
|
+
`TLC cannot handle the temporal formula ${describeRange(conjunct.expression)}`,
|
|
387
|
+
),
|
|
388
|
+
EXIT_STATUS.error,
|
|
384
389
|
);
|
|
385
390
|
}
|
|
386
391
|
const level = getLevel(conjunct, item.scope, environment);
|
|
@@ -926,9 +931,16 @@ const withHeadline = (error: unknown, headline: string) =>
|
|
|
926
931
|
// TLC finishes the -dump file whether or not the search finds a violation.
|
|
927
932
|
export const checkSequentially = (options: CheckOptions): CheckResult => {
|
|
928
933
|
const stateWriter = options.dump && createStateWriter(options.dump, options.writeFile);
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
934
|
+
try {
|
|
935
|
+
return searchStates(options, stateWriter);
|
|
936
|
+
} catch (error) {
|
|
937
|
+
// TLC reports a stack overflow outside the search as a failure of its own, with exit code 255.
|
|
938
|
+
throw isStackOverflow(error)
|
|
939
|
+
? setExitCode(new TlaEvaluationError(STACK_OVERFLOW), EXIT_STATUS.error)
|
|
940
|
+
: error;
|
|
941
|
+
} finally {
|
|
942
|
+
stateWriter?.close();
|
|
943
|
+
}
|
|
932
944
|
};
|
|
933
945
|
|
|
934
946
|
const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefined): CheckResult => {
|
|
@@ -1191,7 +1203,17 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1191
1203
|
trace: TraceStep[],
|
|
1192
1204
|
initialState?: Value[],
|
|
1193
1205
|
failureOutDegrees?: number[],
|
|
1194
|
-
) => {
|
|
1206
|
+
): CheckResult => {
|
|
1207
|
+
// TLC exits with 255 on a stack overflow while it computes next states, and prints the
|
|
1208
|
+
// behavior up to the state it was expanding.
|
|
1209
|
+
if (isStackOverflow(error)) {
|
|
1210
|
+
return current.isExpanding
|
|
1211
|
+
? toFailure(
|
|
1212
|
+
setExitCode(new TlaEvaluationError(STACK_OVERFLOW), EXIT_STATUS.error),
|
|
1213
|
+
getStateTrace(current.index),
|
|
1214
|
+
)
|
|
1215
|
+
: toFailure(new TlaEvaluationError(STACK_OVERFLOW), trace, initialState);
|
|
1216
|
+
}
|
|
1195
1217
|
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
1196
1218
|
return {
|
|
1197
1219
|
...createResult("error", undefined, {
|
package/src/errors.ts
CHANGED
|
@@ -5,6 +5,13 @@ import { EXIT_STATUS, getExitCode } from "./exit-codes";
|
|
|
5
5
|
export const UNEXPECTED_EXCEPTION =
|
|
6
6
|
"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
7
|
|
|
8
|
+
// How TLC reports a Java StackOverflowError, which V8 raises as this RangeError.
|
|
9
|
+
export const STACK_OVERFLOW =
|
|
10
|
+
"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.";
|
|
11
|
+
|
|
12
|
+
export const isStackOverflow = (error: unknown) =>
|
|
13
|
+
error instanceof RangeError && error.message === "Maximum call stack size exceeded";
|
|
14
|
+
|
|
8
15
|
export class TlaError extends Error {
|
|
9
16
|
constructor(message: string, cause?: unknown) {
|
|
10
17
|
super(message, { cause });
|
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);
|