tla-ts 0.0.4-dev.b254db0 → 0.0.4-dev.ca40dfe

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 (207) hide show
  1. package/README.md +31 -10
  2. package/dist/cli.cjs +1 -1
  3. package/dist/cli.js +1 -1
  4. package/dist/deciders.cjs +27 -27
  5. package/dist/deciders.js +34 -34
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +12 -14
  8. package/dist/index.d.ts +12 -14
  9. package/dist/index.js +1 -1
  10. package/dist/parallel-worker.cjs +1 -1
  11. package/dist/parallel-worker.js +1 -1
  12. package/dist/prove-worker.cjs +1 -1
  13. package/dist/prove-worker.js +1 -1
  14. package/dist/prove.cjs +37 -27
  15. package/dist/prove.js +39 -29
  16. package/dist/run.cjs +45 -0
  17. package/dist/run.js +45 -0
  18. package/dist/tlapm.cjs +2 -2
  19. package/dist/tlapm.js +2 -2
  20. package/dist/transfer.cjs +76 -86
  21. package/dist/transfer.js +73 -83
  22. package/dist/worker.cjs +6 -6
  23. package/dist/worker.js +6 -6
  24. package/package.json +1 -1
  25. package/src/ast.ts +2 -2
  26. package/src/bags.ts +22 -23
  27. package/src/builtins.ts +16 -8
  28. package/src/check.ts +131 -1154
  29. package/src/{cli-options.ts → cli/options.ts} +54 -9
  30. package/src/cli/run.ts +63 -0
  31. package/src/cli/shared.ts +106 -0
  32. package/src/cli/tlapm.ts +374 -0
  33. package/src/cli/tlc.ts +941 -0
  34. package/src/cli/xml-exporter.ts +221 -0
  35. package/src/cli.ts +1 -1
  36. package/src/codegen.ts +17 -15
  37. package/src/config.ts +5 -5
  38. package/src/dependencies.ts +4 -6
  39. package/src/environment.ts +55 -60
  40. package/src/errors.ts +12 -36
  41. package/src/evaluate.ts +81 -101
  42. package/src/exit-codes.ts +1 -1
  43. package/src/fingerprints.ts +3 -3
  44. package/src/instances.ts +56 -46
  45. package/src/java-overrides.ts +79 -41
  46. package/src/json.ts +31 -36
  47. package/src/levels.ts +10 -13
  48. package/src/{live-check.ts → liveness-checker.ts} +169 -142
  49. package/src/liveness.ts +38 -34
  50. package/src/obligations/action.ts +9 -45
  51. package/src/obligations/{anon.ts → anonymize.ts} +13 -25
  52. package/src/obligations/equality.ts +260 -0
  53. package/src/obligations/expression.ts +42 -517
  54. package/src/obligations/generate.ts +88 -778
  55. package/src/obligations/index.ts +20 -22
  56. package/src/obligations/levels.ts +36 -41
  57. package/src/obligations/module.ts +88 -708
  58. package/src/obligations/normalize.ts +554 -0
  59. package/src/obligations/operators.ts +176 -0
  60. package/src/obligations/pragma.ts +21 -15
  61. package/src/obligations/printer.ts +81 -188
  62. package/src/obligations/proof.ts +0 -1
  63. package/src/obligations/regroup.ts +100 -0
  64. package/src/obligations/simplify.ts +668 -0
  65. package/src/obligations/source.ts +25 -131
  66. package/src/obligations/{deref.ts → subexpression.ts} +48 -56
  67. package/src/obligations/substitution.ts +261 -0
  68. package/src/obligations/temporal.ts +28 -26
  69. package/src/obligations/tuples.ts +37 -53
  70. package/src/parallel-worker.ts +37 -33
  71. package/src/parallel.ts +30 -24
  72. package/src/parser.ts +67 -74
  73. package/src/{pcal-ast.ts → pcal/ast.ts} +2 -17
  74. package/src/{pcal-parse.ts → pcal/parse.ts} +28 -64
  75. package/src/{pcal-tokenize.ts → pcal/tokenize.ts} +10 -39
  76. package/src/{pcal-translate.ts → pcal/translate.ts} +30 -109
  77. package/src/{pcal-validate.ts → pcal/validate.ts} +10 -20
  78. package/src/prove/decide-pool.ts +7 -12
  79. package/src/{obligations/pickle.ts → prove/first-order.ts} +79 -2
  80. package/src/prove/isabelle/decide.ts +3 -6
  81. package/src/prove/isabelle/encode.ts +35 -93
  82. package/src/prove/isabelle/isar/inner-syntax.ts +1 -1
  83. package/src/prove/isabelle/isar/method.ts +3 -3
  84. package/src/prove/isabelle/isar/type-check.ts +1 -1
  85. package/src/prove/isabelle/provers/blast/blast.ts +1 -1
  86. package/src/prove/isabelle/provers/blast/branch.ts +1 -1
  87. package/src/prove/isabelle/provers/blast/term.ts +3 -4
  88. package/src/prove/isabelle/provers/clasimp.ts +1 -1
  89. package/src/prove/isabelle/provers/classical.ts +3 -3
  90. package/src/prove/isabelle/provers/hypsubst.ts +1 -9
  91. package/src/prove/isabelle/pure/conv.ts +1 -1
  92. package/src/prove/isabelle/pure/drule.ts +2 -2
  93. package/src/prove/isabelle/pure/envir.ts +3 -35
  94. package/src/prove/isabelle/pure/logic.ts +4 -76
  95. package/src/prove/isabelle/pure/name.ts +1 -13
  96. package/src/prove/isabelle/pure/net.ts +2 -49
  97. package/src/prove/isabelle/pure/pattern.ts +3 -22
  98. package/src/prove/isabelle/pure/raw-simplifier.ts +3 -18
  99. package/src/prove/isabelle/pure/seq.ts +0 -23
  100. package/src/prove/isabelle/pure/simplifier.ts +2 -8
  101. package/src/prove/isabelle/pure/table.ts +1 -8
  102. package/src/prove/isabelle/pure/tactic.ts +5 -113
  103. package/src/prove/isabelle/pure/tactical.ts +1 -84
  104. package/src/prove/isabelle/pure/term-ord.ts +1 -55
  105. package/src/prove/isabelle/pure/term.ts +8 -128
  106. package/src/prove/isabelle/pure/thm.ts +4 -27
  107. package/src/prove/isabelle/pure/type.ts +0 -12
  108. package/src/prove/isabelle/pure/unify.ts +1 -1
  109. package/src/prove/isabelle/tla/classical-setup.ts +1 -1
  110. package/src/prove/ocaml.ts +1 -1
  111. package/src/prove/prep/action.ts +23 -36
  112. package/src/prove/prep/enabled-axioms.ts +2 -2
  113. package/src/prove/prep/fingerprint.ts +3 -3
  114. package/src/prove/prep/level-comparison.ts +9 -37
  115. package/src/prove/prep/md5.ts +2 -9
  116. package/src/prove/prep/normalize.ts +309 -0
  117. package/src/prove/prove-worker.ts +2 -5
  118. package/src/prove/prove.ts +98 -111
  119. package/src/prove/ptl/encode.ts +19 -31
  120. package/src/prove/smt/axioms.ts +45 -58
  121. package/src/prove/smt/encode.ts +124 -15
  122. package/src/prove/smt/instances.ts +2 -3
  123. package/src/prove/smt/rewrite.ts +24 -31
  124. package/src/prove/smt/solver/ast-util.ts +0 -56
  125. package/src/prove/smt/solver/case-split-queue.ts +1 -1
  126. package/src/prove/smt/solver/enode.ts +1 -1
  127. package/src/prove/smt/solver/lp/dep-intervals.ts +0 -14
  128. package/src/prove/smt/solver/model-macro-solver.ts +1 -1
  129. package/src/prove/smt/solver/nlsat/algebraic.ts +3 -3
  130. package/src/prove/smt/solver/nlsat/atoms.ts +1 -1
  131. package/src/prove/smt/solver/nlsat/explain.ts +1 -1
  132. package/src/prove/smt/solver/nlsat/interval-set.ts +1 -1
  133. package/src/prove/smt/solver/nlsat/levelwise.ts +4 -7
  134. package/src/prove/smt/solver/nlsat/polynomial.ts +4 -4
  135. package/src/prove/smt/solver/nlsat/upolynomial.ts +2 -2
  136. package/src/prove/smt/solver/pattern-inference.ts +1 -1
  137. package/src/prove/smt/solver/relevancy.ts +2 -2
  138. package/src/prove/smt/solver/rewriter.ts +1 -1
  139. package/src/prove/smt/solver/solver.ts +2 -2
  140. package/src/{tlapm-cache.ts → prove/tlapm/cache.ts} +11 -11
  141. package/src/{ocaml-marshal.ts → prove/tlapm/ocaml-marshal.ts} +1 -1
  142. package/src/prove/verdict.ts +0 -5
  143. package/src/prove/zenon/decide.ts +5 -11
  144. package/src/prove/zenon/encode.ts +21 -80
  145. package/src/prove/zenon/eqrel.ts +1 -1
  146. package/src/prove/zenon/equality-rules.ts +1 -1
  147. package/src/prove/zenon/expr.ts +2 -2
  148. package/src/prove/zenon/index-table.ts +1 -1
  149. package/src/prove/zenon/isar.ts +1 -1
  150. package/src/prove/zenon/llproof.ts +1 -1
  151. package/src/prove/zenon/mltoll.ts +1 -1
  152. package/src/prove/zenon/node.ts +1 -1
  153. package/src/prove/zenon/search.ts +1 -1
  154. package/src/prove/zenon/tla/terms.ts +1 -20
  155. package/src/prove/zenon/tla/tla.ts +1 -1
  156. package/src/randomization.ts +19 -24
  157. package/src/resolve.ts +15 -22
  158. package/src/runtime.ts +8 -8
  159. package/src/{sany-builtins.ts → sany/builtins.ts} +1 -1
  160. package/src/{sany-generator.ts → sany/generator.ts} +38 -55
  161. package/src/{sany-levels.ts → sany/levels.ts} +45 -48
  162. package/src/{sany-lexer.ts → sany/lexer.ts} +2 -3
  163. package/src/{sany-linter.ts → sany/linter.ts} +1 -1
  164. package/src/{sany-modules.ts → sany/modules.ts} +2 -2
  165. package/src/{sany-nodes.ts → sany/nodes.ts} +2 -2
  166. package/src/{sany-parse-error.ts → sany/parse-error.ts} +2 -2
  167. package/src/{sany-report.ts → sany/report.ts} +16 -17
  168. package/src/{sany-selectors.ts → sany/selectors.ts} +3 -5
  169. package/src/{sany-source.ts → sany/source.ts} +6 -7
  170. package/src/{sany-xml.ts → sany/xml.ts} +5 -6
  171. package/src/search.ts +969 -0
  172. package/src/spec-description.ts +26 -20
  173. package/src/{standard-levels.ts → standard-definitions.ts} +118 -2
  174. package/src/standard-modules.ts +16 -20
  175. package/src/state-graph.ts +9 -8
  176. package/src/substitution-levels.ts +2 -2
  177. package/src/successors.ts +16 -19
  178. package/src/symmetry.ts +1 -1
  179. package/src/tableau.ts +6 -7
  180. package/src/tlc/fingerprint.ts +214 -0
  181. package/src/{tlc-messages.ts → tlc/messages.ts} +119 -7
  182. package/src/{tlc-order.ts → tlc/order.ts} +7 -7
  183. package/src/{tlc-random.ts → tlc/random.ts} +3 -213
  184. package/src/{tlc-replay.ts → tlc/replay.ts} +40 -36
  185. package/src/{tlc-module.ts → tlc/tlc-operators.ts} +9 -9
  186. package/src/{tlc-ext.ts → tlc/tlcext-operators.ts} +30 -25
  187. package/src/transfer.ts +32 -32
  188. package/src/values.ts +72 -67
  189. package/src/worker.ts +1 -4
  190. package/dist/run-cli.cjs +0 -45
  191. package/dist/run-cli.js +0 -45
  192. package/src/canonical.ts +0 -40
  193. package/src/obligations/ctx.ts +0 -64
  194. package/src/prove/prep/defs.ts +0 -33
  195. package/src/prove/prep/elab.ts +0 -156
  196. package/src/prove/prep/enabled.ts +0 -43
  197. package/src/prove/prep/flatten.ts +0 -70
  198. package/src/prove/prep/trivial.ts +0 -22
  199. package/src/prove/smt/axiomatize.ts +0 -69
  200. package/src/prove/smt/simplify.ts +0 -57
  201. package/src/run-cli.ts +0 -1806
  202. package/src/standard-ranges.ts +0 -116
  203. package/src/value-sources.ts +0 -29
  204. /package/src/prove/prep/{pragma.ts → methods.ts} +0 -0
  205. /package/src/{tlc-modules.ts → tlc/jar-data.ts} +0 -0
  206. /package/src/{tlc-summary.ts → tlc/summary.ts} +0 -0
  207. /package/src/{tlc-version.ts → tlc/version.ts} +0 -0
