tla-ts 0.0.10-dev.96638cd93 → 0.0.10-dev.a17d6d9fa
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/deciders.cjs +30 -30
- package/dist/deciders.js +30 -30
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +60 -60
- package/dist/prove.js +73 -73
- package/dist/run.cjs +42 -42
- package/dist/run.js +42 -42
- package/dist/transfer.cjs +34 -34
- package/dist/transfer.js +29 -29
- package/dist/worker.cjs +1 -1
- package/dist/worker.js +1 -1
- package/package.json +1 -1
- package/src/bags.ts +5 -2
- package/src/builtins.ts +4 -3
- package/src/check-failure.ts +1 -1
- package/src/check-trace.ts +90 -51
- package/src/check.ts +251 -133
- package/src/cli/tlc.ts +3 -2
- package/src/codegen.ts +18 -5
- package/src/dfid.ts +13 -8
- package/src/environment.ts +1 -0
- package/src/evaluate.ts +25 -9
- package/src/exit-codes.ts +1 -0
- package/src/java-hash.ts +14 -0
- package/src/liveness-checker.ts +63 -31
- package/src/liveness.ts +48 -10
- package/src/parser.ts +6 -1
- package/src/prover/smt/solver/arith-rewriter.ts +11 -3
- package/src/prover/smt/solver/array-rewriter.ts +12 -2
- package/src/prover/smt/solver/asserted-formulas.ts +109 -63
- package/src/prover/smt/solver/ast.ts +5 -3
- package/src/prover/smt/solver/auf-solver.ts +23 -12
- package/src/prover/smt/solver/bit-blast-tactic.ts +26 -0
- package/src/prover/smt/solver/bound-simplifier.ts +10 -11
- package/src/prover/smt/solver/card2bv.ts +31 -15
- package/src/prover/smt/solver/cofactor-elim-term-ite.ts +39 -23
- package/src/prover/smt/solver/context.ts +24 -7
- package/src/prover/smt/solver/dependent-expr-state.ts +1 -1
- package/src/prover/smt/solver/elim-bounds.ts +89 -0
- package/src/prover/smt/solver/elim-uncnstr.ts +1 -1
- package/src/prover/smt/solver/internalizer.ts +1 -1
- package/src/prover/smt/solver/lp/lp-settings.ts +4 -0
- package/src/prover/smt/solver/model-evaluator.ts +2 -0
- package/src/prover/smt/solver/model-generator.ts +82 -42
- package/src/prover/smt/solver/opt-context.ts +11 -4
- package/src/prover/smt/solver/opt-pareto.ts +19 -0
- package/src/prover/smt/solver/opt-solver.ts +3 -2
- package/src/prover/smt/solver/poly-rewriter.ts +1 -0
- package/src/prover/smt/solver/proto-model.ts +4 -2
- package/src/prover/smt/solver/push-app-ite.ts +37 -0
- package/src/prover/smt/solver/qsat.ts +16 -6
- package/src/prover/smt/solver/rewriter.ts +31 -25
- package/src/prover/smt/solver/sat/goal2sat.ts +0 -1
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +13 -4
- package/src/prover/smt/solver/sat/sat-tactic.ts +9 -2
- package/src/prover/smt/solver/smt-kernel.ts +30 -2
- package/src/prover/smt/solver/smt-setup.ts +28 -4
- package/src/prover/smt/solver/smtlib-parser.ts +26 -3
- package/src/prover/smt/solver/smtlib-script.ts +34 -21
- package/src/prover/smt/solver/solve-eqs.ts +24 -17
- package/src/prover/smt/solver/solver.ts +18 -3
- package/src/prover/smt/solver/tactic.ts +68 -41
- package/src/prover/smt/solver/theory-bv.ts +11 -1
- package/src/prover/smt/solver/theory-fpa.ts +1 -1
- package/src/prover/smt/solver/theory-lra-final-check.ts +1 -0
- package/src/prover/smt/solver/theory-lra-internalize.ts +1 -0
- package/src/prover/smt/solver/theory-lra-propagate.ts +7 -1
- package/src/prover/smt/solver/theory-lra.ts +1 -0
- package/src/prover/smt/solver/tseitin-cnf.ts +1 -0
- package/src/resolve.ts +120 -52
- package/src/runtime.ts +4 -0
- package/src/search.ts +117 -81
- package/src/simulate.ts +110 -50
- package/src/spec-description.ts +3 -4
- package/src/standard-modules.ts +15 -6
- package/src/subexpressions.ts +34 -9
- package/src/successors.ts +3 -2
- package/src/tlc/random.ts +2 -1
- package/src/tlc/replay.ts +3 -2
- package/src/tlc/tlc-operators.ts +7 -7
- package/src/tlc/tlcext-operators.ts +26 -10
- package/src/tlc/trace-spec.ts +6 -20
- package/src/typed-tier.ts +3 -2
- package/src/values.ts +95 -57
package/src/values.ts
CHANGED
|
@@ -350,16 +350,16 @@ const checkModelValueTypes = (left: Value, right: Value, isEquality: boolean) =>
|
|
|
350
350
|
if (isModelValue(left) && isModelValue(right)) {
|
|
351
351
|
if (leftType === undefined || rightType === undefined || leftType === rightType) return;
|
|
352
352
|
throw new TlaEvaluationError(
|
|
353
|
-
`Attempted to ${action} the differently-typed model values ${formatValue(left)} and ${formatValue(right)}`,
|
|
353
|
+
`Attempted to ${action} the differently-typed model values ${prettyPrint(formatValue(left))} and ${prettyPrint(formatValue(right))}`,
|
|
354
354
|
);
|
|
355
355
|
}
|
|
356
356
|
if (leftType !== undefined) {
|
|
357
357
|
throw new TlaEvaluationError(
|
|
358
|
-
`Attempted to ${action}${isEquality ? "" : " the"} typed model value ${formatValue(left)} and non-model value\n${formatValue(right)}`,
|
|
358
|
+
`Attempted to ${action}${isEquality ? "" : " the"} typed model value ${prettyPrint(formatValue(left))} and non-model value\n${prettyPrint(formatValue(right))}`,
|
|
359
359
|
);
|
|
360
360
|
}
|
|
361
361
|
throw new TlaEvaluationError(
|
|
362
|
-
`Attempted to ${action} the typed model value ${formatValue(right)} and the non-model value\n${formatValue(left)}`,
|
|
362
|
+
`Attempted to ${action} the typed model value ${prettyPrint(formatValue(right))} and the non-model value\n${prettyPrint(formatValue(left))}`,
|
|
363
363
|
);
|
|
364
364
|
};
|
|
365
365
|
|
|
@@ -464,7 +464,7 @@ const isOverriddenComparison = (left: Value, right: Value) =>
|
|
|
464
464
|
const createComparisonError = (left: Value, right: Value) =>
|
|
465
465
|
new TlaEvaluationError(
|
|
466
466
|
isOverriddenSet(left)
|
|
467
|
-
? `Attempted to compare overridden value ${formatValue(left, true)} with non-overridden value:\n${formatValue(right)}`
|
|
467
|
+
? `Attempted to compare overridden value ${prettyPrint(formatValue(left, true))} with non-overridden value:\n${prettyPrint(formatValue(right))}`
|
|
468
468
|
: `Attempted to compare ${describeKind(left)} ${formatValue(left)} with ${describeKind(right)} ${formatValue(right)}`,
|
|
469
469
|
);
|
|
470
470
|
|
|
@@ -475,7 +475,7 @@ const compareOverriddenSets = (
|
|
|
475
475
|
) => {
|
|
476
476
|
if (!isOverriddenSet(left)) {
|
|
477
477
|
throw new TlaEvaluationError(
|
|
478
|
-
`Attempted to ${verb} the set ${formatValue(isEnumerable(left) ? toFiniteSet(left) : left, true)} with the value:\n${formatValue(right, true)}`,
|
|
478
|
+
`Attempted to ${verb} the set ${prettyPrint(formatValue(isEnumerable(left) ? toFiniteSet(left) : left, true))} with the value:\n${prettyPrint(formatValue(right, true))}`,
|
|
479
479
|
);
|
|
480
480
|
}
|
|
481
481
|
if (!isOverriddenSet(right)) throw createComparisonError(left, right);
|
|
@@ -486,14 +486,16 @@ const compareOverriddenSets = (
|
|
|
486
486
|
return leftName === "Nat" ? -1 : 1;
|
|
487
487
|
}
|
|
488
488
|
throw new TlaModuleError(
|
|
489
|
-
`Attempted to compare ${formatValue(left, true)} with the value\n${formatValue(right, true)}`,
|
|
489
|
+
`Attempted to compare ${prettyPrint(formatValue(left, true))} with the value\n${prettyPrint(formatValue(right, true))}`,
|
|
490
490
|
);
|
|
491
491
|
};
|
|
492
492
|
|
|
493
493
|
export const ANY_SET: InfiniteSetValue = { kind: "InfiniteSet", name: "Any" };
|
|
494
494
|
|
|
495
495
|
const compareAny = (other: Value): never => {
|
|
496
|
-
throw new TlaModuleError(
|
|
496
|
+
throw new TlaModuleError(
|
|
497
|
+
`Attempted to compare ANY with the value\n${prettyPrint(formatValue(other))}`,
|
|
498
|
+
);
|
|
497
499
|
};
|
|
498
500
|
|
|
499
501
|
const compareWithItself = (value: Value) => {
|
|
@@ -874,7 +876,7 @@ const describeScalarMismatch = (
|
|
|
874
876
|
SCALAR_KINDS[
|
|
875
877
|
typeof left === "number" ? "number" : typeof left === "string" ? "string" : "boolean"
|
|
876
878
|
];
|
|
877
|
-
return `Attempted to ${isEquality ? kind.equality : "compare"} ${kind.name} ${formatValue(left)} with ${kind.other}:\n${formatValue(right)}`;
|
|
879
|
+
return `Attempted to ${isEquality ? kind.equality : "compare"} ${kind.name} ${prettyPrint(formatValue(left))} with ${kind.other}:\n${prettyPrint(formatValue(right))}`;
|
|
878
880
|
};
|
|
879
881
|
|
|
880
882
|
const getComparisonVerb = (isEquality: boolean) => (isEquality ? "check equality of" : "compare");
|
|
@@ -889,7 +891,7 @@ const compareTlcFunctions = (
|
|
|
889
891
|
if (!other) {
|
|
890
892
|
if (isModelValue(right)) return compareModelValueWith(right, left, isEquality);
|
|
891
893
|
throw new TlaEvaluationError(
|
|
892
|
-
`Attempted to ${getComparisonVerb(isEquality)} the function ${formatValue(left)} with the value:\n${formatValue(right)}`,
|
|
894
|
+
`Attempted to ${getComparisonVerb(isEquality)} the function ${prettyPrint(formatValue(left))} with the value:\n${prettyPrint(formatValue(right))}`,
|
|
893
895
|
);
|
|
894
896
|
}
|
|
895
897
|
if (functionValue.range.length !== other.range.length)
|
|
@@ -910,7 +912,7 @@ const compareTlcFunctions = (
|
|
|
910
912
|
const key = keys[index];
|
|
911
913
|
if (typeof key !== "number") {
|
|
912
914
|
throw new TlaEvaluationError(
|
|
913
|
-
`Attempted to compare ${isEquality ? "an " : ""}integer with non-integer${isEquality || functionValue.low !== undefined ? ":" : ""}\n${formatValue(key)}.`,
|
|
915
|
+
`Attempted to compare ${isEquality ? "an " : ""}integer with non-integer${isEquality || functionValue.low !== undefined ? ":" : ""}\n${prettyPrint(formatValue(key))}.`,
|
|
914
916
|
);
|
|
915
917
|
}
|
|
916
918
|
const difference =
|
|
@@ -947,7 +949,7 @@ const compareFunctionLikeTlc = (
|
|
|
947
949
|
if (!record) {
|
|
948
950
|
if (isModelValue(right)) return compareModelValueWith(right, left, isEquality);
|
|
949
951
|
throw new TlaEvaluationError(
|
|
950
|
-
`Attempted to ${getComparisonVerb(isEquality)} record:\n${formatValue(left)}\nwith non-record\n${formatValue(right)}`,
|
|
952
|
+
`Attempted to ${getComparisonVerb(isEquality)} record:\n${prettyPrint(formatValue(left))}\nwith non-record\n${prettyPrint(formatValue(right))}`,
|
|
951
953
|
);
|
|
952
954
|
}
|
|
953
955
|
return (
|
|
@@ -989,7 +991,7 @@ const compareSetLikeTlc = (left: ObjectValue, right: Value, isEquality: boolean)
|
|
|
989
991
|
if (!isSetValue(right)) {
|
|
990
992
|
if (isModelValue(right)) return compareModelValueWith(right, left, isEquality);
|
|
991
993
|
throw new TlaEvaluationError(
|
|
992
|
-
`Attempted to ${getComparisonVerb(isEquality)} the set ${formatValue(left)} with the value:\n${formatValue(right)}`,
|
|
994
|
+
`Attempted to ${getComparisonVerb(isEquality)} the set ${prettyPrint(formatValue(left))} with the value:\n${prettyPrint(formatValue(right))}`,
|
|
993
995
|
);
|
|
994
996
|
}
|
|
995
997
|
const sets = getSetElementsLikeTlc(left, right);
|
|
@@ -1068,6 +1070,7 @@ export const markNormalized = (value: Value): void => {
|
|
|
1068
1070
|
value.elements.forEach(markNormalized);
|
|
1069
1071
|
}
|
|
1070
1072
|
if (value.kind === "Function") {
|
|
1073
|
+
value.writtenKeys = undefined;
|
|
1071
1074
|
value.domain.forEach(markNormalized);
|
|
1072
1075
|
value.range.forEach(markNormalized);
|
|
1073
1076
|
}
|
|
@@ -1341,7 +1344,7 @@ const getUnionSet = (set: Value, index: number, union: UnionValue) => {
|
|
|
1341
1344
|
throw new TlaEvaluationError(
|
|
1342
1345
|
index === 0
|
|
1343
1346
|
? "Attempted to enumerate UNION(s), but some element of s is nonenumerable."
|
|
1344
|
-
: `Attempted to enumerate the nonenumerable set:\n${formatValue(set)}\nwhen enumerating:\n${formatUnion(union)}`,
|
|
1347
|
+
: `Attempted to enumerate the nonenumerable set:\n${prettyPrint(formatValue(set))}\nwhen enumerating:\n${prettyPrint(formatUnion(union))}`,
|
|
1345
1348
|
);
|
|
1346
1349
|
};
|
|
1347
1350
|
|
|
@@ -1541,13 +1544,13 @@ const enumerateSet = (
|
|
|
1541
1544
|
if (!isVersion174 && isEmptySet(value)) return [];
|
|
1542
1545
|
if (isOverriddenSet(value.domain)) {
|
|
1543
1546
|
throw new TlaEvaluationError(
|
|
1544
|
-
`Attempted to enumerate a set of the form [D -> R],but the domain D:\n${formatValue(value.domain)}\ncannot be enumerated.`,
|
|
1547
|
+
`Attempted to enumerate a set of the form [D -> R],but the domain D:\n${prettyPrint(formatValue(value.domain))}\ncannot be enumerated.`,
|
|
1545
1548
|
);
|
|
1546
1549
|
}
|
|
1547
1550
|
const domain = getFunctionDomain(value.domain);
|
|
1548
1551
|
if ((domain.length > 0 || isVersion174) && isOverriddenSet(value.range)) {
|
|
1549
1552
|
throw new TlaEvaluationError(
|
|
1550
|
-
`Attempted to enumerate a set of the form [D -> R],but the range R:\n${formatValue(value.range)}\ncannot be enumerated.`,
|
|
1553
|
+
`Attempted to enumerate a set of the form [D -> R],but the range R:\n${prettyPrint(formatValue(value.range))}\ncannot be enumerated.`,
|
|
1551
1554
|
);
|
|
1552
1555
|
}
|
|
1553
1556
|
const range = domain.length === 0 ? [] : getElements(value.range);
|
|
@@ -1561,7 +1564,7 @@ const enumerateSet = (
|
|
|
1561
1564
|
value.sets,
|
|
1562
1565
|
getElements,
|
|
1563
1566
|
(set, index) =>
|
|
1564
|
-
`Attempted to enumerate a set of the form [l1 : v1, ..., ln : vn],\nbut can't enumerate the value of the \`${value.names[index]}' field:\n${formatValue(set)}`,
|
|
1567
|
+
`Attempted to enumerate a set of the form [l1 : v1, ..., ln : vn],\nbut can't enumerate the value of the \`${value.names[index]}' field:\n${prettyPrint(formatValue(set))}`,
|
|
1565
1568
|
);
|
|
1566
1569
|
return getCartesianProduct(fields).map((combination) =>
|
|
1567
1570
|
createRecord(value.names.map((name, index): [string, Value] => [name, combination[index]])),
|
|
@@ -1573,14 +1576,14 @@ const enumerateSet = (
|
|
|
1573
1576
|
value.factors,
|
|
1574
1577
|
getElements,
|
|
1575
1578
|
(factor, index) =>
|
|
1576
|
-
`Attempted to enumerate a set of the form s1 \\X s2 ... \\X sn,\nbut can't enumerate s${index}:\n${formatValue(factor)}`,
|
|
1579
|
+
`Attempted to enumerate a set of the form s1 \\X s2 ... \\X sn,\nbut can't enumerate s${index}:\n${prettyPrint(formatValue(factor))}`,
|
|
1577
1580
|
);
|
|
1578
1581
|
return getCartesianProduct(factors).map(createTuple);
|
|
1579
1582
|
}
|
|
1580
1583
|
case "FilteredSet":
|
|
1581
1584
|
if (!isSetValue(value.base) || isOverriddenSet(value.base)) {
|
|
1582
1585
|
throw new TlaEvaluationError(
|
|
1583
|
-
`Attempted to enumerate { x \\in S : p(x) } when S:\n${formatValue(value.base)}\nis not enumerable`,
|
|
1586
|
+
`Attempted to enumerate { x \\in S : p(x) } when S:\n${prettyPrint(formatValue(value.base))}\nis not enumerable`,
|
|
1584
1587
|
);
|
|
1585
1588
|
}
|
|
1586
1589
|
return toFiniteSet(
|
|
@@ -1604,12 +1607,12 @@ const enumerateSet = (
|
|
|
1604
1607
|
!isTlcEnumerable(value.right)
|
|
1605
1608
|
) {
|
|
1606
1609
|
throw new TlaEvaluationError(
|
|
1607
|
-
`Attempted to enumerate S \\cap T when neither S:\n${formatValue(value.left)}\nnor T:\n${formatValue(value.right)}\nis enumerable`,
|
|
1610
|
+
`Attempted to enumerate S \\cap T when neither S:\n${prettyPrint(formatValue(value.left))}\nnor T:\n${prettyPrint(formatValue(value.right))}\nis enumerable`,
|
|
1608
1611
|
);
|
|
1609
1612
|
}
|
|
1610
1613
|
if (value.operator === "\\" && !isTlcEnumerable(value.left)) {
|
|
1611
1614
|
throw new TlaEvaluationError(
|
|
1612
|
-
`Attempted to enumerate S \\ T when S:\n${formatValue(value.left)}\nis not enumerable.`,
|
|
1615
|
+
`Attempted to enumerate S \\ T when S:\n${prettyPrint(formatValue(value.left))}\nis not enumerable.`,
|
|
1613
1616
|
);
|
|
1614
1617
|
}
|
|
1615
1618
|
if (value.operator === "\\cup") {
|
|
@@ -1700,7 +1703,7 @@ const openStream = (value: Value): void => {
|
|
|
1700
1703
|
const listUnionLikeTlc = (union: SetOperationValue) => {
|
|
1701
1704
|
if (!isTlcEnumerable(union.left) || !isTlcEnumerable(union.right)) {
|
|
1702
1705
|
throw new TlaEvaluationError(
|
|
1703
|
-
`Attempted to enumerate S \\cup T when S:\n${formatValue(union.left)}\nand T:\n${formatValue(union.right)}\nare not both enumerable`,
|
|
1706
|
+
`Attempted to enumerate S \\cup T when S:\n${prettyPrint(formatValue(union.left))}\nand T:\n${prettyPrint(formatValue(union.right))}\nare not both enumerable`,
|
|
1704
1707
|
);
|
|
1705
1708
|
}
|
|
1706
1709
|
openStream(union.left);
|
|
@@ -1838,6 +1841,7 @@ const someElementOfStream = (value: ObjectValue, visit: (element: Value) => bool
|
|
|
1838
1841
|
|
|
1839
1842
|
export const isEmptySet = (value: Value): boolean => {
|
|
1840
1843
|
if (typeof value !== "object" || !isSetValue(value)) {
|
|
1844
|
+
setTrace.sets?.push(value);
|
|
1841
1845
|
throw new TlaEvaluationError(`Shouldn't call isEmpty() on value ${formatValue(value)}`);
|
|
1842
1846
|
}
|
|
1843
1847
|
switch (value.kind) {
|
|
@@ -1879,18 +1883,18 @@ const getProductCardinality = (
|
|
|
1879
1883
|
}, 1);
|
|
1880
1884
|
|
|
1881
1885
|
const describeOverflow = (value: Value) =>
|
|
1882
|
-
`Overflow when computing the number of elements in:\n${formatValue(value)}`;
|
|
1886
|
+
`Overflow when computing the number of elements in:\n${prettyPrint(formatValue(value))}`;
|
|
1883
1887
|
|
|
1884
1888
|
export const getCardinality = (value: Value, version?: TlcVersion): number => {
|
|
1885
1889
|
if (typeof value !== "object") {
|
|
1886
1890
|
throw new TlaEvaluationError(
|
|
1887
|
-
`Attempted to compute the number of elements in the ${describeKind(value)} ${formatValue(value)}.`,
|
|
1891
|
+
`Attempted to compute the number of elements in the ${describeKind(value)} ${prettyPrint(formatValue(value))}.`,
|
|
1888
1892
|
);
|
|
1889
1893
|
}
|
|
1890
1894
|
switch (value.kind) {
|
|
1891
1895
|
case "ModelValue":
|
|
1892
1896
|
throw new TlaEvaluationError(
|
|
1893
|
-
`Attempted to compute the number of elements in the model value ${formatValue(value)}.`,
|
|
1897
|
+
`Attempted to compute the number of elements in the model value ${prettyPrint(formatValue(value))}.`,
|
|
1894
1898
|
);
|
|
1895
1899
|
case "Function":
|
|
1896
1900
|
return value.domain.length;
|
|
@@ -1908,7 +1912,7 @@ export const getCardinality = (value: Value, version?: TlcVersion): number => {
|
|
|
1908
1912
|
case "InfiniteSet":
|
|
1909
1913
|
case "SequenceSet":
|
|
1910
1914
|
throw new TlaEvaluationError(
|
|
1911
|
-
`Attempted to compute the number of elements in the overridden value ${formatValue(value)}.`,
|
|
1915
|
+
`Attempted to compute the number of elements in the overridden value ${prettyPrint(formatValue(value))}.`,
|
|
1912
1916
|
);
|
|
1913
1917
|
case "Subset": {
|
|
1914
1918
|
const size = getCardinality(value.base, version);
|
|
@@ -1939,7 +1943,8 @@ export const getCardinality = (value: Value, version?: TlcVersion): number => {
|
|
|
1939
1943
|
return getProductCardinality(
|
|
1940
1944
|
value.factors,
|
|
1941
1945
|
version,
|
|
1942
|
-
() =>
|
|
1946
|
+
() =>
|
|
1947
|
+
`Overflow when computing the number of elements in ${prettyPrint(formatValue(value))}`,
|
|
1943
1948
|
);
|
|
1944
1949
|
default:
|
|
1945
1950
|
cacheSet(value);
|
|
@@ -1948,12 +1953,12 @@ export const getCardinality = (value: Value, version?: TlcVersion): number => {
|
|
|
1948
1953
|
};
|
|
1949
1954
|
|
|
1950
1955
|
const describeInfiniteCheck = (value: Value) =>
|
|
1951
|
-
`Attempted to check if the set ${formatValue(value)}is finite.`;
|
|
1956
|
+
`Attempted to check if the set ${prettyPrint(formatValue(value))}is finite.`;
|
|
1952
1957
|
|
|
1953
1958
|
export const isFiniteSet = (value: Value): boolean => {
|
|
1954
1959
|
if (typeof value !== "object" || value.kind === "ModelValue") {
|
|
1955
1960
|
throw new TlaEvaluationError(
|
|
1956
|
-
`Attempted to check if the ${describeKind(value)} ${formatValue(value)} is a finite set.`,
|
|
1961
|
+
`Attempted to check if the ${describeKind(value)} ${prettyPrint(formatValue(value))} is a finite set.`,
|
|
1957
1962
|
);
|
|
1958
1963
|
}
|
|
1959
1964
|
switch (value.kind) {
|
|
@@ -1964,7 +1969,7 @@ export const isFiniteSet = (value: Value): boolean => {
|
|
|
1964
1969
|
return true;
|
|
1965
1970
|
case "LazyFunction":
|
|
1966
1971
|
throw new TlaEvaluationError(
|
|
1967
|
-
`Attempted to check if the function:\n${formatValue(value)}\nis a finite set.`,
|
|
1972
|
+
`Attempted to check if the function:\n${prettyPrint(formatValue(value))}\nis a finite set.`,
|
|
1968
1973
|
);
|
|
1969
1974
|
case "InfiniteSet":
|
|
1970
1975
|
return false;
|
|
@@ -2010,7 +2015,7 @@ export const isFiniteSet = (value: Value): boolean => {
|
|
|
2010
2015
|
case "FilteredSet":
|
|
2011
2016
|
if (!isFiniteSet(value.base)) {
|
|
2012
2017
|
throw new TlaEvaluationError(
|
|
2013
|
-
`Attempted to check if expression of form {x \\in S : p(x)} is a finite set, but cannot check if S:\n${formatValue(value.base)}\nis finite.`,
|
|
2018
|
+
`Attempted to check if expression of form {x \\in S : p(x)} is a finite set, but cannot check if S:\n${prettyPrint(formatValue(value.base))}\nis finite.`,
|
|
2014
2019
|
);
|
|
2015
2020
|
}
|
|
2016
2021
|
return true;
|
|
@@ -2064,14 +2069,15 @@ export const getSequenceElements = (value: Value): Value[] | undefined => {
|
|
|
2064
2069
|
};
|
|
2065
2070
|
|
|
2066
2071
|
const describeNonSetMembership = (element: Value, value: Value) => {
|
|
2067
|
-
const prefix = `Attempted to check if the value:\n${formatValue(element)}\nis an element of the`;
|
|
2068
|
-
if (!isFunctionValue(value))
|
|
2072
|
+
const prefix = `Attempted to check if the value:\n${prettyPrint(formatValue(element))}\nis an element of the`;
|
|
2073
|
+
if (!isFunctionValue(value))
|
|
2074
|
+
return `${prefix} ${describeKind(value)} ${prettyPrint(formatValue(value))}`;
|
|
2069
2075
|
const functionClass = getFunctionClass(value);
|
|
2070
2076
|
if (functionClass === "record") {
|
|
2071
|
-
return `Attempted to check if element:\n${formatValue(element)}\nis in the record:\n${formatValue(value)}`;
|
|
2077
|
+
return `Attempted to check if element:\n${prettyPrint(formatValue(element))}\nis in the record:\n${prettyPrint(formatValue(value))}`;
|
|
2072
2078
|
}
|
|
2073
2079
|
if (functionClass === "tuple") return "Attempted to check set membership in a tuple value.";
|
|
2074
|
-
return `${prefix} function ${formatValue(value)}`;
|
|
2080
|
+
return `${prefix} function ${prettyPrint(formatValue(value))}`;
|
|
2075
2081
|
};
|
|
2076
2082
|
|
|
2077
2083
|
interface TracedCallStack {
|
|
@@ -2177,7 +2183,7 @@ const isElementOfAnySet = (element: Value, set: Value): boolean => {
|
|
|
2177
2183
|
if (typeof element === "number") return element >= set.low && element <= set.high;
|
|
2178
2184
|
if (set.low <= set.high && (!isModelValue(element) || element.type !== undefined)) {
|
|
2179
2185
|
throw new TlaEvaluationError(
|
|
2180
|
-
`Attempted to check if the value:\n${formatValue(element)}\nis in the integer interval ${formatValue(set)}`,
|
|
2186
|
+
`Attempted to check if the value:\n${prettyPrint(formatValue(element))}\nis in the integer interval ${prettyPrint(formatValue(set))}`,
|
|
2181
2187
|
);
|
|
2182
2188
|
}
|
|
2183
2189
|
return false;
|
|
@@ -2188,7 +2194,7 @@ const isElementOfAnySet = (element: Value, set: Value): boolean => {
|
|
|
2188
2194
|
set.name === "STRING" ? typeof element === "string" : typeof element === "number";
|
|
2189
2195
|
if (!isMemberType) {
|
|
2190
2196
|
throw new TlaModuleError(
|
|
2191
|
-
`Attempted to check if the value:\n${formatValue(element)}\nis an element of ${set.name}.`,
|
|
2197
|
+
`Attempted to check if the value:\n${prettyPrint(formatValue(element))}\nis an element of ${set.name}.`,
|
|
2192
2198
|
);
|
|
2193
2199
|
}
|
|
2194
2200
|
return set.name !== "Nat" || (typeof element === "number" && element >= 0);
|
|
@@ -2223,7 +2229,7 @@ const isElementOfAnySet = (element: Value, set: Value): boolean => {
|
|
|
2223
2229
|
if (!functionValue || !isRecordDomain(functionValue.domain)) {
|
|
2224
2230
|
if (isModelValue(element)) return isModelValueMember(element, set);
|
|
2225
2231
|
throw new TlaEvaluationError(
|
|
2226
|
-
`Attempted to check if non-record\n${formatValue(element)}\nis in the set of records:\n${formatValue(set)}`,
|
|
2232
|
+
`Attempted to check if non-record\n${formatValue(element)}\nis in the set of records:\n${prettyPrint(formatValue(set))}`,
|
|
2227
2233
|
);
|
|
2228
2234
|
}
|
|
2229
2235
|
return (
|
|
@@ -2243,7 +2249,7 @@ const isElementOfAnySet = (element: Value, set: Value): boolean => {
|
|
|
2243
2249
|
if (isModelValue(element)) return isModelValueMember(element, set);
|
|
2244
2250
|
if (isFunction) return false;
|
|
2245
2251
|
throw new TlaEvaluationError(
|
|
2246
|
-
`Attempted to check if non-tuple\n${formatValue(element)}\nis in the set of tuples:\n${formatValue(set)}`,
|
|
2252
|
+
`Attempted to check if non-tuple\n${prettyPrint(formatValue(element))}\nis in the set of tuples:\n${prettyPrint(formatValue(set))}`,
|
|
2247
2253
|
);
|
|
2248
2254
|
}
|
|
2249
2255
|
return (
|
|
@@ -2263,7 +2269,7 @@ const isElementOfAnySet = (element: Value, set: Value): boolean => {
|
|
|
2263
2269
|
case "Union": {
|
|
2264
2270
|
if (!isTlcEnumerable(set.base)) {
|
|
2265
2271
|
throw new TlaEvaluationError(
|
|
2266
|
-
`Attempted to check if:\n ${formatValue(element)}\nis an element of the non-enumerable set:\n ${formatUnion(set)}`,
|
|
2272
|
+
`Attempted to check if:\n ${prettyPrint(formatValue(element))}\nis an element of the non-enumerable set:\n ${prettyPrint(formatUnion(set))}`,
|
|
2267
2273
|
);
|
|
2268
2274
|
}
|
|
2269
2275
|
const sets = toFiniteSet(set.base).elements;
|
|
@@ -2433,6 +2439,24 @@ const findKeyIndexLikeTlc = (
|
|
|
2433
2439
|
return computeLikeTlcOnFailure(findDomainIndex, failKeyLikeTlc, functionValue, argument);
|
|
2434
2440
|
};
|
|
2435
2441
|
|
|
2442
|
+
const describeBoundArgument = (
|
|
2443
|
+
functionValue: LazyFunctionValue,
|
|
2444
|
+
position: string,
|
|
2445
|
+
shown: Value,
|
|
2446
|
+
problem: string,
|
|
2447
|
+
) =>
|
|
2448
|
+
`In applying the function\n${prettyPrint(formatValue(functionValue))},\nthe ${position} is:\n${prettyPrint(formatValue(shown))}\nwhich ${problem}.\n`;
|
|
2449
|
+
|
|
2450
|
+
const createArgumentListError = (functionValue: LazyFunctionValue, argument: Value) =>
|
|
2451
|
+
new TlaEvaluationError(
|
|
2452
|
+
describeBoundArgument(
|
|
2453
|
+
functionValue,
|
|
2454
|
+
"argument list",
|
|
2455
|
+
argument,
|
|
2456
|
+
"does not match its formal parameter",
|
|
2457
|
+
),
|
|
2458
|
+
);
|
|
2459
|
+
|
|
2436
2460
|
// Deviation from TLC: FcnLambdaValue#apply indexes past an argument tuple shorter than the bounds and ignores a longer one, where this rejects the list.
|
|
2437
2461
|
const checkBoundArguments = (
|
|
2438
2462
|
functionValue: LazyFunctionValue,
|
|
@@ -2441,25 +2465,20 @@ const checkBoundArguments = (
|
|
|
2441
2465
|
) => {
|
|
2442
2466
|
const domain = functionValue.domain;
|
|
2443
2467
|
const elements = getSequenceElements(argument);
|
|
2444
|
-
|
|
2445
|
-
`In applying the function\n${prettyPrint(formatValue(functionValue))},\nthe ${position} is:\n${prettyPrint(formatValue(shown))}\nwhich ${problem}.\n`;
|
|
2446
|
-
const createListError = () =>
|
|
2447
|
-
new TlaEvaluationError(
|
|
2448
|
-
describe("argument list", argument, "does not match its formal parameter"),
|
|
2449
|
-
);
|
|
2450
|
-
if (elements === undefined) throw createListError();
|
|
2468
|
+
if (elements === undefined) throw createArgumentListError(functionValue, argument);
|
|
2451
2469
|
if (typeof domain !== "object" || domain.kind !== "ProductSet") {
|
|
2452
2470
|
throw new TlaEvaluationError(
|
|
2453
2471
|
`Attempted to apply a function to ${formatValue(argument)}, which is not in its domain`,
|
|
2454
2472
|
);
|
|
2455
2473
|
}
|
|
2456
2474
|
tupleLengths.forEach((tupleLength, index) => {
|
|
2457
|
-
if (index >= elements.length) throw
|
|
2475
|
+
if (index >= elements.length) throw createArgumentListError(functionValue, argument);
|
|
2458
2476
|
const element = elements[index];
|
|
2459
2477
|
const position = `argument number ${index + 1}`;
|
|
2460
2478
|
if (!isElementOf(element, domain.factors[index])) {
|
|
2461
2479
|
throw new TlaEvaluationError(
|
|
2462
|
-
|
|
2480
|
+
describeBoundArgument(
|
|
2481
|
+
functionValue,
|
|
2463
2482
|
position,
|
|
2464
2483
|
element,
|
|
2465
2484
|
tupleLength === undefined
|
|
@@ -2470,11 +2489,18 @@ const checkBoundArguments = (
|
|
|
2470
2489
|
}
|
|
2471
2490
|
if (tupleLength !== undefined && getSequenceElements(element)?.length !== tupleLength) {
|
|
2472
2491
|
throw new TlaEvaluationError(
|
|
2473
|
-
|
|
2492
|
+
describeBoundArgument(
|
|
2493
|
+
functionValue,
|
|
2494
|
+
position,
|
|
2495
|
+
element,
|
|
2496
|
+
"does not match its formal parameter",
|
|
2497
|
+
),
|
|
2474
2498
|
);
|
|
2475
2499
|
}
|
|
2476
2500
|
});
|
|
2477
|
-
if (elements.length > tupleLengths.length)
|
|
2501
|
+
if (elements.length > tupleLengths.length) {
|
|
2502
|
+
throw createArgumentListError(functionValue, argument);
|
|
2503
|
+
}
|
|
2478
2504
|
};
|
|
2479
2505
|
|
|
2480
2506
|
const isOutsideLambdaDomain = (functionValue: FunctionValue, argument: Value) =>
|
|
@@ -2552,6 +2578,12 @@ export const updateFunction = (
|
|
|
2552
2578
|
functionValue.kind === "LazyFunction" &&
|
|
2553
2579
|
(isKeptLazy || functionValue.enumerated === undefined);
|
|
2554
2580
|
if (isLazy) {
|
|
2581
|
+
if (
|
|
2582
|
+
functionValue.boundTupleLengths !== undefined &&
|
|
2583
|
+
getSequenceElements(argument) === undefined
|
|
2584
|
+
) {
|
|
2585
|
+
throw createArgumentListError(functionValue, argument);
|
|
2586
|
+
}
|
|
2555
2587
|
if (!isElementOf(argument, functionValue.domain)) return functionValue;
|
|
2556
2588
|
const updated = update(functionValue.apply(argument));
|
|
2557
2589
|
return setFunctionClass<LazyFunctionValue>(
|
|
@@ -2665,7 +2697,7 @@ const fingerprintValue = (value: Value): void => {
|
|
|
2665
2697
|
if (typeof value !== "object" || value.kind === "ModelValue") return;
|
|
2666
2698
|
if (value.kind === "InfiniteSet" || value.kind === "SequenceSet") {
|
|
2667
2699
|
throw new TlaEvaluationError(
|
|
2668
|
-
`TLC has found a state in which the value of a variable contains ${formatValue(value)}`,
|
|
2700
|
+
`TLC has found a state in which the value of a variable contains ${prettyPrint(formatValue(value))}`,
|
|
2669
2701
|
);
|
|
2670
2702
|
}
|
|
2671
2703
|
if (isSetValue(value)) {
|
|
@@ -2906,9 +2938,11 @@ const toPrintedFunction = (value: LazyFunctionValue) => {
|
|
|
2906
2938
|
export const formatNormalizedCopies = (values: Value[]) => {
|
|
2907
2939
|
const markedSets: SetValue[] = [];
|
|
2908
2940
|
const writtenFunctions: [FunctionValue, Value[]][] = [];
|
|
2909
|
-
const
|
|
2941
|
+
const copiedFunctions: LazyFunctionValue[] = [];
|
|
2942
|
+
// TLC prints a deep copy, which copies functions but shares sets, so it caches only the functions inside a set.
|
|
2943
|
+
const normalize = (value: Value, isWrittenOrderKept: boolean, isCopied: boolean): void => {
|
|
2910
2944
|
if (typeof value !== "object") return;
|
|
2911
|
-
const normalizeInner = (inner: Value) => normalize(inner, isWrittenOrderKept);
|
|
2945
|
+
const normalizeInner = (inner: Value) => normalize(inner, isWrittenOrderKept, false);
|
|
2912
2946
|
switch (value.kind) {
|
|
2913
2947
|
case "Set":
|
|
2914
2948
|
value.elements.forEach(normalizeInner);
|
|
@@ -2922,15 +2956,16 @@ export const formatNormalizedCopies = (values: Value[]) => {
|
|
|
2922
2956
|
return;
|
|
2923
2957
|
case "Function": {
|
|
2924
2958
|
const isRangeWrittenOrderKept = isWrittenOrderKept || getFunctionClass(value) === "lambda";
|
|
2925
|
-
value.range.forEach((inner) => normalize(inner, isRangeWrittenOrderKept));
|
|
2959
|
+
value.range.forEach((inner) => normalize(inner, isRangeWrittenOrderKept, isCopied));
|
|
2926
2960
|
if (isWrittenOrderKept || value.writtenKeys === undefined) return;
|
|
2927
2961
|
writtenFunctions.push([value, value.writtenKeys]);
|
|
2928
2962
|
value.writtenKeys = undefined;
|
|
2929
2963
|
return;
|
|
2930
2964
|
}
|
|
2931
2965
|
case "LazyFunction":
|
|
2932
|
-
if (value.enumerated) normalize(value.enumerated, true);
|
|
2933
|
-
|
|
2966
|
+
if (value.enumerated) return normalize(value.enumerated, true, isCopied);
|
|
2967
|
+
if (isCopied) copiedFunctions.push(value);
|
|
2968
|
+
normalizeInner(value.domain);
|
|
2934
2969
|
return;
|
|
2935
2970
|
case "SetOperation":
|
|
2936
2971
|
normalizeInner(value.left);
|
|
@@ -2957,12 +2992,15 @@ export const formatNormalizedCopies = (values: Value[]) => {
|
|
|
2957
2992
|
}
|
|
2958
2993
|
};
|
|
2959
2994
|
try {
|
|
2960
|
-
values.forEach((value) => normalize(value, false));
|
|
2995
|
+
values.forEach((value) => normalize(value, false, true));
|
|
2961
2996
|
return values.map((value) => formatValue(value, true, true));
|
|
2962
2997
|
} finally {
|
|
2963
2998
|
markedSets.forEach((set) => {
|
|
2964
2999
|
set.isNormalized = false;
|
|
2965
3000
|
});
|
|
3001
|
+
copiedFunctions.forEach((copied) => {
|
|
3002
|
+
copied.enumerated = undefined;
|
|
3003
|
+
});
|
|
2966
3004
|
writtenFunctions.forEach((entry) => {
|
|
2967
3005
|
entry[0].writtenKeys = entry[1];
|
|
2968
3006
|
});
|