tla-ts 0.0.10-dev.b4a856304 → 0.0.10-dev.f16792fed

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