tla-ts 0.0.2 → 0.0.3-dev.1a99ab7

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 (60) hide show
  1. package/README.md +78 -12
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.d.cts +60 -1
  4. package/dist/index.d.ts +60 -1
  5. package/dist/index.js +1 -1
  6. package/dist/parallel-worker.cjs +2 -2
  7. package/dist/parallel-worker.js +2 -2
  8. package/dist/parallel.cjs +1 -1
  9. package/dist/parallel.js +2 -2
  10. package/dist/run-cli.cjs +21 -2
  11. package/dist/run-cli.js +21 -2
  12. package/dist/transfer.cjs +27 -15
  13. package/dist/transfer.js +27 -15
  14. package/package.json +3 -1
  15. package/src/ast.ts +134 -4
  16. package/src/check.ts +274 -76
  17. package/src/cli-options.ts +64 -0
  18. package/src/codegen.ts +9 -19
  19. package/src/dependencies.ts +2 -2
  20. package/src/environment.ts +75 -16
  21. package/src/errors.ts +46 -3
  22. package/src/evaluate.ts +88 -143
  23. package/src/exit-codes.ts +21 -43
  24. package/src/fingerprints.ts +46 -11
  25. package/src/instances.ts +15 -14
  26. package/src/levels.ts +8 -8
  27. package/src/lexer.ts +11 -2
  28. package/src/live-check.ts +711 -0
  29. package/src/liveness.ts +54 -535
  30. package/src/obligation-action.ts +384 -0
  31. package/src/obligation-anon.ts +575 -0
  32. package/src/obligation-deref.ts +637 -0
  33. package/src/obligation-expression.ts +1060 -0
  34. package/src/obligation-format.ts +406 -0
  35. package/src/obligation-generate.ts +1074 -0
  36. package/src/obligation-levels.ts +329 -0
  37. package/src/obligation-module.ts +1042 -0
  38. package/src/obligation-printer.ts +889 -0
  39. package/src/obligation-proof.ts +76 -0
  40. package/src/obligation-source.ts +1084 -0
  41. package/src/obligation-tuples.ts +184 -0
  42. package/src/obligations.ts +316 -0
  43. package/src/parallel-worker.ts +166 -210
  44. package/src/parallel.ts +76 -35
  45. package/src/parser.ts +297 -53
  46. package/src/resolve.ts +16 -15
  47. package/src/run-cli.ts +353 -40
  48. package/src/runtime.ts +3 -1
  49. package/src/spec-description.ts +18 -6
  50. package/src/standard-levels.ts +3 -3
  51. package/src/standard-modules.ts +2 -7
  52. package/src/state-graph.ts +157 -0
  53. package/src/subexpressions.ts +10 -10
  54. package/src/successors.ts +77 -13
  55. package/src/symmetry.ts +14 -2
  56. package/src/tlc-ext.ts +29 -12
  57. package/src/tlc-module.ts +9 -28
  58. package/src/tlc-order.ts +17 -3
  59. package/src/transfer.ts +22 -1
  60. package/src/values.ts +118 -34
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tla-ts",
3
- "version": "0.0.2",
3
+ "version": "0.0.3-dev.1a99ab7",
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,9 @@ 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[];
47
50
  location: SourceLocation;
48
51
  resolution?: LocalResolution;
49
52
  }
