tla-ts 0.0.3-dev.e5b05b9 → 0.0.3-dev.e8bef80
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/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +150 -48
- package/dist/index.d.ts +150 -48
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +2 -2
- package/dist/parallel.cjs +1 -1
- package/dist/parallel.js +2 -2
- package/dist/run-cli.cjs +1351 -22
- package/dist/run-cli.js +1352 -23
- package/dist/transfer.cjs +83 -43
- package/dist/transfer.js +83 -43
- package/package.json +5 -1
- package/src/ast.ts +28 -4
- package/src/bags.ts +4 -7
- package/src/builtins.ts +29 -17
- package/src/bundled-modules.ts +3 -3
- package/src/canonical.ts +4 -3
- package/src/check.ts +1317 -428
- package/src/cli.ts +8 -1
- package/src/codegen.ts +68 -21
- package/src/config.ts +226 -207
- package/src/environment.ts +221 -75
- package/src/errors.ts +130 -15
- package/src/evaluate.ts +713 -259
- package/src/exit-codes.ts +6 -24
- package/src/fingerprints.ts +1 -2
- package/src/index.ts +1 -0
- package/src/instances.ts +3 -1
- package/src/java-overrides.ts +104 -25
- package/src/levels.ts +6 -1
- package/src/lexer.ts +122 -29
- package/src/live-check.ts +204 -148
- package/src/liveness.ts +191 -122
- package/src/obligation-expression.ts +2 -2
- package/src/obligation-source.ts +2 -0
- package/src/parallel-worker.ts +6 -1
- package/src/parallel.ts +57 -6
- package/src/parser.ts +327 -147
- package/src/pcal-ast.ts +770 -0
- package/src/pcal-parse.ts +1523 -0
- package/src/pcal-tokenize.ts +516 -0
- package/src/pcal-translate.ts +1230 -0
- package/src/pcal-validate.ts +454 -0
- package/src/randomization.ts +24 -7
- package/src/resolve.ts +252 -87
- package/src/run-cli.ts +1162 -200
- package/src/runtime.ts +16 -0
- package/src/sany-builtins.ts +147 -0
- package/src/sany-generator.ts +3128 -0
- package/src/sany-levels.ts +1208 -0
- package/src/sany-lexer.ts +410 -480
- package/src/sany-linter.ts +122 -0
- package/src/sany-modules.ts +1398 -0
- package/src/sany-nodes.ts +463 -0
- package/src/sany-parse-error.ts +2033 -3015
- package/src/sany-report.ts +356 -0
- package/src/sany-selectors.ts +738 -0
- package/src/sany-source.ts +248 -0
- package/src/sany-xml.ts +1017 -0
- package/src/spec-description.ts +25 -5
- package/src/standard-modules.ts +172 -129
- package/src/state-graph.ts +29 -6
- package/src/subexpressions.ts +121 -26
- package/src/successors.ts +141 -173
- package/src/symmetry.ts +168 -50
- package/src/tableau.ts +3 -1
- package/src/tlc-ext.ts +13 -17
- package/src/tlc-messages.ts +329 -0
- package/src/tlc-module.ts +49 -21
- package/src/tlc-modules.ts +0 -4
- package/src/tlc-order.ts +55 -9
- package/src/tlc-random.ts +28 -3
- package/src/tlc-replay.ts +655 -0
- package/src/tlc-version.ts +18 -0
- package/src/transfer.ts +15 -3
- package/src/values.ts +664 -317
package/src/spec-description.ts
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
import { TEMPORAL_LEVEL } from "./levels";
|
|
25
25
|
import { getLevel } from "./liveness";
|
|
26
26
|
import { createRecord, createSet, createTuple, formatValue, type Value } from "./values";
|
|
27
|
+
import type { TlcVersion } from "./tlc-version";
|
|
27
28
|
|
|
28
29
|
export interface SpecAction {
|
|
29
30
|
name: string;
|
|
@@ -62,7 +63,8 @@ const toLocationValue = (location: SourceLocation) => {
|
|
|
62
63
|
]);
|
|
63
64
|
};
|
|
64
65
|
|
|
65
|
-
|
|
66
|
+
// TLC's RecordValue(Action): the action's name and location, with the values of its parameters.
|
|
67
|
+
export const toActionValue = (action: SpecAction) => {
|
|
66
68
|
const fields: [string, Value][] = [
|
|
67
69
|
["name", action.name],
|
|
68
70
|
["location", toLocationValue(action.location)],
|
|
@@ -249,8 +251,12 @@ const getActions = (
|
|
|
249
251
|
return getInstanceActions(instanceAction, expression, scope, called, environment);
|
|
250
252
|
if (!called) return [createSplitAction()];
|
|
251
253
|
const args = getArguments(expression);
|
|
254
|
+
// TLC names an action after the operator it applies, as SANY names it in the spec.
|
|
255
|
+
const calledName = isLocallyResolved(expression)
|
|
256
|
+
? called.name
|
|
257
|
+
: (environment.instanceNames.get(getOperatorName(expression) ?? "") ?? called.name);
|
|
252
258
|
const callAction = (): SpecAction[] => [
|
|
253
|
-
{ name:
|
|
259
|
+
{ name: calledName, location: expression.location, parameters: [], expression, scope },
|
|
254
260
|
];
|
|
255
261
|
if (isConstantDefinition(called, environment)) return callAction();
|
|
256
262
|
if (args.some((arg) => getLevel(arg, scope, environment) !== 0)) return callAction();
|
|
@@ -266,7 +272,13 @@ const getActions = (
|
|
|
266
272
|
}),
|
|
267
273
|
called.scope,
|
|
268
274
|
);
|
|
269
|
-
return getActions(
|
|
275
|
+
return getActions(
|
|
276
|
+
called.body,
|
|
277
|
+
boundScope,
|
|
278
|
+
{ ...called, name: calledName },
|
|
279
|
+
environment,
|
|
280
|
+
instanceActions,
|
|
281
|
+
);
|
|
270
282
|
}, callAction);
|
|
271
283
|
};
|
|
272
284
|
|
|
@@ -461,6 +473,13 @@ const describe = (
|
|
|
461
473
|
return description;
|
|
462
474
|
};
|
|
463
475
|
|
|
476
|
+
// TLC's initial predicates, which it conjoins to compute the initial states.
|
|
477
|
+
export const getInitActions = (
|
|
478
|
+
config: ModelConfig,
|
|
479
|
+
environment: Environment,
|
|
480
|
+
instanceActions: Map<string, InstanceAction>,
|
|
481
|
+
) => describe(config, environment, instanceActions).inits;
|
|
482
|
+
|
|
464
483
|
// TLC's split of the next-state relation into the actions it names in a behavior.
|
|
465
484
|
export const getNextActions = (
|
|
466
485
|
config: ModelConfig,
|
|
@@ -473,8 +492,9 @@ const formatParameters = (action: SpecAction) =>
|
|
|
473
492
|
? ""
|
|
474
493
|
: `(${action.parameters.map((parameter) => formatValue(parameter[1])).join(",")})`;
|
|
475
494
|
|
|
476
|
-
|
|
477
|
-
|
|
495
|
+
// TLC's Action.getLocation, which TLC 1.7.4 names the action in without its parameters.
|
|
496
|
+
export const getActionLabel = (action: SpecAction, version?: TlcVersion) =>
|
|
497
|
+
`${action.name === UNNAMED_ACTION ? "Action" : action.name}${version === "1.7.4" ? "" : formatParameters(action)} ${formatRange(action.location.range ?? BUILTIN_RANGE)}`;
|
|
478
498
|
|
|
479
499
|
// TLC's Action.getInvocationSignature, which names the action and the values of its parameters.
|
|
480
500
|
export const getActionSignature = (action: SpecAction) =>
|
package/src/standard-modules.ts
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
getNumber,
|
|
12
12
|
getOperator,
|
|
13
13
|
getSet,
|
|
14
|
-
|
|
14
|
+
getJavaSignature,
|
|
15
15
|
getJavaInteger,
|
|
16
16
|
getValue,
|
|
17
17
|
isOutOfRange,
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
} from "./builtins";
|
|
20
20
|
import type { Builtin, BuiltinArgument } from "./evaluate";
|
|
21
21
|
import type { CheckerRuntime } from "./runtime";
|
|
22
|
-
import {
|
|
22
|
+
import { createBagsOperators } from "./bags";
|
|
23
23
|
import { createJsonOperators, type FileSystem } from "./json";
|
|
24
24
|
import { createRandomizationOperators } from "./randomization";
|
|
25
25
|
import { createPossibleOperators, createTlcExtOperators } from "./tlc-ext";
|
|
@@ -40,7 +40,9 @@ import {
|
|
|
40
40
|
isEnumerable,
|
|
41
41
|
isFiniteSet,
|
|
42
42
|
isFunctionValue,
|
|
43
|
-
|
|
43
|
+
computeLikeTlcOnFailure,
|
|
44
|
+
isReducibleSet,
|
|
45
|
+
markStreamedSet,
|
|
44
46
|
isSetValue,
|
|
45
47
|
toFiniteSet,
|
|
46
48
|
unionSorted,
|
|
@@ -48,13 +50,14 @@ import {
|
|
|
48
50
|
createEnumeratedSet,
|
|
49
51
|
EMPTY_SET,
|
|
50
52
|
isEnumeratedSet,
|
|
51
|
-
type
|
|
53
|
+
type IntervalValue,
|
|
52
54
|
type MixedSetValue,
|
|
53
55
|
type SetOperationValue,
|
|
54
56
|
type SetValue,
|
|
55
57
|
type Value,
|
|
56
58
|
rankString,
|
|
57
59
|
} from "./values";
|
|
60
|
+
import type { TlcVersion } from "./tlc-version";
|
|
58
61
|
|
|
59
62
|
interface StandardModule {
|
|
60
63
|
extends: string[];
|
|
@@ -76,6 +79,8 @@ const unionInTree = (sets: SetValue[], start: number, end: number): SetValue =>
|
|
|
76
79
|
|
|
77
80
|
const SET_OPERATORS: SetOperationValue["operator"][] = ["\\cup", "\\cap", "\\"];
|
|
78
81
|
|
|
82
|
+
type ReducibleSet = SetValue | MixedSetValue | IntervalValue;
|
|
83
|
+
|
|
79
84
|
const isMixedSet = (value: Value) => typeof value === "object" && value.kind === "MixedSet";
|
|
80
85
|
|
|
81
86
|
const getReducibleElements = (set: ReducibleSet) =>
|
|
@@ -96,7 +101,9 @@ const combineReducible = (
|
|
|
96
101
|
);
|
|
97
102
|
}
|
|
98
103
|
if (elements.length === 0) return other;
|
|
99
|
-
if (!
|
|
104
|
+
if (!isReducibleSet(other)) {
|
|
105
|
+
return markStreamedSet({ kind: "SetOperation", operator, left: set, right: other });
|
|
106
|
+
}
|
|
100
107
|
const added = toFiniteSet(other).elements.filter((element) => !isElementOf(element, set));
|
|
101
108
|
return createEnumeratedSet([...elements, ...added]);
|
|
102
109
|
};
|
|
@@ -123,6 +130,7 @@ export const CORE_OPERATORS: Builtin[] = [
|
|
|
123
130
|
),
|
|
124
131
|
defineOperator("\\subseteq", 2, (args) => {
|
|
125
132
|
const left = getSet(args, 0, "\\subseteq");
|
|
133
|
+
// TLC tests each element of the left set for membership in the right value.
|
|
126
134
|
const right = getValue(args, 1, "\\subseteq");
|
|
127
135
|
const isPowerSets =
|
|
128
136
|
typeof left === "object" &&
|
|
@@ -133,11 +141,18 @@ export const CORE_OPERATORS: Builtin[] = [
|
|
|
133
141
|
if (isPowerSets) return isSubsetOf(toFiniteSet(left.base).elements, right.base);
|
|
134
142
|
return isSubsetOf(toFiniteSet(left).elements, right);
|
|
135
143
|
}),
|
|
144
|
+
// TLC defers the set operations of values that aren't sets to the enumeration or the membership
|
|
145
|
+
// tests of the result.
|
|
136
146
|
...SET_OPERATORS.map((operator) =>
|
|
137
147
|
defineOperator(operator, 2, (args) => {
|
|
138
148
|
const left = getValue(args, 0, operator);
|
|
139
149
|
const right = getValue(args, 1, operator);
|
|
140
|
-
if (
|
|
150
|
+
if (
|
|
151
|
+
isReducibleSet(left) &&
|
|
152
|
+
isReducibleSet(right) &&
|
|
153
|
+
!isMixedSet(left) &&
|
|
154
|
+
!isMixedSet(right)
|
|
155
|
+
) {
|
|
141
156
|
if (operator === "\\cup" && isEmptySet(left)) return right;
|
|
142
157
|
const merge =
|
|
143
158
|
operator === "\\cup"
|
|
@@ -145,25 +160,24 @@ export const CORE_OPERATORS: Builtin[] = [
|
|
|
145
160
|
: operator === "\\cap"
|
|
146
161
|
? intersectSorted
|
|
147
162
|
: differenceSorted;
|
|
148
|
-
//
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
if (!(error instanceof TlaEvaluationError)) throw error;
|
|
154
|
-
}
|
|
163
|
+
// The merge compares the elements, which TLC tests for membership one by one instead.
|
|
164
|
+
return computeLikeTlcOnFailure(
|
|
165
|
+
() => merge(toFiniteSet(left), toFiniteSet(right)),
|
|
166
|
+
() => combineReducible(operator, left, right),
|
|
167
|
+
);
|
|
155
168
|
}
|
|
156
|
-
if (
|
|
157
|
-
if (operator !== "\\" &&
|
|
158
|
-
|
|
169
|
+
if (isReducibleSet(left)) return combineReducible(operator, left, right);
|
|
170
|
+
if (operator !== "\\" && isReducibleSet(right))
|
|
171
|
+
return combineReducible(operator, right, left);
|
|
172
|
+
return markStreamedSet({ kind: "SetOperation", operator, left, right });
|
|
159
173
|
}),
|
|
160
174
|
),
|
|
161
|
-
defineOperator("SUBSET", 1, (args) => ({ kind: "Subset", base:
|
|
175
|
+
defineOperator("SUBSET", 1, (args) => ({ kind: "Subset", base: getValue(args, 0, "SUBSET") })),
|
|
162
176
|
defineOperator("UNION", 1, (args) => {
|
|
163
177
|
const outer = getSet(args, 0, "UNION");
|
|
164
178
|
const sets = isEnumeratedSet(outer) ? outer.elements.filter(isEnumeratedSet) : [];
|
|
165
179
|
if (!isEnumeratedSet(outer) || sets.length !== outer.elements.length) {
|
|
166
|
-
return { kind: "Union", base: outer };
|
|
180
|
+
return markStreamedSet({ kind: "Union", base: outer });
|
|
167
181
|
}
|
|
168
182
|
if (isMixedSet(outer) || sets.some(isMixedSet)) {
|
|
169
183
|
const union: MixedSetValue = { kind: "MixedSet", elements: [] };
|
|
@@ -185,17 +199,17 @@ export const CORE_OPERATORS: Builtin[] = [
|
|
|
185
199
|
}),
|
|
186
200
|
];
|
|
187
201
|
|
|
188
|
-
const NEG_SIGNATURE =
|
|
202
|
+
const NEG_SIGNATURE = getJavaSignature("Integers", "Neg", "IntValue", 1);
|
|
189
203
|
|
|
190
|
-
// TLC overrides the
|
|
191
|
-
// Integers,
|
|
192
|
-
const
|
|
193
|
-
const dotDotSignature =
|
|
204
|
+
// TLC overrides the arithmetic of Naturals with the Java methods of tlc2.module.Naturals, or with
|
|
205
|
+
// those of tlc2.module.Integers when the spec loads Integers, and names the method in an error.
|
|
206
|
+
const createArithmeticOperators = (module: string) => {
|
|
207
|
+
const dotDotSignature = getJavaSignature(module, "DotDot", "IntervalValue", 2);
|
|
194
208
|
return [
|
|
195
|
-
defineArithmetic(
|
|
196
|
-
defineArithmetic(
|
|
197
|
-
defineArithmetic(
|
|
198
|
-
defineArithmetic(
|
|
209
|
+
defineArithmetic(module, "+", "Plus", (left, right) => left + right),
|
|
210
|
+
defineArithmetic(module, "-", "Minus", (left, right) => left - right),
|
|
211
|
+
defineArithmetic(module, "*", "Times", (left, right) => left * right),
|
|
212
|
+
defineArithmetic(module, "^", "Expt", (base, exponent) => {
|
|
199
213
|
if (exponent < 0) {
|
|
200
214
|
throw new TlaModuleError(
|
|
201
215
|
`The second argument of ^ should be a natural number, but instead it is:\n${exponent}`,
|
|
@@ -204,13 +218,19 @@ const getArithmeticOperators = (javaClass: "Naturals" | "Integers") => {
|
|
|
204
218
|
if (base === 0 && exponent === 0) throw new TlaModuleError("0^0 is undefined.");
|
|
205
219
|
return base ** exponent;
|
|
206
220
|
}),
|
|
207
|
-
defineArithmetic(
|
|
221
|
+
defineArithmetic(module, "\\div", "Divide", (left, right) => {
|
|
208
222
|
if (right === 0) throw new TlaModuleError("The second argument of \\div is 0.");
|
|
223
|
+
// tlc2.module.Naturals#Divide floors only a quotient Java truncates below 0, and lets
|
|
224
|
+
// -2147483648 \div -1 overflow.
|
|
225
|
+
if (module === "Naturals") {
|
|
226
|
+
const truncated = Math.trunc(left / right) | 0;
|
|
227
|
+
return truncated < 0 && Math.imul(truncated, right) !== left ? truncated - 1 : truncated;
|
|
228
|
+
}
|
|
209
229
|
const quotient = Math.floor(left / right);
|
|
210
230
|
if (isOutOfRange(quotient)) throw createOverflowError(`${left} \\div ${right}`);
|
|
211
231
|
return quotient;
|
|
212
232
|
}),
|
|
213
|
-
defineArithmetic(
|
|
233
|
+
defineArithmetic(module, "%", "Mod", (left, right) => {
|
|
214
234
|
if (right <= 0) {
|
|
215
235
|
throw new TlaModuleError(
|
|
216
236
|
`The second argument of % should be a positive number, but instead it is:\n${right}`,
|
|
@@ -226,18 +246,32 @@ const getArithmeticOperators = (javaClass: "Naturals" | "Integers") => {
|
|
|
226
246
|
];
|
|
227
247
|
};
|
|
228
248
|
|
|
249
|
+
const NATURALS_ARITHMETIC = createArithmeticOperators("Naturals");
|
|
250
|
+
|
|
251
|
+
const INTEGERS_ARITHMETIC = createArithmeticOperators("Integers");
|
|
252
|
+
|
|
253
|
+
// The operators of Naturals that TLC overrides with the methods of tlc2.module.Integers when it
|
|
254
|
+
// loads Integers for its trace exploration spec, by the operator each replaces.
|
|
255
|
+
export const getTraceSpecArithmetic = (builtin: Builtin) => {
|
|
256
|
+
const index = NATURALS_ARITHMETIC.indexOf(builtin);
|
|
257
|
+
return index === -1 ? undefined : INTEGERS_ARITHMETIC[index];
|
|
258
|
+
};
|
|
259
|
+
|
|
229
260
|
const NATURALS_OPERATORS = [
|
|
230
261
|
defineConstant("Nat", { kind: "InfiniteSet", name: "Nat" }),
|
|
231
|
-
...
|
|
262
|
+
...NATURALS_ARITHMETIC,
|
|
232
263
|
defineComparison("<", (left, right) => left < right),
|
|
233
264
|
defineComparison(">", (left, right) => left > right),
|
|
234
265
|
defineComparison("<=", (left, right) => left <= right),
|
|
235
|
-
|
|
266
|
+
// tlc2.module.Naturals#GEQ names itself > in its errors. Only a spec that extends Integers gets
|
|
267
|
+
// the GEQ of tlc2.module.Integers, not one that loads Integers for its trace exploration spec.
|
|
268
|
+
defineComparison(">=", (left, right) => left >= right, ">"),
|
|
236
269
|
];
|
|
237
270
|
|
|
238
271
|
const INTEGERS_OPERATORS = [
|
|
239
272
|
defineConstant("Int", { kind: "InfiniteSet", name: "Int" }),
|
|
240
|
-
...
|
|
273
|
+
...INTEGERS_ARITHMETIC,
|
|
274
|
+
defineComparison(">=", (left, right) => left >= right),
|
|
241
275
|
defineOperator("-.", 1, (args) => {
|
|
242
276
|
const value = getJavaInteger(getValue(args, 0, "-"), NEG_SIGNATURE);
|
|
243
277
|
if (isOutOfRange(-value)) throw createOverflowError(`-${value}`);
|
|
@@ -277,103 +311,111 @@ const withJavaMethods = (module: string, operators: Builtin[]) => {
|
|
|
277
311
|
});
|
|
278
312
|
};
|
|
279
313
|
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
314
|
+
const createSequencesOperators = (version: TlcVersion) =>
|
|
315
|
+
withJavaMethods("Sequences", [
|
|
316
|
+
defineOperator("Seq", 1, (args) => ({ kind: "SequenceSet", base: getValue(args, 0, "Seq") })),
|
|
317
|
+
defineOperator(
|
|
318
|
+
"Len",
|
|
319
|
+
1,
|
|
320
|
+
(args) => getSequenceOrString(args, 0, getSequenceMessage("", "Len")).length,
|
|
321
|
+
),
|
|
322
|
+
defineOperator("\\o", 2, (args) => {
|
|
323
|
+
const left = getSequenceOrString(args, 0, getEvaluatingMessage("s \\o t", "sequence"));
|
|
324
|
+
if (typeof left !== "string") {
|
|
325
|
+
const right = getSequenceArgument(args, 1, getEvaluatingMessage("t \\o s", "sequence"));
|
|
326
|
+
return createTuple([...left, ...right]);
|
|
327
|
+
}
|
|
328
|
+
const right = getValue(args, 1, "\\o");
|
|
329
|
+
if (typeof right !== "string") {
|
|
330
|
+
throw new TlaModuleError(
|
|
331
|
+
`${getEvaluatingMessage("t \\o s", "string")}\n${formatValue(right)}`,
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
return rankString(left + right);
|
|
335
|
+
}),
|
|
336
|
+
defineOperator("Append", 2, (args) =>
|
|
337
|
+
createTuple([
|
|
338
|
+
...getSequenceArgument(
|
|
339
|
+
args,
|
|
340
|
+
0,
|
|
341
|
+
getEvaluatingMessage(version === "1.7.4" ? "Append(v, s)" : "Append(s, v)", "sequence"),
|
|
342
|
+
),
|
|
343
|
+
getValue(args, 1, "Append"),
|
|
344
|
+
]),
|
|
345
|
+
),
|
|
346
|
+
defineOperator("Head", 1, (args) => {
|
|
347
|
+
const elements = getSequenceArgument(args, 0, getSequenceMessage("", "Head"));
|
|
348
|
+
if (elements.length === 0)
|
|
349
|
+
throw new TlaModuleError("Attempted to apply Head to the empty sequence.");
|
|
350
|
+
return elements[0];
|
|
351
|
+
}),
|
|
352
|
+
defineOperator("Tail", 1, (args) => {
|
|
353
|
+
const sequence = getSequenceOrString(args, 0, getSequenceMessage("", "Tail"));
|
|
354
|
+
if (sequence.length === 0)
|
|
355
|
+
throw new TlaModuleError("Attempted to apply Tail to the empty sequence.");
|
|
356
|
+
return sliceSequence(sequence, 1);
|
|
357
|
+
}),
|
|
358
|
+
defineOperator("SubSeq", 3, (args) => {
|
|
359
|
+
const sequence = getSequenceOrString(args, 0, getSequenceMessage("first ", "SubSeq"));
|
|
360
|
+
const start = getNumber(args, 1, "SubSeq");
|
|
361
|
+
const end = getNumber(args, 2, "SubSeq");
|
|
362
|
+
if (start > end) return sliceSequence(sequence, 0, 0);
|
|
363
|
+
const outOfDomain =
|
|
364
|
+
start < 1 || start > sequence.length
|
|
365
|
+
? { position: "second", value: start }
|
|
366
|
+
: end > sequence.length
|
|
367
|
+
? { position: "third", value: end }
|
|
368
|
+
: undefined;
|
|
369
|
+
if (outOfDomain) {
|
|
370
|
+
throw new TlaModuleError(
|
|
371
|
+
`The ${outOfDomain.position} argument of SubSeq must be in the domain of its first argument:\n${formatValue(getValue(args, 0, "SubSeq"))}\n, but instead it is\n${outOfDomain.value}`,
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
return sliceSequence(sequence, start - 1, end);
|
|
375
|
+
}),
|
|
376
|
+
defineHigherOrderOperator("SelectSeq", 2, (args) => {
|
|
377
|
+
const test = getOperator(args, 1, "SelectSeq");
|
|
378
|
+
return createTuple(
|
|
379
|
+
getSequenceArgument(args, 0, getSequenceMessage("first ", "SelectSeq")).filter(
|
|
380
|
+
(element) => {
|
|
381
|
+
const result = test.call([element]);
|
|
382
|
+
if (typeof result !== "boolean") {
|
|
383
|
+
throw new TlaModuleError(
|
|
384
|
+
`The second argument of SelectSeq should be a operator, but instead it is:\n${formatValue(result)}`,
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
return result;
|
|
388
|
+
},
|
|
389
|
+
),
|
|
333
390
|
);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
}),
|
|
337
|
-
defineHigherOrderOperator("SelectSeq", 2, (args) => {
|
|
338
|
-
const test = getOperator(args, 1, "SelectSeq");
|
|
339
|
-
return createTuple(
|
|
340
|
-
getSequenceArgument(args, 0, getSequenceMessage("first ", "SelectSeq")).filter((element) => {
|
|
341
|
-
const result = test.call([element]);
|
|
342
|
-
if (typeof result !== "boolean") {
|
|
343
|
-
throw new TlaModuleError(
|
|
344
|
-
`The second argument of SelectSeq should be a operator, but instead it is:\n${formatValue(result)}`,
|
|
345
|
-
);
|
|
346
|
-
}
|
|
347
|
-
return result;
|
|
348
|
-
}),
|
|
349
|
-
);
|
|
350
|
-
}),
|
|
351
|
-
]);
|
|
391
|
+
}),
|
|
392
|
+
]);
|
|
352
393
|
|
|
353
|
-
const
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}),
|
|
364
|
-
defineOperator("Cardinality", 1, (args) => {
|
|
365
|
-
const set = getValue(args, 0, "Cardinality");
|
|
366
|
-
if (
|
|
367
|
-
!isSetValue(set) ||
|
|
368
|
-
(typeof set === "object" && (set.kind === "InfiniteSet" || set.kind === "SequenceSet"))
|
|
369
|
-
) {
|
|
370
|
-
throw new TlaModuleError(
|
|
371
|
-
`Attempted to compute cardinality of the value\n${formatValue(set)}`,
|
|
394
|
+
const createFiniteSetsOperators = (version: TlcVersion) =>
|
|
395
|
+
withJavaMethods("FiniteSets", [
|
|
396
|
+
defineOperator("IsFiniteSet", 1, (args) => {
|
|
397
|
+
const value = getValue(args, 0, "IsFiniteSet");
|
|
398
|
+
if (isSetValue(value)) return isFiniteSet(value);
|
|
399
|
+
if (typeof value === "object" && value.kind === "Function") return true;
|
|
400
|
+
throw new TlaEvaluationError(
|
|
401
|
+
typeof value === "object" && value.kind === "LazyFunction"
|
|
402
|
+
? `Attempted to check if the function:\n${formatValue(value)}\nis a finite set.`
|
|
403
|
+
: `Attempted to check if the ${describeKind(value)} ${formatValue(value)} is a finite set.`,
|
|
372
404
|
);
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
405
|
+
}),
|
|
406
|
+
defineOperator("Cardinality", 1, (args) => {
|
|
407
|
+
const set = getValue(args, 0, "Cardinality");
|
|
408
|
+
if (
|
|
409
|
+
!isSetValue(set) ||
|
|
410
|
+
(typeof set === "object" && (set.kind === "InfiniteSet" || set.kind === "SequenceSet"))
|
|
411
|
+
) {
|
|
412
|
+
throw new TlaModuleError(
|
|
413
|
+
`Attempted to compute cardinality of the value\n${formatValue(set)}`,
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
return getCardinality(set, version);
|
|
417
|
+
}),
|
|
418
|
+
]);
|
|
377
419
|
|
|
378
420
|
// The modules that each standard module loads through EXTENDS and LOCAL INSTANCE in TLC.
|
|
379
421
|
export const STANDARD_DEPENDENCIES = new Map([
|
|
@@ -393,6 +435,7 @@ export const getStandardModule = (
|
|
|
393
435
|
print: (text: string) => void,
|
|
394
436
|
runtime: CheckerRuntime,
|
|
395
437
|
files: FileSystem,
|
|
438
|
+
builtins: ReadonlyMap<string, Builtin>,
|
|
396
439
|
): StandardModule | undefined => {
|
|
397
440
|
switch (name) {
|
|
398
441
|
case "Naturals":
|
|
@@ -400,9 +443,9 @@ export const getStandardModule = (
|
|
|
400
443
|
case "Integers":
|
|
401
444
|
return { extends: ["Naturals"], operators: INTEGERS_OPERATORS };
|
|
402
445
|
case "Sequences":
|
|
403
|
-
return { extends: [], operators:
|
|
446
|
+
return { extends: [], operators: createSequencesOperators(runtime.version) };
|
|
404
447
|
case "FiniteSets":
|
|
405
|
-
return { extends: [], operators:
|
|
448
|
+
return { extends: [], operators: createFiniteSetsOperators(runtime.version) };
|
|
406
449
|
case "TLC":
|
|
407
450
|
return { extends: [], operators: withJavaMethods("TLC", createTlcOperators(print, runtime)) };
|
|
408
451
|
case "Randomization":
|
|
@@ -412,7 +455,7 @@ export const getStandardModule = (
|
|
|
412
455
|
case "Json":
|
|
413
456
|
return { extends: [], operators: createJsonOperators(files) };
|
|
414
457
|
case "Bags":
|
|
415
|
-
return { extends: [], operators:
|
|
458
|
+
return { extends: [], operators: createBagsOperators(builtins) };
|
|
416
459
|
case "TLCExt":
|
|
417
460
|
return { extends: [], operators: createTlcExtOperators(print, runtime) };
|
|
418
461
|
default:
|
package/src/state-graph.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// A port of TLC's -dump writers, tlc2.util.StateWriter and tlc2.util.DotStateWriter.
|
|
2
2
|
|
|
3
|
+
import type { TlcVersion } from "./tlc-version";
|
|
4
|
+
|
|
3
5
|
export interface StateDump {
|
|
4
6
|
path: string;
|
|
5
7
|
dot?: boolean;
|
|
@@ -29,6 +31,8 @@ export interface StateWriter {
|
|
|
29
31
|
isSeen: boolean,
|
|
30
32
|
action: GraphAction | undefined,
|
|
31
33
|
) => void;
|
|
34
|
+
// The stuttering step of a state that TLC 1.7.4 adds to the behavior graph.
|
|
35
|
+
writeStuttering: (state: GraphState) => void;
|
|
32
36
|
close: () => void;
|
|
33
37
|
}
|
|
34
38
|
|
|
@@ -77,14 +81,23 @@ const createPlainWriter = (dump: StateDump, writeFile: WriteFile): StateWriter =
|
|
|
77
81
|
writeSuccessor: (_state, successor, isSeen) => {
|
|
78
82
|
if (!isSeen) writeState(successor);
|
|
79
83
|
},
|
|
84
|
+
// TLC 1.7.4 writes the state again, as it takes the stuttering step for one to a new state.
|
|
85
|
+
writeStuttering: writeState,
|
|
80
86
|
close: () => writeFile?.(dump.path, states.join("")),
|
|
81
87
|
};
|
|
82
88
|
};
|
|
83
89
|
|
|
84
|
-
|
|
90
|
+
// TLC 1.7.4 draws its nodes as ellipses, gives them no tooltip, and labels an edge with the name
|
|
91
|
+
// of its action alone.
|
|
92
|
+
const createDotWriter = (
|
|
93
|
+
dump: StateDump,
|
|
94
|
+
writeFile: WriteFile,
|
|
95
|
+
version: TlcVersion | undefined,
|
|
96
|
+
): StateWriter => {
|
|
97
|
+
const is174 = version === "1.7.4";
|
|
85
98
|
const lines = [
|
|
86
99
|
"strict digraph DiskGraph {\n",
|
|
87
|
-
"node [shape=box,style=rounded]\n",
|
|
100
|
+
is174 ? "" : "node [shape=box,style=rounded]\n",
|
|
88
101
|
dump.colorize ? `edge [colorscheme="${COLOR_SCHEME}"]\n` : "",
|
|
89
102
|
"nodesep=0.35;\n",
|
|
90
103
|
"subgraph cluster_graph {\n",
|
|
@@ -137,21 +150,31 @@ const createDotWriter = (dump: StateDump, writeFile: WriteFile): StateWriter =>
|
|
|
137
150
|
},
|
|
138
151
|
writeSuccessor: (state, successor, isSeen, action) => {
|
|
139
152
|
const color = dump.colorize ? String(getColor(action)) : "black";
|
|
140
|
-
const label =
|
|
153
|
+
const label =
|
|
154
|
+
dump.actionLabels && action ? escape(is174 ? action.name : action.signature) : "";
|
|
141
155
|
lines.push(
|
|
142
156
|
`${state.fingerprint} -> ${successor.fingerprint} [label="${label}",color="${color}",fontcolor="${color}"];\n`,
|
|
143
157
|
);
|
|
144
158
|
if (!isSeen) {
|
|
159
|
+
const tooltip = is174 ? "" : `,tooltip="${toDot(successor.getText())}"`;
|
|
145
160
|
lines.push(
|
|
146
|
-
`${successor.fingerprint} [label="${toDot(successor.getLabel())}"
|
|
161
|
+
`${successor.fingerprint} [label="${toDot(successor.getLabel())}"${tooltip}];\n`,
|
|
147
162
|
);
|
|
148
163
|
}
|
|
149
164
|
addRank(state);
|
|
150
165
|
writeSnapshot();
|
|
151
166
|
},
|
|
167
|
+
writeStuttering: (state) => {
|
|
168
|
+
lines.push(`${state.fingerprint} -> ${state.fingerprint} [style="dashed"];\n`);
|
|
169
|
+
addRank(state);
|
|
170
|
+
writeSnapshot();
|
|
171
|
+
},
|
|
152
172
|
close: () => writeFile?.(dump.path, lines.join("") + getEnding()),
|
|
153
173
|
};
|
|
154
174
|
};
|
|
155
175
|
|
|
156
|
-
export const createStateWriter = (
|
|
157
|
-
dump
|
|
176
|
+
export const createStateWriter = (
|
|
177
|
+
dump: StateDump,
|
|
178
|
+
writeFile: WriteFile,
|
|
179
|
+
version: TlcVersion | undefined,
|
|
180
|
+
) => (dump.dot ? createDotWriter(dump, writeFile, version) : createPlainWriter(dump, writeFile));
|