tla-ts 0.0.3-dev.3ce2f00 → 0.0.3-dev.3ef4193

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 (81) hide show
  1. package/dist/cli.cjs +1 -1
  2. package/dist/cli.js +1 -1
  3. package/dist/index.cjs +1 -1
  4. package/dist/index.d.cts +164 -46
  5. package/dist/index.d.ts +164 -46
  6. package/dist/index.js +1 -1
  7. package/dist/parallel-worker.cjs +1 -1
  8. package/dist/parallel-worker.js +2 -2
  9. package/dist/parallel.cjs +1 -1
  10. package/dist/parallel.js +2 -2
  11. package/dist/run-cli.cjs +1351 -22
  12. package/dist/run-cli.js +1351 -22
  13. package/dist/transfer.cjs +83 -33
  14. package/dist/transfer.js +83 -33
  15. package/package.json +5 -1
  16. package/src/ast.ts +54 -7
  17. package/src/bags.ts +4 -7
  18. package/src/builtins.ts +29 -17
  19. package/src/bundled-modules.ts +3 -3
  20. package/src/canonical.ts +4 -3
  21. package/src/check.ts +1317 -428
  22. package/src/cli.ts +8 -1
  23. package/src/codegen.ts +68 -21
  24. package/src/config.ts +225 -206
  25. package/src/environment.ts +417 -129
  26. package/src/errors.ts +155 -18
  27. package/src/evaluate.ts +713 -259
  28. package/src/exit-codes.ts +6 -24
  29. package/src/fingerprints.ts +1 -2
  30. package/src/index.ts +1 -0
  31. package/src/instances.ts +3 -1
  32. package/src/java-overrides.ts +104 -25
  33. package/src/levels.ts +122 -22
  34. package/src/lexer.ts +32 -4
  35. package/src/live-check.ts +204 -148
  36. package/src/liveness.ts +191 -122
  37. package/src/obligation-expression.ts +2 -2
  38. package/src/obligation-source.ts +2 -0
  39. package/src/parallel-worker.ts +6 -1
  40. package/src/parallel.ts +57 -6
  41. package/src/parser.ts +408 -168
  42. package/src/pcal-ast.ts +770 -0
  43. package/src/pcal-parse.ts +1523 -0
  44. package/src/pcal-tokenize.ts +516 -0
  45. package/src/pcal-translate.ts +1230 -0
  46. package/src/pcal-validate.ts +454 -0
  47. package/src/randomization.ts +24 -7
  48. package/src/resolve.ts +1379 -448
  49. package/src/run-cli.ts +1161 -196
  50. package/src/runtime.ts +16 -0
  51. package/src/sany-builtins.ts +147 -0
  52. package/src/sany-generator.ts +3112 -0
  53. package/src/sany-levels.ts +1208 -0
  54. package/src/sany-lexer.ts +545 -0
  55. package/src/sany-linter.ts +122 -0
  56. package/src/sany-modules.ts +1398 -0
  57. package/src/sany-nodes.ts +463 -0
  58. package/src/sany-parse-error.ts +2161 -0
  59. package/src/sany-report.ts +354 -0
  60. package/src/sany-selectors.ts +738 -0
  61. package/src/sany-source.ts +248 -0
  62. package/src/sany-xml.ts +1017 -0
  63. package/src/spec-description.ts +25 -5
  64. package/src/standard-modules.ts +172 -129
  65. package/src/standard-ranges.ts +116 -0
  66. package/src/state-graph.ts +29 -6
  67. package/src/subexpressions.ts +221 -161
  68. package/src/substitution-levels.ts +5 -8
  69. package/src/successors.ts +141 -173
  70. package/src/symmetry.ts +168 -50
  71. package/src/tableau.ts +3 -1
  72. package/src/tlc-ext.ts +13 -17
  73. package/src/tlc-messages.ts +329 -0
  74. package/src/tlc-module.ts +49 -21
  75. package/src/tlc-modules.ts +0 -4
  76. package/src/tlc-order.ts +55 -9
  77. package/src/tlc-random.ts +28 -3
  78. package/src/tlc-replay.ts +655 -0
  79. package/src/tlc-version.ts +18 -0
  80. package/src/transfer.ts +15 -3
  81. package/src/values.ts +664 -317
package/src/parallel.ts CHANGED
@@ -4,8 +4,12 @@ import {
4
4
  checkSequentially,
5
5
  createSearch,
6
6
  findAssumptionViolation,
7
+ reportInitialStatesProgress,
8
+ reportStartup,
7
9
  type CheckOptions,
10
+ type CheckProgress,
8
11
  type CheckResult,
12
+ type InitialStates,
9
13
  } from "./check";
10
14
  import { parseConfig, type ModelConfig } from "./config";
11
15
  import { createEnvironment } from "./environment";
@@ -20,10 +24,11 @@ import {
20
24
  type SharedFingerprints,
21
25
  } from "./fingerprints";
22
26
  import { getInitialStates } from "./successors";
23
- import { getTlcStringOrder, getTlcDeclarationOrder } from "./tlc-order";
27
+ import { getTlcStringOrder, getTlcVariableOrder } from "./tlc-order";
24
28
  import { getFingerprintDistance, OUT_DEGREE_BUCKETS } from "./tlc-summary";
25
29
  import { createStateEncoder, type EncodedStates } from "./transfer";
26
- import { getRankedStringCount, setStringOrder, type Value } from "./values";
30
+ import type { TlcVersion } from "./tlc-version";
31
+ import { getRankedStringCount, setStringOrder, setValueVersion, type Value } from "./values";
27
32
 
28
33
  const WORKER_THREADS_MODULE = "node:worker_threads";
29
34
 
