tla-ts 0.0.3-dev.fb38eba → 0.0.3-dev.fd18eec
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/README.md +5 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +40 -22
- package/dist/index.d.ts +40 -22
- 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 +6 -5
- package/dist/run-cli.js +7 -6
- package/dist/transfer.cjs +34 -17
- package/dist/transfer.js +34 -17
- package/package.json +1 -1
- package/src/ast.ts +2 -0
- package/src/check.ts +250 -58
- package/src/cli-options.ts +11 -5
- package/src/codegen.ts +6 -3
- package/src/config.ts +224 -170
- package/src/environment.ts +106 -18
- package/src/errors.ts +56 -1
- package/src/evaluate.ts +53 -19
- package/src/exit-codes.ts +22 -3
- package/src/instances.ts +3 -3
- package/src/live-check.ts +132 -70
- package/src/liveness.ts +113 -22
- package/src/parallel-worker.ts +2 -2
- package/src/parallel.ts +5 -2
- package/src/parser.ts +17 -9
- package/src/resolve.ts +45 -15
- package/src/run-cli.ts +65 -18
- package/src/runtime.ts +2 -0
- package/src/spec-description.ts +12 -6
- package/src/standard-modules.ts +2 -7
- package/src/state-graph.ts +157 -0
- package/src/successors.ts +84 -18
- package/src/symmetry.ts +16 -6
- package/src/tableau.ts +51 -24
- package/src/tlc-module.ts +11 -5
- package/src/tlc-modules.ts +4 -0
- package/src/tlc-order.ts +8 -4
- package/src/tlc-random.ts +9 -6
- package/src/tlc-summary.ts +20 -5
- package/src/values.ts +121 -20
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
|
}
|
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
|
+
TlaIncompleteStateError,
|
|
16
20
|
TlaModuleError,
|
|
17
21
|
UNEXPECTED_EXCEPTION,
|
|
18
22
|
} from "./errors";
|
|
@@ -21,7 +25,6 @@ import {
|
|
|
21
25
|
describeRange,
|
|
22
26
|
evaluate,
|
|
23
27
|
expectBoolean,
|
|
24
|
-
formatRange,
|
|
25
28
|
getDefinition,
|
|
26
29
|
isConstantLevel,
|
|
27
30
|
isImpure,
|
|
@@ -47,12 +50,19 @@ import {
|
|
|
47
50
|
} from "./successors";
|
|
48
51
|
import {
|
|
49
52
|
getActionLabel,
|
|
53
|
+
getActionSignature,
|
|
50
54
|
getNextActions,
|
|
51
55
|
getSpecificationValue,
|
|
52
56
|
type SpecAction,
|
|
53
57
|
} from "./spec-description";
|
|
58
|
+
import {
|
|
59
|
+
createStateWriter,
|
|
60
|
+
type GraphState,
|
|
61
|
+
type StateDump,
|
|
62
|
+
type StateWriter,
|
|
63
|
+
} from "./state-graph";
|
|
54
64
|
import { getRepresentative, getSymmetryGroup } from "./symmetry";
|
|
55
|
-
import { getTlcStringOrder,
|
|
65
|
+
import { getTlcStringOrder, getTlcDeclarationOrder } from "./tlc-order";
|
|
56
66
|
import { createTlcFingerprinter, getTlcFingerprint } from "./tlc-random";
|
|
57
67
|
import { createCanonicalizer } from "./canonical";
|
|
58
68
|
import { getPossibleCounts, type CheckerRuntime } from "./runtime";
|
|
@@ -60,6 +70,8 @@ import { createCounterExample } from "./tlc-ext";
|
|
|
60
70
|
import { getFingerprintDistance, OUT_DEGREE_BUCKETS } from "./tlc-summary";
|
|
61
71
|
import {
|
|
62
72
|
combineHash,
|
|
73
|
+
createModelValue,
|
|
74
|
+
formatState,
|
|
63
75
|
formatValue,
|
|
64
76
|
getValueHash,
|
|
65
77
|
isFunctionValue,
|
|
@@ -83,6 +95,8 @@ export interface CheckOptions {
|
|
|
83
95
|
workers?: number;
|
|
84
96
|
// TLC's -lncheck: "final" checks liveness only on the complete state graph.
|
|
85
97
|
livenessCheck?: "default" | "final";
|
|
98
|
+
// TLC's -dump: writes the reachable states, or with `dot` the state graph, through writeFile.
|
|
99
|
+
dump?: StateDump;
|
|
86
100
|
}
|
|
87
101
|
|
|
88
102
|
export type CheckStatus =
|
|
@@ -237,7 +251,7 @@ const getConstantValue = (name: string, definition: Definition, environment: Env
|
|
|
237
251
|
try {
|
|
238
252
|
return evaluate(createIdentifier(name), getContext(environment, undefined, undefined));
|
|
239
253
|
} catch (error) {
|
|
240
|
-
if (error instanceof TlaEvaluationError) return undefined;
|
|
254
|
+
if (error instanceof TlaEvaluationError || isStackOverflow(error)) return undefined;
|
|
241
255
|
throw error;
|
|
242
256
|
}
|
|
243
257
|
};
|
|
@@ -266,8 +280,11 @@ const getInvariants = (names: string[], environment: Environment) => {
|
|
|
266
280
|
levels.params.size === 0
|
|
267
281
|
? ""
|
|
268
282
|
: "\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.";
|
|
269
|
-
throw
|
|
270
|
-
|
|
283
|
+
throw setExitCode(
|
|
284
|
+
new TlaConfigError(
|
|
285
|
+
`The invariant ${name} is not a state predicate (one with no primes or temporal operators).${note}`,
|
|
286
|
+
),
|
|
287
|
+
EXIT_STATUS.safetyEvaluationFailure,
|
|
271
288
|
);
|
|
272
289
|
}
|
|
273
290
|
return [{ name, expression: createIdentifier(name), scope: undefined }];
|
|
@@ -365,8 +382,11 @@ const getSpecification = (config: ModelConfig, environment: Environment): Specif
|
|
|
365
382
|
conjunct.kind === "Always" &&
|
|
366
383
|
getLevel(conjunct.expression, item.scope, environment) < ACTION_LEVEL
|
|
367
384
|
) {
|
|
368
|
-
throw
|
|
369
|
-
|
|
385
|
+
throw setExitCode(
|
|
386
|
+
new TlaConfigError(
|
|
387
|
+
`TLC cannot handle the temporal formula ${describeRange(conjunct.expression)}`,
|
|
388
|
+
),
|
|
389
|
+
EXIT_STATUS.error,
|
|
370
390
|
);
|
|
371
391
|
}
|
|
372
392
|
const level = getLevel(conjunct, item.scope, environment);
|
|
@@ -436,12 +456,12 @@ const getProperties = (config: ModelConfig, environment: Environment): Propertie
|
|
|
436
456
|
config.properties.forEach((name) => {
|
|
437
457
|
const definition = getConfigPredicate("property", name, environment);
|
|
438
458
|
if (!definition) return;
|
|
439
|
-
expandTemporal(definition.body, undefined, environment, true).forEach((item) => {
|
|
459
|
+
expandTemporal(definition.body, undefined, environment, true, name).forEach((item) => {
|
|
440
460
|
const conjunct = item.expression;
|
|
441
461
|
if (isConstantTrue(item, environment, "property")) return;
|
|
442
462
|
if (conjunct.kind === "Always" && conjunct.expression.kind === "BoxAction") {
|
|
443
463
|
properties.actionProperties.push({
|
|
444
|
-
name,
|
|
464
|
+
name: item.name,
|
|
445
465
|
box: conjunct.expression,
|
|
446
466
|
action: conjunct.expression.action,
|
|
447
467
|
subscript: conjunct.expression.subscript,
|
|
@@ -453,12 +473,22 @@ const getProperties = (config: ModelConfig, environment: Environment): Propertie
|
|
|
453
473
|
conjunct.kind === "Always" &&
|
|
454
474
|
getLevel(conjunct.expression, item.scope, environment) <= 1
|
|
455
475
|
) {
|
|
456
|
-
|
|
476
|
+
// TLC names the invariant []P after P when P is an operator name.
|
|
477
|
+
const expression = conjunct.expression;
|
|
478
|
+
properties.invariants.push({
|
|
479
|
+
name: expression.kind === "Identifier" ? expression.name : item.name,
|
|
480
|
+
expression,
|
|
481
|
+
scope: item.scope,
|
|
482
|
+
});
|
|
457
483
|
return;
|
|
458
484
|
}
|
|
459
485
|
const level = getLevel(conjunct, item.scope, environment);
|
|
460
486
|
if (level < ACTION_LEVEL) {
|
|
461
|
-
properties.initialPredicates.push({
|
|
487
|
+
properties.initialPredicates.push({
|
|
488
|
+
name: item.name,
|
|
489
|
+
expression: conjunct,
|
|
490
|
+
scope: item.scope,
|
|
491
|
+
});
|
|
462
492
|
return;
|
|
463
493
|
}
|
|
464
494
|
if (level === ACTION_LEVEL) {
|
|
@@ -518,7 +548,9 @@ const getMembership = (
|
|
|
518
548
|
const getStateChecks = (named: NamedExpression[], environment: Environment): StateCheck[] =>
|
|
519
549
|
named.flatMap((item) =>
|
|
520
550
|
getConjuncts(item.expression, environment).map((expression) => {
|
|
521
|
-
|
|
551
|
+
// A LET or an argument in the scope can read variables the expression doesn't name.
|
|
552
|
+
const variables =
|
|
553
|
+
item.scope === undefined ? getReadVariables(expression, environment) : undefined;
|
|
522
554
|
return {
|
|
523
555
|
name: item.name,
|
|
524
556
|
expression,
|
|
@@ -765,11 +797,13 @@ export const createSearch = (
|
|
|
765
797
|
if (view !== undefined || isFingerprintedLikeTlc) {
|
|
766
798
|
return BigInt64Array.from(states, getTlcStateFingerprint);
|
|
767
799
|
}
|
|
768
|
-
const
|
|
769
|
-
const
|
|
770
|
-
|
|
771
|
-
|
|
800
|
+
const fingerprints = new BigInt64Array(fingerprintStates.length);
|
|
801
|
+
const fingerprint = createTlcFingerprinter(
|
|
802
|
+
getTlcOrder(),
|
|
803
|
+
new Int32Array(fingerprints.buffer),
|
|
772
804
|
);
|
|
805
|
+
fingerprintStates.forEach(fingerprint);
|
|
806
|
+
return fingerprints;
|
|
773
807
|
},
|
|
774
808
|
getFingerprintState: (state) => {
|
|
775
809
|
if (isFingerprintedLikeTlc) return [String(getTlcStateFingerprint(state))];
|
|
@@ -801,11 +835,17 @@ export const createSearch = (
|
|
|
801
835
|
}
|
|
802
836
|
}),
|
|
803
837
|
satisfiesConstraints: (state, parent) =>
|
|
804
|
-
constraints.every(
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
838
|
+
constraints.every((constraint) => {
|
|
839
|
+
try {
|
|
840
|
+
return (
|
|
841
|
+
isUnchangedFor(constraint, state, parent) ||
|
|
842
|
+
holdsLikeTlc(constraint.expression, getContext(environment, state, undefined))
|
|
843
|
+
);
|
|
844
|
+
} catch (error) {
|
|
845
|
+
// TLC reports a failing constraint on a successor like a failure of the next-state relation.
|
|
846
|
+
throw parent ? toNextStateError(error) : error;
|
|
847
|
+
}
|
|
848
|
+
}),
|
|
809
849
|
findFailedInitialPredicate: (state) =>
|
|
810
850
|
properties.initialPredicates.find(
|
|
811
851
|
(predicate) =>
|
|
@@ -838,13 +878,13 @@ export const createSearch = (
|
|
|
838
878
|
}
|
|
839
879
|
}),
|
|
840
880
|
satisfiesActionConstraints: (state, next) =>
|
|
841
|
-
actionConstraints.every((constraint) =>
|
|
842
|
-
|
|
843
|
-
constraint.expression,
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
),
|
|
881
|
+
actionConstraints.every((constraint) => {
|
|
882
|
+
try {
|
|
883
|
+
return holdsLikeTlc(constraint.expression, getContext(environment, state, next));
|
|
884
|
+
} catch (error) {
|
|
885
|
+
throw toNextStateError(error);
|
|
886
|
+
}
|
|
887
|
+
}),
|
|
848
888
|
trackStatePossible:
|
|
849
889
|
statePossible.length === 0
|
|
850
890
|
? ignorePossible
|
|
@@ -875,6 +915,18 @@ export const createSearch = (
|
|
|
875
915
|
const withNextStateExitCode = (error: unknown) =>
|
|
876
916
|
error instanceof TlaModuleError ? setExitCode(error, error.exitCode) : error;
|
|
877
917
|
|
|
918
|
+
// TLC reports a failure of the next-state relation as an unexpected exception, unless a standard
|
|
919
|
+
// module raised it as an EvalException.
|
|
920
|
+
const toNextStateError = (error: unknown) =>
|
|
921
|
+
error instanceof TlaEvaluationError &&
|
|
922
|
+
!(error instanceof TlaModuleError) &&
|
|
923
|
+
!(error instanceof TlaIncompleteStateError)
|
|
924
|
+
? setExitCode(
|
|
925
|
+
new TlaEvaluationError(`${UNEXPECTED_EXCEPTION}${error.message}`, error),
|
|
926
|
+
getErrorExitCode(error),
|
|
927
|
+
)
|
|
928
|
+
: withNextStateExitCode(error);
|
|
929
|
+
|
|
878
930
|
const withHeadline = (error: unknown, headline: string) =>
|
|
879
931
|
error instanceof TlaEvaluationError
|
|
880
932
|
? setExitCode(
|
|
@@ -883,7 +935,22 @@ const withHeadline = (error: unknown, headline: string) =>
|
|
|
883
935
|
)
|
|
884
936
|
: error;
|
|
885
937
|
|
|
938
|
+
// TLC finishes the -dump file whether or not the search finds a violation.
|
|
886
939
|
export const checkSequentially = (options: CheckOptions): CheckResult => {
|
|
940
|
+
const stateWriter = options.dump && createStateWriter(options.dump, options.writeFile);
|
|
941
|
+
try {
|
|
942
|
+
return searchStates(options, stateWriter);
|
|
943
|
+
} catch (error) {
|
|
944
|
+
// TLC reports a stack overflow outside the search as a failure of its own, with exit code 255.
|
|
945
|
+
throw isStackOverflow(error)
|
|
946
|
+
? setExitCode(new TlaEvaluationError(STACK_OVERFLOW), EXIT_STATUS.error)
|
|
947
|
+
: error;
|
|
948
|
+
} finally {
|
|
949
|
+
stateWriter?.close();
|
|
950
|
+
}
|
|
951
|
+
};
|
|
952
|
+
|
|
953
|
+
const searchStates = (options: CheckOptions, stateWriter: StateWriter | undefined): CheckResult => {
|
|
887
954
|
const config = typeof options.config === "string" ? parseConfig(options.config) : options.config;
|
|
888
955
|
const onPrint = options.onPrint ?? console.log;
|
|
889
956
|
// TLC prints again while it rebuilds a trace, between the states it prints. Printing those lines
|
|
@@ -953,7 +1020,7 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
|
|
|
953
1020
|
});
|
|
954
1021
|
|
|
955
1022
|
const search = createSearch(config, environment, () =>
|
|
956
|
-
|
|
1023
|
+
getTlcDeclarationOrder(options.source, options.loadModule, "variable"),
|
|
957
1024
|
);
|
|
958
1025
|
const assumptionViolation = findAssumptionViolation(specification.assumptions, environment);
|
|
959
1026
|
if (assumptionViolation) return createResult("assumption-violation", assumptionViolation);
|
|
@@ -1017,7 +1084,9 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
|
|
|
1017
1084
|
const parents: number[] = [];
|
|
1018
1085
|
const actions: (string | undefined)[] = [];
|
|
1019
1086
|
const depths: number[] = [];
|
|
1020
|
-
|
|
1087
|
+
// A Map holds at most 2^24 entries, so an open-addressing table keeps each seen state's hash
|
|
1088
|
+
// and its index plus one side by side, probed by the hash.
|
|
1089
|
+
const seen = { slots: new Int32Array(1 << 17), size: 0, shift: 16 };
|
|
1021
1090
|
const canonicalizeState = createCanonicalizer();
|
|
1022
1091
|
|
|
1023
1092
|
const toRecord = (state: Value[]): Record<string, Value> =>
|
|
@@ -1030,11 +1099,16 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
|
|
|
1030
1099
|
position: number,
|
|
1031
1100
|
loopStart: number | undefined,
|
|
1032
1101
|
) => {
|
|
1033
|
-
const state = steps[position].state;
|
|
1034
|
-
const next = (steps[position + 1] ?? steps[loopStart ?? position]).state;
|
|
1035
1102
|
// TLC evaluates TLCGet("level") and Trace in an alias at the state's position in the trace.
|
|
1036
1103
|
runtime.getLevel = () => position + 1;
|
|
1037
1104
|
runtime.getBehavior = () => steps.slice(0, position + 1).map((step) => step.state);
|
|
1105
|
+
return evaluateAlias(
|
|
1106
|
+
alias,
|
|
1107
|
+
steps[position].state,
|
|
1108
|
+
(steps[position + 1] ?? steps[loopStart ?? position]).state,
|
|
1109
|
+
);
|
|
1110
|
+
};
|
|
1111
|
+
const evaluateAlias = (alias: string, state: Value[], next: Value[] | undefined) => {
|
|
1038
1112
|
try {
|
|
1039
1113
|
const body = getConfigDefinition("alias", alias, environment).body;
|
|
1040
1114
|
const value = evaluate(createIdentifier(alias), getContext(environment, state, next));
|
|
@@ -1136,7 +1210,17 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
|
|
|
1136
1210
|
trace: TraceStep[],
|
|
1137
1211
|
initialState?: Value[],
|
|
1138
1212
|
failureOutDegrees?: number[],
|
|
1139
|
-
) => {
|
|
1213
|
+
): CheckResult => {
|
|
1214
|
+
// TLC exits with 255 on a stack overflow while it computes next states, and prints the
|
|
1215
|
+
// behavior up to the state it was expanding.
|
|
1216
|
+
if (isStackOverflow(error)) {
|
|
1217
|
+
return current.isExpanding
|
|
1218
|
+
? toFailure(
|
|
1219
|
+
setExitCode(new TlaEvaluationError(STACK_OVERFLOW), EXIT_STATUS.error),
|
|
1220
|
+
getStateTrace(current.index),
|
|
1221
|
+
)
|
|
1222
|
+
: toFailure(new TlaEvaluationError(STACK_OVERFLOW), trace, initialState);
|
|
1223
|
+
}
|
|
1140
1224
|
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
1141
1225
|
return {
|
|
1142
1226
|
...createResult("error", undefined, {
|
|
@@ -1172,19 +1256,35 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
|
|
|
1172
1256
|
}
|
|
1173
1257
|
return true;
|
|
1174
1258
|
};
|
|
1259
|
+
const getSlot = (hash: number) => (Math.imul(hash, 0x9e3779b1) >>> seen.shift) << 1;
|
|
1175
1260
|
const findStateIndex = (hash: number, state: Value[]) => {
|
|
1176
|
-
const
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1261
|
+
const mask = seen.slots.length - 1;
|
|
1262
|
+
for (let slot = getSlot(hash); ; slot = (slot + 2) & mask) {
|
|
1263
|
+
const entry = seen.slots[slot + 1];
|
|
1264
|
+
if (entry === 0) return -1;
|
|
1265
|
+
if (seen.slots[slot] === hash && isSameState(fingerprintStates[entry - 1], state)) {
|
|
1266
|
+
return entry - 1;
|
|
1267
|
+
}
|
|
1180
1268
|
}
|
|
1181
|
-
|
|
1269
|
+
};
|
|
1270
|
+
const insertSeen = (hash: number, entry: number) => {
|
|
1271
|
+
const mask = seen.slots.length - 1;
|
|
1272
|
+
let slot = getSlot(hash);
|
|
1273
|
+
while (seen.slots[slot + 1] !== 0) slot = (slot + 2) & mask;
|
|
1274
|
+
seen.slots[slot] = hash;
|
|
1275
|
+
seen.slots[slot + 1] = entry;
|
|
1182
1276
|
};
|
|
1183
1277
|
const markSeen = (hash: number, index: number) => {
|
|
1184
|
-
|
|
1185
|
-
if (
|
|
1186
|
-
|
|
1187
|
-
|
|
1278
|
+
seen.size++;
|
|
1279
|
+
if (seen.size * 4 > seen.slots.length) {
|
|
1280
|
+
const slots = seen.slots;
|
|
1281
|
+
seen.slots = new Int32Array(slots.length * 2);
|
|
1282
|
+
seen.shift--;
|
|
1283
|
+
for (let slot = 0; slot < slots.length; slot += 2) {
|
|
1284
|
+
if (slots[slot + 1] !== 0) insertSeen(slots[slot], slots[slot + 1]);
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
insertSeen(hash, index + 1);
|
|
1188
1288
|
};
|
|
1189
1289
|
const countDistinctState = (depth: number) => {
|
|
1190
1290
|
runtime.distinctStates = states.length + 1;
|
|
@@ -1210,6 +1310,7 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
|
|
|
1210
1310
|
isExpanding: false,
|
|
1211
1311
|
candidate: undefined as Value[] | undefined,
|
|
1212
1312
|
candidateLevel: 0,
|
|
1313
|
+
isFingerprinting: false,
|
|
1213
1314
|
livenessSource: -1,
|
|
1214
1315
|
};
|
|
1215
1316
|
const getPath = (index: number): Value[][] =>
|
|
@@ -1235,6 +1336,18 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
|
|
|
1235
1336
|
return current.isExpanding ? depths[current.index] + 1 : 0;
|
|
1236
1337
|
};
|
|
1237
1338
|
|
|
1339
|
+
const getGraphState = (state: Value[], level: number): GraphState => ({
|
|
1340
|
+
fingerprint: BigInt.asIntN(64, runtime.getFingerprint(state)),
|
|
1341
|
+
level,
|
|
1342
|
+
getLabel: () =>
|
|
1343
|
+
formatState(
|
|
1344
|
+
config.alias === undefined
|
|
1345
|
+
? toRecord(state)
|
|
1346
|
+
: evaluateAlias(config.alias, state, undefined),
|
|
1347
|
+
),
|
|
1348
|
+
getText: () => formatState(toRecord(state)),
|
|
1349
|
+
});
|
|
1350
|
+
|
|
1238
1351
|
const visitInitialState = (state: Value[]) => {
|
|
1239
1352
|
canonicalizeState(state);
|
|
1240
1353
|
runtime.generatedStates++;
|
|
@@ -1251,6 +1364,7 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
|
|
|
1251
1364
|
countDistinctState(1);
|
|
1252
1365
|
runtime.queueSize++;
|
|
1253
1366
|
liveness?.addInitialState(states.length, state);
|
|
1367
|
+
stateWriter?.writeInitialState(getGraphState(state, 1));
|
|
1254
1368
|
}
|
|
1255
1369
|
const violated = search.findViolatedInvariant(state);
|
|
1256
1370
|
if (violated) {
|
|
@@ -1271,20 +1385,36 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
|
|
|
1271
1385
|
addState(state, fingerprintState, -1, undefined);
|
|
1272
1386
|
return undefined;
|
|
1273
1387
|
};
|
|
1274
|
-
const visitSuccessor = (
|
|
1388
|
+
const visitSuccessor = (
|
|
1389
|
+
index: number,
|
|
1390
|
+
successor: Successor,
|
|
1391
|
+
liveSuccessors: LiveSuccessor[],
|
|
1392
|
+
source: GraphState | undefined,
|
|
1393
|
+
action: SpecAction | undefined,
|
|
1394
|
+
) => {
|
|
1275
1395
|
const state = states[index];
|
|
1276
1396
|
runtime.generatedStates++;
|
|
1277
1397
|
current.candidate = successor.state;
|
|
1278
1398
|
current.candidateLevel = depths[index] + 1;
|
|
1279
1399
|
if (isCanonicalizedFirst) canonicalizeState(successor.state);
|
|
1400
|
+
current.isFingerprinting = true;
|
|
1280
1401
|
const fingerprintState = getFingerprintState(successor.state);
|
|
1281
1402
|
const hash = getStateHash(fingerprintState);
|
|
1403
|
+
current.isFingerprinting = false;
|
|
1282
1404
|
const found = findStateIndex(hash, fingerprintState);
|
|
1283
1405
|
const isStateInModel = search.satisfiesConstraints(successor.state, state);
|
|
1284
1406
|
if (isStateInModel) search.trackStatePossible(successor.state);
|
|
1285
1407
|
const isInModel = isStateInModel && search.satisfiesActionConstraints(state, successor.state);
|
|
1286
1408
|
if (isInModel) search.trackActionPossible(state, successor.state);
|
|
1287
1409
|
const existing = isInModel ? found : -1;
|
|
1410
|
+
if (source && isInModel) {
|
|
1411
|
+
stateWriter?.writeSuccessor(
|
|
1412
|
+
source,
|
|
1413
|
+
getGraphState(successor.state, depths[index] + 1),
|
|
1414
|
+
existing !== -1,
|
|
1415
|
+
action && { name: action.name, signature: getActionSignature(action) },
|
|
1416
|
+
);
|
|
1417
|
+
}
|
|
1288
1418
|
if (existing !== -1 && liveness) {
|
|
1289
1419
|
const stored = states[existing];
|
|
1290
1420
|
const isStored = stored.every((value, position) => value === successor.state[position]);
|
|
@@ -1356,23 +1486,57 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
|
|
|
1356
1486
|
}
|
|
1357
1487
|
return createSuccess();
|
|
1358
1488
|
}
|
|
1489
|
+
// TLC labels and colors an edge of the -dump state graph by the action that generated it. When
|
|
1490
|
+
// the graph names its edges, the search generates successors action by action, as TLC does.
|
|
1491
|
+
const isNamingEdges = Boolean(
|
|
1492
|
+
options.dump?.dot && (options.dump.actionLabels || options.dump.colorize),
|
|
1493
|
+
);
|
|
1494
|
+
const forEachActionSuccessor = (
|
|
1495
|
+
state: Value[],
|
|
1496
|
+
onSuccessor: (successor: Successor, action: SpecAction | undefined) => boolean,
|
|
1497
|
+
) => {
|
|
1498
|
+
if (!isNamingEdges) {
|
|
1499
|
+
return forEachSuccessor(
|
|
1500
|
+
next,
|
|
1501
|
+
state,
|
|
1502
|
+
environment,
|
|
1503
|
+
(successor) => onSuccessor(successor, undefined),
|
|
1504
|
+
spec.scope,
|
|
1505
|
+
);
|
|
1506
|
+
}
|
|
1507
|
+
nextActions.value ??= getNextActions(config, environment, specification.instanceActions);
|
|
1508
|
+
const progress = { isStopped: false };
|
|
1509
|
+
return nextActions.value.reduce((count, action) => {
|
|
1510
|
+
if (progress.isStopped) return count;
|
|
1511
|
+
return (
|
|
1512
|
+
count +
|
|
1513
|
+
forEachSuccessor(
|
|
1514
|
+
action.expression,
|
|
1515
|
+
state,
|
|
1516
|
+
environment,
|
|
1517
|
+
(successor) => {
|
|
1518
|
+
progress.isStopped = onSuccessor(successor, action);
|
|
1519
|
+
return progress.isStopped;
|
|
1520
|
+
},
|
|
1521
|
+
action.scope,
|
|
1522
|
+
)
|
|
1523
|
+
);
|
|
1524
|
+
}, 0);
|
|
1525
|
+
};
|
|
1359
1526
|
const expandState = (index: number) => {
|
|
1360
1527
|
const state = states[index];
|
|
1361
1528
|
const liveSuccessors: LiveSuccessor[] = [];
|
|
1362
|
-
const
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
(
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
},
|
|
1374
|
-
spec.scope,
|
|
1375
|
-
);
|
|
1529
|
+
const source = stateWriter && getGraphState(state, depths[index]);
|
|
1530
|
+
const successorCount = forEachActionSuccessor(state, (successor, action) => {
|
|
1531
|
+
try {
|
|
1532
|
+
outcome.result = visitSuccessor(index, successor, liveSuccessors, source, action);
|
|
1533
|
+
} catch (error) {
|
|
1534
|
+
// TLC reports a successor it cannot fingerprint as a failure of the state it expands.
|
|
1535
|
+
if (current.isFingerprinting) throw error;
|
|
1536
|
+
outcome.result = toFailure(error, getTrace(index, successor));
|
|
1537
|
+
}
|
|
1538
|
+
return outcome.result !== undefined;
|
|
1539
|
+
});
|
|
1376
1540
|
current.isExpanding = false;
|
|
1377
1541
|
if (outcome.result) return outcome.result;
|
|
1378
1542
|
if (successorCount === 0 && config.checkDeadlock) {
|
|
@@ -1395,6 +1559,31 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
|
|
|
1395
1559
|
return toFailure(error, getStateTrace(index), undefined, getPartialOutDegrees());
|
|
1396
1560
|
}
|
|
1397
1561
|
};
|
|
1562
|
+
// TLC names the action when the next-state relation has more than one, and prints the
|
|
1563
|
+
// incomplete successor with null for each variable it leaves undefined.
|
|
1564
|
+
const reportIncompleteSuccessor = (error: TlaIncompleteStateError, index: number) => {
|
|
1565
|
+
nextActions.value ??= getNextActions(config, environment, specification.instanceActions);
|
|
1566
|
+
const actions = nextActions.value;
|
|
1567
|
+
const action =
|
|
1568
|
+
actions.length === 1 ? actions[0] : actions.find((item) => item.name === error.action);
|
|
1569
|
+
const variables = `variable${error.missing.length > 1 ? "s are" : " is"} not defined: ${error.missing.join(", ")}.\n`;
|
|
1570
|
+
runtime.generatedStates++;
|
|
1571
|
+
return toFailure(
|
|
1572
|
+
actions.length === 1
|
|
1573
|
+
? error
|
|
1574
|
+
: new TlaEvaluationError(
|
|
1575
|
+
`Successor state is not completely specified by action ${error.action} of the next-state relation. The following ${variables}`,
|
|
1576
|
+
),
|
|
1577
|
+
[
|
|
1578
|
+
...getStateTrace(index),
|
|
1579
|
+
{
|
|
1580
|
+
action: error.action,
|
|
1581
|
+
label: action && getActionLabel(action),
|
|
1582
|
+
state: toRecord(error.state.map((value) => value ?? createModelValue("null"))),
|
|
1583
|
+
},
|
|
1584
|
+
],
|
|
1585
|
+
);
|
|
1586
|
+
};
|
|
1398
1587
|
// TLC names the properties and the step back into the cycle from the states it prints.
|
|
1399
1588
|
const reportLasso = (checker: LivenessChecker, lasso: Lasso) => {
|
|
1400
1589
|
const path = [...lasso.prefix, ...lasso.cycle];
|
|
@@ -1440,7 +1629,10 @@ export const checkSequentially = (options: CheckOptions): CheckResult => {
|
|
|
1440
1629
|
try {
|
|
1441
1630
|
outcome.result = expandState(index);
|
|
1442
1631
|
} catch (error) {
|
|
1443
|
-
outcome.result =
|
|
1632
|
+
outcome.result =
|
|
1633
|
+
error instanceof TlaIncompleteStateError
|
|
1634
|
+
? reportIncompleteSuccessor(error, index)
|
|
1635
|
+
: toFailure(toNextStateError(error), getStateTrace(index));
|
|
1444
1636
|
}
|
|
1445
1637
|
if (outcome.result) return outcome.result;
|
|
1446
1638
|
outDegrees[getOutDegreeBucket()]++;
|
package/src/cli-options.ts
CHANGED
|
@@ -2,6 +2,8 @@ export interface OptionSpec {
|
|
|
2
2
|
flag: string;
|
|
3
3
|
isRequired?: boolean;
|
|
4
4
|
isRepeatable?: boolean;
|
|
5
|
+
// How many of the arguments after the flag the option takes, when that depends on them.
|
|
6
|
+
getArity?: (rest: string[]) => number;
|
|
5
7
|
}
|
|
6
8
|
|
|
7
9
|
export interface ParsedOption {
|
|
@@ -29,27 +31,31 @@ export const defineCommand = (usage: string, specs: OptionSpec[]) => {
|
|
|
29
31
|
const arities = new Map(
|
|
30
32
|
specs.map((spec) => {
|
|
31
33
|
const [name, ...values] = spec.flag.split(" ");
|
|
32
|
-
return [name, values.length];
|
|
34
|
+
return [name, spec.getArity ?? (() => values.length)];
|
|
33
35
|
}),
|
|
34
36
|
);
|
|
35
37
|
const parse = (args: string[]): ParsedArgs => {
|
|
36
38
|
const options: ParsedOption[] = [];
|
|
37
39
|
const positionals: string[] = [];
|
|
38
40
|
const unknown: string[] = [];
|
|
41
|
+
const incomplete: ParsedOption[] = [];
|
|
39
42
|
for (let index = 0; index < args.length; index++) {
|
|
40
|
-
const
|
|
41
|
-
if (
|
|
43
|
+
const getArity = arities.get(args[index]);
|
|
44
|
+
if (getArity === undefined) {
|
|
42
45
|
(args[index].startsWith("-") ? unknown : positionals).push(args[index]);
|
|
43
46
|
continue;
|
|
44
47
|
}
|
|
45
|
-
|
|
48
|
+
const arity = getArity(args.slice(index + 1));
|
|
49
|
+
const option = { name: args[index], values: args.slice(index + 1, index + 1 + arity) };
|
|
50
|
+
options.push(option);
|
|
51
|
+
if (option.values.length < arity) incomplete.push(option);
|
|
46
52
|
index += arity;
|
|
47
53
|
}
|
|
48
54
|
return {
|
|
49
55
|
options,
|
|
50
56
|
positionals,
|
|
51
57
|
unknown,
|
|
52
|
-
incomplete:
|
|
58
|
+
incomplete: incomplete[0],
|
|
53
59
|
has: (name) => options.some((option) => option.name === name),
|
|
54
60
|
get: (name) => options.findLast((option) => option.name === name)?.values,
|
|
55
61
|
};
|
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);
|