tla-ts 0.0.2 → 0.0.3-dev.07eab97
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/README.md +78 -12
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +98 -15
- package/dist/index.d.ts +98 -15
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +2 -2
- package/dist/parallel-worker.js +2 -2
- package/dist/parallel.cjs +1 -1
- package/dist/parallel.js +2 -2
- package/dist/run-cli.cjs +23 -2
- package/dist/run-cli.js +23 -2
- package/dist/transfer.cjs +36 -16
- package/dist/transfer.js +36 -16
- package/package.json +3 -1
- package/src/ast.ts +139 -4
- package/src/builtins.ts +9 -3
- package/src/check.ts +555 -107
- package/src/cli-options.ts +64 -0
- package/src/codegen.ts +15 -22
- package/src/config.ts +224 -170
- package/src/dependencies.ts +2 -2
- package/src/environment.ts +156 -48
- package/src/errors.ts +123 -3
- package/src/evaluate.ts +258 -160
- package/src/exit-codes.ts +39 -42
- package/src/fingerprints.ts +48 -12
- package/src/instances.ts +16 -15
- package/src/levels.ts +181 -45
- package/src/lexer.ts +11 -2
- package/src/live-check.ts +772 -0
- package/src/liveness.ts +120 -543
- package/src/obligation-action.ts +384 -0
- package/src/obligation-anon.ts +575 -0
- package/src/obligation-deref.ts +637 -0
- package/src/obligation-expression.ts +1060 -0
- package/src/obligation-format.ts +406 -0
- package/src/obligation-generate.ts +1074 -0
- package/src/obligation-levels.ts +329 -0
- package/src/obligation-module.ts +1042 -0
- package/src/obligation-printer.ts +889 -0
- package/src/obligation-proof.ts +76 -0
- package/src/obligation-source.ts +1084 -0
- package/src/obligation-tuples.ts +184 -0
- package/src/obligations.ts +316 -0
- package/src/parallel-worker.ts +168 -212
- package/src/parallel.ts +78 -37
- package/src/parser.ts +350 -63
- package/src/resolve.ts +124 -44
- package/src/run-cli.ts +405 -45
- package/src/runtime.ts +3 -1
- package/src/spec-description.ts +19 -8
- package/src/standard-levels.ts +3 -3
- package/src/standard-modules.ts +54 -45
- package/src/state-graph.ts +157 -0
- package/src/subexpressions.ts +10 -10
- package/src/substitution-levels.ts +38 -17
- package/src/successors.ts +183 -39
- package/src/symmetry.ts +30 -8
- package/src/tableau.ts +51 -24
- package/src/tlc-ext.ts +29 -12
- package/src/tlc-module.ts +14 -33
- package/src/tlc-modules.ts +4 -0
- package/src/tlc-order.ts +25 -7
- package/src/tlc-random.ts +9 -6
- package/src/tlc-summary.ts +20 -5
- package/src/transfer.ts +22 -1
- package/src/value-sources.ts +29 -0
- package/src/values.ts +300 -83
package/README.md
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
[](https://npmjs.com/package/tla-ts)
|
|
4
4
|
[](https://npmjs.com/package/tla-ts)
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
tla-ts is a drop-in replacement for [TLC](https://github.com/tlaplus/tlaplus) that's **2× faster**.
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
TLA+ lets you write formal models of a system, and TLC model checks them. But TLC is written in Java and needs the JVM. tla-ts runs anywhere JavaScript runs, such as the browser, Node, and Bun. Try it in the [playground](https://tla-ts.aidenybai.com).
|
|
9
9
|
|
|
10
10
|
```ts
|
|
11
11
|
import { check } from "tla-ts";
|
|
@@ -30,19 +30,66 @@ result.status; // "invariant-violation"
|
|
|
30
30
|
npm install tla-ts
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
##
|
|
33
|
+
## Command line
|
|
34
|
+
|
|
35
|
+
The `tla-ts` command takes TLC's options and prints TLC's output. `tla-ts prove` takes tlapm's options and prints tlapm's output.
|
|
36
|
+
|
|
37
|
+
### Check a spec
|
|
38
|
+
|
|
39
|
+
To check a spec, pass its path:
|
|
40
|
+
|
|
41
|
+
```shell
|
|
42
|
+
npx tla-ts Spec.tla
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
tla-ts reads the configuration from `Spec.cfg` next to the spec. It exits with the exit code TLC uses for the same result.
|
|
46
|
+
|
|
47
|
+
You can pass several paths, or a glob such as `"specs/*.tla"`. tla-ts checks each spec in turn and exits with the exit code of the first spec that fails. A glob skips each module that has no `.cfg` next to it, so it doesn't check helper modules that other specs import. tla-ts never skips a path that you pass by name. If you pass a `.cfg` path, tla-ts checks the `.tla` file with the same name.
|
|
48
|
+
|
|
49
|
+
The options are:
|
|
50
|
+
|
|
51
|
+
- `-config <Spec.cfg>`: read the configuration from this file. You can use it only when you check one spec.
|
|
52
|
+
- `-deadlock`: don't report deadlocks.
|
|
53
|
+
- `-dump [dot[,colorize][,actionlabels][,snapshot]] <file>`: write every reachable state to `<file>.dump`, or with `dot`, the state graph to `<file>.dot`. The output matches TLC run with `-fp 0`. tla-ts doesn't support the `constrained`, `stuttering`, or `strict` formats.
|
|
54
|
+
- `-lncheck final`: check liveness once, after the search ends.
|
|
55
|
+
- `-seed <num>`: seed `RandomElement` and the `Randomization` module. The default is 0.
|
|
56
|
+
- `-workers <count|auto>`: search with this number of worker threads. `auto` uses one thread per core. The default is 1.
|
|
57
|
+
|
|
58
|
+
TLC can replace a module's operators with Java methods, and tla-ts reads the same files. If the spec's directory has `Module.class`, tla-ts replaces each operator in `Module` with the public static method that has the same name and arity.
|
|
59
|
+
|
|
60
|
+
### Generate proof obligations
|
|
61
|
+
|
|
62
|
+
A proof obligation is one claim that a backend prover must prove. `tla-ts prove -N` prints the obligations of a module, as `tlapm -N` does. It doesn't run a prover. For example, this command prints every obligation in `Module.tla` with its text:
|
|
34
63
|
|
|
35
64
|
```shell
|
|
36
|
-
npx tla-ts
|
|
65
|
+
npx tla-ts prove -N --toolbox 0 0 --printallobs Module.tla
|
|
37
66
|
```
|
|
38
67
|
|
|
39
|
-
-
|
|
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.
|
|
68
|
+
With `--toolbox` or `--line`, tla-ts writes the messages of the TLA+ Toolbox protocol to stderr, as tlapm does. If you pass a tlapm option that isn't in this list, tla-ts prints an error:
|
|
44
69
|
|
|
45
|
-
|
|
70
|
+
- `--toolbox <start> <end>`: print Toolbox messages for the proofs from line `start` to line `end`. `0 0` selects the whole module.
|
|
71
|
+
- `--line <num>`: print Toolbox messages for the proof at this line.
|
|
72
|
+
- `--printallobs`: print the text of each obligation.
|
|
73
|
+
- `--summary`: print the number of obligations in each module, and list its missing and omitted proofs. You don't need `-N` with `--summary`.
|
|
74
|
+
- `--strict`: report missing proofs, omitted proofs and a selected range with no obligations as errors.
|
|
75
|
+
- `-I <directory>`: search this directory for modules.
|
|
76
|
+
|
|
77
|
+
tla-ts searches for modules in the same order as tlapm:
|
|
78
|
+
|
|
79
|
+
1. The directory of each module you pass, the last one first.
|
|
80
|
+
2. The current directory.
|
|
81
|
+
3. The standard library of tlapm, which has the `TLAPS` module. tla-ts searches it only if `tlapm` is on your `PATH`.
|
|
82
|
+
4. The `-I` directories, the last one first.
|
|
83
|
+
|
|
84
|
+
### Prove with tlapm
|
|
85
|
+
|
|
86
|
+
tla-ts doesn't include a prover. Without `-N` or `--summary`, `tla-ts prove` runs [tlapm](https://github.com/tlaplus/tlapm) from your `PATH`:
|
|
87
|
+
|
|
88
|
+
```shell
|
|
89
|
+
npx tla-ts prove Module.tla
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
tla-ts expands the globs and passes every argument to tlapm, so all of tlapm's options work. tlapm sends the obligations to its provers, and tla-ts exits with the exit code of tlapm. If `tlapm` isn't on your `PATH`, tla-ts prints an error and exits with code 1.
|
|
46
93
|
|
|
47
94
|
## API reference
|
|
48
95
|
|
|
@@ -69,9 +116,12 @@ const result = await check({
|
|
|
69
116
|
| `loadClass` | Returns a compiled Java class that overrides a module's operators with constants |
|
|
70
117
|
| `onPrint` | Receives the output of `Print` and `PrintT`. Defaults to `console.log` |
|
|
71
118
|
| `onPause` | Runs when `TLCSet("pause", TRUE)` pauses checking, which resumes when it returns |
|
|
72
|
-
| `readFile`, `writeFile` | Read and write files for the Json module
|
|
119
|
+
| `readFile`, `writeFile` | Read and write files for the Json module and `dump` |
|
|
73
120
|
| `seed` | A `bigint` seed. Defaults to `0n`, and matches TLC run with the same `-seed` and `-fp 0` |
|
|
74
121
|
| `workers` | The number of worker threads. Defaults to 1 |
|
|
122
|
+
| `dump` | Writes the reachable states or the state graph, as TLC's `-dump` does |
|
|
123
|
+
|
|
124
|
+
`dump` takes the `path` that `check` passes to `writeFile` before it returns. Set `dot` to write the state graph in the DOT language of Graphviz, and `colorize`, `actionLabels`, or `snapshot` for TLC's formats of the same names. A dump checks the spec on the calling thread, as one TLC worker does.
|
|
75
125
|
|
|
76
126
|
The result has these fields:
|
|
77
127
|
|
|
@@ -80,7 +130,14 @@ The result has these fields:
|
|
|
80
130
|
- `failure`: the message and trace when `status` is `"error"`.
|
|
81
131
|
- `generatedStates`, `distinctStates`, and `depth`: TLC's state counts.
|
|
82
132
|
|
|
83
|
-
Workers run in Node, Bun, Deno, and the browser,
|
|
133
|
+
Workers run in Node, Bun, Deno, and cross-origin isolated pages in the browser. Like TLC's workers, they share one table of 64-bit fingerprints. `check` runs on the calling thread in these cases:
|
|
134
|
+
|
|
135
|
+
- `SharedArrayBuffer` is unavailable, as on a page without cross-origin isolation.
|
|
136
|
+
- The spec has liveness properties.
|
|
137
|
+
- The spec uses impure operators such as `Print`.
|
|
138
|
+
- The configuration has `VIEW`, `POSTCONDITION`, or `_POSSIBLE`.
|
|
139
|
+
|
|
140
|
+
After a violation or an error, `check` reruns on the calling thread to return TLC's exact trace.
|
|
84
141
|
|
|
85
142
|
`check` supports:
|
|
86
143
|
|
|
@@ -144,6 +201,15 @@ Wall time on one worker, including JVM and Node startup. Both checkers report th
|
|
|
144
201
|
| [Bounded queue](packages/tla-ts/benchmarks/queue) | 44,044 | 0.37 s | 0.17 s | 2.2× |
|
|
145
202
|
| 542 conformance models | | 986.6 s | 403.3 s | 2.4× |
|
|
146
203
|
|
|
204
|
+
Wall time on 8 workers, also including startup. Each time is the median of 3 runs on an Apple M4 Pro.
|
|
205
|
+
|
|
206
|
+
| Spec | Distinct states | TLC | tla-ts | Speedup |
|
|
207
|
+
| --------------------------------------------------------------------------------------------------------------------- | --------------: | ------: | -----: | ------: |
|
|
208
|
+
| [Raft with reconfiguration](https://github.com/will62794/tla-web/blob/8193eb0/specs/RaftWithReconfigSingleServer.tla) | 298,493 | 10.50 s | 8.96 s | 1.2× |
|
|
209
|
+
| [Sailfish](https://github.com/tlaplus/Examples/tree/0cab2b3/specifications/dag-consensus) | 109,604 | 4.34 s | 4.07 s | 1.1× |
|
|
210
|
+
| [Fast Paxos](https://github.com/tlaplus/Examples/tree/0cab2b3/specifications/SimplifiedFastPaxos) | 25,617 | 3.91 s | 2.57 s | 1.5× |
|
|
211
|
+
| [Buffered random access file](https://github.com/tlaplus/Examples/tree/0cab2b3/specifications/braf) | 3,316 | 4.70 s | 3.61 s | 1.3× |
|
|
212
|
+
|
|
147
213
|
## Development
|
|
148
214
|
|
|
149
215
|
```shell
|
package/dist/index.cjs
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
* This source code is licensed under the MIT license found in the
|
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
|
8
8
|
*/
|
|
9
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./transfer.cjs"),t=require("./parallel.cjs");exports.TlaConfigError=e.
|
|
9
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./transfer.cjs"),t=require("./parallel.cjs");exports.TlaConfigError=e.M,exports.TlaError=e.N,exports.TlaEvaluationError=e.P,exports.TlaSyntaxError=e.I,exports.TlaUnsupportedError=e.L,exports.check=t.t,exports.formatValue=e.D,exports.parseConfig=e.A,exports.parseModule=e.b;
|
package/dist/index.d.cts
CHANGED
|
@@ -45,6 +45,8 @@ interface ApplyExpression {
|
|
|
45
45
|
kind: "Apply";
|
|
46
46
|
operator: string;
|
|
47
47
|
args: Expression[];
|
|
48
|
+
argumentCounts?: number[];
|
|
49
|
+
argumentsRange?: SourceRange;
|
|
48
50
|
location: SourceLocation;
|
|
49
51
|
resolution?: LocalResolution;
|
|
50
52
|
}
|
|
@@ -62,6 +64,7 @@ interface LambdaExpression {
|
|
|
62
64
|
interface JunctionExpression {
|
|
63
65
|
kind: "And" | "Or";
|
|
64
66
|
operands: Expression[];
|
|
67
|
+
isBulleted?: boolean;
|
|
65
68
|
location: SourceLocation;
|
|
66
69
|
}
|
|
67
70
|
interface PrimeExpression {
|
|
@@ -122,6 +125,7 @@ interface QuantifierExpression {
|
|
|
122
125
|
}
|
|
123
126
|
interface UnboundedQuantifierExpression {
|
|
124
127
|
kind: "UnboundedQuantifier";
|
|
128
|
+
quantifier: "Forall" | "Exists";
|
|
125
129
|
names: string[];
|
|
126
130
|
isTemporal?: boolean;
|
|
127
131
|
body: Expression;
|
|
@@ -172,6 +176,7 @@ interface FunctionSetExpression {
|
|
|
172
176
|
interface RecordField {
|
|
173
177
|
name: string;
|
|
174
178
|
value: Expression;
|
|
179
|
+
location: SourceLocation;
|
|
175
180
|
}
|
|
176
181
|
interface RecordExpression {
|
|
177
182
|
kind: "Record" | "RecordSet";
|
|
@@ -265,6 +270,7 @@ type Expression = NumberExpression | DecimalExpression | StringExpression | Iden
|
|
|
265
270
|
interface OperatorParam {
|
|
266
271
|
name: string;
|
|
267
272
|
arity: number;
|
|
273
|
+
location?: SourceLocation;
|
|
268
274
|
}
|
|
269
275
|
interface OperatorDefinition {
|
|
270
276
|
kind: "Operator";
|
|
@@ -309,6 +315,8 @@ interface Instance {
|
|
|
309
315
|
substitutions: InstanceSubstitution[];
|
|
310
316
|
isLocal: boolean;
|
|
311
317
|
location: SourceLocation;
|
|
318
|
+
instanceRange: SourceRange;
|
|
319
|
+
definitionRange?: SourceRange;
|
|
312
320
|
}
|
|
313
321
|
interface NewSymbol {
|
|
314
322
|
kind: "NewSymbol";
|
|
@@ -334,16 +342,19 @@ interface UseOrHide {
|
|
|
334
342
|
isOnly: boolean;
|
|
335
343
|
facts: Fact[];
|
|
336
344
|
defs: Fact[];
|
|
345
|
+
keyword: SourceRange;
|
|
337
346
|
location: SourceLocation;
|
|
338
347
|
}
|
|
339
348
|
type Proof = {
|
|
340
349
|
kind: "Obvious" | "Omitted";
|
|
350
|
+
keyword: SourceRange;
|
|
341
351
|
location: SourceLocation;
|
|
342
352
|
} | {
|
|
343
353
|
kind: "By";
|
|
344
354
|
isOnly: boolean;
|
|
345
355
|
facts: Fact[];
|
|
346
356
|
defs: Fact[];
|
|
357
|
+
keyword: SourceRange;
|
|
347
358
|
location: SourceLocation;
|
|
348
359
|
} | {
|
|
349
360
|
kind: "Steps";
|
|
@@ -383,7 +394,10 @@ type StepBody = UseOrHide | Instance | DefineStep | {
|
|
|
383
394
|
};
|
|
384
395
|
interface ProofStep {
|
|
385
396
|
name: string | undefined;
|
|
397
|
+
token: string;
|
|
386
398
|
body: StepBody;
|
|
399
|
+
head: SourceRange;
|
|
400
|
+
statement: SourceRange;
|
|
387
401
|
proof: Proof | undefined;
|
|
388
402
|
location: SourceLocation;
|
|
389
403
|
}
|
|
@@ -393,10 +407,39 @@ interface Theorem {
|
|
|
393
407
|
proof: Proof | undefined;
|
|
394
408
|
location: SourceLocation;
|
|
395
409
|
}
|
|
410
|
+
type ModuleUnit = {
|
|
411
|
+
kind: "Constants";
|
|
412
|
+
declarations: Declaration[];
|
|
413
|
+
} | {
|
|
414
|
+
kind: "Variables";
|
|
415
|
+
declarations: Declaration[];
|
|
416
|
+
} | {
|
|
417
|
+
kind: "Recursive";
|
|
418
|
+
declarations: Declaration[];
|
|
419
|
+
} | {
|
|
420
|
+
kind: "Definition";
|
|
421
|
+
definition: Definition;
|
|
422
|
+
} | {
|
|
423
|
+
kind: "Instance";
|
|
424
|
+
instance: Instance;
|
|
425
|
+
} | {
|
|
426
|
+
kind: "Assumption";
|
|
427
|
+
assumption: Assumption;
|
|
428
|
+
} | {
|
|
429
|
+
kind: "Theorem";
|
|
430
|
+
theorem: Theorem;
|
|
431
|
+
} | {
|
|
432
|
+
kind: "Use";
|
|
433
|
+
use: UseOrHide;
|
|
434
|
+
} | {
|
|
435
|
+
kind: "Module";
|
|
436
|
+
module: Module;
|
|
437
|
+
};
|
|
396
438
|
interface Module {
|
|
397
439
|
name: string;
|
|
398
440
|
modules: Module[];
|
|
399
441
|
extends: string[];
|
|
442
|
+
extendsRanges: SourceRange[];
|
|
400
443
|
constants: Declaration[];
|
|
401
444
|
variables: Declaration[];
|
|
402
445
|
definitions: Definition[];
|
|
@@ -405,6 +448,7 @@ interface Module {
|
|
|
405
448
|
location: SourceLocation;
|
|
406
449
|
theorems: Theorem[];
|
|
407
450
|
uses: UseOrHide[];
|
|
451
|
+
units: ModuleUnit[];
|
|
408
452
|
}
|
|
409
453
|
type ConfigValue = {
|
|
410
454
|
kind: "Number";
|
|
@@ -453,24 +497,11 @@ interface ModelConfig {
|
|
|
453
497
|
rlReward: string | undefined;
|
|
454
498
|
}
|
|
455
499
|
export declare const parseConfig: (source: string) => ModelConfig;
|
|
456
|
-
export declare class TlaError extends Error {
|
|
457
|
-
constructor(message: string, cause?: unknown);
|
|
458
|
-
}
|
|
459
|
-
export declare class TlaSyntaxError extends TlaError {
|
|
460
|
-
constructor(message: string, cause?: unknown);
|
|
461
|
-
}
|
|
462
|
-
export declare class TlaConfigError extends TlaError {
|
|
463
|
-
constructor(message: string, cause?: unknown);
|
|
464
|
-
}
|
|
465
|
-
export declare class TlaEvaluationError extends TlaError {
|
|
466
|
-
constructor(message: string, cause?: unknown);
|
|
467
|
-
}
|
|
468
|
-
export declare class TlaUnsupportedError extends TlaError {
|
|
469
|
-
constructor(message: string, cause?: unknown);
|
|
470
|
-
}
|
|
471
500
|
interface ModelValue {
|
|
472
501
|
kind: "ModelValue";
|
|
473
502
|
name: string;
|
|
503
|
+
type: string | undefined;
|
|
504
|
+
rank: number;
|
|
474
505
|
}
|
|
475
506
|
interface SetValue {
|
|
476
507
|
kind: "Set";
|
|
@@ -552,6 +583,44 @@ interface LazyFunctionValue {
|
|
|
552
583
|
}
|
|
553
584
|
type Value = boolean | number | string | ModelValue | SetValue | MixedSetValue | FunctionValue | IntervalValue | InfiniteSetValue | SubsetValue | FunctionSetValue | RecordSetValue | ProductSetValue | SequenceSetValue | SetOperationValue | FilteredSetValue | UnionValue | LazyFunctionValue;
|
|
554
585
|
export declare const formatValue: (value: Value, isStrict?: boolean, isNormalized?: boolean) => string;
|
|
586
|
+
export declare class TlaError extends Error {
|
|
587
|
+
constructor(message: string, cause?: unknown);
|
|
588
|
+
}
|
|
589
|
+
interface SyntaxFailure {
|
|
590
|
+
reason: string;
|
|
591
|
+
line: number;
|
|
592
|
+
column: number;
|
|
593
|
+
isEnd: boolean;
|
|
594
|
+
}
|
|
595
|
+
interface SanyError {
|
|
596
|
+
location: string;
|
|
597
|
+
message: string;
|
|
598
|
+
}
|
|
599
|
+
interface SanyReport {
|
|
600
|
+
errors: SanyError[];
|
|
601
|
+
isFatal: boolean;
|
|
602
|
+
}
|
|
603
|
+
export declare class TlaSyntaxError extends TlaError {
|
|
604
|
+
failure: SyntaxFailure | undefined;
|
|
605
|
+
sany: SanyReport | undefined;
|
|
606
|
+
constructor(message: string, cause?: unknown, failure?: SyntaxFailure, sany?: SanyReport);
|
|
607
|
+
}
|
|
608
|
+
export declare class TlaConfigError extends TlaError {
|
|
609
|
+
constructor(message: string, cause?: unknown);
|
|
610
|
+
}
|
|
611
|
+
export declare class TlaEvaluationError extends TlaError {
|
|
612
|
+
constructor(message: string, cause?: unknown);
|
|
613
|
+
}
|
|
614
|
+
export declare class TlaUnsupportedError extends TlaError {
|
|
615
|
+
constructor(message: string, cause?: unknown);
|
|
616
|
+
}
|
|
617
|
+
interface StateDump {
|
|
618
|
+
path: string;
|
|
619
|
+
dot?: boolean;
|
|
620
|
+
colorize?: boolean;
|
|
621
|
+
actionLabels?: boolean;
|
|
622
|
+
snapshot?: boolean;
|
|
623
|
+
}
|
|
555
624
|
interface CheckOptions {
|
|
556
625
|
source: string;
|
|
557
626
|
config: string | ModelConfig;
|
|
@@ -564,6 +633,7 @@ interface CheckOptions {
|
|
|
564
633
|
seed?: bigint;
|
|
565
634
|
workers?: number;
|
|
566
635
|
livenessCheck?: "default" | "final";
|
|
636
|
+
dump?: StateDump;
|
|
567
637
|
}
|
|
568
638
|
type CheckStatus = "success" | "assumption-violation" | "invariant-violation" | "property-violation" | "liveness-violation" | "postcondition-violation" | "deadlock" | "error";
|
|
569
639
|
interface TraceStep {
|
|
@@ -573,6 +643,7 @@ interface TraceStep {
|
|
|
573
643
|
}
|
|
574
644
|
interface Violation {
|
|
575
645
|
name: string;
|
|
646
|
+
properties?: string[];
|
|
576
647
|
trace: TraceStep[];
|
|
577
648
|
loopStart: number | undefined;
|
|
578
649
|
loopLabel?: string;
|
|
@@ -590,6 +661,18 @@ interface EvaluationFailure {
|
|
|
590
661
|
trace: TraceStep[];
|
|
591
662
|
initialState: Record<string, Value> | undefined;
|
|
592
663
|
exitCode: number;
|
|
664
|
+
replay?: Replay;
|
|
665
|
+
isWithoutStatistics?: boolean;
|
|
666
|
+
}
|
|
667
|
+
interface Replay {
|
|
668
|
+
output: string[];
|
|
669
|
+
callStack: string[] | undefined;
|
|
670
|
+
fingerprint?: Fingerprint;
|
|
671
|
+
isBeforeError?: boolean;
|
|
672
|
+
}
|
|
673
|
+
interface Fingerprint {
|
|
674
|
+
sources: string[];
|
|
675
|
+
reason: string;
|
|
593
676
|
}
|
|
594
677
|
interface CheckResult {
|
|
595
678
|
status: CheckStatus;
|
package/dist/index.d.ts
CHANGED
|
@@ -45,6 +45,8 @@ interface ApplyExpression {
|
|
|
45
45
|
kind: "Apply";
|
|
46
46
|
operator: string;
|
|
47
47
|
args: Expression[];
|
|
48
|
+
argumentCounts?: number[];
|
|
49
|
+
argumentsRange?: SourceRange;
|
|
48
50
|
location: SourceLocation;
|
|
49
51
|
resolution?: LocalResolution;
|
|
50
52
|
}
|
|
@@ -62,6 +64,7 @@ interface LambdaExpression {
|
|
|
62
64
|
interface JunctionExpression {
|
|
63
65
|
kind: "And" | "Or";
|
|
64
66
|
operands: Expression[];
|
|
67
|
+
isBulleted?: boolean;
|
|
65
68
|
location: SourceLocation;
|
|
66
69
|
}
|
|
67
70
|
interface PrimeExpression {
|
|
@@ -122,6 +125,7 @@ interface QuantifierExpression {
|
|
|
122
125
|
}
|
|
123
126
|
interface UnboundedQuantifierExpression {
|
|
124
127
|
kind: "UnboundedQuantifier";
|
|
128
|
+
quantifier: "Forall" | "Exists";
|
|
125
129
|
names: string[];
|
|
126
130
|
isTemporal?: boolean;
|
|
127
131
|
body: Expression;
|
|
@@ -172,6 +176,7 @@ interface FunctionSetExpression {
|
|
|
172
176
|
interface RecordField {
|
|
173
177
|
name: string;
|
|
174
178
|
value: Expression;
|
|
179
|
+
location: SourceLocation;
|
|
175
180
|
}
|
|
176
181
|
interface RecordExpression {
|
|
177
182
|
kind: "Record" | "RecordSet";
|
|
@@ -265,6 +270,7 @@ type Expression = NumberExpression | DecimalExpression | StringExpression | Iden
|
|
|
265
270
|
interface OperatorParam {
|
|
266
271
|
name: string;
|
|
267
272
|
arity: number;
|
|
273
|
+
location?: SourceLocation;
|
|
268
274
|
}
|
|
269
275
|
interface OperatorDefinition {
|
|
270
276
|
kind: "Operator";
|
|
@@ -309,6 +315,8 @@ interface Instance {
|
|
|
309
315
|
substitutions: InstanceSubstitution[];
|
|
310
316
|
isLocal: boolean;
|
|
311
317
|
location: SourceLocation;
|
|
318
|
+
instanceRange: SourceRange;
|
|
319
|
+
definitionRange?: SourceRange;
|
|
312
320
|
}
|
|
313
321
|
interface NewSymbol {
|
|
314
322
|
kind: "NewSymbol";
|
|
@@ -334,16 +342,19 @@ interface UseOrHide {
|
|
|
334
342
|
isOnly: boolean;
|
|
335
343
|
facts: Fact[];
|
|
336
344
|
defs: Fact[];
|
|
345
|
+
keyword: SourceRange;
|
|
337
346
|
location: SourceLocation;
|
|
338
347
|
}
|
|
339
348
|
type Proof = {
|
|
340
349
|
kind: "Obvious" | "Omitted";
|
|
350
|
+
keyword: SourceRange;
|
|
341
351
|
location: SourceLocation;
|
|
342
352
|
} | {
|
|
343
353
|
kind: "By";
|
|
344
354
|
isOnly: boolean;
|
|
345
355
|
facts: Fact[];
|
|
346
356
|
defs: Fact[];
|
|
357
|
+
keyword: SourceRange;
|
|
347
358
|
location: SourceLocation;
|
|
348
359
|
} | {
|
|
349
360
|
kind: "Steps";
|
|
@@ -383,7 +394,10 @@ type StepBody = UseOrHide | Instance | DefineStep | {
|
|
|
383
394
|
};
|
|
384
395
|
interface ProofStep {
|
|
385
396
|
name: string | undefined;
|
|
397
|
+
token: string;
|
|
386
398
|
body: StepBody;
|
|
399
|
+
head: SourceRange;
|
|
400
|
+
statement: SourceRange;
|
|
387
401
|
proof: Proof | undefined;
|
|
388
402
|
location: SourceLocation;
|
|
389
403
|
}
|
|
@@ -393,10 +407,39 @@ interface Theorem {
|
|
|
393
407
|
proof: Proof | undefined;
|
|
394
408
|
location: SourceLocation;
|
|
395
409
|
}
|
|
410
|
+
type ModuleUnit = {
|
|
411
|
+
kind: "Constants";
|
|
412
|
+
declarations: Declaration[];
|
|
413
|
+
} | {
|
|
414
|
+
kind: "Variables";
|
|
415
|
+
declarations: Declaration[];
|
|
416
|
+
} | {
|
|
417
|
+
kind: "Recursive";
|
|
418
|
+
declarations: Declaration[];
|
|
419
|
+
} | {
|
|
420
|
+
kind: "Definition";
|
|
421
|
+
definition: Definition;
|
|
422
|
+
} | {
|
|
423
|
+
kind: "Instance";
|
|
424
|
+
instance: Instance;
|
|
425
|
+
} | {
|
|
426
|
+
kind: "Assumption";
|
|
427
|
+
assumption: Assumption;
|
|
428
|
+
} | {
|
|
429
|
+
kind: "Theorem";
|
|
430
|
+
theorem: Theorem;
|
|
431
|
+
} | {
|
|
432
|
+
kind: "Use";
|
|
433
|
+
use: UseOrHide;
|
|
434
|
+
} | {
|
|
435
|
+
kind: "Module";
|
|
436
|
+
module: Module;
|
|
437
|
+
};
|
|
396
438
|
interface Module {
|
|
397
439
|
name: string;
|
|
398
440
|
modules: Module[];
|
|
399
441
|
extends: string[];
|
|
442
|
+
extendsRanges: SourceRange[];
|
|
400
443
|
constants: Declaration[];
|
|
401
444
|
variables: Declaration[];
|
|
402
445
|
definitions: Definition[];
|
|
@@ -405,6 +448,7 @@ interface Module {
|
|
|
405
448
|
location: SourceLocation;
|
|
406
449
|
theorems: Theorem[];
|
|
407
450
|
uses: UseOrHide[];
|
|
451
|
+
units: ModuleUnit[];
|
|
408
452
|
}
|
|
409
453
|
type ConfigValue = {
|
|
410
454
|
kind: "Number";
|
|
@@ -453,24 +497,11 @@ interface ModelConfig {
|
|
|
453
497
|
rlReward: string | undefined;
|
|
454
498
|
}
|
|
455
499
|
export declare const parseConfig: (source: string) => ModelConfig;
|
|
456
|
-
export declare class TlaError extends Error {
|
|
457
|
-
constructor(message: string, cause?: unknown);
|
|
458
|
-
}
|
|
459
|
-
export declare class TlaSyntaxError extends TlaError {
|
|
460
|
-
constructor(message: string, cause?: unknown);
|
|
461
|
-
}
|
|
462
|
-
export declare class TlaConfigError extends TlaError {
|
|
463
|
-
constructor(message: string, cause?: unknown);
|
|
464
|
-
}
|
|
465
|
-
export declare class TlaEvaluationError extends TlaError {
|
|
466
|
-
constructor(message: string, cause?: unknown);
|
|
467
|
-
}
|
|
468
|
-
export declare class TlaUnsupportedError extends TlaError {
|
|
469
|
-
constructor(message: string, cause?: unknown);
|
|
470
|
-
}
|
|
471
500
|
interface ModelValue {
|
|
472
501
|
kind: "ModelValue";
|
|
473
502
|
name: string;
|
|
503
|
+
type: string | undefined;
|
|
504
|
+
rank: number;
|
|
474
505
|
}
|
|
475
506
|
interface SetValue {
|
|
476
507
|
kind: "Set";
|
|
@@ -552,6 +583,44 @@ interface LazyFunctionValue {
|
|
|
552
583
|
}
|
|
553
584
|
type Value = boolean | number | string | ModelValue | SetValue | MixedSetValue | FunctionValue | IntervalValue | InfiniteSetValue | SubsetValue | FunctionSetValue | RecordSetValue | ProductSetValue | SequenceSetValue | SetOperationValue | FilteredSetValue | UnionValue | LazyFunctionValue;
|
|
554
585
|
export declare const formatValue: (value: Value, isStrict?: boolean, isNormalized?: boolean) => string;
|
|
586
|
+
export declare class TlaError extends Error {
|
|
587
|
+
constructor(message: string, cause?: unknown);
|
|
588
|
+
}
|
|
589
|
+
interface SyntaxFailure {
|
|
590
|
+
reason: string;
|
|
591
|
+
line: number;
|
|
592
|
+
column: number;
|
|
593
|
+
isEnd: boolean;
|
|
594
|
+
}
|
|
595
|
+
interface SanyError {
|
|
596
|
+
location: string;
|
|
597
|
+
message: string;
|
|
598
|
+
}
|
|
599
|
+
interface SanyReport {
|
|
600
|
+
errors: SanyError[];
|
|
601
|
+
isFatal: boolean;
|
|
602
|
+
}
|
|
603
|
+
export declare class TlaSyntaxError extends TlaError {
|
|
604
|
+
failure: SyntaxFailure | undefined;
|
|
605
|
+
sany: SanyReport | undefined;
|
|
606
|
+
constructor(message: string, cause?: unknown, failure?: SyntaxFailure, sany?: SanyReport);
|
|
607
|
+
}
|
|
608
|
+
export declare class TlaConfigError extends TlaError {
|
|
609
|
+
constructor(message: string, cause?: unknown);
|
|
610
|
+
}
|
|
611
|
+
export declare class TlaEvaluationError extends TlaError {
|
|
612
|
+
constructor(message: string, cause?: unknown);
|
|
613
|
+
}
|
|
614
|
+
export declare class TlaUnsupportedError extends TlaError {
|
|
615
|
+
constructor(message: string, cause?: unknown);
|
|
616
|
+
}
|
|
617
|
+
interface StateDump {
|
|
618
|
+
path: string;
|
|
619
|
+
dot?: boolean;
|
|
620
|
+
colorize?: boolean;
|
|
621
|
+
actionLabels?: boolean;
|
|
622
|
+
snapshot?: boolean;
|
|
623
|
+
}
|
|
555
624
|
interface CheckOptions {
|
|
556
625
|
source: string;
|
|
557
626
|
config: string | ModelConfig;
|
|
@@ -564,6 +633,7 @@ interface CheckOptions {
|
|
|
564
633
|
seed?: bigint;
|
|
565
634
|
workers?: number;
|
|
566
635
|
livenessCheck?: "default" | "final";
|
|
636
|
+
dump?: StateDump;
|
|
567
637
|
}
|
|
568
638
|
type CheckStatus = "success" | "assumption-violation" | "invariant-violation" | "property-violation" | "liveness-violation" | "postcondition-violation" | "deadlock" | "error";
|
|
569
639
|
interface TraceStep {
|
|
@@ -573,6 +643,7 @@ interface TraceStep {
|
|
|
573
643
|
}
|
|
574
644
|
interface Violation {
|
|
575
645
|
name: string;
|
|
646
|
+
properties?: string[];
|
|
576
647
|
trace: TraceStep[];
|
|
577
648
|
loopStart: number | undefined;
|
|
578
649
|
loopLabel?: string;
|
|
@@ -590,6 +661,18 @@ interface EvaluationFailure {
|
|
|
590
661
|
trace: TraceStep[];
|
|
591
662
|
initialState: Record<string, Value> | undefined;
|
|
592
663
|
exitCode: number;
|
|
664
|
+
replay?: Replay;
|
|
665
|
+
isWithoutStatistics?: boolean;
|
|
666
|
+
}
|
|
667
|
+
interface Replay {
|
|
668
|
+
output: string[];
|
|
669
|
+
callStack: string[] | undefined;
|
|
670
|
+
fingerprint?: Fingerprint;
|
|
671
|
+
isBeforeError?: boolean;
|
|
672
|
+
}
|
|
673
|
+
interface Fingerprint {
|
|
674
|
+
sources: string[];
|
|
675
|
+
reason: string;
|
|
593
676
|
}
|
|
594
677
|
interface CheckResult {
|
|
595
678
|
status: CheckStatus;
|
package/dist/index.js
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
* This source code is licensed under the MIT license found in the
|
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
|
8
8
|
*/
|
|
9
|
-
import{A as e,D as t,
|
|
9
|
+
import{A as e,D as t,I as n,L as r,M as i,N as a,P as o,b as s}from"./transfer.js";import{t as c}from"./parallel.js";export{i as TlaConfigError,a as TlaError,o as TlaEvaluationError,n as TlaSyntaxError,r as TlaUnsupportedError,c as check,t as formatValue,e as parseConfig,s as parseModule};
|
package/dist/parallel-worker.cjs
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* This source code is licensed under the MIT license found in the
|
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
|
8
8
|
*/
|
|
9
|
-
const e=require("./transfer.cjs"),t=
|
|
9
|
+
const e=require("./transfer.cjs"),t=async()=>typeof globalThis.postMessage==`function`?globalThis:(await import(
|
|
10
10
|
/* @vite-ignore */
|
|
11
11
|
/* webpackIgnore: true */
|
|
12
|
-
`node:worker_threads`)).parentPort,
|
|
12
|
+
`node:worker_threads`)).parentPort,n=(t,n)=>{let r=new Map(t.modules),i=e=>r.get(e),a=new Map(t.classes);e.k(e.y(t.source,t.config,i));let o=e.O(),s=e._(t.config,{source:t.source,loadModule:i,loadClass:e=>a.get(e),print:()=>{},files:{readFile:void 0,writeFile:void 0}}).environment,c=e.u(t.config,s,()=>e.v(t.source,i,`variable`)),l=c?.spec.next;if(!c||l===void 0)return n.postMessage({type:`abort`});let u=t.index,d=e.T(),f=e.t(s.variables.length),p={fingerprints:t.fingerprints},m=t.requests,h=t.remaining,g=c.isSymmetric?e.r():void 0,_=/* @__PURE__ */ new Int32Array(2),v={resume:()=>{},loot:e=>{}};t.ports.forEach(e=>{e?.addEventListener(`message`,e=>v.loot(e.data)),e?.start?.()});let y={states:f(t.seed).map(d)},b=(n,r)=>{let i=Atomics.load(m,u)-1,a=Math.floor((n.end-n.origin-1)/2),o=e.n(),s=n.states.slice(n.end-a,n.end),c=a>0&&s.every(o.encode);c&&(n.end-=a);let l=c?o.finish():e.n().finish();t.ports[i]?.postMessage(l,[l.words.buffer]),Atomics.store(m,u,r),Atomics.notify(m,u)},x=e=>{Atomics.store(h,u,0),Atomics.compareExchange(m,u,0,-1)!==0&&b(e,-1)},S=e=>{Atomics.store(h,u,e.end-e.origin),Atomics.store(m,u,0)},C=n=>{for(;n.origin<n.end;n.origin++){let r=n.states[n.origin];if(!n.successors&&(Atomics.load(m,u)>0&&b(n,0),Atomics.store(h,u,n.end-n.origin-1),n.successors=e.w(l,r,s,c.spec.scope),n.generated+=n.successors.length,n.successors.length===0&&t.config.checkDeadlock))return;let i=n.successors;for(;n.index<i.length;n.index++){if(e.s(p.fingerprints))return`paused`;let t=i[n.index];if(c.findViolatedActionProperty(r,t.state))return;if(!c.satisfiesActionConstraints(r,t.state)){if(c.findViolatedInvariant(t.state,r))return;continue}if(g&&(e.c(t.state,_),!g.insert(_[0],_[1])))continue;d(t.state);let a=c.getFingerprintState(t.state);if(e.c(a,_),e.o(p.fingerprints,_[0],_[1])){if(c.findViolatedInvariant(t.state,r))return;c.satisfiesConstraints(t.state,r)&&(n.next.push(t.state),n.fingerprintStates.push(a),n.added++)}}n.outDegrees[Math.min(n.added,31)]++,n.successors=void 0,n.index=0,n.added=0}return`done`},w=async e=>{let n=/* @__PURE__ */ new Set;for(;;){let r=t.ports.reduce((e,t,r)=>!t||n.has(r)||Atomics.load(h,r)<2?e:e===void 0||Atomics.load(h,r)>Atomics.load(h,e)?r:e,void 0);if(r===void 0)return!1;let i=Atomics.compareExchange(m,r,0,u+1);if(i===-1&&n.add(r),i>0&&Atomics.wait(m,r,i),i!==0)continue;let a=await new Promise(e=>v.loot=e);if(a.count===0)n.add(r);else return e.states=f(a).map(d),e.origin=0,e.end=e.states.length,S(e),!0}},T=e=>n.postMessage(e,e.type===`level`?[e.fingerprints.buffer]:[]),E=async t=>{let n={states:y.states,origin:0,end:y.states.length,successors:void 0,index:0,added:0,generated:0,outDegrees:Array.from({length:32},()=>0),next:[],fingerprintStates:[]};for(;;){let e=C(n);if(e===void 0)return;if(x(n),e===`paused`){let e=new Promise(e=>v.resume=e);T({type:`paused`}),await e,S(n)}else if(!await w(n))break}if(e.O()===o)return y.states=n.next,Atomics.store(h,u,y.states.length),{type:`level`,level:t,generated:n.generated,added:n.next.length,outDegrees:n.outDegrees,fingerprints:c.getStoredFingerprints(n.next,n.fingerprintStates)}},D=e=>{E(e).then(e=>T(e??{type:`abort`}),()=>T({type:`abort`}))};n.addEventListener(`message`,e=>{let t=e.data;t.type===`level`&&D(t.level),t.type===`resize`&&(p.fingerprints=t.fingerprints,v.resume())}),Atomics.store(h,u,y.states.length),T({type:`ready`})};t().then(e=>{let t=r=>{let i=r.data;if(i.type===`start`){e.removeEventListener?.(`message`,t);try{n(i,e)}catch{e.postMessage({type:`abort`})}}};e.addEventListener(`message`,t),e.start?.()});
|