tla-ts 0.0.10-dev.28c823e4b → 0.0.10-dev.b4a856304
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/dist/index.cjs +1 -1
- package/dist/index.d.cts +0 -34
- package/dist/index.d.ts +0 -34
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +43 -43
- package/dist/prove.js +47 -47
- package/dist/run.cjs +30 -30
- package/dist/run.js +33 -33
- package/dist/transfer.cjs +38 -38
- package/dist/transfer.js +39 -39
- package/package.json +1 -1
- package/src/ast.ts +5 -0
- package/src/bags.ts +5 -2
- package/src/builtins.ts +8 -1
- package/src/check.ts +193 -128
- package/src/cli/run.ts +2 -0
- package/src/cli/runtime-invariants.ts +7 -8
- package/src/cli/shared.ts +4 -0
- package/src/cli/tlc-arguments.ts +30 -24
- package/src/cli/tlc-usage.ts +3 -2
- package/src/evaluate.ts +102 -26
- package/src/java-overrides.ts +9 -4
- package/src/json-reader.ts +2 -1
- package/src/json.ts +11 -4
- package/src/levels.ts +15 -7
- package/src/lexer.ts +83 -72
- package/src/liveness-checker.ts +106 -77
- package/src/liveness.ts +34 -10
- package/src/parallel.ts +33 -26
- package/src/parser.ts +226 -163
- package/src/pcal/ast.ts +65 -53
- package/src/pcal/parse.ts +191 -144
- package/src/pcal/tokenize.ts +115 -91
- package/src/pcal/translate.ts +98 -83
- package/src/pcal/validate.ts +50 -48
- package/src/pretty-print.ts +6 -6
- package/src/randomization.ts +4 -1
- package/src/resolve.ts +70 -12
- package/src/runtime.ts +18 -11
- package/src/sany/builtins.ts +3 -1
- package/src/sany/generator.ts +127 -74
- package/src/sany/levels.ts +9 -5
- package/src/sany/lexer.ts +44 -40
- package/src/sany/linter.ts +1 -0
- package/src/search.ts +1 -1
- package/src/simulate.ts +59 -50
- package/src/spec-description.ts +34 -23
- package/src/standard-definitions.ts +3 -0
- package/src/standard-modules.ts +12 -1
- package/src/state-graph.ts +8 -1
- package/src/subexpressions.ts +47 -38
- package/src/successors.ts +35 -14
- package/src/symmetry.ts +19 -4
- package/src/tlc/fingerprint.ts +21 -15
- package/src/tlc/jar-data.ts +1 -0
- package/src/tlc/messages.ts +21 -2
- package/src/tlc/order.ts +38 -20
- package/src/tlc/random.ts +30 -18
- package/src/tlc/replay.ts +33 -13
- package/src/tlc/summary.ts +45 -36
- package/src/tlc/tlc-operators.ts +14 -4
- package/src/tlc/tlcext-operators.ts +15 -11
- package/src/tlc/trace-spec.ts +4 -0
- package/src/tlc/value-stream.ts +13 -9
- package/src/tlc/version.ts +1 -0
- package/src/values.ts +181 -74
package/src/parallel.ts
CHANGED
|
@@ -85,7 +85,7 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
85
85
|
? parseConfig(options.config, options.version)
|
|
86
86
|
: options.config;
|
|
87
87
|
const print = options.onPrint ?? console.log;
|
|
88
|
-
|
|
88
|
+
const printed = { count: 0 };
|
|
89
89
|
const getKey = (progress: CheckProgress) =>
|
|
90
90
|
[
|
|
91
91
|
progress.kind,
|
|
@@ -98,21 +98,26 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
98
98
|
reported.add(getKey(progress));
|
|
99
99
|
options.onProgress?.(progress);
|
|
100
100
|
};
|
|
101
|
+
// The search on the calling thread prints and reports what this one did while it started, so it
|
|
102
|
+
// skips that.
|
|
101
103
|
const fallBack = (createdString?: string) => {
|
|
102
104
|
if (createdString !== undefined) {
|
|
103
105
|
options.onProgress?.({ kind: "sequential-fallback", string: createdString });
|
|
104
106
|
}
|
|
105
|
-
|
|
107
|
+
const skipped = { count: printed.count };
|
|
106
108
|
return checkSequentially({
|
|
107
109
|
...options,
|
|
108
110
|
config,
|
|
109
|
-
onPrint: (text) => (
|
|
111
|
+
onPrint: (text) => (skipped.count-- > 0 ? undefined : print(text)),
|
|
110
112
|
onProgress: (progress) => {
|
|
111
113
|
if (!reported.has(getKey(progress))) options.onProgress?.(progress);
|
|
112
114
|
},
|
|
113
115
|
});
|
|
114
116
|
};
|
|
115
117
|
const workerCount = options.workers ?? 1;
|
|
118
|
+
// TLC's workers write the -dump state graph, and print the violations -continue goes on past, in
|
|
119
|
+
// whichever order they find them, so one worker does what a single TLC worker does. The
|
|
120
|
+
// coverage counts live in one worker's evaluators.
|
|
116
121
|
const isSequential =
|
|
117
122
|
workerCount < 2 ||
|
|
118
123
|
typeof SharedArrayBuffer !== "function" ||
|
|
@@ -147,7 +152,7 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
147
152
|
order,
|
|
148
153
|
loadClass,
|
|
149
154
|
print: (text) => {
|
|
150
|
-
|
|
155
|
+
printed.count++;
|
|
151
156
|
print(text);
|
|
152
157
|
},
|
|
153
158
|
files: {
|
|
@@ -182,7 +187,7 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
182
187
|
}
|
|
183
188
|
|
|
184
189
|
const canonicalize = createCanonicalizer();
|
|
185
|
-
|
|
190
|
+
const shared = { fingerprints: createSharedFingerprints() };
|
|
186
191
|
const fingerprint = new Int32Array(2);
|
|
187
192
|
const seeds = Array.from({ length: workerCount }, createStateEncoder);
|
|
188
193
|
const statistics = {
|
|
@@ -219,10 +224,10 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
219
224
|
canonicalize(state);
|
|
220
225
|
statistics.generatedStates++;
|
|
221
226
|
writeStateFingerprint(search.getFingerprintState(state), fingerprint);
|
|
222
|
-
if (isSharedFingerprintsFull(
|
|
223
|
-
|
|
227
|
+
if (isSharedFingerprintsFull(shared.fingerprints)) {
|
|
228
|
+
shared.fingerprints = growSharedFingerprints(shared.fingerprints);
|
|
224
229
|
}
|
|
225
|
-
if (!insertSharedFingerprint(
|
|
230
|
+
if (!insertSharedFingerprint(shared.fingerprints, fingerprint[0], fingerprint[1])) continue;
|
|
226
231
|
if (search.findViolatedInvariant(state) || search.findFailedInitialPredicate(state)) {
|
|
227
232
|
return false;
|
|
228
233
|
}
|
|
@@ -236,6 +241,7 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
236
241
|
);
|
|
237
242
|
return true;
|
|
238
243
|
};
|
|
244
|
+
// The sequential search reports a violation or a failed evaluation in the initial states.
|
|
239
245
|
report({ kind: "initial-states-started" });
|
|
240
246
|
try {
|
|
241
247
|
if (!seedInitialStates(search.spec.init)) return fallBack();
|
|
@@ -254,18 +260,17 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
254
260
|
if (statistics.distinctStates === 0) return createSuccess();
|
|
255
261
|
|
|
256
262
|
const reports: WorkerMessage[] = [];
|
|
257
|
-
|
|
258
|
-
let resolvePending = (_reports: WorkerMessage[]) => {};
|
|
263
|
+
const pending = { count: workerCount, resolve: (_reports: WorkerMessage[]) => {} };
|
|
259
264
|
const onMessage = (message: WorkerMessage) => {
|
|
260
265
|
reports.push(message);
|
|
261
|
-
if (message.type === "abort" || reports.length ===
|
|
262
|
-
|
|
266
|
+
if (message.type === "abort" || reports.length === pending.count) {
|
|
267
|
+
pending.resolve(reports.splice(0));
|
|
263
268
|
}
|
|
264
269
|
};
|
|
265
270
|
const waitForReports = (expected: number) =>
|
|
266
271
|
new Promise<WorkerMessage[]>((resolve) => {
|
|
267
|
-
|
|
268
|
-
|
|
272
|
+
pending.count = expected;
|
|
273
|
+
pending.resolve = resolve;
|
|
269
274
|
});
|
|
270
275
|
const ready = waitForReports(workerCount);
|
|
271
276
|
const requests = new Int32Array(new SharedArrayBuffer(workerCount * 4));
|
|
@@ -288,7 +293,7 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
288
293
|
return (from < to ? channel.port1 : channel.port2) as unknown as Port;
|
|
289
294
|
};
|
|
290
295
|
workers.forEach((worker, index) => {
|
|
291
|
-
const ports = Array.from({ length: workerCount }, (
|
|
296
|
+
const ports = Array.from({ length: workerCount }, (_, peer) =>
|
|
292
297
|
peer === index ? undefined : getPort(index, peer),
|
|
293
298
|
);
|
|
294
299
|
const seed = seeds[index].finish();
|
|
@@ -308,7 +313,7 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
308
313
|
fingerprintPolynomial: options.fingerprintPolynomial,
|
|
309
314
|
maxSetSize: options.maxSetSize,
|
|
310
315
|
isLazyValueExpanded: options.isLazyValueExpanded,
|
|
311
|
-
fingerprints:
|
|
316
|
+
fingerprints: shared.fingerprints,
|
|
312
317
|
requests,
|
|
313
318
|
remaining,
|
|
314
319
|
};
|
|
@@ -318,24 +323,26 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
318
323
|
messages.some((message) => message.type === "abort");
|
|
319
324
|
const send = (message: CoordinatorMessage) =>
|
|
320
325
|
workers.forEach((worker) => worker.postMessage(message));
|
|
326
|
+
// Workers pause when the shared table needs to grow, and resume once it has.
|
|
321
327
|
const collectLevels = async (messages: WorkerMessage[]): Promise<WorkerMessage[]> => {
|
|
322
|
-
const
|
|
323
|
-
if (
|
|
324
|
-
|
|
325
|
-
const resumed = waitForReports(
|
|
326
|
-
send({ type: "resize", fingerprints:
|
|
327
|
-
const
|
|
328
|
-
return [...
|
|
328
|
+
const paused = messages.filter((message) => message.type === "paused").length;
|
|
329
|
+
if (paused === 0 || isAborted(messages)) return messages;
|
|
330
|
+
shared.fingerprints = growSharedFingerprints(shared.fingerprints);
|
|
331
|
+
const resumed = waitForReports(paused);
|
|
332
|
+
send({ type: "resize", fingerprints: shared.fingerprints });
|
|
333
|
+
const reported = messages.filter((message) => message.type !== "paused");
|
|
334
|
+
return [...reported, ...(await collectLevels(await resumed))];
|
|
329
335
|
};
|
|
330
336
|
if (isAborted(await ready)) {
|
|
331
337
|
terminate();
|
|
332
338
|
return fallBack();
|
|
333
339
|
}
|
|
334
340
|
for (;;) {
|
|
335
|
-
const
|
|
336
|
-
|
|
341
|
+
const reported = waitForReports(workerCount);
|
|
342
|
+
// Every worker is idle, so peers can ask any of them for states once the level starts.
|
|
343
|
+
requests.forEach((_, index) => Atomics.store(requests, index, 0));
|
|
337
344
|
send({ type: "level" });
|
|
338
|
-
const messages = await collectLevels(await
|
|
345
|
+
const messages = await collectLevels(await reported);
|
|
339
346
|
if (isAborted(messages)) {
|
|
340
347
|
terminate();
|
|
341
348
|
const aborted = messages.find(
|