tla-ts 0.0.0-stage → 0.0.1

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 (56) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +179 -2
  3. package/dist/cli.cjs +10 -0
  4. package/dist/cli.d.cts +9 -0
  5. package/dist/cli.d.ts +9 -0
  6. package/dist/cli.js +10 -0
  7. package/dist/index.cjs +9 -0
  8. package/dist/index.d.cts +471 -0
  9. package/dist/index.d.ts +471 -0
  10. package/dist/index.js +9 -0
  11. package/dist/parallel-worker.cjs +12 -0
  12. package/dist/parallel-worker.d.cts +9 -0
  13. package/dist/parallel-worker.d.ts +9 -0
  14. package/dist/parallel-worker.js +12 -0
  15. package/dist/parallel.cjs +12 -0
  16. package/dist/parallel.js +12 -0
  17. package/dist/run-cli.cjs +9 -0
  18. package/dist/run-cli.js +9 -0
  19. package/dist/transfer.cjs +60 -0
  20. package/dist/transfer.js +60 -0
  21. package/package.json +73 -3
  22. package/src/ast.ts +371 -0
  23. package/src/bags.ts +185 -0
  24. package/src/builtins.ts +161 -0
  25. package/src/bundled-modules.ts +51 -0
  26. package/src/canonical.ts +39 -0
  27. package/src/check.ts +704 -0
  28. package/src/cli.ts +6 -0
  29. package/src/codegen.ts +305 -0
  30. package/src/config.ts +309 -0
  31. package/src/dependencies.ts +51 -0
  32. package/src/environment.ts +583 -0
  33. package/src/errors.ts +34 -0
  34. package/src/evaluate.ts +1526 -0
  35. package/src/fingerprints.ts +69 -0
  36. package/src/index.ts +17 -0
  37. package/src/instances.ts +589 -0
  38. package/src/json.ts +134 -0
  39. package/src/lexer.ts +428 -0
  40. package/src/liveness.ts +1062 -0
  41. package/src/parallel-worker.ts +276 -0
  42. package/src/parallel.ts +224 -0
  43. package/src/parser.ts +1052 -0
  44. package/src/randomization.ts +188 -0
  45. package/src/resolve.ts +362 -0
  46. package/src/run-cli.ts +112 -0
  47. package/src/runtime.ts +59 -0
  48. package/src/standard-modules.ts +281 -0
  49. package/src/subexpressions.ts +463 -0
  50. package/src/successors.ts +810 -0
  51. package/src/symmetry.ts +192 -0
  52. package/src/tableau.ts +620 -0
  53. package/src/tlc-ext.ts +247 -0
  54. package/src/tlc-module.ts +214 -0
  55. package/src/transfer.ts +113 -0
  56. package/src/values.ts +1060 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Aiden Bai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,180 @@
