tla-ts 0.0.3-dev.4c8c06c → 0.0.3-dev.4fdd845
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/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +157 -8
- package/dist/index.d.ts +157 -8
- 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 +1351 -19
- package/dist/run-cli.js +1351 -19
- package/dist/transfer.cjs +86 -16
- package/dist/transfer.js +86 -16
- package/package.json +5 -1
- package/src/ast.ts +142 -6
- package/src/bags.ts +4 -7
- package/src/builtins.ts +29 -11
- package/src/bundled-modules.ts +3 -3
- package/src/canonical.ts +4 -3
- package/src/check.ts +1539 -235
- package/src/cli-options.ts +11 -5
- package/src/cli.ts +8 -1
- package/src/codegen.ts +77 -37
- package/src/config.ts +252 -179
- package/src/dependencies.ts +2 -2
- package/src/environment.ts +518 -137
- package/src/errors.ts +224 -3
- package/src/evaluate.ts +796 -246
- package/src/exit-codes.ts +22 -43
- package/src/index.ts +1 -0
- package/src/instances.ts +19 -16
- package/src/java-overrides.ts +104 -25
- package/src/levels.ts +191 -45
- package/src/lexer.ts +32 -4
- package/src/live-check.ts +828 -0
- package/src/liveness.ts +218 -572
- package/src/obligation-expression.ts +2 -2
- package/src/obligation-source.ts +2 -0
- package/src/parallel-worker.ts +13 -4
- package/src/parallel.ts +73 -6
- package/src/parser.ts +447 -128
- package/src/pcal-ast.ts +770 -0
- package/src/pcal-parse.ts +1523 -0
- package/src/pcal-tokenize.ts +516 -0
- package/src/pcal-translate.ts +1230 -0
- package/src/pcal-validate.ts +454 -0
- package/src/randomization.ts +24 -7
- package/src/resolve.ts +1380 -420
- package/src/run-cli.ts +1200 -143
- package/src/runtime.ts +19 -1
- package/src/sany-builtins.ts +147 -0
- package/src/sany-generator.ts +3112 -0
- package/src/sany-levels.ts +1208 -0
- package/src/sany-lexer.ts +545 -0
- package/src/sany-linter.ts +122 -0
- package/src/sany-modules.ts +1398 -0
- package/src/sany-nodes.ts +463 -0
- package/src/sany-parse-error.ts +2161 -0
- package/src/sany-report.ts +354 -0
- package/src/sany-selectors.ts +738 -0
- package/src/sany-source.ts +248 -0
- package/src/sany-xml.ts +1017 -0
- package/src/spec-description.ts +42 -11
- package/src/standard-modules.ts +200 -148
- package/src/standard-ranges.ts +116 -0
- package/src/state-graph.ts +180 -0
- package/src/subexpressions.ts +231 -171
- package/src/substitution-levels.ts +38 -17
- package/src/successors.ts +219 -107
- package/src/symmetry.ts +180 -52
- package/src/tableau.ts +54 -25
- package/src/tlc-ext.ts +42 -29
- package/src/tlc-messages.ts +329 -0
- package/src/tlc-module.ts +52 -43
- package/src/tlc-order.ts +73 -9
- package/src/tlc-random.ts +37 -9
- package/src/tlc-replay.ts +655 -0
- package/src/tlc-summary.ts +20 -5
- package/src/tlc-version.ts +18 -0
- package/src/transfer.ts +15 -3
- package/src/value-sources.ts +29 -0
- package/src/values.ts +708 -180
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { SourceRange } from "./ast";
|
|
2
|
+
|
|
3
|
+
// Where the modules in TLC's tla2sany/StandardModules define the operators that tla-ts implements
|
|
4
|
+
// natively, which SANY reports when a spec defines one of them again.
|
|
5
|
+
const RANGES: Record<string, Record<string, [number, number, number, number]>> = {
|
|
6
|
+
Naturals: {
|
|
7
|
+
Nat: [14, 1, 14, 16],
|
|
8
|
+
"+": [15, 1, 15, 19],
|
|
9
|
+
"-": [17, 1, 17, 33],
|
|
10
|
+
"*": [18, 1, 18, 17],
|
|
11
|
+
"^": [19, 1, 19, 19],
|
|
12
|
+
"<": [20, 1, 20, 19],
|
|
13
|
+
">": [21, 1, 21, 19],
|
|
14
|
+
"<=": [22, 1, 22, 19],
|
|
15
|
+
">=": [23, 1, 23, 19],
|
|
16
|
+
"%": [33, 1, 33, 20],
|
|
17
|
+
"\\div": [34, 1, 34, 20],
|
|
18
|
+
"..": [35, 1, 35, 20],
|
|
19
|
+
},
|
|
20
|
+
Integers: {
|
|
21
|
+
Int: [18, 1, 18, 12],
|
|
22
|
+
"-.": [22, 1, 22, 13],
|
|
23
|
+
},
|
|
24
|
+
Sequences: {
|
|
25
|
+
Seq: [20, 1, 20, 41],
|
|
26
|
+
Len: [25, 1, 25, 44],
|
|
27
|
+
"\\o": [30, 1, 31, 76],
|
|
28
|
+
Append: [36, 1, 36, 26],
|
|
29
|
+
Head: [41, 1, 41, 15],
|
|
30
|
+
Tail: [42, 1, 42, 61],
|
|
31
|
+
SubSeq: [48, 1, 48, 50],
|
|
32
|
+
SelectSeq: [53, 1, 65, 14],
|
|
33
|
+
},
|
|
34
|
+
FiniteSets: {
|
|
35
|
+
IsFiniteSet: [14, 1, 19, 68],
|
|
36
|
+
Cardinality: [21, 1, 27, 11],
|
|
37
|
+
},
|
|
38
|
+
Bags: {
|
|
39
|
+
IsABag: [20, 1, 24, 41],
|
|
40
|
+
BagToSet: [26, 1, 26, 23],
|
|
41
|
+
SetToBag: [31, 1, 31, 30],
|
|
42
|
+
BagIn: [36, 1, 36, 31],
|
|
43
|
+
EmptyBag: [41, 1, 41, 24],
|
|
44
|
+
"\\oplus": [43, 1, 49, 46],
|
|
45
|
+
"\\ominus": [51, 1, 60, 50],
|
|
46
|
+
BagUnion: [74, 1, 79, 58],
|
|
47
|
+
"\\sqsubseteq": [81, 1, 87, 42],
|
|
48
|
+
SubBag: [89, 1, 110, 11],
|
|
49
|
+
BagOfAll: [122, 1, 130, 66],
|
|
50
|
+
BagCardinality: [132, 1, 138, 8],
|
|
51
|
+
CopiesIn: [140, 1, 145, 33],
|
|
52
|
+
},
|
|
53
|
+
TLC: {
|
|
54
|
+
Print: [17, 1, 17, 22],
|
|
55
|
+
PrintT: [18, 1, 18, 19],
|
|
56
|
+
Assert: [24, 1, 25, 54],
|
|
57
|
+
JavaTime: [26, 1, 26, 32],
|
|
58
|
+
TLCGet: [75, 1, 75, 28],
|
|
59
|
+
TLCSet: [76, 1, 76, 20],
|
|
60
|
+
":>": [78, 1, 78, 27],
|
|
61
|
+
"@@": [79, 1, 80, 50],
|
|
62
|
+
Permutations: [81, 1, 82, 54],
|
|
63
|
+
SortSeq: [88, 1, 92, 40],
|
|
64
|
+
RandomElement: [110, 1, 110, 41],
|
|
65
|
+
Any: [119, 1, 119, 22],
|
|
66
|
+
ToString: [121, 1, 121, 58],
|
|
67
|
+
TLCEval: [145, 1, 145, 15],
|
|
68
|
+
},
|
|
69
|
+
TLCExt: {
|
|
70
|
+
AssertEq: [14, 1, 20, 14],
|
|
71
|
+
AssertError: [23, 1, 26, 72],
|
|
72
|
+
TLCGetOrDefault: [30, 1, 31, 17],
|
|
73
|
+
TLCGetAndSet: [33, 1, 35, 57],
|
|
74
|
+
Trace: [41, 1, 57, 6],
|
|
75
|
+
CounterExample: [61, 1, 75, 8],
|
|
76
|
+
ToTrace: [77, 1, 87, 12],
|
|
77
|
+
TLCModelValue: [91, 1, 120, 29],
|
|
78
|
+
TLCDefer: [122, 1, 134, 6],
|
|
79
|
+
TLCNoOp: [138, 1, 145, 5],
|
|
80
|
+
PickSuccessor: [148, 1, 162, 37],
|
|
81
|
+
TLCCache: [166, 1, 173, 12],
|
|
82
|
+
TLCFP: [175, 1, 181, 24],
|
|
83
|
+
TLCEvalDefinition: [185, 1, 190, 6],
|
|
84
|
+
},
|
|
85
|
+
Randomization: {
|
|
86
|
+
RandomSubset: [30, 1, 30, 64],
|
|
87
|
+
RandomSetOfSubsets: [48, 1, 49, 67],
|
|
88
|
+
TestRandomSetOfSubsets: [61, 1, 62, 71],
|
|
89
|
+
},
|
|
90
|
+
Json: {
|
|
91
|
+
ToJson: [46, 1, 55, 37],
|
|
92
|
+
ToJsonArray: [57, 1, 64, 42],
|
|
93
|
+
ToJsonObject: [66, 1, 73, 43],
|
|
94
|
+
JsonSerialize: [75, 1, 80, 6],
|
|
95
|
+
JsonDeserialize: [82, 1, 87, 19],
|
|
96
|
+
ndJsonSerialize: [89, 1, 95, 6],
|
|
97
|
+
ndJsonDeserialize: [97, 1, 103, 19],
|
|
98
|
+
},
|
|
99
|
+
_Possible: {
|
|
100
|
+
_Track: [10, 1, 17, 38],
|
|
101
|
+
_Counts: [24, 1, 30, 14],
|
|
102
|
+
_CheckName: [32, 1, 35, 35],
|
|
103
|
+
_PrintCounts: [37, 1, 37, 31],
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export const getStandardRange = (module: string, name: string): SourceRange | undefined => {
|
|
108
|
+
const range = RANGES[module]?.[name];
|
|
109
|
+
return (
|
|
110
|
+
range && {
|
|
111
|
+
module,
|
|
112
|
+
start: { line: range[0], column: range[1] },
|
|
113
|
+
end: { line: range[2], column: range[3] },
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
};
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// A port of TLC's -dump writers, tlc2.util.StateWriter and tlc2.util.DotStateWriter.
|
|
2
|
+
|
|
3
|
+
import type { TlcVersion } from "./tlc-version";
|
|
4
|
+
|
|
5
|
+
export interface StateDump {
|
|
6
|
+
path: string;
|
|
7
|
+
dot?: boolean;
|
|
8
|
+
colorize?: boolean;
|
|
9
|
+
actionLabels?: boolean;
|
|
10
|
+
snapshot?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface GraphState {
|
|
14
|
+
fingerprint: bigint;
|
|
15
|
+
level: number;
|
|
16
|
+
// The state as TLC prints it after evaluating the alias, and as it prints it without the alias.
|
|
17
|
+
getLabel: () => string;
|
|
18
|
+
getText: () => string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface GraphAction {
|
|
22
|
+
name: string;
|
|
23
|
+
signature: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface StateWriter {
|
|
27
|
+
writeInitialState: (state: GraphState) => void;
|
|
28
|
+
writeSuccessor: (
|
|
29
|
+
state: GraphState,
|
|
30
|
+
successor: GraphState,
|
|
31
|
+
isSeen: boolean,
|
|
32
|
+
action: GraphAction | undefined,
|
|
33
|
+
) => void;
|
|
34
|
+
// The stuttering step of a state that TLC 1.7.4 adds to the behavior graph.
|
|
35
|
+
writeStuttering: (state: GraphState) => void;
|
|
36
|
+
close: () => void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
type WriteFile = ((path: string, content: string) => void) | undefined;
|
|
40
|
+
|
|
41
|
+
const COLOR_SCHEME = "paired12";
|
|
42
|
+
const LOAD_FACTOR = 0.75;
|
|
43
|
+
const INITIAL_CAPACITY = 16;
|
|
44
|
+
|
|
45
|
+
const getCapacity = (size: number, capacity = INITIAL_CAPACITY): number =>
|
|
46
|
+
size <= capacity * LOAD_FACTOR ? capacity : getCapacity(size, capacity * 2);
|
|
47
|
+
|
|
48
|
+
// The order in which a java.util.HashMap iterates over keys put in this order: by bucket, and in
|
|
49
|
+
// insertion order within a bucket. A bucket only becomes a tree once 8 keys collide in it.
|
|
50
|
+
const getJavaHashOrder = <Key>(keys: Key[], getHash: (key: Key) => number) => {
|
|
51
|
+
const mask = getCapacity(keys.length) - 1;
|
|
52
|
+
const getBucket = (key: Key) => {
|
|
53
|
+
const hash = getHash(key);
|
|
54
|
+
return (hash ^ (hash >>> 16)) & mask;
|
|
55
|
+
};
|
|
56
|
+
return keys
|
|
57
|
+
.map((key, position) => ({ key, position, bucket: getBucket(key) }))
|
|
58
|
+
.sort((left, right) => left.bucket - right.bucket || left.position - right.position)
|
|
59
|
+
.map((entry) => entry.key);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const getLongHash = (value: bigint) =>
|
|
63
|
+
Number(BigInt.asIntN(32, value ^ (BigInt.asUintN(64, value) >> 32n)));
|
|
64
|
+
|
|
65
|
+
const getStringHash = (text: string) =>
|
|
66
|
+
[...Array(text.length).keys()].reduce(
|
|
67
|
+
(hash, index) => (Math.imul(31, hash) + text.charCodeAt(index)) | 0,
|
|
68
|
+
0,
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const escape = (text: string) => text.replaceAll("\\", "\\\\").replaceAll('"', '\\"').trim();
|
|
72
|
+
|
|
73
|
+
const toDot = (text: string) => escape(text).replaceAll("\n", "\\n");
|
|
74
|
+
|
|
75
|
+
const createPlainWriter = (dump: StateDump, writeFile: WriteFile): StateWriter => {
|
|
76
|
+
const states: string[] = [];
|
|
77
|
+
const writeState = (state: GraphState) =>
|
|
78
|
+
states.push(`State ${states.length + 1}:\n${state.getText()}\n`);
|
|
79
|
+
return {
|
|
80
|
+
writeInitialState: writeState,
|
|
81
|
+
writeSuccessor: (_state, successor, isSeen) => {
|
|
82
|
+
if (!isSeen) writeState(successor);
|
|
83
|
+
},
|
|
84
|
+
// TLC 1.7.4 writes the state again, as it takes the stuttering step for one to a new state.
|
|
85
|
+
writeStuttering: writeState,
|
|
86
|
+
close: () => writeFile?.(dump.path, states.join("")),
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// TLC 1.7.4 draws its nodes as ellipses, gives them no tooltip, and labels an edge with the name
|
|
91
|
+
// of its action alone.
|
|
92
|
+
const createDotWriter = (
|
|
93
|
+
dump: StateDump,
|
|
94
|
+
writeFile: WriteFile,
|
|
95
|
+
version: TlcVersion | undefined,
|
|
96
|
+
): StateWriter => {
|
|
97
|
+
const is174 = version === "1.7.4";
|
|
98
|
+
const lines = [
|
|
99
|
+
"strict digraph DiskGraph {\n",
|
|
100
|
+
is174 ? "" : "node [shape=box,style=rounded]\n",
|
|
101
|
+
dump.colorize ? `edge [colorscheme="${COLOR_SCHEME}"]\n` : "",
|
|
102
|
+
"nodesep=0.35;\n",
|
|
103
|
+
"subgraph cluster_graph {\n",
|
|
104
|
+
'color="white";\n',
|
|
105
|
+
];
|
|
106
|
+
const ranks = new Map<number, Set<bigint>>();
|
|
107
|
+
const colors = new Map<string, number>();
|
|
108
|
+
const addRank = (state: GraphState) => {
|
|
109
|
+
const rank = ranks.get(state.level) ?? new Set();
|
|
110
|
+
ranks.set(state.level, rank.add(state.fingerprint));
|
|
111
|
+
};
|
|
112
|
+
// TLC colors an edge by the name of its action, numbering the names from 2 as it finds them.
|
|
113
|
+
const getColor = (action: GraphAction | undefined) => {
|
|
114
|
+
if (!action) return 1;
|
|
115
|
+
const color = colors.get(action.name) ?? colors.size + 2;
|
|
116
|
+
colors.set(action.name, color);
|
|
117
|
+
return color;
|
|
118
|
+
};
|
|
119
|
+
const getLegend = () =>
|
|
120
|
+
[
|
|
121
|
+
`subgraph cluster_legend {graph[style=bold];label = "Next State Actions" style="solid"\n`,
|
|
122
|
+
`node [ labeljust="l",colorscheme="${COLOR_SCHEME}",style=filled,shape=record ]\n`,
|
|
123
|
+
...getJavaHashOrder([...colors.keys()], getStringHash).map(
|
|
124
|
+
(name) => `${name.replaceAll("!", ":")} [label="${name}",fillcolor=${colors.get(name)}]\n`,
|
|
125
|
+
),
|
|
126
|
+
"}",
|
|
127
|
+
].join("");
|
|
128
|
+
const getEnding = () =>
|
|
129
|
+
[
|
|
130
|
+
...getJavaHashOrder([...ranks], (rank) => rank[0]).map(
|
|
131
|
+
(rank) =>
|
|
132
|
+
`{rank = same; ${getJavaHashOrder([...rank[1]], getLongHash)
|
|
133
|
+
.map((fingerprint) => `${fingerprint};`)
|
|
134
|
+
.join("")}}\n`,
|
|
135
|
+
),
|
|
136
|
+
"}\n",
|
|
137
|
+
dump.colorize && colors.size > 1 ? getLegend() : "",
|
|
138
|
+
"}",
|
|
139
|
+
].join("");
|
|
140
|
+
const writeSnapshot = () => {
|
|
141
|
+
if (dump.snapshot) {
|
|
142
|
+
writeFile?.(dump.path.replaceAll(".dot", "_snapshot.dot"), lines.join("") + getEnding());
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
return {
|
|
146
|
+
writeInitialState: (state) => {
|
|
147
|
+
lines.push(`${state.fingerprint} [label="${toDot(state.getLabel())}",style = filled]\n`);
|
|
148
|
+
addRank(state);
|
|
149
|
+
writeSnapshot();
|
|
150
|
+
},
|
|
151
|
+
writeSuccessor: (state, successor, isSeen, action) => {
|
|
152
|
+
const color = dump.colorize ? String(getColor(action)) : "black";
|
|
153
|
+
const label =
|
|
154
|
+
dump.actionLabels && action ? escape(is174 ? action.name : action.signature) : "";
|
|
155
|
+
lines.push(
|
|
156
|
+
`${state.fingerprint} -> ${successor.fingerprint} [label="${label}",color="${color}",fontcolor="${color}"];\n`,
|
|
157
|
+
);
|
|
158
|
+
if (!isSeen) {
|
|
159
|
+
const tooltip = is174 ? "" : `,tooltip="${toDot(successor.getText())}"`;
|
|
160
|
+
lines.push(
|
|
161
|
+
`${successor.fingerprint} [label="${toDot(successor.getLabel())}"${tooltip}];\n`,
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
addRank(state);
|
|
165
|
+
writeSnapshot();
|
|
166
|
+
},
|
|
167
|
+
writeStuttering: (state) => {
|
|
168
|
+
lines.push(`${state.fingerprint} -> ${state.fingerprint} [style="dashed"];\n`);
|
|
169
|
+
addRank(state);
|
|
170
|
+
writeSnapshot();
|
|
171
|
+
},
|
|
172
|
+
close: () => writeFile?.(dump.path, lines.join("") + getEnding()),
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
export const createStateWriter = (
|
|
177
|
+
dump: StateDump,
|
|
178
|
+
writeFile: WriteFile,
|
|
179
|
+
version: TlcVersion | undefined,
|
|
180
|
+
) => (dump.dot ? createDotWriter(dump, writeFile, version) : createPlainWriter(dump, writeFile));
|