tla-ts 0.0.10-dev.68b2c4968 → 0.0.10-dev.6b2a6741a

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 (50) hide show
  1. package/dist/deciders.cjs +1 -1
  2. package/dist/deciders.js +1 -1
  3. package/dist/index.d.cts +1 -0
  4. package/dist/index.d.ts +1 -0
  5. package/dist/prove.cjs +6 -6
  6. package/dist/prove.js +6 -6
  7. package/dist/run.cjs +7 -7
  8. package/dist/run.js +7 -7
  9. package/dist/transfer.cjs +33 -33
  10. package/dist/transfer.js +29 -29
  11. package/package.json +1 -1
  12. package/src/ast.ts +1 -0
  13. package/src/cli/xml-exporter.ts +1 -1
  14. package/src/codegen.ts +3 -3
  15. package/src/environment.ts +40 -33
  16. package/src/instances.ts +4 -4
  17. package/src/java-overrides.ts +2 -2
  18. package/src/levels.ts +4 -4
  19. package/src/obligations/index.ts +1 -1
  20. package/src/obligations/normalize.ts +1 -4
  21. package/src/obligations/printer.ts +5 -5
  22. package/src/parser.ts +35 -106
  23. package/src/prover/isabelle/isar/attrib.ts +4 -4
  24. package/src/prover/isabelle/pure/rewriter.ts +3 -3
  25. package/src/prover/isabelle/pure/term.ts +3 -3
  26. package/src/prover/prep/md5.ts +26 -29
  27. package/src/prover/smt/solver/logic-tactics.ts +2 -2
  28. package/src/prover/smt/solver/opt-preprocess.ts +1 -1
  29. package/src/prover/smt/solver/seq-decl-plugin.ts +1 -1
  30. package/src/prover/smt/solver/seq-rewriter.ts +1 -1
  31. package/src/prover/smt/solver/tactic.ts +4 -4
  32. package/src/prover/tlapm/cache.ts +8 -8
  33. package/src/resolve.ts +374 -125
  34. package/src/runtime.ts +1 -1
  35. package/src/sany/builtins.ts +10 -10
  36. package/src/sany/generation.ts +1 -0
  37. package/src/sany/generator-definitions.ts +1 -0
  38. package/src/sany/generator-expressions.ts +6 -3
  39. package/src/sany/generator-proofs.ts +4 -2
  40. package/src/sany/lexer.ts +3 -3
  41. package/src/sany/modules.ts +4 -2
  42. package/src/sany/selectors.ts +5 -1
  43. package/src/sany/xml.ts +2 -3
  44. package/src/subexpressions.ts +102 -18
  45. package/src/symmetry.ts +1 -1
  46. package/src/tlc/jar-data.ts +1 -3
  47. package/src/tlc/messages.ts +3 -3
  48. package/src/tlc/tlc-operators.ts +3 -1
  49. package/src/tlc/trace-spec.ts +3 -2
  50. package/src/values.ts +4 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tla-ts",
3
- "version": "0.0.10-dev.68b2c4968",
3
+ "version": "0.0.10-dev.6b2a6741a",
4
4
  "description": "A TLA+ interpreter and model checker in TypeScript, 2× faster than TLC",
