tla-ts 0.0.8-dev.d9bffda → 0.0.9-dev.0dd11f695

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 (119) hide show
  1. package/README.md +30 -0
  2. package/dist/compile.cjs +23 -0
  3. package/dist/compile.js +23 -0
  4. package/dist/deciders.cjs +15 -15
  5. package/dist/deciders.js +40 -40
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +80 -10
  8. package/dist/index.d.ts +80 -10
  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 +116 -36
  15. package/dist/prove.js +116 -36
  16. package/dist/run.cjs +143 -31
  17. package/dist/run.js +143 -31
  18. package/dist/tlapm.cjs +2 -2
  19. package/dist/tlapm.js +1 -1
  20. package/dist/transfer.cjs +128 -103
  21. package/dist/transfer.js +128 -103
  22. package/dist/worker.cjs +7 -7
  23. package/dist/worker.js +7 -7
  24. package/package.json +3 -1
  25. package/src/ast.ts +7 -21
  26. package/src/bags.ts +99 -99
  27. package/src/builtins.ts +44 -75
  28. package/src/bundled-modules.ts +1 -8
  29. package/src/check.ts +605 -311
  30. package/src/cli/options.ts +12 -3
  31. package/src/cli/run.ts +2 -2
  32. package/src/cli/runtime-invariants.ts +135 -0
  33. package/src/cli/shared.ts +20 -9
  34. package/src/cli/tlc-arguments.ts +646 -0
  35. package/src/cli/tlc-usage.ts +362 -0
  36. package/src/cli/tlc.ts +571 -185
  37. package/src/cli/typescript.ts +26 -0
  38. package/src/cli/xml-exporter.ts +4 -10
  39. package/src/codegen.ts +190 -46
  40. package/src/config.ts +101 -68
  41. package/src/coverage.ts +855 -0
  42. package/src/dependencies.ts +20 -28
  43. package/src/dfid.ts +636 -0
  44. package/src/environment.ts +266 -98
  45. package/src/errors.ts +142 -45
  46. package/src/evaluate.ts +632 -298
  47. package/src/exit-codes.ts +37 -1
  48. package/src/index.ts +3 -0
  49. package/src/instances.ts +85 -9
  50. package/src/java-overrides.ts +2 -12
  51. package/src/json-reader.ts +456 -0
  52. package/src/json.ts +262 -139
  53. package/src/levels.ts +2 -3
  54. package/src/lexer.ts +17 -26
  55. package/src/liveness-checker.ts +10 -18
  56. package/src/liveness.ts +121 -49
  57. package/src/parallel-worker.ts +14 -10
  58. package/src/parallel.ts +41 -17
  59. package/src/parser.ts +436 -90
  60. package/src/pcal/ast.ts +7 -28
  61. package/src/pcal/parse.ts +11 -39
  62. package/src/pcal/tokenize.ts +4 -20
  63. package/src/pcal/translate.ts +10 -42
  64. package/src/pcal/validate.ts +3 -21
  65. package/src/pretty-print.ts +1 -2
  66. package/src/prover/smt/solver/solver.ts +31 -27
  67. package/src/randomization.ts +84 -35
  68. package/src/resolve.ts +18 -60
  69. package/src/runtime.ts +11 -4
  70. package/src/sany/builtins.ts +3 -4
  71. package/src/sany/generator.ts +128 -176
  72. package/src/sany/levels.ts +6 -30
  73. package/src/sany/lexer.ts +7 -23
  74. package/src/sany/linter.ts +31 -29
  75. package/src/sany/modules.ts +1 -5
  76. package/src/sany/nodes.ts +4 -28
  77. package/src/sany/parse-error.ts +44 -100
  78. package/src/sany/report.ts +25 -40
  79. package/src/sany/selectors.ts +8 -22
  80. package/src/sany/source.ts +8 -15
  81. package/src/sany/xml.ts +11 -42
  82. package/src/search.ts +547 -144
  83. package/src/simulate.ts +694 -0
  84. package/src/spec-description.ts +166 -48
  85. package/src/standard-definitions.ts +2 -3
  86. package/src/standard-modules.ts +264 -68
  87. package/src/state-graph.ts +51 -18
  88. package/src/subexpressions.ts +31 -5
  89. package/src/successors.ts +267 -77
  90. package/src/symmetry.ts +31 -8
  91. package/src/tableau.ts +1 -2
  92. package/src/tlc/fingerprint.ts +183 -61
  93. package/src/tlc/jar-data.ts +113 -6
  94. package/src/tlc/messages.ts +122 -37
  95. package/src/tlc/order.ts +33 -38
  96. package/src/tlc/random.ts +16 -16
  97. package/src/tlc/replay.ts +563 -211
  98. package/src/tlc/summary.ts +2 -4
  99. package/src/tlc/tlc-operators.ts +81 -36
  100. package/src/tlc/tlcext-operators.ts +138 -117
  101. package/src/tlc/trace-spec.ts +273 -0
  102. package/src/tlc/value-stream.ts +143 -0
  103. package/src/tlc/version.ts +2 -4
  104. package/src/typescript/actions.ts +494 -0
  105. package/src/typescript/collections.ts +615 -0
  106. package/src/typescript/compile.ts +70 -0
  107. package/src/typescript/context.ts +106 -0
  108. package/src/typescript/emit.ts +122 -0
  109. package/src/typescript/expressions.ts +508 -0
  110. package/src/typescript/formula.ts +160 -0
  111. package/src/typescript/functions.ts +295 -0
  112. package/src/typescript/model.ts +164 -0
  113. package/src/typescript/names.ts +116 -0
  114. package/src/typescript/program.ts +51 -0
  115. package/src/typescript/properties.ts +148 -0
  116. package/src/typescript/scope.ts +117 -0
  117. package/src/typescript/steps.ts +175 -0
  118. package/src/typescript/types.ts +178 -0
  119. package/src/values.ts +832 -255
