tla-ts 0.0.3-dev.5e999f2 → 0.0.3-dev.5fd6731
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.cjs +1 -1
- package/dist/index.d.cts +38 -1
- package/dist/index.d.ts +38 -1
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +2 -2
- package/dist/parallel.cjs +1 -1
- package/dist/parallel.js +2 -2
- package/dist/run-cli.cjs +14 -12
- package/dist/run-cli.js +22 -20
- package/dist/transfer.cjs +36 -21
- package/dist/transfer.js +36 -21
- package/package.json +1 -1
- package/src/ast.ts +27 -4
- package/src/builtins.ts +9 -3
- package/src/check.ts +234 -53
- package/src/config.ts +224 -170
- package/src/environment.ts +225 -74
- package/src/errors.ts +74 -1
- 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 +177 -36
- package/src/live-check.ts +3 -1
- package/src/liveness.ts +66 -6
- package/src/parser.ts +155 -49
- package/src/resolve.ts +911 -342
- package/src/run-cli.ts +61 -11
- package/src/sany-lexer.ts +615 -0
- package/src/sany-parse-error.ts +3143 -0
- package/src/spec-description.ts +1 -2
- package/src/standard-modules.ts +52 -38
- package/src/standard-ranges.ts +116 -0
- package/src/subexpressions.ts +26 -14
- package/src/substitution-levels.ts +38 -17
- package/src/successors.ts +105 -27
- package/src/value-sources.ts +29 -0
- package/src/values.ts +122 -42
package/package.json
CHANGED
package/src/ast.ts
CHANGED
|
@@ -33,9 +33,12 @@ export interface StringExpression {
|
|
|
33
33
|
location: SourceLocation;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
// selectorRanges holds the range of each part of a name such as foo!lab, where SANY reports an
|
|
37
|
+
// error in selecting that part.
|
|
36
38
|
export interface IdentifierExpression {
|
|
37
39
|
kind: "Identifier";
|
|
38
40
|
name: string;
|
|
41
|
+
selectorRanges?: SourceRange[];
|
|
39
42
|
location: SourceLocation;
|
|
40
43
|
resolution?: LocalResolution;
|
|
41
44
|
}
|
|
@@ -47,6 +50,9 @@ export interface ApplyExpression {
|
|
|
47
50
|
// The number of args each part of a name like F(x)!l(y) takes, when a part before the last takes
|
|
48
51
|
// some.
|
|
49
52
|
argumentCounts?: number[];
|
|
53
|
+
// The range of the parenthesized arguments of a named operator, where SANY reports their count.
|
|
54
|
+
argumentsRange?: SourceRange;
|
|
55
|
+
selectorRanges?: SourceRange[];
|
|
50
56
|
location: SourceLocation;
|
|
51
57
|
resolution?: LocalResolution;
|
|
52
58
|
}
|
|
@@ -60,6 +66,7 @@ export interface OperatorReferenceExpression {
|
|
|
60
66
|
export interface LambdaExpression {
|
|
61
67
|
kind: "Lambda";
|
|
62
68
|
params: string[];
|
|
69
|
+
paramRanges?: SourceRange[];
|
|
63
70
|
body: Expression;
|
|
64
71
|
location: SourceLocation;
|
|
65
72
|
}
|
|
@@ -117,7 +124,10 @@ export interface LetExpression {
|
|
|
117
124
|
location: SourceLocation;
|
|
118
125
|
}
|
|
119
126
|
|
|
120
|
-
|
|
127
|
+
// ranges holds the range of each name the pattern binds.
|
|
128
|
+
export type BoundPattern =
|
|
129
|
+
| { kind: "Name"; name: string; ranges?: SourceRange[] }
|
|
130
|
+
| { kind: "Tuple"; names: string[]; ranges?: SourceRange[] };
|
|
121
131
|
|
|
122
132
|
export interface Bound {
|
|
123
133
|
pattern: BoundPattern;
|
|
@@ -135,6 +145,7 @@ export interface UnboundedQuantifierExpression {
|
|
|
135
145
|
kind: "UnboundedQuantifier";
|
|
136
146
|
quantifier: "Forall" | "Exists";
|
|
137
147
|
names: string[];
|
|
148
|
+
nameRanges?: SourceRange[];
|
|
138
149
|
isTemporal?: boolean;
|
|
139
150
|
body: Expression;
|
|
140
151
|
location: SourceLocation;
|
|
@@ -192,6 +203,7 @@ export interface FunctionSetExpression {
|
|
|
192
203
|
export interface RecordField {
|
|
193
204
|
name: string;
|
|
194
205
|
value: Expression;
|
|
206
|
+
location: SourceLocation;
|
|
195
207
|
}
|
|
196
208
|
|
|
197
209
|
export interface RecordExpression {
|
|
@@ -280,6 +292,7 @@ export type Selector =
|
|
|
280
292
|
export interface SubexpressionExpression {
|
|
281
293
|
kind: "Subexpression";
|
|
282
294
|
selectors: Selector[];
|
|
295
|
+
selectorRanges?: SourceRange[];
|
|
283
296
|
location: SourceLocation;
|
|
284
297
|
}
|
|
285
298
|
|
|
@@ -363,6 +376,7 @@ export interface Assumption {
|
|
|
363
376
|
|
|
364
377
|
export interface InstanceSubstitution {
|
|
365
378
|
name: string;
|
|
379
|
+
nameRange: SourceRange;
|
|
366
380
|
expression: Expression;
|
|
367
381
|
}
|
|
368
382
|
|
|
@@ -384,6 +398,7 @@ export interface NewSymbol {
|
|
|
384
398
|
arity: number;
|
|
385
399
|
level: "Constant" | "Variable" | "State" | "Action" | "Temporal";
|
|
386
400
|
set: Expression | undefined;
|
|
401
|
+
nameRange?: SourceRange;
|
|
387
402
|
location: SourceLocation;
|
|
388
403
|
}
|
|
389
404
|
|
|
@@ -435,19 +450,27 @@ export type StepBody =
|
|
|
435
450
|
| Instance
|
|
436
451
|
| DefineStep
|
|
437
452
|
| { kind: "Have"; expression: Expression }
|
|
438
|
-
| { kind: "Take"; names: string[]; bounds: Bound[] }
|
|
453
|
+
| { kind: "Take"; names: string[]; nameRanges?: SourceRange[]; bounds: Bound[] }
|
|
439
454
|
| { kind: "Witness"; expressions: Expression[] }
|
|
440
|
-
| {
|
|
455
|
+
| {
|
|
456
|
+
kind: "Pick";
|
|
457
|
+
names: string[];
|
|
458
|
+
nameRanges?: SourceRange[];
|
|
459
|
+
bounds: Bound[];
|
|
460
|
+
body: Expression;
|
|
461
|
+
}
|
|
441
462
|
| { kind: "Case"; expression: Expression }
|
|
442
463
|
| { kind: "Assert"; isSuffices: boolean; statement: Expression | AssumeProve }
|
|
443
464
|
| { kind: "Qed" };
|
|
444
465
|
|
|
445
|
-
// head is the range of the step number and its statement, without the proof
|
|
466
|
+
// head is the range of the step number and its statement, without the proof, and statement is the
|
|
467
|
+
// range of the statement alone.
|
|
446
468
|
export interface ProofStep {
|
|
447
469
|
name: string | undefined;
|
|
448
470
|
token: string;
|
|
449
471
|
body: StepBody;
|
|
450
472
|
head: SourceRange;
|
|
473
|
+
statement: SourceRange;
|
|
451
474
|
proof: Proof | undefined;
|
|
452
475
|
location: SourceLocation;
|
|
453
476
|
}
|
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
|
@@ -12,9 +12,11 @@ import { createEnvironment } from "./environment";
|
|
|
12
12
|
import {
|
|
13
13
|
getErrorExitCode,
|
|
14
14
|
isStackOverflow,
|
|
15
|
+
formatRange,
|
|
15
16
|
STACK_OVERFLOW,
|
|
16
17
|
TlaConfigError,
|
|
17
18
|
TlaEvaluationError,
|
|
19
|
+
TlaIllegalStateError,
|
|
18
20
|
TlaIncompleteStateError,
|
|
19
21
|
TlaModuleError,
|
|
20
22
|
UNEXPECTED_EXCEPTION,
|
|
@@ -24,7 +26,6 @@ import {
|
|
|
24
26
|
describeRange,
|
|
25
27
|
evaluate,
|
|
26
28
|
expectBoolean,
|
|
27
|
-
formatRange,
|
|
28
29
|
getDefinition,
|
|
29
30
|
isConstantLevel,
|
|
30
31
|
isImpure,
|
|
@@ -35,6 +36,7 @@ import {
|
|
|
35
36
|
import {
|
|
36
37
|
createLivenessChecker,
|
|
37
38
|
type Lasso,
|
|
39
|
+
type LiveGraph,
|
|
38
40
|
type LivenessChecker,
|
|
39
41
|
type LiveSuccessor,
|
|
40
42
|
} from "./live-check";
|
|
@@ -67,8 +69,10 @@ import { createTlcFingerprinter, getTlcFingerprint } from "./tlc-random";
|
|
|
67
69
|
import { createCanonicalizer } from "./canonical";
|
|
68
70
|
import { getPossibleCounts, type CheckerRuntime } from "./runtime";
|
|
69
71
|
import { createCounterExample } from "./tlc-ext";
|
|
72
|
+
import { getFingerprintTrace, valueSources } from "./value-sources";
|
|
70
73
|
import { getFingerprintDistance, OUT_DEGREE_BUCKETS } from "./tlc-summary";
|
|
71
74
|
import {
|
|
75
|
+
assertFingerprintable,
|
|
72
76
|
combineHash,
|
|
73
77
|
createModelValue,
|
|
74
78
|
formatState,
|
|
@@ -140,6 +144,25 @@ export interface EvaluationFailure {
|
|
|
140
144
|
trace: TraceStep[];
|
|
141
145
|
initialState: Record<string, Value> | undefined;
|
|
142
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;
|
|
143
166
|
}
|
|
144
167
|
|
|
145
168
|
export interface CheckResult {
|
|
@@ -835,11 +858,17 @@ export const createSearch = (
|
|
|
835
858
|
}
|
|
836
859
|
}),
|
|
837
860
|
satisfiesConstraints: (state, parent) =>
|
|
838
|
-
constraints.every(
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
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
|
+
}),
|
|
843
872
|
findFailedInitialPredicate: (state) =>
|
|
844
873
|
properties.initialPredicates.find(
|
|
845
874
|
(predicate) =>
|
|
@@ -872,13 +901,13 @@ export const createSearch = (
|
|
|
872
901
|
}
|
|
873
902
|
}),
|
|
874
903
|
satisfiesActionConstraints: (state, next) =>
|
|
875
|
-
actionConstraints.every((constraint) =>
|
|
876
|
-
|
|
877
|
-
constraint.expression,
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
),
|
|
904
|
+
actionConstraints.every((constraint) => {
|
|
905
|
+
try {
|
|
906
|
+
return holdsLikeTlc(constraint.expression, getContext(environment, state, next));
|
|
907
|
+
} catch (error) {
|
|
908
|
+
throw toNextStateError(error);
|
|
909
|
+
}
|
|
910
|
+
}),
|
|
882
911
|
trackStatePossible:
|
|
883
912
|
statePossible.length === 0
|
|
884
913
|
? ignorePossible
|
|
@@ -909,8 +938,8 @@ export const createSearch = (
|
|
|
909
938
|
const withNextStateExitCode = (error: unknown) =>
|
|
910
939
|
error instanceof TlaModuleError ? setExitCode(error, error.exitCode) : error;
|
|
911
940
|
|
|
912
|
-
// TLC reports a failure of the next-state relation
|
|
913
|
-
// 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.
|
|
914
943
|
const toNextStateError = (error: unknown) =>
|
|
915
944
|
error instanceof TlaEvaluationError &&
|
|
916
945
|
!(error instanceof TlaModuleError) &&
|
|
@@ -921,6 +950,47 @@ const toNextStateError = (error: unknown) =>
|
|
|
921
950
|
)
|
|
922
951
|
: withNextStateExitCode(error);
|
|
923
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
|
+
|
|
924
994
|
const withHeadline = (error: unknown, headline: string) =>
|
|
925
995
|
error instanceof TlaEvaluationError
|
|
926
996
|
? setExitCode(
|
|
@@ -949,9 +1019,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
949
1019
|
const onPrint = options.onPrint ?? console.log;
|
|
950
1020
|
// TLC prints again while it rebuilds a trace, between the states it prints. Printing those lines
|
|
951
1021
|
// before the trace would misplace them, so rebuilding a trace prints nothing.
|
|
952
|
-
const output = { isMuted: false };
|
|
1022
|
+
const output = { isMuted: false, replayed: undefined as string[] | undefined };
|
|
953
1023
|
const print = (text: string) => {
|
|
954
|
-
if (
|
|
1024
|
+
if (output.replayed) output.replayed.push(text);
|
|
1025
|
+
else if (!output.isMuted) onPrint(text);
|
|
955
1026
|
};
|
|
956
1027
|
const withoutOutput = <Result>(rebuild: () => Result) => {
|
|
957
1028
|
output.isMuted = true;
|
|
@@ -1013,9 +1084,9 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1013
1084
|
),
|
|
1014
1085
|
});
|
|
1015
1086
|
|
|
1016
|
-
const
|
|
1017
|
-
getTlcDeclarationOrder(options.source, options.loadModule, "variable")
|
|
1018
|
-
);
|
|
1087
|
+
const getVariableOrder = () =>
|
|
1088
|
+
getTlcDeclarationOrder(options.source, options.loadModule, "variable");
|
|
1089
|
+
const search = createSearch(config, environment, getVariableOrder);
|
|
1019
1090
|
const assumptionViolation = findAssumptionViolation(specification.assumptions, environment);
|
|
1020
1091
|
if (assumptionViolation) return createResult("assumption-violation", assumptionViolation);
|
|
1021
1092
|
if (!search) return createSuccess();
|
|
@@ -1039,37 +1110,114 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1039
1110
|
const spec = search.spec;
|
|
1040
1111
|
const getFingerprintState = search.getFingerprintState;
|
|
1041
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
|
+
});
|
|
1042
1191
|
const isReducing = config.view !== undefined || config.symmetry !== undefined;
|
|
1043
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
|
+
};
|
|
1044
1219
|
const liveness = withLivenessExitCode(() =>
|
|
1045
|
-
createLivenessChecker(search.properties.liveness, spec.temporals, environment,
|
|
1046
|
-
getFingerprint: (index) =>
|
|
1047
|
-
(tlcFingerprints[index] ??= Number(
|
|
1048
|
-
BigInt.asIntN(32, runtime.getFingerprint(states[index])),
|
|
1049
|
-
)),
|
|
1050
|
-
getSuccessors: (state) => {
|
|
1051
|
-
const successors: LiveSuccessor[] = [];
|
|
1052
|
-
if (spec.next === undefined) return successors;
|
|
1053
|
-
forEachSuccessor(
|
|
1054
|
-
spec.next,
|
|
1055
|
-
state,
|
|
1056
|
-
environment,
|
|
1057
|
-
(successor) => {
|
|
1058
|
-
canonicalizeState(successor.state);
|
|
1059
|
-
const isInModel =
|
|
1060
|
-
search.satisfiesConstraints(successor.state, state) &&
|
|
1061
|
-
search.satisfiesActionConstraints(state, successor.state);
|
|
1062
|
-
if (!isInModel) return false;
|
|
1063
|
-
const fingerprintState = getFingerprintState(successor.state);
|
|
1064
|
-
const index = findStateIndex(getStateHash(fingerprintState), fingerprintState);
|
|
1065
|
-
successors.push({ index, state: successor.state });
|
|
1066
|
-
return false;
|
|
1067
|
-
},
|
|
1068
|
-
spec.scope,
|
|
1069
|
-
);
|
|
1070
|
-
return successors;
|
|
1071
|
-
},
|
|
1072
|
-
}),
|
|
1220
|
+
createLivenessChecker(search.properties.liveness, spec.temporals, environment, liveGraph),
|
|
1073
1221
|
);
|
|
1074
1222
|
const isCanonicalizedFirst = search.isSymmetric || liveness !== undefined;
|
|
1075
1223
|
|
|
@@ -1242,6 +1390,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1242
1390
|
let hash = 0x811c9dc5;
|
|
1243
1391
|
for (let index = 0; index < state.length; index++)
|
|
1244
1392
|
hash = combineHash(hash, getValueHash(state[index]));
|
|
1393
|
+
assertFingerprintable(state);
|
|
1245
1394
|
return hash & 0x3fffffff;
|
|
1246
1395
|
};
|
|
1247
1396
|
const isSameState = (stored: Value[], state: Value[]) => {
|
|
@@ -1304,6 +1453,7 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1304
1453
|
isExpanding: false,
|
|
1305
1454
|
candidate: undefined as Value[] | undefined,
|
|
1306
1455
|
candidateLevel: 0,
|
|
1456
|
+
isFingerprinting: false,
|
|
1307
1457
|
livenessSource: -1,
|
|
1308
1458
|
};
|
|
1309
1459
|
const getPath = (index: number): Value[][] =>
|
|
@@ -1390,8 +1540,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1390
1540
|
current.candidate = successor.state;
|
|
1391
1541
|
current.candidateLevel = depths[index] + 1;
|
|
1392
1542
|
if (isCanonicalizedFirst) canonicalizeState(successor.state);
|
|
1543
|
+
current.isFingerprinting = true;
|
|
1393
1544
|
const fingerprintState = getFingerprintState(successor.state);
|
|
1394
1545
|
const hash = getStateHash(fingerprintState);
|
|
1546
|
+
current.isFingerprinting = false;
|
|
1395
1547
|
const found = findStateIndex(hash, fingerprintState);
|
|
1396
1548
|
const isStateInModel = search.satisfiesConstraints(successor.state, state);
|
|
1397
1549
|
if (isStateInModel) search.trackStatePossible(successor.state);
|
|
@@ -1463,10 +1615,22 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1463
1615
|
spec.scope,
|
|
1464
1616
|
);
|
|
1465
1617
|
} catch (error) {
|
|
1466
|
-
|
|
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
|
+
};
|
|
1467
1631
|
}
|
|
1468
1632
|
}
|
|
1469
|
-
if (outcome.result) return outcome.result;
|
|
1633
|
+
if (outcome.result) return replayInitialStates(outcome.result);
|
|
1470
1634
|
|
|
1471
1635
|
const next = spec.next;
|
|
1472
1636
|
if (next === undefined) {
|
|
@@ -1522,7 +1686,10 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1522
1686
|
try {
|
|
1523
1687
|
outcome.result = visitSuccessor(index, successor, liveSuccessors, source, action);
|
|
1524
1688
|
} catch (error) {
|
|
1525
|
-
|
|
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);
|
|
1526
1693
|
}
|
|
1527
1694
|
return outcome.result !== undefined;
|
|
1528
1695
|
});
|
|
@@ -1545,7 +1712,17 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1545
1712
|
trace: toTrace(steps, accepted),
|
|
1546
1713
|
});
|
|
1547
1714
|
} catch (error) {
|
|
1548
|
-
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
|
+
);
|
|
1549
1726
|
}
|
|
1550
1727
|
};
|
|
1551
1728
|
// TLC names the action when the next-state relation has more than one, and prints the
|
|
@@ -1618,10 +1795,14 @@ const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefine
|
|
|
1618
1795
|
try {
|
|
1619
1796
|
outcome.result = expandState(index);
|
|
1620
1797
|
} catch (error) {
|
|
1621
|
-
|
|
1798
|
+
const failure =
|
|
1622
1799
|
error instanceof TlaIncompleteStateError
|
|
1623
1800
|
? reportIncompleteSuccessor(error, index)
|
|
1624
1801
|
: toFailure(toNextStateError(error), getStateTrace(index));
|
|
1802
|
+
outcome.result =
|
|
1803
|
+
error instanceof TlaIncompleteStateError || isStackOverflow(error)
|
|
1804
|
+
? failure
|
|
1805
|
+
: replaySuccessors(failure, index);
|
|
1625
1806
|
}
|
|
1626
1807
|
if (outcome.result) return outcome.result;
|
|
1627
1808
|
outDegrees[getOutDegreeBucket()]++;
|