tla-ts 0.0.10-dev.b4a856304 → 0.0.10-dev.f16792fed
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 +34 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +48 -48
- package/dist/prove.js +29 -29
- package/dist/run.cjs +40 -40
- package/dist/run.js +31 -31
- package/dist/transfer.cjs +36 -36
- package/dist/transfer.js +40 -40
- package/package.json +1 -1
- package/src/ast.ts +0 -5
- package/src/bags.ts +2 -5
- package/src/builtins.ts +1 -8
- package/src/check.ts +128 -193
- package/src/cli/options.ts +1 -1
- package/src/cli/run.ts +0 -2
- package/src/cli/runtime-invariants.ts +8 -7
- package/src/cli/shared.ts +0 -4
- package/src/cli/tlc-arguments.ts +24 -30
- package/src/cli/tlc-usage.ts +2 -3
- package/src/coverage.ts +3 -8
- package/src/evaluate.ts +26 -102
- package/src/java-hash.ts +7 -0
- package/src/java-overrides.ts +4 -9
- package/src/json-reader.ts +1 -2
- package/src/json.ts +4 -11
- package/src/levels.ts +7 -15
- package/src/lexer.ts +72 -83
- package/src/liveness-checker.ts +77 -106
- package/src/liveness.ts +10 -34
- package/src/parallel.ts +26 -33
- package/src/parser.ts +163 -226
- package/src/pcal/ast.ts +53 -65
- package/src/pcal/parse.ts +144 -191
- package/src/pcal/tokenize.ts +91 -115
- package/src/pcal/translate.ts +83 -98
- package/src/pcal/validate.ts +48 -50
- package/src/pretty-print.ts +6 -6
- package/src/randomization.ts +1 -4
- package/src/resolve.ts +12 -70
- package/src/runtime.ts +11 -18
- package/src/sany/builtins.ts +1 -3
- package/src/sany/generator.ts +74 -127
- package/src/sany/levels.ts +5 -9
- package/src/sany/lexer.ts +40 -44
- package/src/sany/linter.ts +0 -1
- package/src/sany/nodes.ts +4 -10
- package/src/search.ts +1 -1
- package/src/simulate.ts +50 -59
- package/src/spec-description.ts +23 -34
- package/src/standard-definitions.ts +0 -3
- package/src/standard-modules.ts +1 -12
- package/src/state-graph.ts +3 -15
- package/src/subexpressions.ts +38 -47
- package/src/successors.ts +14 -35
- package/src/symmetry.ts +4 -19
- package/src/tlc/fingerprint.ts +15 -21
- package/src/tlc/jar-data.ts +0 -1
- package/src/tlc/messages.ts +2 -21
- package/src/tlc/order.ts +22 -47
- package/src/tlc/random.ts +18 -30
- package/src/tlc/replay.ts +13 -33
- package/src/tlc/summary.ts +36 -45
- package/src/tlc/tlc-operators.ts +4 -14
- package/src/tlc/tlcext-operators.ts +11 -15
- package/src/tlc/trace-spec.ts +4 -9
- package/src/tlc/value-stream.ts +9 -13
- package/src/tlc/version.ts +0 -1
- package/src/values.ts +74 -186
package/src/successors.ts
CHANGED
|
@@ -114,13 +114,11 @@ const assign = (partial: State, index: number, value: Value) => {
|
|
|
114
114
|
const getComputation = (run: Run) =>
|
|
115
115
|
run.isInit ? "initial states" : run.isEnabled ? "ENABLED" : "next states";
|
|
116
116
|
|
|
117
|
-
// TLC fails with an unexpected exception when it fails to compute the next states or ENABLED.
|
|
118
117
|
const createRunError = (run: Run, message: string) => {
|
|
119
118
|
const error = new TlaEvaluationError(message);
|
|
120
119
|
return run.isInit ? error : setExitCode(error, EXIT_STATUS.error);
|
|
121
120
|
};
|
|
122
121
|
|
|
123
|
-
// TLC words this differently for a literal it walks to rather than evaluates.
|
|
124
122
|
const getNonBooleanMessage = (
|
|
125
123
|
run: Run,
|
|
126
124
|
value: Value,
|
|
@@ -136,7 +134,6 @@ const getNonBooleanMessage = (
|
|
|
136
134
|
return `In computing ${getComputation(run)}, TLC expected a boolean expression,\nbut instead found ${formatValue(value)}.\n${node}`;
|
|
137
135
|
};
|
|
138
136
|
|
|
139
|
-
// TLC words an IF whose condition isn't a boolean differently for each computation.
|
|
140
137
|
const getIfConditionMessage = (run: Run, value: Value, expression: Expression) => {
|
|
141
138
|
const kind = getKindString(value);
|
|
142
139
|
const range = describeRange(expression);
|
|
@@ -151,7 +148,6 @@ const holds = (run: Run, expression: Expression, context: Context) =>
|
|
|
151
148
|
|
|
152
149
|
const CORE_OPERATOR_NAMES = new Set(CORE_OPERATORS.map((operator) => operator.name));
|
|
153
150
|
|
|
154
|
-
// TLC's initial states evaluate a built-in operator for its value, and report it in a plain message.
|
|
155
151
|
const isBuiltInOperation = (expression: Expression) =>
|
|
156
152
|
expression.kind === "Apply"
|
|
157
153
|
? CORE_OPERATOR_NAMES.has(expression.operator)
|
|
@@ -313,8 +309,7 @@ const isGuard = (expression: Expression, environment: Environment, isInit: boole
|
|
|
313
309
|
|
|
314
310
|
const NO_NAMES: ReadonlySet<string> = new Set();
|
|
315
311
|
|
|
316
|
-
|
|
317
|
-
export const getReadLocals = (
|
|
312
|
+
const getReadLocals = (
|
|
318
313
|
expression: Expression,
|
|
319
314
|
bound: ReadonlySet<string>,
|
|
320
315
|
): string[] | undefined => {
|
|
@@ -323,19 +318,18 @@ export const getReadLocals = (
|
|
|
323
318
|
return bound.has(expression.name) ? [] : [expression.name];
|
|
324
319
|
}
|
|
325
320
|
const names: string[] = [];
|
|
326
|
-
|
|
321
|
+
let isReadOnly = true;
|
|
327
322
|
mapChildren(expression, (child, childNames) => {
|
|
328
|
-
const childLocals =
|
|
323
|
+
const childLocals = isReadOnly
|
|
329
324
|
? getReadLocals(child, childNames.length === 0 ? bound : new Set([...bound, ...childNames]))
|
|
330
325
|
: [];
|
|
331
326
|
if (childLocals) names.push(...childLocals);
|
|
332
|
-
else
|
|
327
|
+
else isReadOnly = false;
|
|
333
328
|
return child;
|
|
334
329
|
});
|
|
335
|
-
return
|
|
330
|
+
return isReadOnly ? names : undefined;
|
|
336
331
|
};
|
|
337
332
|
|
|
338
|
-
// TLC generates a successor per disjunct and witness, so only an expression without any is a guard.
|
|
339
333
|
const hasBranches = (
|
|
340
334
|
expression: Expression,
|
|
341
335
|
environment: Environment,
|
|
@@ -378,7 +372,6 @@ const toConjunct = (
|
|
|
378
372
|
return { kind: "Branch", expression, runner: getRunner(expression, environment, isInit) };
|
|
379
373
|
};
|
|
380
374
|
|
|
381
|
-
// Leading guards that read no inner bound hold for every inner binding, so they run once.
|
|
382
375
|
const getHoistedGuards = (expression: QuantifierExpression, environment: Environment) => {
|
|
383
376
|
if (expression.bounds.length < 2 || expression.body.kind !== "And") return undefined;
|
|
384
377
|
const names = expression.bounds.flatMap((bound) =>
|
|
@@ -422,8 +415,6 @@ const compileConjunction = (
|
|
|
422
415
|
context ??= getContext(run, scope, current);
|
|
423
416
|
for (let rest = index; rest < conjuncts.length; rest++) {
|
|
424
417
|
const conjunct = conjuncts[rest];
|
|
425
|
-
// Tool#getNextStates0 takes this shortcut with warnings on, though its comment says the
|
|
426
|
-
// shortcut skips the warning for a changed UNCHANGED variable. tla-ts still warns.
|
|
427
418
|
const state = run.current;
|
|
428
419
|
const changed =
|
|
429
420
|
state && conjunct.kind === "Unchanged"
|
|
@@ -585,8 +576,6 @@ const compileDynamicAssignment = (
|
|
|
585
576
|
};
|
|
586
577
|
};
|
|
587
578
|
|
|
588
|
-
// TLC walks the body of an applied function that is still lazy, which it evaluates as it
|
|
589
|
-
// computes the initial states eagerly, and otherwise applies it.
|
|
590
579
|
const compileFunctionAction = (
|
|
591
580
|
expression: Expression & { kind: "FunctionApplication" },
|
|
592
581
|
environment: Environment,
|
|
@@ -646,7 +635,6 @@ const compileUnchanged = (expression: Expression, environment: Environment): Run
|
|
|
646
635
|
return;
|
|
647
636
|
}
|
|
648
637
|
const context = getContext(run, scope, partial);
|
|
649
|
-
// Tool#enabledUnchanged fails on an operator application, as its comment says.
|
|
650
638
|
if (run.isEnabled && expression.kind === "Apply") {
|
|
651
639
|
const operator = resolveApplyOperator(expression, context);
|
|
652
640
|
if (operator?.kind === "Closure" && operator.params.length === expression.args.length) {
|
|
@@ -678,10 +666,10 @@ const compileCall = (
|
|
|
678
666
|
if (global?.kind === "Builtin") return guard;
|
|
679
667
|
if (global?.kind === "Closure") {
|
|
680
668
|
const bindArguments = compileArgumentScope(global, expression.args, environment);
|
|
681
|
-
|
|
669
|
+
let bodyRunner: Runner | undefined;
|
|
682
670
|
return (run, scope, partial, action, isFixed, onComplete) => {
|
|
683
|
-
|
|
684
|
-
|
|
671
|
+
bodyRunner ??= getRunner(global.body, environment, isInit);
|
|
672
|
+
bodyRunner(
|
|
685
673
|
run,
|
|
686
674
|
bindArguments(getContext(run, scope, partial)),
|
|
687
675
|
partial,
|
|
@@ -718,7 +706,7 @@ const compileIdentifier = (
|
|
|
718
706
|
const definition = isLocallyResolved(expression)
|
|
719
707
|
? undefined
|
|
720
708
|
: getZeroArityBody(expression.name, environment);
|
|
721
|
-
|
|
709
|
+
let bodyRunner: Runner | undefined;
|
|
722
710
|
return (run, scope, partial, action, isFixed, onComplete) => {
|
|
723
711
|
const binding = lookupScope(scope, expression.name);
|
|
724
712
|
if (binding?.kind === "Thunk" && !binding.isReleased) {
|
|
@@ -732,8 +720,6 @@ const compileIdentifier = (
|
|
|
732
720
|
);
|
|
733
721
|
return;
|
|
734
722
|
}
|
|
735
|
-
// TLC computed a constant definition at startup, so it looks up its value. It walks the body
|
|
736
|
-
// of the configured INIT or NEXT, which isn't a reference in the source and has no range.
|
|
737
723
|
if (
|
|
738
724
|
binding ||
|
|
739
725
|
!definition ||
|
|
@@ -742,14 +728,11 @@ const compileIdentifier = (
|
|
|
742
728
|
guard(run, scope, partial, action, isFixed, onComplete);
|
|
743
729
|
return;
|
|
744
730
|
}
|
|
745
|
-
|
|
746
|
-
|
|
731
|
+
bodyRunner ??= getRunner(definition.body, environment, isInit);
|
|
732
|
+
bodyRunner(run, undefined, partial, isFixed ? action : definition.name, isFixed, onComplete);
|
|
747
733
|
};
|
|
748
734
|
};
|
|
749
735
|
|
|
750
|
-
// A disjunction of PlusCal actions skips the operands whose label guard, such as
|
|
751
|
-
// pc[self] = "L1", is false. TLC evaluates guards before the label's guard, so a skipped
|
|
752
|
-
// operand still runs them, for their errors.
|
|
753
736
|
interface LabelGuard {
|
|
754
737
|
variable: number;
|
|
755
738
|
argument: string;
|
|
@@ -774,7 +757,6 @@ const toLabelGuard = (expression: Expression, environment: Environment) => {
|
|
|
774
757
|
const getConjuncts = (expression: Expression): Expression[] =>
|
|
775
758
|
expression.kind === "And" ? expression.operands.flatMap(getConjuncts) : [expression];
|
|
776
759
|
|
|
777
|
-
// An operand with another conjunct first, such as an assignment, runs in full.
|
|
778
760
|
const isLeadingGuard = (expression: Expression, environment: Environment) =>
|
|
779
761
|
(expression.kind === "Identifier" ||
|
|
780
762
|
(expression.kind === "Apply" &&
|
|
@@ -1093,7 +1075,6 @@ const compileAction = (
|
|
|
1093
1075
|
const arm = arms.find((candidate) => {
|
|
1094
1076
|
const value = evaluate(candidate.condition, context);
|
|
1095
1077
|
if (typeof value === "boolean") return value;
|
|
1096
|
-
// TLC leaves out the space before the kind under ENABLED.
|
|
1097
1078
|
throw createRunError(
|
|
1098
1079
|
run,
|
|
1099
1080
|
`In computing ${getComputation(run)}, a non-boolean expression${run.isEnabled ? "" : " "}(${getKindString(value)}) was used as a guard condition of a CASE.\n${describeNode(candidate.source)}`,
|
|
@@ -1133,7 +1114,6 @@ const compileAction = (
|
|
|
1133
1114
|
return compileUnchanged(expression.expression, environment);
|
|
1134
1115
|
case "AngleAction": {
|
|
1135
1116
|
const body = getChildRunner(expression.action);
|
|
1136
|
-
// TLC compares the whole subscript of <<A>>_v, unlike UNCHANGED's, which it splits.
|
|
1137
1117
|
const unchanged: Expression = {
|
|
1138
1118
|
kind: "Unchanged",
|
|
1139
1119
|
expression: expression.subscript,
|
|
@@ -1225,7 +1205,6 @@ export const isEnabled = (expression: Expression, context: Context): boolean =>
|
|
|
1225
1205
|
);
|
|
1226
1206
|
}
|
|
1227
1207
|
const environment = context.environment;
|
|
1228
|
-
// TLC computes ENABLED again with its call stack recorded as it computes successors.
|
|
1229
1208
|
if (environment.callStack) return replayEnabled(expression, context.scope, state, environment);
|
|
1230
1209
|
const run: Run = {
|
|
1231
1210
|
environment,
|
|
@@ -1236,7 +1215,6 @@ export const isEnabled = (expression: Expression, context: Context): boolean =>
|
|
|
1236
1215
|
generator: undefined,
|
|
1237
1216
|
successors: 0,
|
|
1238
1217
|
};
|
|
1239
|
-
// TLC stops computing ENABLED at the first successor, so it skips the rest of the action.
|
|
1240
1218
|
getRunner(expression, environment, false)(
|
|
1241
1219
|
run,
|
|
1242
1220
|
context.scope,
|
|
@@ -1279,7 +1257,6 @@ export const forEachInitialState = (
|
|
|
1279
1257
|
run.isStopped = onIncomplete([...partial]);
|
|
1280
1258
|
return;
|
|
1281
1259
|
}
|
|
1282
|
-
// TLC reports an initial state that isn't completely specified as an illegal state.
|
|
1283
1260
|
throw setExitCode(new TlaIllegalStateError([...partial]), EXIT_STATUS.error);
|
|
1284
1261
|
}
|
|
1285
1262
|
run.isStopped = onState(partial);
|
|
@@ -1333,7 +1310,9 @@ export const forEachSuccessor = (
|
|
|
1333
1310
|
(partial, action) => {
|
|
1334
1311
|
if (run.isStopped) return;
|
|
1335
1312
|
if (!isComplete(partial)) {
|
|
1336
|
-
const missing = environment.variables.filter(
|
|
1313
|
+
const missing = environment.variables.filter(
|
|
1314
|
+
(_name, index) => partial[index] === undefined,
|
|
1315
|
+
);
|
|
1337
1316
|
throw new TlaIncompleteSuccessorError(
|
|
1338
1317
|
`Successor state is not completely specified by action ${action ?? "Next"}. The following variables are not assigned: ${missing.join(", ")}`,
|
|
1339
1318
|
partial,
|
package/src/symmetry.ts
CHANGED
|
@@ -39,8 +39,6 @@ const composePermutations = (first: Images, second: Images) => {
|
|
|
39
39
|
return composed;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
// Tool#getSymmetryPerms fails with a RuntimeException as TLC starts, which TLC reports as one it
|
|
43
|
-
// did not expect.
|
|
44
42
|
const createSymmetryError = (message: string) =>
|
|
45
43
|
setExitCode(new TlaEvaluationError(`${UNEXPECTED_EXCEPTION}${message}`), EXIT_STATUS.error);
|
|
46
44
|
|
|
@@ -57,7 +55,6 @@ const toImages = (value: Value) => {
|
|
|
57
55
|
return permutation;
|
|
58
56
|
};
|
|
59
57
|
|
|
60
|
-
// SyntaxTreeNode.getHumanReadableImage, which joins the tokens of an expression without spaces.
|
|
61
58
|
const getBoundImage = (pattern: BoundPattern, set: Expression | undefined) => {
|
|
62
59
|
const names = pattern.kind === "Name" ? pattern.name : `<<${pattern.names.join(",")}>>`;
|
|
63
60
|
return set ? `${names}\\in${getExpressionImage(set)}` : names;
|
|
@@ -122,8 +119,6 @@ export const getSymmetryGroup = (
|
|
|
122
119
|
if (!elements.every(isFunctionValue)) {
|
|
123
120
|
throw createSymmetryError("The symmetry values must be function records.");
|
|
124
121
|
}
|
|
125
|
-
// Tool#getSymmetryPerms warns about each permuted set with fewer than two elements, by the name
|
|
126
|
-
// the config substitutes for it. As many permuted sets as permutations means none has two.
|
|
127
122
|
const body = definition.body;
|
|
128
123
|
const permutedSets =
|
|
129
124
|
body.kind === "Apply" ? body.args : body.kind === "SetEnumeration" ? body.elements : [];
|
|
@@ -153,24 +148,22 @@ export const getSymmetryGroup = (
|
|
|
153
148
|
if (permutation.size > 0) group.set(getPermutationKey(permutation), permutation);
|
|
154
149
|
});
|
|
155
150
|
const generators = [...group.values()];
|
|
156
|
-
|
|
157
|
-
while (
|
|
151
|
+
let frontierStart = 0;
|
|
152
|
+
while (frontierStart < group.size) {
|
|
158
153
|
const members = [...group.values()];
|
|
159
154
|
const end = members.length;
|
|
160
155
|
generators.forEach((generator) =>
|
|
161
|
-
members.slice(
|
|
156
|
+
members.slice(frontierStart, end).forEach((member) => {
|
|
162
157
|
const composed = composePermutations(generator, member);
|
|
163
158
|
const key = getPermutationKey(composed);
|
|
164
159
|
if (composed.size > 0 && !group.has(key)) group.set(key, composed);
|
|
165
160
|
}),
|
|
166
161
|
);
|
|
167
|
-
|
|
162
|
+
frontierStart = end;
|
|
168
163
|
}
|
|
169
164
|
const movedNames = new Set(
|
|
170
165
|
[...group.values()].flatMap((images) => [...images.values()].map((image) => image.name)),
|
|
171
166
|
);
|
|
172
|
-
// Only a permutation of a constant that TLC holds as an enumerated set is checked. TLC binds a
|
|
173
|
-
// constant the config substitutes with <- to the definition, which it skips.
|
|
174
167
|
const substitutedNames = new Set(substitutions.map((substitution) => substitution.name));
|
|
175
168
|
warnSmallSets(
|
|
176
169
|
permutedSets.filter((node) => {
|
|
@@ -204,8 +197,6 @@ const permuteElements = (elements: Value[], images: Images) => {
|
|
|
204
197
|
return undefined;
|
|
205
198
|
};
|
|
206
199
|
|
|
207
|
-
// A permutation maps distinct elements to distinct elements and keeps the elements it doesn't move
|
|
208
|
-
// in order, so it sorts only the moved ones and merges them back.
|
|
209
200
|
const permuteSortedElements = (elements: Value[], images: Images) => {
|
|
210
201
|
const kept: Value[] = [];
|
|
211
202
|
const moved: Value[] = [];
|
|
@@ -231,8 +222,6 @@ const permuteSortedElements = (elements: Value[], images: Images) => {
|
|
|
231
222
|
return merged;
|
|
232
223
|
};
|
|
233
224
|
|
|
234
|
-
// Value#permute: the value with each model value replaced by its image. A value the permutation
|
|
235
|
-
// doesn't move is returned itself, so that comparing it with itself stops at identity.
|
|
236
225
|
const permuteValue = (value: Value, images: Images): Value => {
|
|
237
226
|
if (typeof value !== "object") return value;
|
|
238
227
|
const kind = value.kind;
|
|
@@ -249,8 +238,6 @@ const permuteValue = (value: Value, images: Images): Value => {
|
|
|
249
238
|
const permuted = createFunction(
|
|
250
239
|
domain.map((key, index): [Value, Value] => [key, range[index]]),
|
|
251
240
|
);
|
|
252
|
-
// A permutation often maps the domain to itself, such as a function over the symmetric set.
|
|
253
|
-
// Sharing the original domain array lets comparisons with other images skip the domain.
|
|
254
241
|
const isSameDomain = permuted.domain.every(
|
|
255
242
|
(key, index) => key === functionValue.domain[index],
|
|
256
243
|
);
|
|
@@ -266,8 +253,6 @@ const permuteValue = (value: Value, images: Images): Value => {
|
|
|
266
253
|
return elements ? createSet(elements) : set;
|
|
267
254
|
};
|
|
268
255
|
|
|
269
|
-
// TLC permutes the state under each permutation, variable by variable, and moves on to the next
|
|
270
|
-
// permutation as soon as a variable's image is larger than the smallest state's.
|
|
271
256
|
export const getRepresentative = (
|
|
272
257
|
state: Value[],
|
|
273
258
|
permutations: Images[],
|
package/src/tlc/fingerprint.ts
CHANGED
|
@@ -143,9 +143,9 @@ const POLYNOMIALS = [
|
|
|
143
143
|
0x91f5a5fa9c5515a5n,
|
|
144
144
|
];
|
|
145
145
|
|
|
146
|
-
|
|
146
|
+
let selectedPolynomial = POLYNOMIALS[0];
|
|
147
147
|
|
|
148
|
-
export const getFingerprintPolynomial = () =>
|
|
148
|
+
export const getFingerprintPolynomial = () => selectedPolynomial;
|
|
149
149
|
|
|
150
150
|
const SLICE_HIGH_0 = new Int32Array(256);
|
|
151
151
|
const SLICE_HIGH_1 = new Int32Array(256);
|
|
@@ -155,8 +155,8 @@ const SLICE_LOW_0 = new Int32Array(256);
|
|
|
155
155
|
const SLICE_LOW_1 = new Int32Array(256);
|
|
156
156
|
const SLICE_LOW_2 = new Int32Array(256);
|
|
157
157
|
const SLICE_LOW_3 = new Int32Array(256);
|
|
158
|
-
|
|
159
|
-
|
|
158
|
+
let initialHigh = 0;
|
|
159
|
+
let initialLow = 0;
|
|
160
160
|
let high = 0;
|
|
161
161
|
let low = 0;
|
|
162
162
|
|
|
@@ -166,12 +166,9 @@ const extendByte = (byte: number) => {
|
|
|
166
166
|
high = (high >>> 8) ^ SLICE_HIGH_0[index];
|
|
167
167
|
};
|
|
168
168
|
|
|
169
|
-
// Extending is linear over GF(2), so extending by four bytes at once shifts the fingerprint by a
|
|
170
|
-
// word and adds, for each of the four, the fingerprint from zero of that byte followed by the zero
|
|
171
|
-
// bytes that come after it: SLICE_HIGH_k and SLICE_LOW_k hold them for k zero bytes after.
|
|
172
169
|
export const setFingerprintPolynomial = (index: number) => {
|
|
173
170
|
const polynomial = POLYNOMIALS[index];
|
|
174
|
-
|
|
171
|
+
selectedPolynomial = polynomial;
|
|
175
172
|
const powers: bigint[] = [];
|
|
176
173
|
for (let power = 1n << 63n; powers.length < 72;) {
|
|
177
174
|
powers.push(power);
|
|
@@ -198,8 +195,8 @@ export const setFingerprintPolynomial = (index: number) => {
|
|
|
198
195
|
highs[zeros][byte] = (previousHigh[byte] >>> 8) ^ SLICE_HIGH_0[index];
|
|
199
196
|
}
|
|
200
197
|
}
|
|
201
|
-
|
|
202
|
-
|
|
198
|
+
initialHigh = Number(BigInt.asIntN(32, polynomial >> 32n));
|
|
199
|
+
initialLow = Number(BigInt.asIntN(32, polynomial));
|
|
203
200
|
};
|
|
204
201
|
|
|
205
202
|
setFingerprintPolynomial(0);
|
|
@@ -221,8 +218,6 @@ const SET_ENUM_VALUE = 5;
|
|
|
221
218
|
const FCN_RCD_VALUE = 9;
|
|
222
219
|
const MODEL_VALUE = 21;
|
|
223
220
|
|
|
224
|
-
// Returns how many bytes it extends the fingerprint by. A model value extends it with its
|
|
225
|
-
// UniqueString token, which TLC numbers from 1 in intern order.
|
|
226
221
|
const extendScalar = (value: boolean | number | string | ModelValue) => {
|
|
227
222
|
if (typeof value === "boolean") {
|
|
228
223
|
extendByte(BOOL_VALUE);
|
|
@@ -273,27 +268,26 @@ const extendValue = (value: Value) => {
|
|
|
273
268
|
}
|
|
274
269
|
};
|
|
275
270
|
|
|
276
|
-
// Evaluating a lazy value can fingerprint another, so this restores the fingerprint it interrupts.
|
|
277
271
|
export const getTlcFingerprint = (state: Value[]) => {
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
272
|
+
const outerHigh = high;
|
|
273
|
+
const outerLow = low;
|
|
274
|
+
high = initialHigh;
|
|
275
|
+
low = initialLow;
|
|
281
276
|
for (const value of state) extendValue(value);
|
|
282
277
|
const fingerprint = (BigInt(high >>> 0) << 32n) | BigInt(low >>> 0);
|
|
283
|
-
high =
|
|
284
|
-
low =
|
|
278
|
+
high = outerHigh;
|
|
279
|
+
low = outerLow;
|
|
285
280
|
return fingerprint;
|
|
286
281
|
};
|
|
287
282
|
|
|
288
283
|
export const getTlcFingerprints = (states: Value[][], order: number[]) => {
|
|
289
284
|
const fingerprints = new BigInt64Array(states.length);
|
|
290
|
-
// Each fingerprint's low and high words, as a BigInt64Array is little-endian.
|
|
291
285
|
const words = new Int32Array(fingerprints.buffer);
|
|
292
286
|
const outerHigh = high;
|
|
293
287
|
const outerLow = low;
|
|
294
288
|
states.forEach((state, position) => {
|
|
295
|
-
high =
|
|
296
|
-
low =
|
|
289
|
+
high = initialHigh;
|
|
290
|
+
low = initialLow;
|
|
297
291
|
for (const index of order) extendValue(state[index]);
|
|
298
292
|
words[2 * position] = low;
|
|
299
293
|
words[2 * position + 1] = high;
|
package/src/tlc/jar-data.ts
CHANGED
package/src/tlc/messages.ts
CHANGED
|
@@ -125,9 +125,6 @@ export const formatMessage = (isTool: boolean, code: number, level: MessageLevel
|
|
|
125
125
|
? `@!@!@STARTMSG ${code}:${level} @!@!@\n${text}\n@!@!@ENDMSG ${code} @!@!@`
|
|
126
126
|
: `${LEVEL_PREFIXES[level]}${text}`;
|
|
127
127
|
|
|
128
|
-
// With -tool, TLC wraps each message in markers of its code and level, and leaves lines such as
|
|
129
|
-
// Print's bare. A warning prints once, -nowarning drops it, and without -tool the first one
|
|
130
|
-
// says how to drop them.
|
|
131
128
|
export const createMessagePrinter = (
|
|
132
129
|
isTool: boolean,
|
|
133
130
|
isWarningEnabled = true,
|
|
@@ -158,12 +155,9 @@ export const createMessagePrinter = (
|
|
|
158
155
|
};
|
|
159
156
|
};
|
|
160
157
|
|
|
161
|
-
// TLC 1.7.4's message for a missing initial predicate also blames a parameterized INSTANCE.
|
|
162
158
|
export const MISSING_INIT_174 =
|
|
163
159
|
"The configuration file did not specify the initial state predicate.\nCan also be caused by trying to run TLC on a specification from\na module imported with a parameterized INSTANCE statement.";
|
|
164
160
|
|
|
165
|
-
// isEvalException: whether TLC throws the message as an EvalException, not a TLCRuntimeException.
|
|
166
|
-
// TLC's -tool output wraps such a message in its own markers even inside another message.
|
|
167
161
|
const CODED_MESSAGES: [code: number, template: string, isEvalException: boolean][] = [
|
|
168
162
|
[1005, STACK_OVERFLOW_MESSAGE, false],
|
|
169
163
|
[
|
|
@@ -343,12 +337,10 @@ interface CodedMessage {
|
|
|
343
337
|
isEvalException: boolean;
|
|
344
338
|
}
|
|
345
339
|
|
|
346
|
-
|
|
347
|
-
value: undefined as { pattern: RegExp; message: CodedMessage }[] | undefined,
|
|
348
|
-
};
|
|
340
|
+
let codedMessagePatterns: { pattern: RegExp; message: CodedMessage }[] | undefined;
|
|
349
341
|
|
|
350
342
|
const getCodedMessagePatterns = () =>
|
|
351
|
-
(codedMessagePatterns
|
|
343
|
+
(codedMessagePatterns ??= CODED_MESSAGES.map(([code, template, isEvalException]) => ({
|
|
352
344
|
pattern: new RegExp(
|
|
353
345
|
`^${template
|
|
354
346
|
.split(/%\d+%/)
|
|
@@ -358,8 +350,6 @@ const getCodedMessagePatterns = () =>
|
|
|
358
350
|
message: { code, isEvalException },
|
|
359
351
|
})));
|
|
360
352
|
|
|
361
|
-
// Plain messages that read like coded ones: the overflows of SetOfFcnsValue and SetOfTuplesValue,
|
|
362
|
-
// SetPredValue's tuple membership, and Tool#enabled's for ~> and -+->.
|
|
363
353
|
const UNCODED_MESSAGE_PATTERN =
|
|
364
354
|
/^Overflow when computing the number of elements in( |:\n\[(?![A-Za-z0-9_]+: ))|\nis an element of a set of \d+-tuples\.$|^In computing ENABLED, TLC encountered a temporal formula \(a (~> b|-\+-> formula)\)\./;
|
|
365
355
|
|
|
@@ -368,13 +358,10 @@ export const getCodedMessage = (text: string): CodedMessage | undefined =>
|
|
|
368
358
|
? undefined
|
|
369
359
|
: getCodedMessagePatterns().find((item) => item.pattern.test(text))?.message;
|
|
370
360
|
|
|
371
|
-
// Only a standard module's Java code throws an EvalException; Assert.fail throws the other kind.
|
|
372
361
|
export const isEvalException = (error: TlaEvaluationError) =>
|
|
373
362
|
error instanceof TlaModuleError || getCodedMessage(error.message)?.isEvalException === true;
|
|
374
363
|
|
|
375
|
-
// The messages that end with the message of the error they report, after this text.
|
|
376
364
|
const INNER_MESSAGE_PREFIXES = new Map([
|
|
377
|
-
// "The exception was a <class>\n: "
|
|
378
365
|
[1000, "\n: "],
|
|
379
366
|
[2105, "failed.\n"],
|
|
380
367
|
[2154, "but it produced the following error:\n"],
|
|
@@ -384,7 +371,6 @@ const INNER_MESSAGE_PREFIXES = new Map([
|
|
|
384
371
|
[2405, "failed.\n"],
|
|
385
372
|
]);
|
|
386
373
|
|
|
387
|
-
// TLC's message holds the inner error's text as TLC printed it, markers included.
|
|
388
374
|
export const formatInnerMessage = (code: number, text: string, isTool: boolean) => {
|
|
389
375
|
const prefix = isTool ? INNER_MESSAGE_PREFIXES.get(code) : undefined;
|
|
390
376
|
const index = prefix === undefined ? -1 : text.indexOf(prefix);
|
|
@@ -440,14 +426,12 @@ const WRONG_INVOCATION_EXCEPTION = getUnexpectedException("util.WrongInvocationE
|
|
|
440
426
|
|
|
441
427
|
const UNEXPECTED_HEADLINE = UNEXPECTED_EXCEPTION.slice(0, UNEXPECTED_EXCEPTION.indexOf("\n"));
|
|
442
428
|
|
|
443
|
-
// TLC 1.7.4 wraps an error in adding a successor in a RuntimeException naming its class.
|
|
444
429
|
const WRAPPED_EVAL_EXCEPTION = `${UNEXPECTED_EXCEPTION}tlc2.tool.EvalException: `;
|
|
445
430
|
const WRAPPED_RUNTIME_EXCEPTION = `${UNEXPECTED_EXCEPTION}util.Assert$TLCRuntimeException: `;
|
|
446
431
|
|
|
447
432
|
export const getWrappedException = (error: TlaEvaluationError) =>
|
|
448
433
|
isEvalException(error) ? WRAPPED_EVAL_EXCEPTION : WRAPPED_RUNTIME_EXCEPTION;
|
|
449
434
|
|
|
450
|
-
// TLC reports an EvalException, or a TLCRuntimeException without its own message, as unexpected.
|
|
451
435
|
export const withUnexpectedException = <Result>(compute: () => Result) => {
|
|
452
436
|
try {
|
|
453
437
|
return compute();
|
|
@@ -477,8 +461,6 @@ const formatErrorMessage = (error: TlaEvaluationError, isTool: boolean): string
|
|
|
477
461
|
return `${prefix}${formatNestedMessage(message.slice(prefix.length), isTool)}`;
|
|
478
462
|
};
|
|
479
463
|
|
|
480
|
-
// TLC reports an error with a headline by its message's code, and one that escapes the next
|
|
481
|
-
// states with an EvalException's code, or as an unexpected exception.
|
|
482
464
|
export interface FailureMessage {
|
|
483
465
|
code: number;
|
|
484
466
|
message: string;
|
|
@@ -498,7 +480,6 @@ export const getFailureMessage = (
|
|
|
498
480
|
toolMessage: formatErrorMessage(error, true),
|
|
499
481
|
};
|
|
500
482
|
}
|
|
501
|
-
// TLC prints a StackOverflowError by its code in the next states, as plain text in the initial.
|
|
502
483
|
if (error instanceof TlaStackOverflowError) {
|
|
503
484
|
return {
|
|
504
485
|
code: isNextState ? MESSAGE_CODE.stackOverflow : MESSAGE_CODE.general,
|