tla-ts 0.0.1 → 0.0.3-dev.19c763f
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 +98 -39
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +225 -30
- package/dist/index.d.ts +225 -30
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +2 -2
- package/dist/parallel-worker.js +2 -2
- package/dist/parallel.cjs +1 -1
- package/dist/parallel.js +2 -2
- package/dist/run-cli.cjs +21 -1
- package/dist/run-cli.js +21 -1
- package/dist/transfer.cjs +400 -39
- package/dist/transfer.js +400 -39
- package/package.json +6 -2
- package/src/ast.ts +213 -6
- package/src/bags.ts +161 -71
- package/src/builtins.ts +203 -23
- package/src/bundled-modules.ts +63 -32
- package/src/check.ts +1086 -244
- package/src/cli-options.ts +64 -0
- package/src/codegen.ts +58 -34
- package/src/config.ts +39 -11
- package/src/dependencies.ts +2 -2
- package/src/environment.ts +557 -153
- package/src/errors.ts +66 -1
- package/src/evaluate.ts +547 -255
- package/src/exit-codes.ts +53 -0
- package/src/fingerprints.ts +48 -13
- package/src/index.ts +9 -4
- package/src/instances.ts +235 -79
- package/src/java-overrides.ts +241 -0
- package/src/json.ts +153 -72
- package/src/levels.ts +850 -0
- package/src/lexer.ts +108 -29
- package/src/live-check.ts +710 -0
- package/src/liveness.ts +37 -599
- package/src/obligation-action.ts +384 -0
- package/src/obligation-anon.ts +575 -0
- package/src/obligation-deref.ts +637 -0
- package/src/obligation-expression.ts +1060 -0
- package/src/obligation-format.ts +406 -0
- package/src/obligation-generate.ts +1074 -0
- package/src/obligation-levels.ts +329 -0
- package/src/obligation-module.ts +1042 -0
- package/src/obligation-printer.ts +889 -0
- package/src/obligation-proof.ts +76 -0
- package/src/obligation-source.ts +1084 -0
- package/src/obligation-tuples.ts +184 -0
- package/src/obligations.ts +316 -0
- package/src/parallel-worker.ts +186 -201
- package/src/parallel.ts +179 -84
- package/src/parser.ts +970 -206
- package/src/pretty-print.ts +259 -0
- package/src/randomization.ts +24 -113
- package/src/resolve.ts +483 -51
- package/src/run-cli.ts +473 -62
- package/src/runtime.ts +65 -28
- package/src/spec-description.ts +521 -0
- package/src/standard-levels.ts +105 -0
- package/src/standard-modules.ts +223 -92
- package/src/state-graph.ts +157 -0
- package/src/subexpressions.ts +31 -45
- package/src/substitution-levels.ts +184 -0
- package/src/successors.ts +276 -53
- package/src/symmetry.ts +79 -23
- package/src/tableau.ts +43 -37
- package/src/tlc-ext.ts +148 -44
- package/src/tlc-module.ts +71 -66
- package/src/tlc-modules.ts +1022 -0
- package/src/tlc-order.ts +511 -0
- package/src/tlc-random.ts +411 -0
- package/src/tlc-summary.ts +109 -0
- package/src/transfer.ts +26 -5
- package/src/values.ts +1245 -176
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { LivenessChecker } from "./live-check";
|
|
2
|
+
|
|
3
|
+
// TLC's exit statuses, from EC.ExitStatus.
|
|
4
|
+
export const EXIT_STATUS = {
|
|
5
|
+
success: 0,
|
|
6
|
+
assumptionViolation: 10,
|
|
7
|
+
deadlock: 11,
|
|
8
|
+
safetyViolation: 12,
|
|
9
|
+
livenessViolation: 13,
|
|
10
|
+
assertViolation: 14,
|
|
11
|
+
specEvaluationFailure: 75,
|
|
12
|
+
safetyEvaluationFailure: 76,
|
|
13
|
+
livenessEvaluationFailure: 77,
|
|
14
|
+
specParseError: 150,
|
|
15
|
+
configParseError: 151,
|
|
16
|
+
error: 255,
|
|
17
|
+
} as const;
|
|
18
|
+
|
|
19
|
+
const exitCodes = new WeakMap<Error, number>();
|
|
20
|
+
|
|
21
|
+
// The innermost site that knows TLC's exit status for an error sets it first and wins.
|
|
22
|
+
export const setExitCode = <Thrown>(error: Thrown, code: number) => {
|
|
23
|
+
if (error instanceof Error && !exitCodes.has(error)) exitCodes.set(error, code);
|
|
24
|
+
return error;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const getExitCode = (error: Error) => exitCodes.get(error);
|
|
28
|
+
|
|
29
|
+
// TLC exits with 255 when it fails to process or evaluate a liveness property, in any phase.
|
|
30
|
+
const withErrorExitCode = <Result>(run: () => Result) => {
|
|
31
|
+
try {
|
|
32
|
+
return run();
|
|
33
|
+
} catch (error) {
|
|
34
|
+
throw setExitCode(error, EXIT_STATUS.error);
|
|
35
|
+
}
|
|
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/fingerprints.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { getValueFingerprint, getValueHash, type Value } from "./values";
|
|
2
2
|
|
|
3
3
|
const EMPTY = 0;
|
|
4
|
-
const TOMBSTONE = 1;
|
|
5
4
|
const INITIAL_CAPACITY = 1 << 12;
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
interface FingerprintTable {
|
|
8
7
|
insert: (first: number, second: number) => boolean;
|
|
9
|
-
remove: (first: number, second: number) => void;
|
|
10
8
|
}
|
|
11
9
|
|
|
12
10
|
const mix = (hash: number) => {
|
|
@@ -15,7 +13,7 @@ const mix = (hash: number) => {
|
|
|
15
13
|
return second ^ (second >>> 16);
|
|
16
14
|
};
|
|
17
15
|
|
|
18
|
-
export const
|
|
16
|
+
export const writeStateFingerprint = (state: Value[], fingerprint: Int32Array) => {
|
|
19
17
|
let first = 0x811c9dc5;
|
|
20
18
|
let second = 0x6a09e667;
|
|
21
19
|
for (let index = 0; index < state.length; index++) {
|
|
@@ -26,15 +24,13 @@ export const getStateFingerprint = (state: Value[], fingerprint: Int32Array) =>
|
|
|
26
24
|
fingerprint[1] = mix(second);
|
|
27
25
|
};
|
|
28
26
|
|
|
29
|
-
export const getFingerprintOwner = (second: number, count: number) => (second >>> 0) % count;
|
|
30
|
-
|
|
31
27
|
export const createFingerprintTable = (): FingerprintTable => {
|
|
32
28
|
const table = { slots: new Int32Array(INITIAL_CAPACITY * 2), used: 0 };
|
|
33
29
|
const findSlot = (slots: Int32Array, first: number, second: number) => {
|
|
34
30
|
const mask = slots.length / 2 - 1;
|
|
35
31
|
for (let index = first & mask; ; index = (index + 1) & mask) {
|
|
36
32
|
const stored = slots[index * 2];
|
|
37
|
-
if (stored === EMPTY
|
|
33
|
+
if (stored === EMPTY) return index;
|
|
38
34
|
if (stored === first && slots[index * 2 + 1] === second) return index;
|
|
39
35
|
}
|
|
40
36
|
};
|
|
@@ -59,11 +55,50 @@ export const createFingerprintTable = (): FingerprintTable => {
|
|
|
59
55
|
table.used++;
|
|
60
56
|
return true;
|
|
61
57
|
},
|
|
62
|
-
remove: (first, second) => {
|
|
63
|
-
const slot = findSlot(table.slots, first, second);
|
|
64
|
-
if (table.slots[slot * 2] !== first) return;
|
|
65
|
-
table.slots[slot * 2] = EMPTY;
|
|
66
|
-
table.slots[slot * 2 + 1] = TOMBSTONE;
|
|
67
|
-
},
|
|
68
58
|
};
|
|
69
59
|
};
|
|
60
|
+
|
|
61
|
+
// Workers share one table of 64-bit fingerprints. The first word is never 0, so 0 marks an empty slot.
|
|
62
|
+
export interface SharedFingerprints {
|
|
63
|
+
slots: BigInt64Array;
|
|
64
|
+
used: Int32Array;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const INITIAL_SHARED_CAPACITY = 1 << 10;
|
|
68
|
+
|
|
69
|
+
const insertSharedKey = (slots: BigInt64Array, key: bigint) => {
|
|
70
|
+
const mask = slots.length - 1;
|
|
71
|
+
for (let index = Number(key >> 32n) & mask; ; index = (index + 1) & mask) {
|
|
72
|
+
const stored = Atomics.load(slots, index);
|
|
73
|
+
if (stored === key) return false;
|
|
74
|
+
if (stored !== 0n) continue;
|
|
75
|
+
const previous = Atomics.compareExchange(slots, index, 0n, key);
|
|
76
|
+
if (previous === 0n) return true;
|
|
77
|
+
if (previous === key) return false;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export const createSharedFingerprints = (): SharedFingerprints => ({
|
|
82
|
+
slots: new BigInt64Array(new SharedArrayBuffer(INITIAL_SHARED_CAPACITY * 8)),
|
|
83
|
+
used: new Int32Array(new SharedArrayBuffer(4)),
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
export const insertSharedFingerprint = (
|
|
87
|
+
table: SharedFingerprints,
|
|
88
|
+
first: number,
|
|
89
|
+
second: number,
|
|
90
|
+
) => {
|
|
91
|
+
const key = BigInt.asIntN(64, (BigInt(first) << 32n) | BigInt(second >>> 0));
|
|
92
|
+
if (!insertSharedKey(table.slots, key)) return false;
|
|
93
|
+
Atomics.add(table.used, 0, 1);
|
|
94
|
+
return true;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export const isSharedFingerprintsFull = (table: SharedFingerprints) =>
|
|
98
|
+
Atomics.load(table.used, 0) * 2 >= table.slots.length;
|
|
99
|
+
|
|
100
|
+
export const growSharedFingerprints = (table: SharedFingerprints): SharedFingerprints => {
|
|
101
|
+
const slots = new BigInt64Array(new SharedArrayBuffer(table.slots.byteLength * 2));
|
|
102
|
+
for (const key of table.slots) if (key !== 0n) insertSharedKey(slots, key);
|
|
103
|
+
return { slots, used: table.used };
|
|
104
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
1
|
+
export type {
|
|
2
|
+
CheckOptions,
|
|
3
|
+
CheckResult,
|
|
4
|
+
CheckStatus,
|
|
5
|
+
EvaluationFailure,
|
|
6
|
+
TraceStep,
|
|
7
|
+
Violation,
|
|
8
|
+
} from "./check";
|
|
3
9
|
export { parseConfig } from "./config";
|
|
4
10
|
export type { ConfigValue, ConstantAssignment, ModelConfig, Substitution } from "./config";
|
|
5
11
|
export {
|
|
@@ -9,8 +15,7 @@ export {
|
|
|
9
15
|
TlaSyntaxError,
|
|
10
16
|
TlaUnsupportedError,
|
|
11
17
|
} from "./errors";
|
|
12
|
-
export {
|
|
13
|
-
export type { ParallelCheckOptions } from "./parallel";
|
|
18
|
+
export { check } from "./parallel";
|
|
14
19
|
export { parseModule } from "./parser";
|
|
15
20
|
export type { Module } from "./ast";
|
|
16
21
|
export { formatValue } from "./values";
|