5
5
  "keywords": [
6
6
  "formal verification",
package/src/ast.ts CHANGED
@@ -122,6 +122,7 @@ export interface LetExpression {
122
122
  kind: "Let";
123
123
  definitions: Definition[];
124
124
  instances?: Instance[];
125
+ recursive?: Declaration[];
125
126
  body: Expression;
126
127
  location: SourceLocation;
127
128
  }
@@ -52,7 +52,7 @@ const XML_EXPORT_USAGE = (() => {
52
52
  "",
53
53
  getBold("OPTIONS"),
54
54
  "",
55
- ...options.map(([flag, description]) => `\t${getBold(flag)}\n\t\t${description}`),
55
+ ...options.map((option) => `\t${getBold(option[0])}\n\t\t${option[1]}`),
56
56
  "",
57
57
  getBold("TIPS"),
58
58
  "",
package/src/codegen.ts CHANGED
@@ -167,13 +167,13 @@ const getFreeNames = (expression: Expression, names = new Set<string>()) => {
167
167
 
168
168
  const getDelegateContext = (generator: Generator, expression: Expression, frame: Frame) => {
169
169
  const freeNames = getFreeNames(expression);
170
- const captured = [...frame.locals].filter(([name]) => freeNames.has(name));
170
+ const captured = [...frame.locals].filter((entry) => freeNames.has(entry[0]));
171
171
  if (captured.length === 0) return frame.context;
172
172
  const names = addReference(
173
173
  generator,
174
- captured.map(([name]) => name),
174
+ captured.map((entry) => entry[0]),
175
175
  );
176
- return `extend(${frame.context}, ${names}, [${captured.map(([, local]) => local).join(", ")}])`;
176
+ return `extend(${frame.context}, ${names}, [${captured.map((entry) => entry[1]).join(", ")}])`;
177
177
  };
178
178
 
179
179
  const generateDelegate = (generator: Generator, expression: Expression, frame: Frame) =>
@@ -505,7 +505,7 @@ export const createEnvironment = (
505
505
  const instantiation = createInstantiation({
506
506
  params,
507
507
  substitutions: new Map(
508
- [...substitutions].map(([name, expression]) => [name, renameLocals(expression, renamed)]),
508
+ [...substitutions].map((entry) => [entry[0], renameLocals(entry[1], renamed)]),
509
509
  ),
510
510
  variables: new Set(linked.variables),
511
511
  getDefinition: (key) => definitions.get(key),
@@ -548,9 +548,14 @@ export const createEnvironment = (
548
548
  instance.name === undefined
549
549
  ? standardSymbols
550
550
  : new Map(
551
- [...standardSymbols].map(([name, symbol]) => [
552
- `${instance.name}!${name}`,
553
- { key: symbol.key, arity: symbol.arity, params: symbol.params, kind: symbol.kind },
551
+ [...standardSymbols].map((entry) => [
552
+ `${instance.name}!${entry[0]}`,
553
+ {
554
+ key: entry[1].key,
555
+ arity: entry[1].arity,
556
+ params: entry[1].params,
557
+ kind: entry[1].kind,
558
+ },
554
559
  ]),
555
560
  );
556
561
 
@@ -563,32 +568,34 @@ export const createEnvironment = (
563
568
  const declared = new Set(declarations.map((declaration) => declaration.name));
564
569
  return new Map(
565
570
  [...exported]
566
- .filter(([name]) => !declared.has(name))
567
- .map(([name, symbol]): [string, ModuleSymbol] => {
571
+ .filter((entry) => !declared.has(entry[0]))
572
+ .map((entry): [string, ModuleSymbol] => {
568
573
  if (instance.name === undefined) {
569
574
  return [
570
- name,
575
+ entry[0],
571
576
  {
572
- key: getKey(symbol.key, name),
573
- arity: symbol.arity,
574
- params: symbol.params,
575
- kind: symbol.kind,
577
+ key: getKey(entry[1].key, entry[0]),
578
+ arity: entry[1].arity,
579
+ params: entry[1].params,
580
+ kind: entry[1].kind,
576
581
  range:
577
- parameterized.get(symbol.key) === true ? instance.location.range : symbol.range,
582
+ parameterized.get(entry[1].key) === true
583
+ ? instance.location.range
584
+ : entry[1].range,
578
585
  },
579
586
  ];
580
587
  }
581
- const qualified = `${instance.name}!${name}`;
588
+ const qualified = `${instance.name}!${entry[0]}`;
582
589
  return [
583
590
  qualified,
584
591
  {
585
- key: getKey(symbol.key, qualified),
586
- arity: symbol.arity + instance.params.length,
587
- params: symbol.params && [
592
+ key: getKey(entry[1].key, qualified),
593
+ arity: entry[1].arity + instance.params.length,
594
+ params: entry[1].params && [
588
595
  ...instance.params.map((param) => param.arity),
589
- ...symbol.params,
596
+ ...entry[1].params,
590
597
  ],
591
- kind: symbol.kind,
598
+ kind: entry[1].kind,
592
599
  },
593
600
  ];
594
601
  }),
@@ -636,11 +643,11 @@ export const createEnvironment = (
636
643
  const standardSymbols = nested ? undefined : getStandardSymbols(instance.module);
637
644
  if (standardSymbols) {
638
645
  if (instance.name === undefined) return [];
639
- return [...standardSymbols].map(([name, symbol]) => {
640
- const forwarded = createArgumentParams(symbol.arity, symbol.params);
646
+ return [...standardSymbols].map((entry) => {
647
+ const forwarded = createArgumentParams(entry[1].arity, entry[1].params);
641
648
  return createLocalAlias(
642
- `${instance.name}!${name}`,
643
- symbol.key,
649
+ `${instance.name}!${entry[0]}`,
650
+ entry[1].key,
644
651
  [...instance.params, ...forwarded],
645
652
  forwarded,
646
653
  location,
@@ -721,16 +728,16 @@ export const createEnvironment = (
721
728
  });
722
729
  const declared = new Set(declarations.map((declaration) => declaration.name));
723
730
  const aliases = [...linked.exported]
724
- .filter(([name]) => !declared.has(name))
725
- .map(([name, symbol]) => {
726
- const key = instantiation.getKey(symbol.key);
727
- const ownParams = createArgumentParams(symbol.arity, symbol.params);
731
+ .filter((entry) => !declared.has(entry[0]))
732
+ .map((entry) => {
733
+ const key = instantiation.getKey(entry[1].key);
734
+ const ownParams = createArgumentParams(entry[1].arity, entry[1].params);
728
735
  const params = [...instance.params, ...ownParams];
729
736
  return createLocalAlias(
730
- instance.name === undefined ? name : `${instance.name}!${name}`,
737
+ instance.name === undefined ? entry[0] : `${instance.name}!${entry[0]}`,
731
738
  key,
732
739
  params,
733
- key === symbol.key ? ownParams : params,
740
+ key === entry[1].key ? ownParams : params,
734
741
  location,
735
742
  );
736
743
  });
@@ -738,9 +745,9 @@ export const createEnvironment = (
738
745
  };
739
746
 
740
747
  const getAvailableDefinitions = (visible: Symbols) =>
741
- [...visible].flatMap(([name, symbol]) => {
742
- const definition = definitions.get(symbol.key);
743
- return definition ? [{ ...definition, name }] : [];
748
+ [...visible].flatMap((entry) => {
749
+ const definition = definitions.get(entry[1].key);
750
+ return definition ? [{ ...definition, name: entry[0] }] : [];
744
751
  });
745
752
 
746
753
  const javaOverrides = new Map<string, JavaOverride[]>();
@@ -909,7 +916,7 @@ export const createEnvironment = (
909
916
  getDefinitionSymbol(definition),
910
917
  ]),
911
918
  ].reduce(
912
- (symbols, [name, symbol]) => (symbols.has(name) ? symbols : symbols.set(name, symbol)),
919
+ (symbols, entry) => (symbols.has(entry[0]) ? symbols : symbols.set(entry[0], entry[1])),
913
920
  new Map(visible),
914
921
  );
915
922
  const linkNested = (nested: Module) => {
@@ -1073,7 +1080,7 @@ export const createEnvironment = (
1073
1080
  root: linkedRoot,
1074
1081
  moduleSymbols: new Map([
1075
1082
  ...standardExports,
1076
- ...[...linkedModules].map(([name, linked]): [string, Symbols] => [name, linked.visible]),
1083
+ ...[...linkedModules].map((entry): [string, Symbols] => [entry[0], entry[1].visible]),
1077
1084
  [root.name, linkedRoot.visible],
1078
1085
  ]),
1079
1086
  definitions,
package/src/instances.ts CHANGED
@@ -744,14 +744,14 @@ const copyDefinition = (rewrite: Rewrite, key: string): string => {
744
744
  ? mapped.body
745
745
  : {
746
746
  kind: "Let",
747
- definitions: [...bindings].map(([name, replacement]): Definition => ({
747
+ definitions: [...bindings].map((entry): Definition => ({
748
748
  kind: "Operator",
749
- name,
749
+ name: entry[0],
750
750
  params: [],
751
- body: replacement,
751
+ body: entry[1],
752
752
  isLocal: true,
753
753
  isRecursive: false,
754
- location: replacement.location,
754
+ location: entry[1].location,
755
755
  })),
756
756
  body: mapped.body,
757
757
  // TLC has no such LET, so the call stack it prints has no position for it.
@@ -184,8 +184,8 @@ const readClassFile = (bytes: Uint8Array) => {
184
184
  getJavaClassName(pool, thrown.readUint16()),
185
185
  )
186
186
  : [];
187
- const modifiers = METHOD_MODIFIERS.filter(([flag]) => (access & flag) !== 0).map(
188
- ([, modifier]) => modifier,
187
+ const modifiers = METHOD_MODIFIERS.filter((entry) => (access & entry[0]) !== 0).map(
188
+ (entry) => entry[1],
189
189
  );
190
190
  const returnType = getTypeNames(descriptor.slice(parametersEnd + 1))[0];
191
191
  const throwsClause = exceptions.length === 0 ? "" : ` throws ${exceptions.join(",")}`;
package/src/levels.ts CHANGED
@@ -156,11 +156,11 @@ const CORE_SIGNATURES = new Map(
156
156
  ["BOOLEAN", 0, [], []],
157
157
  ["STRING", 0, [], []],
158
158
  ] as const
159
- ).map(([name, level, maxLevels, weights]): [string, OperatorLevels] => [
160
- name,
159
+ ).map((signature): [string, OperatorLevels] => [
160
+ signature[0],
161
161
  {
162
- ...createSignature(name, level, [...maxLevels], [...weights]),
163
- nonLeibniz: new Set(level > 1 ? [0, 1] : []),
162
+ ...createSignature(signature[0], signature[1], [...signature[2]], [...signature[3]]),
163
+ nonLeibniz: new Set(signature[1] > 1 ? [0, 1] : []),
164
164
  },
165
165
  ]),
166
166
  );
@@ -179,7 +179,7 @@ const loadMule = (
179
179
 
180
180
  const schedule = (modules: Map<string, Mule>) => {
181
181
  const dependencies = new Map(
182
- [...modules].map(([name, module]) => [name, getDependencies(module).dependencies]),
182
+ [...modules].map((entry) => [entry[0], getDependencies(entry[1]).dependencies]),
183
183
  );
184
184
  const seen = new Set<string>();
185
185
  const order: Mule[] = [];
@@ -351,10 +351,7 @@ const instantiate = (
351
351
  substitutes.set(name, at({ kind: "Opaque", name }, { location }));
352
352
  }
353
353
  const anonymized = new Map(
354
- [...substitutes].map(([name, expression]) => [
355
- name,
356
- pipeline.anonymizer.expr(instanceScope, expression),
357
- ]),
354
+ [...substitutes].map((entry) => [entry[0], pipeline.anonymizer.expr(instanceScope, entry[1])]),
358
355
  );
359
356
  const body = substituteUnits(
360
357
  shift((instanceScope?.size ?? 0) - (module.depth ?? 0)),
@@ -430,26 +430,26 @@ const createPrinter = (hyps: Hyp[] = [], options: PrinterOptions = {}) => {
430
430
  );
431
431
  case "Choose": {
432
432
  const domainDoc = expression.domain && printExpr(expression.domain);
433
- return withNames(context, [expression.name], ([name]) =>
433
+ return withNames(context, [expression.name], (names) =>
434
434
  createBig(
435
435
  domainDoc
436
436
  ? format(
437
437
  "@[<b2>CHOOSE @[<b2>%s \\in@ %a@] :@ %a@]",
438
- name,
438
+ names[0],
439
439
  domainDoc,
440
440
  printExpr(expression.body),
441
441
  )
442
- : format("@[<b2>CHOOSE %s :@ %a@]", name, printExpr(expression.body)),
442
+ : format("@[<b2>CHOOSE %s :@ %a@]", names[0], printExpr(expression.body)),
443
443
  ),
444
444
  );
445
445
  }
446
446
  case "SetSt": {
447
447
  const domainDoc = printExpr(expression.domain);
448
- return withNames(context, [expression.name], ([name]) =>
448
+ return withNames(context, [expression.name], (names) =>
449
449
  createAtom(
450
450
  format(
451
451
  "@[<b3>{@[<b2>%s \\in@ %a@] :@ %a}@]",
452
- name,
452
+ names[0],
453
453
  domainDoc,
454
454
  printExpr(expression.body),
455
455
  ),
package/src/parser.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import type {
2
2
  AssumeProve,
3
3
  Assumption,
4
- Bound,
5
4
  BoundPattern,
6
5
  CaseArm,
7
6
  Declaration,
@@ -22,7 +21,7 @@ import type {
22
21
  StepBody,
23
22
  UseOrHide,
24
23
  } from "./ast";
25
- import { createSanyError, formatRange, TlaSyntaxError } from "./errors";
24
+ import { TlaSyntaxError } from "./errors";
26
25
  import { getNumeralValue, readAtAsIdentifier, tokenize, type Token } from "./lexer";
27
26
  import { getSanyParseError } from "./sany/parse-error";
28
27
 
@@ -501,8 +500,6 @@ const parse = (
501
500
  let lastOperator: Precedence | undefined;
502
501
  let precedingOperator: Precedence | undefined;
503
502
  const recursiveScopes: Set<string>[] = [];
504
- const factNames = new Set<string>();
505
- const proofScopes: Set<string>[] = [];
506
503
  const openModules: Module[] = [];
507
504
  // Pco's backtracking: a failure not past a commit rewinds to its attempt's frame.
508
505
  let attemptFrame: number | undefined;
@@ -1214,9 +1211,15 @@ const parse = (
1214
1211
  const argumentRanges = [argumentsRange];
1215
1212
  while (isSelectorAhead()) {
1216
1213
  advance();
1217
- selectorRanges.push(getRange(cursor, cursor));
1214
+ const selectorStart = cursor;
1218
1215
  lastArgumentsRange = undefined;
1219
- selectors.push(parseSelector());
1216
+ const selector = parseSelector();
1217
+ selectorRanges.push(
1218
+ selector.kind === "Bound"
1219
+ ? getRange(selectorStart)
1220
+ : getRange(selectorStart, selectorStart),
1221
+ );
1222
+ selectors.push(selector);
1220
1223
  argumentRanges.push(lastArgumentsRange);
1221
1224
  }
1222
1225
  const names = selectors.flatMap((selector) =>
@@ -1367,11 +1370,12 @@ const parse = (
1367
1370
  case "LET": {
1368
1371
  const definitions: Definition[] = [];
1369
1372
  const instances: Instance[] = [];
1373
+ const recursive: Declaration[] = [];
1370
1374
  recursiveScopes.push(new Set());
1371
1375
  while (!accept("IN")) {
1372
1376
  if (isTlapm && isAt("RECURSIVE")) throw createUnexpected("Unexpected keyword RECURSIVE");
1373
1377
  if (accept("RECURSIVE")) {
1374
- declareRecursive();
1378
+ recursive.push(...declareRecursive());
1375
1379
  continue;
1376
1380
  }
1377
1381
  const unit = parseDefinition(!isTlapm && accept("LOCAL"));
@@ -1379,10 +1383,14 @@ const parse = (
1379
1383
  else definitions.push(unit);
1380
1384
  }
1381
1385
  recursiveScopes.pop();
1382
- const body = parseExpression();
1383
- return instances.length === 0
1384
- ? { kind: "Let", definitions, body, location }
1385
- : { kind: "Let", definitions, instances, body, location };
1386
+ return {
1387
+ kind: "Let",
1388
+ definitions,
1389
+ ...(instances.length > 0 && { instances }),
1390
+ ...(recursive.length > 0 && { recursive }),
1391
+ body: parseExpression(),
1392
+ location,
1393
+ };
1386
1394
  }
1387
1395
  case "CHOOSE": {
1388
1396
  const pattern = parsePattern();
@@ -2061,23 +2069,6 @@ const parse = (
2061
2069
  return isFirst ? level > outer : proofLevels[top] === level;
2062
2070
  };
2063
2071
 
2064
- const isDeclared = (name: string) =>
2065
- !factNames.has(name) &&
2066
- openModules.some(
2067
- (module) =>
2068
- module.constants.some((constant) => constant.name === name) ||
2069
- module.variables.some((variable) => variable.name === name) ||
2070
- module.definitions.some((definition) => definition.name === name),
2071
- );
2072
-
2073
- const isHideFact = (fact: Fact) => {
2074
- if (fact.kind === "ModuleFact" || fact.kind === "Subexpression") return true;
2075
- if (fact.kind === "Apply") return fact.operator.includes("!");
2076
- if (fact.kind !== "Identifier") return false;
2077
- if (fact.name.startsWith("<") || fact.name.includes("!")) return true;
2078
- return !BUILTIN_CONSTANTS.has(fact.name) && !isDeclared(fact.name);
2079
- };
2080
-
2081
2072
  const isFactAhead = () => {
2082
2073
  const token = peek();
2083
2074
  if (token.kind === "Step") return isStepReference(token);
@@ -2114,23 +2105,6 @@ const parse = (
2114
2105
  );
2115
2106
  };
2116
2107
 
2117
- const declareProofSymbol = (name: string) => proofScopes[proofScopes.length - 1]?.add(name);
2118
-
2119
- const withProofScope = <Result>(parse: () => Result) => {
2120
- proofScopes.push(new Set());
2121
- const result = parse();
2122
- proofScopes.pop();
2123
- return result;
2124
- };
2125
-
2126
- const isDeclaredSymbol = (name: string) =>
2127
- proofScopes.some((scope) => scope.has(name)) ||
2128
- openModules.some(
2129
- (module) =>
2130
- module.constants.some((constant) => constant.name === name) ||
2131
- module.variables.some((variable) => variable.name === name),
2132
- );
2133
-
2134
2108
  const parseDefinable = (): Fact => {
2135
2109
  const start = cursor;
2136
2110
  const token = peek();
@@ -2152,18 +2126,7 @@ const parse = (
2152
2126
  );
2153
2127
  };
2154
2128
 
2155
- const parseDefs = () => {
2156
- if (isTlapm) return parseSeparated(parseDefinable);
2157
- const defs = parseSeparated(parseFact);
2158
- const invalid =
2159
- mode === "tlc"
2160
- ? defs.find((def) => def.kind === "Identifier" && isDeclaredSymbol(def.name))
2161
- : undefined;
2162
- if (invalid) {
2163
- throw createError("DEF clause entry should describe a defined operator", invalid.location);
2164
- }
2165
- return defs;
2166
- };
2129
+ const parseDefs = () => parseSeparated(isTlapm ? parseDefinable : parseFact);
2167
2130
 
2168
2131
  // tlapm's usebody reads facts while an expression starts after the comma.
2169
2132
  const parseTlapmFacts = (): Fact[] => {
@@ -2195,25 +2158,16 @@ const parse = (
2195
2158
  const keyword = advance();
2196
2159
  const isOnly = keyword.text === "USE" && accept("ONLY");
2197
2160
  const keywordRange = getRange(start);
2198
- const use: UseOrHide = {
2199
- kind: keyword.text === "USE" ? "Use" : "Hide",
2200
- isOnly,
2201
- ...parseFacts(),
2202
- keyword: keywordRange,
2203
- location: getLocation(keyword),
2204
- };
2205
- const invalid =
2206
- use.kind === "Hide" && mode === "tlc" ? use.facts.filter((fact) => !isHideFact(fact)) : [];
2207
- if (invalid.length > 0) {
2208
- throw createSanyError(
2209
- invalid.map((fact) => ({
2210
- location: formatRange(fact.location.range ?? getRange(start)),
2211
- message:
2212
- "The only expression allowed as a fact in a HIDE is \nthe name of a theorem, assumption, or step.",
2213
- })),
2214
- );
2215
- }
2216
- return withRange(use, start);
2161
+ return withRange(
2162
+ {
2163
+ kind: keyword.text === "USE" ? "Use" : "Hide",
2164
+ isOnly,
2165
+ ...parseFacts(),
2166
+ keyword: keywordRange,
2167
+ location: getLocation(keyword),
2168
+ },
2169
+ start,
2170
+ );
2217
2171
  };
2218
2172
 
2219
2173
  const parseNewSymbol = (): NewSymbol => {
@@ -2229,7 +2183,6 @@ const parse = (
2229
2183
  if (level !== undefined) advance();
2230
2184
  if (level === "Variable") {
2231
2185
  const named = expectName();
2232
- declareProofSymbol(named.name);
2233
2186
  return withRange(
2234
2187
  {
2235
2188
  kind: "NewSymbol",
@@ -2244,7 +2197,6 @@ const parse = (
2244
2197
  );
2245
2198
  }
2246
2199
  const declaration = parseDeclaration();
2247
- declareProofSymbol(declaration.name);
2248
2200
  const isBounded = (level ?? "Constant") === "Constant" && isAt("\\in");
2249
2201
  if (isBounded && declaration.arity > 0) {
2250
2202
  throw createError("declared symbol with arguments before \\in");
@@ -2269,7 +2221,7 @@ const parse = (
2269
2221
  advance();
2270
2222
  advance();
2271
2223
  }
2272
- if (isAt("ASSUME")) return withProofScope(parseAssumeProve);
2224
+ if (isAt("ASSUME")) return parseAssumeProve();
2273
2225
  if (peek().kind === "Keyword" && NEW_SYMBOL_STARTS.has(peek().text))
2274
2226
  return isTlapm ? commit(parseNewSymbol) : parseNewSymbol();
2275
2227
  if (!isTlapm) return parseExpression();
@@ -2318,15 +2270,6 @@ const parse = (
2318
2270
  return peek(offset).kind === "Identifier" && isAt(terminator, offset + 1);
2319
2271
  };
2320
2272
 
2321
- const declareProofSymbols = (names: string[], bounds: Bound[]) => {
2322
- names.forEach(declareProofSymbol);
2323
- bounds.forEach((bound) =>
2324
- (bound.pattern.kind === "Name" ? [bound.pattern.name] : bound.pattern.names).forEach(
2325
- declareProofSymbol,
2326
- ),
2327
- );
2328
- };
2329
-
2330
2273
  const parseStepBody = (): StepBody => {
2331
2274
  const token = peek();
2332
2275
  if (isAt("USE") || isAt("HIDE")) return parseUseOrHide();
@@ -2347,7 +2290,6 @@ const parse = (
2347
2290
  const isBounded = isBoundAhead();
2348
2291
  const names = getNames(isBounded ? [] : parseSeparated(expectName));
2349
2292
  const bounds = isBounded ? parseBounds() : [];
2350
- declareProofSymbols(names.names, bounds);
2351
2293
  return { kind: "Take", names: names.names, nameRanges: names.ranges, bounds };
2352
2294
  }
2353
2295
  if (accept("WITNESS")) {
@@ -2357,7 +2299,6 @@ const parse = (
2357
2299
  const isNames = isNameListAhead(":");
2358
2300
  const names = getNames(isNames ? parseSeparated(expectName) : []);
2359
2301
  const bounds = isNames ? [] : parseBounds();
2360
- declareProofSymbols(names.names, bounds);
2361
2302
  expect(":");
2362
2303
  return {
2363
2304
  kind: "Pick",
@@ -2394,8 +2335,6 @@ const parse = (
2394
2335
  const start = cursor;
2395
2336
  const step = parseStepStart(isAt("QED", 1));
2396
2337
  const statementStart = cursor;
2397
- const scope = new Set<string>();
2398
- proofScopes.push(scope);
2399
2338
  const body: StepBody = accept("QED") ? { kind: "Qed" } : parseStepBody();
2400
2339
  const head = getRange(start);
2401
2340
  const statement = getRange(statementStart);
@@ -2404,8 +2343,6 @@ const parse = (
2404
2343
  throw createError("Proof of a step that does not take a proof");
2405
2344
  }
2406
2345
  const proof = hasProof ? parseProof() : undefined;
2407
- proofScopes.pop();
2408
- if (body.kind !== "Assert" || body.isSuffices) scope.forEach(declareProofSymbol);
2409
2346
  return withRange({ ...step, body, head, statement, proof }, start);
2410
2347
  };
2411
2348
 
@@ -2437,7 +2374,7 @@ const parse = (
2437
2374
  const parseProof = (): Proof => {
2438
2375
  const start = cursor;
2439
2376
  proofLevels.push(-1);
2440
- const proof = withProofScope(parseProofBody);
2377
+ const proof = parseProofBody();
2441
2378
  proofLevels.pop();
2442
2379
  return withRange(proof, start);
2443
2380
  };
@@ -2621,7 +2558,6 @@ const parse = (
2621
2558
  const parseFactName = () => {
2622
2559
  if (peek().kind !== "Identifier" || !isAt("==", 1)) return undefined;
2623
2560
  const name = expectIdentifier();
2624
- factNames.add(name);
2625
2561
  advance();
2626
2562
  return name;
2627
2563
  };
@@ -2639,16 +2575,9 @@ const parse = (
2639
2575
  const start = cursor;
2640
2576
  const keyword = advance();
2641
2577
  const name = parseFactName();
2642
- const parsed = withProofScope(() => {
2643
- const statement = isAt("ASSUME") ? parseAssumeProve() : parseTheoremExpression();
2644
- if (isTlapm) return { statement, proof: parseTlapmProof() };
2645
- return { statement, proof: isProofStart(peek()) ? parseProof() : undefined };
2646
- });
2647
- const statement = parsed.statement;
2648
- const theorem = withRange(
2649
- { name, statement, proof: parsed.proof, location: getLocation(keyword) },
2650
- start,
2651
- );
2578
+ const statement = isAt("ASSUME") ? parseAssumeProve() : parseTheoremExpression();
2579
+ const proof = isTlapm ? parseTlapmProof() : isProofStart(peek()) ? parseProof() : undefined;
2580
+ const theorem = withRange({ name, statement, proof, location: getLocation(keyword) }, start);
2652
2581
  module.theorems.push(theorem);
2653
2582
  module.units.push({ kind: "Theorem", theorem });
2654
2583
  if (name === undefined || statement.kind === "AssumeProve") return;
@@ -226,12 +226,12 @@ export const applyAttributes = (
226
226
  thms: readonly Thm[],
227
227
  ): [IsarContext, Thm[]] =>
228
228
  thms.reduce<[IsarContext, Thm[]]>(
229
- ([current, results], thm) => {
229
+ (accumulated, thm) => {
230
230
  const [declared, result] = attributes.reduce<[IsarContext, Thm]>(
231
- ([inner, changed], attribute) => applyAttribute(inner, attribute, changed),
232
- [current, thm],
231
+ (state, attribute) => applyAttribute(state[0], attribute, state[1]),
232
+ [accumulated[0], thm],
233
233
  );
234
- return [declared, [...results, result]];
234
+ return [declared, [...accumulated[1], result]];
235
235
  },
236
236
  [context, []],
237
237
  );
@@ -83,9 +83,9 @@ const rhsOf = (thm: Thm) => destEquals(thm.prop)[1];
83
83
 
84
84
  const instantiateMatch = (env: MatchEnv, rule: Thm): Thm => {
85
85
  const typed = instantiateTypes(env.tyenv, rule);
86
- const insts: Instantiation[] = tableEntries(env.tenv).map(([key, binding]) => ({
87
- variable: mkVar(key.name, key.index, substType(env.tyenv, binding.type)),
88
- term: binding.term,
86
+ const insts: Instantiation[] = tableEntries(env.tenv).map((entry) => ({
87
+ variable: mkVar(entry[0].name, entry[0].index, substType(env.tyenv, entry[1].type)),
88
+ term: entry[1].term,
89
89
  }));
90
90
  return instantiate(insts, typed);
91
91
  };
@@ -636,10 +636,10 @@ const mapAbsVars = (rename: (name: string) => string, term: Term): Term => {
636
636
 
637
637
  export const renameAbs = (pattern: Term, object: Term, term: Term): Term | undefined => {
638
638
  const renaming = new Map<string, string>();
639
- matchBvs(pattern, object, []).forEach(([from, to]) => {
640
- if (!renaming.has(from)) renaming.set(from, to);
639
+ matchBvs(pattern, object, []).forEach((pair) => {
640
+ if (!renaming.has(pair[0])) renaming.set(pair[0], pair[1]);
641
641
  });
642
- if ([...renaming].every(([from, to]) => from === to)) return undefined;
642
+ if ([...renaming].every((pair) => pair[0] === pair[1])) return undefined;
643
643
  const renamed = mapAbsVars((name) => renaming.get(name) ?? name, term);
644
644
  return renamed === term ? undefined : renamed;
645
645
  };