tla-ts 0.0.8-dev.d9bffda → 0.0.9-dev.0dd11f695

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 (119) hide show
  1. package/README.md +30 -0
  2. package/dist/compile.cjs +23 -0
  3. package/dist/compile.js +23 -0
  4. package/dist/deciders.cjs +15 -15
  5. package/dist/deciders.js +40 -40
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +80 -10
  8. package/dist/index.d.ts +80 -10
  9. package/dist/index.js +1 -1
  10. package/dist/parallel-worker.cjs +1 -1
  11. package/dist/parallel-worker.js +1 -1
  12. package/dist/prove-worker.cjs +1 -1
  13. package/dist/prove-worker.js +1 -1
  14. package/dist/prove.cjs +116 -36
  15. package/dist/prove.js +116 -36
  16. package/dist/run.cjs +143 -31
  17. package/dist/run.js +143 -31
  18. package/dist/tlapm.cjs +2 -2
  19. package/dist/tlapm.js +1 -1
  20. package/dist/transfer.cjs +128 -103
  21. package/dist/transfer.js +128 -103
  22. package/dist/worker.cjs +7 -7
  23. package/dist/worker.js +7 -7
  24. package/package.json +3 -1
  25. package/src/ast.ts +7 -21
  26. package/src/bags.ts +99 -99
  27. package/src/builtins.ts +44 -75
  28. package/src/bundled-modules.ts +1 -8
  29. package/src/check.ts +605 -311
  30. package/src/cli/options.ts +12 -3
  31. package/src/cli/run.ts +2 -2
  32. package/src/cli/runtime-invariants.ts +135 -0
  33. package/src/cli/shared.ts +20 -9
  34. package/src/cli/tlc-arguments.ts +646 -0
  35. package/src/cli/tlc-usage.ts +362 -0
  36. package/src/cli/tlc.ts +571 -185
  37. package/src/cli/typescript.ts +26 -0
  38. package/src/cli/xml-exporter.ts +4 -10
  39. package/src/codegen.ts +190 -46
  40. package/src/config.ts +101 -68
  41. package/src/coverage.ts +855 -0
  42. package/src/dependencies.ts +20 -28
  43. package/src/dfid.ts +636 -0
  44. package/src/environment.ts +266 -98
  45. package/src/errors.ts +142 -45
  46. package/src/evaluate.ts +632 -298
  47. package/src/exit-codes.ts +37 -1
  48. package/src/index.ts +3 -0
  49. package/src/instances.ts +85 -9
  50. package/src/java-overrides.ts +2 -12
  51. package/src/json-reader.ts +456 -0
  52. package/src/json.ts +262 -139
  53. package/src/levels.ts +2 -3
  54. package/src/lexer.ts +17 -26
  55. package/src/liveness-checker.ts +10 -18
  56. package/src/liveness.ts +121 -49
  57. package/src/parallel-worker.ts +14 -10
  58. package/src/parallel.ts +41 -17
  59. package/src/parser.ts +436 -90
  60. package/src/pcal/ast.ts +7 -28
  61. package/src/pcal/parse.ts +11 -39
  62. package/src/pcal/tokenize.ts +4 -20
  63. package/src/pcal/translate.ts +10 -42
  64. package/src/pcal/validate.ts +3 -21
  65. package/src/pretty-print.ts +1 -2
  66. package/src/prover/smt/solver/solver.ts +31 -27
  67. package/src/randomization.ts +84 -35
  68. package/src/resolve.ts +18 -60
  69. package/src/runtime.ts +11 -4
  70. package/src/sany/builtins.ts +3 -4
  71. package/src/sany/generator.ts +128 -176
  72. package/src/sany/levels.ts +6 -30
  73. package/src/sany/lexer.ts +7 -23
  74. package/src/sany/linter.ts +31 -29
  75. package/src/sany/modules.ts +1 -5
  76. package/src/sany/nodes.ts +4 -28
  77. package/src/sany/parse-error.ts +44 -100
  78. package/src/sany/report.ts +25 -40
  79. package/src/sany/selectors.ts +8 -22
  80. package/src/sany/source.ts +8 -15
  81. package/src/sany/xml.ts +11 -42
  82. package/src/search.ts +547 -144
  83. package/src/simulate.ts +694 -0
  84. package/src/spec-description.ts +166 -48
  85. package/src/standard-definitions.ts +2 -3
  86. package/src/standard-modules.ts +264 -68
  87. package/src/state-graph.ts +51 -18
  88. package/src/subexpressions.ts +31 -5
  89. package/src/successors.ts +267 -77
  90. package/src/symmetry.ts +31 -8
  91. package/src/tableau.ts +1 -2
  92. package/src/tlc/fingerprint.ts +183 -61
  93. package/src/tlc/jar-data.ts +113 -6
  94. package/src/tlc/messages.ts +122 -37
  95. package/src/tlc/order.ts +33 -38
  96. package/src/tlc/random.ts +16 -16
  97. package/src/tlc/replay.ts +563 -211
  98. package/src/tlc/summary.ts +2 -4
  99. package/src/tlc/tlc-operators.ts +81 -36
  100. package/src/tlc/tlcext-operators.ts +138 -117
  101. package/src/tlc/trace-spec.ts +273 -0
  102. package/src/tlc/value-stream.ts +143 -0
  103. package/src/tlc/version.ts +2 -4
  104. package/src/typescript/actions.ts +494 -0
  105. package/src/typescript/collections.ts +615 -0
  106. package/src/typescript/compile.ts +70 -0
  107. package/src/typescript/context.ts +106 -0
  108. package/src/typescript/emit.ts +122 -0
  109. package/src/typescript/expressions.ts +508 -0
  110. package/src/typescript/formula.ts +160 -0
  111. package/src/typescript/functions.ts +295 -0
  112. package/src/typescript/model.ts +164 -0
  113. package/src/typescript/names.ts +116 -0
  114. package/src/typescript/program.ts +51 -0
  115. package/src/typescript/properties.ts +148 -0
  116. package/src/typescript/scope.ts +117 -0
  117. package/src/typescript/steps.ts +175 -0
  118. package/src/typescript/types.ts +178 -0
  119. package/src/values.ts +832 -255
