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.
Files changed (68) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.d.cts +0 -34
  3. package/dist/index.d.ts +0 -34
  4. package/dist/index.js +1 -1
  5. package/dist/parallel-worker.cjs +1 -1
  6. package/dist/parallel-worker.js +1 -1
  7. package/dist/prove.cjs +43 -43
  8. package/dist/prove.js +47 -47
  9. package/dist/run.cjs +30 -30
  10. package/dist/run.js +33 -33
  11. package/dist/transfer.cjs +38 -38
  12. package/dist/transfer.js +39 -39
  13. package/package.json +1 -1
  14. package/src/ast.ts +5 -0
  15. package/src/bags.ts +5 -2
  16. package/src/builtins.ts +8 -1
  17. package/src/check.ts +193 -128
  18. package/src/cli/run.ts +2 -0
  19. package/src/cli/runtime-invariants.ts +7 -8
  20. package/src/cli/shared.ts +4 -0
  21. package/src/cli/tlc-arguments.ts +30 -24
  22. package/src/cli/tlc-usage.ts +3 -2
  23. package/src/evaluate.ts +102 -26
  24. package/src/java-overrides.ts +9 -4
  25. package/src/json-reader.ts +2 -1
  26. package/src/json.ts +11 -4
  27. package/src/levels.ts +15 -7
  28. package/src/lexer.ts +83 -72
  29. package/src/liveness-checker.ts +106 -77
  30. package/src/liveness.ts +34 -10
  31. package/src/parallel.ts +33 -26
  32. package/src/parser.ts +226 -163
  33. package/src/pcal/ast.ts +65 -53
  34. package/src/pcal/parse.ts +191 -144
  35. package/src/pcal/tokenize.ts +115 -91
  36. package/src/pcal/translate.ts +98 -83
  37. package/src/pcal/validate.ts +50 -48
  38. package/src/pretty-print.ts +6 -6
  39. package/src/randomization.ts +4 -1
  40. package/src/resolve.ts +70 -12
  41. package/src/runtime.ts +18 -11
  42. package/src/sany/builtins.ts +3 -1
  43. package/src/sany/generator.ts +127 -74
  44. package/src/sany/levels.ts +9 -5
  45. package/src/sany/lexer.ts +44 -40
  46. package/src/sany/linter.ts +1 -0
  47. package/src/search.ts +1 -1
  48. package/src/simulate.ts +59 -50
  49. package/src/spec-description.ts +34 -23
  50. package/src/standard-definitions.ts +3 -0
  51. package/src/standard-modules.ts +12 -1
  52. package/src/state-graph.ts +8 -1
  53. package/src/subexpressions.ts +47 -38
  54. package/src/successors.ts +35 -14
  55. package/src/symmetry.ts +19 -4
  56. package/src/tlc/fingerprint.ts +21 -15
  57. package/src/tlc/jar-data.ts +1 -0
  58. package/src/tlc/messages.ts +21 -2
  59. package/src/tlc/order.ts +38 -20
  60. package/src/tlc/random.ts +30 -18
  61. package/src/tlc/replay.ts +33 -13
  62. package/src/tlc/summary.ts +45 -36
  63. package/src/tlc/tlc-operators.ts +14 -4
  64. package/src/tlc/tlcext-operators.ts +15 -11
  65. package/src/tlc/trace-spec.ts +4 -0
  66. package/src/tlc/value-stream.ts +13 -9
  67. package/src/tlc/version.ts +1 -0
  68. 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
- let printedCount = 0;
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
- let skippedCount = printedCount;
107
+ const skipped = { count: printed.count };
106
108
  return checkSequentially({
107
109
  ...options,
108
110
  config,
109
- onPrint: (text) => (skippedCount-- > 0 ? undefined : print(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
- printedCount++;
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
- let sharedFingerprints = createSharedFingerprints();
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(sharedFingerprints)) {
223
- sharedFingerprints = growSharedFingerprints(sharedFingerprints);
227
+ if (isSharedFingerprintsFull(shared.fingerprints)) {
228
+ shared.fingerprints = growSharedFingerprints(shared.fingerprints);
224
229
  }
225
- if (!insertSharedFingerprint(sharedFingerprints, fingerprint[0], fingerprint[1])) continue;
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
- let pendingCount = workerCount;
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 === pendingCount) {
262
- resolvePending(reports.splice(0));
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
- pendingCount = expected;
268
- resolvePending = resolve;
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 }, (_value, peer) =>
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: sharedFingerprints,
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 pausedCount = messages.filter((message) => message.type === "paused").length;
323
- if (pausedCount === 0 || isAborted(messages)) return messages;
324
- sharedFingerprints = growSharedFingerprints(sharedFingerprints);
325
- const resumed = waitForReports(pausedCount);
326
- send({ type: "resize", fingerprints: sharedFingerprints });
327
- const unpaused = messages.filter((message) => message.type !== "paused");
328
- return [...unpaused, ...(await collectLevels(await resumed))];
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 levelReports = waitForReports(workerCount);
336
- requests.forEach((_request, index) => Atomics.store(requests, index, 0));
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 levelReports);
345
+ const messages = await collectLevels(await reported);
339
346
  if (isAborted(messages)) {
340
347
  terminate();
341
348
  const aborted = messages.find(