tla-ts 0.0.3-dev.4c8c06c → 0.0.3-dev.4cf9a33
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 +47 -22
- package/dist/index.d.ts +47 -22
- 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 +19 -16
- package/dist/run-cli.js +20 -17
- package/dist/transfer.cjs +36 -15
- package/dist/transfer.js +36 -15
- package/package.json +1 -1
- package/src/ast.ts +93 -0
- package/src/check.ts +438 -98
- 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 +116 -28
- package/src/errors.ts +65 -3
- package/src/evaluate.ts +163 -156
- package/src/exit-codes.ts +39 -42
- package/src/instances.ts +16 -15
- package/src/levels.ts +62 -34
- package/src/live-check.ts +772 -0
- package/src/liveness.ts +120 -543
- package/src/parallel-worker.ts +7 -3
- package/src/parallel.ts +20 -4
- package/src/parser.ts +33 -11
- package/src/resolve.ts +122 -44
- package/src/run-cli.ts +91 -19
- package/src/runtime.ts +3 -1
- package/src/spec-description.ts +19 -8
- package/src/standard-modules.ts +2 -7
- package/src/state-graph.ts +157 -0
- package/src/subexpressions.ts +10 -10
- package/src/successors.ts +145 -27
- package/src/symmetry.ts +16 -6
- 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/values.ts +121 -20
package/src/levels.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import {
|
|
2
|
+
getChildren,
|
|
3
|
+
type AssumeProve,
|
|
4
|
+
type Definition,
|
|
5
|
+
type Expression,
|
|
6
|
+
type Module,
|
|
7
|
+
type OperatorParam,
|
|
8
8
|
} from "./ast";
|
|
9
|
-
import { TlaSyntaxError } from "./errors";
|
|
10
|
-
import { getChildren } from "./evaluate";
|
|
9
|
+
import { createSemanticError, TlaSyntaxError } from "./errors";
|
|
11
10
|
import { mapChildren } from "./instances";
|
|
12
|
-
import { getBoundNames, getPatternNames } from "./resolve";
|
|
11
|
+
import { collectSemanticErrors, getBoundNames, getPatternNames } from "./resolve";
|
|
13
12
|
import { STANDARD_LEVELS } from "./standard-levels";
|
|
14
13
|
|
|
15
14
|
interface LevelData {
|
|
@@ -176,8 +175,13 @@ export const ACTION_LEVEL = 2;
|
|
|
176
175
|
|
|
177
176
|
export const TEMPORAL_LEVEL = 3;
|
|
178
177
|
|
|
179
|
-
|
|
180
|
-
|
|
178
|
+
// SANY reports a level error at the range of the expression it rejects.
|
|
179
|
+
const createLevelError = (message: string, expression: Expression) =>
|
|
180
|
+
expression.location.range
|
|
181
|
+
? createSemanticError(`${message}.`, expression.location.range)
|
|
182
|
+
: new TlaSyntaxError(
|
|
183
|
+
`${message} at line ${expression.location.line}, column ${expression.location.column}`,
|
|
184
|
+
);
|
|
181
185
|
|
|
182
186
|
const LOGICAL_OPERATORS = new Set(["/\\", "\\/", "=>", "<=>"]);
|
|
183
187
|
|
|
@@ -237,13 +241,13 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
237
241
|
if (operand.operator || operand.declared) return;
|
|
238
242
|
if (operand.data.level > getMaxLevel(operator, index)) {
|
|
239
243
|
throw new TlaSyntaxError(
|
|
240
|
-
`Level error in applying operator ${operator.name}
|
|
244
|
+
`Level error in applying operator ${operator.name}:\nThe level of argument ${index + 1} exceeds the maximum level allowed by the operator`,
|
|
241
245
|
);
|
|
242
246
|
}
|
|
243
247
|
});
|
|
244
248
|
if (ranges.some((range) => range.level > ACTION_LEVEL)) {
|
|
245
249
|
throw new TlaSyntaxError(
|
|
246
|
-
`Level error in applying operator ${operator.name}
|
|
250
|
+
`Level error in applying operator ${operator.name}:\nThe level of the range for a bounded variable exceeds the maximum level allowed by the operator`,
|
|
247
251
|
);
|
|
248
252
|
}
|
|
249
253
|
const getOperand = (formal: string) => {
|
|
@@ -444,10 +448,13 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
444
448
|
? applyDeclared(resolved.name, resolved.level, operands)
|
|
445
449
|
: applyDefined(resolved.levels, operands);
|
|
446
450
|
|
|
447
|
-
const checkJunction = (operands: Operand[],
|
|
451
|
+
const checkJunction = (operands: Operand[], expression: Expression) => {
|
|
448
452
|
const levels = operands.map((operand) => operand.data.level);
|
|
449
453
|
if (levels.includes(ACTION_LEVEL) && levels.includes(TEMPORAL_LEVEL)) {
|
|
450
|
-
throw createLevelError(
|
|
454
|
+
throw createLevelError(
|
|
455
|
+
"Formula has both temporal formula and action as arguments",
|
|
456
|
+
expression,
|
|
457
|
+
);
|
|
451
458
|
}
|
|
452
459
|
};
|
|
453
460
|
|
|
@@ -456,10 +463,10 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
456
463
|
if (isLeadsTo && operands.some((operand) => operand.data.level === ACTION_LEVEL)) {
|
|
457
464
|
throw createLevelError(
|
|
458
465
|
"Action used where only temporal formula or state predicate allowed",
|
|
459
|
-
expression
|
|
466
|
+
expression,
|
|
460
467
|
);
|
|
461
468
|
}
|
|
462
|
-
if (LOGICAL_OPERATORS.has(expression.operator)) checkJunction(operands, expression
|
|
469
|
+
if (LOGICAL_OPERATORS.has(expression.operator)) checkJunction(operands, expression);
|
|
463
470
|
};
|
|
464
471
|
|
|
465
472
|
const checkTemporal = (
|
|
@@ -473,7 +480,7 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
473
480
|
expression.kind === "Always"
|
|
474
481
|
? "[] followed by action not of form [A]_v"
|
|
475
482
|
: "<> followed by action not of form <<A>>_v",
|
|
476
|
-
expression
|
|
483
|
+
expression,
|
|
477
484
|
);
|
|
478
485
|
};
|
|
479
486
|
|
|
@@ -501,7 +508,17 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
501
508
|
return data;
|
|
502
509
|
};
|
|
503
510
|
|
|
511
|
+
// SANY reports a level error of an operator's arguments at the application.
|
|
504
512
|
const analyze = (expression: Expression, scope: Scope): LevelData => {
|
|
513
|
+
try {
|
|
514
|
+
return analyzeNode(expression, scope);
|
|
515
|
+
} catch (error) {
|
|
516
|
+
if (!(error instanceof TlaSyntaxError) || error.sany) throw error;
|
|
517
|
+
throw createLevelError(error.message, expression);
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
const analyzeNode = (expression: Expression, scope: Scope): LevelData => {
|
|
505
522
|
switch (expression.kind) {
|
|
506
523
|
case "Number":
|
|
507
524
|
case "Decimal":
|
|
@@ -521,7 +538,7 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
521
538
|
case "And":
|
|
522
539
|
case "Or": {
|
|
523
540
|
const operands = toOperands(expression.operands, scope);
|
|
524
|
-
checkJunction(operands, expression
|
|
541
|
+
checkJunction(operands, expression);
|
|
525
542
|
return applyDefined(JUNCTION_LEVELS, operands);
|
|
526
543
|
}
|
|
527
544
|
case "Prime":
|
|
@@ -561,13 +578,14 @@ export const createLevelAnalyzer = (context: LevelContext) => {
|
|
|
561
578
|
expression.bounds.map((bound) => bound.set),
|
|
562
579
|
getBoundNames(expression.bounds),
|
|
563
580
|
);
|
|
564
|
-
|
|
565
|
-
data.level === TEMPORAL_LEVEL
|
|
566
|
-
|
|
567
|
-
|
|
581
|
+
const actionBound =
|
|
582
|
+
data.level === TEMPORAL_LEVEL
|
|
583
|
+
? expression.bounds.find((bound) => analyze(bound.set, scope).level === ACTION_LEVEL)
|
|
584
|
+
: undefined;
|
|
585
|
+
if (actionBound) {
|
|
568
586
|
throw createLevelError(
|
|
569
587
|
"Action-level bound of quantified temporal formula",
|
|
570
|
-
|
|
588
|
+
actionBound.set,
|
|
571
589
|
);
|
|
572
590
|
}
|
|
573
591
|
return data;
|
|
@@ -838,13 +856,23 @@ const analyzeAssumeProve = (
|
|
|
838
856
|
// SANY checks the level of every definition, assumption, and theorem of a module.
|
|
839
857
|
export const checkModuleLevels = (module: Module, context: LevelContext) => {
|
|
840
858
|
const analyzer = createLevelAnalyzer(context);
|
|
841
|
-
|
|
842
|
-
.
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
859
|
+
collectSemanticErrors([
|
|
860
|
+
...module.definitions
|
|
861
|
+
.filter((definition) => !definition.name.includes("!"))
|
|
862
|
+
.map((definition) => ({
|
|
863
|
+
location: definition.location,
|
|
864
|
+
check: () => analyzer.analyzeDefinition(definition, new Map()),
|
|
865
|
+
})),
|
|
866
|
+
...module.assumptions.map((assumption) => ({
|
|
867
|
+
location: assumption.location,
|
|
868
|
+
check: () => analyzer.analyze(assumption.expression, new Map()),
|
|
869
|
+
})),
|
|
870
|
+
...module.theorems.map((theorem) => ({
|
|
871
|
+
location: theorem.location,
|
|
872
|
+
check: () =>
|
|
873
|
+
theorem.statement.kind === "AssumeProve"
|
|
874
|
+
? analyzeAssumeProve(theorem.statement, new Map(), analyzer)
|
|
875
|
+
: analyzer.analyze(theorem.statement, new Map()),
|
|
876
|
+
})),
|
|
877
|
+
]);
|
|
850
878
|
};
|