@@ -43,6 +48,10 @@ export interface StartMessage {
43
48
  index: number;
44
49
  ports: (Port | undefined)[];
45
50
  seed: EncodedStates;
51
+ isTool: boolean | undefined;
52
+ isTraceRecorded: boolean | undefined;
53
+ isWarningEnabled: boolean | undefined;
54
+ version: TlcVersion | undefined;
46
55
  fingerprints: SharedFingerprints;
47
56
  requests: Int32Array;
48
57
  remaining: Int32Array;
@@ -101,16 +110,36 @@ const spawnWorker = async (onMessage: (message: WorkerMessage) => void): Promise
101
110
  };
102
111
 
103
112
  export const check = async (options: CheckOptions): Promise<CheckResult> => {
104
- const config = typeof options.config === "string" ? parseConfig(options.config) : options.config;
113
+ const config =
114
+ typeof options.config === "string"
115
+ ? parseConfig(options.config, options.version)
116
+ : options.config;
105
117
  const print = options.onPrint ?? console.log;
106
118
  const printed = { count: 0 };
107
- // The search on the calling thread prints what this one printed while it started, so it skips that.
119
+ // What each point the search reports is about, such as the invariant TLC warns about.
120
+ const getKey = (progress: CheckProgress) =>
121
+ [
122
+ progress.kind,
123
+ "name" in progress ? progress.name : "",
124
+ "count" in progress ? progress.count : "",
125
+ "text" in progress ? progress.text : "",
126
+ ].join(" ");
127
+ const reported = new Set<string>();
128
+ const report = (progress: CheckProgress) => {
129
+ reported.add(getKey(progress));
130
+ options.onProgress?.(progress);
131
+ };
132
+ // The search on the calling thread prints and reports what this one did while it started, so it
133
+ // skips that.
108
134
  const fallBack = () => {
109
135
  const skipped = { count: printed.count };
110
136
  return checkSequentially({
111
137
  ...options,
112
138
  config,
113
139
  onPrint: (text) => (skipped.count-- > 0 ? undefined : print(text)),
140
+ onProgress: (progress) => {
141
+ if (!reported.has(getKey(progress))) options.onProgress?.(progress);
142
+ },
114
143
  });
115
144
  };
116
145
  const count = options.workers ?? 1;
@@ -137,6 +166,7 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
137
166
  return bytes;
138
167
  };
139
168
  setStringOrder(getTlcStringOrder(options.source, config, loadModule));
169
+ setValueVersion(options.version);
140
170
  const startupStrings = getRankedStringCount();
141
171
  const specification = createEnvironment(config, {
142
172
  source: options.source,
@@ -147,10 +177,19 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
147
177
  print(text);
148
178
  },
149
179
  files: { readFile: options.readFile, writeFile: options.writeFile },
180
+ isTool: options.isTool,
181
+ isTraceRecorded: options.isTraceRecorded,
182
+ isSanyReported: options.isSanyReported,
183
+ isWarningEnabled: options.isWarningEnabled,
184
+ version: options.version,
150
185
  });
186
+ reportStartup(specification, config, report);
151
187
  const environment = specification.environment;
152
- const search = createSearch(config, environment, () =>
153
- getTlcDeclarationOrder(options.source, loadModule, "variable"),
188
+ const search = createSearch(
189
+ config,
190
+ environment,
191
+ () => getTlcVariableOrder(options.source, loadModule),
192
+ report,
154
193
  );
155
194
  if (findAssumptionViolation(specification.assumptions, environment)) return fallBack();
156
195
  if (
@@ -172,6 +211,7 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
172
211
  distinctStates: 0,
173
212
  queuedStates: 0,
174
213
  depth: 0,
214
+ initialStates: undefined as InitialStates | undefined,
175
215
  outDegrees: Array.from({ length: OUT_DEGREE_BUCKETS }, () => 0),
176
216
  };
177
217
  const tlcFingerprints: BigInt64Array[] = [];
@@ -196,6 +236,7 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
196
236
  const seedInitialStates = (init: Expression) => {
197
237
  const seeded: Value[][] = [];
198
238
  for (const state of getInitialStates(init, environment, search.spec.scope)) {
239
+ reportInitialStatesProgress(statistics.generatedStates, report);
199
240
  canonicalize(state);
200
241
  statistics.generatedStates++;
201
242
  writeStateFingerprint(search.getFingerprintState(state), fingerprint);
@@ -217,6 +258,7 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
217
258
  return true;
218
259
  };
219
260
  // The sequential search reports a violation or a failed evaluation in the initial states.
261
+ report({ kind: "initial-states-started" });
220
262
  try {
221
263
  if (!seedInitialStates(search.spec.init)) return fallBack();
222
264
  } catch (error) {
@@ -225,6 +267,11 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
225
267
  }
226
268
  if (getRankedStringCount() !== startupStrings) return fallBack();
227
269
  statistics.depth = statistics.generatedStates === 0 ? 0 : 1;
270
+ statistics.initialStates = {
271
+ generated: statistics.generatedStates,
272
+ distinct: statistics.distinctStates,
273
+ };
274
+ report({ kind: "initial-states-computed", initialStates: statistics.initialStates });
228
275
  if (statistics.distinctStates === 0) return createSuccess();
229
276
 
230
277
  const reports: WorkerMessage[] = [];
@@ -266,6 +313,10 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
266
313
  index,
267
314
  ports,
268
315
  seed,
316
+ isTool: options.isTool,
317
+ isTraceRecorded: options.isTraceRecorded,
318
+ isWarningEnabled: options.isWarningEnabled,
319
+ version: options.version,
269
320
  fingerprints: shared.fingerprints,
270
321
  requests,
271
322
  remaining,