@@ -1,53 +1,34 @@
1
- // A port of tlapm's module pipeline: flattening EXTENDS (Module.Flatten), normalization
2
- // (Module.Elab.normalize) and obligation generation (Module.Gen).
1
+ // tlapm's module units, with the standard modules, flattening EXTENDS (Module.Flatten), the
2
+ // modules a module depends on (Module.Dep), and substitution in units (Module.Subst).
3
3
 
4
4
  import { TlaProofError, TlapmBugError } from "../errors";
5
- import { lambdify } from "./action";
6
- import type { Anonymizer } from "./anon";
7
5
  import {
8
- adjoinAll,
9
6
  at,
10
- bumpBy,
11
- consAll,
12
- consSubstitution,
13
7
  exprifySequent,
14
- findNamed,
15
- getAtPrefix,
16
- getLocusText,
17
- getLocusPrefix,
18
- getScopeHyps,
19
- mapAccumulate,
8
+ getFact,
20
9
  getFresh,
21
- isEqualHyp,
22
- shiftExpr,
23
- substituteDefn,
24
- substituteExpr,
25
- substituteExprs,
26
- substituteHyp,
27
- substituteSequent,
28
- shift,
10
+ mapAccumulate,
29
11
  type Builtin,
30
12
  type Defn,
31
13
  type Expr,
32
14
  type Hyp,
33
15
  type InstanceDefinition,
34
16
  type Locus,
35
- type ObligationWarning,
36
- type Scope,
37
17
  type Sequent,
38
- type Substitution,
39
18
  type Visibility,
40
19
  type WhereDefined,
41
20
  } from "./expression";
