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
@@ -39,10 +39,13 @@ export interface SpecAction {
39
39
  scope: Scope | undefined;
40
40
  }
41
41
 
42
- interface SpecDescription {
42
+ export interface SpecDescription {
43
43
  inits: SpecAction[];
44
44
  actions: SpecAction[];
45
45
  temporals: SpecAction[];
46
+ }
47
+
48
+ interface PropertyDescription {
46
49
  invariants: SpecAction[];
47
50
  impliedInits: SpecAction[];
48
51
  impliedActions: SpecAction[];
@@ -180,6 +183,16 @@ const unwrapBinding = (
180
183
  return thunk && { expression: thunk.expression, scope: thunk.scope };
181
184
  };
182
185
 
186
+ const getCallScope = (
187
+ called: Closure,
188
+ expression: Expression,
189
+ scope: Scope | undefined,
190
+ environment: Environment,
191
+ ) =>
192
+ expression.kind === "Apply"
193
+ ? bindOperatorArguments(called, expression.args, getConstantContext(environment, scope))
194
+ : called.scope;
195
+
183
196
  const getParameters = (closure: Closure | undefined, scope: Scope | undefined) =>
184
197
  (closure?.params ?? []).flatMap((param): [string, Value][] => {
185
198
  const binding = lookupScope(scope, param.name);
@@ -388,7 +401,7 @@ const describeProperty = (
388
401
  expression: Expression,
389
402
  scope: Scope | undefined,
390
403
  environment: Environment,
391
- description: SpecDescription,
404
+ description: PropertyDescription,
392
405
  ): void => {
393
406
  const recurse = (inner: Expression, innerScope: Scope | undefined) =>
394
407
  describeProperty(configName, inner, innerScope, environment, description);
@@ -400,12 +413,7 @@ const describeProperty = (
400
413
  const called = resolveClosure(expression, scope, environment);
401
414
  if (called && isConstantDefinition(called, environment)) return;
402
415
  if (called && called.params.length === getArguments(expression).length) {
403
- recurse(
404
- called.body,
405
- expression.kind === "Apply"
406
- ? bindOperatorArguments(called, expression.args, getConstantContext(environment, scope))
407
- : called.scope,
408
- );
416
+ recurse(called.body, getCallScope(called, expression, scope, environment));
409
417
  return;
410
418
  }
411
419
  if (expression.kind === "Forall") {
@@ -451,20 +459,13 @@ const getOperatorDefinition = (name: string, environment: Environment) => {
451
459
  : undefined;
452
460
  };
453
461
 
454
- const getSpecDescription = (
462
+ // Tool's constructor describes the specification once, so a caller keeps the description and never walks it again.
463
+ export const getSpecDescription = (
455
464
  config: ModelConfig,
456
465
  environment: Environment,
457
466
  instanceActions: Map<string, InstanceAction>,
458
467
  ) => {
459
- const description: SpecDescription = {
460
- inits: [],
461
- actions: [],
462
- temporals: [],
463
- invariants: [],
464
- impliedInits: [],
465
- impliedActions: [],
466
- impliedTemporals: [],
467
- };
468
+ const description: SpecDescription = { inits: [], actions: [], temporals: [] };
468
469
  const next: NextItem[] = [];
469
470
  const specification =
470
471
  config.specification === undefined
@@ -546,32 +547,11 @@ export const getSubscriptVariables = (
546
547
  if (!called || called.params.length !== getArguments(expression).length) return true;
547
548
  const definition = getDefinition(called.name, environment);
548
549
  if (definition?.body === called.body && isStartupValue(definition, environment)) return true;
549
- return collect(
550
- called.body,
551
- expression.kind === "Apply"
552
- ? bindOperatorArguments(
553
- called,
554
- expression.args,
555
- getConstantContext(environment, innerScope),
556
- )
557
- : called.scope,
558
- );
550
+ return collect(called.body, getCallScope(called, expression, innerScope, environment));
559
551
  };
560
552
  return collect(subscript, scope) ? variables : undefined;
561
553
  };
562
554
 
563
- export const getInitActions = (
564
- config: ModelConfig,
565
- environment: Environment,
566
- instanceActions: Map<string, InstanceAction>,
567
- ) => getSpecDescription(config, environment, instanceActions).inits;
568
-
569
- export const getNextActions = (
570
- config: ModelConfig,
571
- environment: Environment,
572
- instanceActions: Map<string, InstanceAction>,
573
- ) => getSpecDescription(config, environment, instanceActions).actions;
574
-
575
555
  const formatParameters = (action: SpecAction) =>
576
556
  action.parameters.length === 0
577
557
  ? ""
@@ -584,19 +564,24 @@ export const getActionSignature = (action: SpecAction) =>
584
564
  `${action.name}${formatParameters(action)}`;
585
565
 
586
566
  export const getSpecificationValue = (
567
+ description: SpecDescription,
587
568
  config: ModelConfig,
588
569
  environment: Environment,
589
570
  variableLocations: SourceLocation[],
590
- instanceActions: Map<string, InstanceAction>,
591
571
  ): Value => {
592
- const description = getSpecDescription(config, environment, instanceActions);
572
+ const properties: PropertyDescription = {
573
+ invariants: [],
574
+ impliedInits: [],
575
+ impliedActions: [],
576
+ impliedTemporals: [],
577
+ };
593
578
  config.invariants.forEach((name) => {
594
579
  const definition = getOperatorDefinition(name, environment);
595
- if (definition) description.invariants.push(createAction(name, definition.body));
580
+ if (definition) properties.invariants.push(createAction(name, definition.body));
596
581
  });
597
582
  config.properties.forEach((name) => {
598
583
  const definition = getOperatorDefinition(name, environment);
599
- if (definition) describeProperty(name, definition.body, undefined, environment, description);
584
+ if (definition) describeProperty(name, definition.body, undefined, environment, properties);
600
585
  });
601
586
  const coverage = environment.coverage;
602
587
  const toSet = (actions: SpecAction[], kind?: CoverageKind) =>
@@ -624,10 +609,10 @@ export const getSpecificationValue = (
624
609
  ["inits", toSet(description.inits, "init")],
625
610
  ["actions", toSet(description.actions, "next")],
626
611
  ["temporals", toSet(description.temporals)],
627
- ["invariants", toSet(description.invariants, "invariant")],
628
- ["impliedinits", toSet(description.impliedInits, "implied")],
629
- ["impliedactions", toSet(description.impliedActions, "implied")],
630
- ["impliedtemporals", toSet(description.impliedTemporals)],
612
+ ["invariants", toSet(properties.invariants, "invariant")],
613
+ ["impliedinits", toSet(properties.impliedInits, "implied")],
614
+ ["impliedactions", toSet(properties.impliedActions, "implied")],
615
+ ["impliedtemporals", toSet(properties.impliedTemporals)],
631
616
  [
632
617
  "variables",
633
618
  createSet(
@@ -35,7 +35,6 @@ import {
35
35
  createSet,
36
36
  createSortedSet,
37
37
  compareValues,
38
- describeKind,
39
38
  createTuple,
40
39
  getSortedDifference,
41
40
  formatValue,
@@ -76,11 +75,6 @@ import {
76
75
  import type { TlcVersion } from "./tlc/version";
77
76
  import { getSanyStandardModules } from "./sany/modules";
78
77
 
79
- interface StandardModule {
80
- extends: string[];
81
- operators: Builtin[];
82
- }
83
-
84
78
  const isSubsetOf = (left: Value[], right: Value) =>
85
79
  left.every((element) => isElementOf(element, right));
86
80
 
@@ -501,16 +495,7 @@ const createSequencesOperators = (version: TlcVersion) =>
501
495
 
502
496
  const createFiniteSetsOperators = (version: TlcVersion) =>
503
497
  withJavaMethods("FiniteSets", [
504
- defineOperator("IsFiniteSet", 1, (args) => {
505
- const value = getValue(args, 0, "IsFiniteSet");
506
- if (isSetValue(value)) return isFiniteSet(value);
507
- if (typeof value === "object" && value.kind === "Function") return true;
508
- throw new TlaEvaluationError(
509
- typeof value === "object" && value.kind === "LazyFunction"
510
- ? `Attempted to check if the function:\n${formatValue(value)}\nis a finite set.`
511
- : `Attempted to check if the ${describeKind(value)} ${formatValue(value)} is a finite set.`,
512
- );
513
- }),
498
+ defineOperator("IsFiniteSet", 1, (args) => isFiniteSet(getValue(args, 0, "IsFiniteSet"))),
514
499
  defineOperator("Cardinality", 1, (args) => {
515
500
  const set = getValue(args, 0, "Cardinality");
516
501
  if (
@@ -593,7 +578,7 @@ export const getJavaOverrides = (
593
578
  if (name === "IOUtils") return createIoUtilsOperators(files, evaluateReplaced);
594
579
  if (name === "_TLCTrace") return createTlcTraceOperators(files);
595
580
  if (!getSanyStandardModules(runtime.version).has(name)) return undefined;
596
- const operators = getStandardModule(name, print, runtime, files, builtins)?.operators;
581
+ const operators = getStandardOperators(name, print, runtime, files, builtins);
597
582
  return name === "Randomization" && operators
598
583
  ? [...operators, createRandomSubsetSet(runtime)]
599
584
  : operators;
@@ -611,37 +596,36 @@ export const STANDARD_DEPENDENCIES = new Map([
611
596
  ["TLCExt", ["TLC", "Integers", "Naturals", "Sequences", "FiniteSets"]],
612
597
  ]);
613
598
 
614
- export const getStandardModule = (
599
+ export const STANDARD_EXTENDS = new Map([["Integers", ["Naturals"]]]);
600
+
601
+ export const getStandardOperators = (
615
602
  name: string,
616
603
  print: (text: string) => void,
617
604
  runtime: CheckerRuntime,
618
605
  files: FileSystem,
619
606
  builtins: ReadonlyMap<string, Builtin>,
620
- ): StandardModule | undefined => {
607
+ ): Builtin[] | undefined => {
621
608
  switch (name) {
622
609
  case "Naturals":
623
- return { extends: [], operators: NATURALS_OPERATORS };
610
+ return NATURALS_OPERATORS;
624
611
  case "Integers":
625
- return { extends: ["Naturals"], operators: INTEGERS_OPERATORS };
612
+ return INTEGERS_OPERATORS;
626
613
  case "Sequences":
627
- return { extends: [], operators: createSequencesOperators(runtime.version) };
614
+ return createSequencesOperators(runtime.version);
628
615
  case "FiniteSets":
629
- return { extends: [], operators: createFiniteSetsOperators(runtime.version) };
616
+ return createFiniteSetsOperators(runtime.version);
630
617
  case "TLC":
631
- return { extends: [], operators: withJavaMethods("TLC", createTlcOperators(print, runtime)) };
618
+ return withJavaMethods("TLC", createTlcOperators(print, runtime));
632
619
  case "Randomization":
633
- return { extends: [], operators: createRandomizationOperators(runtime) };
620
+ return createRandomizationOperators(runtime);
634
621
  case "_Possible":
635
- return { extends: [], operators: createPossibleOperators(print, runtime) };
622
+ return createPossibleOperators(print, runtime);
636
623
  case "Json":
637
- return { extends: [], operators: createJsonOperators(files) };
624
+ return createJsonOperators(files);
638
625
  case "Bags":
639
- return { extends: [], operators: withJavaMethods("Bags", createBagsOperators(builtins)) };
626
+ return withJavaMethods("Bags", createBagsOperators(builtins));
640
627
  case "TLCExt":
641
- return {
642
- extends: [],
643
- operators: withJavaMethods("TLCExt", createTlcExtOperators(print, runtime)),
644
- };
628
+ return withJavaMethods("TLCExt", createTlcExtOperators(print, runtime));
645
629
  default:
646
630
  return undefined;
647
631
  }
@@ -1,5 +1,6 @@
1
1
  // A port of TLC's -dump writers, tlc2.util.StateWriter and tlc2.util.DotStateWriter.
2
2
 
3
+ import { getJavaHashCode } from "./java-hash";
3
4
  import type { TlcVersion } from "./tlc/version";
4
5
 
5
6
  export interface StateDump {
@@ -67,12 +68,6 @@ const getJavaHashOrder = <Key>(keys: Key[], getHash: (key: Key) => number) => {
67
68
  const getLongHash = (value: bigint) =>
68
69
  Number(BigInt.asIntN(32, value ^ (BigInt.asUintN(64, value) >> 32n)));
69
70
 
70
- const getStringHash = (text: string) =>
71
- [...Array(text.length).keys()].reduce(
72
- (hash, index) => (Math.imul(31, hash) + text.charCodeAt(index)) | 0,
73
- 0,
74
- );
75
-
76
71
  const escapeDotString = (text: string) =>
77
72
  text.replaceAll("\\", "\\\\").replaceAll('"', '\\"').trim();
78
73
 
@@ -132,7 +127,7 @@ const createDotWriter = (
132
127
  [
133
128
  `subgraph cluster_legend {graph[style=bold];label = "Next State Actions" style="solid"\n`,
134
129
  `node [ labeljust="l",colorscheme="${COLOR_SCHEME}",style=filled,shape=record ]\n`,
135
- ...getJavaHashOrder([...colors.keys()], getStringHash).map(
130
+ ...getJavaHashOrder([...colors.keys()], getJavaHashCode).map(
136
131
  (name) => `${name.replaceAll("!", ":")} [label="${name}",fillcolor=${colors.get(name)}]\n`,
137
132
  ),
138
133
  "}",
@@ -151,12 +151,13 @@ export const createInstanceChecker = (getModule: (name: string) => ModuleContext
151
151
  return [{ ...declaration, level: data.level, operator: undefined, isLeibniz: true }];
152
152
  }
153
153
  const operand = analyzer.toOperand(expression, scope);
154
+ const operator = operand.kind === "Operator" ? operand.data : undefined;
154
155
  return [
155
156
  {
156
157
  ...declaration,
157
158
  level: operand.data.level,
158
- operator: operand.operator,
159
- isLeibniz: operand.operator === undefined || operand.operator.nonLeibniz.size === 0,
159
+ operator,
160
+ isLeibniz: operator === undefined || operator.nonLeibniz.size === 0,
160
161
  },
161
162
  ];
162
163
  });
@@ -178,14 +179,14 @@ export const createInstanceChecker = (getModule: (name: string) => ModuleContext
178
179
  addMessage(getLevelMessage(item.name, maximum));
179
180
  const operator = item.operator;
180
181
  if (!operator) return;
181
- Array.from({ length: item.arity }, (_, index) => {
182
+ for (let index = 0; index < item.arity; index++) {
182
183
  const minimum = levels.argConstraints.get(getArgumentKey(item.name, index));
183
184
  if (minimum !== undefined && getMaxLevel(operator, index) < minimum) {
184
185
  addMessage(
185
186
  `Level error in instantiating module '${check.module}':\nThe level of the argument ${index + 1} of the operator ${operator.name} \nmust be at least ${minimum}.`,
186
187
  );
187
188
  }
188
- });
189
+ }
189
190
  });
190
191
  levels.argParams.forEach((key) => {
191
192
  const parameter = parseArgumentParamKey(key);
package/src/successors.ts CHANGED
@@ -44,7 +44,7 @@ import {
44
44
  type Scope,
45
45
  type State,
46
46
  } from "./evaluate";
47
- import { mapChildren } from "./instances";
47
+ import { forEachChild } from "./instances";
48
48
  import { CORE_OPERATORS } from "./standard-modules";
49
49
  import { getRandomSubset, nextPrime, type JavaRandom } from "./tlc/random";
50
50
  import {
@@ -319,13 +319,12 @@ const getReadLocals = (
319
319
  }
320
320
  const names: string[] = [];
321
321
  let isReadOnly = true;
322
- mapChildren(expression, (child, childNames) => {
322
+ forEachChild(expression, (child, childNames) => {
323
323
  const childLocals = isReadOnly
324
324
  ? getReadLocals(child, childNames.length === 0 ? bound : new Set([...bound, ...childNames]))
325
325
  : [];
326
326
  if (childLocals) names.push(...childLocals);
327
327
  else isReadOnly = false;
328
- return child;
329
328
  });
330
329
  return isReadOnly ? names : undefined;
331
330
  };
@@ -615,11 +614,10 @@ const compileFunctionAction = (
615
614
  };
616
615
 
617
616
  const compileUnchanged = (expression: Expression, environment: Environment): Runner => {
618
- if (getUnchangedVariables(expression, environment))
619
- return compileConjunction([getUnchangedWrapper(expression)], environment, false);
620
- if (expression.kind === "Tuple")
621
- return getRunner(getUnchangedWrapper(expression), environment, false);
622
617
  const unchanged = getUnchangedWrapper(expression);
618
+ if (getUnchangedVariables(expression, environment))
619
+ return compileConjunction([unchanged], environment, false);
620
+ if (expression.kind === "Tuple") return getRunner(unchanged, environment, false);
623
621
  return (run, scope, partial, action, isFixed, onComplete) => {
624
622
  const binding =
625
623
  expression.kind === "Identifier" ? lookupScope(scope, expression.name) : undefined;
@@ -116,38 +116,43 @@ const LEVEL_PREFIXES: Record<MessageLevel, string> = {
116
116
 
117
117
  export interface MessagePrinter {
118
118
  isTool: boolean;
119
+ isDiffTrace: boolean;
119
120
  version: TlcVersion;
120
121
  print: (code: number, level: MessageLevel, text: string) => void;
121
122
  }
122
123
 
124
+ interface MessagePrinterOptions {
125
+ isTool: boolean;
126
+ isWarningEnabled?: boolean;
127
+ isDiffTrace?: boolean;
128
+ version?: TlcVersion;
129
+ suppressedCodes?: number[];
130
+ errorCodes?: number[];
131
+ }
132
+
123
133
  export const formatMessage = (isTool: boolean, code: number, level: MessageLevel, text: string) =>
124
134
  isTool
125
135
  ? `@!@!@STARTMSG ${code}:${level} @!@!@\n${text}\n@!@!@ENDMSG ${code} @!@!@`
126
136
  : `${LEVEL_PREFIXES[level]}${text}`;
127
137
 
128
- export const createMessagePrinter = (
129
- isTool: boolean,
130
- isWarningEnabled = true,
131
- version: TlcVersion = "master",
132
- suppressedCodes: number[] = [],
133
- errorCodes: number[] = [],
134
- ): MessagePrinter => {
138
+ export const createMessagePrinter = (options: MessagePrinterOptions): MessagePrinter => {
135
139
  const warnings = new Set<string>();
136
140
  return {
137
- isTool,
138
- version,
141
+ isTool: options.isTool,
142
+ isDiffTrace: options.isDiffTrace ?? false,
143
+ version: options.version ?? "master",
139
144
  print: (code, level, text) => {
140
145
  const isWarning = level === MESSAGE_LEVEL.warning;
141
- if (isWarning && errorCodes.includes(code)) {
146
+ if (isWarning && options.errorCodes?.includes(code)) {
142
147
  throw new TlaWarningAsError(code, text);
143
148
  }
144
- if (isWarning && !isWarningEnabled) return;
145
- if (level !== MESSAGE_LEVEL.error && suppressedCodes.includes(code)) return;
149
+ if (isWarning && options.isWarningEnabled === false) return;
150
+ if (level !== MESSAGE_LEVEL.error && options.suppressedCodes?.includes(code)) return;
146
151
  const hint =
147
- isWarning && !isTool && warnings.size === 0
152
+ isWarning && !options.isTool && warnings.size === 0
148
153
  ? "\n(Use the -nowarning option to disable this warning.)"
149
154
  : "";
150
- const message = formatMessage(isTool, code, level, `${text}${hint}`);
155
+ const message = formatMessage(options.isTool, code, level, `${text}${hint}`);
151
156
  if (isWarning && warnings.has(message)) return;
152
157
  if (isWarning) warnings.add(message);
153
158
  console.log(message);
@@ -386,7 +391,7 @@ export const formatNestedMessage = (text: string, isTool: boolean): string => {
386
391
  : `@!@!@STARTMSG ${code}:${MESSAGE_LEVEL.none} @!@!@\n${formatInnerMessage(code, text, isTool)}\n@!@!@ENDMSG ${code} @!@!@`;
387
392
  };
388
393
 
389
- const zeroPad = (value: number) => String(value).padStart(2, "0");
394
+ export const zeroPad = (value: number, length = 2) => String(value).padStart(length, "0");
390
395
 
391
396
  export const formatTlcDuration = (milliseconds: number) => {
392
397
  const seconds = Math.floor(milliseconds / 1000) % 60;
package/src/tlc/order.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { Module, SourceLocation } from "../ast";
2
2
  import type { ConfigValue, ModelConfig } from "../config";
3
3
  import { createMissingModuleError } from "../errors";
4
+ import { getJavaHashCode } from "../java-hash";
4
5
  import { tokenize, type Token } from "../lexer";
5
6
  import { extractModule, parseModule, parseModuleTokens } from "../parser";
6
7
  import { isBefore } from "../resolve";
@@ -55,14 +56,6 @@ const CANONICAL_OPERATORS = new Map(
55
56
 
56
57
  const getCanonicalName = (name: string) => CANONICAL_OPERATORS.get(name) ?? name;
57
58
 
58
- const getJavaHash = (text: string) => {
59
- let hash = 0;
60
- for (let index = 0; index < text.length; index++) {
61
- hash = (Math.imul(hash, 31) + text.charCodeAt(index)) | 0;
62
- }
63
- return hash;
64
- };
65
-
66
59
  const createSymbolTable = (): SymbolTable => {
67
60
  let buckets: SymbolEntry[][] = Array.from({ length: 11 }, () => []);
68
61
  let threshold = 8;
@@ -102,7 +95,7 @@ const createSymbolTable = (): SymbolTable => {
102
95
  const createEntry = (name: string, kind: SymbolKind, isLocal: boolean): SymbolEntry => ({
103
96
  key: kind === "module" ? `module ${name}` : name,
104
97
  name,
105
- hash: getJavaHash(name) & 0x7fffffff,
98
+ hash: getJavaHashCode(name) & 0x7fffffff,
106
99
  kind,
107
100
  isLocal,
108
101
  });
package/src/tlc/random.ts CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  formatValue,
9
9
  getFunctionDomain,
10
10
  isEmptySet,
11
+ MAXIMUM_INTEGER,
11
12
  toFiniteSet,
12
13
  type Value,
13
14
  } from "../values";
@@ -21,7 +22,6 @@ export interface JavaRandom {
21
22
 
22
23
  const MULTIPLIER = 0x5deece66dn;
23
24
  const SEED_MASK = (1n << 48n) - 1n;
24
- const MAXIMUM_INT = 2147483647;
25
25
 
26
26
  export const createJavaRandom = (seed: bigint): JavaRandom => {
27
27
  let state = (BigInt.asUintN(64, seed) ^ MULTIPLIER) & SEED_MASK;
@@ -39,7 +39,7 @@ export const createJavaRandom = (seed: bigint): JavaRandom => {
39
39
  if ((bound & mask) === 0) return Number((BigInt(bound) * BigInt(first)) >> 31n);
40
40
  for (let candidate = first; ; candidate = next(31)) {
41
41
  const value = candidate % bound;
42
- if (candidate - value + mask <= MAXIMUM_INT) return value;
42
+ if (candidate - value + mask <= MAXIMUM_INTEGER) return value;
43
43
  }
44
44
  },
45
45
  nextLong: () => BigInt.asIntN(64, (BigInt(next(32)) << 32n) + BigInt(next(32))),
@@ -111,7 +111,7 @@ const getSubsetIndicesMaster = (count: number, size: number, random: JavaRandom)
111
111
 
112
112
  const getSubsetIndices174 = (count: number, size: number, random: JavaRandom) => {
113
113
  if (size <= 0) return [];
114
- const stride = BigInt(size < 191 ? 191 : MAXIMUM_INT);
114
+ const stride = BigInt(size < 191 ? 191 : MAXIMUM_INTEGER);
115
115
  const offset = BigInt(random.nextInt(size));
116
116
  return Array.from(
117
117
  { length: Math.min(count, size) },
@@ -192,7 +192,7 @@ export const getRandomSubset = (
192
192
  if (product) {
193
193
  const size = product.lists.reduce((total, list) => total * BigInt(list.length), 1n);
194
194
  const indices =
195
- size > BigInt(MAXIMUM_INT)
195
+ size > BigInt(MAXIMUM_INTEGER)
196
196
  ? getLargeSubsetIndices(count, size, random)
197
197
  : getSubsetIndices(count, Number(size), random);
198
198
  return indices.map((index) => product.create(getProductElements(product.lists, index)));
package/src/tlc/replay.ts CHANGED
@@ -776,17 +776,16 @@ const visitUnchanged = (
776
776
 
777
777
  const createReplay = (
778
778
  environment: Environment,
779
- isInit: boolean,
779
+ kind: "init" | "next" | "enabled",
780
780
  current: Value[] | undefined,
781
781
  onState: (state: Value[]) => void,
782
- isEnabled = false,
783
782
  onIncomplete?: (state: State) => void,
784
783
  ): Replay => ({
785
784
  environment,
786
785
  callStack: environment.callStack,
787
786
  coverage: environment.coverage,
788
- isInit,
789
- isEnabled,
787
+ isInit: kind === "init",
788
+ isEnabled: kind === "enabled",
790
789
  current,
791
790
  onState,
792
791
  onIncomplete,
@@ -800,15 +799,9 @@ export const replayEnabled = (
800
799
  state: Value[],
801
800
  environment: Environment,
802
801
  ) => {
803
- const replay = createReplay(
804
- environment,
805
- false,
806
- state,
807
- () => {
808
- throw ENABLED_FOUND;
809
- },
810
- true,
811
- );
802
+ const replay = createReplay(environment, "enabled", state, () => {
803
+ throw ENABLED_FOUND;
804
+ });
812
805
  const callStack = replay.callStack;
813
806
  const depth = callStack?.expressions.length ?? 0;
814
807
  try {
@@ -837,7 +830,7 @@ export const replayInitialStates = (
837
830
  ) => {
838
831
  const [first, ...others] = inits;
839
832
  if (first === undefined) return;
840
- const replay = createReplay(environment, true, undefined, onState, false, onIncomplete);
833
+ const replay = createReplay(environment, "init", undefined, onState, onIncomplete);
841
834
  const rest = others.reduceRight<ActionItem | undefined>(
842
835
  (tail, init) => createItem("Predicate", init.expression, init.scope, init.node ?? -1, tail),
843
836
  undefined,
@@ -867,7 +860,7 @@ export const walkSuccessors = (
867
860
  onState: (state: Value[]) => void,
868
861
  onIncomplete?: (state: State) => void,
869
862
  ) => {
870
- const replay = createReplay(environment, false, state, onState, false, onIncomplete);
863
+ const replay = createReplay(environment, "next", state, onState, onIncomplete);
871
864
  visit(replay, action.expression, undefined, action.scope, getEmptyState(environment), node);
872
865
  };
873
866
 
@@ -37,11 +37,10 @@ import {
37
37
  setFunctionClass,
38
38
  } from "../values";
39
39
  import { getFingerprintPolynomial } from "./fingerprint";
40
-
41
- const padTime = (value: number) => String(value).padStart(2, "0");
40
+ import { zeroPad } from "./messages";
42
41
 
43
42
  const formatCalendarVersion = (date: Date) =>
44
- `${date.getUTCFullYear()}.${padTime(date.getUTCMonth() + 1)}.${padTime(date.getUTCDate())}.${padTime(date.getUTCHours())}${padTime(date.getUTCMinutes())}${padTime(date.getUTCSeconds())}`;
43
+ `${date.getUTCFullYear()}.${zeroPad(date.getUTCMonth() + 1)}.${zeroPad(date.getUTCDate())}.${zeroPad(date.getUTCHours())}${zeroPad(date.getUTCMinutes())}${zeroPad(date.getUTCSeconds())}`;
45
44
 
46
45
  const getRegisterFunction = <Key extends Value>(registers: Map<Key, Value>) =>
47
46
  createFunction([...registers].map(([key, value]): [Value, Value] => [key, createTuple([value])]));