@@ -2,21 +2,17 @@ import { getChildren, isLocallyResolved, type Definition, type Expression } from
2
2
  import type { Environment } from "./evaluate";
3
3
  import { ACTION_LEVEL, CONSTANT_LEVEL, TEMPORAL_LEVEL, VARIABLE_LEVEL } from "./levels";
4
4
 
5
- // The names of a spec that the facts depend on, which are final before the environment is built.
6
5
  interface DefinitionNames extends Pick<
7
6
  Environment,
8
7
  "definitions" | "substitutions" | "constants" | "variableIndex" | "builtins" | "variables"
9
8
  > {}
10
9
 
11
- // What TLC's evaluation needs to know about each definition of a spec: whether it is constant-level,
12
- // which effects evaluating it has, which variables it reads and its liveness level. Each fact is
13
- // reachability over the definitions it calls, so one pass over the spec's call graph computes them
14
- // all, once, when the environment is created. A row of words holds a definition's facts: the first
15
- // word holds the flags below, and the rest a bitset of the variables it reads.
10
+ // Each fact is reachability over the definitions a definition calls, so one pass over the call
11
+ // graph computes them all. A row's first word holds the flags below, and the rest a bitset of the
12
+ // variables the definition reads.
16
13
  export interface DefinitionFacts {
17
14
  ids: Map<Definition, number>;
18
15
  rows: Uint32Array;
19
- // The words of each row: one of flags, then one per 32 variables.
20
16
  words: number;
21
17
  }
22
18
 
@@ -70,8 +66,8 @@ const IMPURE_BUILTINS = new Set([
70
66
  "TLCSet",
71
67
  ]);
72
68
 
73
- // UNION and \cup build sets that stream the sets they combine until TLC caches them, and TLC
74
- // builds a new one at each evaluation.
69
+ // UNION and \cup stream the sets they combine until TLC caches them, and TLC builds a new one at
70
+ // each evaluation.
75
71
  const STREAMED_BUILTINS = new Set(["UNION", "\\cup"]);
76
72
 
