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
@@ -14,6 +14,7 @@ import {
14
14
  getParamFresh,
15
15
  getScopeAt,
16
16
  isBuiltinApply,
17
+ mapChildren,
17
18
  mapScoped,
18
19
  stripProps,
19
20
  type Expr,
@@ -46,14 +47,6 @@ const NESTED_CDOT =
46
47
 
47
48
  const NESTED_CDOT_SPACED = `${NESTED_CDOT} For example, writing \`BY ExpandCdot\`.`;
48
49
 
49
- const mapVisibleChildren = (expression: Expr, map: (child: Expr) => Expr) =>
50
- mapScoped(
51
- undefined,
52
- expression,
53
- (_state, child) => map(child),
54
- () => undefined,
55
- );
56
-
57
50
  const getHyp = (scope: Scope | undefined, index: number) => {
58
51
  const hyp = getScopeAt(scope, index - 1)?.hyp;
59
52
  if (!hyp) throw new TlapmBugError();
@@ -392,7 +385,7 @@ const renameParams = (isKeepingNames: boolean, expression: Expr): Expr => {
392
385
  ],
393
386
  };
394
387
  }
395
- return mapVisibleChildren(expression, (child) => renameParams(isKeepingNames, child));
388
+ return mapChildren(expression, (child) => renameParams(isKeepingNames, child), "visible");
396
389
  };
397
390
 
398
391
  const checkArity = (expression: Expr): Expr => {
@@ -403,7 +396,7 @@ const checkArity = (expression: Expr): Expr => {
403
396
  ) {
404
397
  throw new TlapmBugError();
405
398
  }
406
- return mapVisibleChildren(expression, checkArity);
399
+ return mapChildren(expression, checkArity, "visible");
407
400
  };
408
401
 
409
402
  const lambdifyOperators = (
@@ -516,7 +509,7 @@ const commuteExistsDisjunction = (expression: Expr): Expr => {
516
509
  });
517
510
  }
518
511
  }
519
- return mapVisibleChildren(expression, commuteExistsDisjunction);
512
+ return mapChildren(expression, commuteExistsDisjunction, "visible");
520
513
  };
521
514
 
