tla-ts 0.0.8 → 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 +98 -19
  8. package/dist/index.d.ts +98 -19
  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 -106
  21. package/dist/transfer.js +128 -106
  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 -51
  40. package/src/config.ts +101 -68
  41. package/src/coverage.ts +855 -0
  42. package/src/dependencies.ts +340 -24
  43. package/src/dfid.ts +636 -0
  44. package/src/environment.ts +289 -109
  45. package/src/errors.ts +142 -45
  46. package/src/evaluate.ts +734 -980
  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 +150 -70
  55. package/src/liveness-checker.ts +10 -18
  56. package/src/liveness.ts +122 -64
  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 +550 -150
  83. package/src/simulate.ts +694 -0
  84. package/src/spec-description.ts +167 -49
  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 +269 -85
  90. package/src/symmetry.ts +59 -147
  91. package/src/tableau.ts +1 -2
  92. package/src/tlc/fingerprint.ts +226 -151
  93. package/src/tlc/jar-data.ts +113 -6
  94. package/src/tlc/messages.ts +122 -37
  95. package/src/tlc/order.ts +56 -82
  96. package/src/tlc/random.ts +16 -16
  97. package/src/tlc/replay.ts +564 -212
  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 +910 -318
@@ -8,43 +8,210 @@ import {
8
8
  type Value,
9
9
  } from "../values";
10
10
 
