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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tla-ts",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3-dev.07eab97",
|
|
4
4
|
"description": "A TLA+ interpreter and model checker in TypeScript, 2× faster than TLC",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"formal verification",
|
|
@@ -71,6 +71,8 @@
|
|
|
71
71
|
"conformance:sany": "tsx scripts/proof-conformance.ts",
|
|
72
72
|
"conformance:record": "tsx scripts/record-tlc.ts",
|
|
73
73
|
"conformance:record-sany": "tsx scripts/record-sany.ts",
|
|
74
|
+
"conformance:record-tlapm": "tsx scripts/record-tlapm.ts",
|
|
75
|
+
"conformance:tlapm": "tsx scripts/tlapm-conformance.ts",
|
|
74
76
|
"publint": "publint",
|
|
75
77
|
"test": "vp test",
|
|
76
78
|
"typecheck": "tsc --noEmit"
|
package/src/ast.ts
CHANGED
|
@@ -44,6 +44,11 @@ export interface ApplyExpression {
|
|
|
44
44
|
kind: "Apply";
|
|
45
45
|
operator: string;
|
|
46
46
|
args: Expression[];
|
|
47
|
+
// The number of args each part of a name like F(x)!l(y) takes, when a part before the last takes
|
|
48
|
+
// some.
|
|
49
|
+
argumentCounts?: number[];
|
|
50
|
+
// The range of the parenthesized arguments of a named operator, where SANY reports their count.
|
|
51
|
+
argumentsRange?: SourceRange;
|
|
47
52
|
location: SourceLocation;
|
|
48
53
|
resolution?: LocalResolution;
|
|
49
54
|
}
|
|
@@ -64,6 +69,7 @@ export interface LambdaExpression {
|
|
|
64
69
|
export interface JunctionExpression {
|
|
65
70
|
kind: "And" | "Or";
|
|
66
71
|
operands: Expression[];
|
|
72
|
+
isBulleted?: boolean;
|
|
67
73
|
location: SourceLocation;
|
|
68
74
|
}
|
|
69
75
|
|
|
@@ -129,6 +135,7 @@ export interface QuantifierExpression {
|
|
|
129
135
|
|
|
130
136
|
export interface UnboundedQuantifierExpression {
|
|
131
137
|
kind: "UnboundedQuantifier";
|
|
138
|
+
quantifier: "Forall" | "Exists";
|
|
132
139
|
names: string[];
|
|
133
140
|
isTemporal?: boolean;
|
|
134
141
|
body: Expression;
|
|
@@ -187,6 +194,7 @@ export interface FunctionSetExpression {
|
|
|
187
194
|
export interface RecordField {
|
|
188
195
|
name: string;
|
|
189
196
|
value: Expression;
|
|
197
|
+
location: SourceLocation;
|
|
190
198
|
}
|
|
191
199
|
|
|
192
200
|
export interface RecordExpression {
|
|
@@ -317,6 +325,7 @@ export type Expression =
|
|
|
317
325
|
export interface OperatorParam {
|
|
318
326
|
name: string;
|
|
319
327
|
arity: number;
|
|
328
|
+
location?: SourceLocation;
|
|
320
329
|
}
|
|
321
330
|
|
|
322
331
|
export interface OperatorDefinition {
|
|
@@ -368,6 +377,8 @@ export interface Instance {
|
|
|
368
377
|
substitutions: InstanceSubstitution[];
|
|
369
378
|
isLocal: boolean;
|
|
370
379
|
location: SourceLocation;
|
|
380
|
+
instanceRange: SourceRange;
|
|
381
|
+
definitionRange?: SourceRange;
|
|
371
382
|
}
|
|
372
383
|
|
|
373
384
|
export interface NewSymbol {
|
|
@@ -388,18 +399,33 @@ export interface AssumeProve {
|
|
|
388
399
|
|
|
389
400
|
export type Fact = Expression | { kind: "ModuleFact"; name: string; location: SourceLocation };
|
|
390
401
|
|
|
402
|
+
// keyword is the range of the USE or HIDE token and any ONLY after it.
|
|
391
403
|
export interface UseOrHide {
|
|
392
404
|
kind: "Use" | "Hide";
|
|
393
405
|
isOnly: boolean;
|
|
394
406
|
facts: Fact[];
|
|
395
407
|
defs: Fact[];
|
|
408
|
+
keyword: SourceRange;
|
|
396
409
|
location: SourceLocation;
|
|
397
410
|
}
|
|
398
411
|
|
|
412
|
+
// keyword is the range of the BY, OBVIOUS, or OMITTED token.
|
|
399
413
|
export type Proof =
|
|
400
|
-
| { kind: "Obvious" | "Omitted"; location: SourceLocation }
|
|
401
|
-
| {
|
|
402
|
-
|
|
414
|
+
| { kind: "Obvious" | "Omitted"; keyword: SourceRange; location: SourceLocation }
|
|
415
|
+
| {
|
|
416
|
+
kind: "By";
|
|
417
|
+
isOnly: boolean;
|
|
418
|
+
facts: Fact[];
|
|
419
|
+
defs: Fact[];
|
|
420
|
+
keyword: SourceRange;
|
|
421
|
+
location: SourceLocation;
|
|
422
|
+
}
|
|
423
|
+
| {
|
|
424
|
+
kind: "Steps";
|
|
425
|
+
level: number;
|
|
426
|
+
steps: ProofStep[];
|
|
427
|
+
location: SourceLocation;
|
|
428
|
+
};
|
|
403
429
|
|
|
404
430
|
export interface DefineStep {
|
|
405
431
|
kind: "Define";
|
|
@@ -419,9 +445,14 @@ export type StepBody =
|
|
|
419
445
|
| { kind: "Assert"; isSuffices: boolean; statement: Expression | AssumeProve }
|
|
420
446
|
| { kind: "Qed" };
|
|
421
447
|
|
|
448
|
+
// head is the range of the step number and its statement, without the proof, and statement is the
|
|
449
|
+
// range of the statement alone.
|
|
422
450
|
export interface ProofStep {
|
|
423
451
|
name: string | undefined;
|
|
452
|
+
token: string;
|
|
424
453
|
body: StepBody;
|
|
454
|
+
head: SourceRange;
|
|
455
|
+
statement: SourceRange;
|
|
425
456
|
proof: Proof | undefined;
|
|
426
457
|
location: SourceLocation;
|
|
427
458
|
}
|
|
@@ -433,10 +464,23 @@ export interface Theorem {
|
|
|
433
464
|
location: SourceLocation;
|
|
434
465
|
}
|
|
435
466
|
|
|
467
|
+
// The units of a module in source order, for consumers that need the order across kinds.
|
|
468
|
+
export type ModuleUnit =
|
|
469
|
+
| { kind: "Constants"; declarations: Declaration[] }
|
|
470
|
+
| { kind: "Variables"; declarations: Declaration[] }
|
|
471
|
+
| { kind: "Recursive"; declarations: Declaration[] }
|
|
472
|
+
| { kind: "Definition"; definition: Definition }
|
|
473
|
+
| { kind: "Instance"; instance: Instance }
|
|
474
|
+
| { kind: "Assumption"; assumption: Assumption }
|
|
475
|
+
| { kind: "Theorem"; theorem: Theorem }
|
|
476
|
+
| { kind: "Use"; use: UseOrHide }
|
|
477
|
+
| { kind: "Module"; module: Module };
|
|
478
|
+
|
|
436
479
|
export interface Module {
|
|
437
480
|
name: string;
|
|
438
481
|
modules: Module[];
|
|
439
482
|
extends: string[];
|
|
483
|
+
extendsRanges: SourceRange[];
|
|
440
484
|
constants: Declaration[];
|
|
441
485
|
variables: Declaration[];
|
|
442
486
|
definitions: Definition[];
|
|
@@ -445,4 +489,95 @@ export interface Module {
|
|
|
445
489
|
location: SourceLocation;
|
|
446
490
|
theorems: Theorem[];
|
|
447
491
|
uses: UseOrHide[];
|
|
448
|
-
|
|
492
|
+
units: ModuleUnit[];
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
export const getChildren = (expression: Expression): Expression[] => {
|
|
496
|
+
switch (expression.kind) {
|
|
497
|
+
case "Number":
|
|
498
|
+
case "Decimal":
|
|
499
|
+
case "String":
|
|
500
|
+
case "Identifier":
|
|
501
|
+
case "OperatorReference":
|
|
502
|
+
case "ExceptAt":
|
|
503
|
+
return [];
|
|
504
|
+
case "Apply":
|
|
505
|
+
return expression.args;
|
|
506
|
+
case "Lambda":
|
|
507
|
+
return [expression.body];
|
|
508
|
+
case "And":
|
|
509
|
+
case "Or":
|
|
510
|
+
return expression.operands;
|
|
511
|
+
case "Prime":
|
|
512
|
+
case "Unchanged":
|
|
513
|
+
case "Enabled":
|
|
514
|
+
case "Always":
|
|
515
|
+
case "Eventually":
|
|
516
|
+
return [expression.expression];
|
|
517
|
+
case "If":
|
|
518
|
+
return [expression.condition, expression.consequent, expression.alternative];
|
|
519
|
+
case "Case":
|
|
520
|
+
return [
|
|
521
|
+
...expression.arms.flatMap((arm) => [arm.condition, arm.body]),
|
|
522
|
+
...(expression.other ? [expression.other] : []),
|
|
523
|
+
];
|
|
524
|
+
case "Let":
|
|
525
|
+
return [
|
|
526
|
+
...expression.definitions.flatMap((definition) =>
|
|
527
|
+
definition.kind === "Function"
|
|
528
|
+
? [...definition.bounds.map((bound) => bound.set), definition.body]
|
|
529
|
+
: [definition.body],
|
|
530
|
+
),
|
|
531
|
+
expression.body,
|
|
532
|
+
];
|
|
533
|
+
case "Forall":
|
|
534
|
+
case "Exists":
|
|
535
|
+
return [...expression.bounds.map((bound) => bound.set), expression.body];
|
|
536
|
+
case "UnboundedQuantifier":
|
|
537
|
+
return [expression.body];
|
|
538
|
+
case "Choose":
|
|
539
|
+
return [...(expression.set ? [expression.set] : []), expression.body];
|
|
540
|
+
case "SetEnumeration":
|
|
541
|
+
case "Tuple":
|
|
542
|
+
return expression.elements;
|
|
543
|
+
case "SetFilter":
|
|
544
|
+
return [expression.bound.set, expression.predicate];
|
|
545
|
+
case "SetMap":
|
|
546
|
+
return [expression.expression, ...expression.bounds.map((bound) => bound.set)];
|
|
547
|
+
case "FunctionConstruction":
|
|
548
|
+
return [...expression.bounds.map((bound) => bound.set), expression.body];
|
|
549
|
+
case "FunctionSet":
|
|
550
|
+
return [expression.domain, expression.range];
|
|
551
|
+
case "Record":
|
|
552
|
+
case "RecordSet":
|
|
553
|
+
return expression.fields.map((field) => field.value);
|
|
554
|
+
case "Except":
|
|
555
|
+
return [
|
|
556
|
+
expression.function,
|
|
557
|
+
...expression.updates.flatMap((update) => [
|
|
558
|
+
...update.path.flatMap((step) => (step.kind === "Index" ? step.args : [])),
|
|
559
|
+
update.value,
|
|
560
|
+
]),
|
|
561
|
+
];
|
|
562
|
+
case "FunctionApplication":
|
|
563
|
+
return [expression.function, ...expression.args];
|
|
564
|
+
case "FieldAccess":
|
|
565
|
+
return [expression.record];
|
|
566
|
+
case "Product":
|
|
567
|
+
return expression.factors;
|
|
568
|
+
case "BoxAction":
|
|
569
|
+
case "AngleAction":
|
|
570
|
+
return [expression.action, expression.subscript];
|
|
571
|
+
case "WeakFairness":
|
|
572
|
+
case "StrongFairness":
|
|
573
|
+
return [expression.subscript, expression.action];
|
|
574
|
+
case "Label":
|
|
575
|
+
return [expression.body];
|
|
576
|
+
case "Subexpression":
|
|
577
|
+
return expression.selectors.flatMap((selector) => ("args" in selector ? selector.args : []));
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
export const isLocallyResolved = (expression: Expression) =>
|
|
582
|
+
(expression.kind === "Identifier" || expression.kind === "Apply") &&
|
|
583
|
+
expression.resolution?.kind === "Local";
|
package/src/builtins.ts
CHANGED
|
@@ -297,15 +297,21 @@ export const getJavaInteger = (value: Value, signature: string) => {
|
|
|
297
297
|
return value;
|
|
298
298
|
};
|
|
299
299
|
|
|
300
|
-
export const
|
|
301
|
-
|
|
300
|
+
export const getArithmeticSignature = (
|
|
301
|
+
javaClass: "Naturals" | "Integers",
|
|
302
|
+
method: string,
|
|
303
|
+
result: string,
|
|
304
|
+
arity: number,
|
|
305
|
+
) =>
|
|
306
|
+
`public static tlc2.value.impl.${result} tlc2.module.${javaClass}.${method}(${Array.from({ length: arity }, () => "tlc2.value.impl.IntValue").join(",")})`;
|
|
302
307
|
|
|
303
308
|
export const defineArithmetic = (
|
|
309
|
+
javaClass: "Naturals" | "Integers",
|
|
304
310
|
name: string,
|
|
305
311
|
method: string,
|
|
306
312
|
compute: (left: number, right: number) => number,
|
|
307
313
|
) => {
|
|
308
|
-
const signature =
|
|
314
|
+
const signature = getArithmeticSignature(javaClass, method, "IntValue", 2);
|
|
309
315
|
return defineBinary(name, (left, right) => {
|
|
310
316
|
const leftNumber = getJavaInteger(left, signature);
|
|
311
317
|
const rightNumber = getJavaInteger(right, signature);
|