522
515
  export const expandActionOperators = (
@@ -4,6 +4,7 @@ import { TlapmBugError, TlaProofError } from "../errors";
4
4
  import { consSubstitution, normalizeApply, shift, shiftExpr, substituteExpr } from "./substitution";
5
5
  import { isEqualExpr } from "./equality";
6
6
  import {
7
+ AT_NOWHERE,
7
8
  adjoin,
8
9
  adjoinAll,
9
10
  applyBuiltin,
@@ -16,6 +17,7 @@ import {
16
17
  getLocalDefn,
17
18
  getLocusPrefix,
18
19
  getScopeAt,
20
+ getTrue,
19
21
  mapAccumulate,
20
22
  mapBoundDomains,
21
23
  mapScoped,
@@ -48,7 +50,7 @@ import {
48
50
 
49
51
  const DUMMY_FACT: Hyp = {
50
52
  kind: "Fact",
51
- expression: { kind: "At", isExcept: false },
53
+ expression: AT_NOWHERE,
52
54
  visibility: "Visible",
53
55
  time: "Always",
54
56
  };
@@ -235,7 +237,7 @@ export const createAnonymizer = (
235
237
  text: `${getLocusPrefix(expression.location)}Warning: ${name} does not introduce any assumptions. It does not make sense to use it here.\n`,
236
238
  channel: "toolbox",
237
239
  });
238
- return at({ kind: "Internal", builtin: "TRUE" }, expression);
240
+ return getTrue(expression);
239
241
  }
240
242
  const args = expression.args.map((arg) => anonymizeExpr(context, arg));
241
243
  return resolveName(context, name, args, expression);
@@ -259,6 +259,10 @@ export const at = (core: ExprCore, from: ExprProps): Expr => {
259
259
  return from.isAtomic ? { ...located, isAtomic: true } : located;
260
260
  };
261
261
 
262
+ export const AT_NOWHERE: Expr = { kind: "At", isExcept: false };
263
+
264
+ export const getTrue = (from: ExprProps) => at({ kind: "Internal", builtin: "TRUE" }, from);
265
+
262
266
  export const getHypName = (hyp: Hyp) => {
263
267
  switch (hyp.kind) {
264
268
  case "Fresh":
@@ -394,6 +398,14 @@ export const getFact = (
394
398
  location: Locus | undefined,
395
399
  ) => ({ kind: "Fact", expression, visibility, time, location }) satisfies Hyp;
396
400
 
401
+ export const getDefinitionHyp = (
402
+ definition: Defn,
403
+ whereDefined: WhereDefined,
404
+ visibility: Visibility,
405
+ isLocal: boolean,
406
+ location: Locus | undefined,
407
+ ) => ({ kind: "Defn", definition, whereDefined, visibility, isLocal, location }) satisfies Hyp;
408
+
397
409
  export const getBoundFresh = (bound: Bound) => getFresh(bound.name, bound.level);
398
410
 
399
411
  export const getParamFresh = (param: Param) => getFresh(param.name, "Unknown", param.shape);
@@ -582,13 +594,17 @@ export const mapScoped = <State>(
582
594
  }
583
595
  };
584
596
 
585
- export const mapChildren = (expression: Expr, map: (inner: Expr) => Expr): Expr =>
597
+ export const mapChildren = (
598
+ expression: Expr,
599
+ map: (inner: Expr) => Expr,
600
+ hyps: "visible" | "all" = "all",
601
+ ): Expr =>
586
602
  mapScoped(
587
603
  undefined,
588
604
  expression,
589
605
  (_state, inner) => map(inner),
590
606
  () => undefined,
591
- "all",
607
+ hyps,
592
608
  );
593
609
 
594
610
  export const getChildren = (expression: Expr) => {
@@ -3,10 +3,14 @@
3
3
  import { TlapmBugError, TlaProofError } from "../errors";
4
4
  import { isEqualExpr } from "./equality";
5
5
  import {
6
+ AT_NOWHERE,
6
7
  at,
7
8
  exprifySequent,
9
+ getDefinitionHyp,
8
10
  getErrorNote,
9
11
  getFact,
12
+ getLocalDefn,
13
+ getTrue,
10
14
  isBuiltinApply,
11
15
  mapAccumulate,
12
16
  type Expr,
@@ -32,13 +36,8 @@ import {
32
36
  import { shiftExpr } from "./substitution";
33
37
  import { getScopeTime } from "./temporal";
34
38
 
35
- export const AT_NOWHERE: Expr = { kind: "At", isExcept: false };
36
-
37
39
  const isAnonymous = (step: StepNumber | undefined) => step?.kind === "Named" && step.isAnonymous;
38
40
 
39
- export const getTrue = (from: { location?: Locus }) =>
40
- at({ kind: "Internal", builtin: "TRUE" }, from);
41
-
42
41
  const getAssumedFacts = (offset: number, sequent: Sequent) =>
43
42
  sequent.context.flatMap((hyp, index) =>
44
43
  hyp.kind === "Fact" && hyp.visibility === "Visible"
@@ -48,14 +47,13 @@ const getAssumedFacts = (offset: number, sequent: Sequent) =>
48
47
 
49
48
  const getStepDefinition = (step: Step, body: Expr, time: Time): Hyp => {
50
49
  if (!step.step) throw new TlapmBugError();
51
- return {
52
- kind: "Defn",
53
- definition: { kind: "Operator", name: getStepName(step.step), body, location: step.location },
54
- whereDefined: { kind: "Proof", time },
55
- visibility: "Visible",
56
- isLocal: true,
57
- location: step.location,
58
- };
50
+ return getDefinitionHyp(
51
+ { kind: "Operator", name: getStepName(step.step), body, location: step.location },
52
+ { kind: "Proof", time },
53
+ "Visible",
54
+ true,
55
+ step.location,
56
+ );
59
57
  };
60
58
 
61
59
  export const proveAssertion = (context: Hyp[], sequent: Sequent, step: Step, time: Time) => {
@@ -204,6 +202,12 @@ export interface ModuleSummary extends ProofSummary {
204
202
  theorems: TheoremSummary[];
205
203
  }
206
204
 
205
+ interface GeneratedStep {
206
+ sequent: Sequent;
207
+ step: Step;
208
+ time: Time;
209
+ }
210
+
207
211
  export const createGenerator = (inputFiles: Set<string>, lines: LineRange, onWarning: Warn) => {
208
212
  const generate = (sequent: Sequent, proof: Proof, time: Time): Proof => {
209
213
  const location = proof.location;
@@ -231,8 +235,8 @@ export const createGenerator = (inputFiles: Set<string>, lines: LineRange, onWar
231
235
  throw new TlaProofError("Proof.Gen.generate");
232
236
  case "Steps": {
233
237
  const [inner, steps] = mapAccumulate({ sequent, time }, proof.steps, (state, step) => {
234
- const [next, generated, nextTime] = generateStep(state.sequent, step, state.time);
235
- return [{ sequent: next, time: nextTime }, generated];
238
+ const next = generateStep(state.sequent, step, state.time);
239
+ return [next, next.step];
236
240
  });
237
241
  const qedProof = generate(inner.sequent, proof.qed.proof, inner.time);
238
242
  return { ...proof, steps, qed: { ...proof.qed, proof: qedProof } };
@@ -240,7 +244,7 @@ export const createGenerator = (inputFiles: Set<string>, lines: LineRange, onWar
240
244
  }
241
245
  };
242
246
 
243
- const generateStep = (sequent: Sequent, step: Step, time: Time): [Sequent, Step, Time] => {
247
+ const generateStep = (sequent: Sequent, step: Step, time: Time): GeneratedStep => {
244
248
  switch (step.kind) {
245
249
  case "Forget": {
246
250
  const count = sequent.context.length;
@@ -249,15 +253,15 @@ export const createGenerator = (inputFiles: Set<string>, lines: LineRange, onWar
249
253
  ? { ...hyp, visibility: "Hidden" }
250
254
  : hyp,
251
255
  );
252
- return [{ ...sequent, context }, step, time];
256
+ return { sequent: { ...sequent, context }, step, time };
253
257
  }
254
258
  case "Use": {
255
259
  const usable = step.usable;
256
260
  if (usable.defs.length === 0 && usable.facts.length === 1) {
257
261
  const fact = usable.facts[0];
258
262
  const obligation = obligate({ ...sequent, active: fact }, step, { kind: "Support" });
259
- return [
260
- {
263
+ return {
264
+ sequent: {
261
265
  context: [
262
266
  ...sequent.context,
263
267
  {
@@ -272,9 +276,9 @@ export const createGenerator = (inputFiles: Set<string>, lines: LineRange, onWar
272
276
  ],
273
277
  active: shiftExpr(1, sequent.active),
274
278
  },
275
- { ...step, obligations: [obligation] },
279
+ step: { ...step, obligations: [obligation] },
276
280
  time,
277
- ];
281
+ };
278
282
  }
279
283
  if (usable.facts.length > 0)
280
284
  throw new TlaProofError("Proof.Gen.gen_step: USE with facts and definitions");
@@ -282,7 +286,7 @@ export const createGenerator = (inputFiles: Set<string>, lines: LineRange, onWar
282
286
  (current, def) => setDefinition("Visible", current, def),
283
287
  sequent.context,
284
288
  );
285
- return [{ ...sequent, context }, step, time];
289
+ return { sequent: { ...sequent, context }, step, time };
286
290
  }
287
291
  case "Hide": {
288
292
  const hidden = step.usable.defs.reduce(
@@ -293,19 +297,15 @@ export const createGenerator = (inputFiles: Set<string>, lines: LineRange, onWar
293
297
  (current, fact) => setExpression(onWarning, "Hidden", fact, current),
294
298
  hidden,
295
299
  );
296
- return [{ ...sequent, context }, step, time];
300
+ return { sequent: { ...sequent, context }, step, time };
297
301
  }
298
302
  case "Define":
299
- return [
300
- {
303
+ return {
304
+ sequent: {
301
305
  context: [
302
306
  ...sequent.context,
303
307
  ...step.definitions.map((definition): Hyp => ({
304
- kind: "Defn",
305
- definition,
306
- whereDefined: "User",
307
- visibility: "Visible",
308
- isLocal: true,
308
+ ...getLocalDefn(definition),
309
309
  location: definition.location,
310
310
  })),
311
311
  ],
@@ -313,16 +313,23 @@ export const createGenerator = (inputFiles: Set<string>, lines: LineRange, onWar
313
313
  },
314
314
  step,
315
315
  time,
316
- ];
316
+ };
317
317
  case "Assert": {
318
318
  const inner = proveAssertion(sequent.context, step.sequent, step, time);
319
319
  const proof = generate(inner, step.proof, inner.time);
320
320
  const generated: Step = { ...step, proof };
321
- return [
322
- useAssertion(false, sequent.context, sequent.active, step.sequent, generated, time),
323
- generated,
321
+ return {
322
+ sequent: useAssertion(
323
+ false,
324
+ sequent.context,
325
+ sequent.active,
326
+ step.sequent,
327
+ generated,
328
+ time,
329
+ ),
330
+ step: generated,
324
331
  time,
325
- ];
332
+ };
326
333
  }
327
334
  case "Suffices": {
328
335
  const proof = generate(
@@ -332,7 +339,7 @@ export const createGenerator = (inputFiles: Set<string>, lines: LineRange, onWar
332
339
  );
333
340
  const generated: Step = { ...step, proof };
334
341
  const next = proveAssertion(sequent.context, step.sequent, generated, time);
335
- return [next, generated, next.time];
342
+ return { sequent: next, step: generated, time: next.time };
336
343
  }
337
344
  default:
338
345
  throw new TlaProofError("Proof.Gen.gen_step");
@@ -346,14 +353,14 @@ export const createGenerator = (inputFiles: Set<string>, lines: LineRange, onWar
346
353
  location: Locus | undefined,
347
354
  ): [Hyp[], Obligation[]] => {
348
355
  const step: StepNumber = { kind: "Unnamed", level: 0, id: 0 };
349
- const [sequent, generated] = generateStep(
356
+ const generated = generateStep(
350
357
  { context, active: { ...AT_NOWHERE, location } },
351
358
  mode === "Use"
352
359
  ? { kind: "Use", usable, isOnly: false, location, step, useLocation: location }
353
360
  : { kind: "Hide", usable, location, step },
354
361
  "Always",
355
362
  );
356
- return [sequent.context, generated.obligations ?? []];
363
+ return [generated.sequent.context, generated.step.obligations ?? []];
357
364
  };
358
365
 
359
366
  const mutate = (
@@ -21,7 +21,7 @@ import { formatObligation } from "./printer";
21
21
  import type { Counter, ObligationKind } from "./proof";
22
22
  import type { OldMethod } from "./pragma";
23
23
  import { createSimplifier } from "./simplify";
24
- import { createSource } from "./source";
24
+ import { createModuleConverter } from "./source";
25
25
  import { tokenize } from "../lexer";
26
26
  import { parseTlapmModule } from "../parser";
27
27
  import type { Module } from "../ast";
@@ -137,7 +137,7 @@ const loadMule = (
137
137
  onWarning({ text: `${errorPrefix}Error: ${message}`, channel: "stderr" });
138
138
  throw new TlaProofError(message, { failure: "Module.Parser.parse_file" });
139
139
  }
140
- const mule = createSource(input.file, input.source, counter, isMain).convertModule(parsed);
140
+ const mule = createModuleConverter(input.file, input.source, counter, isMain)(parsed);
141
141
  const fileName = input.file.slice(input.file.lastIndexOf("/") + 1);
142
142
  const name = fileName.replace(/\.tla$/, "");
143
143
  if (mule.name === name) return mule;
@@ -4,6 +4,7 @@ import { TlaProofError, TlapmBugError } from "../errors";
4
4
  import {
5
5
  at,
6
6
  exprifySequent,
7
+ getDefinitionHyp,
7
8
  getFact,
8
9
  getFresh,
9
10
  mapAccumulate,
@@ -172,31 +173,26 @@ export const getUnitHyps = (unit: ModuleUnit): Hyp[] => {
172
173
  location,
173
174
  }));
174
175
  case "Recursives":
175
- return unit.declarations.map((declaration) => ({
176
- kind: "Defn",
177
- definition: {
178
- kind: "Recursive",
179
- name: declaration.name,
180
- shape: declaration.shape,
176
+ return unit.declarations.map((declaration) =>
177
+ getDefinitionHyp(
178
+ { kind: "Recursive", name: declaration.name, shape: declaration.shape, location },
179
+ "User",
180
+ "Hidden",
181
+ false,
181
182
  location,
182
- },
183
- whereDefined: "User",
184
- visibility: "Hidden",
185
- isLocal: false,
186
- location,
187
- }));
183
+ ),
184
+ );
188
185
  case "Variables":
189
186
  return unit.names.map((name) => ({ kind: "Flex", name, location }));
190
187
  case "Definition":
191
188
  return [
192
- {
193
- kind: "Defn",
194
- definition: unit.definition,
195
- whereDefined: unit.whereDefined,
196
- visibility: unit.visibility,
197
- isLocal: unit.isLocal,
189
+ getDefinitionHyp(
190
+ unit.definition,
191
+ unit.whereDefined,
192
+ unit.visibility,
193
+ unit.isLocal,
198
194
  location,
199
- },
195
+ ),
200
196
  ];
201
197
  case "Axiom":
202
198
  case "Theorem": {
@@ -236,14 +232,13 @@ export const getHypSize = (unit: ModuleUnit) =>
236
232
  : getUnitHyps(unit).length;
237
233
 
238
234
  const getNamedFact = (name: string, expression: Expr, location: Locus | undefined): Hyp[] => [
239
- {
240
- kind: "Defn",
241
- definition: { kind: "Operator", name, body: expression, location },
242
- whereDefined: "User",
243
- visibility: "Visible",
244
- isLocal: false,
235
+ getDefinitionHyp(
236
+ { kind: "Operator", name, body: expression, location },
237
+ "User",
238
+ "Visible",
239
+ false,
245
240
  location,
246
- },
241
+ ),
247
242
  getFact({ kind: "Ix", index: 1, location }, "Hidden", "Always", location),
248
243
  ];
249
244
 
@@ -413,19 +408,13 @@ export const bindTheoremName = (
413
408
  ? { hyps: [], sequent }
414
409
  : {
415
410
  hyps: [
416
- {
417
- kind: "Defn",
418
- definition: {
419
- kind: "Operator",
420
- name,
421
- body: at(exprifySequent(sequent), { location }),
422
- location,
423
- },
424
- whereDefined: { kind: "Proof", time: "Always" },
425
- visibility: "Visible",
426
- isLocal: false,
411
+ getDefinitionHyp(
412
+ { kind: "Operator", name, body: at(exprifySequent(sequent), { location }), location },
413
+ { kind: "Proof", time: "Always" },
414
+ "Visible",
415
+ false,
427
416
  location,
428
- },
417
+ ),
429
418
  ],
430
419
  sequent: substituteSequent(shift(1), sequent),
431
420
  };
@@ -15,6 +15,7 @@ import {
15
15
  getLocationText,
16
16
  getLocusPrefix,
17
17
  getScopeHyps,
18
+ getTrue,
18
19
  mapAccumulate,
19
20
  type Defn,
20
21
  type Expr,
@@ -74,7 +75,7 @@ const lambdifyTheorem = (
74
75
  const message = `${error.failure}\nCould not instantiate the theorem ${name === undefined ? "" : `named: ${name}, `}at: ${getLocationText(location)}`;
75
76
  pipeline.onWarning({ text: `${getAtPrefix(location)}[ERROR]${message}`, channel: "stdout" });
76
77
  pipeline.onWarning({ text: message, channel: "toolboxOnly" });
77
- return { context: [], active: at({ kind: "Internal", builtin: "TRUE" }, sequent.active) };
78
+ return { context: [], active: getTrue(sequent.active) };
78
79
  }
79
80
  };
80
81
 
@@ -3,9 +3,12 @@
3
3
  import { TlaProofError } from "../errors";
4
4
  import { isEqualExpr } from "./equality";
5
5
  import {
6
+ AT_NOWHERE,
6
7
  applyBuiltin,
7
8
  at,
9
+ getDefinitionHyp,
8
10
  getFact,
11
+ getTrue,
9
12
  isBuiltinApply,
10
13
  mapAccumulate,
11
14
  mapBoundDomains,
@@ -19,7 +22,7 @@ import {
19
22
  type Time,
20
23
  } from "./expression";
21
24
  import { format, renderDoc, type Doc } from "./format";
22
- import { AT_NOWHERE, getTrue, proveAssertion, useAssertion } from "./generate";
25
+ import { proveAssertion, useAssertion } from "./generate";
23
26
  import { printExpression } from "./printer";
24
27
  import { getUnique, type Counter, type Proof, type Step, type StepNumber } from "./proof";
25
28
  import {
@@ -127,6 +130,13 @@ const replaceAt = (expression: Expr, replacement: Expr): Expr =>
127
130
  ? at(stripProps(replacement), expression)
128
131
  : mapChildren(expression, (inner) => replaceAt(inner, replacement));
129
132
 
133
+ interface SimplifiedSteps {
134
+ context: Hyp[];
135
+ goal: Expr;
136
+ steps: Step[];
137
+ time: Time;
138
+ }
139
+
130
140
  export const createSimplifier = (counter: Counter) => {
131
141
  const getAnonymous = (level: number): StepNumber => ({
132
142
  kind: "Named",
@@ -273,13 +283,8 @@ export const createSimplifier = (counter: Counter) => {
273
283
  { context, goal, time },
274
284
  proof.steps,
275
285
  (state, step) => {
276
- const [nextContext, nextGoal, simplified, nextTime] = simplifyStep(
277
- state.context,
278
- state.goal,
279
- step,
280
- state.time,
281
- );
282
- return [{ context: nextContext, goal: nextGoal, time: nextTime }, simplified];
286
+ const next = simplifyStep(state.context, state.goal, step, state.time);
287
+ return [next, next.steps];
283
288
  },
284
289
  );
285
290
  const qedProof = simplify(inner.context, inner.goal, proof.qed.proof, inner.time);
@@ -288,16 +293,11 @@ export const createSimplifier = (counter: Counter) => {
288
293
  }
289
294
  };
290
295
 
291
- const simplifyStep = (
292
- context: Hyp[],
293
- goal: Expr,
294
- step: Step,
295
- time: Time,
296
- ): [Hyp[], Expr, Step[], Time] => {
296
+ const simplifyStep = (context: Hyp[], goal: Expr, step: Step, time: Time): SimplifiedSteps => {
297
297
  const level = getLevel(step.step);
298
298
  switch (step.kind) {
299
299
  case "Forget":
300
- return [context, goal, [step], time];
300
+ return { context, goal, steps: [step], time };
301
301
  case "Assert": {
302
302
  const inner = proveAssertion(context, step.sequent, step, time);
303
303
  const simplified: Step = {
@@ -305,7 +305,7 @@ export const createSimplifier = (counter: Counter) => {
305
305
  proof: simplify(inner.context, inner.active, step.proof, inner.time),
306
306
  };
307
307
  const next = useAssertion(false, context, goal, step.sequent, simplified, time);
308
- return [next.context, next.active, [simplified], time];
308
+ return { context: next.context, goal: next.active, steps: [simplified], time };
309
309
  }
310
310
  case "Suffices": {
311
311
  const inner = useAssertion(true, context, goal, step.sequent, step, time);
@@ -314,7 +314,7 @@ export const createSimplifier = (counter: Counter) => {
314
314
  proof: simplify(inner.context, inner.active, step.proof, time),
315
315
  };
316
316
  const next = proveAssertion(context, step.sequent, simplified, time);
317
- return [next.context, next.active, [simplified], next.time];
317
+ return { context: next.context, goal: next.active, steps: [simplified], time: next.time };
318
318
  }
319
319
  case "Use": {
320
320
  const byProof: Proof = {
@@ -331,12 +331,12 @@ export const createSimplifier = (counter: Counter) => {
331
331
  const assumed = step.usable.facts.map(() =>
332
332
  getFact(AT_NOWHERE, "Visible", time, step.location),
333
333
  );
334
- return [
335
- [...context, ...assumed],
336
- shiftExpr(step.usable.facts.length, goal),
337
- simplified.steps,
334
+ return {
335
+ context: [...context, ...assumed],
336
+ goal: shiftExpr(step.usable.facts.length, goal),
337
+ steps: simplified.steps,
338
338
  time,
339
- ];
339
+ };
340
340
  }
341
341
  case "Hide": {
342
342
  const hidden = step.usable.defs.reduce((current, def) => {
@@ -353,25 +353,20 @@ export const createSimplifier = (counter: Counter) => {
353
353
  position === index ? { ...hyp, visibility: "Hidden", location: step.location } : entry,
354
354
  );
355
355
  }, context);
356
- return [hidden, goal, [step], time];
356
+ return { context: hidden, goal, steps: [step], time };
357
357
  }
358
358
  case "Define":
359
- return [
360
- [
359
+ return {
360
+ context: [
361
361
  ...context,
362
- ...step.definitions.map((definition): Hyp => ({
363
- kind: "Defn",
364
- definition,
365
- whereDefined: { kind: "Proof", time },
366
- visibility: "Visible",
367
- isLocal: true,
368
- location: step.location,
369
- })),
362
+ ...step.definitions.map((definition) =>
363
+ getDefinitionHyp(definition, { kind: "Proof", time }, "Visible", true, step.location),
364
+ ),
370
365
  ],
371
- shiftExpr(step.definitions.length, goal),
372
- [step],
366
+ goal: shiftExpr(step.definitions.length, goal),
367
+ steps: [step],
373
368
  time,
374
- ];
369
+ };
375
370
  case "Have": {
376
371
  const connective = exposeConnective(context, goal);
377
372
  const isImplication = isBinary(connective, "Implies");
@@ -437,7 +432,7 @@ export const createSimplifier = (counter: Counter) => {
437
432
  step,
438
433
  );
439
434
  const salted = getSalted(step.step, "ex");
440
- const [assertContext, assertGoal, asserted, assertTime] = simplifyStep(
435
+ const asserted = simplifyStep(
441
436
  context,
442
437
  goal,
443
438
  {
@@ -453,20 +448,20 @@ export const createSimplifier = (counter: Counter) => {
453
448
  if (shifted.kind !== "Quant") throw new TlaProofError("Proof.Simplify.simplify_step/PICK");
454
449
  const hyps = [
455
450
  ...getBoundHyps(shifted.bounds),
456
- getFact(shifted.body, "Visible", assertTime, shifted.body.location),
451
+ getFact(shifted.body, "Visible", asserted.time, shifted.body.location),
457
452
  ];
458
- const [nextContext, nextGoal, sufficed, nextTime] = simplifyStep(
459
- assertContext,
460
- assertGoal,
453
+ const sufficed = simplifyStep(
454
+ asserted.context,
455
+ asserted.goal,
461
456
  {
462
457
  kind: "Suffices",
463
- sequent: { context: hyps, active: shiftExpr(hyps.length, assertGoal) },
458
+ sequent: { context: hyps, active: shiftExpr(hyps.length, asserted.goal) },
464
459
  proof: { kind: "Omitted", omission: "Elsewhere", ...getProps(step) },
465
460
  ...getProps(step),
466
461
  },
467
- assertTime,
462
+ asserted.time,
468
463
  );
469
- return [nextContext, nextGoal, [...asserted, ...sufficed], nextTime];
464
+ return { ...sufficed, steps: [...asserted.steps, ...sufficed.steps] };
470
465
  }
471
466
  }
472
467
  };