tla-ts 0.0.10-dev.a17d6d9fa → 0.0.10-dev.a5705bfbf

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 (78) hide show
  1. package/dist/deciders.cjs +31 -31
  2. package/dist/deciders.js +2 -2
  3. package/dist/index.cjs +1 -1
  4. package/dist/index.d.cts +12 -2
  5. package/dist/index.d.ts +12 -2
  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.cjs +64 -64
  10. package/dist/prove.js +76 -76
  11. package/dist/run.cjs +42 -42
  12. package/dist/run.js +44 -44
  13. package/dist/transfer.cjs +37 -35
  14. package/dist/transfer.js +43 -41
  15. package/dist/worker.cjs +7 -7
  16. package/dist/worker.js +7 -7
  17. package/package.json +1 -1
  18. package/src/ast.ts +10 -1
  19. package/src/check-failure.ts +12 -10
  20. package/src/check-trace.ts +36 -23
  21. package/src/check.ts +182 -135
  22. package/src/cli/tlc-output.ts +17 -2
  23. package/src/cli/tlc.ts +2 -2
  24. package/src/codegen.ts +15 -19
  25. package/src/coverage.ts +190 -1
  26. package/src/dependencies.ts +19 -6
  27. package/src/dfid.ts +80 -27
  28. package/src/environment.ts +30 -1
  29. package/src/evaluate.ts +254 -59
  30. package/src/exit-codes.ts +25 -13
  31. package/src/instances.ts +11 -1
  32. package/src/levels.ts +48 -7
  33. package/src/liveness-checker.ts +98 -27
  34. package/src/liveness.ts +4 -1
  35. package/src/obligations/source.ts +2 -0
  36. package/src/parser.ts +3 -0
  37. package/src/prover/smt/solver/card2bv.ts +7 -4
  38. package/src/prover/smt/solver/context.ts +20 -4
  39. package/src/prover/smt/solver/dependent-expr-state.ts +18 -12
  40. package/src/prover/smt/solver/dt2bv-tactic.ts +36 -20
  41. package/src/prover/smt/solver/fd-solver.ts +146 -39
  42. package/src/prover/smt/solver/maxcore.ts +2 -1
  43. package/src/prover/smt/solver/maxsmt-base.ts +1 -0
  44. package/src/prover/smt/solver/model-checker.ts +1 -1
  45. package/src/prover/smt/solver/muz/dl-context.ts +12 -40
  46. package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +1 -1
  47. package/src/prover/smt/solver/muz/dl-rule.ts +6 -7
  48. package/src/prover/smt/solver/muz/hnf.ts +2 -2
  49. package/src/prover/smt/solver/muz/horn-tactic.ts +14 -1
  50. package/src/prover/smt/solver/muz/rule-properties.ts +22 -0
  51. package/src/prover/smt/solver/muz/spacer-prop-solver.ts +1 -1
  52. package/src/prover/smt/solver/opt-context.ts +1 -0
  53. package/src/prover/smt/solver/opt-solver.ts +1 -1
  54. package/src/prover/smt/solver/parallel-tactic.ts +1 -1
  55. package/src/prover/smt/solver/qsat.ts +7 -2
  56. package/src/prover/smt/solver/rewriter-tpl.ts +7 -6
  57. package/src/prover/smt/solver/sat/inc-sat-solver.ts +45 -26
  58. package/src/prover/smt/solver/sat/sat-tactic.ts +4 -2
  59. package/src/prover/smt/solver/sat/sat2goal.ts +10 -7
  60. package/src/prover/smt/solver/smt-consequences.ts +1 -1
  61. package/src/prover/smt/solver/smt-kernel.ts +9 -2
  62. package/src/prover/smt/solver/smtlib-parser.ts +6 -2
  63. package/src/prover/smt/solver/smtlib-script.ts +197 -73
  64. package/src/prover/smt/solver/tactic.ts +64 -37
  65. package/src/resolve.ts +143 -39
  66. package/src/sany/generator-expressions.ts +2 -0
  67. package/src/sany/generator-proofs.ts +1 -0
  68. package/src/search.ts +156 -37
  69. package/src/simulate.ts +143 -150
  70. package/src/spec-description.ts +3 -0
  71. package/src/standard-modules.ts +41 -16
  72. package/src/subexpressions.ts +168 -63
  73. package/src/successors.ts +33 -11
  74. package/src/symmetry.ts +1 -0
  75. package/src/tlc/replay.ts +64 -41
  76. package/src/trace-liveness.ts +529 -0
  77. package/src/typed-tier.ts +20 -6
  78. package/src/values.ts +15 -1