11
- // FP64 with TLC's first irreducible polynomial, FP64.Polys[0], which `-fp 0` selects.
12
- const IRREDUCIBLE_POLYNOMIAL = 0x911498ae0e66bad6n;
11
+ // TLC's FP64.Polys, the irreducible polynomials that -fp picks from.
12
+ const POLYNOMIALS = [
13
+ 0x911498ae0e66bad6n,
14
+ 0xda8a0ba66dae0181n,
15
+ 0xc02f176b8f268d9fn,
16
+ 0xd617bb1220fc7812n,
17
+ 0xc6fd951ad34f9f74n,
18
+ 0xdd1897bd991704d4n,
19
+ 0xf5394c541cbfd343n,
20
+ 0xb1dded37b5c7b8f7n,
21
+ 0xb713ff61039dc632n,
22
+ 0xdfb340cb2fb03d43n,
23
+ 0xbc3e7e4c5ecb76a3n,
24
+ 0xdbb4b1349cd7058an,
25
+ 0xf53e9dcb9e915cdfn,
26
+ 0xca5f58e90dd01848n,
27
+ 0x80e7ff4406891aa1n,
28
+ 0xab541bf881fa8571n,
29
+ 0xbf274e07ac5499d5n,
30
+ 0x939b1ea933040a4en,
31
+ 0xb791a595448d75b1n,
32
+ 0x8bf88d6ef85563a2n,
33
+ 0xecb33ec339513a53n,
34
+ 0xfa2d3e722db5208an,
35
+ 0xb4e2058aac479d24n,
36
+ 0xafbd6474e7213b82n,
37
+ 0x98c1694d14ffaeefn,
38
+ 0xe188fb5c0a125e24n,
39
+ 0xfa71cc3865487d80n,
40
+ 0x891135f7c1c94569n,
41
+ 0xcf77cdd16d22e3e6n,
42
+ 0xeb5e3a1d2e2bb4b5n,
43
+ 0x92f7f5b69cd00c55n,
44
+ 0xa9fbbe40ca3b9ae9n,
45
+ 0x84a7b33d85295bden,
46
+ 0xebd4680dbb6fdee2n,
47
+ 0xa31fc46a0583b4d0n,
48
+ 0xa792c94f15de3e49n,
49
+ 0xd9d60a9feff4521an,
50
+ 0x9227ba31dfdda04bn,
51
+ 0xfb4c89c607ce162dn,
52
+ 0xa89b3b2e01479cc0n,
53
+ 0xb35a0c2a28b89f7dn,
54
+ 0x91d0b700b99d9ec2n,
55
+ 0xf0646bbda05020b0n,
56
+ 0xcb5d5f63ce043056n,
57
+ 0xd276b6a04f42a1b8n,
58
+ 0xbc1a7a7dbfeb47a3n,
59
+ 0xe138acff7a963036n,
60
+ 0xed860223c1557ee7n,
61
+ 0x9b2491e980150ab6n,
62
+ 0xe7e03dd8a5b4e59en,
63
+ 0xaaa3f5eac516783cn,
64
+ 0xfe78cc267a724180n,
65
+ 0xc22519a21edfac64n,
66
+ 0xcdb2941933fec60fn,
67
+ 0xc5f485551ef38aa1n,
68
+ 0xa19293d250bd3335n,
69
+ 0xa4d4c215a50b7afen,
70
+ 0xc1155176406a5070n,
71
+ 0xecadaa8200e123ecn,
72
+ 0xbacfe629d58b2f08n,
73
+ 0xded991082148cb42n,
74
+ 0x9a0ccbe5deaa88dbn,
75
+ 0x9a83246f342061bbn,
76
+ 0xb71482842297ab05n,
77
+ 0xf2407eeb997592bdn,
78
+ 0xb7b43d4b5c4c4bccn,
79
+ 0xb339a2568221ffe7n,
80
+ 0xdb4b6b379446ef9en,
81
+ 0xe43c205bb5c0b2b6n,
82
+ 0xe8e1d141f19d6db0n,
83
+ 0xd19e8710a4ea1c86n,
84
+ 0x9704cecfa8d6d07bn,
85
+ 0xb0a35716162c3f26n,
86
+ 0xa2a68c0cf56390acn,
87
+ 0xe4a74bc601c95b46n,
88
+ 0xe668fff675595e56n,
89
+ 0xe0ea77ebe06fabbbn,
90
+ 0xa8bb94f585279523n,
91
+ 0xbeb667b42b684f21n,
92
+ 0xd7b65410189e28afn,
93
+ 0x85722037beffc5b9n,
94
+ 0xe7e7c5f773426204n,
95
+ 0xa5fd0cc8e060c6f4n,
96
+ 0xb8f91ee9065dcf95n,
97
+ 0xb4047008040f8b50n,
98
+ 0xecb9ab6291c8cfccn,
99
+ 0xe08bb9b70caad6dfn,
100
+ 0xd6e086a301d95d56n,
101
+ 0xf6a808f5f3fb9da3n,
102
+ 0xfa74b8a8ef86fbc5n,
103
+ 0xa0b6b33ba9e6381cn,
104
+ 0x8c78703427873dbbn,
105
+ 0xc5516ea423011021n,
106
+ 0xb075cce8528ae7e2n,
107
+ 0x92e4a37979e2b13bn,
108
+ 0xafc9ab000ed81026n,
109
+ 0xf1873f2a861a518an,
110
+ 0xf885d6b35770192cn,
111
+ 0xd2a82f27f71f5f7en,
112
+ 0xd5e7a4dd8beb2d9fn,
113
+ 0xbab9e7e65dc23e0fn,
114
+ 0xd5fc877c0bdf5b85n,
115
+ 0xab428169b9f31c02n,
116
+ 0xb7b1351f9266d3ean,
117
+ 0xfad564914328f635n,
118
+ 0x9623ecb1000db9bdn,
119
+ 0x88d371ec6644c892n,
120
+ 0xd0a71270573e271cn,
121
+ 0xbd200d763f9d81b4n,
122
+ 0x8484fd96374bf2ean,
123
+ 0xe0d0810749432294n,
124
+ 0x8ebe9dadc88658ban,
125
+ 0xf6268c58993ae542n,
126
+ 0xd6cc88fed0d359c9n,
127
+ 0xbcaddb8d40a16690n,
128
+ 0x92817c6db421cbf6n,
129
+ 0xac63721120a371b5n,
130
+ 0xd6cc137fdced0820n,
131
+ 0xf1c5fbaebb617bd7n,
132
+ 0xac35d78c765237a5n,
133
+ 0xbd0a471fa9a23116n,
134
+ 0x943a7031b946a5aen,
135
+ 0xe4e83520cb1aaebbn,
136
+ 0xe92a4b73246dd124n,
137
+ 0xafc1e070787c4c86n,
138
+ 0xdfe84d42cf06286bn,
139
+ 0x8b29ec962e4b964bn,
140
+ 0x807eb5de812ede0fn,
141
+ 0xa3cd71299c8b3bfdn,
142
+ 0x845b8031ef886f35n,
143
+ 0x91f5a5fa9c5515a5n,
144
+ ];
13
145
 
