tla-ts 0.0.8 → 0.0.9-dev.4ce0657
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 +23 -0
- 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 +27 -9
- package/dist/index.d.ts +27 -9
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +17 -17
- package/dist/prove.js +32 -32
- 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 +30 -33
- package/dist/transfer.js +30 -33
- package/dist/worker.cjs +4 -4
- package/dist/worker.js +4 -4
- package/package.json +3 -1
- package/src/check.ts +77 -46
- package/src/cli/options.ts +2 -1
- package/src/cli/tlc.ts +26 -8
- package/src/cli/typescript.ts +26 -0
- package/src/codegen.ts +0 -5
- package/src/dependencies.ts +348 -24
- package/src/environment.ts +27 -11
- package/src/errors.ts +15 -0
- package/src/evaluate.ts +188 -712
- package/src/instances.ts +67 -6
- package/src/lexer.ts +140 -51
- package/src/liveness-checker.ts +6 -3
- package/src/liveness.ts +8 -18
- package/src/parallel-worker.ts +6 -3
- package/src/parallel.ts +15 -7
- package/src/prover/smt/solver/solver.ts +31 -27
- package/src/sany/generator.ts +9 -7
- package/src/sany/linter.ts +30 -21
- package/src/search.ts +48 -32
- package/src/spec-description.ts +1 -1
- package/src/successors.ts +6 -12
- package/src/symmetry.ts +32 -143
- package/src/tlc/fingerprint.ts +69 -116
- package/src/tlc/order.ts +27 -48
- package/src/tlc/replay.ts +1 -1
- 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 +141 -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 +126 -82
package/src/values.ts
CHANGED
|
@@ -7,6 +7,16 @@ export interface ModelValue {
|
|
|
7
7
|
name: string;
|
|
8
8
|
type: string | undefined;
|
|
9
9
|
rank: number;
|
|
10
|
+
hash: number;
|
|
11
|
+
fingerprint: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// What TLC keeps on a set it builds lazily: the enumeration it converted to and cached, as
|
|
15
|
+
// SetPredValue#convertAndCache does, whether it has cached it, and whether it has fingerprinted it.
|
|
16
|
+
interface LazySet {
|
|
17
|
+
enumerated?: SetValue;
|
|
18
|
+
isCached?: boolean;
|
|
19
|
+
isFingerprinted?: boolean;
|
|
10
20
|
}
|
|
11
21
|
|
|
12
22
|
export interface SetValue {
|
|
@@ -19,7 +29,7 @@ export interface SetValue {
|
|
|
19
29
|
|
|
20
30
|
// A set enumeration whose elements TLC can't sort, such as {1, "a"}. TLC sorts a set enumeration
|
|
21
31
|
// only when it has to, so it still checks membership in one element by element.
|
|
22
|
-
export interface MixedSetValue {
|
|
32
|
+
export interface MixedSetValue extends LazySet {
|
|
23
33
|
kind: "MixedSet";
|
|
24
34
|
elements: Value[];
|
|
25
35
|
}
|
|
@@ -46,34 +56,34 @@ export interface InfiniteSetValue {
|
|
|
46
56
|
name: "Nat" | "Int" | "STRING" | "Any";
|
|
47
57
|
}
|
|
48
58
|
|
|
49
|
-
export interface SubsetValue {
|
|
59
|
+
export interface SubsetValue extends LazySet {
|
|
50
60
|
kind: "Subset";
|
|
51
61
|
base: Value;
|
|
52
62
|
}
|
|
53
63
|
|
|
54
|
-
export interface FunctionSetValue {
|
|
64
|
+
export interface FunctionSetValue extends LazySet {
|
|
55
65
|
kind: "FunctionSet";
|
|
56
66
|
domain: Value;
|
|
57
67
|
range: Value;
|
|
58
68
|
}
|
|
59
69
|
|
|
60
|
-
export interface RecordSetValue {
|
|
70
|
+
export interface RecordSetValue extends LazySet {
|
|
61
71
|
kind: "RecordSet";
|
|
62
72
|
names: string[];
|
|
63
73
|
sets: Value[];
|
|
64
74
|
}
|
|
65
75
|
|
|
66
|
-
export interface ProductSetValue {
|
|
76
|
+
export interface ProductSetValue extends LazySet {
|
|
67
77
|
kind: "ProductSet";
|
|
68
78
|
factors: Value[];
|
|
69
79
|
}
|
|
70
80
|
|
|
71
|
-
export interface SequenceSetValue {
|
|
81
|
+
export interface SequenceSetValue extends LazySet {
|
|
72
82
|
kind: "SequenceSet";
|
|
73
83
|
base: Value;
|
|
74
84
|
}
|
|
75
85
|
|
|
76
|
-
export interface SetOperationValue {
|
|
86
|
+
export interface SetOperationValue extends LazySet {
|
|
77
87
|
kind: "SetOperation";
|
|
78
88
|
operator: "\\cup" | "\\cap" | "\\";
|
|
79
89
|
left: Value;
|
|
@@ -86,7 +96,7 @@ interface FilteredSetSource {
|
|
|
86
96
|
predicate: string;
|
|
87
97
|
}
|
|
88
98
|
|
|
89
|
-
export interface FilteredSetValue {
|
|
99
|
+
export interface FilteredSetValue extends LazySet {
|
|
90
100
|
kind: "FilteredSet";
|
|
91
101
|
base: Value;
|
|
92
102
|
test: (element: Value) => boolean;
|
|
@@ -94,7 +104,7 @@ export interface FilteredSetValue {
|
|
|
94
104
|
}
|
|
95
105
|
|
|
96
106
|
// UNION S when some element of S isn't a set enumeration. TLC enumerates it only when it has to.
|
|
97
|
-
export interface UnionValue {
|
|
107
|
+
export interface UnionValue extends LazySet {
|
|
98
108
|
kind: "Union";
|
|
99
109
|
base: Value;
|
|
100
110
|
}
|
|
@@ -109,12 +119,16 @@ export interface LazyFunctionSource {
|
|
|
109
119
|
body: string;
|
|
110
120
|
}
|
|
111
121
|
|
|
122
|
+
// enumerated is the FcnRcdValue TLC converts the function to and keeps, as FcnLambdaValue#toFcnRcd
|
|
123
|
+
// does, from the first time it compares or fingerprints the function.
|
|
112
124
|
export interface LazyFunctionValue {
|
|
113
125
|
kind: "LazyFunction";
|
|
114
126
|
domain: Value;
|
|
115
127
|
apply: (argument: Value) => Value;
|
|
116
128
|
source?: LazyFunctionSource;
|
|
117
129
|
functionClass?: FunctionClass;
|
|
130
|
+
enumerated?: FunctionValue;
|
|
131
|
+
isFingerprinted?: boolean;
|
|
118
132
|
}
|
|
119
133
|
|
|
120
134
|
export type Value =
|
|
@@ -139,6 +153,26 @@ export type Value =
|
|
|
139
153
|
|
|
140
154
|
export type ObjectValue = Exclude<Value, boolean | number | string>;
|
|
141
155
|
|
|
156
|
+
// The sets TLC builds lazily, which it converts and caches as it uses them.
|
|
157
|
+
type ConvertibleSetValue =
|
|
158
|
+
| MixedSetValue
|
|
159
|
+
| SubsetValue
|
|
160
|
+
| FunctionSetValue
|
|
161
|
+
| RecordSetValue
|
|
162
|
+
| ProductSetValue
|
|
163
|
+
| SequenceSetValue
|
|
164
|
+
| SetOperationValue
|
|
165
|
+
| FilteredSetValue
|
|
166
|
+
| UnionValue;
|
|
167
|
+
|
|
168
|
+
const isLazySet = (value: ObjectValue): value is ConvertibleSetValue =>
|
|
169
|
+
value.kind !== "ModelValue" &&
|
|
170
|
+
value.kind !== "Set" &&
|
|
171
|
+
value.kind !== "Function" &&
|
|
172
|
+
value.kind !== "Interval" &&
|
|
173
|
+
value.kind !== "InfiniteSet" &&
|
|
174
|
+
value.kind !== "LazyFunction";
|
|
175
|
+
|
|
142
176
|
export const MAXIMUM_INTEGER = 2147483647;
|
|
143
177
|
export const MINIMUM_INTEGER = -2147483648;
|
|
144
178
|
const MAXIMUM_ENUMERATED_SUBSET_BASE = 30;
|
|
@@ -310,6 +344,9 @@ export const rankString = (text: string) => {
|
|
|
310
344
|
|
|
311
345
|
export const getRankedStringCount = () => stringOrder.size;
|
|
312
346
|
|
|
347
|
+
export const getRankedString = (rank: number) =>
|
|
348
|
+
Object.keys(stringOrder.ranks).find((text) => stringOrder.ranks[text] === rank);
|
|
349
|
+
|
|
313
350
|
export const getStringRank = (text: string) => stringOrder.ranks[rankString(text)];
|
|
314
351
|
|
|
315
352
|
const compareStrings = (left: string, right: string) => {
|
|
@@ -430,6 +467,8 @@ export const createModelValue = (name: string): ModelValue => {
|
|
|
430
467
|
name,
|
|
431
468
|
type: name.length > 2 && name[1] === "_" ? name[0] : undefined,
|
|
432
469
|
rank: getStringRank(name),
|
|
470
|
+
hash: finalizeHash(combineHash(hashString(name), 0x6d)),
|
|
471
|
+
fingerprint: finalizeFingerprint(fingerprintString(name) ^ 0x3c),
|
|
433
472
|
};
|
|
434
473
|
modelValues.set(name, value);
|
|
435
474
|
return value;
|
|
@@ -480,12 +519,9 @@ export const markLambdaFunction = <FunctionLike extends FunctionValue | LazyFunc
|
|
|
480
519
|
functionValue: FunctionLike,
|
|
481
520
|
) => setFunctionClass(functionValue, "lambda");
|
|
482
521
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
// equals, size, and fingerPrint, not as their argument, and enumerates the sets an uncached one
|
|
487
|
-
// combines, duplicates and all.
|
|
488
|
-
const cachedSets = new WeakSet<ObjectValue>();
|
|
522
|
+
// TLC caches a lazy set as the receiver of compareTo, equals, size, and fingerPrint, not as their
|
|
523
|
+
// argument, and enumerates the sets an uncached one combines, duplicates and all.
|
|
524
|
+
const isCachedSet = (value: ObjectValue) => isLazySet(value) && value.isCached === true;
|
|
489
525
|
|
|
490
526
|
// Whether the spec has built a UNION or \cup set, the sets that stream duplicates, so that a spec
|
|
491
527
|
// without one skips tracking what TLC caches.
|
|
@@ -512,9 +548,10 @@ const cacheSet = (value: Value) => {
|
|
|
512
548
|
if (
|
|
513
549
|
streamedSetPresence.isPresent &&
|
|
514
550
|
typeof value === "object" &&
|
|
551
|
+
isLazySet(value) &&
|
|
515
552
|
STREAMING_KINDS.has(value.kind)
|
|
516
553
|
) {
|
|
517
|
-
|
|
554
|
+
value.isCached = true;
|
|
518
555
|
}
|
|
519
556
|
};
|
|
520
557
|
|
|
@@ -524,13 +561,11 @@ export const markFingerprinted = (value: Value): void => {
|
|
|
524
561
|
if ((!lambdaPresence.isPresent && !streamedSetPresence.isPresent) || typeof value !== "object") {
|
|
525
562
|
return;
|
|
526
563
|
}
|
|
527
|
-
if (value.kind === "
|
|
528
|
-
|
|
529
|
-
value.isFingerprinted = true;
|
|
530
|
-
} else {
|
|
531
|
-
if (fingerprintedValues.has(value)) return;
|
|
532
|
-
fingerprintedValues.add(value);
|
|
564
|
+
if (value.kind === "ModelValue" || value.kind === "Interval" || value.kind === "InfiniteSet") {
|
|
565
|
+
return;
|
|
533
566
|
}
|
|
567
|
+
if (value.isFingerprinted) return;
|
|
568
|
+
value.isFingerprinted = true;
|
|
534
569
|
if (value.kind === "Function") {
|
|
535
570
|
if (value.functionClass === "lambda") value.functionClass = undefined;
|
|
536
571
|
value.domain.forEach(markFingerprinted);
|
|
@@ -556,12 +591,6 @@ export const valuesEqual = (left: Value, right: Value): boolean => {
|
|
|
556
591
|
}
|
|
557
592
|
return compareValues(left, right) === 0;
|
|
558
593
|
}
|
|
559
|
-
const isHashed =
|
|
560
|
-
(left.kind === "Set" || left.kind === "Function") &&
|
|
561
|
-
(right.kind === "Set" || right.kind === "Function") &&
|
|
562
|
-
left.hash !== 0 &&
|
|
563
|
-
right.hash !== 0;
|
|
564
|
-
if (isHashed && left.hash !== right.hash) return false;
|
|
565
594
|
if (left.kind === "Function" && right.kind === "Function")
|
|
566
595
|
return compareFunctions(left, right) === 0;
|
|
567
596
|
if (left.kind === "Set" && right.kind === "Set") return compareSets(left, right) === 0;
|
|
@@ -1194,18 +1223,23 @@ export const createWrittenFunction = (pairs: [Value, Value][]) => {
|
|
|
1194
1223
|
);
|
|
1195
1224
|
};
|
|
1196
1225
|
|
|
1226
|
+
const MAX_SHARED_INTERVAL_LENGTH = 1024;
|
|
1197
1227
|
const intervalDomains: Value[][] = [];
|
|
1228
|
+
const longIntervalDomains = new Map<number, WeakRef<Value[]>>();
|
|
1198
1229
|
const intervalValues: IntervalValue[] = [];
|
|
1199
1230
|
const intervalArrays = new WeakMap<Value[], IntervalValue>();
|
|
1200
1231
|
|
|
1201
1232
|
// TLC keeps the domain of a tuple, or of a function built over an interval, as an interval. Every
|
|
1202
1233
|
// function over 1..n shares one domain array per length, and the elements of any other interval
|
|
1203
1234
|
// map to it, so the array's identity records it. Callers must not mutate the returned array.
|
|
1235
|
+
// Longer domains are held weakly: a sequence that grows one element at a time would otherwise keep
|
|
1236
|
+
// an array of every length it passed through, n * n / 2 numbers in all.
|
|
1204
1237
|
const getIntervalDomain = (length: number): Value[] => {
|
|
1205
|
-
const cached = intervalDomains[length];
|
|
1238
|
+
const cached = intervalDomains[length] ?? longIntervalDomains.get(length)?.deref();
|
|
1206
1239
|
if (cached) return cached;
|
|
1207
1240
|
const domain = Array.from({ length }, (_, index) => index + 1);
|
|
1208
|
-
|
|
1241
|
+
if (length > MAX_SHARED_INTERVAL_LENGTH) longIntervalDomains.set(length, new WeakRef(domain));
|
|
1242
|
+
else intervalDomains[length] = domain;
|
|
1209
1243
|
return domain;
|
|
1210
1244
|
};
|
|
1211
1245
|
|
|
@@ -1220,7 +1254,10 @@ export const getIntervalElements = (value: IntervalValue): Value[] => {
|
|
|
1220
1254
|
};
|
|
1221
1255
|
|
|
1222
1256
|
const isIntervalDomain = (domain: Value[]) =>
|
|
1223
|
-
domain.length > 0 &&
|
|
1257
|
+
domain.length > 0 &&
|
|
1258
|
+
(domain === intervalDomains[domain.length] ||
|
|
1259
|
+
domain === longIntervalDomains.get(domain.length)?.deref() ||
|
|
1260
|
+
intervalArrays.has(domain));
|
|
1224
1261
|
|
|
1225
1262
|
// TLC keeps an interval domain only for a function built over an interval itself, so a set
|
|
1226
1263
|
// such as (1..2) \cap S, whose elements are the shared array, gets a copy.
|
|
@@ -1546,8 +1583,14 @@ const enumerateSet = (
|
|
|
1546
1583
|
`Attempted to enumerate S \\ T when S:\n${formatValue(value.left)}\nis not enumerable.`,
|
|
1547
1584
|
);
|
|
1548
1585
|
}
|
|
1549
|
-
if (value.operator === "\\cup")
|
|
1550
|
-
return
|
|
1586
|
+
if (value.operator === "\\cup") {
|
|
1587
|
+
return computeLikeTlcOnFailure(
|
|
1588
|
+
(union) => getSortedUnion(toFiniteSet(union.left), toFiniteSet(union.right)).elements,
|
|
1589
|
+
(union) => sortLikeTlc(listUnionLikeTlc(union)),
|
|
1590
|
+
value,
|
|
1591
|
+
value,
|
|
1592
|
+
);
|
|
1593
|
+
}
|
|
1551
1594
|
const isLeftEnumerated = value.operator === "\\" || isTlcEnumerable(value.left);
|
|
1552
1595
|
const enumerated = isLeftEnumerated ? value.left : value.right;
|
|
1553
1596
|
const other = isLeftEnumerated ? value.right : value.left;
|
|
@@ -1565,15 +1608,13 @@ const enumerateSet = (
|
|
|
1565
1608
|
}
|
|
1566
1609
|
};
|
|
1567
1610
|
|
|
1568
|
-
const finiteSets = new WeakMap<ObjectValue, SetValue>();
|
|
1569
|
-
|
|
1570
1611
|
export const toFiniteSet = (value: Value): SetValue => {
|
|
1571
1612
|
if (typeof value === "object" && value.kind === "Set") return value;
|
|
1572
1613
|
if (typeof value === "object" && value.kind === "Interval") {
|
|
1573
1614
|
return createSortedSet(enumerateSet(value));
|
|
1574
1615
|
}
|
|
1575
|
-
const
|
|
1576
|
-
if (
|
|
1616
|
+
const lazy = typeof value === "object" && isLazySet(value) ? value : undefined;
|
|
1617
|
+
if (lazy?.enumerated) return lazy.enumerated;
|
|
1577
1618
|
const sets = setTrace.sets;
|
|
1578
1619
|
sets?.push(value);
|
|
1579
1620
|
const elements = enumerateSet(value);
|
|
@@ -1588,14 +1629,32 @@ export const toFiniteSet = (value: Value): SetValue => {
|
|
|
1588
1629
|
value.kind === "FunctionSet" ||
|
|
1589
1630
|
value.kind === "Subset");
|
|
1590
1631
|
const set = isSorted ? createSortedSet(elements) : createSet(elements);
|
|
1591
|
-
if (
|
|
1632
|
+
if (lazy) lazy.enumerated = set;
|
|
1592
1633
|
return set;
|
|
1593
1634
|
};
|
|
1594
1635
|
|
|
1636
|
+
// SetCupValue#toSetEnum.
|
|
1637
|
+
const listUnionLikeTlc = (union: SetOperationValue) => [
|
|
1638
|
+
...toFiniteSet(union.left).elements,
|
|
1639
|
+
...toFiniteSet(union.right).elements,
|
|
1640
|
+
];
|
|
1641
|
+
|
|
1642
|
+
// EnumerableValue#elements(NORMALIZED) sorts a union outside its methods, so a failed comparison
|
|
1643
|
+
// isn't a fingerprint failure.
|
|
1644
|
+
export const getNormalizedSetElements = (value: Value) =>
|
|
1645
|
+
typeof value === "object" && value.kind === "SetOperation" && value.operator === "\\cup"
|
|
1646
|
+
? computeLikeTlcOnFailure(
|
|
1647
|
+
(union) => toFiniteSet(union).elements,
|
|
1648
|
+
(union) => sortLikeTlc(callTracedMethod(union, () => listUnionLikeTlc(union))),
|
|
1649
|
+
value,
|
|
1650
|
+
value,
|
|
1651
|
+
)
|
|
1652
|
+
: toFiniteSet(value).elements;
|
|
1653
|
+
|
|
1595
1654
|
// TLC's Enumerator for a lazy set streams the sets it combines until the set caches its elements,
|
|
1596
1655
|
// so an element that two of them share comes up once for each.
|
|
1597
1656
|
export const getStreamedElements = (value: Value): Value[] => {
|
|
1598
|
-
if (typeof value !== "object" ||
|
|
1657
|
+
if (typeof value !== "object" || isCachedSet(value)) return toFiniteSet(value).elements;
|
|
1599
1658
|
const sets = setTrace.sets;
|
|
1600
1659
|
sets?.push(value);
|
|
1601
1660
|
const elements = streamElements(value);
|
|
@@ -1647,7 +1706,7 @@ export const isSettledValue = (value: Value): boolean => {
|
|
|
1647
1706
|
// Whether a set streams its elements in another order than the normalized set, so that a set of
|
|
1648
1707
|
// tuples, records, or functions it is a component of has to stream too.
|
|
1649
1708
|
const isStreamedApart = (value: Value): boolean => {
|
|
1650
|
-
if (typeof value !== "object" ||
|
|
1709
|
+
if (typeof value !== "object" || isCachedSet(value)) return false;
|
|
1651
1710
|
if (value.kind === "Union") return true;
|
|
1652
1711
|
if (value.kind === "FilteredSet") return isStreamedApart(value.base);
|
|
1653
1712
|
if (value.kind === "SetOperation") {
|
|
@@ -2102,15 +2161,17 @@ export const isUpdatedElementOf = (element: Value, member: Value, set: Value): b
|
|
|
2102
2161
|
export const toFiniteFunction = (value: Value): FunctionValue => {
|
|
2103
2162
|
if (typeof value === "object" && value.kind === "Function") return value;
|
|
2104
2163
|
if (typeof value === "object" && value.kind === "LazyFunction") {
|
|
2164
|
+
if (value.enumerated) return value.enumerated;
|
|
2105
2165
|
if (!isEnumerable(value.domain)) getCardinality(value.domain);
|
|
2106
2166
|
const domain = getFunctionDomain(value.domain);
|
|
2107
|
-
|
|
2167
|
+
value.enumerated = setFunctionClass(
|
|
2108
2168
|
createSortedFunction(
|
|
2109
2169
|
domain,
|
|
2110
2170
|
domain.map((key) => value.apply(key)),
|
|
2111
2171
|
),
|
|
2112
2172
|
getFunctionClass(value),
|
|
2113
2173
|
);
|
|
2174
|
+
return value.enumerated;
|
|
2114
2175
|
}
|
|
2115
2176
|
throw new TlaEvaluationError(`Expected a function but found ${formatValue(value)}`);
|
|
2116
2177
|
};
|
|
@@ -2315,8 +2376,6 @@ export const updateFunction = (
|
|
|
2315
2376
|
return updated;
|
|
2316
2377
|
};
|
|
2317
2378
|
|
|
2318
|
-
const valueHashes = new WeakMap<ObjectValue, number>();
|
|
2319
|
-
|
|
2320
2379
|
const HASH_SEED = 0x811c9dc5;
|
|
2321
2380
|
|
|
2322
2381
|
const finalizeHash = (hash: number) => {
|
|
@@ -2348,11 +2407,9 @@ const getEntryContribution = (keyHash: number, valueHash: number) =>
|
|
|
2348
2407
|
// when TLC fingerprints it.
|
|
2349
2408
|
const UNFINGERPRINTABLE_HASH = 0x2f6b1c4d;
|
|
2350
2409
|
|
|
2351
|
-
const computeValueHash = (value:
|
|
2352
|
-
if (value.kind === "
|
|
2353
|
-
|
|
2354
|
-
if (!isEnumerable(value)) return UNFINGERPRINTABLE_HASH;
|
|
2355
|
-
const elements = toFiniteSet(value).elements;
|
|
2410
|
+
const computeValueHash = (value: SetValue | FunctionValue) => {
|
|
2411
|
+
if (value.kind === "Set") {
|
|
2412
|
+
const elements = value.elements;
|
|
2356
2413
|
let hash = SET_HASH_SEED;
|
|
2357
2414
|
for (let index = 0; index < elements.length; index++) {
|
|
2358
2415
|
const elementHash = getValueHash(elements[index]);
|
|
@@ -2361,12 +2418,10 @@ const computeValueHash = (value: ObjectValue) => {
|
|
|
2361
2418
|
}
|
|
2362
2419
|
return hash;
|
|
2363
2420
|
}
|
|
2364
|
-
if (value.kind === "LazyFunction" && !isEnumerable(value.domain)) return UNFINGERPRINTABLE_HASH;
|
|
2365
|
-
const functionValue = toFiniteFunction(value);
|
|
2366
2421
|
let hash = FUNCTION_HASH_SEED;
|
|
2367
|
-
for (let index = 0; index <
|
|
2368
|
-
const keyHash = getValueHash(
|
|
2369
|
-
const itemHash = getValueHash(
|
|
2422
|
+
for (let index = 0; index < value.domain.length; index++) {
|
|
2423
|
+
const keyHash = getValueHash(value.domain[index]);
|
|
2424
|
+
const itemHash = getValueHash(value.range[index]);
|
|
2370
2425
|
if (keyHash === UNFINGERPRINTABLE_HASH || itemHash === UNFINGERPRINTABLE_HASH) {
|
|
2371
2426
|
return UNFINGERPRINTABLE_HASH;
|
|
2372
2427
|
}
|
|
@@ -2442,15 +2497,15 @@ export const getValueHash = (value: Value): number => {
|
|
|
2442
2497
|
if (value.hash === 0) value.hash = computeValueHash(value);
|
|
2443
2498
|
return value.hash;
|
|
2444
2499
|
}
|
|
2445
|
-
|
|
2446
|
-
if (
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2500
|
+
if (value.kind === "ModelValue") return value.hash;
|
|
2501
|
+
if (value.kind === "LazyFunction") {
|
|
2502
|
+
return isEnumerable(value.domain)
|
|
2503
|
+
? getValueHash(toFiniteFunction(value))
|
|
2504
|
+
: UNFINGERPRINTABLE_HASH;
|
|
2505
|
+
}
|
|
2506
|
+
return isEnumerable(value) ? getValueHash(toFiniteSet(value)) : UNFINGERPRINTABLE_HASH;
|
|
2450
2507
|
};
|
|
2451
2508
|
|
|
2452
|
-
const valueFingerprints = new WeakMap<ObjectValue, number>();
|
|
2453
|
-
|
|
2454
2509
|
const finalizeFingerprint = (hash: number) => {
|
|
2455
2510
|
const first = Math.imul(hash ^ (hash >>> 15), 0x2c1b3c6d);
|
|
2456
2511
|
const second = Math.imul(first ^ (first >>> 12), 0x297a2d39);
|
|
@@ -2472,23 +2527,18 @@ const getEntryFingerprint = (key: Value, value: Value) =>
|
|
|
2472
2527
|
(Math.imul(getValueFingerprint(key), 0x165667b1) + getValueFingerprint(value)) | 0,
|
|
2473
2528
|
);
|
|
2474
2529
|
|
|
2475
|
-
const computeValueFingerprint = (value:
|
|
2476
|
-
if (value.kind === "
|
|
2477
|
-
|
|
2478
|
-
if (!isEnumerable(value)) return fingerprintString(getValueKey(value));
|
|
2479
|
-
const elements = toFiniteSet(value).elements;
|
|
2530
|
+
const computeValueFingerprint = (value: SetValue | FunctionValue) => {
|
|
2531
|
+
if (value.kind === "Set") {
|
|
2532
|
+
const elements = value.elements;
|
|
2480
2533
|
let fingerprint = 0x1b873593;
|
|
2481
2534
|
for (let index = 0; index < elements.length; index++) {
|
|
2482
2535
|
fingerprint = (fingerprint + getElementFingerprint(elements[index])) | 0;
|
|
2483
2536
|
}
|
|
2484
2537
|
return fingerprint;
|
|
2485
2538
|
}
|
|
2486
|
-
const functionValue = toFiniteFunction(value);
|
|
2487
2539
|
let fingerprint = 0x4cf5ad43;
|
|
2488
|
-
for (let index = 0; index <
|
|
2489
|
-
fingerprint =
|
|
2490
|
-
(fingerprint + getEntryFingerprint(functionValue.domain[index], functionValue.range[index])) |
|
|
2491
|
-
0;
|
|
2540
|
+
for (let index = 0; index < value.domain.length; index++) {
|
|
2541
|
+
fingerprint = (fingerprint + getEntryFingerprint(value.domain[index], value.range[index])) | 0;
|
|
2492
2542
|
}
|
|
2493
2543
|
return fingerprint;
|
|
2494
2544
|
};
|
|
@@ -2501,24 +2551,18 @@ export const getValueFingerprint = (value: Value): number => {
|
|
|
2501
2551
|
if (value.fingerprint === 0) value.fingerprint = computeValueFingerprint(value);
|
|
2502
2552
|
return value.fingerprint;
|
|
2503
2553
|
}
|
|
2504
|
-
|
|
2505
|
-
if (
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2554
|
+
if (value.kind === "ModelValue") return value.fingerprint;
|
|
2555
|
+
if (value.kind === "LazyFunction") return getValueFingerprint(toFiniteFunction(value));
|
|
2556
|
+
return isEnumerable(value)
|
|
2557
|
+
? getValueFingerprint(toFiniteSet(value))
|
|
2558
|
+
: fingerprintString(getValueKey(value));
|
|
2509
2559
|
};
|
|
2510
2560
|
|
|
2511
|
-
const valueKeys = new WeakMap<ObjectValue, string>();
|
|
2512
|
-
|
|
2513
2561
|
export const getValueKey = (value: Value): string => {
|
|
2514
2562
|
if (typeof value === "boolean") return value ? "T" : "F";
|
|
2515
2563
|
if (typeof value === "number") return String(value);
|
|
2516
2564
|
if (typeof value === "string") return JSON.stringify(value);
|
|
2517
|
-
|
|
2518
|
-
if (cached !== undefined) return cached;
|
|
2519
|
-
const key = computeValueKey(value);
|
|
2520
|
-
valueKeys.set(value, key);
|
|
2521
|
-
return key;
|
|
2565
|
+
return computeValueKey(value);
|
|
2522
2566
|
};
|
|
2523
2567
|
|
|
2524
2568
|
const computeValueKey = (value: ObjectValue) => {
|