tla-ts 0.0.3-dev.45d0f50 → 0.0.3-dev.4a4ed63
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 +45 -22
- package/dist/index.d.ts +45 -22
- package/dist/run-cli.cjs +5 -3
- package/dist/run-cli.js +20 -18
- package/dist/transfer.cjs +30 -21
- package/dist/transfer.js +30 -21
- package/package.json +1 -1
- package/src/ast.ts +3 -0
- package/src/builtins.ts +9 -3
- package/src/check.ts +287 -58
- package/src/config.ts +224 -170
- package/src/environment.ts +31 -6
- package/src/errors.ts +71 -3
- package/src/evaluate.ts +136 -15
- package/src/exit-codes.ts +22 -3
- package/src/fingerprints.ts +2 -1
- package/src/instances.ts +1 -1
- package/src/levels.ts +63 -28
- package/src/live-check.ts +3 -1
- package/src/liveness.ts +68 -10
- package/src/parser.ts +57 -16
- package/src/resolve.ts +106 -29
- package/src/run-cli.ts +56 -9
- package/src/spec-description.ts +1 -2
- package/src/standard-modules.ts +52 -38
- package/src/successors.ts +108 -28
- package/src/value-sources.ts +29 -0
- package/src/values.ts +122 -42
package/package.json
CHANGED
package/src/ast.ts
CHANGED
|
@@ -47,6 +47,8 @@ export interface ApplyExpression {
|
|
|
47
47
|
// The number of args each part of a name like F(x)!l(y) takes, when a part before the last takes
|
|
48
48
|
// some.
|
|
49
49
|
argumentCounts?: number[];
|
|
50
|
+
// The range of the parenthesized arguments of a named operator, where SANY reports their count.
|
|
51
|
+
argumentsRange?: SourceRange;
|
|
50
52
|
location: SourceLocation;
|
|
51
53
|
resolution?: LocalResolution;
|
|
52
54
|
}
|
|
@@ -192,6 +194,7 @@ export interface FunctionSetExpression {
|
|
|
192
194
|
export interface RecordField {
|
|
193
195
|
name: string;
|
|
194
196
|
value: Expression;
|
|
197
|
+
location: SourceLocation;
|
|
195
198
|
}
|
|
196
199
|
|
|
197
200
|
export interface RecordExpression {
|
package/src/builtins.ts
CHANGED
|
@@ -297,15 +297,21 @@ export const getJavaInteger = (value: Value, signature: string) => {
|
|
|
297
297
|
return value;
|
|
298
298
|
};
|
|
299
299
|
|
|
300
|
-
export const
|
|
301
|
-
|
|
300
|
+
export const getArithmeticSignature = (
|
|
301
|
+
javaClass: "Naturals" | "Integers",
|
|
302
|
+
method: string,
|
|
303
|
+
result: string,
|
|
304
|
+
arity: number,
|
|
305
|
+
) =>
|
|
306
|
+
`public static tlc2.value.impl.${result} tlc2.module.${javaClass}.${method}(${Array.from({ length: arity }, () => "tlc2.value.impl.IntValue").join(",")})`;
|
|
302
307
|
|
|
303
308
|
export const defineArithmetic = (
|
|
309
|
+
javaClass: "Naturals" | "Integers",
|
|
304
310
|
name: string,
|
|
305
311
|
method: string,
|
|
306
312
|
compute: (left: number, right: number) => number,
|
|
307
313
|
) => {
|
|
308
|
-
const signature =
|
|
314
|
+
const signature = getArithmeticSignature(javaClass, method, "IntValue", 2);
|
|
309
315
|
return defineBinary(name, (left, right) => {
|
|
310
316
|
const leftNumber = getJavaInteger(left, signature);
|
|
311
317
|
const rightNumber = getJavaInteger(right, signature);
|
package/src/check.ts
CHANGED
|
@@ -11,8 +11,12 @@ import { getReadVariables } from "./dependencies";
|
|
|
11
11
|
import { createEnvironment } from "./environment";
|
|
12
12
|
import {
|
|
13
13
|
getErrorExitCode,
|
|
14
|
+
isStackOverflow,
|
|
15
|
+
formatRange,
|
|
16
|
+
STACK_OVERFLOW,
|
|
14
17
|
TlaConfigError,
|
|
15
18
|
TlaEvaluationError,
|
|
19
|
+
TlaIllegalStateError,
|
|
16
20
|
TlaIncompleteStateError,
|
|
17
21
|
TlaModuleError,
|
|
18
22
|
UNEXPECTED_EXCEPTION,
|
|
@@ -22,7 +26,6 @@ import {
|
|
|
22
26
|
describeRange,
|
|
23
27
|
evaluate,
|
|
24
28
|
expectBoolean,
|
|
25
|
-
formatRange,
|
|
26
29
|
getDefinition,
|
|
27
30
|
isConstantLevel,
|
|
28
31
|
isImpure,
|
|
@@ -33,6 +36,7 @@ import {
|
|
|
33
36
|
import {
|
|
34
37
|
createLivenessChecker,
|
|
35
38
|
type Lasso,
|
|
39
|
+
type LiveGraph,
|
|
36
40
|
type LivenessChecker,
|
|
37
41
|
type LiveSuccessor,
|
|
38
42
|
} from "./live-check";
|
|
@@ -65,9 +69,12 @@ import { createTlcFingerprinter, getTlcFingerprint } from "./tlc-random";
|
|
|
65
69
|
import { createCanonicalizer } from "./canonical";
|
|
66
70
|
import { getPossibleCounts, type CheckerRuntime } from "./runtime";
|
|
67
71
|
import { createCounterExample } from "./tlc-ext";
|
|
72
|
+
import { getFingerprintTrace, valueSources } from "./value-sources";
|
|
68
73
|
import { getFingerprintDistance, OUT_DEGREE_BUCKETS } from "./tlc-summary";
|
|
69
74
|
import {
|
|
75
|
+
assertFingerprintable,
|
|
70
76
|
combineHash,
|
|
77
|
+
createModelValue,
|
|
71
78
|
formatState,
|
|
72
79
|
formatValue,
|
|
73
80
|
getValueHash,
|
|
@@ -137,6 +144,25 @@ export interface EvaluationFailure {
|
|
|
137
144
|
trace: TraceStep[];
|
|
138
145
|
initialState: Record<string, Value> | undefined;
|
|
139
146
|
exitCode: number;
|
|
147
|
+
replay?: Replay;
|
|
148
|
+
isWithoutStatistics?: boolean;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// TLC replays a failed step to print the expressions it was evaluating when the replay failed.
|
|
152
|
+
export interface Replay {
|
|
153
|
+
output: string[];
|
|
154
|
+
callStack: string[] | undefined;
|
|
155
|
+
fingerprint?: Fingerprint;
|
|
156
|
+
// The worker that fails to check liveness replays the step at once, so TLC prints the stack
|
|
157
|
+
// before the error, and only when it holds a frame.
|
|
158
|
+
isBeforeError?: boolean;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// TLC reports an error from a method of a value that has a source as one it was unable to
|
|
162
|
+
// fingerprint. With an empty stack, it lists the sources of the values instead.
|
|
163
|
+
export interface Fingerprint {
|
|
164
|
+
sources: string[];
|
|
165
|
+
reason: string;
|
|
140
166
|
}
|
|
141
167
|
|
|
142
168
|
export interface CheckResult {
|
|
@@ -248,7 +274,7 @@ const getConstantValue = (name: string, definition: Definition, environment: Env
|
|
|
248
274
|
try {
|
|
249
275
|
return evaluate(createIdentifier(name), getContext(environment, undefined, undefined));
|
|
250
276
|
} catch (error) {
|
|
251
|
-
if (error instanceof TlaEvaluationError) return undefined;
|
|
277
|
+
if (error instanceof TlaEvaluationError || isStackOverflow(error)) return undefined;
|
|
252
278
|
throw error;
|
|
253
279
|
}
|
|
254
280
|
};
|
|
@@ -832,11 +858,17 @@ export const createSearch = (
|
|
|
832
858
|
}
|
|
833
859
|
}),
|
|
834
860
|
satisfiesConstraints: (state, parent) =>
|
|
835
|
-
constraints.every(
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
861
|
+
constraints.every((constraint) => {
|
|
862
|
+
try {
|
|
863
|
+
return (
|
|
864
|
+
isUnchangedFor(constraint, state, parent) ||
|
|
865
|
+
holdsLikeTlc(constraint.expression, getContext(environment, state, undefined))
|
|
866
|
+
);
|
|
867
|
+
} catch (error) {
|
|
868
|
+
// TLC reports a failing constraint on a successor like a failure of the next-state relation.
|
|
869
|
+
throw parent ? toNextStateError(error) : error;
|
|
870
|
+
}
|
|
871
|
+
}),
|
|
840
872
|
findFailedInitialPredicate: (state) =>
|
|
841
873
|
properties.initialPredicates.find(
|
|
842
874
|
(predicate) =>
|
|
@@ -869,13 +901,13 @@ export const createSearch = (
|
|
|
869
901
|
}
|
|
870
902
|
}),
|
|
871
903
|
satisfiesActionConstraints: (state, next) =>
|
|
872
|
-
actionConstraints.every((constraint) =>
|
|
873
|
-
|
|
874
|
-
constraint.expression,
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
),
|
|
904
|
+
actionConstraints.every((constraint) => {
|
|
905
|
+
try {
|
|
906
|
+
return holdsLikeTlc(constraint.expression, getContext(environment, state, next));
|
|
907
|
+
} catch (error) {
|
|
908
|
+
throw toNextStateError(error);
|
|
909
|
+
}
|
|
910
|
+
}),
|
|
879
911
|
trackStatePossible:
|
|
880
912
|
statePossible.length === 0
|
|
881
913
|
? ignorePossible
|
|
@@ -906,8 +938,8 @@ export const createSearch = (
|
|
|
906
938
|
const withNextStateExitCode = (error: unknown) =>
|
|
907
939
|
error instanceof TlaModuleError ? setExitCode(error, error.exitCode) : error;
|
|
908
940
|
|
|
909
|
-
// TLC reports a failure of the next-state relation
|
|
910
|
-
// module raised it as an EvalException.
|
|
941
|
+
// TLC reports a failure of the next-state relation, or of the liveness check of a step, as an
|
|
942
|
+
// unexpected exception, unless a standard module raised it as an EvalException.
|
|
911
943
|
const toNextStateError = (error: unknown) =>
|
|
912
944
|
error instanceof TlaEvaluationError &&
|
|
913
945
|
!(error instanceof TlaModuleError) &&
|
|
@@ -918,6 +950,47 @@ const toNextStateError = (error: unknown) =>
|
|
|
918
950
|
)
|
|
919
951
|
: withNextStateExitCode(error);
|
|
920
952
|
|
|
953
|
+
const isRepeated = (frame: string, index: number, frames: string[]) =>
|
|
954
|
+
index > 0 && frames[index - 1] === frame;
|
|
955
|
+
|
|
956
|
+
// FingerprintException#getTrace numbers the sources from the outermost value and lists the innermost
|
|
957
|
+
// first.
|
|
958
|
+
const getSourceTrace = (sources: Expression[]) =>
|
|
959
|
+
sources
|
|
960
|
+
.flatMap((source) => (source.location.range ? [formatRange(source.location.range)] : []))
|
|
961
|
+
.filter((source, index, all) => !isRepeated(source, index, all))
|
|
962
|
+
.map((source, index) => `${index}) ${source}`)
|
|
963
|
+
.reverse();
|
|
964
|
+
|
|
965
|
+
// TLC keeps the stack only when an evaluation fails, and prints each expression on it once, however
|
|
966
|
+
// many times in a row it pushed it.
|
|
967
|
+
const getReplayedCallStack = (
|
|
968
|
+
replay: () => void,
|
|
969
|
+
trace: Expression[],
|
|
970
|
+
): Pick<Replay, "callStack" | "fingerprint"> => {
|
|
971
|
+
try {
|
|
972
|
+
replay();
|
|
973
|
+
return { callStack: undefined };
|
|
974
|
+
} catch (error) {
|
|
975
|
+
if (!(error instanceof TlaEvaluationError)) return { callStack: [] };
|
|
976
|
+
const callStack = trace
|
|
977
|
+
.flatMap((expression) => {
|
|
978
|
+
const range = expression.location.range;
|
|
979
|
+
return range
|
|
980
|
+
? [
|
|
981
|
+
`Line ${range.start.line}, column ${range.start.column} to line ${range.end.line}, column ${range.end.column} in ${range.module}`,
|
|
982
|
+
]
|
|
983
|
+
: [];
|
|
984
|
+
})
|
|
985
|
+
.filter((frame, index, frames) => !isRepeated(frame, index, frames));
|
|
986
|
+
const sources = getFingerprintTrace(error);
|
|
987
|
+
return {
|
|
988
|
+
callStack,
|
|
989
|
+
fingerprint: sources && { sources: getSourceTrace(sources), reason: error.message },
|
|
990
|
+
};
|
|
991
|
+
}
|
|
992
|
+
};
|
|
993
|
+
|
|
921
994
|
const withHeadline = (error: unknown, headline: string) =>
|
|
922
995
|
error instanceof TlaEvaluationError
|
|
923
996
|
? setExitCode(
|
|
@@ -929,9 +1002,16 @@ const withHeadline = (error: unknown, headline: string) =>
|
|
|
929
1002
|
// TLC finishes the -dump file whether or not the search finds a violation.
|
|
930
1003
|
export const checkSequentially = (options: CheckOptions): CheckResult => {
|
|
931
1004
|
const stateWriter = options.dump && createStateWriter(options.dump, options.writeFile);
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
1005
|
+
try {
|
|
1006
|
+
return searchStates(options, stateWriter);
|
|
1007
|
+
} catch (error) {
|
|
1008
|
+
// TLC reports a stack overflow outside the search as a failure of its own, with exit code 255.
|
|
1009
|
+
throw isStackOverflow(error)
|
|
1010
|
+
? setExitCode(new TlaEvaluationError(STACK_OVERFLOW), EXIT_STATUS.error)
|
|
1011
|
+
: error;
|
|
1012
|
+
} finally {
|
|
1013
|
+
stateWriter?.close();
|
|
1014
|
+
}
|
|
935
1015
|
};
|
|
936
1016
|
|
|
937
1017
|
const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefined): CheckResult => {
|
|
@@ -939,9 +1019,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
939
1019
|
const onPrint = options.onPrint ?? console.log;
|
|
940
1020
|
// TLC prints again while it rebuilds a trace, between the states it prints. Printing those lines
|
|
941
1021
|
// before the trace would misplace them, so rebuilding a trace prints nothing.
|
|
942
|
-
const output = { isMuted: false };
|
|
1022
|
+
const output = { isMuted: false, replayed: undefined as string[] | undefined };
|
|
943
1023
|
const print = (text: string) => {
|
|
944
|
-
if (
|
|
1024
|
+
if (output.replayed) output.replayed.push(text);
|
|
1025
|
+
else if (!output.isMuted) onPrint(text);
|
|
945
1026
|
};
|
|
946
1027
|
const withoutOutput = <Result>(rebuild: () => Result) => {
|
|
947
1028
|
output.isMuted = true;
|
|
@@ -1003,9 +1084,9 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1003
1084
|
),
|
|
1004
1085
|
});
|
|
1005
1086
|
|
|
1006
|
-
const
|
|
1007
|
-
getTlcDeclarationOrder(options.source, options.loadModule, "variable")
|
|
1008
|
-
);
|
|
1087
|
+
const getVariableOrder = () =>
|
|
1088
|
+
getTlcDeclarationOrder(options.source, options.loadModule, "variable");
|
|
1089
|
+
const search = createSearch(config, environment, getVariableOrder);
|
|
1009
1090
|
const assumptionViolation = findAssumptionViolation(specification.assumptions, environment);
|
|
1010
1091
|
if (assumptionViolation) return createResult("assumption-violation", assumptionViolation);
|
|
1011
1092
|
if (!search) return createSuccess();
|
|
@@ -1029,37 +1110,114 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1029
1110
|
const spec = search.spec;
|
|
1030
1111
|
const getFingerprintState = search.getFingerprintState;
|
|
1031
1112
|
const nextActions = { value: undefined as SpecAction[] | undefined };
|
|
1113
|
+
const replayFailure = (
|
|
1114
|
+
result: CheckResult,
|
|
1115
|
+
replay: (tracedSearch: Search, traced: Environment) => void,
|
|
1116
|
+
isBeforeError = false,
|
|
1117
|
+
): CheckResult => {
|
|
1118
|
+
if (!result.failure) return result;
|
|
1119
|
+
const trace: Expression[] = [];
|
|
1120
|
+
const traced: Environment = { ...environment, evaluators: new WeakMap(), trace };
|
|
1121
|
+
const tracedSearch = createSearch(config, traced, getVariableOrder);
|
|
1122
|
+
if (!tracedSearch) return result;
|
|
1123
|
+
const replayed: string[] = [];
|
|
1124
|
+
output.replayed = replayed;
|
|
1125
|
+
valueSources.current = new WeakMap();
|
|
1126
|
+
const replayedStack = getReplayedCallStack(() => replay(tracedSearch, traced), trace);
|
|
1127
|
+
valueSources.current = undefined;
|
|
1128
|
+
output.replayed = undefined;
|
|
1129
|
+
return {
|
|
1130
|
+
...result,
|
|
1131
|
+
failure: { ...result.failure, replay: { output: replayed, ...replayedStack, isBeforeError } },
|
|
1132
|
+
};
|
|
1133
|
+
};
|
|
1134
|
+
// TLC fingerprints a state outside CallStackTool, so a failure of a value with a source leaves
|
|
1135
|
+
// the stack empty. Any other failure keeps the stack of the initial predicate.
|
|
1136
|
+
const fingerprintReplayed = (state: Value[], traced: Environment) => {
|
|
1137
|
+
try {
|
|
1138
|
+
getStateHash(getFingerprintState(state));
|
|
1139
|
+
} catch (error) {
|
|
1140
|
+
if (traced.trace && getFingerprintTrace(error)) traced.trace.length = 0;
|
|
1141
|
+
throw error;
|
|
1142
|
+
}
|
|
1143
|
+
};
|
|
1144
|
+
// TLC checks every initial state again, as when it first generated them.
|
|
1145
|
+
const replayInitialStates = (result: CheckResult) =>
|
|
1146
|
+
replayFailure(result, (tracedSearch, traced) => {
|
|
1147
|
+
if (spec.init === undefined) return;
|
|
1148
|
+
forEachInitialState(
|
|
1149
|
+
spec.init,
|
|
1150
|
+
traced,
|
|
1151
|
+
(state) => {
|
|
1152
|
+
if (tracedSearch.satisfiesConstraints(state)) fingerprintReplayed(state, traced);
|
|
1153
|
+
return (
|
|
1154
|
+
tracedSearch.findViolatedInvariant(state) !== undefined ||
|
|
1155
|
+
tracedSearch.findFailedInitialPredicate(state) !== undefined
|
|
1156
|
+
);
|
|
1157
|
+
},
|
|
1158
|
+
spec.scope,
|
|
1159
|
+
);
|
|
1160
|
+
});
|
|
1161
|
+
// TLC rebuilds the behavior up to the state it expanded before it replays the step.
|
|
1162
|
+
const rebuildBehavior = (index: number): void => {
|
|
1163
|
+
const parent = parents[index];
|
|
1164
|
+
if (parent === -1) {
|
|
1165
|
+
getSpecInitialStates();
|
|
1166
|
+
return;
|
|
1167
|
+
}
|
|
1168
|
+
rebuildBehavior(parent);
|
|
1169
|
+
getLabel(parent, states[parent], states[index]);
|
|
1170
|
+
};
|
|
1171
|
+
// TLC generates the successors of each action before it checks them. It checks the invariants
|
|
1172
|
+
// only of a successor outside the model, since it has seen the others.
|
|
1173
|
+
const replaySuccessors = (result: CheckResult, index: number) =>
|
|
1174
|
+
replayFailure(result, (tracedSearch, traced) => {
|
|
1175
|
+
rebuildBehavior(index);
|
|
1176
|
+
const state = states[index];
|
|
1177
|
+
nextActions.value ??= getNextActions(config, environment, specification.instanceActions);
|
|
1178
|
+
nextActions.value.find((action) =>
|
|
1179
|
+
getSuccessors(action.expression, state, traced, action.scope).some((successor) => {
|
|
1180
|
+
const isInModel =
|
|
1181
|
+
tracedSearch.satisfiesConstraints(successor.state) &&
|
|
1182
|
+
tracedSearch.satisfiesActionConstraints(state, successor.state);
|
|
1183
|
+
if (isInModel) fingerprintReplayed(successor.state, traced);
|
|
1184
|
+
return (
|
|
1185
|
+
(!isInModel && tracedSearch.findViolatedInvariant(successor.state) !== undefined) ||
|
|
1186
|
+
tracedSearch.findViolatedActionProperty(state, successor.state) !== undefined
|
|
1187
|
+
);
|
|
1188
|
+
}),
|
|
1189
|
+
);
|
|
1190
|
+
});
|
|
1032
1191
|
const isReducing = config.view !== undefined || config.symmetry !== undefined;
|
|
1033
1192
|
const tlcFingerprints: number[] = [];
|
|
1193
|
+
const liveGraph: LiveGraph = {
|
|
1194
|
+
getFingerprint: (index) =>
|
|
1195
|
+
(tlcFingerprints[index] ??= Number(BigInt.asIntN(32, runtime.getFingerprint(states[index])))),
|
|
1196
|
+
getSuccessors: (state) => {
|
|
1197
|
+
const successors: LiveSuccessor[] = [];
|
|
1198
|
+
if (spec.next === undefined) return successors;
|
|
1199
|
+
forEachSuccessor(
|
|
1200
|
+
spec.next,
|
|
1201
|
+
state,
|
|
1202
|
+
environment,
|
|
1203
|
+
(successor) => {
|
|
1204
|
+
canonicalizeState(successor.state);
|
|
1205
|
+
const isInModel =
|
|
1206
|
+
search.satisfiesConstraints(successor.state, state) &&
|
|
1207
|
+
search.satisfiesActionConstraints(state, successor.state);
|
|
1208
|
+
if (!isInModel) return false;
|
|
1209
|
+
const fingerprintState = getFingerprintState(successor.state);
|
|
1210
|
+
const index = findStateIndex(getStateHash(fingerprintState), fingerprintState);
|
|
1211
|
+
successors.push({ index, state: successor.state });
|
|
1212
|
+
return false;
|
|
1213
|
+
},
|
|
1214
|
+
spec.scope,
|
|
1215
|
+
);
|
|
1216
|
+
return successors;
|
|
1217
|
+
},
|
|
1218
|
+
};
|
|
1034
1219
|
const liveness = withLivenessExitCode(() =>
|
|
1035
|
-
createLivenessChecker(search.properties.liveness, spec.temporals, environment,
|
|
1036
|
-
getFingerprint: (index) =>
|
|
1037
|
-
(tlcFingerprints[index] ??= Number(
|
|
1038
|
-
BigInt.asIntN(32, runtime.getFingerprint(states[index])),
|
|
1039
|
-
)),
|
|
1040
|
-
getSuccessors: (state) => {
|
|
1041
|
-
const successors: LiveSuccessor[] = [];
|
|
1042
|
-
if (spec.next === undefined) return successors;
|
|
1043
|
-
forEachSuccessor(
|
|
1044
|
-
spec.next,
|
|
1045
|
-
state,
|
|
1046
|
-
environment,
|
|
1047
|
-
(successor) => {
|
|
1048
|
-
canonicalizeState(successor.state);
|
|
1049
|
-
const isInModel =
|
|
1050
|
-
search.satisfiesConstraints(successor.state, state) &&
|
|
1051
|
-
search.satisfiesActionConstraints(state, successor.state);
|
|
1052
|
-
if (!isInModel) return false;
|
|
1053
|
-
const fingerprintState = getFingerprintState(successor.state);
|
|
1054
|
-
const index = findStateIndex(getStateHash(fingerprintState), fingerprintState);
|
|
1055
|
-
successors.push({ index, state: successor.state });
|
|
1056
|
-
return false;
|
|
1057
|
-
},
|
|
1058
|
-
spec.scope,
|
|
1059
|
-
);
|
|
1060
|
-
return successors;
|
|
1061
|
-
},
|
|
1062
|
-
}),
|
|
1220
|
+
createLivenessChecker(search.properties.liveness, spec.temporals, environment, liveGraph),
|
|
1063
1221
|
);
|
|
1064
1222
|
const isCanonicalizedFirst = search.isSymmetric || liveness !== undefined;
|
|
1065
1223
|
|
|
@@ -1194,7 +1352,17 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1194
1352
|
trace: TraceStep[],
|
|
1195
1353
|
initialState?: Value[],
|
|
1196
1354
|
failureOutDegrees?: number[],
|
|
1197
|
-
) => {
|
|
1355
|
+
): CheckResult => {
|
|
1356
|
+
// TLC exits with 255 on a stack overflow while it computes next states, and prints the
|
|
1357
|
+
// behavior up to the state it was expanding.
|
|
1358
|
+
if (isStackOverflow(error)) {
|
|
1359
|
+
return current.isExpanding
|
|
1360
|
+
? toFailure(
|
|
1361
|
+
setExitCode(new TlaEvaluationError(STACK_OVERFLOW), EXIT_STATUS.error),
|
|
1362
|
+
getStateTrace(current.index),
|
|
1363
|
+
)
|
|
1364
|
+
: toFailure(new TlaEvaluationError(STACK_OVERFLOW), trace, initialState);
|
|
1365
|
+
}
|
|
1198
1366
|
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
1199
1367
|
return {
|
|
1200
1368
|
...createResult("error", undefined, {
|
|
@@ -1222,6 +1390,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1222
1390
|
let hash = 0x811c9dc5;
|
|
1223
1391
|
for (let index = 0; index < state.length; index++)
|
|
1224
1392
|
hash = combineHash(hash, getValueHash(state[index]));
|
|
1393
|
+
assertFingerprintable(state);
|
|
1225
1394
|
return hash & 0x3fffffff;
|
|
1226
1395
|
};
|
|
1227
1396
|
const isSameState = (stored: Value[], state: Value[]) => {
|
|
@@ -1284,6 +1453,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1284
1453
|
isExpanding: false,
|
|
1285
1454
|
candidate: undefined as Value[] | undefined,
|
|
1286
1455
|
candidateLevel: 0,
|
|
1456
|
+
isFingerprinting: false,
|
|
1287
1457
|
livenessSource: -1,
|
|
1288
1458
|
};
|
|
1289
1459
|
const getPath = (index: number): Value[][] =>
|
|
@@ -1370,8 +1540,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1370
1540
|
current.candidate = successor.state;
|
|
1371
1541
|
current.candidateLevel = depths[index] + 1;
|
|
1372
1542
|
if (isCanonicalizedFirst) canonicalizeState(successor.state);
|
|
1543
|
+
current.isFingerprinting = true;
|
|
1373
1544
|
const fingerprintState = getFingerprintState(successor.state);
|
|
1374
1545
|
const hash = getStateHash(fingerprintState);
|
|
1546
|
+
current.isFingerprinting = false;
|
|
1375
1547
|
const found = findStateIndex(hash, fingerprintState);
|
|
1376
1548
|
const isStateInModel = search.satisfiesConstraints(successor.state, state);
|
|
1377
1549
|
if (isStateInModel) search.trackStatePossible(successor.state);
|
|
@@ -1443,10 +1615,22 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1443
1615
|
spec.scope,
|
|
1444
1616
|
);
|
|
1445
1617
|
} catch (error) {
|
|
1446
|
-
|
|
1618
|
+
if (!(error instanceof TlaIllegalStateError))
|
|
1619
|
+
return replayInitialStates(toFailure(error, []));
|
|
1620
|
+
// TLC prints an illegal initial state with null for each variable it leaves undefined, and
|
|
1621
|
+
// stops before it prints the statistics.
|
|
1622
|
+
const illegal = toFailure(
|
|
1623
|
+
error,
|
|
1624
|
+
[],
|
|
1625
|
+
error.state.map((value) => value ?? createModelValue("null")),
|
|
1626
|
+
);
|
|
1627
|
+
return {
|
|
1628
|
+
...illegal,
|
|
1629
|
+
failure: illegal.failure && { ...illegal.failure, isWithoutStatistics: true },
|
|
1630
|
+
};
|
|
1447
1631
|
}
|
|
1448
1632
|
}
|
|
1449
|
-
if (outcome.result) return outcome.result;
|
|
1633
|
+
if (outcome.result) return replayInitialStates(outcome.result);
|
|
1450
1634
|
|
|
1451
1635
|
const next = spec.next;
|
|
1452
1636
|
if (next === undefined) {
|
|
@@ -1502,7 +1686,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1502
1686
|
try {
|
|
1503
1687
|
outcome.result = visitSuccessor(index, successor, liveSuccessors, source, action);
|
|
1504
1688
|
} catch (error) {
|
|
1505
|
-
|
|
1689
|
+
// TLC reports a successor it cannot fingerprint as a failure of the state it expands.
|
|
1690
|
+
if (current.isFingerprinting) throw error;
|
|
1691
|
+
const failure = toFailure(error, getTrace(index, successor));
|
|
1692
|
+
outcome.result = isStackOverflow(error) ? failure : replaySuccessors(failure, index);
|
|
1506
1693
|
}
|
|
1507
1694
|
return outcome.result !== undefined;
|
|
1508
1695
|
});
|
|
@@ -1525,9 +1712,44 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1525
1712
|
trace: toTrace(steps, accepted),
|
|
1526
1713
|
});
|
|
1527
1714
|
} catch (error) {
|
|
1528
|
-
return
|
|
1715
|
+
return replayFailure(
|
|
1716
|
+
toFailure(toNextStateError(error), getStateTrace(index), undefined, getPartialOutDegrees()),
|
|
1717
|
+
(_, traced) =>
|
|
1718
|
+
createLivenessChecker(
|
|
1719
|
+
search.properties.liveness,
|
|
1720
|
+
spec.temporals,
|
|
1721
|
+
traced,
|
|
1722
|
+
liveGraph,
|
|
1723
|
+
)?.addState(index, state, liveSuccessors),
|
|
1724
|
+
true,
|
|
1725
|
+
);
|
|
1529
1726
|
}
|
|
1530
1727
|
};
|
|
1728
|
+
// TLC names the action when the next-state relation has more than one, and prints the
|
|
1729
|
+
// incomplete successor with null for each variable it leaves undefined.
|
|
1730
|
+
const reportIncompleteSuccessor = (error: TlaIncompleteStateError, index: number) => {
|
|
1731
|
+
nextActions.value ??= getNextActions(config, environment, specification.instanceActions);
|
|
1732
|
+
const actions = nextActions.value;
|
|
1733
|
+
const action =
|
|
1734
|
+
actions.length === 1 ? actions[0] : actions.find((item) => item.name === error.action);
|
|
1735
|
+
const variables = `variable${error.missing.length > 1 ? "s are" : " is"} not defined: ${error.missing.join(", ")}.\n`;
|
|
1736
|
+
runtime.generatedStates++;
|
|
1737
|
+
return toFailure(
|
|
1738
|
+
actions.length === 1
|
|
1739
|
+
? error
|
|
1740
|
+
: new TlaEvaluationError(
|
|
1741
|
+
`Successor state is not completely specified by action ${error.action} of the next-state relation. The following ${variables}`,
|
|
1742
|
+
),
|
|
1743
|
+
[
|
|
1744
|
+
...getStateTrace(index),
|
|
1745
|
+
{
|
|
1746
|
+
action: error.action,
|
|
1747
|
+
label: action && getActionLabel(action),
|
|
1748
|
+
state: toRecord(error.state.map((value) => value ?? createModelValue("null"))),
|
|
1749
|
+
},
|
|
1750
|
+
],
|
|
1751
|
+
);
|
|
1752
|
+
};
|
|
1531
1753
|
// TLC names the properties and the step back into the cycle from the states it prints.
|
|
1532
1754
|
const reportLasso = (checker: LivenessChecker, lasso: Lasso) => {
|
|
1533
1755
|
const path = [...lasso.prefix, ...lasso.cycle];
|
|
@@ -1573,7 +1795,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1573
1795
|
try {
|
|
1574
1796
|
outcome.result = expandState(index);
|
|
1575
1797
|
} catch (error) {
|
|
1576
|
-
|
|
1798
|
+
const failure =
|
|
1799
|
+
error instanceof TlaIncompleteStateError
|
|
1800
|
+
? reportIncompleteSuccessor(error, index)
|
|
1801
|
+
: toFailure(toNextStateError(error), getStateTrace(index));
|
|
1802
|
+
outcome.result =
|
|
1803
|
+
error instanceof TlaIncompleteStateError || isStackOverflow(error)
|
|
1804
|
+
? failure
|
|
1805
|
+
: replaySuccessors(failure, index);
|
|
1577
1806
|
}
|
|
1578
1807
|
if (outcome.result) return outcome.result;
|
|
1579
1808
|
outDegrees[getOutDegreeBucket()]++;
|