tla-ts 0.0.10-dev.28c823e4b → 0.0.10-dev.63a6693bd
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/compile.cjs +6 -6
- package/dist/compile.js +10 -10
- package/dist/deciders.cjs +29 -29
- package/dist/deciders.js +40 -40
- package/dist/index.cjs +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-worker.cjs +1 -1
- package/dist/prove-worker.js +1 -1
- package/dist/prove.cjs +54 -54
- package/dist/prove.js +52 -52
- package/dist/run.cjs +42 -42
- package/dist/run.js +44 -44
- package/dist/tlapm.cjs +2 -2
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +39 -39
- package/dist/transfer.js +41 -41
- package/dist/worker.cjs +4 -4
- package/dist/worker.js +4 -4
- package/package.json +1 -1
- package/src/ast.ts +44 -39
- package/src/builtins.ts +4 -13
- package/src/check-failure.ts +116 -0
- package/src/check-trace.ts +282 -0
- package/src/check.ts +152 -518
- package/src/cli/options.ts +6 -31
- package/src/cli/shared.ts +1 -1
- package/src/cli/tlapm.ts +14 -13
- package/src/cli/tlc-arguments.ts +222 -210
- package/src/cli/tlc-output.ts +687 -0
- package/src/cli/tlc-usage.ts +1 -1
- package/src/cli/tlc.ts +34 -701
- package/src/cli/xml-exporter.ts +23 -33
- package/src/codegen.ts +5 -10
- package/src/coverage.ts +3 -10
- package/src/dependencies.ts +8 -13
- package/src/dfid.ts +16 -16
- package/src/environment-config.ts +315 -0
- package/src/environment.ts +45 -333
- package/src/errors.ts +3 -2
- package/src/evaluate.ts +5 -4
- package/src/fingerprints.ts +65 -1
- package/src/instances.ts +47 -10
- package/src/java-hash.ts +7 -0
- package/src/json.ts +4 -7
- package/src/levels.ts +39 -42
- package/src/liveness-checker.ts +24 -37
- package/src/liveness.ts +47 -54
- package/src/obligations/action.ts +4 -11
- package/src/obligations/anonymize.ts +4 -2
- package/src/obligations/expression.ts +18 -2
- package/src/obligations/generate.ts +45 -38
- package/src/obligations/index.ts +2 -2
- package/src/obligations/module.ts +27 -38
- package/src/obligations/normalize.ts +2 -1
- package/src/obligations/simplify.ts +39 -44
- package/src/obligations/source.ts +47 -57
- package/src/obligations/temporal.ts +5 -5
- package/src/parallel-worker.ts +10 -30
- package/src/parallel.ts +22 -45
- package/src/parser.ts +19 -34
- package/src/prover/decide-pool.ts +3 -3
- package/src/prover/deciders.ts +3 -3
- package/src/prover/isabelle/encode.ts +1 -1
- package/src/prover/isabelle/isar/inner-syntax.ts +9 -4
- package/src/prover/isabelle/isar/method.ts +14 -25
- package/src/prover/isabelle/isar/theory.ts +11 -10
- package/src/prover/isabelle/isar/type-check.ts +6 -6
- package/src/prover/isabelle/provers/blast/blast.ts +7 -63
- package/src/prover/isabelle/provers/hypsubst.ts +17 -26
- package/src/prover/isabelle/pure/bicompose.ts +9 -25
- package/src/prover/isabelle/pure/conv.ts +2 -8
- package/src/prover/isabelle/pure/drule.ts +9 -2
- package/src/prover/isabelle/pure/logic.ts +1 -1
- package/src/prover/isabelle/pure/raw-simplifier.ts +4 -13
- package/src/prover/isabelle/pure/rewriter.ts +5 -9
- package/src/prover/isabelle/pure/table.ts +2 -1
- package/src/prover/isabelle/pure/tactical.ts +42 -35
- package/src/prover/isabelle/pure/thm.ts +14 -11
- package/src/prover/isabelle/tla/classical-setup.ts +17 -14
- package/src/prover/isabelle/tla/context.ts +7 -2
- package/src/prover/isabelle/tla/logic.ts +10 -21
- package/src/prover/isabelle/tla/simpdata.ts +1 -10
- package/src/prover/prep/action.ts +11 -19
- package/src/prover/prep/fingerprint.ts +2 -5
- package/src/prover/prep/methods.ts +24 -3
- package/src/prover/prove.ts +87 -64
- package/src/prover/smt/context.ts +1 -2
- package/src/prover/smt/data.ts +418 -406
- package/src/prover/smt/encode.ts +30 -18
- package/src/prover/smt/rewrite.ts +657 -626
- package/src/prover/smt/solver/ast.ts +0 -22
- package/src/prover/smt/solver/auf-solver.ts +2 -5
- package/src/prover/smt/solver/context.ts +3 -3
- package/src/prover/smt/solver/e-matching.ts +1 -1
- package/src/prover/smt/solver/expr-safe-replace.ts +1 -1
- package/src/prover/smt/solver/internalizer.ts +1 -2
- package/src/prover/smt/solver/lp/dioph-eq.ts +1 -8
- package/src/prover/smt/solver/lp/hnf-cutter.ts +1 -1
- package/src/prover/smt/solver/lp/nla-core.ts +2 -6
- package/src/prover/smt/solver/mam-compiler.ts +4 -2
- package/src/prover/smt/solver/model-checker.ts +1 -1
- package/src/prover/smt/solver/model-finder.ts +12 -17
- package/src/prover/smt/solver/model-macro-solver.ts +11 -19
- package/src/prover/smt/solver/nlsat/algebraic.ts +9 -9
- package/src/prover/smt/solver/nlsat/atoms.ts +20 -4
- package/src/prover/smt/solver/nlsat/explain.ts +7 -22
- package/src/prover/smt/solver/nlsat/levelwise.ts +1 -6
- package/src/prover/smt/solver/nlsat/polynomial.ts +12 -3
- package/src/prover/smt/solver/nlsat/solver.ts +12 -24
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -1
- package/src/prover/smt/solver/proto-model.ts +0 -4
- package/src/prover/smt/solver/quantifier-analyzer.ts +10 -10
- package/src/prover/smt/solver/quantifier-manager.ts +1 -5
- package/src/prover/smt/solver/smtlib-parser.ts +78 -94
- package/src/prover/smt/solver/theory-lra-bounds.ts +1 -2
- package/src/prover/smt/solver/theory-lra-internalize.ts +5 -16
- package/src/prover/tlapm/cache.ts +28 -18
- package/src/prover/tlapm/tlapm.ts +15 -9
- package/src/prover/verdict.ts +7 -0
- package/src/prover/zenon/check/check.ts +1 -2
- package/src/prover/zenon/check/records.ts +1 -1
- package/src/prover/zenon/check/relations.ts +2 -1
- package/src/prover/zenon/check/rewrites.ts +2 -15
- package/src/prover/zenon/check/sets.ts +40 -58
- package/src/prover/zenon/check/terms.ts +1 -2
- package/src/prover/zenon/eqrel.ts +2 -0
- package/src/prover/zenon/expr.ts +7 -0
- package/src/prover/zenon/index-table.ts +9 -19
- package/src/prover/zenon/isar.ts +35 -35
- package/src/prover/zenon/llproof.ts +2 -11
- package/src/prover/zenon/mltoll.ts +12 -28
- package/src/prover/zenon/parse.ts +3 -6
- package/src/prover/zenon/search.ts +4 -14
- package/src/prover/zenon/tla/functions.ts +2 -2
- package/src/prover/zenon/tla/llproof.ts +9 -11
- package/src/prover/zenon/tla/records.ts +1 -6
- package/src/prover/zenon/tla/sets.ts +15 -14
- package/src/prover/zenon/tla/tla.ts +7 -6
- package/src/resolve.ts +55 -72
- package/src/sany/generation.ts +394 -0
- package/src/sany/generator-def-entries.ts +210 -0
- package/src/sany/generator-definitions.ts +686 -0
- package/src/sany/generator-expressions.ts +1100 -0
- package/src/sany/generator-proofs.ts +662 -0
- package/src/sany/generator.ts +155 -2625
- package/src/sany/lexer.ts +17 -16
- package/src/sany/nodes.ts +6 -13
- package/src/sany/report.ts +3 -6
- package/src/sany/selectors.ts +35 -38
- package/src/sany/xml.ts +23 -55
- package/src/search.ts +65 -27
- package/src/simulate.ts +157 -133
- package/src/spec-description.ts +33 -48
- package/src/standard-modules.ts +16 -32
- package/src/state-graph.ts +2 -7
- package/src/substitution-levels.ts +5 -4
- package/src/successors.ts +5 -7
- package/src/tlc/messages.ts +20 -15
- package/src/tlc/order.ts +2 -9
- package/src/tlc/random.ts +4 -4
- package/src/tlc/replay.ts +8 -15
- package/src/tlc/tlc-operators.ts +2 -3
- package/src/tlc/trace-spec.ts +25 -45
- package/src/typescript/actions.ts +2 -4
- package/src/typescript/collections.ts +34 -20
- package/src/typescript/compile.ts +1 -3
- package/src/typescript/formula.ts +5 -3
- package/src/typescript/model.ts +4 -5
- package/src/typescript/steps.ts +20 -18
- package/src/values.ts +63 -158
package/src/cli/xml-exporter.ts
CHANGED
|
@@ -13,9 +13,9 @@ import {
|
|
|
13
13
|
reportMissingModules174,
|
|
14
14
|
toLibraryPath,
|
|
15
15
|
} from "./shared";
|
|
16
|
+
import { getBold } from "./tlc-usage";
|
|
16
17
|
|
|
17
18
|
const XML_EXPORT_USAGE = (() => {
|
|
18
|
-
const bold = (text: string) => `\x1b[1m${text}\x1b[0m`;
|
|
19
19
|
const options = [
|
|
20
20
|
["-I", "Include; use given directory path to resolve module dependencies."],
|
|
21
21
|
["-help", "Print this usage information."],
|
|
@@ -37,24 +37,24 @@ const XML_EXPORT_USAGE = (() => {
|
|
|
37
37
|
];
|
|
38
38
|
return [
|
|
39
39
|
"",
|
|
40
|
-
|
|
40
|
+
getBold("NAME"),
|
|
41
41
|
"",
|
|
42
42
|
"\ttla2sany.xml.XMLExporter - Emit SANY's parse tree as XML - Version 2.2 created 08 July 2020",
|
|
43
43
|
"",
|
|
44
44
|
"",
|
|
45
|
-
|
|
45
|
+
getBold("SYNOPSIS"),
|
|
46
46
|
"",
|
|
47
|
-
`\t${
|
|
47
|
+
`\t${getBold("tla2sany.xml.XMLExporter")} [${getBold("-Iortu")}] [${getBold("-help")}] FILE`,
|
|
48
48
|
"",
|
|
49
|
-
|
|
49
|
+
getBold("DESCRIPTION"),
|
|
50
50
|
"",
|
|
51
51
|
"\tGiven a TLA+ file, parse that file with SANY then translate the module's semantic parse tree to XML, including all the modules depended on. The XML is printed to stdout and its output format is given by an XML Schema file (.xsd) found at https://proofs.tlapl.us/doc/web/sany.xsd.",
|
|
52
52
|
"",
|
|
53
|
-
|
|
53
|
+
getBold("OPTIONS"),
|
|
54
54
|
"",
|
|
55
|
-
...options.map(([flag, description]) => `\t${
|
|
55
|
+
...options.map(([flag, description]) => `\t${getBold(flag)}\n\t\t${description}`),
|
|
56
56
|
"",
|
|
57
|
-
|
|
57
|
+
getBold("TIPS"),
|
|
58
58
|
"",
|
|
59
59
|
...tips.flatMap((tip) => [`\t${tip}`, ""]),
|
|
60
60
|
"",
|
|
@@ -83,14 +83,24 @@ const writeXml = (specification: SanySpecification, options: XmlExportOptions) =
|
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
85
|
|
|
86
|
+
const ARGUMENT_ERRORS = {
|
|
87
|
+
"no-file": { message: "at least one .tla file must be given", line174: 59 },
|
|
88
|
+
"missing-include": {
|
|
89
|
+
message: "the -I flag must be followed by a directory and at least one .tla file",
|
|
90
|
+
line174: 71,
|
|
91
|
+
},
|
|
92
|
+
"several-files": { message: "Only one TLA file to check allowed!", line174: 83 },
|
|
93
|
+
};
|
|
94
|
+
|
|
86
95
|
interface XmlExportArgs {
|
|
87
96
|
flags: Set<string>;
|
|
88
97
|
includes: string[];
|
|
89
|
-
error:
|
|
98
|
+
error: keyof typeof ARGUMENT_ERRORS | undefined;
|
|
90
99
|
}
|
|
91
100
|
|
|
92
101
|
const parseXmlExportArgs = (args: string[], flagNames: Set<string>): XmlExportArgs => {
|
|
93
102
|
const parsed: XmlExportArgs = { flags: new Set(), includes: [], error: undefined };
|
|
103
|
+
if (args.length === 0) return { ...parsed, error: "no-file" };
|
|
94
104
|
let lastFlagIndex = -1;
|
|
95
105
|
for (let index = 0; index < args.length - 1; index++) {
|
|
96
106
|
if (flagNames.has(args[index])) {
|
|
@@ -108,16 +118,8 @@ const parseXmlExportArgs = (args: string[], flagNames: Set<string>): XmlExportAr
|
|
|
108
118
|
};
|
|
109
119
|
|
|
110
120
|
export const exportXml = (args: string[]) => {
|
|
111
|
-
if (args.length === 0) return printXmlExportUsageError("at least one .tla file must be given");
|
|
112
121
|
const parsed = parseXmlExportArgs(args, new Set(["-o", "-t", "-r", "-u"]));
|
|
113
|
-
if (parsed.error
|
|
114
|
-
return printXmlExportUsageError(
|
|
115
|
-
"the -I flag must be followed by a directory and at least one .tla file",
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
if (parsed.error === "several-files") {
|
|
119
|
-
return printXmlExportUsageError("Only one TLA file to check allowed!");
|
|
120
|
-
}
|
|
122
|
+
if (parsed.error) return printXmlExportUsageError(ARGUMENT_ERRORS[parsed.error].message);
|
|
121
123
|
const name = args[args.length - 1];
|
|
122
124
|
if (name === "-help") {
|
|
123
125
|
process.stdout.write(XML_EXPORT_USAGE);
|
|
@@ -154,23 +156,11 @@ const printXmlExporterException = (exception: string, line: number) => {
|
|
|
154
156
|
};
|
|
155
157
|
|
|
156
158
|
export const exportXml174 = (args: string[], jar: string | undefined) => {
|
|
157
|
-
if (args.length === 0) {
|
|
158
|
-
return printXmlExporterException(
|
|
159
|
-
"java.lang.IllegalArgumentException: at least one .tla file must be given",
|
|
160
|
-
59,
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
159
|
const parsed = parseXmlExportArgs(args, new Set(["-o"]));
|
|
164
|
-
if (parsed.error
|
|
165
|
-
return printXmlExporterException(
|
|
166
|
-
"java.lang.IllegalArgumentException: the -I flag must be followed by a directory and at least one .tla file",
|
|
167
|
-
71,
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
if (parsed.error === "several-files") {
|
|
160
|
+
if (parsed.error) {
|
|
171
161
|
return printXmlExporterException(
|
|
172
|
-
|
|
173
|
-
|
|
162
|
+
`java.lang.IllegalArgumentException: ${ARGUMENT_ERRORS[parsed.error].message}`,
|
|
163
|
+
ARGUMENT_ERRORS[parsed.error].line174,
|
|
174
164
|
);
|
|
175
165
|
}
|
|
176
166
|
const name = args[args.length - 1];
|
package/src/codegen.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getChildren, isLocallyResolved, type Expression } from "./ast";
|
|
1
|
+
import { getChildren, getReferencedName, isLocallyResolved, type Expression } from "./ast";
|
|
2
2
|
import {
|
|
3
3
|
bindValue,
|
|
4
4
|
expectBooleanBody,
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
resolveGlobalOperator,
|
|
26
26
|
expectFunction,
|
|
27
27
|
toKeepLazyContext,
|
|
28
|
+
toNextContext,
|
|
28
29
|
createUnassignedError,
|
|
29
30
|
getSortedFields,
|
|
30
31
|
hasDuplicateFields,
|
|
@@ -122,13 +123,7 @@ const createGeneratedHelpers = () => ({
|
|
|
122
123
|
unassigned: (name: string, expression: Expression): never => {
|
|
123
124
|
throw createUnassignedError(name, expression);
|
|
124
125
|
},
|
|
125
|
-
prime:
|
|
126
|
-
environment: context.environment,
|
|
127
|
-
scope: context.scope,
|
|
128
|
-
state: context.next,
|
|
129
|
-
next: undefined,
|
|
130
|
-
isKeepLazy: context.isKeepLazy,
|
|
131
|
-
}),
|
|
126
|
+
prime: toNextContext,
|
|
132
127
|
keepLazyContext: toKeepLazyContext,
|
|
133
128
|
extend: (context: Context, names: string[], values: Value[]): Context => ({
|
|
134
129
|
environment: context.environment,
|
|
@@ -164,8 +159,8 @@ const addReference = (generator: Generator, value: unknown) => {
|
|
|
164
159
|
const createLocal = (generator: Generator) => `local${generator.counter++}`;
|
|
165
160
|
|
|
166
161
|
const getFreeNames = (expression: Expression, names = new Set<string>()) => {
|
|
167
|
-
|
|
168
|
-
if (
|
|
162
|
+
const name = getReferencedName(expression);
|
|
163
|
+
if (name !== undefined) names.add(name);
|
|
169
164
|
getChildren(expression).forEach((child) => getFreeNames(child, names));
|
|
170
165
|
return names;
|
|
171
166
|
};
|
package/src/coverage.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from "./ast";
|
|
9
9
|
import { formatRange } from "./errors";
|
|
10
10
|
import type { Environment, Scope } from "./evaluate";
|
|
11
|
+
import { getJavaHashCode } from "./java-hash";
|
|
11
12
|
import { getTlcFingerprint } from "./tlc/fingerprint";
|
|
12
13
|
import type { Value } from "./values";
|
|
13
14
|
|
|
@@ -204,12 +205,6 @@ const getStartRange = (location: SourceLocation, last: SourceRange | undefined)
|
|
|
204
205
|
end: last.end,
|
|
205
206
|
};
|
|
206
207
|
|
|
207
|
-
const getJavaHashCode = (text: string) =>
|
|
208
|
-
Array.from({ length: text.length }, (_value, index) => text.charCodeAt(index)).reduce(
|
|
209
|
-
(hash, code) => (Math.imul(hash, 31) + code) | 0,
|
|
210
|
-
0,
|
|
211
|
-
) & 0x7fffffff;
|
|
212
|
-
|
|
213
208
|
const getHashtableOrder = (definitions: Definition[]) => {
|
|
214
209
|
let buckets = Array.from({ length: 11 }, (): Definition[] => []);
|
|
215
210
|
definitions.forEach((definition, count) => {
|
|
@@ -217,12 +212,12 @@ const getHashtableOrder = (definitions: Definition[]) => {
|
|
|
217
212
|
const grown = Array.from({ length: buckets.length * 2 + 1 }, (): Definition[] => []);
|
|
218
213
|
for (let index = buckets.length - 1; index >= 0; index--) {
|
|
219
214
|
buckets[index].forEach((entry) =>
|
|
220
|
-
grown[getJavaHashCode(entry.name) % grown.length].unshift(entry),
|
|
215
|
+
grown[(getJavaHashCode(entry.name) & 0x7fffffff) % grown.length].unshift(entry),
|
|
221
216
|
);
|
|
222
217
|
}
|
|
223
218
|
buckets = grown;
|
|
224
219
|
}
|
|
225
|
-
buckets[getJavaHashCode(definition.name) % buckets.length].unshift(definition);
|
|
220
|
+
buckets[(getJavaHashCode(definition.name) & 0x7fffffff) % buckets.length].unshift(definition);
|
|
226
221
|
});
|
|
227
222
|
return buckets.toReversed().flat();
|
|
228
223
|
};
|
|
@@ -382,8 +377,6 @@ export const buildCoverage = (
|
|
|
382
377
|
case "OperatorReference":
|
|
383
378
|
return;
|
|
384
379
|
case "Label":
|
|
385
|
-
walk(expression.body, bindNames(expression.params, locals));
|
|
386
|
-
return;
|
|
387
380
|
case "Lambda":
|
|
388
381
|
walk(expression.body, bindNames(expression.params, locals));
|
|
389
382
|
return;
|
package/src/dependencies.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
getChildren,
|
|
3
|
+
getDefinitionExpressions,
|
|
4
|
+
getReferencedName,
|
|
5
|
+
isLocallyResolved,
|
|
6
|
+
type Definition,
|
|
7
|
+
type Expression,
|
|
8
|
+
} from "./ast";
|
|
2
9
|
import type { Environment } from "./evaluate";
|
|
3
10
|
import { ACTION_LEVEL, CONSTANT_LEVEL, TEMPORAL_LEVEL, VARIABLE_LEVEL } from "./levels";
|
|
4
11
|
|
|
@@ -58,13 +65,6 @@ const IMPURE_BUILTINS = new Set([
|
|
|
58
65
|
|
|
59
66
|
const STREAMED_BUILTINS = new Set(["UNION", "\\cup"]);
|
|
60
67
|
|
|
61
|
-
const getReferencedName = (expression: Expression) => {
|
|
62
|
-
if (expression.kind === "Identifier") return expression.name;
|
|
63
|
-
if (expression.kind === "Apply" || expression.kind === "OperatorReference")
|
|
64
|
-
return expression.operator;
|
|
65
|
-
return undefined;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
68
|
const isImpureBuiltin = (name: string, environment: DefinitionNames) =>
|
|
69
69
|
IMPURE_BUILTINS.has(name) || environment.builtins.get(name)?.isStateLevel === true;
|
|
70
70
|
|
|
@@ -152,11 +152,6 @@ const collectLocalFacts = (
|
|
|
152
152
|
return { row, edges };
|
|
153
153
|
};
|
|
154
154
|
|
|
155
|
-
const getDefinitionExpressions = (definition: Definition) =>
|
|
156
|
-
definition.kind === "Function"
|
|
157
|
-
? [...definition.bounds.map((bound) => bound.set), definition.body]
|
|
158
|
-
: [definition.body];
|
|
159
|
-
|
|
160
155
|
const closeRows = (local: Uint32Array, words: number, edges: Int32Array[], mask: number) => {
|
|
161
156
|
const count = edges.length;
|
|
162
157
|
const closed = local.slice();
|
package/src/dfid.ts
CHANGED
|
@@ -14,7 +14,7 @@ import { createTracingEnvironment } from "./evaluate";
|
|
|
14
14
|
import { EXIT_STATUS, getMessageExitStatus, withLivenessExitCode } from "./exit-codes";
|
|
15
15
|
import { createLivenessChecker } from "./liveness-checker";
|
|
16
16
|
import { getIncompleteSuccessorMessage, prepareSearch, reportAssumptionViolation } from "./search";
|
|
17
|
-
import {
|
|
17
|
+
import type { SpecAction } from "./spec-description";
|
|
18
18
|
import { forEachInitialState, forEachSuccessor } from "./successors";
|
|
19
19
|
import {
|
|
20
20
|
formatNestedMessage,
|
|
@@ -52,7 +52,8 @@ interface CheckerState {
|
|
|
52
52
|
continuedCode: number;
|
|
53
53
|
isKeepingCallStack: boolean;
|
|
54
54
|
errorEntry: StateEntry | undefined;
|
|
55
|
-
stopCode:
|
|
55
|
+
/** DFIDWorker's stopCode: 0 while it searches, 1 once every initial state is done, 2 after an error. */
|
|
56
|
+
stopCode: "searching" | "done" | "error";
|
|
56
57
|
isMoreLevel: boolean;
|
|
57
58
|
}
|
|
58
59
|
|
|
@@ -163,7 +164,7 @@ export const checkDepthFirst = (options: DepthFirstOptions): number => {
|
|
|
163
164
|
);
|
|
164
165
|
if (assumptionStatus !== undefined) return assumptionStatus;
|
|
165
166
|
|
|
166
|
-
const nextActions =
|
|
167
|
+
const nextActions = prepared.getDescription().actions;
|
|
167
168
|
const statuses = new Map<bigint, number>();
|
|
168
169
|
const fingerprintSet = { level: 1, leveled: 0, buckets: INITIAL_BUCKETS };
|
|
169
170
|
const setStatus = (fingerprint: bigint, status: number) => {
|
|
@@ -188,7 +189,7 @@ export const checkDepthFirst = (options: DepthFirstOptions): number => {
|
|
|
188
189
|
continuedCode: NO_ERROR,
|
|
189
190
|
isKeepingCallStack: false,
|
|
190
191
|
errorEntry: undefined,
|
|
191
|
-
stopCode:
|
|
192
|
+
stopCode: "searching",
|
|
192
193
|
isMoreLevel: false,
|
|
193
194
|
};
|
|
194
195
|
const setErrorState = (entry: StateEntry, isKeepingCallStack: boolean, code: number) => {
|
|
@@ -197,7 +198,7 @@ export const checkDepthFirst = (options: DepthFirstOptions): number => {
|
|
|
197
198
|
checker.errorCode = code;
|
|
198
199
|
checker.isDone = true;
|
|
199
200
|
checker.isKeepingCallStack = isKeepingCallStack;
|
|
200
|
-
checker.stopCode =
|
|
201
|
+
checker.stopCode = "error";
|
|
201
202
|
return true;
|
|
202
203
|
};
|
|
203
204
|
const toRecord = (state: (Value | undefined)[]) =>
|
|
@@ -442,28 +443,28 @@ export const checkDepthFirst = (options: DepthFirstOptions): number => {
|
|
|
442
443
|
throw failure;
|
|
443
444
|
}
|
|
444
445
|
};
|
|
445
|
-
const
|
|
446
|
+
const hasNext = (successors: StateEntry[], level: number) => {
|
|
446
447
|
while (successors.length > 0) {
|
|
447
448
|
const status = getStatus(successors[0].fingerprint);
|
|
448
|
-
if (!isCompleted(status) && level < status >>> 2) return
|
|
449
|
+
if (!isCompleted(status) && level < status >>> 2) return true;
|
|
449
450
|
successors[0] = successors[successors.length - 1];
|
|
450
451
|
successors.pop();
|
|
451
452
|
}
|
|
452
|
-
return
|
|
453
|
+
return false;
|
|
453
454
|
};
|
|
454
455
|
const searchLevel = (toLevel: number) => {
|
|
455
456
|
const initials = [...initialEntries];
|
|
456
|
-
checker.stopCode =
|
|
457
|
+
checker.stopCode = "searching";
|
|
457
458
|
checker.isMoreLevel = false;
|
|
458
459
|
let stackLevel = 0;
|
|
459
460
|
try {
|
|
460
|
-
while (checker.stopCode ===
|
|
461
|
+
while (checker.stopCode === "searching") {
|
|
461
462
|
while (initials.length > 0 && isCompleted(getStatus(initials[0].fingerprint))) {
|
|
462
463
|
initials[0] = initials[initials.length - 1];
|
|
463
464
|
initials.pop();
|
|
464
465
|
}
|
|
465
466
|
if (initials.length === 0) {
|
|
466
|
-
checker.stopCode =
|
|
467
|
+
checker.stopCode = "done";
|
|
467
468
|
return;
|
|
468
469
|
}
|
|
469
470
|
stack[0] = initials[0];
|
|
@@ -474,8 +475,7 @@ export const checkDepthFirst = (options: DepthFirstOptions): number => {
|
|
|
474
475
|
checker.isMoreLevel ||= !isInitialNoLeaf;
|
|
475
476
|
stackLevel = 1;
|
|
476
477
|
while (!isInitialLeaf) {
|
|
477
|
-
|
|
478
|
-
if (index === -1) {
|
|
478
|
+
if (!hasNext(successorStack[stackLevel - 1], stackLevel)) {
|
|
479
479
|
const entry = stack[stackLevel - 1];
|
|
480
480
|
statuses.set(
|
|
481
481
|
entry.fingerprint,
|
|
@@ -485,7 +485,7 @@ export const checkDepthFirst = (options: DepthFirstOptions): number => {
|
|
|
485
485
|
stackLevel--;
|
|
486
486
|
continue;
|
|
487
487
|
}
|
|
488
|
-
stack[stackLevel] = successorStack[stackLevel - 1][
|
|
488
|
+
stack[stackLevel] = successorStack[stackLevel - 1][0];
|
|
489
489
|
successorStack[stackLevel] = [];
|
|
490
490
|
const isLeaf = stackLevel >= toLevel - 1;
|
|
491
491
|
const isNoLeaf = expandState(stackLevel, isLeaf, successorStack[stackLevel]);
|
|
@@ -496,7 +496,7 @@ export const checkDepthFirst = (options: DepthFirstOptions): number => {
|
|
|
496
496
|
}
|
|
497
497
|
} catch (error) {
|
|
498
498
|
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
499
|
-
checker.stopCode =
|
|
499
|
+
checker.stopCode = "error";
|
|
500
500
|
if (setErrorState(stack[stackLevel], true, MESSAGE_CODE.general)) {
|
|
501
501
|
const unexpected = getUnexpectedMessage("", error);
|
|
502
502
|
message(
|
|
@@ -612,7 +612,7 @@ export const checkDepthFirst = (options: DepthFirstOptions): number => {
|
|
|
612
612
|
checker.isDone = false;
|
|
613
613
|
levelCode = checker.isKeepingCallStack ? NO_ERROR : checker.errorCode;
|
|
614
614
|
if (levelCode !== NO_ERROR) return finish(levelCode);
|
|
615
|
-
isTerminated = checker.stopCode ===
|
|
615
|
+
isTerminated = checker.stopCode === "error" || !checker.isMoreLevel;
|
|
616
616
|
}
|
|
617
617
|
return finish(levelCode);
|
|
618
618
|
};
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import type { Definition } from "./ast";
|
|
2
|
+
import type { ConfigValue, ModelConfig } from "./config";
|
|
3
|
+
import {
|
|
4
|
+
TlaConfigError,
|
|
5
|
+
TlaEvaluationError,
|
|
6
|
+
TlaFeatureUnsupportedError,
|
|
7
|
+
TlaModuleError,
|
|
8
|
+
UNEXPECTED_EXCEPTION,
|
|
9
|
+
} from "./errors";
|
|
10
|
+
import { EXIT_STATUS, setExitCode } from "./exit-codes";
|
|
11
|
+
import type { LinkedModule } from "./environment";
|
|
12
|
+
import type { Builtin } from "./evaluate";
|
|
13
|
+
import { createLocalAlias } from "./instances";
|
|
14
|
+
import type { Symbols } from "./resolve";
|
|
15
|
+
import type { TlcOrder } from "./tlc/order";
|
|
16
|
+
import {
|
|
17
|
+
createModelValue,
|
|
18
|
+
formatValue,
|
|
19
|
+
isTlcInteger,
|
|
20
|
+
markNormalized,
|
|
21
|
+
toFiniteSet,
|
|
22
|
+
valuesEqual,
|
|
23
|
+
type Value,
|
|
24
|
+
} from "./values";
|
|
25
|
+
|
|
26
|
+
export interface CopySource {
|
|
27
|
+
source: string;
|
|
28
|
+
prefix: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface LinkedSpecification {
|
|
32
|
+
root: LinkedModule;
|
|
33
|
+
moduleSymbols: Map<string, Symbols>;
|
|
34
|
+
definitions: Map<string, Definition>;
|
|
35
|
+
builtins: Map<string, Builtin>;
|
|
36
|
+
copySources: Map<string, CopySource>;
|
|
37
|
+
operatorConstants: Map<string, Value>;
|
|
38
|
+
order: TlcOrder;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface AppliedConfig {
|
|
42
|
+
constants: Map<string, Value>;
|
|
43
|
+
substitutions: Map<string, string>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const toValue = (value: ConfigValue): Value => {
|
|
47
|
+
switch (value.kind) {
|
|
48
|
+
case "Number":
|
|
49
|
+
// Deviation from TLC: ModelConfig#parseValue lets Integer.parseInt fail on a number too big, where tla-ts reports it as TLC reports such a number in a module.
|
|
50
|
+
if (!isTlcInteger(value.value)) {
|
|
51
|
+
throw setExitCode(
|
|
52
|
+
new TlaModuleError(`TLC can't handle a number this big.\n${value.value}`),
|
|
53
|
+
EXIT_STATUS.error,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
return value.value;
|
|
57
|
+
case "String":
|
|
58
|
+
case "Boolean":
|
|
59
|
+
return value.value;
|
|
60
|
+
case "ModelValue":
|
|
61
|
+
return createModelValue(value.name);
|
|
62
|
+
case "Set":
|
|
63
|
+
return toFiniteSet({ kind: "MixedSet", elements: value.elements.map(toValue) });
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const toConstantValue = (value: ConfigValue) => {
|
|
68
|
+
try {
|
|
69
|
+
return toValue(value);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if (
|
|
72
|
+
!(error instanceof TlaEvaluationError) ||
|
|
73
|
+
error instanceof TlaModuleError ||
|
|
74
|
+
error instanceof TlaFeatureUnsupportedError
|
|
75
|
+
) {
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
throw setExitCode(
|
|
79
|
+
new TlaEvaluationError(`${UNEXPECTED_EXCEPTION}${error.message}`),
|
|
80
|
+
EXIT_STATUS.error,
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const createOperatorTable = (name: string, arity: number, rows: [Value[], Value][]): Builtin => {
|
|
86
|
+
const table = `{ ${rows.map((row) => `<${[...row[0], row[1]].map((value) => formatValue(value)).join(", ")}>`).join(", ")}}`;
|
|
87
|
+
return {
|
|
88
|
+
kind: "Builtin",
|
|
89
|
+
name,
|
|
90
|
+
arity,
|
|
91
|
+
evaluate: (args) => {
|
|
92
|
+
const row = rows.find((candidate) => {
|
|
93
|
+
if (candidate[0].length !== args.length) {
|
|
94
|
+
throw new TlaEvaluationError(
|
|
95
|
+
`Attempted to apply the operator ${table}\nwith wrong number of arguments.`,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
return candidate[0].every((value, index) => {
|
|
99
|
+
const argument = args[index];
|
|
100
|
+
return (
|
|
101
|
+
!(typeof argument === "object" && argument.kind === "Operator") &&
|
|
102
|
+
valuesEqual(value, argument)
|
|
103
|
+
);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
if (row) return row[1];
|
|
107
|
+
throw new TlaEvaluationError(
|
|
108
|
+
`Attempted to apply operator:\n${table}\nto arguments (${args.map((argument) => (typeof argument === "object" && argument.kind === "Operator" ? argument.name : formatValue(argument))).join(", ")}), which is undefined.`,
|
|
109
|
+
);
|
|
110
|
+
},
|
|
111
|
+
evaluateUnary: undefined,
|
|
112
|
+
evaluateBinary: undefined,
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const createReusedTargetError = (target: string) =>
|
|
117
|
+
new TlaConfigError(
|
|
118
|
+
`In the configuration file, the identifier ${target} appears\non the right-hand side of a <- after already appearing on the\nleft-hand side of one.`,
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
export const applyConfig = (config: ModelConfig, linked: LinkedSpecification): AppliedConfig => {
|
|
122
|
+
const getRootKey = (name: string) => linked.root.visible.get(name)?.key ?? name;
|
|
123
|
+
const declaredConstants = linked.root.constants.map((constant) => constant.name);
|
|
124
|
+
const variables = linked.root.variables;
|
|
125
|
+
const getScopedSymbol = (item: { name: string; module?: string }) => {
|
|
126
|
+
const symbol = linked.moduleSymbols.get(item.module ?? "")?.get(item.name);
|
|
127
|
+
return symbol?.kind === "Definition" ? symbol : undefined;
|
|
128
|
+
};
|
|
129
|
+
const getSubstitutedKeys = (item: { name: string; module?: string }) => {
|
|
130
|
+
if (item.module === undefined) return [item.name, getRootKey(item.name)];
|
|
131
|
+
const symbol = getScopedSymbol(item);
|
|
132
|
+
return symbol ? [symbol.key] : [];
|
|
133
|
+
};
|
|
134
|
+
const getScopedKeys = (item: { name: string; module?: string }) =>
|
|
135
|
+
item.module === linked.root.module.name ? [] : getSubstitutedKeys(item);
|
|
136
|
+
const getKeyArity = (key: string) => {
|
|
137
|
+
const definition = linked.definitions.get(key);
|
|
138
|
+
return definition?.kind === "Operator"
|
|
139
|
+
? definition.params.length
|
|
140
|
+
: (linked.root.constants.find((constant) => constant.name === key)?.arity ??
|
|
141
|
+
linked.builtins.get(key)?.arity ??
|
|
142
|
+
0);
|
|
143
|
+
};
|
|
144
|
+
const constants = new Map<string, Value>();
|
|
145
|
+
const operatorKeys = new Set<string>();
|
|
146
|
+
const setOperator = (key: string, operator: Builtin) => {
|
|
147
|
+
linked.builtins.set(key, operator);
|
|
148
|
+
linked.definitions.delete(key);
|
|
149
|
+
constants.delete(key);
|
|
150
|
+
operatorKeys.add(key);
|
|
151
|
+
};
|
|
152
|
+
config.constants
|
|
153
|
+
.filter((assignment) => assignment.args === undefined)
|
|
154
|
+
.forEach((assignment) => {
|
|
155
|
+
const value = toConstantValue(assignment.value);
|
|
156
|
+
markNormalized(value);
|
|
157
|
+
getScopedKeys(assignment).forEach((key) => {
|
|
158
|
+
const arity = getKeyArity(key);
|
|
159
|
+
if (arity === 0) constants.set(key, value);
|
|
160
|
+
else
|
|
161
|
+
setOperator(key, {
|
|
162
|
+
kind: "Builtin",
|
|
163
|
+
name: key,
|
|
164
|
+
arity,
|
|
165
|
+
evaluate: () => value,
|
|
166
|
+
evaluateUnary: undefined,
|
|
167
|
+
evaluateBinary: undefined,
|
|
168
|
+
isLazy: true,
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
const tables = new Map<string, { name: string; module?: string; rows: [Value[], Value][] }>();
|
|
173
|
+
config.constants.forEach((assignment) => {
|
|
174
|
+
if (assignment.args === undefined) return;
|
|
175
|
+
const tableKey = `${assignment.module ?? ""}!${assignment.name}`;
|
|
176
|
+
const table = tables.get(tableKey) ?? {
|
|
177
|
+
name: assignment.name,
|
|
178
|
+
module: assignment.module,
|
|
179
|
+
rows: [],
|
|
180
|
+
};
|
|
181
|
+
if (table.rows.length > 0 && table.rows[0][0].length !== assignment.args.length) {
|
|
182
|
+
throw new TlaConfigError(
|
|
183
|
+
`The arity of the operator ${assignment.name} is inconsistent in the configuration file.`,
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
table.rows.push([assignment.args.map(toValue), toValue(assignment.value)]);
|
|
187
|
+
tables.set(tableKey, table);
|
|
188
|
+
});
|
|
189
|
+
tables.forEach((table) =>
|
|
190
|
+
getScopedKeys(table).forEach((key) =>
|
|
191
|
+
setOperator(key, createOperatorTable(table.name, getKeyArity(key), table.rows)),
|
|
192
|
+
),
|
|
193
|
+
);
|
|
194
|
+
const substitutions = new Map(
|
|
195
|
+
config.substitutions.flatMap((substitution) =>
|
|
196
|
+
getSubstitutedKeys(substitution).map((key): [string, string] => [
|
|
197
|
+
key,
|
|
198
|
+
getRootKey(substitution.target),
|
|
199
|
+
]),
|
|
200
|
+
),
|
|
201
|
+
);
|
|
202
|
+
[...substitutions.keys()].forEach((key) => constants.delete(key));
|
|
203
|
+
const checkSubstitutionTarget = (name: string, target: string, arity: number | undefined) => {
|
|
204
|
+
const targetKey = getRootKey(target);
|
|
205
|
+
const definition = linked.definitions.get(targetKey);
|
|
206
|
+
const isDefined =
|
|
207
|
+
definition !== undefined ||
|
|
208
|
+
linked.builtins.has(targetKey) ||
|
|
209
|
+
constants.has(targetKey) ||
|
|
210
|
+
declaredConstants.includes(target) ||
|
|
211
|
+
variables.includes(target);
|
|
212
|
+
if (!isDefined) {
|
|
213
|
+
throw new TlaConfigError(
|
|
214
|
+
`The configuration file substitutes for ${name} with the undefined identifier ${target}.`,
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
if (definition?.kind === "Operator" && definition.params.length !== arity) {
|
|
218
|
+
throw new TlaConfigError(
|
|
219
|
+
`The configuration file substitutes for ${name} with ${target} of different number of arguments.`,
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
config.substitutions
|
|
224
|
+
.filter((substitution) => substitution.module === undefined)
|
|
225
|
+
.forEach((substitution) => {
|
|
226
|
+
const name = substitution.name;
|
|
227
|
+
const target = substitution.target;
|
|
228
|
+
if (!declaredConstants.includes(name) && !linked.root.visible.has(name)) {
|
|
229
|
+
throw new TlaConfigError(
|
|
230
|
+
`In the configuration file, the identifier ${name} does not appear in the specification.`,
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
if (config.substitutions.some((other) => other.name === target)) {
|
|
234
|
+
throw createReusedTargetError(target);
|
|
235
|
+
}
|
|
236
|
+
checkSubstitutionTarget(
|
|
237
|
+
name,
|
|
238
|
+
target,
|
|
239
|
+
linked.root.constants.find((constant) => constant.name === name)?.arity ??
|
|
240
|
+
linked.root.visible.get(name)?.arity,
|
|
241
|
+
);
|
|
242
|
+
});
|
|
243
|
+
const scopedSubstitutions = config.substitutions.filter(
|
|
244
|
+
(substitution) => substitution.module !== undefined,
|
|
245
|
+
);
|
|
246
|
+
[...linked.moduleSymbols.keys()].forEach((name) => {
|
|
247
|
+
const inModule = scopedSubstitutions.filter((substitution) => substitution.module === name);
|
|
248
|
+
inModule.forEach((substitution) => {
|
|
249
|
+
const symbol = getScopedSymbol(substitution);
|
|
250
|
+
if (!symbol) return;
|
|
251
|
+
if (inModule.some((other) => other.name === substitution.target)) {
|
|
252
|
+
throw createReusedTargetError(substitution.target);
|
|
253
|
+
}
|
|
254
|
+
checkSubstitutionTarget(substitution.name, substitution.target, symbol.arity);
|
|
255
|
+
});
|
|
256
|
+
const missing = inModule.find((substitution) => !getScopedSymbol(substitution));
|
|
257
|
+
if (missing) {
|
|
258
|
+
throw new TlaConfigError(
|
|
259
|
+
`In the configuration file, the identifier ${missing.name} does not appear in the specification.`,
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
const unknownModule = scopedSubstitutions.find(
|
|
264
|
+
(substitution) => !linked.moduleSymbols.has(substitution.module ?? ""),
|
|
265
|
+
);
|
|
266
|
+
if (unknownModule) {
|
|
267
|
+
throw new TlaConfigError(
|
|
268
|
+
`In the configuration file, the module name ${unknownModule.module} is not a module in the specification.`,
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
const scopedKeys = new Set(
|
|
272
|
+
[...config.constants, ...config.substitutions]
|
|
273
|
+
.filter((item) => item.module !== undefined)
|
|
274
|
+
.flatMap(getScopedKeys),
|
|
275
|
+
);
|
|
276
|
+
const getOverride = (
|
|
277
|
+
key: string,
|
|
278
|
+
prefix: number,
|
|
279
|
+
): { key: string; prefix: number } | undefined => {
|
|
280
|
+
if (scopedKeys.has(key)) return { key, prefix };
|
|
281
|
+
const copy = linked.copySources.get(key);
|
|
282
|
+
return copy && getOverride(copy.source, prefix + copy.prefix);
|
|
283
|
+
};
|
|
284
|
+
linked.copySources.forEach((copy, key) => {
|
|
285
|
+
const override = getOverride(copy.source, copy.prefix);
|
|
286
|
+
const definition = linked.definitions.get(key);
|
|
287
|
+
if (!override || !definition) return;
|
|
288
|
+
const params = definition.kind === "Operator" ? definition.params : [];
|
|
289
|
+
const alias = createLocalAlias(
|
|
290
|
+
key,
|
|
291
|
+
override.key,
|
|
292
|
+
params,
|
|
293
|
+
params.slice(override.prefix),
|
|
294
|
+
definition.location,
|
|
295
|
+
);
|
|
296
|
+
linked.definitions.set(key, alias);
|
|
297
|
+
linked.root.visible.forEach((symbol, name) => {
|
|
298
|
+
if (symbol.key === key && name !== key) linked.definitions.set(name, alias);
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
linked.operatorConstants.forEach((value, name) => constants.set(name, value));
|
|
302
|
+
const unassigned = declaredConstants.filter(
|
|
303
|
+
(name) => !constants.has(name) && !substitutions.has(name) && !operatorKeys.has(name),
|
|
304
|
+
);
|
|
305
|
+
if (unassigned.length > 0) {
|
|
306
|
+
const name =
|
|
307
|
+
linked.order
|
|
308
|
+
.getDeclarationOrder("constant")
|
|
309
|
+
.find((constant) => unassigned.includes(constant)) ?? unassigned[0];
|
|
310
|
+
throw new TlaConfigError(
|
|
311
|
+
`The constant parameter ${name} is not assigned a value by the configuration file.`,
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
return { constants, substitutions };
|
|
315
|
+
};
|