tla-ts 0.0.4-dev.c4929d7 → 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 -6
  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
@@ -90,18 +90,6 @@ export const matchTypes = (pattern: Typ, object: Typ, tyenv: TyEnv): TyEnv | und
90
90
  return object.kind === "TFree" && object.name === pattern.name ? tyenv : undefined;
91
91
  };
92
92
 
93
- // Type.could_unify
94
- export const couldUnifyTypes = (left: Typ, right: Typ): boolean => {
95
- if (left.kind === "TVar" || right.kind === "TVar") return true;
96
- if (left.kind === "Type" && right.kind === "Type")
97
- return (
98
- left.name === right.name &&
99
- left.args.length === right.args.length &&
100
- left.args.every((arg, index) => couldUnifyTypes(arg, right.args[index]))
101
- );
102
- return left.kind === "TFree" && right.kind === "TFree" && left.name === right.name;
103
- };
104
-
105
93
  // Envir.norm_type: instantiates the assigned type variables, chasing chains.
106
94
  export const normType = (tyenv: TyEnv, type: Typ): Typ => {
107
95
  if (type.kind === "TFree") return type;
@@ -653,7 +653,7 @@ const addFfpair = (dpair: Dpair, envir: Envir, tpairs: readonly Tpair[]): [Envir
653
653
  : cleanFfpair({ binders: dpair.binders, left, right }, envir, tpairs);
654
654
  };
655
655
 
656
- export interface Unifier {
656
+ interface Unifier {
657
657
  readonly envir: Envir;
658
658
  readonly tpairs: readonly Tpair[];
659
659
  }
@@ -37,7 +37,7 @@ const destBinary = (name: string, term: Term): [Term, Term] => {
37
37
  throw new TlaIsabelleError("TERM", `dest ${name}`);
38
38
  };
39
39
 
40
- export const destTrueprop = (term: Term): Term => {
40
+ const destTrueprop = (term: Term): Term => {
41
41
  if (
42
42
  term.kind === "App" &&
43
43
  term.fun.kind === "Const" &&
@@ -1,6 +1,6 @@
1
1
  // The parts of OCaml's standard library whose exact order steers what tlapm prints.
2
2
 
3
- export type OcamlValue = number | string | OcamlValue[];
3
+ type OcamlValue = number | string | OcamlValue[];
4
4
 
5
5
  // String.compare: byte by byte, on the UTF-8 bytes. Code units order the same way for the ASCII
6
6
  // names tlapm compares.
@@ -3,7 +3,7 @@
3
3
  // down to the variables (Symbol_commute), and what remains modal becomes opaque (Coalesce).
4
4
 
5
5
  import { TlapmBugError } from "../../errors";
6
- import { rewriteUnchanged } from "../../obligations/action";
6
+ import { rewriteUnchanged } from "../../obligations/temporal";
7
7
  import {
8
8
  adjoin,
9
9
  adjoinAll,
@@ -11,7 +11,10 @@ import {
11
11
  at,
12
12
  createContextMap,
13
13
  getBoundedFresh,
14
+ getBoundFresh,
14
15
  getFresh,
16
+ getLocalDefn,
17
+ getParamFresh,
15
18
  getScopeAt,
16
19
  getScopeHyps,
17
20
  mapAccumulate,
@@ -82,7 +85,7 @@ const expandUnchanged: Rewrite = (scope, expression) =>
82
85
  ? rewriteUnchanged(expression.args[0])
83
86
  : mapScoped(scope, expression, expandUnchanged, adjoin, "all");
84
87
 
85
- const getModal = (builtin: Builtin, expression: Expr) =>
88
+ const applyModal = (builtin: Builtin, expression: Expr) =>
86
89
  applyBuiltin(builtin, [expression], expression);
87
90
 
88
91
  // prime_commuter: a prime distributes down to the declarations that are not constant.
@@ -96,7 +99,7 @@ const commutePrime: Rewrite = (scope, expression) => {
96
99
  getLevel(getScopeAt(scope, expression.index), hyp.definition.body) === 0
97
100
  )
98
101
  return expression;
99
- return getModal("Prime", expression);
102
+ return applyModal("Prime", expression);
100
103
  }
101
104
  if (
102
105
  isBuiltin(expression, ["ENABLED"]) ||
@@ -104,7 +107,7 @@ const commutePrime: Rewrite = (scope, expression) => {
104
107
  expression.kind === "Sequent" ||
105
108
  expression.kind === "Let"
106
109
  )
107
- return getModal("Prime", expression);
110
+ return applyModal("Prime", expression);
108
111
  if (
109
112
  isBuiltin(expression, [
110
113
  "UNCHANGED",
@@ -137,7 +140,7 @@ const getModalCommuter = (builtin: "BoxTrue" | "Diamond"): Rewrite => {
137
140
  expression.quantifier === quantifier);
138
141
  return isDistributed
139
142
  ? mapScoped(scope, expression, commute, adjoin)
140
- : getModal(builtin, expression);
143
+ : applyModal(builtin, expression);
141
144
  };
142
145
  return commute;
143
146
  };
@@ -160,9 +163,9 @@ const commuteSymbols: Rewrite = (scope, expression) => {
160
163
  return mapScoped(scope, expression, commuteSymbols, adjoin, "all");
161
164
  };
162
165
 
163
- const LEVEL_KINDS = ["CONSTANT", "STATE", "ACTION", "TEMPORAL"];
164
-
165
- const FRESH_KINDS: Record<Level, string> = {
166
+ // The prefix rename_with_loc gives a declaration of each level, and a definition by the number of
167
+ // its body's level.
168
+ export const LEVEL_PREFIXES: Record<Level, string> = {
166
169
  Constant: "CONSTANT",
167
170
  State: "STATE",
168
171
  Action: "ACTION",
@@ -170,6 +173,8 @@ const FRESH_KINDS: Record<Level, string> = {
170
173
  Unknown: "Unknown",
171
174
  };
172
175
 
176
+ export const LEVEL_NUMBER_PREFIXES = ["CONSTANT", "STATE", "ACTION", "TEMPORAL"];
177
+
173
178
  const getRenamed = (kind: string, name: string) => `${kind}_${name}_`;
174
179
 
175
180
  interface RenameState {
@@ -186,7 +191,7 @@ const renameDefn = (scope: Scope | undefined, definition: Defn, level?: number):
186
191
  : definition;
187
192
  }
188
193
  const body = rename(scope, definition.body);
189
- const kind = LEVEL_KINDS[level ?? getLevel(scope, body)];
194
+ const kind = LEVEL_NUMBER_PREFIXES[level ?? getLevel(scope, body)];
190
195
  if (kind === undefined) throw new TlapmBugError();
191
196
  return { ...definition, name: getRenamed(kind, definition.name), body };
192
197
  };
@@ -196,7 +201,7 @@ const renameHyp = (scope: Scope | undefined, hyp: Hyp, level?: number): Hyp => {
196
201
  case "Fresh":
197
202
  return {
198
203
  ...hyp,
199
- name: getRenamed(FRESH_KINDS[hyp.level], hyp.name),
204
+ name: getRenamed(LEVEL_PREFIXES[hyp.level], hyp.name),
200
205
  domain: hyp.domain && rename(scope, hyp.domain),
201
206
  };
202
207
  case "Flex":
@@ -264,10 +269,7 @@ const rename: Rewrite = (scope, expression) => {
264
269
  ...param,
265
270
  name: getRenamed("Unknown", param.name),
266
271
  }));
267
- const inner = adjoinAll(
268
- scope,
269
- params.map((param) => getFresh(param.name, "Unknown", param.shape)),
270
- );
272
+ const inner = adjoinAll(scope, params.map(getParamFresh));
271
273
  return { ...expression, params, body: rename(inner, expression.body) };
272
274
  }
273
275
  case "Tquant": {
@@ -294,16 +296,13 @@ const rename: Rewrite = (scope, expression) => {
294
296
  case "SetOf": {
295
297
  const bounds = expression.bounds.map((bound) => ({
296
298
  ...bound,
297
- name: getRenamed(FRESH_KINDS[bound.level], bound.name),
299
+ name: getRenamed(LEVEL_PREFIXES[bound.level], bound.name),
298
300
  domain:
299
301
  bound.domain.kind === "Domain"
300
302
  ? { kind: "Domain" as const, expression: rename(scope, bound.domain.expression) }
301
303
  : bound.domain,
302
304
  }));
303
- const inner = adjoinAll(
304
- scope,
305
- bounds.map((bound) => getFresh(bound.name, bound.level)),
306
- );
305
+ const inner = adjoinAll(scope, bounds.map(getBoundFresh));
307
306
  return expression.kind === "SetOf"
308
307
  ? { ...expression, bounds, element: rename(inner, expression.element) }
309
308
  : { ...expression, bounds, body: rename(inner, expression.body) };
@@ -314,14 +313,7 @@ const rename: Rewrite = (scope, expression) => {
314
313
  expression.definitions,
315
314
  (current, definition) => {
316
315
  const renamed = renameDefn(current, definition);
317
- const hyp: Hyp = {
318
- kind: "Defn",
319
- definition: renamed,
320
- whereDefined: "User",
321
- visibility: "Visible",
322
- isLocal: true,
323
- };
324
- return [adjoin(current, hyp), renamed];
316
+ return [adjoin(current, getLocalDefn(renamed)), renamed];
325
317
  },
326
318
  );
327
319
  return { ...expression, definitions, body: rename(inner, expression.body) };
@@ -342,10 +334,7 @@ const getSubstitutiveArgs = (scope: Scope | undefined, definition: Defn): boolea
342
334
  if (cached) return cached;
343
335
  const body = definition.kind === "Operator" ? definition.body : undefined;
344
336
  if (body?.kind !== "Lambda") return [];
345
- const inner = adjoinAll(
346
- scope,
347
- body.params.map((param) => getFresh(param.name, "Unknown", param.shape)),
348
- );
337
+ const inner = adjoinAll(scope, body.params.map(getParamFresh));
349
338
  const result = body.params.map((_param, index) =>
350
339
  isSubstitutive(inner, body.body, index + 1, true),
351
340
  );
@@ -415,13 +404,11 @@ const isSubstitutive = (
415
404
 
416
405
  // Coalesce.crypthash: h and the first five hexadecimal digits of the MD5 of the expression as
417
406
  // tlapm prints it.
418
- const getHashName = (scope: Scope | undefined, expression: Expr) => {
419
- const text = renderDoc(printExpression(getScopeHyps(scope), expression));
420
- return `h${getMd5(text).slice(0, 5)}`;
421
- };
407
+ export const getHashName = (hyps: Hyp[], expression: Expr) =>
408
+ `h${getMd5(renderDoc(printExpression(hyps, expression))).slice(0, 5)}`;
422
409
 
423
410
  const coalesce = (scope: Scope | undefined, expression: Expr): Expr =>
424
- at({ kind: "Opaque", name: getHashName(scope, expression) }, expression);
411
+ at({ kind: "Opaque", name: getHashName(getScopeHyps(scope), expression) }, expression);
425
412
 
426
413
  // coalesce_operator: an operator applied to arguments that are not all substitutive is opaque,
427
414
  // hiding the arguments that are constant or substitutive.
@@ -2,13 +2,13 @@
2
2
  // from facts of the form the rule needs.
3
3
 
4
4
  import { TlapmBugError, TlaProverError } from "../../errors";
5
+ import { shiftExpr } from "../../obligations/substitution";
6
+ import { isEqualExpr } from "../../obligations/equality";
5
7
  import {
6
8
  adjoin,
7
9
  adjoinAll,
8
10
  getScopeAt,
9
- isEqualExpr,
10
11
  mapScoped,
11
- shiftExpr,
12
12
  type Builtin,
13
13
  type Expr,
14
14
  type Scope,
@@ -150,7 +150,7 @@ const getFreshLabel = (hyp: Extract<Hyp, { kind: "Fresh" }>) =>
150
150
  // fp_sequent's text for an obligation, before its digest.
151
151
  const getFingerprintText = (sequent: Sequent) => {
152
152
  const stack: Entry[] = [];
153
- const get = (index: number) => {
153
+ const getEntry = (index: number) => {
154
154
  const entry = stack[stack.length - index];
155
155
  if (!entry) throw new TlapmBugError();
156
156
  return entry;
@@ -197,7 +197,7 @@ const getFingerprintText = (sequent: Sequent) => {
197
197
  entries.map((entry) => `${getVariableNumber(entry)}.`).join("");
198
198
  switch (expression.kind) {
199
199
  case "Ix": {
200
- const entry = get(expression.index);
200
+ const entry = getEntry(expression.index);
201
201
  entry.isUsed = true;
202
202
  const ident = entry.ident;
203
203
  switch (ident.kind) {
@@ -234,7 +234,7 @@ const getFingerprintText = (sequent: Sequent) => {
234
234
  return printSequent(expression.sequent);
235
235
  case "Apply": {
236
236
  const operator = expression.operator;
237
- if (operator.kind === "Ix" && get(operator.index).ident.kind === "Pragma") return "";
237
+ if (operator.kind === "Ix" && getEntry(operator.index).ident.kind === "Pragma") return "";
238
238
  return `$OpApp(${print(operator)};${printList(expression.args)})`;
239
239
  }
240
240
  case "With":
@@ -7,7 +7,10 @@ import {
7
7
  adjoin,
8
8
  adjoinAll,
9
9
  getBoundedFresh,
10
+ getBoundFresh,
10
11
  getFresh,
12
+ getLocalDefn,
13
+ getParamFresh,
11
14
  getScopeAt,
12
15
  getScopeHyps,
13
16
  type Bound,
@@ -64,28 +67,13 @@ const getDeclaration = (scope: Scope | undefined, index: number): Declaration =>
64
67
  };
65
68
 
66
69
  const bindBounds = (scope: Scope | undefined, bounds: Bound[]) =>
67
- adjoinAll(
68
- scope,
69
- bounds.map((bound) => getFresh(bound.name, bound.level)),
70
- );
70
+ adjoinAll(scope, bounds.map(getBoundFresh));
71
71
 
72
72
  const bindParams = (scope: Scope | undefined, params: Param[]) =>
73
- adjoinAll(
74
- scope,
75
- params.map((param) => getFresh(param.name, "Unknown", param.shape)),
76
- );
73
+ adjoinAll(scope, params.map(getParamFresh));
77
74
 
78
75
  const bindDefinitions = (scope: Scope | undefined, definitions: Defn[]) =>
79
- adjoinAll(
80
- scope,
81
- definitions.map((definition) => ({
82
- kind: "Defn",
83
- definition,
84
- whereDefined: "User",
85
- visibility: "Visible",
86
- isLocal: true,
87
- })),
88
- );
76
+ adjoinAll(scope, definitions.map(getLocalDefn));
89
77
 
90
78
  const bindFlexible = (scope: Scope | undefined, names: string[]) =>
91
79
  adjoinAll(
@@ -389,9 +377,8 @@ const compare = (
389
377
  )
390
378
  );
391
379
  case "Choose":
392
- return right.kind === "Choose" && isSameBinder(leftScope, rightScope, left, right);
393
380
  case "SetSt":
394
- return right.kind === "SetSt" && isSameBinder(leftScope, rightScope, left, right);
381
+ return right.kind === left.kind && isSameBinder(leftScope, rightScope, left, right);
395
382
  case "SetOf":
396
383
  return (
397
384
  right.kind === "SetOf" &&
@@ -432,18 +419,9 @@ const compare = (
432
419
  case "Product":
433
420
  return right.kind === "Product" && recurseList(left.factors, right.factors);
434
421
  case "Rect":
435
- return (
436
- right.kind === "Rect" &&
437
- isSameFields(
438
- leftScope,
439
- rightScope,
440
- getSortedFields(left.fields),
441
- getSortedFields(right.fields),
442
- )
443
- );
444
422
  case "Record":
445
423
  return (
446
- right.kind === "Record" &&
424
+ right.kind === left.kind &&
447
425
  isSameFields(
448
426
  leftScope,
449
427
  rightScope,
@@ -477,15 +455,9 @@ const compare = (
477
455
  left.field === right.field
478
456
  );
479
457
  case "Sub":
480
- return (
481
- right.kind === "Sub" &&
482
- left.modal === right.modal &&
483
- recurse(left.action, right.action) &&
484
- recurse(left.subscript, right.subscript)
485
- );
486
458
  case "Tsub":
487
459
  return (
488
- right.kind === "Tsub" &&
460
+ right.kind === left.kind &&
489
461
  left.modal === right.modal &&
490
462
  recurse(left.action, right.action) &&
491
463
  recurse(left.subscript, right.subscript)
@@ -22,7 +22,7 @@ export const getMd5 = (text: string): string => {
22
22
  const words = Array.from({ length: 16 }, (_value, index) =>
23
23
  view.getUint32(offset + index * 4, true),
24
24
  );
25
- const [a, b, c, d] = Array.from({ length: 64 }).reduce<number[]>(
25
+ const mixedState = Array.from({ length: 64 }).reduce<number[]>(
26
26
  ([innerA, innerB, innerC, innerD], _value, index) => {
27
27
  const round = Math.floor(index / 16);
28
28
  const mixed =
@@ -51,14 +51,7 @@ export const getMd5 = (text: string): string => {
51
51
  },
52
52
  state,
53
53
  );
54
- state.splice(
55
- 0,
56
- 4,
57
- (state[0] + a) | 0,
58
- (state[1] + b) | 0,
59
- (state[2] + c) | 0,
60
- (state[3] + d) | 0,
61
- );
54
+ state.splice(0, 4, ...state.map((word, index) => (word + mixedState[index]) | 0));
62
55
  }
63
56
  return state
64
57
  .flatMap((word) => [word, word >>> 8, word >>> 16, word >>> 24])