tla-ts 0.0.3-dev.b74f28c → 0.0.3-dev.bffbba3
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 +9 -0
- package/dist/index.d.ts +9 -0
- 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 +17 -16
- package/dist/run-cli.js +6 -5
- package/dist/transfer.cjs +27 -15
- package/dist/transfer.js +27 -15
- package/package.json +1 -1
- package/src/ast.ts +90 -0
- package/src/check.ts +233 -68
- package/src/cli-options.ts +11 -5
- package/src/codegen.ts +9 -19
- package/src/dependencies.ts +2 -2
- package/src/environment.ts +75 -16
- package/src/errors.ts +9 -2
- package/src/evaluate.ts +85 -142
- package/src/exit-codes.ts +21 -43
- package/src/instances.ts +15 -14
- package/src/levels.ts +8 -8
- package/src/lexer.ts +5 -1
- package/src/live-check.ts +692 -0
- package/src/liveness.ts +54 -535
- package/src/parallel-worker.ts +5 -1
- package/src/parallel.ts +18 -2
- package/src/parser.ts +12 -1
- package/src/resolve.ts +16 -15
- package/src/run-cli.ts +58 -13
- package/src/runtime.ts +3 -1
- package/src/spec-description.ts +18 -6
- package/src/standard-modules.ts +2 -7
- package/src/state-graph.ts +157 -0
- package/src/subexpressions.ts +10 -10
- package/src/successors.ts +77 -13
- package/src/tableau.ts +50 -23
- package/src/tlc-ext.ts +29 -12
- package/src/tlc-module.ts +9 -28
- package/src/tlc-order.ts +17 -3
- package/src/values.ts +59 -11
package/src/exit-codes.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { LivenessChecker } from "./
|
|
1
|
+
import type { LivenessChecker } from "./live-check";
|
|
2
2
|
|
|
3
3
|
// TLC's exit statuses, from EC.ExitStatus.
|
|
4
4
|
export const EXIT_STATUS = {
|
|
@@ -17,12 +17,6 @@ export const EXIT_STATUS = {
|
|
|
17
17
|
} as const;
|
|
18
18
|
|
|
19
19
|
const exitCodes = new WeakMap<Error, number>();
|
|
20
|
-
const moduleExitCodes = new WeakMap<Error, number>();
|
|
21
|
-
const phase = { isNextState: false };
|
|
22
|
-
|
|
23
|
-
export const setNextStatePhase = (isNextState: boolean) => {
|
|
24
|
-
phase.isNextState = isNextState;
|
|
25
|
-
};
|
|
26
20
|
|
|
27
21
|
// The innermost site that knows TLC's exit status for an error sets it first and wins.
|
|
28
22
|
export const setExitCode = <Thrown>(error: Thrown, code: number) => {
|
|
@@ -30,46 +24,30 @@ export const setExitCode = <Thrown>(error: Thrown, code: number) => {
|
|
|
30
24
|
return error;
|
|
31
25
|
};
|
|
32
26
|
|
|
33
|
-
|
|
34
|
-
// escapes the computation of next states. In every other phase, the phase decides the code.
|
|
35
|
-
export const setModuleExitCode = (error: Error, code: number) => {
|
|
36
|
-
if (phase.isNextState) moduleExitCodes.set(error, code);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const getExitCode = (error: Error) => exitCodes.get(error) ?? moduleExitCodes.get(error);
|
|
27
|
+
export const getExitCode = (error: Error) => exitCodes.get(error);
|
|
40
28
|
|
|
41
29
|
// TLC exits with 255 when it fails to process or evaluate a liveness property, in any phase.
|
|
42
|
-
|
|
43
|
-
create: () => LivenessChecker | undefined,
|
|
44
|
-
): LivenessChecker | undefined => {
|
|
30
|
+
const withErrorExitCode = <Result>(run: () => Result) => {
|
|
45
31
|
try {
|
|
46
|
-
|
|
47
|
-
return (
|
|
48
|
-
checker && {
|
|
49
|
-
addInitialState: (index, state) => {
|
|
50
|
-
try {
|
|
51
|
-
checker.addInitialState(index, state);
|
|
52
|
-
} catch (error) {
|
|
53
|
-
throw setExitCode(error, EXIT_STATUS.error);
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
addState: (index, state, successors) => {
|
|
57
|
-
try {
|
|
58
|
-
return checker.addState(index, state, successors);
|
|
59
|
-
} catch (error) {
|
|
60
|
-
throw setExitCode(error, EXIT_STATUS.error);
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
findViolation: () => {
|
|
64
|
-
try {
|
|
65
|
-
return checker.findViolation();
|
|
66
|
-
} catch (error) {
|
|
67
|
-
throw setExitCode(error, EXIT_STATUS.error);
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
}
|
|
71
|
-
);
|
|
32
|
+
return run();
|
|
72
33
|
} catch (error) {
|
|
73
34
|
throw setExitCode(error, EXIT_STATUS.error);
|
|
74
35
|
}
|
|
75
36
|
};
|
|
37
|
+
|
|
38
|
+
export const withLivenessExitCode = (
|
|
39
|
+
create: () => LivenessChecker | undefined,
|
|
40
|
+
): LivenessChecker | undefined => {
|
|
41
|
+
const checker = withErrorExitCode(create);
|
|
42
|
+
return (
|
|
43
|
+
checker && {
|
|
44
|
+
addInitialState: (index, state) =>
|
|
45
|
+
withErrorExitCode(() => checker.addInitialState(index, state)),
|
|
46
|
+
addState: (index, state, successors) =>
|
|
47
|
+
withErrorExitCode(() => checker.addState(index, state, successors)),
|
|
48
|
+
findViolation: () => withErrorExitCode(() => checker.findViolation()),
|
|
49
|
+
getViolatedProperties: (path, cycleStart) =>
|
|
50
|
+
withErrorExitCode(() => checker.getViolatedProperties(path, cycleStart)),
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
};
|
package/src/instances.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import {
|
|
2
|
+
getChildren,
|
|
3
|
+
isLocallyResolved,
|
|
4
|
+
type Bound,
|
|
5
|
+
type BoundPattern,
|
|
6
|
+
type Definition,
|
|
7
|
+
type Expression,
|
|
8
|
+
type Instance,
|
|
9
|
+
type Module,
|
|
10
|
+
type OperatorParam,
|
|
11
|
+
type SourceLocation,
|
|
12
|
+
type Theorem,
|
|
11
13
|
} from "./ast";
|
|
12
14
|
import { TlaSyntaxError } from "./errors";
|
|
13
|
-
import { getChildren, isLocallyResolved } from "./evaluate";
|
|
14
15
|
import { getArity, getBoundNames, getPatternNames, isBefore } from "./resolve";
|
|
15
16
|
|
|
16
17
|
export const substitutedExpressions = new WeakSet<Expression>();
|
|
@@ -218,7 +219,7 @@ interface Instantiation {
|
|
|
218
219
|
variables: Set<string>;
|
|
219
220
|
getDefinition: (key: string) => Definition | undefined;
|
|
220
221
|
isParameterized: (key: string) => boolean;
|
|
221
|
-
addDefinition: (name: string, create: (key: string) => Definition) => string;
|
|
222
|
+
addDefinition: (source: string, name: string, create: (key: string) => Definition) => string;
|
|
222
223
|
createName: (name: string) => string;
|
|
223
224
|
}
|
|
224
225
|
|
|
@@ -639,7 +640,7 @@ const copyDefinition = (rewrite: Rewrite, key: string): string => {
|
|
|
639
640
|
const instantiation = rewrite.instantiation;
|
|
640
641
|
const definition = instantiation.getDefinition(key);
|
|
641
642
|
if (!definition) return key;
|
|
642
|
-
return instantiation.addDefinition(definition.name, (copyKey) => {
|
|
643
|
+
return instantiation.addDefinition(key, definition.name, (copyKey) => {
|
|
643
644
|
rewrite.copies.set(key, copyKey);
|
|
644
645
|
const rename = createRenamer(rewrite);
|
|
645
646
|
const mapped = renameParams(
|
|
@@ -678,7 +679,7 @@ export const createInstantiation = (instantiation: Instantiation) => {
|
|
|
678
679
|
if (copy !== undefined) return copy;
|
|
679
680
|
const definition = instantiation.getDefinition(key);
|
|
680
681
|
if (!definition) return key;
|
|
681
|
-
return instantiation.addDefinition(definition.name, () =>
|
|
682
|
+
return instantiation.addDefinition(key, definition.name, () =>
|
|
682
683
|
withInstanceParams(definition, instantiation.params, definition.location),
|
|
683
684
|
);
|
|
684
685
|
},
|
package/src/levels.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
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
|
+
type SourceLocation,
|
|
8
9
|
} from "./ast";
|
|
9
10
|
import { TlaSyntaxError } from "./errors";
|
|
10
|
-
import { getChildren } from "./evaluate";
|
|
11
11
|
import { mapChildren } from "./instances";
|
|
12
12
|
import { getBoundNames, getPatternNames } from "./resolve";
|
|
13
13
|
import { STANDARD_LEVELS } from "./standard-levels";
|
package/src/lexer.ts
CHANGED
|
@@ -345,6 +345,8 @@ export const tokenize = (source: string): Token[] => {
|
|
|
345
345
|
if (!headerMatch)
|
|
346
346
|
throw new TlaSyntaxError("Expected a module header such as ---- MODULE Name ----");
|
|
347
347
|
const tokens: Token[] = [];
|
|
348
|
+
// Each name is one string object, so looking a name up in a scope compares pointers.
|
|
349
|
+
const names = new Map<string, string>();
|
|
348
350
|
const prefixLines = source.slice(0, headerMatch.index).split("\n");
|
|
349
351
|
const cursor = {
|
|
350
352
|
index: headerMatch.index,
|
|
@@ -481,7 +483,9 @@ export const tokenize = (source: string): Token[] => {
|
|
|
481
483
|
pushToken("Keyword", word.slice(0, 3), 3);
|
|
482
484
|
continue;
|
|
483
485
|
}
|
|
484
|
-
|
|
486
|
+
const name = names.get(word) ?? word;
|
|
487
|
+
names.set(name, name);
|
|
488
|
+
pushToken(KEYWORDS.has(word) ? "Keyword" : "Identifier", name, word.length);
|
|
485
489
|
continue;
|
|
486
490
|
}
|
|
487
491
|
const stepLength = matchStep(source, cursor.index);
|