14
- const BYTE_MOD_TABLE = (() => {
15
- const powers: bigint[] = [];
16
- for (let power = 1n << 63n; powers.length < 72;) {
17
- powers.push(power);
18
- power = (power >> 1n) ^ ((power & 1n) === 0n ? 0n : IRREDUCIBLE_POLYNOMIAL);
19
- }
20
- return Array.from({ length: 256 }, (_, byte) =>
21
- powers
22
- .slice(64, 72)
23
- .reverse()
24
- .reduce((value, power, bit) => ((byte >> bit) & 1 ? value ^ power : value), 0n),
25
- );
26
- })();
146
+ const selected = { polynomial: POLYNOMIALS[0] };
27
147
 
28
- const BYTE_MOD_HIGH = Int32Array.from(BYTE_MOD_TABLE, (entry) =>
29
- Number(BigInt.asIntN(32, entry >> 32n)),
30
- );
31
- const BYTE_MOD_LOW = Int32Array.from(BYTE_MOD_TABLE, (entry) => Number(BigInt.asIntN(32, entry)));
148
+ export const getFingerprintPolynomial = () => selected.polynomial;
32
149
 
33
- // The fingerprint being extended, as its high and low 32 bits, which avoids a BigInt operation
34
- // for every byte.
35
- const INITIAL_HIGH = Number(BigInt.asIntN(32, IRREDUCIBLE_POLYNOMIAL >> 32n));
36
- const INITIAL_LOW = Number(BigInt.asIntN(32, IRREDUCIBLE_POLYNOMIAL));
37
- let high = INITIAL_HIGH;
38
- let low = INITIAL_LOW;
150
+ const SLICE_HIGH_0 = new Int32Array(256);
151
+ const SLICE_HIGH_1 = new Int32Array(256);
152
+ const SLICE_HIGH_2 = new Int32Array(256);
153
+ const SLICE_HIGH_3 = new Int32Array(256);
154
+ const SLICE_LOW_0 = new Int32Array(256);
155
+ const SLICE_LOW_1 = new Int32Array(256);
156
+ const SLICE_LOW_2 = new Int32Array(256);
157
+ const SLICE_LOW_3 = new Int32Array(256);
158
+ // The polynomial's high and low 32 bits, which avoid a BigInt operation for every byte.
159
+ const initial = { high: 0, low: 0 };
160
+ let high = 0;
161
+ let low = 0;
39
162
 
40
163
  const extendByte = (byte: number) => {
41
164
  const index = (byte ^ low) & 0xff;
42
- low = ((low >>> 8) | (high << 24)) ^ BYTE_MOD_LOW[index];
43
- high = (high >>> 8) ^ BYTE_MOD_HIGH[index];
165
+ low = ((low >>> 8) | (high << 24)) ^ SLICE_LOW_0[index];
166
+ high = (high >>> 8) ^ SLICE_HIGH_0[index];
44
167
  };
45
168
 
