tla-ts 0.0.0-stage → 0.0.2
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.
- package/LICENSE +21 -0
- package/README.md +172 -2
- package/dist/cli.cjs +10 -0
- package/dist/cli.d.cts +9 -0
- package/dist/cli.d.ts +9 -0
- package/dist/cli.js +10 -0
- package/dist/index.cjs +9 -0
- package/dist/index.d.cts +607 -0
- package/dist/index.d.ts +607 -0
- package/dist/index.js +9 -0
- package/dist/parallel-worker.cjs +12 -0
- package/dist/parallel-worker.d.cts +9 -0
- package/dist/parallel-worker.d.ts +9 -0
- package/dist/parallel-worker.js +12 -0
- package/dist/parallel.cjs +12 -0
- package/dist/parallel.js +12 -0
- package/dist/run-cli.cjs +10 -0
- package/dist/run-cli.js +10 -0
- package/dist/transfer.cjs +409 -0
- package/dist/transfer.js +409 -0
- package/package.json +75 -3
- package/src/ast.ts +448 -0
- package/src/bags.ts +275 -0
- package/src/builtins.ts +341 -0
- package/src/bundled-modules.ts +82 -0
- package/src/canonical.ts +39 -0
- package/src/check.ts +1378 -0
- package/src/cli.ts +6 -0
- package/src/codegen.ts +339 -0
- package/src/config.ts +337 -0
- package/src/dependencies.ts +51 -0
- package/src/environment.ts +928 -0
- package/src/errors.ts +56 -0
- package/src/evaluate.ts +1876 -0
- package/src/exit-codes.ts +75 -0
- package/src/fingerprints.ts +69 -0
- package/src/index.ts +22 -0
- package/src/instances.ts +744 -0
- package/src/java-overrides.ts +241 -0
- package/src/json.ts +215 -0
- package/src/levels.ts +850 -0
- package/src/lexer.ts +498 -0
- package/src/liveness.ts +1018 -0
- package/src/parallel-worker.ts +305 -0
- package/src/parallel.ts +278 -0
- package/src/parser.ts +1572 -0
- package/src/pretty-print.ts +259 -0
- package/src/randomization.ts +99 -0
- package/src/resolve.ts +793 -0
- package/src/run-cli.ts +210 -0
- package/src/runtime.ts +94 -0
- package/src/spec-description.ts +509 -0
- package/src/standard-levels.ts +105 -0
- package/src/standard-modules.ts +412 -0
- package/src/subexpressions.ts +449 -0
- package/src/substitution-levels.ts +184 -0
- package/src/successors.ts +1025 -0
- package/src/symmetry.ts +236 -0
- package/src/tableau.ts +626 -0
- package/src/tlc-ext.ts +334 -0
- package/src/tlc-module.ts +238 -0
- package/src/tlc-modules.ts +1022 -0
- package/src/tlc-order.ts +497 -0
- package/src/tlc-random.ts +411 -0
- package/src/tlc-summary.ts +109 -0
- package/src/transfer.ts +113 -0
- package/src/values.ts +2082 -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,173 @@
|
|
|
1
|
-
#
|
|
1
|
+
# tla-ts
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://npmjs.com/package/tla-ts)
|
|
4
|
+
[](https://npmjs.com/package/tla-ts)
|
|
5
|
+
|
|
6
|
+
A TLA+ model checker in TypeScript, **2× 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 = await 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 [-config Spec.cfg] [-deadlock] [-lncheck final] [-seed 0] [-workers auto]
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
- `-config`: the TLC configuration. Defaults to `Spec.cfg` next to the spec.
|
|
40
|
+
- `-deadlock`: turns off deadlock checking.
|
|
41
|
+
- `-lncheck final`: checks liveness once, after the search.
|
|
42
|
+
- `-seed`: seeds `RandomElement` and the Randomization module. Defaults to 0.
|
|
43
|
+
- `-workers`: the number of worker threads, or `auto` for one per core. Defaults to 1.
|
|
44
|
+
|
|
45
|
+
Output and exit codes match TLC's. The CLI loads a compiled Java class such as `Module.class` from the spec's directory as an override for that module.
|
|
46
|
+
|
|
47
|
+
## API reference
|
|
48
|
+
|
|
49
|
+
### `check`
|
|
50
|
+
|
|
51
|
+
Checks a spec against a TLC configuration and resolves to the result.
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { check } from "tla-ts";
|
|
55
|
+
|
|
56
|
+
const result = await check({
|
|
57
|
+
source: specSource,
|
|
58
|
+
config: configSource,
|
|
59
|
+
loadModule: (name) => modules[name],
|
|
60
|
+
onPrint: (text) => console.log(text),
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
| Option | Description |
|
|
65
|
+
| ----------------------- | ---------------------------------------------------------------------------------------- |
|
|
66
|
+
| `source` | The TLA+ module to check |
|
|
67
|
+
| `config` | A TLC configuration, as text or as the result of `parseConfig` |
|
|
68
|
+
| `loadModule` | Returns the source of a module that isn't a standard module |
|
|
69
|
+
| `loadClass` | Returns a compiled Java class that overrides a module's operators with constants |
|
|
70
|
+
| `onPrint` | Receives the output of `Print` and `PrintT`. Defaults to `console.log` |
|
|
71
|
+
| `onPause` | Runs when `TLCSet("pause", TRUE)` pauses checking, which resumes when it returns |
|
|
72
|
+
| `readFile`, `writeFile` | Read and write files for the Json module |
|
|
73
|
+
| `seed` | A `bigint` seed. Defaults to `0n`, and matches TLC run with the same `-seed` and `-fp 0` |
|
|
74
|
+
| `workers` | The number of worker threads. Defaults to 1 |
|
|
75
|
+
|
|
76
|
+
The result has these fields:
|
|
77
|
+
|
|
78
|
+
- `status`: `"success"`, `"deadlock"`, `"assumption-violation"`, `"invariant-violation"`, `"property-violation"`, `"liveness-violation"`, `"postcondition-violation"`, or `"error"`.
|
|
79
|
+
- `violation`: the `name` of what failed and the `trace` that reaches it. `loopStart` marks where a liveness counterexample loops back.
|
|
80
|
+
- `failure`: the message and trace when `status` is `"error"`.
|
|
81
|
+
- `generatedStates`, `distinctStates`, and `depth`: TLC's state counts.
|
|
82
|
+
|
|
83
|
+
Workers run in Node, Bun, Deno, and the browser, and deduplicate states by 64-bit fingerprint as TLC does. `check` runs on the calling thread for specs with liveness properties or impure operators such as `Print`. After a violation, it reruns there to return the exact trace.
|
|
84
|
+
|
|
85
|
+
`check` supports:
|
|
86
|
+
|
|
87
|
+
- **Modules**: the standard modules, TLCExt, Json, and Randomization, plus `EXTENDS`, `INSTANCE`, and `LAMBDA`.
|
|
88
|
+
- **Configuration**: `CONSTANTS`, `INIT`, `NEXT`, `SPECIFICATION`, invariants, properties, constraints, `SYMMETRY`, `VIEW`, `ALIAS`, `POSTCONDITION`, `CHECK_DEADLOCK`, and `_POSSIBLE`.
|
|
89
|
+
- **Properties**: invariants and every temporal formula TLC accepts, checked through TLC's tableau construction.
|
|
90
|
+
- **TLC semantics**: 32-bit integer overflow, `TLCGet` and `TLCSet`, subexpression references such as `Op!2`, and TLC's enumeration order for `CHOOSE` and quantifiers.
|
|
91
|
+
|
|
92
|
+
### `parseModule`
|
|
93
|
+
|
|
94
|
+
Parses a TLA+ module into its syntax tree. Throws `TlaSyntaxError` on invalid input.
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
import { parseModule } from "tla-ts";
|
|
98
|
+
|
|
99
|
+
const module = parseModule(specSource);
|
|
100
|
+
module.name; // "Counter"
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### `parseConfig`
|
|
104
|
+
|
|
105
|
+
Parses a TLC configuration file into a `ModelConfig`. Pass the result to `check` to change it before checking.
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
import { check, parseConfig } from "tla-ts";
|
|
109
|
+
|
|
110
|
+
const config = parseConfig(configSource);
|
|
111
|
+
config.checkDeadlock = false;
|
|
112
|
+
await check({ source: specSource, config });
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### `formatValue`
|
|
116
|
+
|
|
117
|
+
Prints a value in TLA+ syntax, as TLC prints it in traces.
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
import { formatValue } from "tla-ts";
|
|
121
|
+
|
|
122
|
+
result.violation?.trace.forEach((step) => {
|
|
123
|
+
Object.entries(step.state).forEach(([name, value]) => console.log(name, formatValue(value)));
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Errors
|
|
128
|
+
|
|
129
|
+
Every error extends `TlaError`:
|
|
130
|
+
|
|
131
|
+
- `TlaSyntaxError`: the module does not parse
|
|
132
|
+
- `TlaConfigError`: the configuration is invalid or refers to an unknown name
|
|
133
|
+
- `TlaEvaluationError`: evaluation failed, as when TLC reports an error
|
|
134
|
+
- `TlaUnsupportedError`: the spec uses a feature tla-ts does not support yet
|
|
135
|
+
|
|
136
|
+
## Benchmarks
|
|
137
|
+
|
|
138
|
+
Wall time on one worker, including JVM and Node startup. Both checkers report the same state counts on every model.
|
|
139
|
+
|
|
140
|
+
| Spec | Distinct states | TLC | tla-ts | Speedup |
|
|
141
|
+
| -------------------------------------------------------------- | --------------: | ------: | ------: | ------: |
|
|
142
|
+
| [Two-phase commit](packages/tla-ts/benchmarks/commit) | 282,251 | 4.32 s | 2.01 s | 2.2× |
|
|
143
|
+
| [Dining philosophers](packages/tla-ts/benchmarks/philosophers) | 128,889 | 1.06 s | 0.71 s | 1.5× |
|
|
144
|
+
| [Bounded queue](packages/tla-ts/benchmarks/queue) | 44,044 | 0.37 s | 0.17 s | 2.2× |
|
|
145
|
+
| 542 conformance models | | 986.6 s | 403.3 s | 2.4× |
|
|
146
|
+
|
|
147
|
+
## Development
|
|
148
|
+
|
|
149
|
+
```shell
|
|
150
|
+
pnpm install
|
|
151
|
+
pnpm test
|
|
152
|
+
pnpm dev
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
`pnpm dev` starts the playground in `packages/website`.
|
|
156
|
+
|
|
157
|
+
Run the conformance suite against TLC's recorded results:
|
|
158
|
+
|
|
159
|
+
```shell
|
|
160
|
+
pnpm --filter tla-ts conformance:fetch
|
|
161
|
+
pnpm --filter tla-ts conformance
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Rerun the benchmarks with `TLA2TOOLS_JAR` set to the path of `tla2tools.jar`:
|
|
165
|
+
|
|
166
|
+
```shell
|
|
167
|
+
pnpm --filter tla-ts bench
|
|
168
|
+
pnpm --filter tla-ts bench:corpus
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## License
|
|
172
|
+
|
|
173
|
+
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
package/dist/cli.d.ts
ADDED
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.D,exports.TlaError=e.O,exports.TlaEvaluationError=e.k,exports.TlaSyntaxError=e.A,exports.TlaUnsupportedError=e.j,exports.check=t.t,exports.formatValue=e.S,exports.parseConfig=e.E,exports.parseModule=e._;
|