tla-ts 0.0.3-dev.e5b05b9 → 0.0.3-dev.e8bef80

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 (79) hide show
  1. package/dist/cli.cjs +1 -1
  2. package/dist/cli.js +1 -1
  3. package/dist/index.cjs +1 -1
  4. package/dist/index.d.cts +150 -48
  5. package/dist/index.d.ts +150 -48
  6. package/dist/index.js +1 -1
  7. package/dist/parallel-worker.cjs +1 -1
  8. package/dist/parallel-worker.js +2 -2
  9. package/dist/parallel.cjs +1 -1
  10. package/dist/parallel.js +2 -2
  11. package/dist/run-cli.cjs +1351 -22
  12. package/dist/run-cli.js +1352 -23
  13. package/dist/transfer.cjs +83 -43
  14. package/dist/transfer.js +83 -43
  15. package/package.json +5 -1
  16. package/src/ast.ts +28 -4
  17. package/src/bags.ts +4 -7
  18. package/src/builtins.ts +29 -17
  19. package/src/bundled-modules.ts +3 -3
  20. package/src/canonical.ts +4 -3
  21. package/src/check.ts +1317 -428
  22. package/src/cli.ts +8 -1
  23. package/src/codegen.ts +68 -21
  24. package/src/config.ts +226 -207
  25. package/src/environment.ts +221 -75
  26. package/src/errors.ts +130 -15
  27. package/src/evaluate.ts +713 -259
  28. package/src/exit-codes.ts +6 -24
  29. package/src/fingerprints.ts +1 -2
  30. package/src/index.ts +1 -0
  31. package/src/instances.ts +3 -1
  32. package/src/java-overrides.ts +104 -25
  33. package/src/levels.ts +6 -1
  34. package/src/lexer.ts +122 -29
  35. package/src/live-check.ts +204 -148
  36. package/src/liveness.ts +191 -122
  37. package/src/obligation-expression.ts +2 -2
  38. package/src/obligation-source.ts +2 -0
  39. package/src/parallel-worker.ts +6 -1
  40. package/src/parallel.ts +57 -6
  41. package/src/parser.ts +327 -147
  42. package/src/pcal-ast.ts +770 -0
  43. package/src/pcal-parse.ts +1523 -0
  44. package/src/pcal-tokenize.ts +516 -0
  45. package/src/pcal-translate.ts +1230 -0
  46. package/src/pcal-validate.ts +454 -0
  47. package/src/randomization.ts +24 -7
  48. package/src/resolve.ts +252 -87
  49. package/src/run-cli.ts +1162 -200
  50. package/src/runtime.ts +16 -0
  51. package/src/sany-builtins.ts +147 -0
  52. package/src/sany-generator.ts +3128 -0
  53. package/src/sany-levels.ts +1208 -0
  54. package/src/sany-lexer.ts +410 -480
  55. package/src/sany-linter.ts +122 -0
  56. package/src/sany-modules.ts +1398 -0
  57. package/src/sany-nodes.ts +463 -0
  58. package/src/sany-parse-error.ts +2033 -3015
  59. package/src/sany-report.ts +356 -0
  60. package/src/sany-selectors.ts +738 -0
  61. package/src/sany-source.ts +248 -0
  62. package/src/sany-xml.ts +1017 -0
  63. package/src/spec-description.ts +25 -5
  64. package/src/standard-modules.ts +172 -129
  65. package/src/state-graph.ts +29 -6
  66. package/src/subexpressions.ts +121 -26
  67. package/src/successors.ts +141 -173
  68. package/src/symmetry.ts +168 -50
  69. package/src/tableau.ts +3 -1
  70. package/src/tlc-ext.ts +13 -17
  71. package/src/tlc-messages.ts +329 -0
  72. package/src/tlc-module.ts +49 -21
  73. package/src/tlc-modules.ts +0 -4
  74. package/src/tlc-order.ts +55 -9
  75. package/src/tlc-random.ts +28 -3
  76. package/src/tlc-replay.ts +655 -0
  77. package/src/tlc-version.ts +18 -0
  78. package/src/transfer.ts +15 -3
  79. package/src/values.ts +664 -317
package/src/runtime.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { createJavaRandom, getTlcFingerprint, type JavaRandom } from "./tlc-random";
2
2
  import { createFunction, createRecord, type Value } from "./values";
3
+ import type { TlcVersion } from "./tlc-version";
3
4
 