21
+ import type { Proof, Usable } from "./proof";
42
22
  import {
43
- EMPTY_SUMMARY,
44
- getProofSummary,
45
- joinSummaries,
46
- type Generator,
47
- type ProofSummary,
48
- } from "./generate";
49
- import { getUnique, type Counter, type Obligation, type Proof, type Usable } from "./proof";
50
- import { getScopeTime } from "./temporal";
23
+ bumpBy,
24
+ shift,
25
+ shiftExpr,
26
+ substituteDefn,
27
+ substituteExpr,
28
+ substituteExprs,
29
+ substituteSequent,
30
+ type Substitution,
31
+ } from "./substitution";
51
32
 
52
33
  export type ModuleUnit = ModuleUnitCore & { location?: Locus };
53
34
 
@@ -70,7 +51,7 @@ type ModuleUnitCore =
70
51
  proof: Proof;
71
52
  }
72
53
  | { kind: "Submod"; module: Mule }
73
- | { kind: "Mutate"; mode: "Use" | "Hide"; isSuppressed: boolean; usable: Usable }
54
+ | { kind: "Mutate"; mode: "Use" | "Hide"; usable: Usable }
74
55
  | { kind: "Anoninst"; instance: InstanceDefinition; isLocal: boolean };
75
56
 
76
57
  // depth is the size of the context the module was normalized in, which instantiation shifts
@@ -86,34 +67,29 @@ export interface Mule {
86
67
  location?: Locus;
87
68
  }
88
69
 
