tla-ts 0.0.9-dev.4ce0657 → 0.0.9-dev.8298a52

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tla-ts",
3
- "version": "0.0.9-dev.4ce0657",
3
+ "version": "0.0.9-dev.8298a52",
4
4
  "description": "A TLA+ interpreter and model checker in TypeScript, 2× faster than TLC",
5
5
  "keywords": [
6
6
  "formal verification",
package/src/cli/tlc.ts CHANGED
@@ -354,7 +354,7 @@ const printCheckProgress = (
354
354
  return;
355
355
  case "sequential-fallback":
356
356
  process.stderr.write(
357
- `Warning: the search created the string ${JSON.stringify(progress.string)}, so tla-ts checks the model again with one worker. Workers agree on the order of strings only when the strings exist before the search.\n`,
357
+ `Warning: the search ordered the string ${JSON.stringify(progress.string)} against another string it created, so tla-ts checks the model again with one worker. Workers don't agree on the order of strings the search creates.\n`,
358
358
  );
359
359
  return;
360
360
  case "warning":
@@ -13,8 +13,8 @@ import { OUT_DEGREE_BUCKETS } from "./tlc/summary";
13
13
  import { createStateDecoder, createStateEncoder, type EncodedStates } from "./transfer";
14
14
  import {
15
15
  createCanonicalizer,
16
- getRankedString,
17
- getRankedStringCount,
16
+ freezeStringOrder,
17
+ getUnorderedString,
18
18
  setStringOrder,
19
19
  setValueVersion,
20
20
  type Value,
@@ -45,7 +45,7 @@ const runWorker = (start: StartMessage, parent: Port) => {
45
45
  const order = createTlcOrder(start.source, loadModule);
46
46
  setStringOrder(order.getStringOrder(start.config));
47
47
  setValueVersion(start.version);
48
- const startupStrings = getRankedStringCount();
48
+ freezeStringOrder();
49
49
  const specification = createEnvironment(start.config, {
50
50
  source: start.source,
51
51
  loadModule,
@@ -223,9 +223,8 @@ const runWorker = (start: StartMessage, parent: Port) => {
223
223
  }
224
224
  if (!(await steal(expansion))) break;
225
225
  }
226
- if (getRankedStringCount() !== startupStrings) {
227
- return { type: "abort", string: getRankedString(startupStrings) };
228
- }
226
+ const unorderedString = getUnorderedString();
227
+ if (unorderedString !== undefined) return { type: "abort", string: unorderedString };
229
228
  frontier.states = expansion.next;
230
229
  Atomics.store(remaining, workerIndex, frontier.states.length);
231
230
  return {
package/src/parallel.ts CHANGED
@@ -31,8 +31,8 @@ import { createStateEncoder, type EncodedStates } from "./transfer";
31
31
  import type { TlcVersion } from "./tlc/version";
32
32
  import {
33
33
  createCanonicalizer,
34
- getRankedString,
35
- getRankedStringCount,
34
+ freezeStringOrder,
35
+ getUnorderedString,
36
36
  setStringOrder,
37
37
  setValueVersion,
38
38
  type Value,
@@ -138,7 +138,7 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
138
138
  const order = createTlcOrder(options.source, loadModule);
139
139
  setStringOrder(order.getStringOrder(config));
140
140
  setValueVersion(options.version);
141
- const startupStrings = getRankedStringCount();
141
+ freezeStringOrder();
142
142
  const specification = createEnvironment(config, {
143
143
  source: options.source,
144
144
  loadModule,
@@ -237,7 +237,8 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
237
237
  if (!(error instanceof TlaEvaluationError)) throw error;
238
238
  return fallBack();
239
239
  }
240
- if (getRankedStringCount() !== startupStrings) return fallBack(getRankedString(startupStrings));
240
+ const unorderedString = getUnorderedString();
241
+ if (unorderedString !== undefined) return fallBack(unorderedString);
241
242
  statistics.depth = statistics.generatedStates === 0 ? 0 : 1;
242
243
  statistics.initialStates = {
243
244
  generated: statistics.generatedStates,
package/src/values.ts CHANGED
@@ -315,20 +315,39 @@ const checkModelValueTypes = (left: Value, right: Value, isEquality: boolean) =>
315
315
  );
316
316
  };
317
317
 
318
+ interface StringOrder {
319
+ ranks: Record<string, number>;
320
+ size: number;
321
+ // A parallel search's workers rank the strings they create in different orders, so the search
322
+ // notes the first string it orders against another string ranked from this rank on.
323
+ searchRank: number | undefined;
324
+ unorderedString: string | undefined;
325
+ }
326
+
318
327
  // TLC orders strings and model value names by when it first interned the text, so every
319
328
  // check sets the order of its spec's strings before it builds any value.
320
- const stringOrder: { ranks: Record<string, number>; size: number } = {
329
+ const stringOrder: StringOrder = {
321
330
  ranks: Object.create(null),
322
331
  size: 0,
332
+ searchRank: undefined,
333
+ unorderedString: undefined,
323
334
  };
324
335
 
325
336
  export const setStringOrder = (texts: Iterable<string>) => {
326
337
  stringOrder.ranks = Object.create(null);
327
338
  stringOrder.size = 0;
339
+ stringOrder.searchRank = undefined;
340
+ stringOrder.unorderedString = undefined;
328
341
  modelValues.clear();
329
342
  for (const text of texts) rankString(text);
330
343
  };
331
344
 
345
+ export const freezeStringOrder = () => {
346
+ stringOrder.searchRank = stringOrder.size;
347
+ };
348
+
349
+ export const getUnorderedString = () => stringOrder.unorderedString;
350
+
332
351
  // TLC 1.7.4 prints an empty function that isn't a tuple with a space between its brackets, and
333
352
  // looks a key up in a function differently, so every check also sets the version its values follow.
334
353
  const valueVersion = { is174: false };
@@ -342,11 +361,6 @@ export const rankString = (text: string) => {
342
361
  return text;
343
362
  };
344
363
 
345
- export const getRankedStringCount = () => stringOrder.size;
346
-
347
- export const getRankedString = (rank: number) =>
348
- Object.keys(stringOrder.ranks).find((text) => stringOrder.ranks[text] === rank);
349
-
350
364
  export const getStringRank = (text: string) => stringOrder.ranks[rankString(text)];
351
365
 
352
366
  const compareStrings = (left: string, right: string) => {
@@ -354,6 +368,14 @@ const compareStrings = (left: string, right: string) => {
354
368
  const ranks = stringOrder.ranks;
355
369
  const leftRank = ranks[left];
356
370
  const rightRank = ranks[right];
371
+ const searchRank = stringOrder.searchRank;
372
+ if (
373
+ searchRank !== undefined &&
374
+ (leftRank === undefined || leftRank >= searchRank) &&
375
+ (rightRank === undefined || rightRank >= searchRank)
376
+ ) {
377
+ stringOrder.unorderedString ??= left;
378
+ }
357
379
  if (leftRank !== undefined && rightRank !== undefined) return leftRank - rightRank;
358
380
  if (leftRank !== undefined) return -1;
359
381
  if (rightRank !== undefined) return 1;