tla-ts 0.0.10-dev.28c823e4b → 0.0.10-dev.63a6693bd

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 (172) hide show
  1. package/dist/compile.cjs +6 -6
  2. package/dist/compile.js +10 -10
  3. package/dist/deciders.cjs +29 -29
  4. package/dist/deciders.js +40 -40
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.js +1 -1
  7. package/dist/parallel-worker.cjs +1 -1
  8. package/dist/parallel-worker.js +1 -1
  9. package/dist/prove-worker.cjs +1 -1
  10. package/dist/prove-worker.js +1 -1
  11. package/dist/prove.cjs +54 -54
  12. package/dist/prove.js +52 -52
  13. package/dist/run.cjs +42 -42
  14. package/dist/run.js +44 -44
  15. package/dist/tlapm.cjs +2 -2
  16. package/dist/tlapm.js +2 -2
  17. package/dist/transfer.cjs +39 -39
  18. package/dist/transfer.js +41 -41
  19. package/dist/worker.cjs +4 -4
  20. package/dist/worker.js +4 -4
  21. package/package.json +1 -1
  22. package/src/ast.ts +44 -39
  23. package/src/builtins.ts +4 -13
  24. package/src/check-failure.ts +116 -0
  25. package/src/check-trace.ts +282 -0
  26. package/src/check.ts +152 -518
  27. package/src/cli/options.ts +6 -31
  28. package/src/cli/shared.ts +1 -1
  29. package/src/cli/tlapm.ts +14 -13
  30. package/src/cli/tlc-arguments.ts +222 -210
  31. package/src/cli/tlc-output.ts +687 -0
  32. package/src/cli/tlc-usage.ts +1 -1
  33. package/src/cli/tlc.ts +34 -701
  34. package/src/cli/xml-exporter.ts +23 -33
  35. package/src/codegen.ts +5 -10
  36. package/src/coverage.ts +3 -10
  37. package/src/dependencies.ts +8 -13
  38. package/src/dfid.ts +16 -16
  39. package/src/environment-config.ts +315 -0
  40. package/src/environment.ts +45 -333
  41. package/src/errors.ts +3 -2
  42. package/src/evaluate.ts +5 -4
  43. package/src/fingerprints.ts +65 -1
  44. package/src/instances.ts +47 -10
  45. package/src/java-hash.ts +7 -0
  46. package/src/json.ts +4 -7
  47. package/src/levels.ts +39 -42
  48. package/src/liveness-checker.ts +24 -37
  49. package/src/liveness.ts +47 -54
  50. package/src/obligations/action.ts +4 -11
  51. package/src/obligations/anonymize.ts +4 -2
  52. package/src/obligations/expression.ts +18 -2
  53. package/src/obligations/generate.ts +45 -38
  54. package/src/obligations/index.ts +2 -2
  55. package/src/obligations/module.ts +27 -38
  56. package/src/obligations/normalize.ts +2 -1
  57. package/src/obligations/simplify.ts +39 -44
  58. package/src/obligations/source.ts +47 -57
  59. package/src/obligations/temporal.ts +5 -5
  60. package/src/parallel-worker.ts +10 -30
  61. package/src/parallel.ts +22 -45
  62. package/src/parser.ts +19 -34
  63. package/src/prover/decide-pool.ts +3 -3
  64. package/src/prover/deciders.ts +3 -3
  65. package/src/prover/isabelle/encode.ts +1 -1
  66. package/src/prover/isabelle/isar/inner-syntax.ts +9 -4
  67. package/src/prover/isabelle/isar/method.ts +14 -25
  68. package/src/prover/isabelle/isar/theory.ts +11 -10
  69. package/src/prover/isabelle/isar/type-check.ts +6 -6
  70. package/src/prover/isabelle/provers/blast/blast.ts +7 -63
  71. package/src/prover/isabelle/provers/hypsubst.ts +17 -26
  72. package/src/prover/isabelle/pure/bicompose.ts +9 -25
  73. package/src/prover/isabelle/pure/conv.ts +2 -8
  74. package/src/prover/isabelle/pure/drule.ts +9 -2
  75. package/src/prover/isabelle/pure/logic.ts +1 -1
  76. package/src/prover/isabelle/pure/raw-simplifier.ts +4 -13
  77. package/src/prover/isabelle/pure/rewriter.ts +5 -9
  78. package/src/prover/isabelle/pure/table.ts +2 -1
  79. package/src/prover/isabelle/pure/tactical.ts +42 -35
  80. package/src/prover/isabelle/pure/thm.ts +14 -11
  81. package/src/prover/isabelle/tla/classical-setup.ts +17 -14
  82. package/src/prover/isabelle/tla/context.ts +7 -2
  83. package/src/prover/isabelle/tla/logic.ts +10 -21
  84. package/src/prover/isabelle/tla/simpdata.ts +1 -10
  85. package/src/prover/prep/action.ts +11 -19
  86. package/src/prover/prep/fingerprint.ts +2 -5
  87. package/src/prover/prep/methods.ts +24 -3
  88. package/src/prover/prove.ts +87 -64
  89. package/src/prover/smt/context.ts +1 -2
  90. package/src/prover/smt/data.ts +418 -406
  91. package/src/prover/smt/encode.ts +30 -18
  92. package/src/prover/smt/rewrite.ts +657 -626
  93. package/src/prover/smt/solver/ast.ts +0 -22
  94. package/src/prover/smt/solver/auf-solver.ts +2 -5
  95. package/src/prover/smt/solver/context.ts +3 -3
  96. package/src/prover/smt/solver/e-matching.ts +1 -1
  97. package/src/prover/smt/solver/expr-safe-replace.ts +1 -1
  98. package/src/prover/smt/solver/internalizer.ts +1 -2
  99. package/src/prover/smt/solver/lp/dioph-eq.ts +1 -8
  100. package/src/prover/smt/solver/lp/hnf-cutter.ts +1 -1
  101. package/src/prover/smt/solver/lp/nla-core.ts +2 -6
  102. package/src/prover/smt/solver/mam-compiler.ts +4 -2
  103. package/src/prover/smt/solver/model-checker.ts +1 -1
  104. package/src/prover/smt/solver/model-finder.ts +12 -17
  105. package/src/prover/smt/solver/model-macro-solver.ts +11 -19
  106. package/src/prover/smt/solver/nlsat/algebraic.ts +9 -9
  107. package/src/prover/smt/solver/nlsat/atoms.ts +20 -4
  108. package/src/prover/smt/solver/nlsat/explain.ts +7 -22
  109. package/src/prover/smt/solver/nlsat/levelwise.ts +1 -6
  110. package/src/prover/smt/solver/nlsat/polynomial.ts +12 -3
  111. package/src/prover/smt/solver/nlsat/solver.ts +12 -24
  112. package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -1
  113. package/src/prover/smt/solver/proto-model.ts +0 -4
  114. package/src/prover/smt/solver/quantifier-analyzer.ts +10 -10
  115. package/src/prover/smt/solver/quantifier-manager.ts +1 -5
  116. package/src/prover/smt/solver/smtlib-parser.ts +78 -94
  117. package/src/prover/smt/solver/theory-lra-bounds.ts +1 -2
  118. package/src/prover/smt/solver/theory-lra-internalize.ts +5 -16
  119. package/src/prover/tlapm/cache.ts +28 -18
  120. package/src/prover/tlapm/tlapm.ts +15 -9
  121. package/src/prover/verdict.ts +7 -0
  122. package/src/prover/zenon/check/check.ts +1 -2
  123. package/src/prover/zenon/check/records.ts +1 -1
  124. package/src/prover/zenon/check/relations.ts +2 -1
  125. package/src/prover/zenon/check/rewrites.ts +2 -15
  126. package/src/prover/zenon/check/sets.ts +40 -58
  127. package/src/prover/zenon/check/terms.ts +1 -2
  128. package/src/prover/zenon/eqrel.ts +2 -0
  129. package/src/prover/zenon/expr.ts +7 -0
  130. package/src/prover/zenon/index-table.ts +9 -19
  131. package/src/prover/zenon/isar.ts +35 -35
  132. package/src/prover/zenon/llproof.ts +2 -11
  133. package/src/prover/zenon/mltoll.ts +12 -28
  134. package/src/prover/zenon/parse.ts +3 -6
  135. package/src/prover/zenon/search.ts +4 -14
  136. package/src/prover/zenon/tla/functions.ts +2 -2
  137. package/src/prover/zenon/tla/llproof.ts +9 -11
  138. package/src/prover/zenon/tla/records.ts +1 -6
  139. package/src/prover/zenon/tla/sets.ts +15 -14
  140. package/src/prover/zenon/tla/tla.ts +7 -6
  141. package/src/resolve.ts +55 -72
  142. package/src/sany/generation.ts +394 -0
  143. package/src/sany/generator-def-entries.ts +210 -0
  144. package/src/sany/generator-definitions.ts +686 -0
  145. package/src/sany/generator-expressions.ts +1100 -0
  146. package/src/sany/generator-proofs.ts +662 -0
  147. package/src/sany/generator.ts +155 -2625
  148. package/src/sany/lexer.ts +17 -16
  149. package/src/sany/nodes.ts +6 -13
  150. package/src/sany/report.ts +3 -6
  151. package/src/sany/selectors.ts +35 -38
  152. package/src/sany/xml.ts +23 -55
  153. package/src/search.ts +65 -27
  154. package/src/simulate.ts +157 -133
  155. package/src/spec-description.ts +33 -48
  156. package/src/standard-modules.ts +16 -32
  157. package/src/state-graph.ts +2 -7
  158. package/src/substitution-levels.ts +5 -4
  159. package/src/successors.ts +5 -7
  160. package/src/tlc/messages.ts +20 -15
  161. package/src/tlc/order.ts +2 -9
  162. package/src/tlc/random.ts +4 -4
  163. package/src/tlc/replay.ts +8 -15
  164. package/src/tlc/tlc-operators.ts +2 -3
  165. package/src/tlc/trace-spec.ts +25 -45
  166. package/src/typescript/actions.ts +2 -4
  167. package/src/typescript/collections.ts +34 -20
  168. package/src/typescript/compile.ts +1 -3
  169. package/src/typescript/formula.ts +5 -3
  170. package/src/typescript/model.ts +4 -5
  171. package/src/typescript/steps.ts +20 -18
  172. package/src/values.ts +63 -158