77
73
  const getReferencedName = (expression: Expression) => {
@@ -89,12 +85,11 @@ interface Edge {
89
85
  // The configuration replaces the name by a constant value, which TLC's level and variable
90
86
  // analyses take for a constant and its effect analysis evaluates.
91
87
  isOverridden: boolean;
92
- // Whether the reference is outside every action and temporal operator, where the level of the
93
- // callee counts. An operator such as ENABLED fixes the level of what it holds.
88
+ // Outside every action and temporal operator, where the level of the callee counts. An operator
89
+ // such as ENABLED fixes the level of what it holds.
94
90
  isLevelCounted: boolean;
95
91
  }
96
92
 
97
- // The facts an expression's own nodes establish, with the definitions it refers to.
98
93
  const collectLocalFacts = (
99
94
  expressions: Expression[],
100
95
  environment: DefinitionNames,
@@ -102,9 +97,8 @@ const collectLocalFacts = (
102
97
  ) => {
103
98
  const row = new Uint32Array(words);
104
99
  const edges: Edge[] = [];
105
- // The level flags of a node, or undefined for a node whose level the nodes it holds decide. An
106
- // action or temporal operator has its own level whatever it holds, as does ENABLED, so nothing
107
- // below one counts towards the level, variables and callees included.
100
+ // Undefined for a node whose level the nodes it holds decide. Nothing below an action or temporal
101
+ // operator, or ENABLED, counts towards the level, variables and callees included.
108
102
  const getOwnLevelFlags = (node: Expression) => {
109
103
  const kind = node.kind;
110
104
  if (ACTION_KINDS.has(kind) || (kind === "Apply" && node.operator === "\\cdot")) {
@@ -139,7 +133,12 @@ const collectLocalFacts = (
139
133
  const definition = environment.definitions.get(target);
140
134
  const isOverridden = environment.constants.has(name);
141
135
  const variableIndex = environment.variableIndex.get(name);
142
- if (variableIndex !== undefined || environment.builtins.get(name)?.isStateLevel) {
136
+ // TLC's level bound takes an instance's definition named like a variable for the variable.
137
+ if (
138
+ variableIndex !== undefined ||
139
+ environment.builtins.get(name)?.isStateLevel ||
140
+ (definition && environment.variableIndex.has(definition.name))
141
+ ) {
143
142
  row[0] |= NONCONSTANT;
144
143
  }
145
144
  if (variableIndex !== undefined) {
@@ -162,7 +161,7 @@ const collectLocalFacts = (
162
161
  builtin?.isStateLevel &&
163
162
  !builtin.isLevelConstant
164
163
  ) {
165
- row[0] |= VARIABLE_LEVEL_FLAGS;
164
+ row[0] |= builtin.isActionLevel ? ACTION_LEVEL_FLAGS : VARIABLE_LEVEL_FLAGS;
166
165
  }
167
166
  }
168
167
  }
@@ -177,9 +176,8 @@ const getDefinitionExpressions = (definition: Definition) =>
177
176
  ? [...definition.bounds.map((bound) => bound.set), definition.body]
178
177
  : [definition.body];
179
178
 
180
- // Closes each row under bitwise or along the edges: a definition's facts are its own and those of
181
- // every definition it reaches. Tarjan's algorithm lists the strongly connected components with the
182
- // callees first, so each component ors in components that are already final.
179
+ // Tarjan's algorithm lists the strongly connected components with the callees first, so each
180
+ // component ors in components that are already final.
183
181
  const closeRows = (local: Uint32Array, words: number, edges: Int32Array[], mask: number) => {
184
182
  const count = edges.length;
185
183
  const closed = local.slice();
@@ -187,7 +185,6 @@ const closeRows = (local: Uint32Array, words: number, edges: Int32Array[], mask:
187
185
  const lowLink = new Int32Array(count);
188
186
  const component = new Int32Array(count).fill(-1);
189
187
  const stack: number[] = [];
190
- // The frame of a depth-first visit: the node and the edge it resumes at.
191
188
  const frames: number[] = [];
192
189
  let nextIndex = 0;
193
190
  let componentCount = 0;
@@ -226,7 +223,7 @@ const closeRows = (local: Uint32Array, words: number, edges: Int32Array[], mask:
226
223
  lowLink[caller] = Math.min(lowLink[caller], lowLink[node]);
227
224
  }
228
225
  if (lowLink[node] !== index[node]) continue;
229
- // The component is complete: its members share one row, which ors in their callees' rows.
226
+ // The component's members share one row, which ors in their callees' rows.
230
227
  const members: number[] = [];
231
228
  for (;;) {
232
229
  const member = stack.pop() ?? node;
@@ -299,8 +296,6 @@ export const createDefinitionFacts = (environment: DefinitionNames): DefinitionF
299
296
  return { ids, rows, words };
300
297
  };
301
298
 
302
- // The facts of a definition: from the table, or for a LET definition from its own body and the
303
- // table's rows of the definitions it calls.
304
299
  const getRow = (definition: Definition, environment: Environment): Uint32Array => {
305
300
  const facts = environment.facts;
306
301
  const id = facts.ids.get(definition);
@@ -309,7 +304,6 @@ const getRow = (definition: Definition, environment: Environment): Uint32Array =
309
304
  : facts.rows.subarray(id * facts.words, (id + 1) * facts.words);
310
305
  };
311
306
 
312
- // The facts of expressions: their own, with the rows of the definitions they call ored in.
313
307
  const getExpressionsRow = (expressions: Expression[], environment: Environment) => {
314
308
  const words = environment.facts.words;
315
309
  const local = collectLocalFacts(expressions, environment, words);
@@ -337,7 +331,6 @@ export const isImpureDefinition = (
337
331
  effect: keyof typeof EFFECT_FLAGS = "any",
338
332
  ) => (getRow(definition, environment)[0] & EFFECT_FLAGS[effect]) !== 0;
339
333
 
340
- // The liveness level of a definition: constant, variable, action or temporal.
341
334
  export const getDefinitionLevel = (definition: Definition, environment: Environment) => {
342
335
  const flags = getRow(definition, environment)[0] & TEMPORAL_LEVEL_FLAGS;
343
336
  return flags === TEMPORAL_LEVEL_FLAGS
@@ -359,8 +352,7 @@ const toVariables = (row: Uint32Array) => {
359
352
  return variables;
360
353
  };
361
354
 
362
- // The variables an expression reads, through the definitions it calls, when they and its scope
363
- // decide its value, or undefined when it has an effect or is an action.
355
+ // Undefined when the expression has an effect or is an action.
364
356
  export const getReadVariables = (
365
357
  expression: Expression,
366
358
  environment: Environment,