tla-ts 0.0.3-dev.6979965 → 0.0.3-dev.6d0aeb6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +60 -22
- package/dist/index.d.ts +60 -22
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +2 -2
- package/dist/parallel-worker.js +2 -2
- package/dist/parallel.cjs +1 -1
- package/dist/parallel.js +2 -2
- package/dist/run-cli.cjs +20 -17
- package/dist/run-cli.js +22 -19
- package/dist/transfer.cjs +45 -16
- package/dist/transfer.js +45 -16
- package/package.json +1 -1
- package/src/ast.ts +101 -1
- package/src/builtins.ts +9 -3
- package/src/check.ts +514 -99
- package/src/cli-options.ts +11 -5
- package/src/codegen.ts +15 -22
- package/src/config.ts +224 -170
- package/src/dependencies.ts +2 -2
- package/src/environment.ts +158 -49
- package/src/errors.ts +98 -3
- package/src/evaluate.ts +255 -159
- package/src/exit-codes.ts +39 -42
- package/src/fingerprints.ts +2 -1
- package/src/instances.ts +16 -15
- package/src/levels.ts +181 -45
- package/src/lexer.ts +5 -1
- package/src/live-check.ts +772 -0
- package/src/liveness.ts +120 -543
- package/src/parallel-worker.ts +102 -115
- package/src/parallel.ts +34 -23
- package/src/parser.ts +83 -20
- package/src/resolve.ts +490 -95
- package/src/run-cli.ts +113 -20
- package/src/runtime.ts +3 -1
- package/src/sany-lexer.ts +615 -0
- package/src/sany-parse-error.ts +3143 -0
- package/src/spec-description.ts +19 -8
- package/src/standard-modules.ts +54 -45
- package/src/state-graph.ts +157 -0
- package/src/subexpressions.ts +35 -23
- package/src/substitution-levels.ts +38 -17
- package/src/successors.ts +183 -39
- package/src/symmetry.ts +30 -8
- package/src/tableau.ts +51 -24
- package/src/tlc-ext.ts +29 -12
- package/src/tlc-module.ts +14 -33
- package/src/tlc-modules.ts +4 -0
- package/src/tlc-order.ts +25 -7
- package/src/tlc-random.ts +9 -6
- package/src/tlc-summary.ts +20 -5
- package/src/value-sources.ts +29 -0
- package/src/values.ts +249 -65
package/src/parser.ts
CHANGED
|
@@ -22,7 +22,7 @@ import type {
|
|
|
22
22
|
StepBody,
|
|
23
23
|
UseOrHide,
|
|
24
24
|
} from "./ast";
|
|
25
|
-
import { TlaSyntaxError } from "./errors";
|
|
25
|
+
import { createSanyError, formatRange, TlaSyntaxError } from "./errors";
|
|
26
26
|
import { getNumeralValue, tokenize, type Token } from "./lexer";
|
|
27
27
|
|
|
28
28
|
interface InfixOperator {
|
|
@@ -135,6 +135,8 @@ const INFIX_OPERATORS = new Map<string, InfixOperator>([
|
|
|
135
135
|
["^^", createInfix(14, 14, false)],
|
|
136
136
|
]);
|
|
137
137
|
|
|
138
|
+
const NEGATION_PRECEDENCE = 12;
|
|
139
|
+
|
|
138
140
|
const POSTFIX_OPERATORS = new Set(["^+", "^*", "^#"]);
|
|
139
141
|
|
|
140
142
|
const PREFIX_OPERATOR_REFERENCES = new Set(["-", "~", "-."]);
|
|
@@ -327,8 +329,7 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
327
329
|
const tokenEnds: SourceLocation[] = [];
|
|
328
330
|
const tokenRanges: SourceRange[] = [];
|
|
329
331
|
|
|
330
|
-
const getRange = (startIndex: number) => {
|
|
331
|
-
const endIndex = cursor.index - 1;
|
|
332
|
+
const getRange = (startIndex: number, endIndex = cursor.index - 1) => {
|
|
332
333
|
const cached = startIndex === endIndex ? tokenRanges[startIndex] : undefined;
|
|
333
334
|
if (cached) return cached;
|
|
334
335
|
const last = tokens[endIndex];
|
|
@@ -626,14 +627,24 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
626
627
|
const body = parseExpression();
|
|
627
628
|
return withRange({ kind: "Lambda", params, body, location: getLocation(token) }, start);
|
|
628
629
|
}
|
|
629
|
-
|
|
630
|
+
const argument = parseExpression();
|
|
631
|
+
// SANY reads an argument that only names an operator of a parameterized instance, such as
|
|
632
|
+
// I!Op, as that operator, which takes the arguments of the instance too.
|
|
633
|
+
if (argument.kind === "Identifier") missingArguments.delete(argument);
|
|
634
|
+
return argument;
|
|
630
635
|
};
|
|
631
636
|
|
|
637
|
+
const missingArguments = new Map<Expression, { location: string; message: string }>();
|
|
638
|
+
|
|
639
|
+
const lastArguments: { range: SourceRange | undefined } = { range: undefined };
|
|
640
|
+
|
|
632
641
|
const parseArguments = () =>
|
|
633
642
|
withoutOffside(() => {
|
|
643
|
+
const start = cursor.index;
|
|
634
644
|
expect("(");
|
|
635
645
|
const args = parseSeparated(parseArgument);
|
|
636
646
|
expect(")");
|
|
647
|
+
lastArguments.range = getRange(start);
|
|
637
648
|
return args;
|
|
638
649
|
});
|
|
639
650
|
|
|
@@ -660,9 +671,12 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
660
671
|
if (peek().kind === "Identifier" && (isAt("|->", 1) || isAt(":", 1))) {
|
|
661
672
|
const kind = isAt("|->", 1) ? "Record" : "RecordSet";
|
|
662
673
|
const fields = parseSeparated(() => {
|
|
674
|
+
const fieldStart = cursor.index;
|
|
675
|
+
const fieldLocation = getLocation(peek());
|
|
663
676
|
const name = expectIdentifier();
|
|
677
|
+
fieldLocation.range = getRange(fieldStart);
|
|
664
678
|
expect(kind === "Record" ? "|->" : ":");
|
|
665
|
-
return { name, value: parseExpression() };
|
|
679
|
+
return { name, value: parseExpression(), location: fieldLocation };
|
|
666
680
|
});
|
|
667
681
|
expect("]");
|
|
668
682
|
return { kind, fields, location };
|
|
@@ -821,7 +835,8 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
821
835
|
};
|
|
822
836
|
|
|
823
837
|
const parsePrimary = (): Expression => {
|
|
824
|
-
const
|
|
838
|
+
const start = cursor.index;
|
|
839
|
+
const isFactStart = start === factStart.index;
|
|
825
840
|
const token = advance();
|
|
826
841
|
const location = getLocation(token);
|
|
827
842
|
if (isTlapm && token.kind === "Keyword" && token.text === "LAMBDA") {
|
|
@@ -854,38 +869,71 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
854
869
|
const args = hasArguments ? parseArguments() : [];
|
|
855
870
|
if (!isSelectorAhead()) {
|
|
856
871
|
return hasArguments
|
|
857
|
-
? { kind: "Apply", operator: name, args, location }
|
|
872
|
+
? { kind: "Apply", operator: name, args, argumentsRange: lastArguments.range, location }
|
|
858
873
|
: { kind: "Identifier", name, location };
|
|
859
874
|
}
|
|
860
875
|
const instance = openModules
|
|
861
876
|
.flatMap((module) => module.instances)
|
|
862
877
|
.find((candidate) => candidate.name === name);
|
|
863
|
-
|
|
878
|
+
const isMissingArguments =
|
|
879
|
+
instance !== undefined &&
|
|
880
|
+
!isFactStart &&
|
|
881
|
+
!isTlapm &&
|
|
882
|
+
instance.params.length !== args.length;
|
|
883
|
+
if (isMissingArguments && args.length > 0) {
|
|
864
884
|
throw createError(
|
|
865
885
|
`The operator ${name} requires ${instance.params.length} arguments`,
|
|
866
886
|
token,
|
|
867
887
|
);
|
|
868
888
|
}
|
|
869
889
|
const selectors: Selector[] = [{ kind: "Name", name, args }];
|
|
890
|
+
const selectorRanges = [getRange(start, start)];
|
|
870
891
|
while (isSelectorAhead()) {
|
|
871
892
|
advance();
|
|
893
|
+
selectorRanges.push(getRange(cursor.index, cursor.index));
|
|
872
894
|
selectors.push(parseSelector());
|
|
873
895
|
}
|
|
874
896
|
const names = selectors.flatMap((selector) =>
|
|
875
897
|
selector.kind === "Name" ? [selector.name] : [],
|
|
876
898
|
);
|
|
877
|
-
if (names.length < selectors.length) return { kind: "Subexpression", selectors, location };
|
|
878
899
|
const operator = names.join("!");
|
|
879
900
|
const qualifiedArgs = selectors.flatMap((selector) =>
|
|
880
901
|
"args" in selector ? selector.args : [],
|
|
881
902
|
);
|
|
882
|
-
if (qualifiedArgs.length === 0) return { kind: "Identifier", name: operator, location };
|
|
883
903
|
const argumentCounts = selectors.map((selector) =>
|
|
884
904
|
"args" in selector ? selector.args.length : 0,
|
|
885
905
|
);
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
906
|
+
const argumentsRange = lastArguments.range;
|
|
907
|
+
const reference: Expression =
|
|
908
|
+
names.length < selectors.length
|
|
909
|
+
? { kind: "Subexpression", selectors, selectorRanges, location }
|
|
910
|
+
: qualifiedArgs.length === 0
|
|
911
|
+
? { kind: "Identifier", name: operator, selectorRanges, location }
|
|
912
|
+
: argumentCounts.slice(0, -1).some((count) => count > 0)
|
|
913
|
+
? {
|
|
914
|
+
kind: "Apply",
|
|
915
|
+
operator,
|
|
916
|
+
args: qualifiedArgs,
|
|
917
|
+
argumentCounts,
|
|
918
|
+
argumentsRange,
|
|
919
|
+
selectorRanges,
|
|
920
|
+
location,
|
|
921
|
+
}
|
|
922
|
+
: {
|
|
923
|
+
kind: "Apply",
|
|
924
|
+
operator,
|
|
925
|
+
args: qualifiedArgs,
|
|
926
|
+
argumentsRange,
|
|
927
|
+
selectorRanges,
|
|
928
|
+
location,
|
|
929
|
+
};
|
|
930
|
+
if (isMissingArguments) {
|
|
931
|
+
missingArguments.set(reference, {
|
|
932
|
+
location: formatRange(getRange(start)),
|
|
933
|
+
message: `The operator ${name} requires ${instance.params.length} arguments.`,
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
return reference;
|
|
889
937
|
}
|
|
890
938
|
if (token.kind === "Operator" && isOperatorName(token.text) && isAt("("))
|
|
891
939
|
return { kind: "Apply", operator: token.text, args: parseArguments(), location };
|
|
@@ -977,7 +1025,12 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
977
1025
|
return { kind: "Apply", operator: "~", args: [parseExpression(5)], location };
|
|
978
1026
|
case "-":
|
|
979
1027
|
advance();
|
|
980
|
-
return {
|
|
1028
|
+
return {
|
|
1029
|
+
kind: "Apply",
|
|
1030
|
+
operator: "-.",
|
|
1031
|
+
args: [parseExpression(NEGATION_PRECEDENCE + 1)],
|
|
1032
|
+
location,
|
|
1033
|
+
};
|
|
981
1034
|
case "[]":
|
|
982
1035
|
advance();
|
|
983
1036
|
return { kind: "Always", expression: parseExpression(16), location };
|
|
@@ -1054,6 +1107,10 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
1054
1107
|
}
|
|
1055
1108
|
}
|
|
1056
1109
|
advance();
|
|
1110
|
+
// SANY reads - after an infix operator as prefix -, and rejects it after one that binds tighter.
|
|
1111
|
+
if (infix.low > NEGATION_PRECEDENCE && isAt("-")) {
|
|
1112
|
+
throw createError(`Precedence conflict between ${token.text} and -`, peek());
|
|
1113
|
+
}
|
|
1057
1114
|
const right = parseExpression(infix.high + 1);
|
|
1058
1115
|
const left = state.left;
|
|
1059
1116
|
if (token.text === "/\\" || token.text === "\\/") {
|
|
@@ -1412,11 +1469,14 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
1412
1469
|
location: getLocation(keyword),
|
|
1413
1470
|
};
|
|
1414
1471
|
const invalid =
|
|
1415
|
-
use.kind === "Hide" && !isTlapm ? use.facts.
|
|
1416
|
-
if (invalid) {
|
|
1417
|
-
throw
|
|
1418
|
-
|
|
1419
|
-
|
|
1472
|
+
use.kind === "Hide" && !isTlapm ? use.facts.filter((fact) => !isHideFact(fact)) : [];
|
|
1473
|
+
if (invalid.length > 0) {
|
|
1474
|
+
throw createSanyError(
|
|
1475
|
+
invalid.map((fact) => ({
|
|
1476
|
+
location: formatRange(fact.location.range ?? getRange(start)),
|
|
1477
|
+
message:
|
|
1478
|
+
"The only expression allowed as a fact in a HIDE is \nthe name of a theorem, assumption, or step.",
|
|
1479
|
+
})),
|
|
1420
1480
|
);
|
|
1421
1481
|
}
|
|
1422
1482
|
return withRange(use, start);
|
|
@@ -1552,10 +1612,12 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
1552
1612
|
const parseStep = (): ProofStep => {
|
|
1553
1613
|
const start = cursor.index;
|
|
1554
1614
|
const step = parseStepStart(isAt("QED", 1));
|
|
1615
|
+
const statementStart = cursor.index;
|
|
1555
1616
|
const scope = new Set<string>();
|
|
1556
1617
|
proofScopes.push(scope);
|
|
1557
1618
|
const body: StepBody = accept("QED") ? { kind: "Qed" } : parseStepBody();
|
|
1558
1619
|
const head = getRange(start);
|
|
1620
|
+
const statement = getRange(statementStart);
|
|
1559
1621
|
const hasProof = isProofStart(peek());
|
|
1560
1622
|
if (hasProof && !PROVABLE_STEPS.has(body.kind)) {
|
|
1561
1623
|
throw createError("Proof of a step that does not take a proof");
|
|
@@ -1563,7 +1625,7 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
1563
1625
|
const proof = hasProof ? parseProof() : undefined;
|
|
1564
1626
|
proofScopes.pop();
|
|
1565
1627
|
if (body.kind !== "Assert" || body.isSuffices) scope.forEach(declareProofSymbol);
|
|
1566
|
-
return withRange({ ...step, body, head, proof }, start);
|
|
1628
|
+
return withRange({ ...step, body, head, statement, proof }, start);
|
|
1567
1629
|
};
|
|
1568
1630
|
|
|
1569
1631
|
const parseProofBody = (): Proof => {
|
|
@@ -1694,6 +1756,7 @@ const parse = (source: string, isTlapm: boolean): Module => {
|
|
|
1694
1756
|
end: { line: token.line, column: token.endColumn },
|
|
1695
1757
|
};
|
|
1696
1758
|
}
|
|
1759
|
+
if (missingArguments.size > 0) throw createSanyError([...missingArguments.values()]);
|
|
1697
1760
|
openModules.pop();
|
|
1698
1761
|
recursiveScopes.pop();
|
|
1699
1762
|
return module;
|