tla-ts 0.0.3-dev.e5b05b9 → 0.0.3-dev.e8bef80
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/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +150 -48
- package/dist/index.d.ts +150 -48
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +2 -2
- package/dist/parallel.cjs +1 -1
- package/dist/parallel.js +2 -2
- package/dist/run-cli.cjs +1351 -22
- package/dist/run-cli.js +1352 -23
- package/dist/transfer.cjs +83 -43
- package/dist/transfer.js +83 -43
- package/package.json +5 -1
- package/src/ast.ts +28 -4
- package/src/bags.ts +4 -7
- package/src/builtins.ts +29 -17
- package/src/bundled-modules.ts +3 -3
- package/src/canonical.ts +4 -3
- package/src/check.ts +1317 -428
- package/src/cli.ts +8 -1
- package/src/codegen.ts +68 -21
- package/src/config.ts +226 -207
- package/src/environment.ts +221 -75
- package/src/errors.ts +130 -15
- package/src/evaluate.ts +713 -259
- package/src/exit-codes.ts +6 -24
- package/src/fingerprints.ts +1 -2
- package/src/index.ts +1 -0
- package/src/instances.ts +3 -1
- package/src/java-overrides.ts +104 -25
- package/src/levels.ts +6 -1
- package/src/lexer.ts +122 -29
- package/src/live-check.ts +204 -148
- package/src/liveness.ts +191 -122
- package/src/obligation-expression.ts +2 -2
- package/src/obligation-source.ts +2 -0
- package/src/parallel-worker.ts +6 -1
- package/src/parallel.ts +57 -6
- package/src/parser.ts +327 -147
- package/src/pcal-ast.ts +770 -0
- package/src/pcal-parse.ts +1523 -0
- package/src/pcal-tokenize.ts +516 -0
- package/src/pcal-translate.ts +1230 -0
- package/src/pcal-validate.ts +454 -0
- package/src/randomization.ts +24 -7
- package/src/resolve.ts +252 -87
- package/src/run-cli.ts +1162 -200
- package/src/runtime.ts +16 -0
- package/src/sany-builtins.ts +147 -0
- package/src/sany-generator.ts +3128 -0
- package/src/sany-levels.ts +1208 -0
- package/src/sany-lexer.ts +410 -480
- package/src/sany-linter.ts +122 -0
- package/src/sany-modules.ts +1398 -0
- package/src/sany-nodes.ts +463 -0
- package/src/sany-parse-error.ts +2033 -3015
- package/src/sany-report.ts +356 -0
- package/src/sany-selectors.ts +738 -0
- package/src/sany-source.ts +248 -0
- package/src/sany-xml.ts +1017 -0
- package/src/spec-description.ts +25 -5
- package/src/standard-modules.ts +172 -129
- package/src/state-graph.ts +29 -6
- package/src/subexpressions.ts +121 -26
- package/src/successors.ts +141 -173
- package/src/symmetry.ts +168 -50
- package/src/tableau.ts +3 -1
- package/src/tlc-ext.ts +13 -17
- package/src/tlc-messages.ts +329 -0
- package/src/tlc-module.ts +49 -21
- package/src/tlc-modules.ts +0 -4
- package/src/tlc-order.ts +55 -9
- package/src/tlc-random.ts +28 -3
- package/src/tlc-replay.ts +655 -0
- package/src/tlc-version.ts +18 -0
- package/src/transfer.ts +15 -3
- package/src/values.ts +664 -317
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {
|
|
2
|
+
formatSanyLocation,
|
|
3
|
+
getContextSymbol,
|
|
4
|
+
type ModuleNode,
|
|
5
|
+
type OpApplNode,
|
|
6
|
+
type SanyMessage,
|
|
7
|
+
type SemanticNode,
|
|
8
|
+
} from "./sany-nodes";
|
|
9
|
+
|
|
10
|
+
// A port of SANY's tla2sany.linter.Linter, which warns about a record field named like a
|
|
11
|
+
// definition or declaration of the module.
|
|
12
|
+
|
|
13
|
+
// SemanticNode.getChildren.
|
|
14
|
+
const getChildren = (node: SemanticNode): (SemanticNode | undefined)[] => {
|
|
15
|
+
switch (node.kind) {
|
|
16
|
+
case "OpAppl":
|
|
17
|
+
return [...node.ranges, ...node.operands];
|
|
18
|
+
case "OpDef":
|
|
19
|
+
case "ThmOrAssumpDef":
|
|
20
|
+
case "Label":
|
|
21
|
+
return [node.body];
|
|
22
|
+
case "LetIn":
|
|
23
|
+
return [...node.opDefs, ...node.instances, node.body];
|
|
24
|
+
case "SubstIn":
|
|
25
|
+
case "APSubstIn":
|
|
26
|
+
return [node.body, ...node.substs.map((subst) => subst.expr)];
|
|
27
|
+
case "Instance":
|
|
28
|
+
return node.substs.map((subst) => subst.expr);
|
|
29
|
+
case "AssumeProve":
|
|
30
|
+
return [...node.assumptions, node.goal];
|
|
31
|
+
case "NewSymb":
|
|
32
|
+
return [node.set];
|
|
33
|
+
default:
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// Operators whose values are sets of values that a record field may range over.
|
|
39
|
+
const SET_OPERATORS = new Map([
|
|
40
|
+
["Integers", "Int"],
|
|
41
|
+
["Naturals", "Nat"],
|
|
42
|
+
// SANY compares the name of the definition with the module's, so no definition of Reals counts.
|
|
43
|
+
["Reals", "Reals"],
|
|
44
|
+
]);
|
|
45
|
+
|
|
46
|
+
// Linter.isBuiltFromDeclarations: whether an expression applies a declared or bound symbol, BOOLEAN
|
|
47
|
+
// or a standard set of numbers, directly or through the definitions it applies.
|
|
48
|
+
const isBuiltFromDeclarations = (node: SemanticNode | undefined) => {
|
|
49
|
+
const visited = new Set<SemanticNode>();
|
|
50
|
+
const visit = (current: SemanticNode | undefined): boolean => {
|
|
51
|
+
if (current === undefined || visited.has(current)) return false;
|
|
52
|
+
visited.add(current);
|
|
53
|
+
if (current.kind === "OpAppl") {
|
|
54
|
+
const operator = current.operator;
|
|
55
|
+
if (operator.kind === "OpDecl" || operator.kind === "FormalParam") return true;
|
|
56
|
+
if (operator.kind === "OpDef") {
|
|
57
|
+
if (operator.name === "BOOLEAN") return true;
|
|
58
|
+
const moduleName = operator.module?.name;
|
|
59
|
+
if (moduleName !== undefined && SET_OPERATORS.get(moduleName) === operator.name)
|
|
60
|
+
return true;
|
|
61
|
+
if (visit(operator)) return true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return getChildren(current).some(visit);
|
|
65
|
+
};
|
|
66
|
+
return visit(node);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const getFieldPairs = (record: OpApplNode) =>
|
|
70
|
+
record.operands.filter((operand): operand is OpApplNode => operand?.kind === "OpAppl");
|
|
71
|
+
|
|
72
|
+
const getFieldName = (pair: OpApplNode) => {
|
|
73
|
+
const name = pair.operands[0];
|
|
74
|
+
return name?.kind === "String" ? name : undefined;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// Records.sameDomain.
|
|
78
|
+
const isSameDomain = (record: OpApplNode, other: OpApplNode) => {
|
|
79
|
+
if (record === other) return true;
|
|
80
|
+
if (record.operands.length !== other.operands.length) return false;
|
|
81
|
+
const names = new Set(getFieldPairs(other).map((pair) => getFieldName(pair)?.value));
|
|
82
|
+
return getFieldPairs(record).every((pair) => names.has(getFieldName(pair)?.value));
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// ModuleNode.getExtendedModuleSet(true).
|
|
86
|
+
const getExtendedModules = (module: ModuleNode, found = new Set<ModuleNode>()) => {
|
|
87
|
+
module.extendees.forEach((extendee) => {
|
|
88
|
+
if (found.has(extendee)) return;
|
|
89
|
+
found.add(extendee);
|
|
90
|
+
getExtendedModules(extendee, found);
|
|
91
|
+
});
|
|
92
|
+
return found;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// Linter.lintRecords: the warnings for the records of a module.
|
|
96
|
+
export const lintSanyModule = (module: ModuleNode): SanyMessage[] => {
|
|
97
|
+
const allRecords = [
|
|
98
|
+
...[...getExtendedModules(module)].flatMap((extended) => extended.records),
|
|
99
|
+
...module.records,
|
|
100
|
+
];
|
|
101
|
+
return module.records.flatMap((record) => {
|
|
102
|
+
// Linter checks the field's value, the record's fields and the fields of every record with the
|
|
103
|
+
// same domain, which includes the record itself.
|
|
104
|
+
const isExempt = allRecords
|
|
105
|
+
.filter((other) => isSameDomain(other, record))
|
|
106
|
+
.flatMap(getFieldPairs)
|
|
107
|
+
.some(isBuiltFromDeclarations);
|
|
108
|
+
if (isExempt) return [];
|
|
109
|
+
return getFieldPairs(record).flatMap((pair) => {
|
|
110
|
+
const name = getFieldName(pair);
|
|
111
|
+
const symbol = name && getContextSymbol(module.context, name.value);
|
|
112
|
+
if (name === undefined || symbol === undefined) return [];
|
|
113
|
+
return [
|
|
114
|
+
{
|
|
115
|
+
location: name.location,
|
|
116
|
+
text: `The field name "${name.value}" in the record constructor is identical to the existing definition or declaration\nnamed ${name.value}, located at ${formatSanyLocation(symbol.location)}.\nThe field in the record will not take the value of the ${name.value} definition or declaration.\nIn TLA+, field names in records are strings, regardless of any similarly named declarations or definitions.\nTherefore, DOMAIN [${name.value} |-> ...] = {"${name.value}"} holds true.`,
|
|
117
|
+
isWarning: true,
|
|
118
|
+
},
|
|
119
|
+
];
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
};
|