89
- const getBuiltinConstant = (name: string, builtin: Builtin): ModuleUnit => ({
90
- kind: "Definition",
91
- definition: { kind: "Operator", name, body: { kind: "Internal", builtin } },
92
- whereDefined: "Builtin",
93
- visibility: "Visible",
94
- isLocal: false,
95
- });
96
-
97
- const getBuiltinOperator = (arity: number, name: string, builtin: Builtin): ModuleUnit => ({
70
+ const defineBuiltin = (arity: number, name: string, builtin: Builtin): ModuleUnit => ({
98
71
  kind: "Definition",
99
72
  definition: {
100
73
  kind: "Operator",
101
74
  name,
102
- body: {
103
- kind: "Lambda",
104
- params: Array.from({ length: arity }, (_item, index) => ({
105
- name: `x${index + 1}`,
106
- shape: 0,
107
- })),
108
- body: {
109
- kind: "Apply",
110
- operator: { kind: "Internal", builtin },
111
- args: Array.from({ length: arity }, (_item, index) => ({
112
- kind: "Ix",
113
- index: arity - index,
114
- })),
115
- },
116
- },
75
+ body:
76
+ arity === 0
77
+ ? { kind: "Internal", builtin }
78
+ : {
79
+ kind: "Lambda",
80
+ params: Array.from({ length: arity }, (_item, index) => ({
81
+ name: `x${index + 1}`,
82
+ shape: 0,
83
+ })),
84
+ body: {
85
+ kind: "Apply",
86
+ operator: { kind: "Internal", builtin },
87
+ args: Array.from({ length: arity }, (_item, index) => ({
88
+ kind: "Ix",
89
+ index: arity - index,
90
+ })),
91
+ },
92
+ },
117
93
  },
118
94
  whereDefined: "Builtin",
119
95
  visibility: "Visible",
@@ -121,62 +97,58 @@ const getBuiltinOperator = (arity: number, name: string, builtin: Builtin): Modu
121
97
  });
122
98
 
123
99
  const NATURALS: ModuleUnit[] = [
124
- getBuiltinConstant("Nat", "Nat"),
125
- getBuiltinOperator(2, "+", "Plus"),
126
- getBuiltinOperator(2, "-", "Minus"),
127
- getBuiltinOperator(2, "*", "Times"),
128
- getBuiltinOperator(2, "^", "Exp"),
129
- getBuiltinOperator(2, "<", "Lt"),
130
- getBuiltinOperator(2, ">", "Gt"),
131
- getBuiltinOperator(2, "=<", "Lteq"),
132
- getBuiltinOperator(2, ">=", "Gteq"),
133
- getBuiltinOperator(2, "%", "Remainder"),
134
- getBuiltinOperator(2, "\\div", "Quotient"),
135
- getBuiltinOperator(2, "..", "Range"),
100
+ defineBuiltin(0, "Nat", "Nat"),
101
+ defineBuiltin(2, "+", "Plus"),
102
+ defineBuiltin(2, "-", "Minus"),
103
+ defineBuiltin(2, "*", "Times"),
104
+ defineBuiltin(2, "^", "Exp"),
105
+ defineBuiltin(2, "<", "Lt"),
106
+ defineBuiltin(2, ">", "Gt"),
107
+ defineBuiltin(2, "=<", "Lteq"),
108
+ defineBuiltin(2, ">=", "Gteq"),
109
+ defineBuiltin(2, "%", "Remainder"),
110
+ defineBuiltin(2, "\\div", "Quotient"),
111
+ defineBuiltin(2, "..", "Range"),
136
112
  ];
137
113
 
138
- const INTEGERS = [
139
- ...NATURALS,
140
- getBuiltinConstant("Int", "Int"),
141
- getBuiltinOperator(1, "-.", "Uminus"),
142
- ];
114
+ const INTEGERS = [...NATURALS, defineBuiltin(0, "Int", "Int"), defineBuiltin(1, "-.", "Uminus")];
143
115
 
144
116
  const REALS = [
145
117
  ...INTEGERS,
146
- getBuiltinConstant("Real", "Real"),
147
- getBuiltinOperator(2, "/", "Ratio"),
148
- getBuiltinConstant("Infinity", "Infinity"),
118
+ defineBuiltin(0, "Real", "Real"),
119
+ defineBuiltin(2, "/", "Ratio"),
120
+ defineBuiltin(0, "Infinity", "Infinity"),
149
121
  ];
150
122
 
151
123
  const SEQUENCES = [
152
- getBuiltinOperator(1, "Seq", "Seq"),
153
- getBuiltinOperator(1, "Len", "Len"),
154
- getBuiltinOperator(2, "BSeq", "BSeq"),
155
- getBuiltinOperator(2, "\\o", "Cat"),
156
- getBuiltinOperator(2, "Append", "Append"),
157
- getBuiltinOperator(1, "Head", "Head"),
158
- getBuiltinOperator(1, "Tail", "Tail"),
159
- getBuiltinOperator(3, "SubSeq", "SubSeq"),
160
- getBuiltinOperator(2, "SelectSeq", "SelectSeq"),
124
+ defineBuiltin(1, "Seq", "Seq"),
125
+ defineBuiltin(1, "Len", "Len"),
126
+ defineBuiltin(2, "BSeq", "BSeq"),
127
+ defineBuiltin(2, "\\o", "Cat"),
128
+ defineBuiltin(2, "Append", "Append"),
129
+ defineBuiltin(1, "Head", "Head"),
130
+ defineBuiltin(1, "Tail", "Tail"),
131
+ defineBuiltin(3, "SubSeq", "SubSeq"),
132
+ defineBuiltin(2, "SelectSeq", "SelectSeq"),
161
133
  ];
162
134
 
163
135
  const TLC = [
164
- getBuiltinOperator(2, "Print", "Print"),
165
- getBuiltinOperator(1, "PrintT", "PrintT"),
166
- getBuiltinOperator(2, "Assert", "Assert"),
167
- getBuiltinConstant("JavaTime", "JavaTime"),
168
- getBuiltinOperator(1, "TLCGet", "TLCGet"),
169
- getBuiltinOperator(2, "TLCSet", "TLCSet"),
170
- getBuiltinOperator(2, ":>", "OneArg"),
171
- getBuiltinOperator(2, "@@", "Extend"),
172
- getBuiltinOperator(1, "Permutations", "Permutations"),
173
- getBuiltinOperator(2, "SortSeq", "SortSeq"),
174
- getBuiltinOperator(1, "RandomElement", "RandomElement"),
175
- getBuiltinConstant("Any", "Any"),
176
- getBuiltinOperator(1, "ToString", "ToString"),
136
+ defineBuiltin(2, "Print", "Print"),
137
+ defineBuiltin(1, "PrintT", "PrintT"),
138
+ defineBuiltin(2, "Assert", "Assert"),
139
+ defineBuiltin(0, "JavaTime", "JavaTime"),
140
+ defineBuiltin(1, "TLCGet", "TLCGet"),
141
+ defineBuiltin(2, "TLCSet", "TLCSet"),
142
+ defineBuiltin(2, ":>", "OneArg"),
143
+ defineBuiltin(2, "@@", "Extend"),
144
+ defineBuiltin(1, "Permutations", "Permutations"),
145
+ defineBuiltin(2, "SortSeq", "SortSeq"),
146
+ defineBuiltin(1, "RandomElement", "RandomElement"),
147
+ defineBuiltin(0, "Any", "Any"),
148
+ defineBuiltin(1, "ToString", "ToString"),
177
149
  ];
178
150
 
179
- const getStandard = (name: string, body: ModuleUnit[]): Mule => ({
151
+ const getStandardModule = (name: string, body: ModuleUnit[]): Mule => ({
180
152
  name,
181
153
  extendees: [],
182
154
  body,
@@ -187,25 +159,20 @@ const getStandard = (name: string, body: ModuleUnit[]): Mule => ({
187
159
  // Module.Standard.initctx, apart from $TLAPM, whose Builtins! names no module of the corpora uses.
188
160
  export const STANDARD_MODULES = new Map(
189
161
  [
190
- getStandard("Naturals", NATURALS),
191
- getStandard("Integers", INTEGERS),
192
- getStandard("Reals", REALS),
193
- getStandard("Sequences", SEQUENCES),
194
- getStandard("TLC", TLC),
162
+ getStandardModule("Naturals", NATURALS),
163
+ getStandardModule("Integers", INTEGERS),
164
+ getStandardModule("Reals", REALS),
165
+ getStandardModule("Sequences", SEQUENCES),
166
+ getStandardModule("TLC", TLC),
195
167
  ].map((module) => [module.name, module]),
196
168
  );
197
169
 
198
- const getUnitHyps = (unit: ModuleUnit): Hyp[] => {
170
+ export const getUnitHyps = (unit: ModuleUnit): Hyp[] => {
199
171
  const location = unit.location;
200
172
  switch (unit.kind) {
201
173
  case "Constants":
202
174
  return unit.declarations.map((declaration) => ({
203
- kind: "Fresh",
204
- name: declaration.name,
205
- shape: declaration.shape,
206
- level: "Constant",
207
- domain: undefined,
208
- domainVisibility: "Visible",
175
+ ...getFresh(declaration.name, "Constant", declaration.shape),
209
176
  location,
210
177
  }));
211
178
  case "Recursives":
@@ -250,18 +217,14 @@ const getUnitHyps = (unit: ModuleUnit): Hyp[] => {
250
217
  unit,
251
218
  );
252
219
  return unit.name === undefined
253
- ? [{ kind: "Fact", expression, visibility: "Hidden", time: "Always", location }]
220
+ ? [getFact(expression, "Hidden", "Always", location)]
254
221
  : getNamedFact(unit.name, expression, location);
255
222
  }
256
223
  case "Mutate":
257
224
  return unit.mode === "Use"
258
- ? unit.usable.facts.map((fact, index) => ({
259
- kind: "Fact",
260
- expression: shiftExpr(index, fact),
261
- visibility: "Visible",
262
- time: "Always",
263
- location,
264
- }))
225
+ ? unit.usable.facts.map((fact, index) =>
226
+ getFact(shiftExpr(index, fact), "Visible", "Always", location),
227
+ )
265
228
  : [];
266
229
  case "Submod":
267
230
  case "Anoninst":
@@ -269,7 +232,7 @@ const getUnitHyps = (unit: ModuleUnit): Hyp[] => {
269
232
  }
270
233
  };
271
234
 
272
- const getHypSize = (unit: ModuleUnit) =>
235
+ export const getHypSize = (unit: ModuleUnit) =>
273
236
  unit.kind === "Axiom" || unit.kind === "Theorem"
274
237
  ? unit.name === undefined
275
238
  ? 1
@@ -285,13 +248,7 @@ const getNamedFact = (name: string, expression: Expr, location: Locus | undefine
285
248
  isLocal: false,
286
249
  location,
287
250
  },
288
- {
289
- kind: "Fact",
290
- expression: { kind: "Ix", index: 1, location },
291
- visibility: "Hidden",
292
- time: "Always",
293
- location,
294
- },
251
+ getFact({ kind: "Ix", index: 1, location }, "Hidden", "Always", location),
295
252
  ];
296
253
 
297
254
  // Module.Flatten.exports: what an extending module sees, with local definitions inlined like
@@ -390,16 +347,6 @@ const isInstanceDefinition = (value: unknown): value is InstanceDefinition =>
390
347
  export const compareNames = (left: string, right: string) =>
391
348
  left < right ? -1 : left > right ? 1 : 0;
392
349
 
393
- // latestModules is the module context of the latest anonymization of an axiom, theorem or USE,
394
- // which tlapm's anonymizer keeps using for the instances inside later definitions.
395
- export interface Pipeline {
396
- anonymizer: Anonymizer;
397
- generator: Generator;
398
- salts: Counter;
399
- latestModules: Map<string, Mule>;
400
- onWarning: (warning: ObligationWarning) => void;
401
- }
402
-
403
350
  const substituteUsable = (substitution: Substitution, usable: Usable): Usable => ({
404
351
  facts: substituteExprs(substitution, usable.facts),
405
352
  defs: usable.defs.map((def) => {
@@ -467,339 +414,11 @@ const substituteUnit = (
467
414
  }
468
415
  };
469
416
 
470
- const substituteUnits = (substitution: Substitution, units: ModuleUnit[]) =>
417
+ export const substituteUnits = (substitution: Substitution, units: ModuleUnit[]) =>
471
418
  mapAccumulate(substitution, units, substituteUnit)[1];
472
419
 
473
- const lambdifyTheorem = (
474
- pipeline: Pipeline,
475
- scope: Scope | undefined,
476
- name: string | undefined,
477
- sequent: Sequent,
478
- ) => {
479
- try {
480
- const lambdified = lambdify(pipeline.anonymizer, pipeline.onWarning, scope, {
481
- kind: "Sequent",
482
- sequent,
483
- });
484
- if (lambdified.kind !== "Sequent") throw new TlapmBugError();
485
- return lambdified.sequent;
486
- } catch (error) {
487
- if (!(error instanceof TlaProofError) || error.failure === undefined) throw error;
488
- const location = sequent.active.location;
489
- const message = `${error.failure}\nCould not instantiate the theorem ${name === undefined ? "" : `named: ${name}, `}at: ${location ? getLocusText(location) : "<unknown location>"}`;
490
- pipeline.onWarning({ text: `${getAtPrefix(location)}[ERROR]${message}`, channel: "stdout" });
491
- pipeline.onWarning({ text: message, channel: "toolboxOnly" });
492
- return { context: [], active: at({ kind: "Internal", builtin: "TRUE" }, sequent.active) };
493
- }
494
- };
495
-
496
- const lambdifyUnit = (pipeline: Pipeline, scope: Scope | undefined, unit: ModuleUnit) => {
497
- if (unit.kind === "Theorem") {
498
- return { ...unit, sequent: lambdifyTheorem(pipeline, scope, unit.name, unit.sequent) };
499
- }
500
- if (unit.kind !== "Definition") return unit;
501
- const definition = unit.definition;
502
- if (definition.kind !== "Operator" && definition.kind !== "Bpragma") return unit;
503
- const body = lambdify(pipeline.anonymizer, pipeline.onWarning, scope, definition.body);
504
- return { ...unit, definition: { ...definition, body } };
505
- };
506
-
507
- // lambdify_enabled_cdot: the ENABLED and \cdot of each definition and theorem statement bind
508
- // their variables before instantiation substitutes for them. A theorem that cannot be lambdified
509
- // states TRUE.
510
- const lambdifyUnits = (
511
- pipeline: Pipeline,
512
- scope: Scope | undefined,
513
- units: ModuleUnit[],
514
- ): [Scope | undefined, ModuleUnit[]] =>
515
- mapAccumulate(scope, units, (current, unit): [Scope | undefined, ModuleUnit] => {
516
- if (unit.kind === "Submod") {
517
- const [inner, body] = lambdifyUnits(pipeline, current, unit.module.body);
518
- return [inner, { ...unit, module: { ...unit.module, body } }];
519
- }
520
- const lambdified = lambdifyUnit(pipeline, current, unit);
521
- return [adjoinAll(current, getUnitHyps(lambdified)), lambdified];
522
- });
523
-
524
- // apply_subst: each parameter declaration of the instancee gives way to its substitute.
525
- const applyParameters = (units: ModuleUnit[], substitutes: Map<string, Expr>) => {
526
- const body: ModuleUnit[] = [];
527
- let size = 0;
528
- let rest = units;
529
- while (rest.length > 0) {
530
- const [unit, ...tail] = rest;
531
- const split =
532
- unit.kind === "Constants"
533
- ? {
534
- name: unit.declarations[0].name,
535
- remaining: { ...unit, declarations: unit.declarations.slice(1) },
536
- }
537
- : unit.kind === "Variables"
538
- ? { name: unit.names[0], remaining: { ...unit, names: unit.names.slice(1) } }
539
- : undefined;
540
- if (split) {
541
- const substitute = substitutes.get(split.name);
542
- if (!substitute) throw new TlaProofError(`Parameter ${split.name} has no substitute`);
543
- const isEmpty = getHypSize(split.remaining) === 0;
544
- rest = substituteUnits(
545
- consSubstitution(shiftExpr(size, substitute), shift(0)),
546
- isEmpty ? tail : [split.remaining, ...tail],
547
- );
548
- continue;
549
- }
550
- body.push(unit);
551
- size += getHypSize(unit);
552
- rest = tail;
553
- }
554
- return body;
555
- };
556
-
557
- // resub_for: references to the instancee's own units become applications to the instance
558
- // arguments, which the definitions now bind themselves.
559
- const getLocalSubstitution = (
560
- count: number,
561
- argumentCount: number,
562
- location: Locus | undefined,
563
- ): Substitution => {
564
- const args = Array.from({ length: argumentCount }, (_item, index) =>
565
- at({ kind: "Ix", index: argumentCount - index }, { location }),
566
- );
567
- const parameters = Array.from({ length: argumentCount }, (_item, index) =>
568
- at({ kind: "Ix", index: index + 1 }, { location }),
569
- );
570
- const locals = Array.from({ length: count }, (_item, index): Expr => {
571
- const operator = at({ kind: "Ix", index: index + argumentCount + 1 }, { location });
572
- return argumentCount > 0 ? at({ kind: "Apply", operator, args }, { location }) : operator;
573
- });
574
- return consAll([...locals, ...parameters].reverse(), shift(count + argumentCount));
575
- };
576
-
577
- const addParameters = (expression: Expr, args: string[]): Expr => {
578
- const params = args.map((name) => ({ name, shape: 0 }));
579
- if (expression.kind === "Lambda")
580
- return { ...expression, params: [...params, ...expression.params] };
581
- return args.length === 0
582
- ? expression
583
- : at({ kind: "Lambda", params, body: expression }, expression);
584
- };
585
-
586
- // localize: renames the instancee's units under the instance name, salts its local definitions
587
- const localize = (
588
- pipeline: Pipeline,
589
- units: ModuleUnit[],
590
- prefix: string,
591
- instance: InstanceDefinition,
592
- isLocal: boolean,
593
- location: Locus | undefined,
594
- ) => {
595
- const getName = (name: string) => (prefix === "" ? name : `${prefix}!${name}`);
596
- const argumentCount = instance.args.length;
597
- const body: ModuleUnit[] = [];
598
- let size = 0;
599
- let rest = units;
600
- let isComplained = argumentCount === 0;
601
- const complain = (text: string) => {
602
- if (isComplained) return;
603
- isComplained = true;
604
- pipeline.onWarning({ text, channel: "stderr" });
605
- };
606
- while (rest.length > 0) {
607
- const [unit, ...tail] = rest;
608
- rest = tail;
609
- const localized = (expression: Expr) =>
610
- addParameters(
611
- substituteExpr(getLocalSubstitution(size, argumentCount, location), expression),
612
- instance.args,
613
- );
614
- switch (unit.kind) {
615
- case "Definition": {
616
- const definition = unit.definition;
617
- if (definition.kind !== "Operator" && definition.kind !== "Bpragma") {
618
- throw new TlaProofError("Module.Elab.localize");
619
- }
620
- const name = unit.isLocal
621
- ? `${definition.name}$${getUnique(pipeline.salts)}`
622
- : definition.name;
623
- body.push({
624
- ...unit,
625
- definition: { ...definition, name: getName(name), body: localized(definition.body) },
626
- whereDefined: unit.isLocal ? "Builtin" : unit.whereDefined,
627
- isLocal: unit.isLocal || isLocal,
628
- });
629
- size += 1;
630
- continue;
631
- }
632
- case "Axiom": {
633
- complain(
634
- `${getLocusPrefix(location)}Instancing produces parametric axioms.\nSuch axioms will be forcibly hidden and cannot be cited.\n(This warning appears at-most once per INSTANCE declaration.)`,
635
- );
636
- const axiom: ModuleUnit = {
637
- ...unit,
638
- name: unit.name === undefined ? undefined : getName(unit.name),
639
- expression: localized(unit.expression),
640
- };
641
- body.push(axiom);
642
- size += getHypSize(axiom);
643
- continue;
644
- }
645
- case "Theorem": {
646
- complain(
647
- `${getAtPrefix(location)}Warning: Instancing produces parametric theorems.\nSuch theorems will be forcibly hidden and cannot be cited.\n(This warning appears at-most once per INSTANCE declaration.)`,
648
- );
649
- const expression = localized(at(exprifySequent(unit.sequent), unit));
650
- body.push({
651
- ...unit,
652
- name: unit.name === undefined ? undefined : getName(unit.name),
653
- sequent:
654
- expression.kind === "Sequent"
655
- ? expression.sequent
656
- : { context: [], active: expression },
657
- proof: { kind: "Omitted", omission: "Elsewhere", location: unit.location },
658
- });
659
- size += 1;
660
- continue;
661
- }
662
- case "Mutate":
663
- if (unit.mode === "Use") rest = substituteUnits(shift(-unit.usable.facts.length), rest);
664
- continue;
665
- case "Submod":
666
- continue;
667
- default:
668
- throw new TlaProofError("Module.Elab.localize");
669
- }
670
- }
671
- return body;
672
- };
673
-
674
- // localize_axioms: an axiom becomes a hypothesis of each theorem after it, and a named one also a
675
- // definition.
676
- const localizeAxioms = (units: ModuleUnit[]) => {
677
- const body: ModuleUnit[] = [];
678
- let rest = units;
679
- while (rest.length > 0) {
680
- const [unit, ...tail] = rest;
681
- if (unit.kind !== "Axiom") {
682
- body.push(unit);
683
- rest = tail;
684
- continue;
685
- }
686
- const location = unit.location;
687
- if (unit.name !== undefined) {
688
- body.push({
689
- kind: "Definition",
690
- definition: { kind: "Operator", name: unit.name, body: unit.expression, location },
691
- whereDefined: { kind: "Proof", time: "Always" },
692
- visibility: "Visible",
693
- isLocal: false,
694
- location,
695
- });
696
- }
697
- const hyp: Hyp = {
698
- kind: "Fact",
699
- expression:
700
- unit.name === undefined
701
- ? shiftExpr(1, unit.expression)
702
- : at({ kind: "Ix", index: 2 }, unit),
703
- visibility: "Visible",
704
- time: "Always",
705
- location,
706
- };
707
- let distance = 0;
708
- const inserted = tail.map((next): ModuleUnit => {
709
- const size = distance;
710
- distance += getHypSize(next);
711
- if (next.kind !== "Theorem") return next;
712
- const sequent = substituteSequent(shift(1), next.sequent);
713
- return {
714
- ...next,
715
- sequent: { ...sequent, context: [substituteHyp(shift(size), hyp), ...sequent.context] },
716
- axiomCount: next.axiomCount + 1,
717
- };
718
- });
719
- rest = substituteUnits(shift(-1), inserted);
720
- }
721
- return body;
722
- };
723
-
724
- const getParameters = (module: Mule) =>
725
- new Set(
726
- module.body.flatMap((unit) =>
727
- unit.kind === "Constants"
728
- ? unit.declarations.map((declaration) => declaration.name)
729
- : unit.kind === "Variables"
730
- ? unit.names
731
- : [],
732
- ),
733
- );
734
-
735
- // Module.Elab.instantiate: the units of an instantiated module, in the context of the instance.
736
- const instantiate = (
737
- pipeline: Pipeline,
738
- modules: Map<string, Mule>,
739
- scope: Scope | undefined,
740
- instance: InstanceDefinition,
741
- isLocal: boolean,
742
- prefix: string,
743
- location: Locus | undefined,
744
- ) => {
745
- const module = modules.get(instance.module);
746
- if (!module) throw new TlaProofError(`Module "${instance.module}" unknown`);
747
- const parameters = getParameters(module);
748
- for (const substitution of instance.substitutions) {
749
- if (!parameters.has(substitution.name)) {
750
- throw new TlaProofError(
751
- `Parameter ${substitution.name} occurs in the statement \`INSTANCE ${instance.module} WITH\`, and is not declared in the module ${instance.module}`,
752
- );
753
- }
754
- }
755
- const instanceScope = adjoinAll(
756
- scope,
757
- instance.args.map((name) => getFresh(name, "Unknown")),
758
- );
759
- const substitutes = new Map(
760
- instance.substitutions.map((entry) => [entry.name, entry.expression]),
761
- );
762
- for (const name of [...parameters].sort(compareNames)) {
763
- if (substitutes.has(name)) continue;
764
- if (!findNamed(instanceScope, name)) {
765
- throw new TlaProofError(
766
- `Required parameter ${name} for module ${instance.module} could not be inferred.`,
767
- );
768
- }
769
- substitutes.set(name, at({ kind: "Opaque", name }, { location }));
770
- }
771
- const anonymized = new Map(
772
- [...substitutes].map(([name, expression]) => [
773
- name,
774
- pipeline.anonymizer.expr(instanceScope, expression),
775
- ]),
776
- );
777
- const body = substituteUnits(
778
- shift((instanceScope?.size ?? 0) - (module.depth ?? 0)),
779
- module.body.map((unit): ModuleUnit =>
780
- unit.kind === "Theorem"
781
- ? {
782
- ...unit,
783
- proof: { kind: "Omitted", omission: "Implicit", location: unit.proof.location },
784
- }
785
- : unit,
786
- ),
787
- );
788
- const [, lambdified] = lambdifyUnits(pipeline, instanceScope, body);
789
- return localizeAxioms(
790
- localize(
791
- pipeline,
792
- applyParameters(lambdified, anonymized),
793
- prefix,
794
- instance,
795
- isLocal,
796
- location,
797
- ),
798
- );
799
- };
800
-
801
420
  // A named theorem binds its name as a proof definition, which its statement shifts past.
802
- const bindTheoremName = (
421
+ export const bindTheoremName = (
803
422
  name: string | undefined,
804
423
  sequent: Sequent,
805
424
  location: Locus | undefined,
@@ -824,242 +443,3 @@ const bindTheoremName = (
824
443
  ],
825
444
  sequent: substituteSequent(shift(1), sequent),
826
445
  };
827
-
828
- // make_defs: the definitions among the units an INSTANCE inside a LET or DEFINE stands for.
829
- export const expandInstance = (
830
- pipeline: Pipeline,
831
- scope: Scope | undefined,
832
- definition: Extract<Defn, { kind: "Instance" }>,
833
- ): Defn[] => {
834
- const name = definition.instance.module;
835
- if (!pipeline.latestModules.has(name)) {
836
- pipeline.onWarning({
837
- text: `${getLocusPrefix(definition.instance.location)}Module ${JSON.stringify(name)} unknown\n`,
838
- channel: "toolbox",
839
- });
840
- throw new TlaProofError(`Module ${JSON.stringify(name)} unknown`, {
841
- failure: "Module.Elab.anon#defns",
842
- });
843
- }
844
- const units = instantiate(
845
- pipeline,
846
- pipeline.latestModules,
847
- scope,
848
- definition.instance,
849
- true,
850
- definition.name,
851
- definition.location,
852
- );
853
- const definitions: Defn[] = [];
854
- let rest = units;
855
- while (rest.length > 0) {
856
- const [unit, ...tail] = rest;
857
- if (unit.kind !== "Definition") {
858
- rest = substituteUnits(shift(-getHypSize(unit)), tail);
859
- continue;
860
- }
861
- definitions.push(unit.definition);
862
- rest = tail;
863
- }
864
- return definitions;
865
- };
866
-
867
- // Module.Elab.normalize: anonymizes each unit in the context of the ones before it, expands
868
- // instances, merges repeated definitions, and simplifies the proofs of important modules. The
869
- // result also joins the modules that later instances can name.
870
- export const normalize = (
871
- pipeline: Pipeline,
872
- modules: Map<string, Mule>,
873
- scope: Scope | undefined,
874
- module: Mule,
875
- ): Mule => {
876
- const body: ModuleUnit[] = [];
877
- let current = scope;
878
- const emit = (unit: ModuleUnit) => {
879
- body.push(unit);
880
- current = adjoinAll(current, getUnitHyps(unit));
881
- };
882
- const isRedundant = (name: string | undefined) =>
883
- name !== undefined && findNamed(current, name) !== undefined;
884
- // Instantiated units arrive anonymized.
885
- const queue = module.body.map((unit) => ({ unit, isAnonymized: false }));
886
- for (let index = 0; index < queue.length; index++) {
887
- const unit = queue[index].unit;
888
- const expand = (instance: InstanceDefinition, isLocal: boolean, prefix: string) => {
889
- const units = instantiate(
890
- pipeline,
891
- modules,
892
- current,
893
- instance,
894
- isLocal,
895
- prefix,
896
- unit.location,
897
- );
898
- queue.splice(index + 1, 0, ...units.map((inner) => ({ unit: inner, isAnonymized: true })));
899
- };
900
- switch (unit.kind) {
901
- case "Anoninst":
902
- expand(unit.instance, unit.isLocal, "");
903
- continue;
904
- case "Definition": {
905
- const definition = unit.definition;
906
- if (definition.kind === "Instance") {
907
- expand(definition.instance, unit.isLocal, definition.name);
908
- continue;
909
- }
910
- const anonymized =
911
- definition.kind === "Recursive" || queue[index].isAnonymized
912
- ? definition
913
- : pipeline.anonymizer.defn(current, definition);
914
- const normalized: ModuleUnit = { ...unit, definition: anonymized };
915
- if (definition.kind === "Recursive") {
916
- emit(normalized);
917
- continue;
918
- }
919
- const hyp = getUnitHyps(normalized)[0];
920
- const found = findNamed(current, definition.name);
921
- if (found?.hyp.kind === "Defn") {
922
- const isMerged =
923
- found.hyp.definition.kind === "Recursive" ||
924
- isEqualHyp(substituteHyp(shift(found.depth + 1), found.hyp), hyp);
925
- if (isMerged) {
926
- const rest = queue.slice(index + 1);
927
- const substituted = substituteUnits(
928
- consSubstitution(at({ kind: "Ix", index: found.depth + 1 }, unit), shift(0)),
929
- rest.map((entry) => entry.unit),
930
- );
931
- queue.splice(
932
- index + 1,
933
- rest.length,
934
- ...rest.map((entry, offset) => ({ ...entry, unit: substituted[offset] })),
935
- );
936
- continue;
937
- }
938
- }
939
- emit(normalized);
940
- continue;
941
- }
942
- case "Recursives":
943
- case "Constants":
944
- case "Variables":
945
- emit(unit);
946
- continue;
947
- case "Axiom":
948
- if (isRedundant(unit.name)) continue;
949
- pipeline.latestModules = new Map(modules);
950
- emit({ ...unit, expression: pipeline.anonymizer.expr(current, unit.expression) });
951
- continue;
952
- case "Theorem": {
953
- const isDuplicate = isRedundant(unit.name);
954
- const name = isDuplicate ? `(redundant)${unit.name}` : unit.name;
955
- const proof: Proof = isDuplicate
956
- ? { kind: "Obvious", location: unit.proof.location }
957
- : unit.proof;
958
- pipeline.latestModules = new Map(modules);
959
- const sequent = pipeline.anonymizer.sequent(current, unit.sequent);
960
- const binding = bindTheoremName(name, sequent, unit.location);
961
- const proofScope = adjoinAll(
962
- adjoinAll(
963
- current,
964
- binding.hyps.map((hyp) => ({ ...hyp, isConstnessUnset: true })),
965
- ),
966
- binding.sequent.context,
967
- );
968
- const anonymized = pipeline.anonymizer.proof(proofScope, proof);
969
- const simplified = module.isImportant
970
- ? pipeline.generator.simplify(
971
- getScopeHyps(proofScope),
972
- binding.sequent.active,
973
- anonymized,
974
- getScopeTime(binding.sequent.context, "Always"),
975
- )
976
- : anonymized;
977
- emit({ ...unit, name, sequent, proof: simplified });
978
- continue;
979
- }
980
- case "Mutate":
981
- pipeline.latestModules = new Map(modules);
982
- emit({ ...unit, usable: pipeline.anonymizer.usable(current, unit.usable) });
983
- continue;
984
- case "Submod":
985
- emit({ ...unit, module: normalize(pipeline, modules, current, unit.module) });
986
- continue;
987
- }
988
- }
989
- const normalized = { ...module, body, depth: scope?.size ?? 0 };
990
- modules.set(module.name, normalized);
991
- return normalized;
992
- };
993
-
994
- export interface TheoremSummary extends ProofSummary {
995
- location: Locus | undefined;
996
- }
997
-
998
- export interface ModuleSummary extends ProofSummary {
999
- theorems: TheoremSummary[];
1000
- }
1001
-
1002
- // Module.Gen.generate.
1003
- export const generate = (
1004
- pipeline: Pipeline,
1005
- context: Hyp[],
1006
- module: Mule,
1007
- ): { obligations: Obligation[]; summary: ModuleSummary } => {
1008
- const obligations: Obligation[] = [];
1009
- const theorems: TheoremSummary[] = [];
1010
- let summary = EMPTY_SUMMARY;
1011
- let current = context;
1012
- for (const unit of module.body) {
1013
- switch (unit.kind) {
1014
- case "Theorem": {
1015
- const binding = bindTheoremName(unit.name, unit.sequent, unit.location);
1016
- const named = [...current, ...binding.hyps];
1017
- const context = [...named, ...binding.sequent.context];
1018
- const proof = pipeline.generator.generate(
1019
- { context, active: binding.sequent.active },
1020
- unit.proof,
1021
- getScopeTime(context, "Always"),
1022
- );
1023
- obligations.push(...pipeline.generator.collect(proof));
1024
- const theorem = getProofSummary(proof);
1025
- theorems.push({ ...theorem, location: unit.location });
1026
- summary = joinSummaries(summary, theorem);
1027
- const fact: Expr =
1028
- unit.name === undefined
1029
- ? at(exprifySequent(unit.sequent), unit)
1030
- : { kind: "Ix", index: 1, location: unit.location };
1031
- current = [
1032
- ...named,
1033
- {
1034
- kind: "Fact",
1035
- expression: fact,
1036
- visibility: "Hidden",
1037
- time: "Always",
1038
- location: unit.location,
1039
- },
1040
- ];
1041
- continue;
1042
- }
1043
- case "Submod": {
1044
- const generated = generate(pipeline, current, unit.module);
1045
- obligations.push(...generated.obligations);
1046
- summary = joinSummaries(summary, generated.summary);
1047
- continue;
1048
- }
1049
- case "Mutate": {
1050
- const [next, generated] = pipeline.generator.mutate(
1051
- current,
1052
- unit.mode,
1053
- unit.usable,
1054
- unit.location,
1055
- );
1056
- obligations.push(...generated);
1057
- current = next;
1058
- continue;
1059
- }
1060
- default:
1061
- current = [...current, ...getUnitHyps(unit)];
1062
- }
1063
- }
1064
- return { obligations, summary: { ...summary, theorems } };
1065
- };