package/src/parallel.ts CHANGED
@@ -25,15 +25,17 @@ import {
25
25
  reportStartup,
26
26
  } from "./search";
27
27
  import { getInitialStates } from "./successors";
28
+ import { setFingerprintPolynomial } from "./tlc/fingerprint";
28
29
  import { createTlcOrder } from "./tlc/order";
29
30
  import { getFingerprintDistance, OUT_DEGREE_BUCKETS } from "./tlc/summary";
30
31
  import { createStateEncoder, type EncodedStates } from "./transfer";
31
32
  import type { TlcVersion } from "./tlc/version";
32
33
  import {
33
34
  createCanonicalizer,
34
- getRankedStringCount,
35
+ freezeStringOrder,
36
+ getUnorderedString,
35
37
  setStringOrder,
36
- setValueVersion,
38
+ setValueOptions,
37
39
  type Value,
38
40
  } from "./values";
39
41
  import { spawnWorker, type Port } from "./worker";
@@ -48,15 +50,18 @@ export interface StartMessage {
48
50
  ports: (Port | undefined)[];
49
51
  seed: EncodedStates;
50
52
  isTool: boolean | undefined;
51
- isTraceRecorded: boolean | undefined;
53
+ traceFile: string | undefined;
52
54
  isWarningEnabled: boolean | undefined;
53
55
  version: TlcVersion | undefined;
56
+ fingerprintPolynomial: number | undefined;
57
+ maxSetSize: number | undefined;
58
+ isLazyValueExpanded: boolean | undefined;
54
59
  fingerprints: SharedFingerprints;
55
60
  requests: Int32Array;
56
61
  remaining: Int32Array;
57
62
  }
58
63
 