@@ -64,6 +67,7 @@ export interface LambdaExpression {
64
67
  export interface JunctionExpression {
65
68
  kind: "And" | "Or";
66
69
  operands: Expression[];
70
+ isBulleted?: boolean;
67
71
  location: SourceLocation;
68
72
  }
69
73
 
@@ -129,6 +133,7 @@ export interface QuantifierExpression {
129
133
 
130
134
  export interface UnboundedQuantifierExpression {
131
135
  kind: "UnboundedQuantifier";
136
+ quantifier: "Forall" | "Exists";
132
137
  names: string[];
133
138
  isTemporal?: boolean;
134
139
  body: Expression;
@@ -317,6 +322,7 @@ export type Expression =
317
322
  export interface OperatorParam {
318
323
  name: string;
319
324
  arity: number;
325
+ location?: SourceLocation;
320
326
  }
321
327
 
322
328
  export interface OperatorDefinition {
@@ -368,6 +374,8 @@ export interface Instance {
368
374
  substitutions: InstanceSubstitution[];
369
375
  isLocal: boolean;
370
376
  location: SourceLocation;
377
+ instanceRange: SourceRange;
378
+ definitionRange?: SourceRange;
371
379
  }
372
380
 
373
381
  export interface NewSymbol {
@@ -388,18 +396,33 @@ export interface AssumeProve {
388
396
 
389
397
  export type Fact = Expression | { kind: "ModuleFact"; name: string; location: SourceLocation };
390
398
 
399
+ // keyword is the range of the USE or HIDE token and any ONLY after it.
391
400
  export interface UseOrHide {
392
401
  kind: "Use" | "Hide";
393
402
  isOnly: boolean;
394
403
  facts: Fact[];
395
404
  defs: Fact[];
405
+ keyword: SourceRange;
396
406
  location: SourceLocation;
397
407
  }
398
408
 
409
+ // keyword is the range of the BY, OBVIOUS, or OMITTED token.
399
410
  export type Proof =
400
- | { kind: "Obvious" | "Omitted"; location: SourceLocation }
401
- | { kind: "By"; isOnly: boolean; facts: Fact[]; defs: Fact[]; location: SourceLocation }
402
- | { kind: "Steps"; level: number; steps: ProofStep[]; location: SourceLocation };
411
+ | { kind: "Obvious" | "Omitted"; keyword: SourceRange; location: SourceLocation }
412
+ | {
413
+ kind: "By";
414
+ isOnly: boolean;
415
+ facts: Fact[];
416
+ defs: Fact[];
417
+ keyword: SourceRange;
418
+ location: SourceLocation;
419
+ }
420
+ | {
421
+ kind: "Steps";
422
+ level: number;
423
+ steps: ProofStep[];
424
+ location: SourceLocation;
425
+ };
403
426
 
404
427
  export interface DefineStep {
405
428
  kind: "Define";
@@ -419,9 +442,12 @@ export type StepBody =
419
442
  | { kind: "Assert"; isSuffices: boolean; statement: Expression | AssumeProve }
420
443
  | { kind: "Qed" };
421
444
 
445
+ // head is the range of the step number and its statement, without the proof.
422
446
  export interface ProofStep {
423
447
  name: string | undefined;
448
+ token: string;
424
449
  body: StepBody;
450
+ head: SourceRange;
425
451
  proof: Proof | undefined;
426
452
  location: SourceLocation;
427
453
  }
@@ -433,10 +459,23 @@ export interface Theorem {
433
459
  location: SourceLocation;
434
460
  }
435
461
 
462
+ // The units of a module in source order, for consumers that need the order across kinds.
463
+ export type ModuleUnit =
464
+ | { kind: "Constants"; declarations: Declaration[] }
465
+ | { kind: "Variables"; declarations: Declaration[] }
466
+ | { kind: "Recursive"; declarations: Declaration[] }
467
+ | { kind: "Definition"; definition: Definition }
468
+ | { kind: "Instance"; instance: Instance }
469
+ | { kind: "Assumption"; assumption: Assumption }
470
+ | { kind: "Theorem"; theorem: Theorem }
471
+ | { kind: "Use"; use: UseOrHide }
472
+ | { kind: "Module"; module: Module };
473
+
436
474
  export interface Module {
437
475
  name: string;
438
476
  modules: Module[];
439
477
  extends: string[];
478
+ extendsRanges: SourceRange[];
440
479
  constants: Declaration[];
441
480
  variables: Declaration[];
442
481
  definitions: Definition[];
@@ -445,4 +484,95 @@ export interface Module {
445
484
  location: SourceLocation;
446
485
  theorems: Theorem[];
447
486
  uses: UseOrHide[];
448
- }
487
+ units: ModuleUnit[];
488
+ }
489
+
490
+ export const getChildren = (expression: Expression): Expression[] => {
491
+ switch (expression.kind) {
492
+ case "Number":
493
+ case "Decimal":
494
+ case "String":
495
+ case "Identifier":
496
+ case "OperatorReference":
497
+ case "ExceptAt":
498
+ return [];
499
+ case "Apply":
500
+ return expression.args;
501
+ case "Lambda":
502
+ return [expression.body];
503
+ case "And":
504
+ case "Or":
505
+ return expression.operands;
506
+ case "Prime":
507
+ case "Unchanged":
508
+ case "Enabled":
509
+ case "Always":
510
+ case "Eventually":
511
+ return [expression.expression];
512
+ case "If":
513
+ return [expression.condition, expression.consequent, expression.alternative];
514
+ case "Case":
515
+ return [
516
+ ...expression.arms.flatMap((arm) => [arm.condition, arm.body]),
517
+ ...(expression.other ? [expression.other] : []),
518
+ ];
519
+ case "Let":
520
+ return [
521
+ ...expression.definitions.flatMap((definition) =>
522
+ definition.kind === "Function"
523
+ ? [...definition.bounds.map((bound) => bound.set), definition.body]
524
+ : [definition.body],
525
+ ),
526
+ expression.body,
527
+ ];
528
+ case "Forall":
529
+ case "Exists":
530
+ return [...expression.bounds.map((bound) => bound.set), expression.body];
531
+ case "UnboundedQuantifier":
532
+ return [expression.body];
533
+ case "Choose":
534
+ return [...(expression.set ? [expression.set] : []), expression.body];
535
+ case "SetEnumeration":
536
+ case "Tuple":
537
+ return expression.elements;
538
+ case "SetFilter":
539
+ return [expression.bound.set, expression.predicate];
540
+ case "SetMap":
541
+ return [expression.expression, ...expression.bounds.map((bound) => bound.set)];
542
+ case "FunctionConstruction":
543
+ return [...expression.bounds.map((bound) => bound.set), expression.body];
544
+ case "FunctionSet":
545
+ return [expression.domain, expression.range];
546
+ case "Record":
547
+ case "RecordSet":
548
+ return expression.fields.map((field) => field.value);
549
+ case "Except":
550
+ return [
551
+ expression.function,
552
+ ...expression.updates.flatMap((update) => [
553
+ ...update.path.flatMap((step) => (step.kind === "Index" ? step.args : [])),
554
+ update.value,
555
+ ]),
556
+ ];
557
+ case "FunctionApplication":
558
+ return [expression.function, ...expression.args];
559
+ case "FieldAccess":
560
+ return [expression.record];
561
+ case "Product":
562
+ return expression.factors;
563
+ case "BoxAction":
564
+ case "AngleAction":
565
+ return [expression.action, expression.subscript];
566
+ case "WeakFairness":
567
+ case "StrongFairness":
568
+ return [expression.subscript, expression.action];
569
+ case "Label":
570
+ return [expression.body];
571
+ case "Subexpression":
572
+ return expression.selectors.flatMap((selector) => ("args" in selector ? selector.args : []));
573
+ }
574
+ };
575
+
576
+ export const isLocallyResolved = (expression: Expression) =>
577
+ (expression.kind === "Identifier" || expression.kind === "Apply") &&
578
+ expression.resolution?.kind === "Local";