tla-ts 0.0.9-dev.2813db5 → 0.0.9-dev.331c500
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/README.md +22 -1
- package/dist/compile.cjs +23 -0
- package/dist/compile.js +23 -0
- package/dist/deciders.cjs +15 -15
- package/dist/deciders.js +48 -48
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +29 -29
- package/dist/prove.js +20 -20
- package/dist/run.cjs +28 -28
- package/dist/run.js +31 -31
- package/dist/tlapm.cjs +2 -2
- package/dist/tlapm.js +1 -1
- package/dist/transfer.cjs +27 -27
- package/dist/transfer.js +26 -26
- package/dist/worker.cjs +4 -4
- package/dist/worker.js +4 -4
- package/package.json +3 -1
- package/src/check.ts +44 -31
- package/src/cli/options.ts +1 -1
- package/src/cli/tlc.ts +18 -9
- package/src/cli/typescript.ts +26 -0
- package/src/environment.ts +4 -0
- package/src/errors.ts +15 -0
- package/src/evaluate.ts +65 -10
- package/src/instances.ts +67 -6
- package/src/liveness-checker.ts +6 -3
- package/src/liveness.ts +7 -3
- package/src/parallel-worker.ts +5 -6
- package/src/parallel.ts +5 -4
- package/src/prover/smt/solver/solver.ts +31 -27
- package/src/successors.ts +3 -3
- package/src/typescript/actions.ts +494 -0
- package/src/typescript/collections.ts +615 -0
- package/src/typescript/compile.ts +70 -0
- package/src/typescript/context.ts +106 -0
- package/src/typescript/emit.ts +122 -0
- package/src/typescript/expressions.ts +508 -0
- package/src/typescript/formula.ts +160 -0
- package/src/typescript/functions.ts +295 -0
- package/src/typescript/model.ts +164 -0
- package/src/typescript/names.ts +116 -0
- package/src/typescript/program.ts +51 -0
- package/src/typescript/properties.ts +142 -0
- package/src/typescript/scope.ts +117 -0
- package/src/typescript/steps.ts +175 -0
- package/src/typescript/types.ts +178 -0
- package/src/values.ts +39 -15
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:
|
|
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;
|
|
@@ -591,12 +613,6 @@ export const valuesEqual = (left: Value, right: Value): boolean => {
|
|
|
591
613
|
}
|
|
592
614
|
return compareValues(left, right) === 0;
|
|
593
615
|
}
|
|
594
|
-
const isHashed =
|
|
595
|
-
(left.kind === "Set" || left.kind === "Function") &&
|
|
596
|
-
(right.kind === "Set" || right.kind === "Function") &&
|
|
597
|
-
left.hash !== 0 &&
|
|
598
|
-
right.hash !== 0;
|
|
599
|
-
if (isHashed && left.hash !== right.hash) return false;
|
|
600
616
|
if (left.kind === "Function" && right.kind === "Function")
|
|
601
617
|
return compareFunctions(left, right) === 0;
|
|
602
618
|
if (left.kind === "Set" && right.kind === "Set") return compareSets(left, right) === 0;
|
|
@@ -1229,18 +1245,23 @@ export const createWrittenFunction = (pairs: [Value, Value][]) => {
|
|
|
1229
1245
|
);
|
|
1230
1246
|
};
|
|
1231
1247
|
|
|
1248
|
+
const MAX_SHARED_INTERVAL_LENGTH = 1024;
|
|
1232
1249
|
const intervalDomains: Value[][] = [];
|
|
1250
|
+
const longIntervalDomains = new Map<number, WeakRef<Value[]>>();
|
|
1233
1251
|
const intervalValues: IntervalValue[] = [];
|
|
1234
1252
|
const intervalArrays = new WeakMap<Value[], IntervalValue>();
|
|
1235
1253
|
|
|
1236
1254
|
// TLC keeps the domain of a tuple, or of a function built over an interval, as an interval. Every
|
|
1237
1255
|
// function over 1..n shares one domain array per length, and the elements of any other interval
|
|
1238
1256
|
// map to it, so the array's identity records it. Callers must not mutate the returned array.
|
|
1257
|
+
// Longer domains are held weakly: a sequence that grows one element at a time would otherwise keep
|
|
1258
|
+
// an array of every length it passed through, n * n / 2 numbers in all.
|
|
1239
1259
|
const getIntervalDomain = (length: number): Value[] => {
|
|
1240
|
-
const cached = intervalDomains[length];
|
|
1260
|
+
const cached = intervalDomains[length] ?? longIntervalDomains.get(length)?.deref();
|
|
1241
1261
|
if (cached) return cached;
|
|
1242
1262
|
const domain = Array.from({ length }, (_, index) => index + 1);
|
|
1243
|
-
|
|
1263
|
+
if (length > MAX_SHARED_INTERVAL_LENGTH) longIntervalDomains.set(length, new WeakRef(domain));
|
|
1264
|
+
else intervalDomains[length] = domain;
|
|
1244
1265
|
return domain;
|
|
1245
1266
|
};
|
|
1246
1267
|
|
|
@@ -1255,7 +1276,10 @@ export const getIntervalElements = (value: IntervalValue): Value[] => {
|
|
|
1255
1276
|
};
|
|
1256
1277
|
|
|
1257
1278
|
const isIntervalDomain = (domain: Value[]) =>
|
|
1258
|
-
domain.length > 0 &&
|
|
1279
|
+
domain.length > 0 &&
|
|
1280
|
+
(domain === intervalDomains[domain.length] ||
|
|
1281
|
+
domain === longIntervalDomains.get(domain.length)?.deref() ||
|
|
1282
|
+
intervalArrays.has(domain));
|
|
1259
1283
|
|
|
1260
1284
|
// TLC keeps an interval domain only for a function built over an interval itself, so a set
|
|
1261
1285
|
// such as (1..2) \cap S, whose elements are the shared array, gets a copy.
|