tla-ts 0.0.4-dev.b254db0 → 0.0.4-dev.ca40dfe
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 +31 -10
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/deciders.cjs +27 -27
- package/dist/deciders.js +34 -34
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +12 -14
- package/dist/index.d.ts +12 -14
- 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 +37 -27
- package/dist/prove.js +39 -29
- package/dist/run.cjs +45 -0
- package/dist/run.js +45 -0
- package/dist/tlapm.cjs +2 -2
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +76 -86
- package/dist/transfer.js +73 -83
- package/dist/worker.cjs +6 -6
- package/dist/worker.js +6 -6
- package/package.json +1 -1
- package/src/ast.ts +2 -2
- package/src/bags.ts +22 -23
- package/src/builtins.ts +16 -8
- package/src/check.ts +131 -1154
- package/src/{cli-options.ts → cli/options.ts} +54 -9
- package/src/cli/run.ts +63 -0
- package/src/cli/shared.ts +106 -0
- package/src/cli/tlapm.ts +374 -0
- package/src/cli/tlc.ts +941 -0
- package/src/cli/xml-exporter.ts +221 -0
- package/src/cli.ts +1 -1
- package/src/codegen.ts +17 -15
- package/src/config.ts +5 -5
- package/src/dependencies.ts +4 -6
- package/src/environment.ts +55 -60
- package/src/errors.ts +12 -36
- package/src/evaluate.ts +81 -101
- package/src/exit-codes.ts +1 -1
- package/src/fingerprints.ts +3 -3
- package/src/instances.ts +56 -46
- package/src/java-overrides.ts +79 -41
- package/src/json.ts +31 -36
- package/src/levels.ts +10 -13
- package/src/{live-check.ts → liveness-checker.ts} +169 -142
- package/src/liveness.ts +38 -34
- package/src/obligations/action.ts +9 -45
- package/src/obligations/{anon.ts → anonymize.ts} +13 -25
- package/src/obligations/equality.ts +260 -0
- package/src/obligations/expression.ts +42 -517
- package/src/obligations/generate.ts +88 -778
- package/src/obligations/index.ts +20 -22
- package/src/obligations/levels.ts +36 -41
- package/src/obligations/module.ts +88 -708
- package/src/obligations/normalize.ts +554 -0
- package/src/obligations/operators.ts +176 -0
- package/src/obligations/pragma.ts +21 -15
- package/src/obligations/printer.ts +81 -188
- package/src/obligations/proof.ts +0 -1
- package/src/obligations/regroup.ts +100 -0
- package/src/obligations/simplify.ts +668 -0
- package/src/obligations/source.ts +25 -131
- package/src/obligations/{deref.ts → subexpression.ts} +48 -56
- package/src/obligations/substitution.ts +261 -0
- package/src/obligations/temporal.ts +28 -26
- package/src/obligations/tuples.ts +37 -53
- package/src/parallel-worker.ts +37 -33
- package/src/parallel.ts +30 -24
- package/src/parser.ts +67 -74
- package/src/{pcal-ast.ts → pcal/ast.ts} +2 -17
- package/src/{pcal-parse.ts → pcal/parse.ts} +28 -64
- package/src/{pcal-tokenize.ts → pcal/tokenize.ts} +10 -39
- package/src/{pcal-translate.ts → pcal/translate.ts} +30 -109
- package/src/{pcal-validate.ts → pcal/validate.ts} +10 -20
- package/src/prove/decide-pool.ts +7 -12
- package/src/{obligations/pickle.ts → prove/first-order.ts} +79 -2
- package/src/prove/isabelle/decide.ts +3 -6
- package/src/prove/isabelle/encode.ts +35 -93
- package/src/prove/isabelle/isar/inner-syntax.ts +1 -1
- package/src/prove/isabelle/isar/method.ts +3 -3
- package/src/prove/isabelle/isar/type-check.ts +1 -1
- package/src/prove/isabelle/provers/blast/blast.ts +1 -1
- package/src/prove/isabelle/provers/blast/branch.ts +1 -1
- package/src/prove/isabelle/provers/blast/term.ts +3 -4
- package/src/prove/isabelle/provers/clasimp.ts +1 -1
- package/src/prove/isabelle/provers/classical.ts +3 -3
- package/src/prove/isabelle/provers/hypsubst.ts +1 -9
- package/src/prove/isabelle/pure/conv.ts +1 -1
- package/src/prove/isabelle/pure/drule.ts +2 -2
- package/src/prove/isabelle/pure/envir.ts +3 -35
- package/src/prove/isabelle/pure/logic.ts +4 -76
- package/src/prove/isabelle/pure/name.ts +1 -13
- package/src/prove/isabelle/pure/net.ts +2 -49
- package/src/prove/isabelle/pure/pattern.ts +3 -22
- package/src/prove/isabelle/pure/raw-simplifier.ts +3 -18
- package/src/prove/isabelle/pure/seq.ts +0 -23
- package/src/prove/isabelle/pure/simplifier.ts +2 -8
- package/src/prove/isabelle/pure/table.ts +1 -8
- package/src/prove/isabelle/pure/tactic.ts +5 -113
- package/src/prove/isabelle/pure/tactical.ts +1 -84
- package/src/prove/isabelle/pure/term-ord.ts +1 -55
- package/src/prove/isabelle/pure/term.ts +8 -128
- package/src/prove/isabelle/pure/thm.ts +4 -27
- package/src/prove/isabelle/pure/type.ts +0 -12
- package/src/prove/isabelle/pure/unify.ts +1 -1
- package/src/prove/isabelle/tla/classical-setup.ts +1 -1
- package/src/prove/ocaml.ts +1 -1
- package/src/prove/prep/action.ts +23 -36
- package/src/prove/prep/enabled-axioms.ts +2 -2
- package/src/prove/prep/fingerprint.ts +3 -3
- package/src/prove/prep/level-comparison.ts +9 -37
- package/src/prove/prep/md5.ts +2 -9
- package/src/prove/prep/normalize.ts +309 -0
- package/src/prove/prove-worker.ts +2 -5
- package/src/prove/prove.ts +98 -111
- package/src/prove/ptl/encode.ts +19 -31
- package/src/prove/smt/axioms.ts +45 -58
- package/src/prove/smt/encode.ts +124 -15
- package/src/prove/smt/instances.ts +2 -3
- package/src/prove/smt/rewrite.ts +24 -31
- package/src/prove/smt/solver/ast-util.ts +0 -56
- package/src/prove/smt/solver/case-split-queue.ts +1 -1
- package/src/prove/smt/solver/enode.ts +1 -1
- package/src/prove/smt/solver/lp/dep-intervals.ts +0 -14
- package/src/prove/smt/solver/model-macro-solver.ts +1 -1
- package/src/prove/smt/solver/nlsat/algebraic.ts +3 -3
- package/src/prove/smt/solver/nlsat/atoms.ts +1 -1
- package/src/prove/smt/solver/nlsat/explain.ts +1 -1
- package/src/prove/smt/solver/nlsat/interval-set.ts +1 -1
- package/src/prove/smt/solver/nlsat/levelwise.ts +4 -7
- package/src/prove/smt/solver/nlsat/polynomial.ts +4 -4
- package/src/prove/smt/solver/nlsat/upolynomial.ts +2 -2
- package/src/prove/smt/solver/pattern-inference.ts +1 -1
- package/src/prove/smt/solver/relevancy.ts +2 -2
- package/src/prove/smt/solver/rewriter.ts +1 -1
- package/src/prove/smt/solver/solver.ts +2 -2
- package/src/{tlapm-cache.ts → prove/tlapm/cache.ts} +11 -11
- package/src/{ocaml-marshal.ts → prove/tlapm/ocaml-marshal.ts} +1 -1
- package/src/prove/verdict.ts +0 -5
- package/src/prove/zenon/decide.ts +5 -11
- package/src/prove/zenon/encode.ts +21 -80
- package/src/prove/zenon/eqrel.ts +1 -1
- package/src/prove/zenon/equality-rules.ts +1 -1
- package/src/prove/zenon/expr.ts +2 -2
- package/src/prove/zenon/index-table.ts +1 -1
- package/src/prove/zenon/isar.ts +1 -1
- package/src/prove/zenon/llproof.ts +1 -1
- package/src/prove/zenon/mltoll.ts +1 -1
- package/src/prove/zenon/node.ts +1 -1
- package/src/prove/zenon/search.ts +1 -1
- package/src/prove/zenon/tla/terms.ts +1 -20
- package/src/prove/zenon/tla/tla.ts +1 -1
- package/src/randomization.ts +19 -24
- package/src/resolve.ts +15 -22
- package/src/runtime.ts +8 -8
- package/src/{sany-builtins.ts → sany/builtins.ts} +1 -1
- package/src/{sany-generator.ts → sany/generator.ts} +38 -55
- package/src/{sany-levels.ts → sany/levels.ts} +45 -48
- package/src/{sany-lexer.ts → sany/lexer.ts} +2 -3
- package/src/{sany-linter.ts → sany/linter.ts} +1 -1
- package/src/{sany-modules.ts → sany/modules.ts} +2 -2
- package/src/{sany-nodes.ts → sany/nodes.ts} +2 -2
- package/src/{sany-parse-error.ts → sany/parse-error.ts} +2 -2
- package/src/{sany-report.ts → sany/report.ts} +16 -17
- package/src/{sany-selectors.ts → sany/selectors.ts} +3 -5
- package/src/{sany-source.ts → sany/source.ts} +6 -7
- package/src/{sany-xml.ts → sany/xml.ts} +5 -6
- package/src/search.ts +969 -0
- package/src/spec-description.ts +26 -20
- package/src/{standard-levels.ts → standard-definitions.ts} +118 -2
- package/src/standard-modules.ts +16 -20
- package/src/state-graph.ts +9 -8
- package/src/substitution-levels.ts +2 -2
- package/src/successors.ts +16 -19
- package/src/symmetry.ts +1 -1
- package/src/tableau.ts +6 -7
- package/src/tlc/fingerprint.ts +214 -0
- package/src/{tlc-messages.ts → tlc/messages.ts} +119 -7
- package/src/{tlc-order.ts → tlc/order.ts} +7 -7
- package/src/{tlc-random.ts → tlc/random.ts} +3 -213
- package/src/{tlc-replay.ts → tlc/replay.ts} +40 -36
- package/src/{tlc-module.ts → tlc/tlc-operators.ts} +9 -9
- package/src/{tlc-ext.ts → tlc/tlcext-operators.ts} +30 -25
- package/src/transfer.ts +32 -32
- package/src/values.ts +72 -67
- package/src/worker.ts +1 -4
- package/dist/run-cli.cjs +0 -45
- package/dist/run-cli.js +0 -45
- package/src/canonical.ts +0 -40
- package/src/obligations/ctx.ts +0 -64
- package/src/prove/prep/defs.ts +0 -33
- package/src/prove/prep/elab.ts +0 -156
- package/src/prove/prep/enabled.ts +0 -43
- package/src/prove/prep/flatten.ts +0 -70
- package/src/prove/prep/trivial.ts +0 -22
- package/src/prove/smt/axiomatize.ts +0 -69
- package/src/prove/smt/simplify.ts +0 -57
- package/src/run-cli.ts +0 -1806
- package/src/standard-ranges.ts +0 -116
- package/src/value-sources.ts +0 -29
- /package/src/prove/prep/{pragma.ts → methods.ts} +0 -0
- /package/src/{tlc-modules.ts → tlc/jar-data.ts} +0 -0
- /package/src/{tlc-summary.ts → tlc/summary.ts} +0 -0
- /package/src/{tlc-version.ts → tlc/version.ts} +0 -0
package/src/parallel.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import type { Expression } from "./ast";
|
|
2
|
-
import { createCanonicalizer } from "./canonical";
|
|
3
2
|
import {
|
|
4
3
|
checkSequentially,
|
|
5
|
-
createSearch,
|
|
6
|
-
findAssumptionViolation,
|
|
7
|
-
reportInitialStatesProgress,
|
|
8
|
-
reportStartup,
|
|
9
4
|
type CheckOptions,
|
|
10
5
|
type CheckProgress,
|
|
11
6
|
type CheckResult,
|
|
@@ -23,12 +18,24 @@ import {
|
|
|
23
18
|
writeStateFingerprint,
|
|
24
19
|
type SharedFingerprints,
|
|
25
20
|
} from "./fingerprints";
|
|
21
|
+
import {
|
|
22
|
+
createSearch,
|
|
23
|
+
findAssumptionViolation,
|
|
24
|
+
reportInitialStatesProgress,
|
|
25
|
+
reportStartup,
|
|
26
|
+
} from "./search";
|
|
26
27
|
import { getInitialStates } from "./successors";
|
|
27
|
-
import { getTlcStringOrder, getTlcVariableOrder } from "./tlc
|
|
28
|
-
import { getFingerprintDistance, OUT_DEGREE_BUCKETS } from "./tlc
|
|
28
|
+
import { getTlcStringOrder, getTlcVariableOrder } from "./tlc/order";
|
|
29
|
+
import { getFingerprintDistance, OUT_DEGREE_BUCKETS } from "./tlc/summary";
|
|
29
30
|
import { createStateEncoder, type EncodedStates } from "./transfer";
|
|
30
|
-
import type { TlcVersion } from "./tlc
|
|
31
|
-
import {
|
|
31
|
+
import type { TlcVersion } from "./tlc/version";
|
|
32
|
+
import {
|
|
33
|
+
createCanonicalizer,
|
|
34
|
+
getRankedStringCount,
|
|
35
|
+
setStringOrder,
|
|
36
|
+
setValueVersion,
|
|
37
|
+
type Value,
|
|
38
|
+
} from "./values";
|
|
32
39
|
import { spawnWorker, type Port } from "./worker";
|
|
33
40
|
|
|
34
41
|
export interface StartMessage {
|
|
@@ -51,7 +58,6 @@ export interface StartMessage {
|
|
|
51
58
|
|
|
52
59
|
export interface LevelMessage {
|
|
53
60
|
type: "level";
|
|
54
|
-
level: number;
|
|
55
61
|
generated: number;
|
|
56
62
|
added: number;
|
|
57
63
|
outDegrees: number[];
|
|
@@ -65,7 +71,7 @@ export type WorkerMessage =
|
|
|
65
71
|
| LevelMessage;
|
|
66
72
|
|
|
67
73
|
export type CoordinatorMessage =
|
|
68
|
-
| { type: "level"
|
|
74
|
+
| { type: "level" }
|
|
69
75
|
| { type: "resize"; fingerprints: SharedFingerprints };
|
|
70
76
|
|
|
71
77
|
export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
@@ -101,11 +107,11 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
101
107
|
},
|
|
102
108
|
});
|
|
103
109
|
};
|
|
104
|
-
const
|
|
110
|
+
const workerCount = options.workers ?? 1;
|
|
105
111
|
// TLC's workers write the -dump state graph in whichever order they find it, so one worker
|
|
106
112
|
// writes the graph a single TLC worker does.
|
|
107
113
|
const isSequential =
|
|
108
|
-
|
|
114
|
+
workerCount < 2 ||
|
|
109
115
|
typeof SharedArrayBuffer !== "function" ||
|
|
110
116
|
options.dump !== undefined ||
|
|
111
117
|
config.view !== undefined ||
|
|
@@ -164,7 +170,7 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
164
170
|
const canonicalize = createCanonicalizer();
|
|
165
171
|
const shared = { fingerprints: createSharedFingerprints() };
|
|
166
172
|
const fingerprint = new Int32Array(2);
|
|
167
|
-
const seeds = Array.from({ length:
|
|
173
|
+
const seeds = Array.from({ length: workerCount }, createStateEncoder);
|
|
168
174
|
const statistics = {
|
|
169
175
|
generatedStates: 0,
|
|
170
176
|
distinctStates: 0,
|
|
@@ -207,7 +213,7 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
207
213
|
return false;
|
|
208
214
|
}
|
|
209
215
|
if (!search.satisfiesConstraints(state)) continue;
|
|
210
|
-
if (!seeds[seeded.length %
|
|
216
|
+
if (!seeds[seeded.length % workerCount].encode(state)) return false;
|
|
211
217
|
seeded.push(state);
|
|
212
218
|
statistics.distinctStates++;
|
|
213
219
|
}
|
|
@@ -234,7 +240,7 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
234
240
|
if (statistics.distinctStates === 0) return createSuccess();
|
|
235
241
|
|
|
236
242
|
const reports: WorkerMessage[] = [];
|
|
237
|
-
const pending = { count, resolve: (_reports: WorkerMessage[]) => {} };
|
|
243
|
+
const pending = { count: workerCount, resolve: (_reports: WorkerMessage[]) => {} };
|
|
238
244
|
const onMessage = (message: WorkerMessage) => {
|
|
239
245
|
reports.push(message);
|
|
240
246
|
if (message.type === "abort" || reports.length === pending.count) {
|
|
@@ -246,11 +252,11 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
246
252
|
pending.count = expected;
|
|
247
253
|
pending.resolve = resolve;
|
|
248
254
|
});
|
|
249
|
-
const ready = waitForReports(
|
|
250
|
-
const requests = new Int32Array(new SharedArrayBuffer(
|
|
251
|
-
const remaining = new Int32Array(new SharedArrayBuffer(
|
|
255
|
+
const ready = waitForReports(workerCount);
|
|
256
|
+
const requests = new Int32Array(new SharedArrayBuffer(workerCount * 4));
|
|
257
|
+
const remaining = new Int32Array(new SharedArrayBuffer(workerCount * 4));
|
|
252
258
|
const workers = await Promise.all(
|
|
253
|
-
Array.from({ length:
|
|
259
|
+
Array.from({ length: workerCount }, () =>
|
|
254
260
|
spawnWorker(
|
|
255
261
|
new URL("./parallel-worker.js", import.meta.url),
|
|
256
262
|
(message) => onMessage(message as WorkerMessage),
|
|
@@ -267,7 +273,7 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
267
273
|
return (from < to ? channel.port1 : channel.port2) as unknown as Port;
|
|
268
274
|
};
|
|
269
275
|
workers.forEach((worker, index) => {
|
|
270
|
-
const ports = Array.from({ length:
|
|
276
|
+
const ports = Array.from({ length: workerCount }, (_, peer) =>
|
|
271
277
|
peer === index ? undefined : getPort(index, peer),
|
|
272
278
|
);
|
|
273
279
|
const seed = seeds[index].finish();
|
|
@@ -308,11 +314,11 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
308
314
|
terminate();
|
|
309
315
|
return fallBack();
|
|
310
316
|
}
|
|
311
|
-
for (
|
|
312
|
-
const reported = waitForReports(
|
|
317
|
+
for (;;) {
|
|
318
|
+
const reported = waitForReports(workerCount);
|
|
313
319
|
// Every worker is idle, so peers can ask any of them for states once the level starts.
|
|
314
320
|
requests.forEach((_, index) => Atomics.store(requests, index, 0));
|
|
315
|
-
send({ type: "level"
|
|
321
|
+
send({ type: "level" });
|
|
316
322
|
const messages = await collectLevels(await reported);
|
|
317
323
|
if (isAborted(messages)) {
|
|
318
324
|
terminate();
|
package/src/parser.ts
CHANGED
|
@@ -24,7 +24,7 @@ import type {
|
|
|
24
24
|
} from "./ast";
|
|
25
25
|
import { createSanyError, formatRange, TlaSyntaxError } from "./errors";
|
|
26
26
|
import { getNumeralValue, readAtAsIdentifier, tokenize, type Token } from "./lexer";
|
|
27
|
-
import { getSanyParseError } from "./sany
|
|
27
|
+
import { getSanyParseError } from "./sany/parse-error";
|
|
28
28
|
|
|
29
29
|
interface Precedence {
|
|
30
30
|
low: number;
|
|
@@ -197,39 +197,6 @@ const OPERATOR_ARGUMENTS = new Set([
|
|
|
197
197
|
...POSTFIX_OPERATORS,
|
|
198
198
|
]);
|
|
199
199
|
|
|
200
|
-
// A SANY InfixExpr or PostfixExpr.
|
|
201
|
-
const isOperatorExpression = (expression: Expression) =>
|
|
202
|
-
expression.kind === "Prime" ||
|
|
203
|
-
expression.kind === "Product" ||
|
|
204
|
-
((expression.kind === "And" || expression.kind === "Or") && !expression.isBulleted) ||
|
|
205
|
-
(expression.kind === "Apply" &&
|
|
206
|
-
(expression.args.length === 2
|
|
207
|
-
? INFIX_OPERATORS.has(expression.operator)
|
|
208
|
-
: POSTFIX_OPERATORS.has(expression.operator)));
|
|
209
|
-
|
|
210
|
-
const isOperatorName = (text: string) =>
|
|
211
|
-
INFIX_OPERATORS.has(text) || POSTFIX_OPERATORS.has(text) || text === "-.";
|
|
212
|
-
|
|
213
|
-
const getOperatorApplication = (
|
|
214
|
-
operator: string,
|
|
215
|
-
argument: Expression,
|
|
216
|
-
location: SourceLocation,
|
|
217
|
-
): Expression => {
|
|
218
|
-
switch (operator) {
|
|
219
|
-
case "ENABLED":
|
|
220
|
-
return { kind: "Enabled", expression: argument, location };
|
|
221
|
-
case "UNCHANGED":
|
|
222
|
-
return { kind: "Unchanged", expression: argument, location };
|
|
223
|
-
case "[]":
|
|
224
|
-
return { kind: "Always", expression: argument, location };
|
|
225
|
-
case "<>":
|
|
226
|
-
return { kind: "Eventually", expression: argument, location };
|
|
227
|
-
case "'":
|
|
228
|
-
return { kind: "Prime", expression: argument, location };
|
|
229
|
-
default:
|
|
230
|
-
return { kind: "Apply", operator, args: [argument], location };
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
200
|
const SELECTOR_SYMBOLS = new Set(["<<", ">>", ":", "@", "("]);
|
|
234
201
|
|
|
235
202
|
const UNIT_KEYWORDS = new Set([
|
|
@@ -330,6 +297,40 @@ const BUILTIN_CONSTANTS = new Set(["TRUE", "FALSE", "BOOLEAN", "STRING"]);
|
|
|
330
297
|
|
|
331
298
|
const NO_OFFSIDE = -1;
|
|
332
299
|
|
|
300
|
+
// A SANY InfixExpr or PostfixExpr.
|
|
301
|
+
const isOperatorExpression = (expression: Expression) =>
|
|
302
|
+
expression.kind === "Prime" ||
|
|
303
|
+
expression.kind === "Product" ||
|
|
304
|
+
((expression.kind === "And" || expression.kind === "Or") && !expression.isBulleted) ||
|
|
305
|
+
(expression.kind === "Apply" &&
|
|
306
|
+
(expression.args.length === 2
|
|
307
|
+
? INFIX_OPERATORS.has(expression.operator)
|
|
308
|
+
: POSTFIX_OPERATORS.has(expression.operator)));
|
|
309
|
+
|
|
310
|
+
const isOperatorName = (text: string) =>
|
|
311
|
+
INFIX_OPERATORS.has(text) || POSTFIX_OPERATORS.has(text) || text === "-.";
|
|
312
|
+
|
|
313
|
+
const getOperatorApplication = (
|
|
314
|
+
operator: string,
|
|
315
|
+
argument: Expression,
|
|
316
|
+
location: SourceLocation,
|
|
317
|
+
): Expression => {
|
|
318
|
+
switch (operator) {
|
|
319
|
+
case "ENABLED":
|
|
320
|
+
return { kind: "Enabled", expression: argument, location };
|
|
321
|
+
case "UNCHANGED":
|
|
322
|
+
return { kind: "Unchanged", expression: argument, location };
|
|
323
|
+
case "[]":
|
|
324
|
+
return { kind: "Always", expression: argument, location };
|
|
325
|
+
case "<>":
|
|
326
|
+
return { kind: "Eventually", expression: argument, location };
|
|
327
|
+
case "'":
|
|
328
|
+
return { kind: "Prime", expression: argument, location };
|
|
329
|
+
default:
|
|
330
|
+
return { kind: "Apply", operator, args: [argument], location };
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
|
|
333
334
|
// MonolithSpecExtractor.module: a module that no file defines can follow the root module in the
|
|
334
335
|
// root module's file, from its ---- MODULE line to the next ==== line.
|
|
335
336
|
export const extractModule = (source: string, name: string) => {
|
|
@@ -403,7 +404,7 @@ const parse = (source: string, mode: ParseMode): Module => {
|
|
|
403
404
|
return token.column <= offsideColumn ? { ...token, kind: "End" as const, text: "" } : token;
|
|
404
405
|
};
|
|
405
406
|
|
|
406
|
-
const
|
|
407
|
+
const describeToken = (token: Token) =>
|
|
407
408
|
token.kind === "End" ? "end of input" : JSON.stringify(token.text);
|
|
408
409
|
|
|
409
410
|
const unitStart = { index: 0 };
|
|
@@ -503,14 +504,14 @@ const parse = (source: string, mode: ParseMode): Module => {
|
|
|
503
504
|
|
|
504
505
|
const expect = (text: string) => {
|
|
505
506
|
if (!isAt(text))
|
|
506
|
-
throw createUnexpected(`Expected ${JSON.stringify(text)} but found ${
|
|
507
|
+
throw createUnexpected(`Expected ${JSON.stringify(text)} but found ${describeToken(peek())}`);
|
|
507
508
|
return advance();
|
|
508
509
|
};
|
|
509
510
|
|
|
510
511
|
const expectIdentifier = () => {
|
|
511
512
|
const token = peek();
|
|
512
513
|
if (token.kind !== "Identifier") {
|
|
513
|
-
throw createUnexpected(`Expected an identifier but found ${
|
|
514
|
+
throw createUnexpected(`Expected an identifier but found ${describeToken(token)}`);
|
|
514
515
|
}
|
|
515
516
|
if (isTlapmKeyword(token)) throw createUnexpected(`Unexpected keyword ${token.text}`);
|
|
516
517
|
cursor.index++;
|
|
@@ -626,7 +627,7 @@ const parse = (source: string, mode: ParseMode): Module => {
|
|
|
626
627
|
);
|
|
627
628
|
}
|
|
628
629
|
if (isAt("<<") || isAt("(")) return parsePrimary();
|
|
629
|
-
throw createUnexpected(`Expected a subscript but found ${
|
|
630
|
+
throw createUnexpected(`Expected a subscript but found ${describeToken(token)}`);
|
|
630
631
|
};
|
|
631
632
|
|
|
632
633
|
const isDefinitionAhead = (operator: Token) => {
|
|
@@ -808,7 +809,7 @@ const parse = (source: string, mode: ParseMode): Module => {
|
|
|
808
809
|
while (isAt(".") || isAt("[")) {
|
|
809
810
|
if (accept(".")) {
|
|
810
811
|
if (!isFieldName(peek()))
|
|
811
|
-
throw createUnexpected(`Expected a field name but found ${
|
|
812
|
+
throw createUnexpected(`Expected a field name but found ${describeToken(peek())}`);
|
|
812
813
|
path.push({ kind: "Field", name: advance().text });
|
|
813
814
|
continue;
|
|
814
815
|
}
|
|
@@ -1037,26 +1038,16 @@ const parse = (source: string, mode: ParseMode): Module => {
|
|
|
1037
1038
|
? { kind: "Subexpression", selectors, selectorRanges, argumentRanges, location }
|
|
1038
1039
|
: qualifiedArgs.length === 0
|
|
1039
1040
|
? { kind: "Identifier", name: operator, selectorRanges, location }
|
|
1040
|
-
:
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
}
|
|
1051
|
-
: {
|
|
1052
|
-
kind: "Apply",
|
|
1053
|
-
operator,
|
|
1054
|
-
args: qualifiedArgs,
|
|
1055
|
-
argumentsRange,
|
|
1056
|
-
selectorRanges,
|
|
1057
|
-
argumentRanges,
|
|
1058
|
-
location,
|
|
1059
|
-
};
|
|
1041
|
+
: {
|
|
1042
|
+
kind: "Apply",
|
|
1043
|
+
operator,
|
|
1044
|
+
args: qualifiedArgs,
|
|
1045
|
+
...(argumentCounts.slice(0, -1).some((count) => count > 0) && { argumentCounts }),
|
|
1046
|
+
argumentsRange,
|
|
1047
|
+
selectorRanges,
|
|
1048
|
+
argumentRanges,
|
|
1049
|
+
location,
|
|
1050
|
+
};
|
|
1060
1051
|
}
|
|
1061
1052
|
// SANY reads an infix or postfix operator as a primary expression, with or without arguments.
|
|
1062
1053
|
if (token.kind === "Operator" && isOperatorName(token.text) && isAt("(")) {
|
|
@@ -1143,7 +1134,7 @@ const parse = (source: string, mode: ParseMode): Module => {
|
|
|
1143
1134
|
};
|
|
1144
1135
|
}
|
|
1145
1136
|
}
|
|
1146
|
-
throw createUnexpected(`Unexpected ${
|
|
1137
|
+
throw createUnexpected(`Unexpected ${describeToken(token)}`, token);
|
|
1147
1138
|
};
|
|
1148
1139
|
|
|
1149
1140
|
// SANY rejects the operator after a prefix operator's operand unless it binds looser than the
|
|
@@ -1636,7 +1627,7 @@ const parse = (source: string, mode: ParseMode): Module => {
|
|
|
1636
1627
|
const part = peek();
|
|
1637
1628
|
const isName = part.kind === "Identifier" && !isTlapmKeyword(part);
|
|
1638
1629
|
if (!isName && part.kind !== "Operator") {
|
|
1639
|
-
throw createUnexpected(`Expected a definition name but found ${
|
|
1630
|
+
throw createUnexpected(`Expected a definition name but found ${describeToken(part)}`, part);
|
|
1640
1631
|
}
|
|
1641
1632
|
cursor.index++;
|
|
1642
1633
|
return part.text;
|
|
@@ -1700,7 +1691,7 @@ const parse = (source: string, mode: ParseMode): Module => {
|
|
|
1700
1691
|
const isNew = accept("NEW");
|
|
1701
1692
|
const level = peek().kind === "Keyword" ? NEW_SYMBOL_LEVELS.get(peek().text) : undefined;
|
|
1702
1693
|
if (!isNew && level === undefined) {
|
|
1703
|
-
throw createUnexpected(`Expected a declaration but found ${
|
|
1694
|
+
throw createUnexpected(`Expected a declaration but found ${describeToken(peek())}`);
|
|
1704
1695
|
}
|
|
1705
1696
|
if (level !== undefined) advance();
|
|
1706
1697
|
if (level === "Variable") {
|
|
@@ -1823,7 +1814,7 @@ const parse = (source: string, mode: ParseMode): Module => {
|
|
|
1823
1814
|
const parseStepStart = (isQed: boolean) => {
|
|
1824
1815
|
const step = peek();
|
|
1825
1816
|
if (step.kind !== "Step") {
|
|
1826
|
-
throw createUnexpected(`Expected a step number but found ${
|
|
1817
|
+
throw createUnexpected(`Expected a step number but found ${describeToken(step)}`, step);
|
|
1827
1818
|
}
|
|
1828
1819
|
if (!isCorrectLevel(step)) {
|
|
1829
1820
|
throw createError(`${isQed ? "QED step" : "step"}'s number has bad level`, step);
|
|
@@ -1935,20 +1926,22 @@ const parse = (source: string, mode: ParseMode): Module => {
|
|
|
1935
1926
|
|
|
1936
1927
|
const parseAssumption = (): Assumption => {
|
|
1937
1928
|
const start = cursor.index;
|
|
1938
|
-
return withRange(parseAssumptionUnit(), start);
|
|
1939
|
-
};
|
|
1940
|
-
|
|
1941
|
-
const parseAssumptionUnit = (): Assumption => {
|
|
1942
1929
|
const keyword = advance();
|
|
1943
|
-
const
|
|
1944
|
-
const
|
|
1945
|
-
if (
|
|
1946
|
-
const name = expectIdentifier();
|
|
1930
|
+
const isNamed = peek().kind === "Identifier" && isAt("==", 1);
|
|
1931
|
+
const name = isNamed ? expectIdentifier() : undefined;
|
|
1932
|
+
if (name !== undefined) {
|
|
1947
1933
|
factNames.add(name);
|
|
1948
1934
|
advance();
|
|
1949
|
-
return { name, expression: parseExpression(), isAxiom, location };
|
|
1950
1935
|
}
|
|
1951
|
-
return
|
|
1936
|
+
return withRange(
|
|
1937
|
+
{
|
|
1938
|
+
name,
|
|
1939
|
+
expression: parseExpression(),
|
|
1940
|
+
isAxiom: keyword.text === "AXIOM",
|
|
1941
|
+
location: getLocation(keyword),
|
|
1942
|
+
},
|
|
1943
|
+
start,
|
|
1944
|
+
);
|
|
1952
1945
|
};
|
|
1953
1946
|
|
|
1954
1947
|
const parseModuleBody = (): Module => {
|
|
@@ -2051,7 +2044,7 @@ const parse = (source: string, mode: ParseMode): Module => {
|
|
|
2051
2044
|
case "HIDE": {
|
|
2052
2045
|
// SANY's module body takes a USE only when ONLY doesn't follow it.
|
|
2053
2046
|
if (isAt("USE") && isAt("ONLY", 1)) {
|
|
2054
|
-
throw createUnexpected(`Expected a module unit but found ${
|
|
2047
|
+
throw createUnexpected(`Expected a module unit but found ${describeToken(token)}`);
|
|
2055
2048
|
}
|
|
2056
2049
|
const use = parseUseOrHide();
|
|
2057
2050
|
module.uses.push(use);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PcalBugError, PcalError, PcalRuntimeError } from "
|
|
2
|
-
import type { TlcVersion } from "
|
|
1
|
+
import { PcalBugError, PcalError, PcalRuntimeError } from "../errors";
|
|
2
|
+
import type { TlcVersion } from "../tlc/version";
|
|
3
3
|
|
|
4
4
|
// TLAToken's types.
|
|
5
5
|
export const PCAL_TOKEN = { builtin: 1, number: 2, string: 3, ident: 4, added: 5 } as const;
|
|
@@ -28,18 +28,11 @@ interface PcalCoord {
|
|
|
28
28
|
// resets, so options one module sets carry over to the modules SANY validates after it.
|
|
29
29
|
export interface PcalParams {
|
|
30
30
|
labelFlag: boolean;
|
|
31
|
-
reportLabelsFlag: boolean;
|
|
32
31
|
labelRoot: string;
|
|
33
32
|
fairnessOption: string;
|
|
34
|
-
fairAlgorithm: boolean;
|
|
35
33
|
checkTermination: boolean;
|
|
36
|
-
noOld: boolean;
|
|
37
|
-
nocfg: boolean;
|
|
38
|
-
noDoneDisjunct: boolean;
|
|
39
34
|
specOption: boolean;
|
|
40
35
|
myspecOption: boolean;
|
|
41
|
-
specFile: string;
|
|
42
|
-
optionsInFile: boolean;
|
|
43
36
|
inputVersionNumber: number;
|
|
44
37
|
}
|
|
45
38
|
|
|
@@ -48,18 +41,11 @@ export const PCAL_VERSION_WEIGHT = 1903;
|
|
|
48
41
|
|
|
49
42
|
export const createPcalParams = (): PcalParams => ({
|
|
50
43
|
labelFlag: false,
|
|
51
|
-
reportLabelsFlag: false,
|
|
52
44
|
labelRoot: "Lbl_",
|
|
53
45
|
fairnessOption: "",
|
|
54
|
-
fairAlgorithm: false,
|
|
55
46
|
checkTermination: false,
|
|
56
|
-
noOld: false,
|
|
57
|
-
nocfg: false,
|
|
58
|
-
noDoneDisjunct: false,
|
|
59
47
|
specOption: false,
|
|
60
48
|
myspecOption: false,
|
|
61
|
-
specFile: "",
|
|
62
|
-
optionsInFile: false,
|
|
63
49
|
inputVersionNumber: PCAL_VERSION_WEIGHT,
|
|
64
50
|
});
|
|
65
51
|
|
|
@@ -315,7 +301,6 @@ export type PcalNode =
|
|
|
315
301
|
| PcalClause
|
|
316
302
|
| PcalMacro;
|
|
317
303
|
|
|
318
|
-
// The fields every AST object starts with.
|
|
319
304
|
export const createPcalBase = (): PcalBase => ({
|
|
320
305
|
col: 0,
|
|
321
306
|
line: 0,
|