tla-ts 0.0.3-dev.6979965 → 0.0.3-dev.6f3cbdb
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 +16 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +2 -2
- package/dist/parallel-worker.js +2 -2
- package/dist/parallel.cjs +1 -1
- package/dist/parallel.js +2 -2
- package/dist/run-cli.cjs +17 -16
- package/dist/run-cli.js +6 -5
- package/dist/transfer.cjs +27 -15
- package/dist/transfer.js +27 -15
- package/package.json +1 -1
- package/src/ast.ts +90 -0
- package/src/check.ts +233 -68
- package/src/cli-options.ts +11 -5
- package/src/codegen.ts +9 -19
- package/src/dependencies.ts +2 -2
- package/src/environment.ts +75 -16
- package/src/errors.ts +9 -2
- package/src/evaluate.ts +85 -142
- package/src/exit-codes.ts +21 -43
- package/src/instances.ts +15 -14
- package/src/levels.ts +8 -8
- package/src/lexer.ts +5 -1
- package/src/live-check.ts +711 -0
- package/src/liveness.ts +54 -535
- package/src/parallel-worker.ts +100 -113
- package/src/parallel.ts +32 -21
- package/src/parser.ts +12 -1
- package/src/resolve.ts +16 -15
- package/src/run-cli.ts +58 -13
- package/src/runtime.ts +3 -1
- package/src/spec-description.ts +18 -6
- package/src/standard-modules.ts +2 -7
- package/src/state-graph.ts +157 -0
- package/src/subexpressions.ts +10 -10
- package/src/successors.ts +77 -13
- package/src/symmetry.ts +14 -2
- package/src/tlc-ext.ts +29 -12
- package/src/tlc-module.ts +9 -28
- package/src/tlc-order.ts +17 -3
- package/src/values.ts +40 -11
package/src/values.ts
CHANGED
|
@@ -5,6 +5,7 @@ export interface ModelValue {
|
|
|
5
5
|
kind: "ModelValue";
|
|
6
6
|
name: string;
|
|
7
7
|
type: string | undefined;
|
|
8
|
+
rank: number;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
export interface SetValue {
|
|
@@ -136,6 +137,13 @@ export const isSetValue = (value: Value) =>
|
|
|
136
137
|
value.kind !== "Function" &&
|
|
137
138
|
value.kind !== "LazyFunction";
|
|
138
139
|
|
|
140
|
+
export type ReducibleSet = SetValue | MixedSetValue | IntervalValue;
|
|
141
|
+
|
|
142
|
+
// TLC reduces a set enumeration or an interval eagerly, and keeps every other set lazy.
|
|
143
|
+
export const isReducible = (value: Value): value is ReducibleSet =>
|
|
144
|
+
typeof value === "object" &&
|
|
145
|
+
(value.kind === "Set" || value.kind === "MixedSet" || value.kind === "Interval");
|
|
146
|
+
|
|
139
147
|
export const isFunctionValue = (value: Value): value is FunctionValue | LazyFunctionValue =>
|
|
140
148
|
typeof value === "object" && (value.kind === "Function" || value.kind === "LazyFunction");
|
|
141
149
|
|
|
@@ -264,6 +272,7 @@ const stringOrder = { ranks: Object.create(null) as Record<string, number>, size
|
|
|
264
272
|
export const setStringOrder = (texts: Iterable<string>) => {
|
|
265
273
|
stringOrder.ranks = Object.create(null);
|
|
266
274
|
stringOrder.size = 0;
|
|
275
|
+
modelValues.clear();
|
|
267
276
|
for (const text of texts) rankString(text);
|
|
268
277
|
};
|
|
269
278
|
|
|
@@ -353,7 +362,7 @@ export const compareValues = (left: Value, right: Value): number => {
|
|
|
353
362
|
if (left.type !== undefined && right.type !== undefined) {
|
|
354
363
|
checkModelValueTypes(left, right, false);
|
|
355
364
|
}
|
|
356
|
-
return
|
|
365
|
+
return left.rank - right.rank;
|
|
357
366
|
}
|
|
358
367
|
if (leftKind === "ModelValue" || rightKind === "ModelValue") {
|
|
359
368
|
checkModelValueTypes(left, right, false);
|
|
@@ -385,14 +394,15 @@ export const compareValues = (left: Value, right: Value): number => {
|
|
|
385
394
|
|
|
386
395
|
const modelValues = new Map<string, ModelValue>();
|
|
387
396
|
|
|
397
|
+
// A check ranks every model value's name when it creates the value, and creates its own values.
|
|
388
398
|
export const createModelValue = (name: string): ModelValue => {
|
|
389
|
-
rankString(name);
|
|
390
399
|
const known = modelValues.get(name);
|
|
391
400
|
if (known) return known;
|
|
392
401
|
const value: ModelValue = {
|
|
393
402
|
kind: "ModelValue",
|
|
394
403
|
name,
|
|
395
404
|
type: name.length > 2 && name[1] === "_" ? name[0] : undefined,
|
|
405
|
+
rank: getStringRank(name),
|
|
396
406
|
};
|
|
397
407
|
modelValues.set(name, value);
|
|
398
408
|
return value;
|
|
@@ -562,7 +572,7 @@ const equalsModelValueWith = (modelValue: ModelValue, other: Value) => {
|
|
|
562
572
|
|
|
563
573
|
const compareModelValue = (left: ModelValue, right: Value) => {
|
|
564
574
|
const type = getModelValueType(left);
|
|
565
|
-
if (type === undefined) return isModelValue(right) ?
|
|
575
|
+
if (type === undefined) return isModelValue(right) ? left.rank - right.rank : -1;
|
|
566
576
|
if (!isModelValue(right)) {
|
|
567
577
|
throw new TlaEvaluationError(
|
|
568
578
|
`Attempted to compare the typed model value ${formatValue(left)} and non-model value\n${formatValue(right)}`,
|
|
@@ -574,7 +584,7 @@ const compareModelValue = (left: ModelValue, right: Value) => {
|
|
|
574
584
|
`Attempted to compare the differently-typed model values ${formatValue(left)} and ${formatValue(right)}`,
|
|
575
585
|
);
|
|
576
586
|
}
|
|
577
|
-
return
|
|
587
|
+
return left.rank - right.rank;
|
|
578
588
|
};
|
|
579
589
|
|
|
580
590
|
const equalsModelValue = (left: ModelValue, right: Value) => {
|
|
@@ -1066,13 +1076,16 @@ const isTlcEnumerable = (value: Value) => isSetValue(value) && !isOverriddenSet(
|
|
|
1066
1076
|
const formatUnion = (value: UnionValue, isStrict = false) =>
|
|
1067
1077
|
`UNION(${formatValue(value.base, isStrict)})`;
|
|
1068
1078
|
|
|
1069
|
-
const getUnionSets = (
|
|
1079
|
+
const getUnionSets = (
|
|
1080
|
+
value: UnionValue,
|
|
1081
|
+
getElements = (set: Value) => toFiniteSet(set).elements,
|
|
1082
|
+
) => {
|
|
1070
1083
|
if (!isTlcEnumerable(value.base)) {
|
|
1071
1084
|
throw new TlaEvaluationError(
|
|
1072
1085
|
`Attempted to enumerate the nonenumerable set:\n${formatUnion(value)}`,
|
|
1073
1086
|
);
|
|
1074
1087
|
}
|
|
1075
|
-
return
|
|
1088
|
+
return getElements(value.base);
|
|
1076
1089
|
};
|
|
1077
1090
|
|
|
1078
1091
|
const getUnionSet = (set: Value, index: number, union: UnionValue) => {
|
|
@@ -1108,7 +1121,7 @@ export const isEnumerable = (value: Value): boolean => {
|
|
|
1108
1121
|
case "ProductSet":
|
|
1109
1122
|
return value.factors.every(isEnumerable) || getEmptiness(value) === true;
|
|
1110
1123
|
case "Union":
|
|
1111
|
-
return isEnumerable(value.base) &&
|
|
1124
|
+
return isEnumerable(value.base) && getStreamedElements(value.base).every(isEnumerable);
|
|
1112
1125
|
case "SetOperation":
|
|
1113
1126
|
if (value.operator === "\\cup") return isEnumerable(value.left) && isEnumerable(value.right);
|
|
1114
1127
|
if (value.operator === "\\cap") return isEnumerable(value.left) || isEnumerable(value.right);
|
|
@@ -1342,8 +1355,10 @@ export const toFiniteSet = (value: Value): SetValue => {
|
|
|
1342
1355
|
// so an element that two of them share comes up once for each.
|
|
1343
1356
|
export const getStreamedElements = (value: Value): Value[] => {
|
|
1344
1357
|
if (typeof value !== "object" || finiteSets.has(value)) return toFiniteSet(value).elements;
|
|
1358
|
+
// TLC streams the sets of a UNION it hasn't enumerated, so a set that appears twice there yields
|
|
1359
|
+
// its elements twice.
|
|
1345
1360
|
if (value.kind === "Union") {
|
|
1346
|
-
return getUnionSets(value).flatMap((set, index) =>
|
|
1361
|
+
return getUnionSets(value, getStreamedElements).flatMap((set, index) =>
|
|
1347
1362
|
getStreamedElements(getUnionSet(set, index, value)),
|
|
1348
1363
|
);
|
|
1349
1364
|
}
|
|
@@ -2098,8 +2113,11 @@ export const formatValue = (value: Value, isStrict = false, isNormalized = false
|
|
|
2098
2113
|
return `[${parameters} |-> <expression ${source.body}>]`;
|
|
2099
2114
|
}
|
|
2100
2115
|
const functionValue = toFiniteFunction(value);
|
|
2116
|
+
// TLC normalizes a lambda's domain to print it, but evaluates its body afterward.
|
|
2117
|
+
const formatRange = (inner: Value) =>
|
|
2118
|
+
formatValue(inner, isStrict, isNormalized && value.kind === "Function");
|
|
2101
2119
|
if (functionValue.domain.every((key, index) => key === index + 1)) {
|
|
2102
|
-
return `<<${functionValue.range.map(
|
|
2120
|
+
return `<<${functionValue.range.map(formatRange).join(", ")}>>`;
|
|
2103
2121
|
}
|
|
2104
2122
|
if (functionValue.domain.every((key) => typeof key === "string" && isFieldName(key))) {
|
|
2105
2123
|
const isSorted =
|
|
@@ -2107,9 +2125,20 @@ export const formatValue = (value: Value, isStrict = false, isNormalized = false
|
|
|
2107
2125
|
const pairs = isSorted
|
|
2108
2126
|
? functionValue.domain.map((key, index) => [key, functionValue.range[index]])
|
|
2109
2127
|
: getWrittenPairs(functionValue);
|
|
2110
|
-
return `[${pairs.map((pair) => `${String(pair[0])} |-> ${
|
|
2128
|
+
return `[${pairs.map((pair) => `${String(pair[0])} |-> ${formatRange(pair[1])}`).join(", ")}]`;
|
|
2111
2129
|
}
|
|
2112
|
-
return `(${functionValue.domain.map((key, index) => `${format(key)} :> ${
|
|
2130
|
+
return `(${functionValue.domain.map((key, index) => `${format(key)} :> ${formatRange(functionValue.range[index])}`).join(" @@ ")})`;
|
|
2113
2131
|
}
|
|
2114
2132
|
}
|
|
2115
2133
|
};
|
|
2134
|
+
|
|
2135
|
+
// TLC's TLCState.toString: a line per variable, as a conjunction when there are several.
|
|
2136
|
+
export const formatState = (state: Record<string, Value>) => {
|
|
2137
|
+
const entries = Object.entries(state);
|
|
2138
|
+
return entries
|
|
2139
|
+
.map(
|
|
2140
|
+
([name, value]) =>
|
|
2141
|
+
`${entries.length === 1 ? "" : "/\\ "}${name} = ${prettyPrint(formatValue(value))}\n`,
|
|
2142
|
+
)
|
|
2143
|
+
.join("");
|
|
2144
|
+
};
|