@@ -0,0 +1,210 @@
1
+ import type { Expression } from "../ast";
2
+ import {
3
+ getExpressionSpan,
4
+ getMatchingIndex,
5
+ getParenthesizedSpan,
6
+ getSpanLocation,
7
+ getTokenSource,
8
+ isToken,
9
+ type SourceFile,
10
+ type TokenSpan,
11
+ } from "./source";
12
+ import type { ModuleGeneration } from "./generation";
13
+
14
+ interface DefEntryParts {
15
+ hasChildlessFirstChild: boolean | undefined;
16
+ last: TokenSpan;
17
+ lastKind: string | undefined;
18
+ }
19
+
20
+ const SYNTAX_KINDS = new Map<Expression["kind"], string>([
21
+ ["Identifier", "N_GeneralId"],
22
+ ["Subexpression", "N_GeneralId"],
23
+ ["Number", "N_Number"],
24
+ ["Decimal", "N_Real"],
25
+ ["SetEnumeration", "N_SetEnumerate"],
26
+ ["SetFilter", "N_SubsetOf"],
27
+ ["SetMap", "N_SetOfAll"],
28
+ ["Tuple", "N_Tuple"],
29
+ ["FunctionApplication", "N_FcnAppl"],
30
+ ["FunctionConstruction", "N_FcnConst"],
31
+ ["FunctionSet", "N_SetOfFcns"],
32
+ ["Record", "N_RcdConstructor"],
33
+ ["RecordSet", "N_SetOfRcds"],
34
+ ["FieldAccess", "N_RecordComponent"],
35
+ ["Except", "N_Except"],
36
+ ["Prime", "N_PostfixExpr"],
37
+ ["Always", "N_PrefixExpr"],
38
+ ["Eventually", "N_PrefixExpr"],
39
+ ["Enabled", "N_PrefixExpr"],
40
+ ["Unchanged", "N_PrefixExpr"],
41
+ ["Forall", "N_BoundedQuant"],
42
+ ["Exists", "N_BoundedQuant"],
43
+ ["UnboundedQuantifier", "N_UnboundedQuant"],
44
+ ["Choose", "N_UnBoundedOrBoundedChoose"],
45
+ ["If", "N_IfThenElse"],
46
+ ["Case", "N_Case"],
47
+ ["Let", "N_LetIn"],
48
+ ["BoxAction", "N_ActionExpr"],
49
+ ["AngleAction", "N_ActionExpr"],
50
+ ["WeakFairness", "N_FairnessExpr"],
51
+ ["StrongFairness", "N_FairnessExpr"],
52
+ ]);
53
+
54
+ const NESTED_FIRST_CHILD_KINDS = new Set([
55
+ "N_GeneralId",
56
+ "N_OpApplication",
57
+ "N_PrefixExpr",
58
+ "N_InfixExpr",
59
+ "N_PostfixExpr",
60
+ "N_FcnAppl",
61
+ "N_RecordComponent",
62
+ ]);
63
+
64
+ const isParenthesized = (file: SourceFile, span: TokenSpan) =>
65
+ isToken(file, span.start, "(") && getMatchingIndex(file, span.start) === span.end;
66
+
67
+ export const getOperandSpan = (file: SourceFile, expression: Expression) =>
68
+ getParenthesizedSpan(file, getExpressionSpan(file, expression));
69
+
70
+ const getApplicationKind = (
71
+ file: SourceFile,
72
+ expression: Expression & { kind: "Apply" },
73
+ span: TokenSpan,
74
+ ) => {
75
+ if (getOperandSpan(file, expression.args[0]).start === span.start) {
76
+ return expression.args.length === 2 ? "N_InfixExpr" : "N_PostfixExpr";
77
+ }
78
+ return file.tokens[span.start].kind === "Identifier" ? "N_OpApplication" : "N_PrefixExpr";
79
+ };
80
+
81
+ const getSyntaxKind = (file: SourceFile, expression: Expression, span: TokenSpan) => {
82
+ if (isParenthesized(file, span)) return "N_ParenExpr";
83
+ if (expression.kind === "String") return getTokenSource(file, span.start);
84
+ if (expression.kind === "Apply") return getApplicationKind(file, expression, span);
85
+ return SYNTAX_KINDS.get(expression.kind);
86
+ };
87
+
88
+ const hasChildlessFirstChild = (file: SourceFile, expression: Expression, span: TokenSpan) => {
89
+ if (expression.kind === "String" && !isParenthesized(file, span)) return false;
90
+ if (expression.kind === "Identifier" && !expression.name.includes("!")) return true;
91
+ const kind = getSyntaxKind(file, expression, span);
92
+ return kind === undefined || NESTED_FIRST_CHILD_KINDS.has(kind) ? undefined : true;
93
+ };
94
+
95
+ const getDefEntryParts = (
96
+ file: SourceFile,
97
+ expression: Expression,
98
+ span: TokenSpan,
99
+ ): DefEntryParts | undefined => {
100
+ const getPart = (operand: Expression, partSpan = getOperandSpan(file, operand)) => ({
101
+ last: partSpan,
102
+ lastKind: getSyntaxKind(file, operand, partSpan),
103
+ });
104
+ if (isParenthesized(file, span)) {
105
+ const inner = { start: span.start + 1, end: span.end - 1 };
106
+ return { hasChildlessFirstChild: false, ...getPart(expression, inner) };
107
+ }
108
+ switch (expression.kind) {
109
+ case "If":
110
+ case "BoxAction":
111
+ case "AngleAction":
112
+ return {
113
+ hasChildlessFirstChild: false,
114
+ ...getPart(expression.kind === "If" ? expression.condition : expression.action),
115
+ };
116
+ case "Tuple":
117
+ case "SetEnumeration": {
118
+ const first = expression.elements[0];
119
+ return first === undefined
120
+ ? {
121
+ hasChildlessFirstChild: false,
122
+ last: { start: span.end, end: span.end },
123
+ lastKind: file.tokens[span.end].text,
124
+ }
125
+ : { hasChildlessFirstChild: false, ...getPart(first) };
126
+ }
127
+ case "Always":
128
+ case "Eventually":
129
+ case "Enabled":
130
+ case "Unchanged":
131
+ return {
132
+ hasChildlessFirstChild: true,
133
+ ...getPart(expression.expression, { start: span.start + 1, end: span.end }),
134
+ };
135
+ case "Prime":
136
+ return {
137
+ hasChildlessFirstChild: hasChildlessFirstChild(
138
+ file,
139
+ expression.expression,
140
+ getOperandSpan(file, expression.expression),
141
+ ),
142
+ last: { start: span.end, end: span.end },
143
+ lastKind: "N_GenPostfixOp",
144
+ };
145
+ case "FunctionApplication":
146
+ case "FieldAccess": {
147
+ const operand =
148
+ expression.kind === "FunctionApplication" ? expression.function : expression.record;
149
+ const operandSpan = getOperandSpan(file, operand);
150
+ const next = operandSpan.end + 1;
151
+ return {
152
+ hasChildlessFirstChild: hasChildlessFirstChild(file, operand, operandSpan),
153
+ last: { start: next, end: next },
154
+ lastKind: file.tokens[next].text,
155
+ };
156
+ }
157
+ case "Apply": {
158
+ const kind = getApplicationKind(file, expression, span);
159
+ if (kind === "N_OpApplication") {
160
+ return expression.operator.includes("!")
161
+ ? undefined
162
+ : {
163
+ hasChildlessFirstChild: true,
164
+ last: { start: span.start + 1, end: span.end },
165
+ lastKind: "N_OpArgs",
166
+ };
167
+ }
168
+ if (kind === "N_PrefixExpr") {
169
+ return {
170
+ hasChildlessFirstChild: true,
171
+ ...getPart(expression.args[0], { start: span.start + 1, end: span.end }),
172
+ };
173
+ }
174
+ const left = getOperandSpan(file, expression.args[0]);
175
+ const operator = left.end + 1;
176
+ return {
177
+ hasChildlessFirstChild: hasChildlessFirstChild(file, expression.args[0], left),
178
+ last: { start: operator, end: operator },
179
+ lastKind: kind === "N_InfixExpr" ? "N_GenInfixOp" : "N_GenPostfixOp",
180
+ };
181
+ }
182
+ }
183
+ return undefined;
184
+ };
185
+
186
+ export const reportDefEntry = (generation: ModuleGeneration, expression: Expression) => {
187
+ const span = getOperandSpan(generation.file, expression);
188
+ const isName =
189
+ expression.kind === "Identifier" ||
190
+ expression.kind === "Subexpression" ||
191
+ expression.kind === "OperatorReference";
192
+ if (isName && !isParenthesized(generation.file, span)) return false;
193
+ const parts = getDefEntryParts(generation.file, expression, span);
194
+ if (parts?.hasChildlessFirstChild === undefined || parts.lastKind === undefined) return false;
195
+ const lastLocation = getSpanLocation(generation.file, parts.last);
196
+ if (parts.hasChildlessFirstChild) {
197
+ generation.addError(getSpanLocation(generation.file, span), "Was expecting a GeneralId.");
198
+ }
199
+ if (parts.lastKind === "N_OpArgs") {
200
+ generation.addError(lastLocation, "Selector `!(...)' should not have argument(s).");
201
+ } else {
202
+ generation.addError(lastLocation, "Unexpected token found.");
203
+ generation.addError(lastLocation, `Need name or step number here, not \`${parts.lastKind}'.`);
204
+ }
205
+ generation.addError(
206
+ getSpanLocation(generation.file, span),
207
+ "DEF clause entry should describe a defined operator.",
208
+ );
209
+ return true;
210
+ };