4
5
  export interface CheckerRuntime {
5
6
  getLevel: (state: (Value | undefined)[]) => number;
@@ -12,6 +13,17 @@ export interface CheckerRuntime {
12
13
  getRandom: () => JavaRandom;
13
14
  evaluateAtStartup: <Result>(evaluate: () => Result) => Result;
14
15
  pause: () => void;
16
+ // Prints a warning TLC raises while it evaluates, with its message code. TLC prints each
17
+ // distinct warning once.
18
+ warn: (code: number, text: string) => void;
19
+ // TLC's -nowarning turns the warnings off, and with them the shortcut that evaluates the rest
20
+ // of an action once it assigns every variable, since that shortcut skips a warning.
21
+ isWarningEnabled: boolean;
22
+ // TLC's -tool, under which the message of an error that TLC raises with a code holds the
23
+ // code's markers, which AssertError compares with.
24
+ isTool: boolean;
25
+ // The TLC whose messages tla-ts reproduces.
26
+ version: TlcVersion;
15
27
  seed: bigint;
16
28
  isSeen: (state: Value[]) => boolean;
17
29
  generatedStates: number;
@@ -65,6 +77,10 @@ export const createRuntime = (checkDeadlock: boolean, seed = 0n): CheckerRuntime
65
77
  }
66
78
  },
67
79
  pause: () => {},
80
+ warn: () => {},
81
+ isWarningEnabled: true,
82
+ isTool: false,
83
+ version: "master",
68
84
  seed,
69
85
  generatedStates: 0,
70
86
  distinctStates: 0,