46
- const extendInt = (value: number) => {
47
- for (let shift = 0; shift < 32; shift += 8) extendByte(value >>> shift);
169
+ // Extending is linear over GF(2), so extending by four bytes at once shifts the fingerprint by a
170
+ // word and adds, for each of the four, the fingerprint from zero of that byte followed by the zero
171
+ // bytes that come after it: SLICE_HIGH_k and SLICE_LOW_k hold them for k zero bytes after.
172
+ export const setFingerprintPolynomial = (index: number) => {
173
+ const polynomial = POLYNOMIALS[index];
174
+ selected.polynomial = polynomial;
175
+ const powers: bigint[] = [];
176
+ for (let power = 1n << 63n; powers.length < 72;) {
177
+ powers.push(power);
178
+ power = (power >> 1n) ^ ((power & 1n) === 0n ? 0n : polynomial);
179
+ }
180
+ const bytePowers = powers.slice(64, 72).reverse();
181
+ for (let byte = 0; byte < 256; byte++) {
182
+ const entry = bytePowers.reduce(
183
+ (value, power, bit) => ((byte >> bit) & 1 ? value ^ power : value),
184
+ 0n,
185
+ );
186
+ SLICE_HIGH_0[byte] = Number(BigInt.asIntN(32, entry >> 32n));
187
+ SLICE_LOW_0[byte] = Number(BigInt.asIntN(32, entry));
188
+ }
189
+ const highs = [SLICE_HIGH_0, SLICE_HIGH_1, SLICE_HIGH_2, SLICE_HIGH_3];
190
+ const lows = [SLICE_LOW_0, SLICE_LOW_1, SLICE_LOW_2, SLICE_LOW_3];
191
+ for (let zeros = 1; zeros < 4; zeros++) {
192
+ const previousHigh = highs[zeros - 1];
193
+ const previousLow = lows[zeros - 1];
194
+ for (let byte = 0; byte < 256; byte++) {
195
+ const index = previousLow[byte] & 0xff;
196
+ lows[zeros][byte] =
197
+ ((previousLow[byte] >>> 8) | (previousHigh[byte] << 24)) ^ SLICE_LOW_0[index];
198
+ highs[zeros][byte] = (previousHigh[byte] >>> 8) ^ SLICE_HIGH_0[index];
199
+ }
200
+ }
201
+ initial.high = Number(BigInt.asIntN(32, polynomial >> 32n));
202
+ initial.low = Number(BigInt.asIntN(32, polynomial));
203
+ };
204
+
205
+ setFingerprintPolynomial(0);
206
+
207
+ const extendInt = (word: number) => {
208
+ const mixed = low ^ word;
209
+ const first = mixed & 0xff;
210
+ const second = (mixed >>> 8) & 0xff;
211
+ const third = (mixed >>> 16) & 0xff;
212
+ const fourth = mixed >>> 24;
213
+ low = high ^ SLICE_LOW_3[first] ^ SLICE_LOW_2[second] ^ SLICE_LOW_1[third] ^ SLICE_LOW_0[fourth];
214
+ high = SLICE_HIGH_3[first] ^ SLICE_HIGH_2[second] ^ SLICE_HIGH_1[third] ^ SLICE_HIGH_0[fourth];
48
215
  };
49
216
 
50
217
  const BOOL_VALUE = 0;
@@ -54,9 +221,8 @@ const SET_ENUM_VALUE = 5;
54
221
  const FCN_RCD_VALUE = 9;
55
222
  const MODEL_VALUE = 21;
56
223
 
57
- // Value#fingerPrint for TLC's booleans, integers, strings, and model values, which returns how
58
- // many bytes it extends the fingerprint by. A model value extends the fingerprint with its
59
- // UniqueString token, and TLC numbers tokens from 1 in intern order.
224
+ // Returns how many bytes it extends the fingerprint by. A model value extends it with its
225
+ // UniqueString token, which TLC numbers from 1 in intern order.
60
226
  const extendScalar = (value: boolean | number | string | ModelValue) => {
61
227
  if (typeof value === "boolean") {
62
228
  extendByte(BOOL_VALUE);
@@ -71,9 +237,16 @@ const extendScalar = (value: boolean | number | string | ModelValue) => {
71
237
  if (typeof value === "string") {
72
238
  extendByte(STRING_VALUE);
73
239
  extendInt(value.length);
74
- for (let index = 0; index < value.length; index++) {
75
- extendByte(value.charCodeAt(index));
240
+ const whole = value.length & ~3;
241
+ for (let index = 0; index < whole; index += 4) {
242
+ extendInt(
243
+ (value.charCodeAt(index) & 0xff) |
244
+ ((value.charCodeAt(index + 1) & 0xff) << 8) |
245
+ ((value.charCodeAt(index + 2) & 0xff) << 16) |
246
+ ((value.charCodeAt(index + 3) & 0xff) << 24),
247
+ );
76
248
  }
249
+ for (let index = whole; index < value.length; index++) extendByte(value.charCodeAt(index));
77
250
  return 5 + value.length;
78
251
  }
79
252
  extendByte(MODEL_VALUE);
@@ -81,7 +254,6 @@ const extendScalar = (value: boolean | number | string | ModelValue) => {
81
254
  return 5;
82
255
  };
83
256
 
84
- // Value#fingerPrint for each of TLC's value classes.
85
257
  const extendValue = (value: Value) => {
86
258
  if (typeof value !== "object" || isModelValue(value)) {
87
259
  extendScalar(value);
@@ -101,12 +273,11 @@ const extendValue = (value: Value) => {
101
273
  }
102
274
  };
103
275
 
104
- // TLCStateMut#fingerPrint of variable values in TLC's variable order. Evaluating a lazy value can
105
- // fingerprint another, so this restores the fingerprint it interrupts.
276
+ // Evaluating a lazy value can fingerprint another, so this restores the fingerprint it interrupts.
106
277
  export const getTlcFingerprint = (state: Value[]) => {
107
278
  const outer = { high, low };
108
- high = INITIAL_HIGH;
109
- low = INITIAL_LOW;
279
+ high = initial.high;
280
+ low = initial.low;
110
281
  for (const value of state) extendValue(value);
111
282
  const fingerprint = (BigInt(high >>> 0) << 32n) | BigInt(low >>> 0);
112
283
  high = outer.high;
@@ -114,116 +285,20 @@ export const getTlcFingerprint = (state: Value[]) => {
114
285
  return fingerprint;
115
286
  };
116
287
 
117
- // The fingerprint after `length` zero bytes, as one table per byte of the fingerprint it shifts.
118
- const createShiftTable = (length: number) => {
119
- const table = new Int32Array(8 * 256 * 2);
120
- for (let bit = 0; bit < 64; bit++) {
121
- high = bit < 32 ? 0 : 1 << (bit - 32);
122
- low = bit < 32 ? 1 << bit : 0;
123
- for (let step = 0; step < length; step++) extendByte(0);
124
- const position = bit >> 3;
125
- const mask = 1 << (bit & 7);
126
- for (let byte = mask; byte < 2 * mask; byte++) {
127
- const entry = (position * 256 + byte) * 2;
128
- const rest = (position * 256 + byte - mask) * 2;
129
- table[entry] = table[rest] ^ high;
130
- table[entry + 1] = table[rest + 1] ^ low;
131
- }
132
- }
133
- return table;
134
- };
135
-
136
- // The functions and sets a fingerprinter caches before it starts over, which bounds the values it
137
- // keeps alive.
138
- const CACHED_VALUE_LIMIT = 1 << 22;
139
-
140
- // Extending a fingerprint by a byte is linear over GF(2), so extending it by a value's bytes
141
- // XORs the value's own fingerprint from zero into the fingerprint shifted by their length.
142
- // The fingerprinter caches each distinct function or set it meets, nested ones included, across
143
- // every batch of states it fingerprints, as states share most of their values, even states of
144
- // different levels. It reads a state's variables in `order`.
145
- export const createTlcFingerprinter = (order: number[], limit = CACHED_VALUE_LIMIT) => {
146
- const shiftTables = new Map<number, Int32Array>();
147
- const ids = new Map<Value, number>();
148
- // The byte count and fingerprint from zero of each cached value, three numbers per id, and the
149
- // shift table for its byte count.
150
- const contributions: number[] = [];
151
- const contributionShiftTables: Int32Array[] = [];
152
- const getShiftTable = (length: number) => {
153
- const cached = shiftTables.get(length);
154
- if (cached) return cached;
155
- const table = createShiftTable(length);
156
- shiftTables.set(length, table);
157
- return table;
158
- };
159
- // Extends the fingerprint by a value's bytes and returns how many there are.
160
- const extendElement = (value: Value): number => {
161
- if (typeof value !== "object" || isModelValue(value)) return extendScalar(value);
162
- const id = getId(value);
163
- const table = contributionShiftTables[id];
164
- const shiftedHigh = high;
165
- const shiftedLow = low;
166
- high = contributions[3 * id + 1];
167
- low = contributions[3 * id + 2];
168
- for (let position = 0; position < 8; position++) {
169
- const word = position < 4 ? shiftedLow : shiftedHigh;
170
- const entry = (position * 256 + ((word >>> ((position & 3) * 8)) & 0xff)) * 2;
171
- high ^= table[entry];
172
- low ^= table[entry + 1];
173
- }
174
- return contributions[3 * id];
175
- };
176
- const getId = (value: Value) => {
177
- const cached = ids.get(value);
178
- if (cached !== undefined) return cached;
179
- const outerHigh = high;
180
- const outerLow = low;
181
- high = 0;
182
- low = 0;
183
- const length = { value: 5 };
184
- if (isFunctionValue(value)) {
185
- const functionValue = toFiniteFunction(value);
186
- extendByte(FCN_RCD_VALUE);
187
- extendInt(functionValue.domain.length);
188
- for (let index = 0; index < functionValue.domain.length; index++) {
189
- length.value += extendElement(functionValue.domain[index]);
190
- length.value += extendElement(functionValue.range[index]);
191
- }
192
- } else {
193
- const elements = toFiniteSet(value).elements;
194
- extendByte(SET_ENUM_VALUE);
195
- extendInt(elements.length);
196
- for (const element of elements) length.value += extendElement(element);
197
- }
198
- const id = contributionShiftTables.length;
199
- ids.set(value, id);
200
- contributions.push(length.value, high, low);
201
- contributionShiftTables.push(getShiftTable(length.value));
202
- high = outerHigh;
203
- low = outerLow;
204
- return id;
205
- };
206
- return (states: Value[][]) => {
207
- const fingerprints = new BigInt64Array(states.length);
208
- // Each fingerprint's low and high words, as a BigInt64Array is little-endian.
209
- const words = new Int32Array(fingerprints.buffer);
210
- const outerHigh = high;
211
- const outerLow = low;
212
- states.forEach((state, position) => {
213
- if (ids.size >= limit) {
214
- shiftTables.clear();
215
- ids.clear();
216
- contributions.length = 0;
217
- contributionShiftTables.length = 0;
218
- }
219
- high = INITIAL_HIGH;
220
- low = INITIAL_LOW;
221
- for (const index of order) extendElement(state[index]);
222
- words[2 * position] = low;
223
- words[2 * position + 1] = high;
224
- });
225
- high = outerHigh;
226
- low = outerLow;
227
- return fingerprints;
228
- };
288
+ export const getTlcFingerprints = (states: Value[][], order: number[]) => {
289
+ const fingerprints = new BigInt64Array(states.length);
290
+ // Each fingerprint's low and high words, as a BigInt64Array is little-endian.
291
+ const words = new Int32Array(fingerprints.buffer);
292
+ const outerHigh = high;
293
+ const outerLow = low;
294
+ states.forEach((state, position) => {
295
+ high = initial.high;
296
+ low = initial.low;
297
+ for (const index of order) extendValue(state[index]);
298
+ words[2 * position] = low;
299
+ words[2 * position + 1] = high;
300
+ });
301
+ high = outerHigh;
302
+ low = outerLow;
303
+ return fingerprints;
229
304
  };
@@ -430,6 +430,16 @@ export const TLC_RUNTIME_STRINGS = [
430
430
  "levelmean",
431
431
  "levelvariance",
432
432
  "bfs",
433
+ "beginLine",
434
+ "beginColumn",
435
+ "endLine",
436
+ "endColumn",
437
+ "module",
438
+ "name",
439
+ "location",
440
+ "context",
441
+ "parameters",
442
+ "_action",
433
443
  ];
434
444
 
435
445
  export const SANY_NODE_NAMES = [
@@ -550,10 +560,6 @@ export const SANY_NODE_NAMES = [
550
560
  "N_AssertStep",
551
561
  ];
552
562
 
553
- // The standard modules that a spec may ship its own file of, such as CommunityModules' Json.tla,
554
- // which SANY reads in place of its own.
555
- export const USER_STANDARD_MODULES = new Set(["Bags", "Json", "Randomization", "TLCExt"]);
556
-
557
563
  export const TLC_MODULE_SOURCES = new Map([
558
564
  [
559
565
  "Naturals",
@@ -925,9 +931,57 @@ _PrintCounts == PrintT(_Counts)
925
931
  ],
926
932
  ]);
927
933
 
928
- // The Java methods that override standard module operators, as java.lang.reflect.Method prints
929
- // them in TLC's errors.
934
+ // As java.lang.reflect.Method prints them in TLC's errors.
930
935
  export const TLC_JAVA_METHODS = new Map([
936
+ [
937
+ "Bags",
938
+ new Map([
939
+ [
940
+ "IsABag",
941
+ "public static tlc2.value.IBoolValue tlc2.module.Bags.IsABag(tlc2.value.impl.Value)",
942
+ ],
943
+ [
944
+ "BagCardinality",
945
+ "public static tlc2.value.impl.IntValue tlc2.module.Bags.BagCardinality(tlc2.value.impl.Value)",
946
+ ],
947
+ [
948
+ "BagIn",
949
+ "public static tlc2.value.IBoolValue tlc2.module.Bags.BagIn(tlc2.value.impl.Value,tlc2.value.impl.Value)",
950
+ ],
951
+ [
952
+ "CopiesIn",
953
+ "public static tlc2.value.impl.IntValue tlc2.module.Bags.CopiesIn(tlc2.value.impl.Value,tlc2.value.impl.Value)",
954
+ ],
955
+ [
956
+ "\\oplus",
957
+ "public static tlc2.value.impl.Value tlc2.module.Bags.BagCup(tlc2.value.impl.Value,tlc2.value.impl.Value)",
958
+ ],
959
+ [
960
+ "\\ominus",
961
+ "public static tlc2.value.impl.Value tlc2.module.Bags.BagDiff(tlc2.value.impl.Value,tlc2.value.impl.Value)",
962
+ ],
963
+ [
964
+ "BagUnion",
965
+ "public static tlc2.value.impl.Value tlc2.module.Bags.BagUnion(tlc2.value.impl.Value)",
966
+ ],
967
+ [
968
+ "\\sqsubseteq",
969
+ "public static tlc2.value.IBoolValue tlc2.module.Bags.SqSubseteq(tlc2.value.impl.Value,tlc2.value.impl.Value)",
970
+ ],
971
+ [
972
+ "BagOfAll",
973
+ "public static tlc2.value.impl.Value tlc2.module.Bags.BagOfAll(tlc2.value.impl.Value,tlc2.value.impl.Value)",
974
+ ],
975
+ [
976
+ "BagToSet",
977
+ "public static tlc2.value.impl.Value tlc2.module.Bags.BagToSet(tlc2.value.impl.Value)",
978
+ ],
979
+ [
980
+ "SetToBag",
981
+ "public static tlc2.value.impl.Value tlc2.module.Bags.SetToBag(tlc2.value.impl.Value)",
982
+ ],
983
+ ]),
984
+ ],
931
985
  [
932
986
  "FiniteSets",
933
987
  new Map([
@@ -1023,4 +1077,57 @@ export const TLC_JAVA_METHODS = new Map([
1023
1077
  ],
1024
1078
  ]),
1025
1079
  ],
1080
+ [
1081
+ "TLCExt",
1082
+ new Map([
1083
+ [
1084
+ "AssertError",
1085
+ "public static synchronized tlc2.value.impl.Value tlc2.module.TLCExt.assertError(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel)",
1086
+ ],
1087
+ [
1088
+ "PickSuccessor",
1089
+ "public static synchronized tlc2.value.impl.Value tlc2.module.TLCExt.pickSuccessor(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel)",
1090
+ ],
1091
+ [
1092
+ "ToTrace",
1093
+ "public static tlc2.value.impl.Value tlc2.module.TLCExt.lassoOrdinal(tlc2.value.impl.Value)",
1094
+ ],
1095
+ [
1096
+ "CounterExample",
1097
+ "public static tlc2.value.impl.Value tlc2.module.TLCExt.error(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel) throws java.io.IOException",
1098
+ ],
1099
+ [
1100
+ "Trace",
1101
+ "public static tlc2.value.impl.TupleValue tlc2.module.TLCExt.getTrace(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel) throws java.io.IOException",
1102
+ ],
1103
+ [
1104
+ "TLCDefer",
1105
+ "public static tlc2.value.impl.Value tlc2.module.TLCExt.tlcDefer(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel)",
1106
+ ],
1107
+ [
1108
+ "TLCNoOp",
1109
+ "public static tlc2.value.impl.Value tlc2.module.TLCExt.tlcNoOp(tlc2.value.impl.Value)",
1110
+ ],
1111
+ [
1112
+ "TLCModelValue",
1113
+ "public static synchronized tlc2.value.impl.Value tlc2.module.TLCExt.tlcModelValue(tlc2.value.impl.Value)",
1114
+ ],
1115
+ [
1116
+ "TLCCache",
1117
+ "public static tlc2.value.impl.Value tlc2.module.TLCExt.tlcEval2(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel)",
1118
+ ],
1119
+ [
1120
+ "TLCFP",
1121
+ "public static synchronized tlc2.value.impl.IntValue tlc2.module.TLCExt.tlcFingerprint(tlc2.value.impl.Value)",
1122
+ ],
1123
+ [
1124
+ "TLCEvalDefinition",
1125
+ "public static tlc2.value.impl.Value tlc2.module.TLCExt.tlcDefByName(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel)",
1126
+ ],
1127
+ [
1128
+ "TLCGetOrDefault",
1129
+ "public static tlc2.value.impl.Value tlc2.module.TLCExt.tlcGetOrDefault(tlc2.value.impl.Value,tlc2.value.impl.Value)",
1130
+ ],
1131
+ ]),
1132
+ ],
1026
1133
  ]);