package/src/resolve.ts CHANGED
@@ -23,6 +23,7 @@ import {
23
23
  type UseOrHide,
24
24
  } from "./ast";
25
25
  import { formatRange, TlaSyntaxError, type SanyError } from "./errors";
26
+ import { parenthesizedRanges } from "./parser";
26
27
  import { resolveSynonym } from "./tlc/jar-data";
27
28
 
28
29
  export type SymbolKind =
@@ -60,7 +61,7 @@ interface LocalName extends Binding {
60
61
  parent: LocalName | undefined;
61
62
  goal?: Goal;
62
63
  isPending?: boolean;
63
- isNonFact?: boolean;
64
+ nonFactStep?: "Use" | "Hide" | "Instance" | "Define";
64
65
  }
65
66
 
66
67
  interface ModuleBinding extends Binding {
@@ -73,6 +74,7 @@ interface Unit {
73
74
  getInstance: (instance: Instance) => InstancedModule;
74
75
  definitions: Map<string, Definition>;
75
76
  getKey: (definition: Definition) => string;
77
+ isModuleKnown: (name: string, location: SourceLocation) => boolean;
76
78
  location: SourceLocation;
77
79
  self: Definition | undefined;
78
80
  facts: Set<string>;
@@ -125,13 +127,12 @@ interface SelectionArgument {
125
127
  range: SourceRange | undefined;
126
128
  }
127
129
 
128
- export const selections = new WeakSet<Expression>();
130
+ export const selections = new WeakMap<Expression, Expression>();
129
131
  export const selectionErrors = new WeakMap<Expression, SelectionError>();
130
132
  export const operatorSelectionErrors = new WeakMap<Expression, SanyError>();
131
133
  export const factReferences = new WeakMap<Fact[], Fact[]>();
132
134
  export const selectionArguments = new WeakMap<Expression, SelectionArgument>();
133
135
  export const nullSelections = new WeakMap<Expression, NullSelection[]>();
134
- export const selectionSources = new WeakMap<Expression, Expression>();
135
136
  const unresolvedExpressions = new WeakSet<Expression>();
136
137
  const emptyExpressions = new WeakSet<Expression>();
137
138
 
@@ -166,7 +167,7 @@ const CORE_SYMBOLS: Symbols = new Map([
166
167
  export const isBefore = (left: SourceLocation, right: SourceLocation) =>
167
168
  left.line < right.line || (left.line === right.line && left.column < right.column);
168
169
 
169
- const compareLocations = (left: SourceLocation, right: SourceLocation) =>
170
+ export const compareLocations = (left: SourceLocation, right: SourceLocation) =>
170
171
  isBefore(left, right) ? -1 : isBefore(right, left) ? 1 : 0;
171
172
 
172
173
  export const getArity = (definition: Definition) =>
@@ -464,6 +465,7 @@ export const getOperands = (expression: Expression): Expression[] | undefined =>
464
465
  case "Enabled":
465
466
  case "Always":
466
467
  case "Eventually":
468
+ case "Selection":
467
469
  return [expression.expression];
468
470
  case "BoxAction":
469
471
  case "AngleAction":
@@ -492,7 +494,7 @@ const isInScopeOfDeclaration = (assumeProve: AssumeProve, clause: number) =>
492
494
 
493
495
  const findLabel = (expression: Expression, name: string): LabelExpression | undefined => {
494
496
  if (expression.kind === "Label") return expression.name === name ? expression : undefined;
495
- if (expression.kind === "Lambda") return undefined;
497
+ if (expression.kind === "Lambda" || expression.kind === "Selection") return undefined;
496
498
  if (expression.kind === "Let") return findLabel(expression.body, name);
497
499
  return getChildren(expression).reduce<LabelExpression | undefined>(
498
500
  (found, child) => found ?? findLabel(child, name),
@@ -778,6 +780,15 @@ const checkReference = (
778
780
  return goal && { node: checkSelection(expression, selectors, goal, unit, isFact) };
779
781
  };
780
782
 
783
+ const isInstanceName = (name: string, scope: LocalName | undefined, unit: Unit) => {
784
+ const binding = lookupLocal(scope, name) ?? getModuleBinding(name, unit, undefined);
785
+ if (binding) return binding.kind === "Instance";
786
+ return (
787
+ findInstance(name, scope, unit) !== undefined &&
788
+ [...unit.bindings.keys()].some((key) => key.startsWith(`${name}!`))
789
+ );
790
+ };
791
+
781
792
  const getSymbolArity = (
782
793
  expression: Expression & { kind: "Identifier" | "Apply" | "OperatorReference" },
783
794
  name: string,
@@ -790,7 +801,7 @@ const getSymbolArity = (
790
801
  if (renamed !== undefined) return renamed;
791
802
  if (isKey(name)) return expression.kind === "Apply" ? expression.args.length : 0;
792
803
  const local = lookupLocal(scope, name);
793
- if (local?.isNonFact) {
804
+ if (local?.nonFactStep) {
794
805
  unit.errors.push({
795
806
  location: formatRange(getSpelledNameRange(expression, name)),
796
807
  message: "Step number of non-expression step used as an expression.",
@@ -808,6 +819,20 @@ const getSymbolArity = (
808
819
  if (checkReference(expression, scope, unit, false) || (isStepName(name) && local)) {
809
820
  return expression.kind === "Apply" ? expression.args.length : 0;
810
821
  }
822
+ if (isInstanceName(name, scope, unit)) {
823
+ const range = getSpelledNameRange(expression, name);
824
+ unit.errors.push({
825
+ location: formatRange({
826
+ ...range,
827
+ start: {
828
+ line: range.end.line,
829
+ column: range.end.column - name.slice(name.lastIndexOf("!") + 1).length + 1,
830
+ },
831
+ }),
832
+ message: `Operator name ${name} is incomplete.`,
833
+ });
834
+ return undefined;
835
+ }
811
836
  if (local && expression.kind !== "OperatorReference") expression.resolution = LOCAL_RESOLUTION;
812
837
  if (local) return local.arity;
813
838
  const symbol = findSymbol(name, unit);
@@ -1179,9 +1204,36 @@ const matchArgument = (
1179
1204
  resolveExpressionArgument(arg, scope, unit);
1180
1205
  return true;
1181
1206
  }
1207
+ const parenthesized = parenthesizedRanges.get(arg);
1208
+ if (parenthesized) {
1209
+ report(
1210
+ parenthesized,
1211
+ `An expression appears as argument number ${index + 1} (counting from 1) to operator '${operator}', in a position an operator is required.`,
1212
+ );
1213
+ return false;
1214
+ }
1215
+ const reference = selections.get(arg) ?? arg;
1216
+ // SANY reads a reference that ends in arguments as an application, not as a selector's arguments.
1217
+ const selectors =
1218
+ reference.kind === "Subexpression" ||
1219
+ (reference.kind === "Apply" && reference.argumentCounts?.at(-1) === 0)
1220
+ ? getSelectors(reference)
1221
+ : [];
1222
+ const selectorIndex = selectors.findIndex(
1223
+ (selector) => "args" in selector && selector.args.length > 0,
1224
+ );
1225
+ if (selectorIndex !== -1 && isReference(reference)) {
1226
+ const selector = selectors[selectorIndex];
1227
+ report(
1228
+ reference.selectorRanges?.[selectorIndex],
1229
+ `Selector \`${selector.kind === "Name" ? selector.name : "!(...)"}' should not have argument(s).`,
1230
+ );
1231
+ return false;
1232
+ }
1182
1233
  if (arg.kind === "Lambda") {
1183
1234
  if (selections.has(arg)) resolveExpression(arg, scope, unit);
1184
1235
  else resolveLambda(arg, scope, unit);
1236
+ if (findNullError(nullSelections.get(arg))) return false;
1185
1237
  const isMatched = arg.params.length === expected;
1186
1238
  if (!isMatched && selections.has(arg)) {
1187
1239
  report(range, `Expected arity ${expected} but found operator of arity ${arg.params.length}.`);
@@ -1195,16 +1247,16 @@ const matchArgument = (
1195
1247
  }
1196
1248
  return isMatched;
1197
1249
  }
1250
+ if (reference !== arg) {
1251
+ const failed = findNullError(nullSelections.get(arg));
1252
+ if (failed) unit.errors.push(failed);
1253
+ if (!failed) {
1254
+ report(reference.location.range, `Expected arity ${expected} but found operator of arity 0.`);
1255
+ }
1256
+ return false;
1257
+ }
1198
1258
  if (arg.kind === "Subexpression") {
1199
1259
  resolveExpression(arg, scope, unit);
1200
- return true;
1201
- }
1202
- if (arg.kind === "Apply" && arg.argumentCounts?.at(-1) === 0) {
1203
- const selectorIndex = arg.argumentCounts.findIndex((count) => count > 0);
1204
- report(
1205
- arg.selectorRanges?.[selectorIndex],
1206
- `Selector \`${arg.operator.split("!")[selectorIndex]}' should not have argument(s).`,
1207
- );
1208
1260
  return false;
1209
1261
  }
1210
1262
  if (arg.kind !== "Identifier" && arg.kind !== "OperatorReference") {
@@ -1344,12 +1396,6 @@ const resolveExpression = (
1344
1396
  unit.errors.push(failed);
1345
1397
  return;
1346
1398
  }
1347
- const source = selectionSources.get(expression);
1348
- if (source) {
1349
- Object.assign(expression, source);
1350
- const arity = renamedArities.get(source);
1351
- if (arity !== undefined) renamedArities.set(expression, arity);
1352
- }
1353
1399
  resolveExpression(expression, scope, { ...unit, isGenerated: true });
1354
1400
  return;
1355
1401
  }
@@ -1538,6 +1584,8 @@ const resolveExpression = (
1538
1584
  case "Subexpression":
1539
1585
  if (isSubexpressionReported(expression, scope, unit)) emptyExpressions.add(expression);
1540
1586
  return;
1587
+ case "Selection":
1588
+ return;
1541
1589
  }
1542
1590
  };
1543
1591
 
@@ -1621,7 +1669,7 @@ const isSubexpressionReported = (
1621
1669
  });
1622
1670
  return true;
1623
1671
  }
1624
- if (binding && (!SELECTABLE_KINDS.has(binding.kind) || local?.isNonFact)) {
1672
+ if (binding && (!SELECTABLE_KINDS.has(binding.kind) || local?.nonFactStep)) {
1625
1673
  reportUnselectable(head.name, range, unit);
1626
1674
  return true;
1627
1675
  }
@@ -1646,8 +1694,23 @@ const isSubexpressionReported = (
1646
1694
  return selected ? selected.node === undefined : false;
1647
1695
  };
1648
1696
 
1697
+ const reportUnknownModule = (fact: Fact & { kind: "ModuleFact" }, unit: Unit) => {
1698
+ const range = fact.location.range;
1699
+ if (unit.isModuleKnown(fact.name, fact.location) || !range) return;
1700
+ unit.errors.push({
1701
+ location: formatRange({
1702
+ ...range,
1703
+ start: { line: range.end.line, column: range.end.column - fact.name.length + 1 },
1704
+ }),
1705
+ message: `Module \`${fact.name}' used without being extended or instantiated.`,
1706
+ });
1707
+ };
1708
+
1649
1709
  const checkFact = (fact: Fact, reference: Fact, scope: LocalName | undefined, unit: Unit) => {
1650
- if (fact.kind === "ModuleFact") return undefined;
1710
+ if (fact.kind === "ModuleFact") {
1711
+ reportUnknownModule(fact, unit);
1712
+ return undefined;
1713
+ }
1651
1714
  if (fact.kind === "ExceptAt" && fact.location.range) {
1652
1715
  unit.errors.push({
1653
1716
  location: formatRange(fact.location.range),
@@ -1656,6 +1719,10 @@ const checkFact = (fact: Fact, reference: Fact, scope: LocalName | undefined, un
1656
1719
  return BUILTIN_LOCATION;
1657
1720
  }
1658
1721
  const hidden = getHiddenExpressionLocation(fact, reference, scope, unit);
1722
+ if (selections.has(fact)) {
1723
+ resolveExpression(fact, scope, unit);
1724
+ return hidden;
1725
+ }
1659
1726
  if (isInstanceArityReported(fact, scope, unit)) return hidden;
1660
1727
  const selected = checkReference(fact, scope, unit, true);
1661
1728
  if (selected) {
@@ -1669,31 +1736,48 @@ const checkFact = (fact: Fact, reference: Fact, scope: LocalName | undefined, un
1669
1736
  return isSubexpressionReported(fact, scope, unit) ? BUILTIN_LOCATION : hidden;
1670
1737
  }
1671
1738
  const name = fact.kind === "Identifier" ? fact.name : fact.kind === "Apply" ? fact.operator : "";
1672
- if (fact.kind === "Identifier" && lookupLocal(scope, name)?.isNonFact) {
1739
+ if (fact.kind === "Identifier" && lookupLocal(scope, name)?.nonFactStep) {
1673
1740
  unit.errors.push({
1674
1741
  location: formatRange(getSpelledNameRange(fact, name)),
1675
1742
  message: "Step number of non-fact used as a fact",
1676
1743
  });
1677
1744
  return BUILTIN_LOCATION;
1678
1745
  }
1679
- if (!isFact(name, unit) && !lookupLocal(scope, name)?.goal) resolveExpression(fact, scope, unit);
1746
+ if (
1747
+ !isFact(name, unit) &&
1748
+ !lookupLocal(scope, name)?.goal &&
1749
+ !(fact.kind === "Identifier" && isInstanceName(name, scope, unit))
1750
+ ) {
1751
+ resolveExpression(fact, scope, unit);
1752
+ }
1680
1753
  return hidden;
1681
1754
  };
1682
1755
 
1683
1756
  const isDefinitionEntry = (def: Fact, scope: LocalName | undefined, unit: Unit) => {
1757
+ if (def.kind === "ModuleFact") {
1758
+ reportUnknownModule(def, unit);
1759
+ return unit.isModuleKnown(def.name, def.location);
1760
+ }
1684
1761
  const range = def.location.range;
1685
1762
  const name =
1686
1763
  def.kind === "Identifier" ? def.name : def.kind === "OperatorReference" ? def.operator : "";
1687
1764
  if (name === "" || !range) return true;
1688
- const binding =
1689
- lookupLocal(scope, name) ?? findSymbol(name, unit) ?? getModuleBinding(name, unit, range);
1690
- if (binding === undefined && (isFact(name, unit) || isStepName(name))) return true;
1765
+ const local = lookupLocal(scope, name);
1766
+ const binding = local ?? findSymbol(name, unit) ?? getModuleBinding(name, unit, range);
1767
+ if (binding === undefined && isFact(name, unit)) return true;
1691
1768
  if (binding === undefined) {
1692
1769
  unit.errors.push({
1693
1770
  location: formatRange(range),
1694
1771
  message: `Unknown operator: \`${resolveSynonym(name)}'.`,
1695
1772
  });
1696
1773
  }
1774
+ if (local?.nonFactStep === "Define") return true;
1775
+ if (local?.nonFactStep) {
1776
+ unit.errors.push({
1777
+ location: formatRange(range),
1778
+ message: "DEF clause entry refers to a non-definition step.",
1779
+ });
1780
+ }
1697
1781
  if (binding && SELECTABLE_KINDS.has(binding.kind) && !isStepName(name)) return true;
1698
1782
  unit.errors.push({
1699
1783
  location: formatRange(range),
@@ -1710,7 +1794,9 @@ const getHiddenExpressionLocation = (
1710
1794
  ) => {
1711
1795
  const range = fact.location.range && formatRange(fact.location.range);
1712
1796
  if (selections.has(fact)) {
1713
- return reference.location.range && formatRange(reference.location.range);
1797
+ return findNullError(nullSelections.get(fact))
1798
+ ? BUILTIN_LOCATION
1799
+ : reference.location.range && formatRange(reference.location.range);
1714
1800
  }
1715
1801
  if (selectionErrors.has(fact) || fact.kind === "ExceptAt") return BUILTIN_LOCATION;
1716
1802
  switch (fact.kind) {
@@ -1727,11 +1813,17 @@ const getHiddenExpressionLocation = (
1727
1813
  if (fact.kind === "Subexpression" || first.kind !== "Name") return undefined;
1728
1814
  const name = fact.kind === "Identifier" ? fact.name : fact.operator;
1729
1815
  const goal = lookupLocal(scope, first.name)?.goal ?? getGoal(first.name, unit);
1730
- if (isFact(name, unit) || goal || (isStepName(name) && lookupLocal(scope, name))) {
1816
+ if (
1817
+ isFact(name, unit) ||
1818
+ goal ||
1819
+ (isStepName(name) && lookupLocal(scope, name)) ||
1820
+ (fact.kind === "Identifier" && isInstanceName(name, scope, unit))
1821
+ ) {
1731
1822
  return undefined;
1732
1823
  }
1733
1824
  const binding = findBinding(name, scope, unit);
1734
1825
  const count = fact.kind === "Apply" ? fact.args.length : 0;
1826
+ // Deviation from SANY: UseOrHideNode#factCheck crashes on a fact whose operator Generator#generateExpression could not resolve, where tla-ts reports it like a null node.
1735
1827
  return binding?.arity === count ? range : BUILTIN_LOCATION;
1736
1828
  }
1737
1829
  default:
@@ -1748,6 +1840,9 @@ const checkUseOrHide = (
1748
1840
  const hidden = statement.facts.map((fact, index) =>
1749
1841
  checkFact(fact, references[index], scope, unit),
1750
1842
  );
1843
+ const factCount = statement.facts.filter(
1844
+ (fact) => fact.kind !== "ModuleFact" || unit.isModuleKnown(fact.name, fact.location),
1845
+ ).length;
1751
1846
  const defCount = statement.defs.filter((def) => isDefinitionEntry(def, scope, unit)).length;
1752
1847
  hidden.forEach((location) => {
1753
1848
  if (location && statement.kind === "Hide") {
@@ -1759,7 +1854,7 @@ const checkUseOrHide = (
1759
1854
  }
1760
1855
  });
1761
1856
  const range = statement.location.range;
1762
- if (statement.facts.length + defCount === 0 && range) {
1857
+ if (factCount + defCount === 0 && range) {
1763
1858
  unit.errors.push({
1764
1859
  location: formatRange(range),
1765
1860
  message: statement.kind === "By" ? "Empty BY" : "Empty USE or HIDE statement.",
@@ -1880,10 +1975,13 @@ const resolveStep = (
1880
1975
  const goal = getStepGoal(body, step.location);
1881
1976
  const bindStep = (parent: LocalName | undefined): LocalName | undefined =>
1882
1977
  step.name === undefined ? parent : { name: step.name, arity: 0, kind: "Theorem", parent, goal };
1883
- const bindNonFactStep = (parent: LocalName | undefined): LocalName | undefined =>
1978
+ const bindNonFactStep = (
1979
+ parent: LocalName | undefined,
1980
+ nonFactStep: LocalName["nonFactStep"],
1981
+ ): LocalName | undefined =>
1884
1982
  step.name === undefined
1885
1983
  ? parent
1886
- : { name: step.name, arity: 0, kind: "Theorem", parent, isNonFact: true };
1984
+ : { name: step.name, arity: 0, kind: "Theorem", parent, nonFactStep };
1887
1985
  switch (body.kind) {
1888
1986
  case "Assert": {
1889
1987
  const assumed = resolveStatement(body.statement, scope, stepUnit);
@@ -1916,9 +2014,9 @@ const resolveStep = (
1916
2014
  case "Use":
1917
2015
  case "Hide":
1918
2016
  checkUseOrHide(body, scope, unit);
1919
- return bindNonFactStep(scope);
2017
+ return bindNonFactStep(scope, body.kind);
1920
2018
  case "Instance":
1921
- return bindNonFactStep(resolveLocalInstance(body, scope, stepUnit));
2019
+ return bindNonFactStep(resolveLocalInstance(body, scope, stepUnit), body.kind);
1922
2020
  case "Define":
1923
2021
  return bindNonFactStep(
1924
2022
  body.definitions.reduce(
@@ -1928,6 +2026,7 @@ const resolveStep = (
1928
2026
  : resolveDefinitions([definition], current, unit),
1929
2027
  scope,
1930
2028
  ),
2029
+ body.kind,
1931
2030
  );
1932
2031
  case "Have":
1933
2032
  case "Case":
@@ -2000,6 +2099,7 @@ export interface ModuleUnit {
2000
2099
  bound: Symbols;
2001
2100
  definitions: Map<string, Definition>;
2002
2101
  getKey: (definition: Definition) => string;
2102
+ isModuleKnown: (name: string, location: SourceLocation) => boolean;
2003
2103
  instanced: Map<Instance, Symbols>;
2004
2104
  facts: Set<string>;
2005
2105
  reports: ModuleReport[];
@@ -2049,23 +2149,25 @@ const checkSubstitutions = (
2049
2149
  resolveExpressionArgument(expression, scope, unit);
2050
2150
  return;
2051
2151
  }
2052
- if (expression.kind === "Lambda") {
2152
+ const parenthesized = parenthesizedRanges.get(expression);
2153
+ if (expression.kind === "Lambda" && !parenthesized) {
2053
2154
  resolveLambda(expression, scope, unit);
2054
2155
  if (expression.params.length !== declaration.arity && range) {
2055
2156
  reportArity(declaration, formatRange(range));
2056
2157
  }
2057
2158
  return;
2058
2159
  }
2059
- if (expression.kind === "OperatorReference") {
2160
+ if (expression.kind === "OperatorReference" && !parenthesized) {
2060
2161
  const arity = getSymbolArity(expression, expression.operator, scope, unit);
2061
2162
  if (arity === undefined) reportArity(declaration, BUILTIN_LOCATION);
2062
2163
  else if (arity !== declaration.arity && range) reportArity(declaration, formatRange(range));
2063
2164
  return;
2064
2165
  }
2065
- if (expression.kind !== "Identifier") {
2066
- if (range) {
2166
+ if (expression.kind !== "Identifier" || parenthesized) {
2167
+ const errorRange = parenthesized ?? range;
2168
+ if (errorRange) {
2067
2169
  unit.errors.push({
2068
- location: formatRange(range),
2170
+ location: formatRange(errorRange),
2069
2171
  message: `Arity ${declaration.arity} operator (not an expression) is expected \nto substitute for CONSTANT '${resolveSynonym(declaration.name)}'.`,
2070
2172
  });
2071
2173
  }
@@ -2181,6 +2283,7 @@ export const resolveSubstitutions = (
2181
2283
  getInstance: unit.getInstance,
2182
2284
  definitions: unit.definitions,
2183
2285
  getKey: unit.getKey,
2286
+ isModuleKnown: unit.isModuleKnown,
2184
2287
  location: instance.location,
2185
2288
  self: undefined,
2186
2289
  facts: new Set(),
@@ -2277,6 +2380,7 @@ export const resolveModule = (module: Module, unit: ModuleUnit) => {
2277
2380
  getInstance: unit.getInstance,
2278
2381
  definitions: unit.definitions,
2279
2382
  getKey: unit.getKey,
2383
+ isModuleKnown: unit.isModuleKnown,
2280
2384
  location,
2281
2385
  self,
2282
2386
  facts: unit.facts,
@@ -985,6 +985,8 @@ export const generateExpression = (
985
985
  return generateLabel(generation, expression);
986
986
  case "Subexpression":
987
987
  return generateSelectorExpression(generation, expression);
988
+ case "Selection":
989
+ return generateExpression(generation, expression.expression);
988
990
  }
989
991
  };
990
992
 
@@ -159,6 +159,7 @@ export const generateUseOrHide = (generation: ModuleGeneration, use: UseOrHide):
159
159
  if (facts.length + defs.length === 0)
160
160
  generation.addError(location, "Empty USE or HIDE statement.");
161
161
  if (use.kind === "Hide") {
162
+ // Deviation from SANY: UseOrHideNode#factCheck crashes on a fact whose operator Generator#generateExpression could not resolve, where tla-ts reports it like a null node.
162
163
  facts
163
164
  .filter((fact) => fact.kind === "OpAppl" && fact.operator.kind !== "ThmOrAssumpDef")
164
165
  .forEach((fact) =>