@@ -0,0 +1,147 @@
1
+ import type { FormalParamNode, LevelFields, OpDefNode, SanyLocation } from "./sany-nodes";
2
+
3
+ // tla2sany.semantic.BuiltInOperators: name, arity, level, maximum argument levels and argument
4
+ // weights. SANY leaves the levels of "." and \neg unset.
5
+ const BUILTIN_OPERATORS: [string, number, number, number[] | undefined, number[] | undefined][] = [
6
+ ["STRING", 0, 0, [], []],
7
+ ["FALSE", 0, 0, [], []],
8
+ ["TRUE", 0, 0, [], []],
9
+ ["BOOLEAN", 0, 0, [], []],
10
+ ["=", 2, 0, [2, 2], [1, 1]],
11
+ ["/=", 2, 0, [2, 2], [1, 1]],
12
+ [".", 2, 0, undefined, undefined],
13
+ ["'", 1, 2, [1], [0]],
14
+ ["\\lnot", 1, 0, [3], [1]],
15
+ ["\\neg", 1, 0, undefined, undefined],
16
+ ["\\land", 2, 0, [3, 3], [1, 1]],
17
+ ["\\lor", 2, 0, [3, 3], [1, 1]],
18
+ ["\\equiv", 2, 0, [3, 3], [1, 1]],
19
+ ["=>", 2, 0, [3, 3], [1, 1]],
20
+ ["SUBSET", 1, 0, [2], [1]],
21
+ ["UNION", 1, 0, [2], [1]],
22
+ ["DOMAIN", 1, 0, [2], [1]],
23
+ ["\\subseteq", 2, 0, [2, 2], [1, 1]],
24
+ ["\\in", 2, 0, [2, 2], [1, 1]],
25
+ ["\\notin", 2, 0, [2, 2], [1, 1]],
26
+ ["\\", 2, 0, [2, 2], [1, 1]],
27
+ ["\\intersect", 2, 0, [2, 2], [1, 1]],
28
+ ["\\union", 2, 0, [2, 2], [1, 1]],
29
+ ["\\times", 2, 0, [2, 2], [1, 1]],
30
+ ["~>", 2, 3, [3, 3], [0, 0]],
31
+ ["[]", 1, 3, [3], [0]],
32
+ ["<>", 1, 3, [3], [0]],
33
+ ["ENABLED", 1, 1, [2], [0]],
34
+ ["UNCHANGED", 1, 2, [1], [0]],
35
+ ["\\cdot", 2, 2, [2, 2], [0, 0]],
36
+ ["-+->", 2, 3, [3, 3], [0, 0]],
37
+ ["$AngleAct", 2, 2, [2, 1], [0, 0]],
38
+ ["$BoundedChoose", -1, 0, [2], [1]],
39
+ ["$BoundedExists", -1, 0, [3], [1]],
40
+ ["$BoundedForall", -1, 0, [3], [1]],
41
+ ["$CartesianProd", -1, 0, [2], [1]],
42
+ ["$Case", -1, 0, [3], [1]],
43
+ ["$ConjList", -1, 0, [3], [1]],
44
+ ["$DisjList", -1, 0, [3], [1]],
45
+ ["$Except", -1, 0, [2], [1]],
46
+ ["$FcnApply", 2, 0, [2, 2], [1, 1]],
47
+ ["$FcnConstructor", -1, 0, [3], [1]],
48
+ ["$IfThenElse", 3, 0, [3, 3, 3], [1, 1, 1]],
49
+ ["$NonRecursiveFcnSpec", 1, 0, [3], [1]],
50
+ ["$Pair", 2, 0, [3, 3], [1, 1]],
51
+ ["$RcdConstructor", -1, 0, [3], [1]],
52
+ ["$RcdSelect", 2, 0, [2, 0], [1, 1]],
53
+ ["$RecursiveFcnSpec", 1, 0, [3], [1]],
54
+ ["$Seq", -1, 0, [2], [1]],
55
+ ["$SetEnumerate", -1, 0, [2], [1]],
56
+ ["$SetOfAll", -1, 0, [2], [1]],
57
+ ["$SetOfFcns", -1, 0, [2], [1]],
58
+ ["$SetOfRcds", -1, 0, [2], [1]],
59
+ ["$SF", 2, 3, [1, 2], [0, 0]],
60
+ ["$SquareAct", 2, 2, [2, 1], [0, 0]],
61
+ ["$SubsetOf", 1, 0, [2], [1]],
62
+ ["$TemporalExists", 1, 3, [3], [0]],
63
+ ["$TemporalForall", 1, 3, [3], [0]],
64
+ ["$TemporalWhile", 2, 3, [3, 3], [0, 0]],
65
+ ["$Tuple", -1, 0, [2], [1]],
66
+ ["$UnboundedChoose", 1, 0, [2], [1]],
67
+ ["$UnboundedExists", 1, 0, [3], [1]],
68
+ ["$UnboundedForall", 1, 0, [3], [1]],
69
+ ["$WF", 2, 3, [1, 2], [0, 0]],
70
+ ["$Nop", 1, 0, [3], [1]],
71
+ ["$Qed", 0, 0, [], []],
72
+ ["$Pfcase", 1, 0, [3], [1]],
73
+ ["$Have", 1, 0, [3], [1]],
74
+ ["$Take", 1, 0, [3], [1]],
75
+ ["$Pick", 1, 0, [3], [1]],
76
+ ["$Witness", -1, 0, [2], [1]],
77
+ ["$Suffices", 1, 0, [3], [1]],
78
+ ];
79
+
80
+ export const BUILTIN_LOCATION: SanyLocation = {
81
+ file: "--TLA+ BUILTINS--",
82
+ beginLine: 0,
83
+ beginColumn: 0,
84
+ endLine: 0,
85
+ endColumn: 0,
86
+ };
87
+
88
+ export const createLevelFields = (id: number): LevelFields => ({
89
+ id,
90
+ levelChecked: 0,
91
+ level: 0,
92
+ levelParams: new Set(),
93
+ allParams: new Set(),
94
+ nonLeibnizParams: new Set(),
95
+ argLevelParams: new Map(),
96
+ levelCorrect: true,
97
+ levelConstraints: new Map(),
98
+ argLevelConstraints: new Map(),
99
+ });
100
+
101
+ // The builtin operators in the order SANY adds them to its global context. OpDefNode's constructor
102
+ // for a builtin numbers the operator, then its phony parameters.
103
+ export const createBuiltins = (getId: () => number) =>
104
+ BUILTIN_OPERATORS.map(([name, arity, level, maxLevels, weights]): OpDefNode => {
105
+ const id = getId();
106
+ const params =
107
+ arity < 0
108
+ ? undefined
109
+ : Array.from({ length: arity }, (_, index): FormalParamNode => ({
110
+ ...createLevelFields(getId()),
111
+ kind: "FormalParam",
112
+ name: `Formal_${index}`,
113
+ arity: 0,
114
+ location: undefined,
115
+ }));
116
+ const isLevelSet = maxLevels !== undefined && weights !== undefined;
117
+ const isLeibnizArg = weights?.map((weight) => weight > 0);
118
+ return {
119
+ ...createLevelFields(id),
120
+ levelChecked: isLevelSet ? 99 : 0,
121
+ level,
122
+ kind: "OpDef",
123
+ defKind: "BuiltIn",
124
+ name,
125
+ arity,
126
+ params,
127
+ body: undefined,
128
+ isLocal: false,
129
+ location: BUILTIN_LOCATION,
130
+ module: undefined,
131
+ source: undefined,
132
+ preComments: [],
133
+ isDefined: true,
134
+ inRecursive: false,
135
+ inRecursiveSection: false,
136
+ recursiveSection: -1,
137
+ letInLevel: 0,
138
+ weights: arity < 0 ? (weights ?? []).slice(0, 1) : (weights ?? []),
139
+ isLeibnizArg: isLevelSet ? isLeibnizArg : undefined,
140
+ isLeibniz: isLeibnizArg?.every(Boolean) ?? true,
141
+ opLevelCond: undefined,
142
+ maxLevels: arity < 0 ? (maxLevels ?? []).slice(0, 1) : (maxLevels ?? []),
143
+ minMaxLevel: undefined,
144
+ labels: new Map(),
145
+ step: undefined,
146
+ };
147
+ });