tla-ts 0.0.10-dev.a4b81b6d0 → 0.0.10-dev.a5705bfbf
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 +31 -31
- package/dist/deciders.js +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -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 +42 -42
- package/dist/prove.js +30 -30
- package/dist/run.cjs +42 -42
- package/dist/run.js +42 -42
- package/dist/transfer.cjs +31 -29
- package/dist/transfer.js +43 -41
- package/dist/worker.cjs +4 -4
- package/dist/worker.js +4 -4
- package/package.json +1 -1
- package/src/ast.ts +10 -1
- package/src/check-failure.ts +5 -6
- package/src/check-trace.ts +4 -4
- package/src/check.ts +78 -90
- package/src/cli/tlc-output.ts +16 -2
- package/src/cli/tlc.ts +2 -2
- package/src/codegen.ts +10 -16
- package/src/coverage.ts +190 -1
- package/src/dependencies.ts +14 -2
- package/src/dfid.ts +80 -27
- package/src/environment.ts +30 -1
- package/src/evaluate.ts +223 -47
- package/src/exit-codes.ts +3 -4
- package/src/instances.ts +11 -1
- package/src/levels.ts +48 -7
- package/src/liveness-checker.ts +123 -70
- package/src/liveness.ts +4 -1
- package/src/obligations/source.ts +2 -0
- package/src/parser.ts +3 -0
- package/src/prover/smt/solver/card2bv.ts +7 -4
- package/src/prover/smt/solver/context.ts +20 -4
- package/src/prover/smt/solver/dependent-expr-state.ts +18 -12
- package/src/prover/smt/solver/dt2bv-tactic.ts +36 -20
- package/src/prover/smt/solver/fd-solver.ts +146 -39
- package/src/prover/smt/solver/maxcore.ts +2 -1
- package/src/prover/smt/solver/maxsmt-base.ts +1 -0
- package/src/prover/smt/solver/model-checker.ts +1 -1
- package/src/prover/smt/solver/muz/dl-context.ts +12 -40
- package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +1 -1
- package/src/prover/smt/solver/muz/dl-rule.ts +6 -7
- package/src/prover/smt/solver/muz/hnf.ts +2 -2
- package/src/prover/smt/solver/muz/horn-tactic.ts +14 -1
- package/src/prover/smt/solver/muz/rule-properties.ts +22 -0
- package/src/prover/smt/solver/muz/spacer-prop-solver.ts +1 -1
- package/src/prover/smt/solver/opt-context.ts +1 -0
- package/src/prover/smt/solver/opt-solver.ts +1 -1
- package/src/prover/smt/solver/parallel-tactic.ts +1 -1
- package/src/prover/smt/solver/qsat.ts +7 -2
- package/src/prover/smt/solver/rewriter-tpl.ts +7 -6
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +45 -26
- package/src/prover/smt/solver/sat/sat-tactic.ts +4 -2
- package/src/prover/smt/solver/sat/sat2goal.ts +10 -7
- package/src/prover/smt/solver/smt-consequences.ts +1 -1
- package/src/prover/smt/solver/smt-kernel.ts +9 -2
- package/src/prover/smt/solver/smtlib-parser.ts +6 -2
- package/src/prover/smt/solver/smtlib-script.ts +197 -73
- package/src/prover/smt/solver/tactic.ts +64 -37
- package/src/resolve.ts +143 -39
- package/src/sany/generator-expressions.ts +2 -0
- package/src/sany/generator-proofs.ts +1 -0
- package/src/search.ts +109 -23
- package/src/simulate.ts +114 -124
- package/src/spec-description.ts +3 -0
- package/src/subexpressions.ts +168 -63
- package/src/successors.ts +30 -10
- package/src/tlc/replay.ts +45 -29
- package/src/trace-liveness.ts +529 -0
- package/src/typed-tier.ts +14 -4
- package/src/values.ts +15 -1
package/src/resolve.ts
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
type UseOrHide,
|
|
24
24
|
} from "./ast";
|
|
25
25
|
import { formatRange, TlaSyntaxError, type SanyError } from "./errors";
|
|
26
|
+
import { parenthesizedRanges } from "./parser";
|
|
26
27
|
import { resolveSynonym } from "./tlc/jar-data";
|
|
27
28
|
|
|
28
29
|
export type SymbolKind =
|
|
@@ -60,7 +61,7 @@ interface LocalName extends Binding {
|
|
|
60
61
|
parent: LocalName | undefined;
|
|
61
62
|
goal?: Goal;
|
|
62
63
|
isPending?: boolean;
|
|
63
|
-
|
|
64
|
+
nonFactStep?: "Use" | "Hide" | "Instance" | "Define";
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
interface ModuleBinding extends Binding {
|
|
@@ -73,6 +74,7 @@ interface Unit {
|
|
|
73
74
|
getInstance: (instance: Instance) => InstancedModule;
|
|
74
75
|
definitions: Map<string, Definition>;
|
|
75
76
|
getKey: (definition: Definition) => string;
|
|
77
|
+
isModuleKnown: (name: string, location: SourceLocation) => boolean;
|
|
76
78
|
location: SourceLocation;
|
|
77
79
|
self: Definition | undefined;
|
|
78
80
|
facts: Set<string>;
|
|
@@ -125,13 +127,12 @@ interface SelectionArgument {
|
|
|
125
127
|
range: SourceRange | undefined;
|
|
126
128
|
}
|
|
127
129
|
|
|
128
|
-
export const selections = new
|
|
130
|
+
export const selections = new WeakMap<Expression, Expression>();
|
|
129
131
|
export const selectionErrors = new WeakMap<Expression, SelectionError>();
|
|
130
132
|
export const operatorSelectionErrors = new WeakMap<Expression, SanyError>();
|
|
131
133
|
export const factReferences = new WeakMap<Fact[], Fact[]>();
|
|
132
134
|
export const selectionArguments = new WeakMap<Expression, SelectionArgument>();
|
|
133
135
|
export const nullSelections = new WeakMap<Expression, NullSelection[]>();
|
|
134
|
-
export const selectionSources = new WeakMap<Expression, Expression>();
|
|
135
136
|
const unresolvedExpressions = new WeakSet<Expression>();
|
|
136
137
|
const emptyExpressions = new WeakSet<Expression>();
|
|
137
138
|
|
|
@@ -166,7 +167,7 @@ const CORE_SYMBOLS: Symbols = new Map([
|
|
|
166
167
|
export const isBefore = (left: SourceLocation, right: SourceLocation) =>
|
|
167
168
|
left.line < right.line || (left.line === right.line && left.column < right.column);
|
|
168
169
|
|
|
169
|
-
const compareLocations = (left: SourceLocation, right: SourceLocation) =>
|
|
170
|
+
export const compareLocations = (left: SourceLocation, right: SourceLocation) =>
|
|
170
171
|
isBefore(left, right) ? -1 : isBefore(right, left) ? 1 : 0;
|
|
171
172
|
|
|
172
173
|
export const getArity = (definition: Definition) =>
|
|
@@ -464,6 +465,7 @@ export const getOperands = (expression: Expression): Expression[] | undefined =>
|
|
|
464
465
|
case "Enabled":
|
|
465
466
|
case "Always":
|
|
466
467
|
case "Eventually":
|
|
468
|
+
case "Selection":
|
|
467
469
|
return [expression.expression];
|
|
468
470
|
case "BoxAction":
|
|
469
471
|
case "AngleAction":
|
|
@@ -492,7 +494,7 @@ const isInScopeOfDeclaration = (assumeProve: AssumeProve, clause: number) =>
|
|
|
492
494
|
|
|
493
495
|
const findLabel = (expression: Expression, name: string): LabelExpression | undefined => {
|
|
494
496
|
if (expression.kind === "Label") return expression.name === name ? expression : undefined;
|
|
495
|
-
if (expression.kind === "Lambda") return undefined;
|
|
497
|
+
if (expression.kind === "Lambda" || expression.kind === "Selection") return undefined;
|
|
496
498
|
if (expression.kind === "Let") return findLabel(expression.body, name);
|
|
497
499
|
return getChildren(expression).reduce<LabelExpression | undefined>(
|
|
498
500
|
(found, child) => found ?? findLabel(child, name),
|
|
@@ -778,6 +780,15 @@ const checkReference = (
|
|
|
778
780
|
return goal && { node: checkSelection(expression, selectors, goal, unit, isFact) };
|
|
779
781
|
};
|
|
780
782
|
|
|
783
|
+
const isInstanceName = (name: string, scope: LocalName | undefined, unit: Unit) => {
|
|
784
|
+
const binding = lookupLocal(scope, name) ?? getModuleBinding(name, unit, undefined);
|
|
785
|
+
if (binding) return binding.kind === "Instance";
|
|
786
|
+
return (
|
|
787
|
+
findInstance(name, scope, unit) !== undefined &&
|
|
788
|
+
[...unit.bindings.keys()].some((key) => key.startsWith(`${name}!`))
|
|
789
|
+
);
|
|
790
|
+
};
|
|
791
|
+
|
|
781
792
|
const getSymbolArity = (
|
|
782
793
|
expression: Expression & { kind: "Identifier" | "Apply" | "OperatorReference" },
|
|
783
794
|
name: string,
|
|
@@ -790,7 +801,7 @@ const getSymbolArity = (
|
|
|
790
801
|
if (renamed !== undefined) return renamed;
|
|
791
802
|
if (isKey(name)) return expression.kind === "Apply" ? expression.args.length : 0;
|
|
792
803
|
const local = lookupLocal(scope, name);
|
|
793
|
-
if (local?.
|
|
804
|
+
if (local?.nonFactStep) {
|
|
794
805
|
unit.errors.push({
|
|
795
806
|
location: formatRange(getSpelledNameRange(expression, name)),
|
|
796
807
|
message: "Step number of non-expression step used as an expression.",
|
|
@@ -808,6 +819,20 @@ const getSymbolArity = (
|
|
|
808
819
|
if (checkReference(expression, scope, unit, false) || (isStepName(name) && local)) {
|
|
809
820
|
return expression.kind === "Apply" ? expression.args.length : 0;
|
|
810
821
|
}
|
|
822
|
+
if (isInstanceName(name, scope, unit)) {
|
|
823
|
+
const range = getSpelledNameRange(expression, name);
|
|
824
|
+
unit.errors.push({
|
|
825
|
+
location: formatRange({
|
|
826
|
+
...range,
|
|
827
|
+
start: {
|
|
828
|
+
line: range.end.line,
|
|
829
|
+
column: range.end.column - name.slice(name.lastIndexOf("!") + 1).length + 1,
|
|
830
|
+
},
|
|
831
|
+
}),
|
|
832
|
+
message: `Operator name ${name} is incomplete.`,
|
|
833
|
+
});
|
|
834
|
+
return undefined;
|
|
835
|
+
}
|
|
811
836
|
if (local && expression.kind !== "OperatorReference") expression.resolution = LOCAL_RESOLUTION;
|
|
812
837
|
if (local) return local.arity;
|
|
813
838
|
const symbol = findSymbol(name, unit);
|
|
@@ -1179,9 +1204,36 @@ const matchArgument = (
|
|
|
1179
1204
|
resolveExpressionArgument(arg, scope, unit);
|
|
1180
1205
|
return true;
|
|
1181
1206
|
}
|
|
1207
|
+
const parenthesized = parenthesizedRanges.get(arg);
|
|
1208
|
+
if (parenthesized) {
|
|
1209
|
+
report(
|
|
1210
|
+
parenthesized,
|
|
1211
|
+
`An expression appears as argument number ${index + 1} (counting from 1) to operator '${operator}', in a position an operator is required.`,
|
|
1212
|
+
);
|
|
1213
|
+
return false;
|
|
1214
|
+
}
|
|
1215
|
+
const reference = selections.get(arg) ?? arg;
|
|
1216
|
+
// SANY reads a reference that ends in arguments as an application, not as a selector's arguments.
|
|
1217
|
+
const selectors =
|
|
1218
|
+
reference.kind === "Subexpression" ||
|
|
1219
|
+
(reference.kind === "Apply" && reference.argumentCounts?.at(-1) === 0)
|
|
1220
|
+
? getSelectors(reference)
|
|
1221
|
+
: [];
|
|
1222
|
+
const selectorIndex = selectors.findIndex(
|
|
1223
|
+
(selector) => "args" in selector && selector.args.length > 0,
|
|
1224
|
+
);
|
|
1225
|
+
if (selectorIndex !== -1 && isReference(reference)) {
|
|
1226
|
+
const selector = selectors[selectorIndex];
|
|
1227
|
+
report(
|
|
1228
|
+
reference.selectorRanges?.[selectorIndex],
|
|
1229
|
+
`Selector \`${selector.kind === "Name" ? selector.name : "!(...)"}' should not have argument(s).`,
|
|
1230
|
+
);
|
|
1231
|
+
return false;
|
|
1232
|
+
}
|
|
1182
1233
|
if (arg.kind === "Lambda") {
|
|
1183
1234
|
if (selections.has(arg)) resolveExpression(arg, scope, unit);
|
|
1184
1235
|
else resolveLambda(arg, scope, unit);
|
|
1236
|
+
if (findNullError(nullSelections.get(arg))) return false;
|
|
1185
1237
|
const isMatched = arg.params.length === expected;
|
|
1186
1238
|
if (!isMatched && selections.has(arg)) {
|
|
1187
1239
|
report(range, `Expected arity ${expected} but found operator of arity ${arg.params.length}.`);
|
|
@@ -1195,16 +1247,16 @@ const matchArgument = (
|
|
|
1195
1247
|
}
|
|
1196
1248
|
return isMatched;
|
|
1197
1249
|
}
|
|
1250
|
+
if (reference !== arg) {
|
|
1251
|
+
const failed = findNullError(nullSelections.get(arg));
|
|
1252
|
+
if (failed) unit.errors.push(failed);
|
|
1253
|
+
if (!failed) {
|
|
1254
|
+
report(reference.location.range, `Expected arity ${expected} but found operator of arity 0.`);
|
|
1255
|
+
}
|
|
1256
|
+
return false;
|
|
1257
|
+
}
|
|
1198
1258
|
if (arg.kind === "Subexpression") {
|
|
1199
1259
|
resolveExpression(arg, scope, unit);
|
|
1200
|
-
return true;
|
|
1201
|
-
}
|
|
1202
|
-
if (arg.kind === "Apply" && arg.argumentCounts?.at(-1) === 0) {
|
|
1203
|
-
const selectorIndex = arg.argumentCounts.findIndex((count) => count > 0);
|
|
1204
|
-
report(
|
|
1205
|
-
arg.selectorRanges?.[selectorIndex],
|
|
1206
|
-
`Selector \`${arg.operator.split("!")[selectorIndex]}' should not have argument(s).`,
|
|
1207
|
-
);
|
|
1208
1260
|
return false;
|
|
1209
1261
|
}
|
|
1210
1262
|
if (arg.kind !== "Identifier" && arg.kind !== "OperatorReference") {
|
|
@@ -1344,12 +1396,6 @@ const resolveExpression = (
|
|
|
1344
1396
|
unit.errors.push(failed);
|
|
1345
1397
|
return;
|
|
1346
1398
|
}
|
|
1347
|
-
const source = selectionSources.get(expression);
|
|
1348
|
-
if (source) {
|
|
1349
|
-
Object.assign(expression, source);
|
|
1350
|
-
const arity = renamedArities.get(source);
|
|
1351
|
-
if (arity !== undefined) renamedArities.set(expression, arity);
|
|
1352
|
-
}
|
|
1353
1399
|
resolveExpression(expression, scope, { ...unit, isGenerated: true });
|
|
1354
1400
|
return;
|
|
1355
1401
|
}
|
|
@@ -1538,6 +1584,8 @@ const resolveExpression = (
|
|
|
1538
1584
|
case "Subexpression":
|
|
1539
1585
|
if (isSubexpressionReported(expression, scope, unit)) emptyExpressions.add(expression);
|
|
1540
1586
|
return;
|
|
1587
|
+
case "Selection":
|
|
1588
|
+
return;
|
|
1541
1589
|
}
|
|
1542
1590
|
};
|
|
1543
1591
|
|
|
@@ -1621,7 +1669,7 @@ const isSubexpressionReported = (
|
|
|
1621
1669
|
});
|
|
1622
1670
|
return true;
|
|
1623
1671
|
}
|
|
1624
|
-
if (binding && (!SELECTABLE_KINDS.has(binding.kind) || local?.
|
|
1672
|
+
if (binding && (!SELECTABLE_KINDS.has(binding.kind) || local?.nonFactStep)) {
|
|
1625
1673
|
reportUnselectable(head.name, range, unit);
|
|
1626
1674
|
return true;
|
|
1627
1675
|
}
|
|
@@ -1646,8 +1694,23 @@ const isSubexpressionReported = (
|
|
|
1646
1694
|
return selected ? selected.node === undefined : false;
|
|
1647
1695
|
};
|
|
1648
1696
|
|
|
1697
|
+
const reportUnknownModule = (fact: Fact & { kind: "ModuleFact" }, unit: Unit) => {
|
|
1698
|
+
const range = fact.location.range;
|
|
1699
|
+
if (unit.isModuleKnown(fact.name, fact.location) || !range) return;
|
|
1700
|
+
unit.errors.push({
|
|
1701
|
+
location: formatRange({
|
|
1702
|
+
...range,
|
|
1703
|
+
start: { line: range.end.line, column: range.end.column - fact.name.length + 1 },
|
|
1704
|
+
}),
|
|
1705
|
+
message: `Module \`${fact.name}' used without being extended or instantiated.`,
|
|
1706
|
+
});
|
|
1707
|
+
};
|
|
1708
|
+
|
|
1649
1709
|
const checkFact = (fact: Fact, reference: Fact, scope: LocalName | undefined, unit: Unit) => {
|
|
1650
|
-
if (fact.kind === "ModuleFact")
|
|
1710
|
+
if (fact.kind === "ModuleFact") {
|
|
1711
|
+
reportUnknownModule(fact, unit);
|
|
1712
|
+
return undefined;
|
|
1713
|
+
}
|
|
1651
1714
|
if (fact.kind === "ExceptAt" && fact.location.range) {
|
|
1652
1715
|
unit.errors.push({
|
|
1653
1716
|
location: formatRange(fact.location.range),
|
|
@@ -1656,6 +1719,10 @@ const checkFact = (fact: Fact, reference: Fact, scope: LocalName | undefined, un
|
|
|
1656
1719
|
return BUILTIN_LOCATION;
|
|
1657
1720
|
}
|
|
1658
1721
|
const hidden = getHiddenExpressionLocation(fact, reference, scope, unit);
|
|
1722
|
+
if (selections.has(fact)) {
|
|
1723
|
+
resolveExpression(fact, scope, unit);
|
|
1724
|
+
return hidden;
|
|
1725
|
+
}
|
|
1659
1726
|
if (isInstanceArityReported(fact, scope, unit)) return hidden;
|
|
1660
1727
|
const selected = checkReference(fact, scope, unit, true);
|
|
1661
1728
|
if (selected) {
|
|
@@ -1669,31 +1736,48 @@ const checkFact = (fact: Fact, reference: Fact, scope: LocalName | undefined, un
|
|
|
1669
1736
|
return isSubexpressionReported(fact, scope, unit) ? BUILTIN_LOCATION : hidden;
|
|
1670
1737
|
}
|
|
1671
1738
|
const name = fact.kind === "Identifier" ? fact.name : fact.kind === "Apply" ? fact.operator : "";
|
|
1672
|
-
if (fact.kind === "Identifier" && lookupLocal(scope, name)?.
|
|
1739
|
+
if (fact.kind === "Identifier" && lookupLocal(scope, name)?.nonFactStep) {
|
|
1673
1740
|
unit.errors.push({
|
|
1674
1741
|
location: formatRange(getSpelledNameRange(fact, name)),
|
|
1675
1742
|
message: "Step number of non-fact used as a fact",
|
|
1676
1743
|
});
|
|
1677
1744
|
return BUILTIN_LOCATION;
|
|
1678
1745
|
}
|
|
1679
|
-
if (
|
|
1746
|
+
if (
|
|
1747
|
+
!isFact(name, unit) &&
|
|
1748
|
+
!lookupLocal(scope, name)?.goal &&
|
|
1749
|
+
!(fact.kind === "Identifier" && isInstanceName(name, scope, unit))
|
|
1750
|
+
) {
|
|
1751
|
+
resolveExpression(fact, scope, unit);
|
|
1752
|
+
}
|
|
1680
1753
|
return hidden;
|
|
1681
1754
|
};
|
|
1682
1755
|
|
|
1683
1756
|
const isDefinitionEntry = (def: Fact, scope: LocalName | undefined, unit: Unit) => {
|
|
1757
|
+
if (def.kind === "ModuleFact") {
|
|
1758
|
+
reportUnknownModule(def, unit);
|
|
1759
|
+
return unit.isModuleKnown(def.name, def.location);
|
|
1760
|
+
}
|
|
1684
1761
|
const range = def.location.range;
|
|
1685
1762
|
const name =
|
|
1686
1763
|
def.kind === "Identifier" ? def.name : def.kind === "OperatorReference" ? def.operator : "";
|
|
1687
1764
|
if (name === "" || !range) return true;
|
|
1688
|
-
const
|
|
1689
|
-
|
|
1690
|
-
if (binding === undefined &&
|
|
1765
|
+
const local = lookupLocal(scope, name);
|
|
1766
|
+
const binding = local ?? findSymbol(name, unit) ?? getModuleBinding(name, unit, range);
|
|
1767
|
+
if (binding === undefined && isFact(name, unit)) return true;
|
|
1691
1768
|
if (binding === undefined) {
|
|
1692
1769
|
unit.errors.push({
|
|
1693
1770
|
location: formatRange(range),
|
|
1694
1771
|
message: `Unknown operator: \`${resolveSynonym(name)}'.`,
|
|
1695
1772
|
});
|
|
1696
1773
|
}
|
|
1774
|
+
if (local?.nonFactStep === "Define") return true;
|
|
1775
|
+
if (local?.nonFactStep) {
|
|
1776
|
+
unit.errors.push({
|
|
1777
|
+
location: formatRange(range),
|
|
1778
|
+
message: "DEF clause entry refers to a non-definition step.",
|
|
1779
|
+
});
|
|
1780
|
+
}
|
|
1697
1781
|
if (binding && SELECTABLE_KINDS.has(binding.kind) && !isStepName(name)) return true;
|
|
1698
1782
|
unit.errors.push({
|
|
1699
1783
|
location: formatRange(range),
|
|
@@ -1710,7 +1794,9 @@ const getHiddenExpressionLocation = (
|
|
|
1710
1794
|
) => {
|
|
1711
1795
|
const range = fact.location.range && formatRange(fact.location.range);
|
|
1712
1796
|
if (selections.has(fact)) {
|
|
1713
|
-
return
|
|
1797
|
+
return findNullError(nullSelections.get(fact))
|
|
1798
|
+
? BUILTIN_LOCATION
|
|
1799
|
+
: reference.location.range && formatRange(reference.location.range);
|
|
1714
1800
|
}
|
|
1715
1801
|
if (selectionErrors.has(fact) || fact.kind === "ExceptAt") return BUILTIN_LOCATION;
|
|
1716
1802
|
switch (fact.kind) {
|
|
@@ -1727,11 +1813,17 @@ const getHiddenExpressionLocation = (
|
|
|
1727
1813
|
if (fact.kind === "Subexpression" || first.kind !== "Name") return undefined;
|
|
1728
1814
|
const name = fact.kind === "Identifier" ? fact.name : fact.operator;
|
|
1729
1815
|
const goal = lookupLocal(scope, first.name)?.goal ?? getGoal(first.name, unit);
|
|
1730
|
-
if (
|
|
1816
|
+
if (
|
|
1817
|
+
isFact(name, unit) ||
|
|
1818
|
+
goal ||
|
|
1819
|
+
(isStepName(name) && lookupLocal(scope, name)) ||
|
|
1820
|
+
(fact.kind === "Identifier" && isInstanceName(name, scope, unit))
|
|
1821
|
+
) {
|
|
1731
1822
|
return undefined;
|
|
1732
1823
|
}
|
|
1733
1824
|
const binding = findBinding(name, scope, unit);
|
|
1734
1825
|
const count = fact.kind === "Apply" ? fact.args.length : 0;
|
|
1826
|
+
// Deviation from SANY: UseOrHideNode#factCheck crashes on a fact whose operator Generator#generateExpression could not resolve, where tla-ts reports it like a null node.
|
|
1735
1827
|
return binding?.arity === count ? range : BUILTIN_LOCATION;
|
|
1736
1828
|
}
|
|
1737
1829
|
default:
|
|
@@ -1748,6 +1840,9 @@ const checkUseOrHide = (
|
|
|
1748
1840
|
const hidden = statement.facts.map((fact, index) =>
|
|
1749
1841
|
checkFact(fact, references[index], scope, unit),
|
|
1750
1842
|
);
|
|
1843
|
+
const factCount = statement.facts.filter(
|
|
1844
|
+
(fact) => fact.kind !== "ModuleFact" || unit.isModuleKnown(fact.name, fact.location),
|
|
1845
|
+
).length;
|
|
1751
1846
|
const defCount = statement.defs.filter((def) => isDefinitionEntry(def, scope, unit)).length;
|
|
1752
1847
|
hidden.forEach((location) => {
|
|
1753
1848
|
if (location && statement.kind === "Hide") {
|
|
@@ -1759,7 +1854,7 @@ const checkUseOrHide = (
|
|
|
1759
1854
|
}
|
|
1760
1855
|
});
|
|
1761
1856
|
const range = statement.location.range;
|
|
1762
|
-
if (
|
|
1857
|
+
if (factCount + defCount === 0 && range) {
|
|
1763
1858
|
unit.errors.push({
|
|
1764
1859
|
location: formatRange(range),
|
|
1765
1860
|
message: statement.kind === "By" ? "Empty BY" : "Empty USE or HIDE statement.",
|
|
@@ -1880,10 +1975,13 @@ const resolveStep = (
|
|
|
1880
1975
|
const goal = getStepGoal(body, step.location);
|
|
1881
1976
|
const bindStep = (parent: LocalName | undefined): LocalName | undefined =>
|
|
1882
1977
|
step.name === undefined ? parent : { name: step.name, arity: 0, kind: "Theorem", parent, goal };
|
|
1883
|
-
const bindNonFactStep = (
|
|
1978
|
+
const bindNonFactStep = (
|
|
1979
|
+
parent: LocalName | undefined,
|
|
1980
|
+
nonFactStep: LocalName["nonFactStep"],
|
|
1981
|
+
): LocalName | undefined =>
|
|
1884
1982
|
step.name === undefined
|
|
1885
1983
|
? parent
|
|
1886
|
-
: { name: step.name, arity: 0, kind: "Theorem", parent,
|
|
1984
|
+
: { name: step.name, arity: 0, kind: "Theorem", parent, nonFactStep };
|
|
1887
1985
|
switch (body.kind) {
|
|
1888
1986
|
case "Assert": {
|
|
1889
1987
|
const assumed = resolveStatement(body.statement, scope, stepUnit);
|
|
@@ -1916,9 +2014,9 @@ const resolveStep = (
|
|
|
1916
2014
|
case "Use":
|
|
1917
2015
|
case "Hide":
|
|
1918
2016
|
checkUseOrHide(body, scope, unit);
|
|
1919
|
-
return bindNonFactStep(scope);
|
|
2017
|
+
return bindNonFactStep(scope, body.kind);
|
|
1920
2018
|
case "Instance":
|
|
1921
|
-
return bindNonFactStep(resolveLocalInstance(body, scope, stepUnit));
|
|
2019
|
+
return bindNonFactStep(resolveLocalInstance(body, scope, stepUnit), body.kind);
|
|
1922
2020
|
case "Define":
|
|
1923
2021
|
return bindNonFactStep(
|
|
1924
2022
|
body.definitions.reduce(
|
|
@@ -1928,6 +2026,7 @@ const resolveStep = (
|
|
|
1928
2026
|
: resolveDefinitions([definition], current, unit),
|
|
1929
2027
|
scope,
|
|
1930
2028
|
),
|
|
2029
|
+
body.kind,
|
|
1931
2030
|
);
|
|
1932
2031
|
case "Have":
|
|
1933
2032
|
case "Case":
|
|
@@ -2000,6 +2099,7 @@ export interface ModuleUnit {
|
|
|
2000
2099
|
bound: Symbols;
|
|
2001
2100
|
definitions: Map<string, Definition>;
|
|
2002
2101
|
getKey: (definition: Definition) => string;
|
|
2102
|
+
isModuleKnown: (name: string, location: SourceLocation) => boolean;
|
|
2003
2103
|
instanced: Map<Instance, Symbols>;
|
|
2004
2104
|
facts: Set<string>;
|
|
2005
2105
|
reports: ModuleReport[];
|
|
@@ -2049,23 +2149,25 @@ const checkSubstitutions = (
|
|
|
2049
2149
|
resolveExpressionArgument(expression, scope, unit);
|
|
2050
2150
|
return;
|
|
2051
2151
|
}
|
|
2052
|
-
|
|
2152
|
+
const parenthesized = parenthesizedRanges.get(expression);
|
|
2153
|
+
if (expression.kind === "Lambda" && !parenthesized) {
|
|
2053
2154
|
resolveLambda(expression, scope, unit);
|
|
2054
2155
|
if (expression.params.length !== declaration.arity && range) {
|
|
2055
2156
|
reportArity(declaration, formatRange(range));
|
|
2056
2157
|
}
|
|
2057
2158
|
return;
|
|
2058
2159
|
}
|
|
2059
|
-
if (expression.kind === "OperatorReference") {
|
|
2160
|
+
if (expression.kind === "OperatorReference" && !parenthesized) {
|
|
2060
2161
|
const arity = getSymbolArity(expression, expression.operator, scope, unit);
|
|
2061
2162
|
if (arity === undefined) reportArity(declaration, BUILTIN_LOCATION);
|
|
2062
2163
|
else if (arity !== declaration.arity && range) reportArity(declaration, formatRange(range));
|
|
2063
2164
|
return;
|
|
2064
2165
|
}
|
|
2065
|
-
if (expression.kind !== "Identifier") {
|
|
2066
|
-
|
|
2166
|
+
if (expression.kind !== "Identifier" || parenthesized) {
|
|
2167
|
+
const errorRange = parenthesized ?? range;
|
|
2168
|
+
if (errorRange) {
|
|
2067
2169
|
unit.errors.push({
|
|
2068
|
-
location: formatRange(
|
|
2170
|
+
location: formatRange(errorRange),
|
|
2069
2171
|
message: `Arity ${declaration.arity} operator (not an expression) is expected \nto substitute for CONSTANT '${resolveSynonym(declaration.name)}'.`,
|
|
2070
2172
|
});
|
|
2071
2173
|
}
|
|
@@ -2181,6 +2283,7 @@ export const resolveSubstitutions = (
|
|
|
2181
2283
|
getInstance: unit.getInstance,
|
|
2182
2284
|
definitions: unit.definitions,
|
|
2183
2285
|
getKey: unit.getKey,
|
|
2286
|
+
isModuleKnown: unit.isModuleKnown,
|
|
2184
2287
|
location: instance.location,
|
|
2185
2288
|
self: undefined,
|
|
2186
2289
|
facts: new Set(),
|
|
@@ -2277,6 +2380,7 @@ export const resolveModule = (module: Module, unit: ModuleUnit) => {
|
|
|
2277
2380
|
getInstance: unit.getInstance,
|
|
2278
2381
|
definitions: unit.definitions,
|
|
2279
2382
|
getKey: unit.getKey,
|
|
2383
|
+
isModuleKnown: unit.isModuleKnown,
|
|
2280
2384
|
location,
|
|
2281
2385
|
self,
|
|
2282
2386
|
facts: unit.facts,
|
|
@@ -985,6 +985,8 @@ export const generateExpression = (
|
|
|
985
985
|
return generateLabel(generation, expression);
|
|
986
986
|
case "Subexpression":
|
|
987
987
|
return generateSelectorExpression(generation, expression);
|
|
988
|
+
case "Selection":
|
|
989
|
+
return generateExpression(generation, expression.expression);
|
|
988
990
|
}
|
|
989
991
|
};
|
|
990
992
|
|
|
@@ -159,6 +159,7 @@ export const generateUseOrHide = (generation: ModuleGeneration, use: UseOrHide):
|
|
|
159
159
|
if (facts.length + defs.length === 0)
|
|
160
160
|
generation.addError(location, "Empty USE or HIDE statement.");
|
|
161
161
|
if (use.kind === "Hide") {
|
|
162
|
+
// Deviation from SANY: UseOrHideNode#factCheck crashes on a fact whose operator Generator#generateExpression could not resolve, where tla-ts reports it like a null node.
|
|
162
163
|
facts
|
|
163
164
|
.filter((fact) => fact.kind === "OpAppl" && fact.operator.kind !== "ThmOrAssumpDef")
|
|
164
165
|
.forEach((fact) =>
|
package/src/search.ts
CHANGED
|
@@ -17,7 +17,11 @@ import type {
|
|
|
17
17
|
import { parseConfig, type ConfigValue, type ModelConfig } from "./config";
|
|
18
18
|
import {
|
|
19
19
|
addCoverageRelation,
|
|
20
|
+
buildCoverage,
|
|
21
|
+
createCoverage,
|
|
22
|
+
createCoverageEnvironment,
|
|
20
23
|
getCoverageLabel,
|
|
24
|
+
getCoverageReport,
|
|
21
25
|
runAtCoverageNode,
|
|
22
26
|
type Coverage,
|
|
23
27
|
type CoverageKind,
|
|
@@ -67,10 +71,12 @@ import { expandTemporal, getLevel, type ScopedExpression, type TemporalProperty
|
|
|
67
71
|
import { getLiveExpressions } from "./liveness-checker";
|
|
68
72
|
import { prettyPrint } from "./pretty-print";
|
|
69
73
|
import { getPossibleCounts, type CheckerRuntime } from "./runtime";
|
|
74
|
+
import { createIncompleteSuccessorError } from "./successors";
|
|
70
75
|
import {
|
|
71
76
|
getSpecDescription,
|
|
72
77
|
getSpecificationValue,
|
|
73
78
|
getSubscriptVariables,
|
|
79
|
+
type SpecAction,
|
|
74
80
|
type SpecDescription,
|
|
75
81
|
} from "./spec-description";
|
|
76
82
|
import { getRepresentative, getSymmetryGroup, type Images } from "./symmetry";
|
|
@@ -83,6 +89,7 @@ import {
|
|
|
83
89
|
withHeadline,
|
|
84
90
|
} from "./tlc/messages";
|
|
85
91
|
import { createTlcOrder } from "./tlc/order";
|
|
92
|
+
import { getPrimedRanges, walkSuccessors } from "./tlc/replay";
|
|
86
93
|
import { getTlcFingerprint, getTlcFingerprints, setFingerprintPolynomial } from "./tlc/fingerprint";
|
|
87
94
|
import type { TlcVersion } from "./tlc/version";
|
|
88
95
|
import {
|
|
@@ -680,7 +687,7 @@ const getStateChecks = (named: NamedExpression[], environment: Environment): Sta
|
|
|
680
687
|
);
|
|
681
688
|
});
|
|
682
689
|
|
|
683
|
-
const isUnchangedFor = (stateCheck: StateCheck, state:
|
|
690
|
+
const isUnchangedFor = (stateCheck: StateCheck, state: State, parent: Value[] | undefined) => {
|
|
684
691
|
const variables = stateCheck.variables;
|
|
685
692
|
if (!parent || !variables) return false;
|
|
686
693
|
for (let index = 0; index < variables.length; index++) {
|
|
@@ -698,23 +705,34 @@ const isWideConfigValue = (value: ConfigValue): boolean =>
|
|
|
698
705
|
? WIDE_CHARACTER.test(value.value)
|
|
699
706
|
: value.kind === "Set" && value.elements.some(isWideConfigValue);
|
|
700
707
|
|
|
701
|
-
const isWideExpression = (expression: Expression): boolean =>
|
|
702
|
-
(expression.kind === "
|
|
703
|
-
|
|
704
|
-
|
|
708
|
+
const isWideExpression = (expression: Expression, checked: Set<Expression>): boolean => {
|
|
709
|
+
if (expression.kind === "Selection") {
|
|
710
|
+
if (checked.has(expression.expression)) return false;
|
|
711
|
+
checked.add(expression.expression);
|
|
712
|
+
}
|
|
713
|
+
return (
|
|
714
|
+
(expression.kind === "String" && WIDE_CHARACTER.test(expression.value)) ||
|
|
715
|
+
(expression.kind === "Apply" && DESERIALIZERS.has(expression.operator)) ||
|
|
716
|
+
getChildren(expression).some((child) => isWideExpression(child, checked))
|
|
717
|
+
);
|
|
718
|
+
};
|
|
705
719
|
|
|
706
720
|
// TLC fingerprints a string by the low byte of each character, so it merges states whose strings differ only above U+00FF.
|
|
707
|
-
const hasWideString = (config: ModelConfig, environment: Environment) =>
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
(definition
|
|
716
|
-
definition.
|
|
721
|
+
const hasWideString = (config: ModelConfig, environment: Environment) => {
|
|
722
|
+
const checked = new Set<Expression>();
|
|
723
|
+
return (
|
|
724
|
+
config.constants.some(
|
|
725
|
+
(constant) =>
|
|
726
|
+
isWideConfigValue(constant.value) || (constant.args ?? []).some(isWideConfigValue),
|
|
727
|
+
) ||
|
|
728
|
+
[...environment.definitions.values()].some(
|
|
729
|
+
(definition) =>
|
|
730
|
+
isWideExpression(definition.body, checked) ||
|
|
731
|
+
(definition.kind === "Function" &&
|
|
732
|
+
definition.bounds.some((bound) => isWideExpression(bound.set, checked))),
|
|
733
|
+
)
|
|
717
734
|
);
|
|
735
|
+
};
|
|
718
736
|
|
|
719
737
|
export interface Search {
|
|
720
738
|
properties: Properties;
|
|
@@ -760,10 +778,10 @@ export interface Search {
|
|
|
760
778
|
tracing: Environment,
|
|
761
779
|
addFingerprint: () => boolean,
|
|
762
780
|
) => boolean;
|
|
763
|
-
satisfiesConstraints: (state:
|
|
781
|
+
satisfiesConstraints: (state: State, parent?: Value[]) => boolean;
|
|
764
782
|
findFailedInitialPredicate: (state: Value[]) => NamedExpression | undefined;
|
|
765
783
|
findViolatedActionProperty: (state: Value[], next: Value[]) => ActionProperty | undefined;
|
|
766
|
-
satisfiesActionConstraints: (state: Value[], next:
|
|
784
|
+
satisfiesActionConstraints: (state: Value[], next: State) => boolean;
|
|
767
785
|
getExcludingConstraints: (state: Value[], next: Value[]) => string[];
|
|
768
786
|
trackStatePossible: (state: Value[]) => void;
|
|
769
787
|
trackActionPossible: (state: Value[], next: Value[]) => void;
|
|
@@ -916,7 +934,13 @@ export const prepareSearch = (options: CheckOptions) => {
|
|
|
916
934
|
const created = createCheckEnvironment(config, options, options.onPrint ?? console.log);
|
|
917
935
|
const specification = created.specification;
|
|
918
936
|
reportStartup(specification, config, options.onProgress);
|
|
919
|
-
const
|
|
937
|
+
const coverage =
|
|
938
|
+
options.coverage === undefined
|
|
939
|
+
? undefined
|
|
940
|
+
: createCoverage(specification.environment.variables.length);
|
|
941
|
+
const environment = coverage
|
|
942
|
+
? createCoverageEnvironment(specification.environment, coverage)
|
|
943
|
+
: specification.environment;
|
|
920
944
|
let description: SpecDescription | undefined;
|
|
921
945
|
const getDescription = () =>
|
|
922
946
|
(description ??= getSpecDescription(config, environment, specification.instanceActions));
|
|
@@ -931,9 +955,71 @@ export const prepareSearch = (options: CheckOptions) => {
|
|
|
931
955
|
specification.moduleOperators,
|
|
932
956
|
specification.runtimeInvariants,
|
|
933
957
|
);
|
|
934
|
-
|
|
958
|
+
const getCoverage = () =>
|
|
959
|
+
coverage &&
|
|
960
|
+
getCoverageReport(
|
|
961
|
+
coverage,
|
|
962
|
+
environment,
|
|
963
|
+
specification.variableLocations,
|
|
964
|
+
search?.getTlcOrder() ?? [],
|
|
965
|
+
);
|
|
966
|
+
return { config, specification, environment, search, getDescription, coverage, getCoverage };
|
|
967
|
+
};
|
|
968
|
+
|
|
969
|
+
export interface CoveredAction extends SpecAction {
|
|
970
|
+
node: number;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
export const STOP_WALK = new Error("The walk stopped");
|
|
974
|
+
|
|
975
|
+
export const addActionCoverage = (
|
|
976
|
+
coverage: Coverage,
|
|
977
|
+
environment: Environment,
|
|
978
|
+
description: SpecDescription,
|
|
979
|
+
) => {
|
|
980
|
+
const addRelations = (kind: "init" | "next", actions: SpecAction[]) =>
|
|
981
|
+
actions.map((action): CoveredAction => ({
|
|
982
|
+
...action,
|
|
983
|
+
node: addCoverageRelation(
|
|
984
|
+
coverage,
|
|
985
|
+
kind,
|
|
986
|
+
getCoverageLabel(action.name, action.expression, environment),
|
|
987
|
+
action.expression,
|
|
988
|
+
action.scope,
|
|
989
|
+
),
|
|
990
|
+
}));
|
|
991
|
+
const inits = addRelations("init", description.inits);
|
|
992
|
+
const actions = addRelations("next", description.actions);
|
|
993
|
+
buildCoverage(coverage, environment, getPrimedRanges(actions, environment));
|
|
994
|
+
return { inits, actions };
|
|
935
995
|
};
|
|
936
996
|
|
|
997
|
+
export const walkCoveredSuccessors = (
|
|
998
|
+
coverage: Coverage,
|
|
999
|
+
action: CoveredAction,
|
|
1000
|
+
state: Value[],
|
|
1001
|
+
environment: Environment,
|
|
1002
|
+
onState: (successor: Value[]) => void,
|
|
1003
|
+
onIncomplete = (partial: State, name: string | undefined): void => {
|
|
1004
|
+
throw createIncompleteSuccessorError(partial, name, environment);
|
|
1005
|
+
},
|
|
1006
|
+
) =>
|
|
1007
|
+
walkSuccessors(
|
|
1008
|
+
action,
|
|
1009
|
+
action.node,
|
|
1010
|
+
state,
|
|
1011
|
+
environment,
|
|
1012
|
+
(successor) => {
|
|
1013
|
+
coverage.primary[action.node]++;
|
|
1014
|
+
onState(successor);
|
|
1015
|
+
},
|
|
1016
|
+
(partial) => {
|
|
1017
|
+
coverage.primary[action.node]++;
|
|
1018
|
+
onIncomplete(partial, action.name);
|
|
1019
|
+
return true;
|
|
1020
|
+
},
|
|
1021
|
+
);
|
|
1022
|
+
|
|
937
1023
|
export const reportAssumptionViolation = (
|
|
938
1024
|
assumptions: Assumption[],
|
|
939
1025
|
environment: Environment,
|
|
@@ -1085,8 +1171,8 @@ export const createSearch = (
|
|
|
1085
1171
|
const evaluateCovered = (
|
|
1086
1172
|
covered: Coverage,
|
|
1087
1173
|
check: CoveredCheck,
|
|
1088
|
-
state:
|
|
1089
|
-
next:
|
|
1174
|
+
state: State,
|
|
1175
|
+
next: State | undefined,
|
|
1090
1176
|
) => {
|
|
1091
1177
|
try {
|
|
1092
1178
|
return runAtCoverageNode(covered, check.node, () =>
|
|
@@ -1104,7 +1190,7 @@ export const createSearch = (
|
|
|
1104
1190
|
coverage && covered
|
|
1105
1191
|
? runAtCoverageNode(coverage, covered.node, () => holdsLikeTlc(covered.expression, context))
|
|
1106
1192
|
: holdsLikeTlc(expression, context);
|
|
1107
|
-
const satisfiesCovered = (checks: CoveredCheck[], state:
|
|
1193
|
+
const satisfiesCovered = (checks: CoveredCheck[], state: State, next?: State) => {
|
|
1108
1194
|
if (!coverage) return undefined;
|
|
1109
1195
|
for (const check of checks) {
|
|
1110
1196
|
const value = evaluateCovered(coverage, check, state, next);
|
|
@@ -1258,7 +1344,7 @@ export const createSearch = (
|
|
|
1258
1344
|
)
|
|
1259
1345
|
.join("")
|
|
1260
1346
|
: prettyPrint(formatValue(getViewValue(expression, state)));
|
|
1261
|
-
const holdsActionConstraint = (constraint: NamedExpression, state: Value[], next:
|
|
1347
|
+
const holdsActionConstraint = (constraint: NamedExpression, state: Value[], next: State) =>
|
|
1262
1348
|
holdsLikeTlc(
|
|
1263
1349
|
constraint.expression,
|
|
1264
1350
|
getContext(environment, state, next),
|