tla-ts 0.0.3-dev.7ca58b6 → 0.0.3-dev.852fbc8
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/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/parallel.cjs +1 -1
- package/dist/parallel.js +1 -1
- 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/check.ts +306 -61
- package/src/codegen.ts +6 -3
- package/src/config.ts +224 -170
- package/src/environment.ts +47 -18
- package/src/errors.ts +78 -1
- package/src/evaluate.ts +169 -16
- package/src/exit-codes.ts +22 -3
- package/src/instances.ts +1 -1
- package/src/levels.ts +55 -27
- package/src/live-check.ts +8 -2
- package/src/liveness.ts +68 -10
- package/src/parallel-worker.ts +2 -2
- package/src/parallel.ts +2 -2
- package/src/parser.ts +21 -10
- 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 +8 -2
- 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 +114 -43
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/check.ts
CHANGED
|
@@ -11,8 +11,13 @@ 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,
|
|
20
|
+
TlaIncompleteStateError,
|
|
16
21
|
TlaModuleError,
|
|
17
22
|
UNEXPECTED_EXCEPTION,
|
|
18
23
|
} from "./errors";
|
|
@@ -21,7 +26,6 @@ import {
|
|
|
21
26
|
describeRange,
|
|
22
27
|
evaluate,
|
|
23
28
|
expectBoolean,
|
|
24
|
-
formatRange,
|
|
25
29
|
getDefinition,
|
|
26
30
|
isConstantLevel,
|
|
27
31
|
isImpure,
|
|
@@ -32,6 +36,7 @@ import {
|
|
|
32
36
|
import {
|
|
33
37
|
createLivenessChecker,
|
|
34
38
|
type Lasso,
|
|
39
|
+
type LiveGraph,
|
|
35
40
|
type LivenessChecker,
|
|
36
41
|
type LiveSuccessor,
|
|
37
42
|
} from "./live-check";
|
|
@@ -59,14 +64,16 @@ import {
|
|
|
59
64
|
type StateWriter,
|
|
60
65
|
} from "./state-graph";
|
|
61
66
|
import { getRepresentative, getSymmetryGroup } from "./symmetry";
|
|
62
|
-
import { getTlcStringOrder,
|
|
67
|
+
import { getTlcStringOrder, getTlcDeclarationOrder } from "./tlc-order";
|
|
63
68
|
import { createTlcFingerprinter, getTlcFingerprint } from "./tlc-random";
|
|
64
69
|
import { createCanonicalizer } from "./canonical";
|
|
65
70
|
import { getPossibleCounts, type CheckerRuntime } from "./runtime";
|
|
66
71
|
import { createCounterExample } from "./tlc-ext";
|
|
72
|
+
import { getFingerprintTrace, valueSources } from "./value-sources";
|
|
67
73
|
import { getFingerprintDistance, OUT_DEGREE_BUCKETS } from "./tlc-summary";
|
|
68
74
|
import {
|
|
69
75
|
combineHash,
|
|
76
|
+
createModelValue,
|
|
70
77
|
formatState,
|
|
71
78
|
formatValue,
|
|
72
79
|
getValueHash,
|
|
@@ -136,6 +143,25 @@ export interface EvaluationFailure {
|
|
|
136
143
|
trace: TraceStep[];
|
|
137
144
|
initialState: Record<string, Value> | undefined;
|
|
138
145
|
exitCode: number;
|
|
146
|
+
replay?: Replay;
|
|
147
|
+
isWithoutStatistics?: boolean;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// TLC replays a failed step to print the expressions it was evaluating when the replay failed.
|
|
151
|
+
export interface Replay {
|
|
152
|
+
output: string[];
|
|
153
|
+
callStack: string[] | undefined;
|
|
154
|
+
fingerprint?: Fingerprint;
|
|
155
|
+
// The worker that fails to check liveness replays the step at once, so TLC prints the stack
|
|
156
|
+
// before the error, and only when it holds a frame.
|
|
157
|
+
isBeforeError?: boolean;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// TLC reports an error from a method of a value that has a source as one it was unable to
|
|
161
|
+
// fingerprint. With an empty stack, it lists the sources of the values instead.
|
|
162
|
+
export interface Fingerprint {
|
|
163
|
+
sources: string[];
|
|
164
|
+
reason: string;
|
|
139
165
|
}
|
|
140
166
|
|
|
141
167
|
export interface CheckResult {
|
|
@@ -247,7 +273,7 @@ const getConstantValue = (name: string, definition: Definition, environment: Env
|
|
|
247
273
|
try {
|
|
248
274
|
return evaluate(createIdentifier(name), getContext(environment, undefined, undefined));
|
|
249
275
|
} catch (error) {
|
|
250
|
-
if (error instanceof TlaEvaluationError) return undefined;
|
|
276
|
+
if (error instanceof TlaEvaluationError || isStackOverflow(error)) return undefined;
|
|
251
277
|
throw error;
|
|
252
278
|
}
|
|
253
279
|
};
|
|
@@ -276,8 +302,11 @@ const getInvariants = (names: string[], environment: Environment) => {
|
|
|
276
302
|
levels.params.size === 0
|
|
277
303
|
? ""
|
|
278
304
|
: "\nNote that a bug can cause TLC to incorrectly report this error.\nIf you believe your TLA+ or PlusCal specification to be correct,\nplease check if this bug described in LevelNode.java starting at line 590ff affects you.";
|
|
279
|
-
throw
|
|
280
|
-
|
|
305
|
+
throw setExitCode(
|
|
306
|
+
new TlaConfigError(
|
|
307
|
+
`The invariant ${name} is not a state predicate (one with no primes or temporal operators).${note}`,
|
|
308
|
+
),
|
|
309
|
+
EXIT_STATUS.safetyEvaluationFailure,
|
|
281
310
|
);
|
|
282
311
|
}
|
|
283
312
|
return [{ name, expression: createIdentifier(name), scope: undefined }];
|
|
@@ -375,8 +404,11 @@ const getSpecification = (config: ModelConfig, environment: Environment): Specif
|
|
|
375
404
|
conjunct.kind === "Always" &&
|
|
376
405
|
getLevel(conjunct.expression, item.scope, environment) < ACTION_LEVEL
|
|
377
406
|
) {
|
|
378
|
-
throw
|
|
379
|
-
|
|
407
|
+
throw setExitCode(
|
|
408
|
+
new TlaConfigError(
|
|
409
|
+
`TLC cannot handle the temporal formula ${describeRange(conjunct.expression)}`,
|
|
410
|
+
),
|
|
411
|
+
EXIT_STATUS.error,
|
|
380
412
|
);
|
|
381
413
|
}
|
|
382
414
|
const level = getLevel(conjunct, item.scope, environment);
|
|
@@ -825,11 +857,17 @@ export const createSearch = (
|
|
|
825
857
|
}
|
|
826
858
|
}),
|
|
827
859
|
satisfiesConstraints: (state, parent) =>
|
|
828
|
-
constraints.every(
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
860
|
+
constraints.every((constraint) => {
|
|
861
|
+
try {
|
|
862
|
+
return (
|
|
863
|
+
isUnchangedFor(constraint, state, parent) ||
|
|
864
|
+
holdsLikeTlc(constraint.expression, getContext(environment, state, undefined))
|
|
865
|
+
);
|
|
866
|
+
} catch (error) {
|
|
867
|
+
// TLC reports a failing constraint on a successor like a failure of the next-state relation.
|
|
868
|
+
throw parent ? toNextStateError(error) : error;
|
|
869
|
+
}
|
|
870
|
+
}),
|
|
833
871
|
findFailedInitialPredicate: (state) =>
|
|
834
872
|
properties.initialPredicates.find(
|
|
835
873
|
(predicate) =>
|
|
@@ -862,13 +900,13 @@ export const createSearch = (
|
|
|
862
900
|
}
|
|
863
901
|
}),
|
|
864
902
|
satisfiesActionConstraints: (state, next) =>
|
|
865
|
-
actionConstraints.every((constraint) =>
|
|
866
|
-
|
|
867
|
-
constraint.expression,
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
),
|
|
903
|
+
actionConstraints.every((constraint) => {
|
|
904
|
+
try {
|
|
905
|
+
return holdsLikeTlc(constraint.expression, getContext(environment, state, next));
|
|
906
|
+
} catch (error) {
|
|
907
|
+
throw toNextStateError(error);
|
|
908
|
+
}
|
|
909
|
+
}),
|
|
872
910
|
trackStatePossible:
|
|
873
911
|
statePossible.length === 0
|
|
874
912
|
? ignorePossible
|
|
@@ -899,6 +937,59 @@ export const createSearch = (
|
|
|
899
937
|
const withNextStateExitCode = (error: unknown) =>
|
|
900
938
|
error instanceof TlaModuleError ? setExitCode(error, error.exitCode) : error;
|
|
901
939
|
|
|
940
|
+
// TLC reports a failure of the next-state relation, or of the liveness check of a step, as an
|
|
941
|
+
// unexpected exception, unless a standard module raised it as an EvalException.
|
|
942
|
+
const toNextStateError = (error: unknown) =>
|
|
943
|
+
error instanceof TlaEvaluationError &&
|
|
944
|
+
!(error instanceof TlaModuleError) &&
|
|
945
|
+
!(error instanceof TlaIncompleteStateError)
|
|
946
|
+
? setExitCode(
|
|
947
|
+
new TlaEvaluationError(`${UNEXPECTED_EXCEPTION}${error.message}`, error),
|
|
948
|
+
getErrorExitCode(error),
|
|
949
|
+
)
|
|
950
|
+
: withNextStateExitCode(error);
|
|
951
|
+
|
|
952
|
+
const isRepeated = (frame: string, index: number, frames: string[]) =>
|
|
953
|
+
index > 0 && frames[index - 1] === frame;
|
|
954
|
+
|
|
955
|
+
// FingerprintException#getTrace numbers the sources from the outermost value and lists the innermost
|
|
956
|
+
// first.
|
|
957
|
+
const getSourceTrace = (sources: Expression[]) =>
|
|
958
|
+
sources
|
|
959
|
+
.flatMap((source) => (source.location.range ? [formatRange(source.location.range)] : []))
|
|
960
|
+
.filter((source, index, all) => !isRepeated(source, index, all))
|
|
961
|
+
.map((source, index) => `${index}) ${source}`)
|
|
962
|
+
.reverse();
|
|
963
|
+
|
|
964
|
+
// TLC keeps the stack only when an evaluation fails, and prints each expression on it once, however
|
|
965
|
+
// many times in a row it pushed it.
|
|
966
|
+
const getReplayedCallStack = (
|
|
967
|
+
replay: () => void,
|
|
968
|
+
trace: Expression[],
|
|
969
|
+
): Pick<Replay, "callStack" | "fingerprint"> => {
|
|
970
|
+
try {
|
|
971
|
+
replay();
|
|
972
|
+
return { callStack: undefined };
|
|
973
|
+
} catch (error) {
|
|
974
|
+
if (!(error instanceof TlaEvaluationError)) return { callStack: [] };
|
|
975
|
+
const callStack = trace
|
|
976
|
+
.flatMap((expression) => {
|
|
977
|
+
const range = expression.location.range;
|
|
978
|
+
return range
|
|
979
|
+
? [
|
|
980
|
+
`Line ${range.start.line}, column ${range.start.column} to line ${range.end.line}, column ${range.end.column} in ${range.module}`,
|
|
981
|
+
]
|
|
982
|
+
: [];
|
|
983
|
+
})
|
|
984
|
+
.filter((frame, index, frames) => !isRepeated(frame, index, frames));
|
|
985
|
+
const sources = getFingerprintTrace(error);
|
|
986
|
+
return {
|
|
987
|
+
callStack,
|
|
988
|
+
fingerprint: sources && { sources: getSourceTrace(sources), reason: error.message },
|
|
989
|
+
};
|
|
990
|
+
}
|
|
991
|
+
};
|
|
992
|
+
|
|
902
993
|
const withHeadline = (error: unknown, headline: string) =>
|
|
903
994
|
error instanceof TlaEvaluationError
|
|
904
995
|
? setExitCode(
|
|
@@ -910,9 +1001,16 @@ const withHeadline = (error: unknown, headline: string) =>
|
|
|
910
1001
|
// TLC finishes the -dump file whether or not the search finds a violation.
|
|
911
1002
|
export const checkSequentially = (options: CheckOptions): CheckResult => {
|
|
912
1003
|
const stateWriter = options.dump && createStateWriter(options.dump, options.writeFile);
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
1004
|
+
try {
|
|
1005
|
+
return searchStates(options, stateWriter);
|
|
1006
|
+
} catch (error) {
|
|
1007
|
+
// TLC reports a stack overflow outside the search as a failure of its own, with exit code 255.
|
|
1008
|
+
throw isStackOverflow(error)
|
|
1009
|
+
? setExitCode(new TlaEvaluationError(STACK_OVERFLOW), EXIT_STATUS.error)
|
|
1010
|
+
: error;
|
|
1011
|
+
} finally {
|
|
1012
|
+
stateWriter?.close();
|
|
1013
|
+
}
|
|
916
1014
|
};
|
|
917
1015
|
|
|
918
1016
|
const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefined): CheckResult => {
|
|
@@ -920,9 +1018,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
920
1018
|
const onPrint = options.onPrint ?? console.log;
|
|
921
1019
|
// TLC prints again while it rebuilds a trace, between the states it prints. Printing those lines
|
|
922
1020
|
// before the trace would misplace them, so rebuilding a trace prints nothing.
|
|
923
|
-
const output = { isMuted: false };
|
|
1021
|
+
const output = { isMuted: false, replayed: undefined as string[] | undefined };
|
|
924
1022
|
const print = (text: string) => {
|
|
925
|
-
if (
|
|
1023
|
+
if (output.replayed) output.replayed.push(text);
|
|
1024
|
+
else if (!output.isMuted) onPrint(text);
|
|
926
1025
|
};
|
|
927
1026
|
const withoutOutput = <Result>(rebuild: () => Result) => {
|
|
928
1027
|
output.isMuted = true;
|
|
@@ -984,9 +1083,9 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
984
1083
|
),
|
|
985
1084
|
});
|
|
986
1085
|
|
|
987
|
-
const
|
|
988
|
-
|
|
989
|
-
);
|
|
1086
|
+
const getVariableOrder = () =>
|
|
1087
|
+
getTlcDeclarationOrder(options.source, options.loadModule, "variable");
|
|
1088
|
+
const search = createSearch(config, environment, getVariableOrder);
|
|
990
1089
|
const assumptionViolation = findAssumptionViolation(specification.assumptions, environment);
|
|
991
1090
|
if (assumptionViolation) return createResult("assumption-violation", assumptionViolation);
|
|
992
1091
|
if (!search) return createSuccess();
|
|
@@ -1010,37 +1109,113 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1010
1109
|
const spec = search.spec;
|
|
1011
1110
|
const getFingerprintState = search.getFingerprintState;
|
|
1012
1111
|
const nextActions = { value: undefined as SpecAction[] | undefined };
|
|
1112
|
+
const replayFailure = (
|
|
1113
|
+
result: CheckResult,
|
|
1114
|
+
replay: (tracedSearch: Search, traced: Environment) => void,
|
|
1115
|
+
isBeforeError = false,
|
|
1116
|
+
): CheckResult => {
|
|
1117
|
+
if (!result.failure) return result;
|
|
1118
|
+
const trace: Expression[] = [];
|
|
1119
|
+
const traced: Environment = { ...environment, evaluators: new WeakMap(), trace };
|
|
1120
|
+
const tracedSearch = createSearch(config, traced, getVariableOrder);
|
|
1121
|
+
if (!tracedSearch) return result;
|
|
1122
|
+
const replayed: string[] = [];
|
|
1123
|
+
output.replayed = replayed;
|
|
1124
|
+
valueSources.current = new WeakMap();
|
|
1125
|
+
const replayedStack = getReplayedCallStack(() => replay(tracedSearch, traced), trace);
|
|
1126
|
+
valueSources.current = undefined;
|
|
1127
|
+
output.replayed = undefined;
|
|
1128
|
+
return {
|
|
1129
|
+
...result,
|
|
1130
|
+
failure: { ...result.failure, replay: { output: replayed, ...replayedStack, isBeforeError } },
|
|
1131
|
+
};
|
|
1132
|
+
};
|
|
1133
|
+
// TLC fingerprints a state outside CallStackTool, so a failure leaves the stack empty.
|
|
1134
|
+
const fingerprintReplayed = (state: Value[], traced: Environment) => {
|
|
1135
|
+
try {
|
|
1136
|
+
getStateHash(getFingerprintState(state));
|
|
1137
|
+
} catch (error) {
|
|
1138
|
+
if (traced.trace) traced.trace.length = 0;
|
|
1139
|
+
throw error;
|
|
1140
|
+
}
|
|
1141
|
+
};
|
|
1142
|
+
// TLC checks every initial state again, as when it first generated them.
|
|
1143
|
+
const replayInitialStates = (result: CheckResult) =>
|
|
1144
|
+
replayFailure(result, (tracedSearch, traced) => {
|
|
1145
|
+
if (spec.init === undefined) return;
|
|
1146
|
+
forEachInitialState(
|
|
1147
|
+
spec.init,
|
|
1148
|
+
traced,
|
|
1149
|
+
(state) => {
|
|
1150
|
+
if (tracedSearch.satisfiesConstraints(state)) fingerprintReplayed(state, traced);
|
|
1151
|
+
return (
|
|
1152
|
+
tracedSearch.findViolatedInvariant(state) !== undefined ||
|
|
1153
|
+
tracedSearch.findFailedInitialPredicate(state) !== undefined
|
|
1154
|
+
);
|
|
1155
|
+
},
|
|
1156
|
+
spec.scope,
|
|
1157
|
+
);
|
|
1158
|
+
});
|
|
1159
|
+
// TLC rebuilds the behavior up to the state it expanded before it replays the step.
|
|
1160
|
+
const rebuildBehavior = (index: number): void => {
|
|
1161
|
+
const parent = parents[index];
|
|
1162
|
+
if (parent === -1) {
|
|
1163
|
+
getSpecInitialStates();
|
|
1164
|
+
return;
|
|
1165
|
+
}
|
|
1166
|
+
rebuildBehavior(parent);
|
|
1167
|
+
getLabel(parent, states[parent], states[index]);
|
|
1168
|
+
};
|
|
1169
|
+
// TLC generates the successors of each action before it checks them. It checks the invariants
|
|
1170
|
+
// only of a successor outside the model, since it has seen the others.
|
|
1171
|
+
const replaySuccessors = (result: CheckResult, index: number) =>
|
|
1172
|
+
replayFailure(result, (tracedSearch, traced) => {
|
|
1173
|
+
rebuildBehavior(index);
|
|
1174
|
+
const state = states[index];
|
|
1175
|
+
nextActions.value ??= getNextActions(config, environment, specification.instanceActions);
|
|
1176
|
+
nextActions.value.find((action) =>
|
|
1177
|
+
getSuccessors(action.expression, state, traced, action.scope).some((successor) => {
|
|
1178
|
+
const isInModel =
|
|
1179
|
+
tracedSearch.satisfiesConstraints(successor.state) &&
|
|
1180
|
+
tracedSearch.satisfiesActionConstraints(state, successor.state);
|
|
1181
|
+
if (isInModel) fingerprintReplayed(successor.state, traced);
|
|
1182
|
+
return (
|
|
1183
|
+
(!isInModel && tracedSearch.findViolatedInvariant(successor.state) !== undefined) ||
|
|
1184
|
+
tracedSearch.findViolatedActionProperty(state, successor.state) !== undefined
|
|
1185
|
+
);
|
|
1186
|
+
}),
|
|
1187
|
+
);
|
|
1188
|
+
});
|
|
1013
1189
|
const isReducing = config.view !== undefined || config.symmetry !== undefined;
|
|
1014
1190
|
const tlcFingerprints: number[] = [];
|
|
1191
|
+
const liveGraph: LiveGraph = {
|
|
1192
|
+
getFingerprint: (index) =>
|
|
1193
|
+
(tlcFingerprints[index] ??= Number(BigInt.asIntN(32, runtime.getFingerprint(states[index])))),
|
|
1194
|
+
getSuccessors: (state) => {
|
|
1195
|
+
const successors: LiveSuccessor[] = [];
|
|
1196
|
+
if (spec.next === undefined) return successors;
|
|
1197
|
+
forEachSuccessor(
|
|
1198
|
+
spec.next,
|
|
1199
|
+
state,
|
|
1200
|
+
environment,
|
|
1201
|
+
(successor) => {
|
|
1202
|
+
canonicalizeState(successor.state);
|
|
1203
|
+
const isInModel =
|
|
1204
|
+
search.satisfiesConstraints(successor.state, state) &&
|
|
1205
|
+
search.satisfiesActionConstraints(state, successor.state);
|
|
1206
|
+
if (!isInModel) return false;
|
|
1207
|
+
const fingerprintState = getFingerprintState(successor.state);
|
|
1208
|
+
const index = findStateIndex(getStateHash(fingerprintState), fingerprintState);
|
|
1209
|
+
successors.push({ index, state: successor.state });
|
|
1210
|
+
return false;
|
|
1211
|
+
},
|
|
1212
|
+
spec.scope,
|
|
1213
|
+
);
|
|
1214
|
+
return successors;
|
|
1215
|
+
},
|
|
1216
|
+
};
|
|
1015
1217
|
const liveness = withLivenessExitCode(() =>
|
|
1016
|
-
createLivenessChecker(search.properties.liveness, spec.temporals, environment,
|
|
1017
|
-
getFingerprint: (index) =>
|
|
1018
|
-
(tlcFingerprints[index] ??= Number(
|
|
1019
|
-
BigInt.asIntN(32, runtime.getFingerprint(states[index])),
|
|
1020
|
-
)),
|
|
1021
|
-
getSuccessors: (state) => {
|
|
1022
|
-
const successors: LiveSuccessor[] = [];
|
|
1023
|
-
if (spec.next === undefined) return successors;
|
|
1024
|
-
forEachSuccessor(
|
|
1025
|
-
spec.next,
|
|
1026
|
-
state,
|
|
1027
|
-
environment,
|
|
1028
|
-
(successor) => {
|
|
1029
|
-
canonicalizeState(successor.state);
|
|
1030
|
-
const isInModel =
|
|
1031
|
-
search.satisfiesConstraints(successor.state, state) &&
|
|
1032
|
-
search.satisfiesActionConstraints(state, successor.state);
|
|
1033
|
-
if (!isInModel) return false;
|
|
1034
|
-
const fingerprintState = getFingerprintState(successor.state);
|
|
1035
|
-
const index = findStateIndex(getStateHash(fingerprintState), fingerprintState);
|
|
1036
|
-
successors.push({ index, state: successor.state });
|
|
1037
|
-
return false;
|
|
1038
|
-
},
|
|
1039
|
-
spec.scope,
|
|
1040
|
-
);
|
|
1041
|
-
return successors;
|
|
1042
|
-
},
|
|
1043
|
-
}),
|
|
1218
|
+
createLivenessChecker(search.properties.liveness, spec.temporals, environment, liveGraph),
|
|
1044
1219
|
);
|
|
1045
1220
|
const isCanonicalizedFirst = search.isSymmetric || liveness !== undefined;
|
|
1046
1221
|
|
|
@@ -1175,7 +1350,17 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1175
1350
|
trace: TraceStep[],
|
|
1176
1351
|
initialState?: Value[],
|
|
1177
1352
|
failureOutDegrees?: number[],
|
|
1178
|
-
) => {
|
|
1353
|
+
): CheckResult => {
|
|
1354
|
+
// TLC exits with 255 on a stack overflow while it computes next states, and prints the
|
|
1355
|
+
// behavior up to the state it was expanding.
|
|
1356
|
+
if (isStackOverflow(error)) {
|
|
1357
|
+
return current.isExpanding
|
|
1358
|
+
? toFailure(
|
|
1359
|
+
setExitCode(new TlaEvaluationError(STACK_OVERFLOW), EXIT_STATUS.error),
|
|
1360
|
+
getStateTrace(current.index),
|
|
1361
|
+
)
|
|
1362
|
+
: toFailure(new TlaEvaluationError(STACK_OVERFLOW), trace, initialState);
|
|
1363
|
+
}
|
|
1179
1364
|
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
1180
1365
|
return {
|
|
1181
1366
|
...createResult("error", undefined, {
|
|
@@ -1265,6 +1450,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1265
1450
|
isExpanding: false,
|
|
1266
1451
|
candidate: undefined as Value[] | undefined,
|
|
1267
1452
|
candidateLevel: 0,
|
|
1453
|
+
isFingerprinting: false,
|
|
1268
1454
|
livenessSource: -1,
|
|
1269
1455
|
};
|
|
1270
1456
|
const getPath = (index: number): Value[][] =>
|
|
@@ -1351,8 +1537,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1351
1537
|
current.candidate = successor.state;
|
|
1352
1538
|
current.candidateLevel = depths[index] + 1;
|
|
1353
1539
|
if (isCanonicalizedFirst) canonicalizeState(successor.state);
|
|
1540
|
+
current.isFingerprinting = true;
|
|
1354
1541
|
const fingerprintState = getFingerprintState(successor.state);
|
|
1355
1542
|
const hash = getStateHash(fingerprintState);
|
|
1543
|
+
current.isFingerprinting = false;
|
|
1356
1544
|
const found = findStateIndex(hash, fingerprintState);
|
|
1357
1545
|
const isStateInModel = search.satisfiesConstraints(successor.state, state);
|
|
1358
1546
|
if (isStateInModel) search.trackStatePossible(successor.state);
|
|
@@ -1424,10 +1612,22 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1424
1612
|
spec.scope,
|
|
1425
1613
|
);
|
|
1426
1614
|
} catch (error) {
|
|
1427
|
-
|
|
1615
|
+
if (!(error instanceof TlaIllegalStateError))
|
|
1616
|
+
return replayInitialStates(toFailure(error, []));
|
|
1617
|
+
// TLC prints an illegal initial state with null for each variable it leaves undefined, and
|
|
1618
|
+
// stops before it prints the statistics.
|
|
1619
|
+
const illegal = toFailure(
|
|
1620
|
+
error,
|
|
1621
|
+
[],
|
|
1622
|
+
error.state.map((value) => value ?? createModelValue("null")),
|
|
1623
|
+
);
|
|
1624
|
+
return {
|
|
1625
|
+
...illegal,
|
|
1626
|
+
failure: illegal.failure && { ...illegal.failure, isWithoutStatistics: true },
|
|
1627
|
+
};
|
|
1428
1628
|
}
|
|
1429
1629
|
}
|
|
1430
|
-
if (outcome.result) return outcome.result;
|
|
1630
|
+
if (outcome.result) return replayInitialStates(outcome.result);
|
|
1431
1631
|
|
|
1432
1632
|
const next = spec.next;
|
|
1433
1633
|
if (next === undefined) {
|
|
@@ -1483,7 +1683,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1483
1683
|
try {
|
|
1484
1684
|
outcome.result = visitSuccessor(index, successor, liveSuccessors, source, action);
|
|
1485
1685
|
} catch (error) {
|
|
1486
|
-
|
|
1686
|
+
// TLC reports a successor it cannot fingerprint as a failure of the state it expands.
|
|
1687
|
+
if (current.isFingerprinting) throw error;
|
|
1688
|
+
const failure = toFailure(error, getTrace(index, successor));
|
|
1689
|
+
outcome.result = isStackOverflow(error) ? failure : replaySuccessors(failure, index);
|
|
1487
1690
|
}
|
|
1488
1691
|
return outcome.result !== undefined;
|
|
1489
1692
|
});
|
|
@@ -1506,9 +1709,44 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1506
1709
|
trace: toTrace(steps, accepted),
|
|
1507
1710
|
});
|
|
1508
1711
|
} catch (error) {
|
|
1509
|
-
return
|
|
1712
|
+
return replayFailure(
|
|
1713
|
+
toFailure(toNextStateError(error), getStateTrace(index), undefined, getPartialOutDegrees()),
|
|
1714
|
+
(_, traced) =>
|
|
1715
|
+
createLivenessChecker(
|
|
1716
|
+
search.properties.liveness,
|
|
1717
|
+
spec.temporals,
|
|
1718
|
+
traced,
|
|
1719
|
+
liveGraph,
|
|
1720
|
+
)?.addState(index, state, liveSuccessors),
|
|
1721
|
+
true,
|
|
1722
|
+
);
|
|
1510
1723
|
}
|
|
1511
1724
|
};
|
|
1725
|
+
// TLC names the action when the next-state relation has more than one, and prints the
|
|
1726
|
+
// incomplete successor with null for each variable it leaves undefined.
|
|
1727
|
+
const reportIncompleteSuccessor = (error: TlaIncompleteStateError, index: number) => {
|
|
1728
|
+
nextActions.value ??= getNextActions(config, environment, specification.instanceActions);
|
|
1729
|
+
const actions = nextActions.value;
|
|
1730
|
+
const action =
|
|
1731
|
+
actions.length === 1 ? actions[0] : actions.find((item) => item.name === error.action);
|
|
1732
|
+
const variables = `variable${error.missing.length > 1 ? "s are" : " is"} not defined: ${error.missing.join(", ")}.\n`;
|
|
1733
|
+
runtime.generatedStates++;
|
|
1734
|
+
return toFailure(
|
|
1735
|
+
actions.length === 1
|
|
1736
|
+
? error
|
|
1737
|
+
: new TlaEvaluationError(
|
|
1738
|
+
`Successor state is not completely specified by action ${error.action} of the next-state relation. The following ${variables}`,
|
|
1739
|
+
),
|
|
1740
|
+
[
|
|
1741
|
+
...getStateTrace(index),
|
|
1742
|
+
{
|
|
1743
|
+
action: error.action,
|
|
1744
|
+
label: action && getActionLabel(action),
|
|
1745
|
+
state: toRecord(error.state.map((value) => value ?? createModelValue("null"))),
|
|
1746
|
+
},
|
|
1747
|
+
],
|
|
1748
|
+
);
|
|
1749
|
+
};
|
|
1512
1750
|
// TLC names the properties and the step back into the cycle from the states it prints.
|
|
1513
1751
|
const reportLasso = (checker: LivenessChecker, lasso: Lasso) => {
|
|
1514
1752
|
const path = [...lasso.prefix, ...lasso.cycle];
|
|
@@ -1554,7 +1792,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1554
1792
|
try {
|
|
1555
1793
|
outcome.result = expandState(index);
|
|
1556
1794
|
} catch (error) {
|
|
1557
|
-
|
|
1795
|
+
const failure =
|
|
1796
|
+
error instanceof TlaIncompleteStateError
|
|
1797
|
+
? reportIncompleteSuccessor(error, index)
|
|
1798
|
+
: toFailure(toNextStateError(error), getStateTrace(index));
|
|
1799
|
+
outcome.result =
|
|
1800
|
+
error instanceof TlaIncompleteStateError || isStackOverflow(error)
|
|
1801
|
+
? failure
|
|
1802
|
+
: replaySuccessors(failure, index);
|
|
1558
1803
|
}
|
|
1559
1804
|
if (outcome.result) return outcome.result;
|
|
1560
1805
|
outDegrees[getOutDegreeBucket()]++;
|
package/src/codegen.ts
CHANGED
|
@@ -10,6 +10,8 @@ import {
|
|
|
10
10
|
getSubsetOperator,
|
|
11
11
|
getEvaluator,
|
|
12
12
|
getFieldError,
|
|
13
|
+
getNonFunctionError,
|
|
14
|
+
getNonRecordError,
|
|
13
15
|
isClosedConstant,
|
|
14
16
|
isTlcInteger,
|
|
15
17
|
isValueArgument,
|
|
@@ -250,12 +252,13 @@ const generateExpression = (generator: Generator, expression: Expression, frame:
|
|
|
250
252
|
case "FunctionApplication": {
|
|
251
253
|
keepLazy(expression.function);
|
|
252
254
|
const functionCode = generate(expression.function);
|
|
255
|
+
const describeNonFunction = addReference(generator, getNonFunctionError(expression));
|
|
253
256
|
if (expression.args.length === 1)
|
|
254
|
-
return `apply(${functionCode}, ${generate(expression.args[0])})`;
|
|
255
|
-
return `apply(${functionCode}, tuple([${expression.args.map((arg) => generate(arg)).join(", ")}]))`;
|
|
257
|
+
return `apply(${functionCode}, ${generate(expression.args[0])}, undefined, ${describeNonFunction})`;
|
|
258
|
+
return `apply(${functionCode}, tuple([${expression.args.map((arg) => generate(arg)).join(", ")}]), undefined, ${describeNonFunction})`;
|
|
256
259
|
}
|
|
257
260
|
case "FieldAccess":
|
|
258
|
-
return `apply(${generate(expression.record)}, ${JSON.stringify(expression.field)}, ${addReference(generator, getFieldError(expression))})`;
|
|
261
|
+
return `apply(${generate(expression.record)}, ${JSON.stringify(expression.field)}, ${addReference(generator, getFieldError(expression))}, ${addReference(generator, getNonRecordError(expression))})`;
|
|
259
262
|
case "Record": {
|
|
260
263
|
const fields = getSortedFields(expression.fields);
|
|
261
264
|
if (hasDuplicateFields(fields)) return generateDelegate(generator, expression, frame);
|