1
- # Temporary Holding Version
1
+ # tla-ts
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![version](https://img.shields.io/npm/v/tla-ts?style=flat&colorA=000000&colorB=000000)](https://npmjs.com/package/tla-ts)
4
+ [![downloads](https://img.shields.io/npm/dt/tla-ts.svg?style=flat&colorA=000000&colorB=000000)](https://npmjs.com/package/tla-ts)
5
+
6
+ A TLA+ model checker in TypeScript, **2.4× faster than TLC**.
7
+
8
+ tla-ts checks TLA+ specs with the same verdicts, error traces, and state counts as TLC. It runs in Node and in the browser without a JVM. Try it in the [playground](https://tla-ts.aidenybai.com).
9
+
10
+ ```ts
11
+ import { check } from "tla-ts";
12
+
13
+ const result = check({
14
+ source: `---- MODULE Counter ----
15
+ EXTENDS Naturals
16
+ VARIABLE x
17
+ Init == x = 0
18
+ Next == x' = x + 1
19
+ Small == x < 3
20
+ ====`,
21
+ config: "INIT Init NEXT Next INVARIANT Small",
22
+ });
23
+
24
+ result.status; // "invariant-violation"
25
+ ```
26
+
27
+ ## Install
28
+
29
+ ```shell
30
+ npm install tla-ts
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ ```shell
36
+ npx tla-ts Spec.tla
37
+ npx tla-ts Spec.tla -config Other.cfg -deadlock
38
+ npx tla-ts Spec.tla -workers auto
39
+ ```
40
+
41
+ Without `-config`, tla-ts reads the `.cfg` file next to the spec. `-deadlock` turns off deadlock checking. `-workers` checks on several threads, one per core with `auto`. Output and exit codes follow TLC:
42
+
43
+ | Exit code | Meaning |
44
+ | --------: | ---------------------------- |
45
+ | 0 | No error found |
46
+ | 10 | An assumption is false |
47
+ | 11 | Deadlock |
48
+ | 12 | Invariant or property broken |
49
+ | 13 | Liveness violation |
50
+
51
+ ## API reference
52
+
53
+ ### `check`
54
+
55
+ Checks a spec against a TLC configuration and returns the result. It explores every reachable state breadth-first, as TLC does.
56
+
57
+ ```ts
58
+ import { check } from "tla-ts";
59
+
60
+ const result = check({
61
+ source: specSource,
62
+ config: configSource,
63
+ loadModule: (name) => modules[name],
64
+ onPrint: (text) => console.log(text),
65
+ });
66
+ ```
67
+
68
+ Options:
69
+
70
+ - `source`: the TLA+ module to check
71
+ - `config`: a TLC configuration, as source text or as the result of `parseConfig`
72
+ - `loadModule`: maps a module name to its source, for modules other than the standard modules
73
+ - `onPrint`: receives the output of `Print` and `PrintT`, which defaults to `console.log`
74
+ - `readFile` and `writeFile`: let the Json module read and write files. Without them, it has no file access
75
+
76
+ The result has `status`, `violation`, `generatedStates`, `distinctStates`, and `depth`. `status` is `"success"`, `"assumption-violation"`, `"invariant-violation"`, `"property-violation"`, `"liveness-violation"`, or `"deadlock"`. `violation` holds the name of what failed and the trace that reaches it. For a liveness violation, `violation.loopStart` is the trace index where the lasso loops back.
77
+
78
+ `check` supports:
79
+
80
+ - **Standard modules**: Naturals, Integers, Sequences, FiniteSets, TLC, Bags, Reals, RealTime, Toolbox, and the community modules TLCExt, Json, and Randomization
81
+ - **Modules**: `EXTENDS`, nested modules, and `INSTANCE` with `WITH` substitutions, `LAMBDA` substitutions for operator parameters, named instances, parameterized instances, and instances inside `LET`
82
+ - **Configuration**: `INIT`, `NEXT`, `SPECIFICATION`, `CONSTANTS`, `INVARIANTS`, `PROPERTIES`, `CONSTRAINTS`, `ACTION_CONSTRAINTS`, `SYMMETRY`, `VIEW`, `POSTCONDITION`, `CHECK_DEADLOCK`, and `_POSSIBLE` properties
83
+ - **Properties**: invariants, `[][A]_v`, and every temporal formula TLC accepts, checked through TLC's tableau construction under the fairness and temporal conjuncts of the specification
84
+ - **Subexpression references**: selectors such as `F(2)!3`, `Op!<<`, `Op!>>`, `Op!:`, `Op!@`, and `Op!(x)`, labels such as `Op!lab`, and names of `THEOREM` formulas
85
+ - **TLC semantics**: 32-bit integer overflow errors, `ENABLED`, `TLCGet` and `TLCSet` with TLC's counters and registers, and TLC's enumeration order for `CHOOSE` and quantifiers
86
+
87
+ ### `checkInParallel`
88
+
89
+ Checks a spec on several worker threads and resolves to the same result as `check`. It takes the options of `check` plus `workers`, and runs in Node, Bun, Deno, and the browser.
90
+
91
+ ```ts
92
+ import { checkInParallel } from "tla-ts";
93
+
94
+ const result = await checkInParallel({ source: specSource, config: configSource, workers: 4 });
95
+ ```
96
+
97
+ Workers deduplicate states by 64-bit fingerprint, as TLC does. When a run finds a violation, or the spec uses liveness properties or impure operators such as `Print`, `checkInParallel` falls back to `check` and returns its exact result and trace.
98
+
99
+ ### `parseModule`
100
+
101
+ Parses a TLA+ module into its syntax tree. Throws `TlaSyntaxError` on invalid input.
102
+
103
+ ```ts
104
+ import { parseModule } from "tla-ts";
105
+
106
+ const module = parseModule(specSource);
107
+ module.name; // "Counter"
108
+ ```
109
+
110
+ ### `parseConfig`
111
+
112
+ Parses a TLC configuration file into a `ModelConfig`. Pass the result to `check` to change it before checking.
113
+
114
+ ```ts
115
+ import { check, parseConfig } from "tla-ts";
116
+
117
+ const config = parseConfig(configSource);
118
+ config.checkDeadlock = false;
119
+ check({ source: specSource, config });
120
+ ```
121
+
122
+ ### `formatValue`
123
+
124
+ Prints a value in TLA+ syntax, as TLC prints it in traces.
125
+
126
+ ```ts
127
+ import { formatValue } from "tla-ts";
128
+
129
+ result.violation?.trace.forEach((step) => {
130
+ Object.entries(step.state).forEach(([name, value]) => console.log(name, formatValue(value)));
131
+ });
132
+ ```
133
+
134
+ ### Errors
135
+
136
+ Every error extends `TlaError`:
137
+
138
+ - `TlaSyntaxError`: the module does not parse
139
+ - `TlaConfigError`: the configuration is invalid or refers to an unknown name
140
+ - `TlaEvaluationError`: evaluation failed, as when TLC reports an error
141
+ - `TlaUnsupportedError`: the spec uses a feature tla-ts does not support yet
142
+
143
+ ## Benchmarks
144
+
145
+ Wall time on one worker, including JVM and Node startup. Both checkers report the same state counts on every model.
146
+
147
+ | Spec | Distinct states | TLC | tla-ts | Speedup |
148
+ | -------------------------------------------------------------- | --------------: | ------: | ------: | ------: |
149
+ | [Two-phase commit](packages/tla-ts/benchmarks/commit) | 282,251 | 4.32 s | 2.01 s | 2.2× |
150
+ | [Dining philosophers](packages/tla-ts/benchmarks/philosophers) | 128,889 | 1.06 s | 0.71 s | 1.5× |
151
+ | [Bounded queue](packages/tla-ts/benchmarks/queue) | 44,044 | 0.37 s | 0.17 s | 2.2× |
152
+ | 542 conformance models | | 986.6 s | 403.3 s | 2.4× |
153
+
154
+ ## Development
155
+
156
+ ```shell
157
+ pnpm install
158
+ pnpm test
159
+ pnpm dev
160
+ ```
161
+
162
+ `pnpm dev` starts the playground in `packages/website`.
163
+
164
+ Run the conformance suite against TLC's recorded results:
165
+
166
+ ```shell
167
+ pnpm --filter tla-ts conformance:fetch
168
+ pnpm --filter tla-ts conformance
169
+ ```
170
+
171
+ Rerun the benchmarks with `TLA2TOOLS_JAR` set to the path of `tla2tools.jar`:
172
+
173
+ ```shell
174
+ pnpm --filter tla-ts bench
175
+ pnpm --filter tla-ts bench:corpus
176
+ ```
177
+
178
+ ## License
179
+
180
+ MIT
package/dist/cli.cjs ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * @license tla-ts
4
+ *
5
+ * Copyright (c) Aiden Bai
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ require("node:module").enableCompileCache?.(),Promise.resolve().then(()=>require("./run-cli.cjs")).then(e=>e.runCli());
package/dist/cli.d.cts ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @license tla-ts
3
+ *
4
+ * Copyright (c) Aiden Bai
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ export {}
package/dist/cli.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @license tla-ts
3
+ *
4
+ * Copyright (c) Aiden Bai
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ export {}
package/dist/cli.js ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * @license tla-ts
4
+ *
5
+ * Copyright (c) Aiden Bai
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import{enableCompileCache as e}from"node:module";e?.(),import(`./run-cli.js`).then(e=>e.runCli());
package/dist/index.cjs ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @license tla-ts
3
+ *
4
+ * Copyright (c) Aiden Bai
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./transfer.cjs"),t=require("./parallel.cjs");exports.TlaConfigError=e.v,exports.TlaError=e.y,exports.TlaEvaluationError=e.b,exports.TlaSyntaxError=e.x,exports.TlaUnsupportedError=e.S,exports.check=e.o,exports.checkInParallel=t.t,exports.formatValue=e.g,exports.parseConfig=e._,exports.parseModule=e.d;