59
- export interface LevelMessage {
64
+ interface LevelMessage {
60
65
  type: "level";
61
66
  generated: number;
62
67
  added: number;
@@ -66,7 +71,7 @@ export interface LevelMessage {
66
71
 
67
72
  export type WorkerMessage =
68
73
  | { type: "ready" }
69
- | { type: "abort" }
74
+ | { type: "abort"; string?: string }
70
75
  | { type: "paused" }
71
76
  | LevelMessage;
72
77
 
@@ -81,7 +86,6 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
81
86
  : options.config;
82
87
  const print = options.onPrint ?? console.log;
83
88
  const printed = { count: 0 };
84
- // What each point the search reports is about, such as the invariant TLC warns about.
85
89
  const getKey = (progress: CheckProgress) =>
86
90
  [
87
91
  progress.kind,
@@ -96,7 +100,10 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
96
100
  };
97
101
  // The search on the calling thread prints and reports what this one did while it started, so it
98
102
  // skips that.
99
- const fallBack = () => {
103
+ const fallBack = (createdString?: string) => {
104
+ if (createdString !== undefined) {
105
+ options.onProgress?.({ kind: "sequential-fallback", string: createdString });
106
+ }
100
107
  const skipped = { count: printed.count };
101
108
  return checkSequentially({
102
109
  ...options,
@@ -108,15 +115,19 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
108
115
  });
109
116
  };
110
117
  const workerCount = options.workers ?? 1;
111
- // TLC's workers write the -dump state graph in whichever order they find it, so one worker
112
- // writes the graph a single TLC worker does.
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.
113
121
  const isSequential =
114
122
  workerCount < 2 ||
115
123
  typeof SharedArrayBuffer !== "function" ||
116
124
  options.dump !== undefined ||
125
+ options.coverage !== undefined ||
126
+ options.isContinued === true ||
117
127
  config.view !== undefined ||
118
128
  config.postconditions.length > 0 ||
119
- config.possible.length > 0;
129
+ config.possible.length > 0 ||
130
+ (options.moduleOperators?.length ?? 0) > 0;
120
131
  if (isSequential) return fallBack();
121
132
  const modules = new Map<string, string | undefined>();
122
133
  const loadModule = (name: string) => {
@@ -132,8 +143,9 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
132
143
  };
133
144
  const order = createTlcOrder(options.source, loadModule);
134
145
  setStringOrder(order.getStringOrder(config));
135
- setValueVersion(options.version);
136
- const startupStrings = getRankedStringCount();
146
+ setValueOptions(options);
147
+ setFingerprintPolynomial(options.fingerprintPolynomial ?? 0);
148
+ freezeStringOrder();
137
149
  const specification = createEnvironment(config, {
138
150
  source: options.source,
139
151
  loadModule,
@@ -143,9 +155,13 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
143
155
  printed.count++;
144
156
  print(text);
145
157
  },
146
- files: { readFile: options.readFile, writeFile: options.writeFile },
158
+ files: {
159
+ readFile: options.readFile,
160
+ writeFile: options.writeFile,
161
+ makeDirectory: options.makeDirectory,
162
+ },
147
163
  isTool: options.isTool,
148
- isTraceRecorded: options.isTraceRecorded,
164
+ traceFile: options.traceSpec?.traceFile,
149
165
  isSanyReported: options.isSanyReported,
150
166
  isWarningEnabled: options.isWarningEnabled,
151
167
  version: options.version,
@@ -155,6 +171,7 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
155
171
  const search = createSearch(
156
172
  config,
157
173
  environment,
174
+ specification.variableLocations,
158
175
  () => order.getDeclarationOrder("variable"),
159
176
  report,
160
177
  );
@@ -232,7 +249,8 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
232
249
  if (!(error instanceof TlaEvaluationError)) throw error;
233
250
  return fallBack();
234
251
  }
235
- if (getRankedStringCount() !== startupStrings) return fallBack();
252
+ const unorderedString = getUnorderedString();
253
+ if (unorderedString !== undefined) return fallBack(unorderedString);
236
254
  statistics.depth = statistics.generatedStates === 0 ? 0 : 1;
237
255
  statistics.initialStates = {
238
256
  generated: statistics.generatedStates,
@@ -289,9 +307,12 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
289
307
  ports,
290
308
  seed,
291
309
  isTool: options.isTool,
292
- isTraceRecorded: options.isTraceRecorded,
310
+ traceFile: options.traceSpec?.traceFile,
293
311
  isWarningEnabled: options.isWarningEnabled,
294
312
  version: options.version,
313
+ fingerprintPolynomial: options.fingerprintPolynomial,
314
+ maxSetSize: options.maxSetSize,
315
+ isLazyValueExpanded: options.isLazyValueExpanded,
295
316
  fingerprints: shared.fingerprints,
296
317
  requests,
297
318
  remaining,
@@ -324,7 +345,10 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
324
345
  const messages = await collectLevels(await reported);
325
346
  if (isAborted(messages)) {
326
347
  terminate();
327
- return fallBack();
348
+ const aborted = messages.find(
349
+ (message) => message.type === "abort" && message.string !== undefined,
350
+ );
351
+ return fallBack(aborted?.type === "abort" ? aborted.string : undefined);
328
352
  }
329
353
  const levels = messages.flatMap((message) => (message.type === "level" ? [message] : []));
330
354
  const added = levels.reduce((sum, message) => sum + message.added, 0);