tla-ts 0.0.10-dev.3a85c3a9e → 0.0.10-dev.4a2a53c48
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/run.cjs +15 -15
- package/dist/run.js +38 -38
- package/dist/transfer.cjs +4 -4
- package/dist/transfer.js +4 -4
- package/package.json +1 -1
- package/src/cli/tlc-output.ts +3 -3
- package/src/cli/tlc.ts +15 -1
- package/src/environment.ts +10 -5
- package/src/resolve.ts +1 -2
- package/src/runtime.ts +4 -0
- package/src/search.ts +29 -20
- package/src/simulate.ts +3 -0
- package/src/standard-definitions.ts +4 -0
- package/src/tlc/tlcext-operators.ts +44 -12
package/package.json
CHANGED
package/src/cli/tlc-output.ts
CHANGED
|
@@ -609,9 +609,9 @@ export const printCommandLineError = (isTool: boolean, version: TlcVersion, mess
|
|
|
609
609
|
return 1;
|
|
610
610
|
};
|
|
611
611
|
|
|
612
|
-
//
|
|
612
|
+
// TLC prints the JVM's default direct memory limit and its default fingerprint set and state queue.
|
|
613
613
|
export const printStartupBanner = (printer: MessagePrinter, args: TlcArguments) => {
|
|
614
|
-
const workers = `${args.workers} worker${args.workers === 1 ? "" : "s"} on ${availableParallelism()} cores with ${Math.floor(getHeapStatistics().heap_size_limit / 1024 / 1024)}MB heap and
|
|
614
|
+
const workers = `${args.workers} worker${args.workers === 1 ? "" : "s"} on ${availableParallelism()} cores with ${Math.floor(getHeapStatistics().heap_size_limit / 1024 / 1024)}MB heap and 64MB offheap memory [pid: ${process.pid}] (${type()} ${release()} ${arch()}, Node.js ${process.versions.node} ${process.arch.endsWith("64") ? 64 : 32}bit`;
|
|
615
615
|
if (args.mode === "model-check" && args.dfidDepth !== undefined) {
|
|
616
616
|
printer.print(
|
|
617
617
|
MESSAGE_CODE.depthFirstModelChecking,
|
|
@@ -624,7 +624,7 @@ export const printStartupBanner = (printer: MessagePrinter, args: TlcArguments)
|
|
|
624
624
|
printer.print(
|
|
625
625
|
MESSAGE_CODE.modelChecking,
|
|
626
626
|
MESSAGE_LEVEL.none,
|
|
627
|
-
`Running breadth-first search Model-Checking with fp ${args.fingerprintIndex} and seed ${args.seed} with ${workers},
|
|
627
|
+
`Running breadth-first search Model-Checking with fp ${args.fingerprintIndex} and seed ${args.seed} with ${workers}, MSBDiskFPSet, DiskStateQueue).`,
|
|
628
628
|
);
|
|
629
629
|
return;
|
|
630
630
|
}
|
package/src/cli/tlc.ts
CHANGED
|
@@ -29,6 +29,7 @@ import { EXIT_STATUS } from "../exit-codes";
|
|
|
29
29
|
import { check } from "../parallel";
|
|
30
30
|
import { extractModule, parseModule } from "../parser";
|
|
31
31
|
import { simulate } from "../simulate";
|
|
32
|
+
import type { StandardInput } from "../search";
|
|
32
33
|
import type { StateDump } from "../state-graph";
|
|
33
34
|
import {
|
|
34
35
|
getSanyStandardModules,
|
|
@@ -385,7 +386,7 @@ const checkSpec = async (
|
|
|
385
386
|
version,
|
|
386
387
|
);
|
|
387
388
|
config.invariants.push(...invariants.names);
|
|
388
|
-
const options: CheckOptions = {
|
|
389
|
+
const options: CheckOptions & StandardInput = {
|
|
389
390
|
workers: args.workers,
|
|
390
391
|
livenessCheck:
|
|
391
392
|
livenessCheck === "off"
|
|
@@ -412,6 +413,7 @@ const checkSpec = async (
|
|
|
412
413
|
source: invariants.source,
|
|
413
414
|
config,
|
|
414
415
|
onPause: () => readSync(0, Buffer.alloc(1)),
|
|
416
|
+
readLine: readStandardInputLine,
|
|
415
417
|
loadModule,
|
|
416
418
|
loadClass: (name) => {
|
|
417
419
|
const classPath = getClassPath(directory, name);
|
|
@@ -478,6 +480,18 @@ const checkSpec = async (
|
|
|
478
480
|
}
|
|
479
481
|
};
|
|
480
482
|
|
|
483
|
+
const readStandardInputLine = () => {
|
|
484
|
+
const bytes: number[] = [];
|
|
485
|
+
const byte = Buffer.alloc(1);
|
|
486
|
+
let isRead = false;
|
|
487
|
+
while (readSync(0, byte) === 1) {
|
|
488
|
+
isRead = true;
|
|
489
|
+
if (byte[0] === 0x0a) break;
|
|
490
|
+
bytes.push(byte[0]);
|
|
491
|
+
}
|
|
492
|
+
return isRead ? Buffer.from(bytes).toString().replace(/\r$/, "") : undefined;
|
|
493
|
+
};
|
|
494
|
+
|
|
481
495
|
const formatSanyErrors = (error: TlaSyntaxError, specName: string) => {
|
|
482
496
|
const isFatal = error instanceof TlaSanyFatalError;
|
|
483
497
|
if (!isFatal && !error.failure)
|
package/src/environment.ts
CHANGED
|
@@ -99,6 +99,7 @@ interface EnvironmentOptions {
|
|
|
99
99
|
isWarningEnabled?: boolean;
|
|
100
100
|
version?: TlcVersion;
|
|
101
101
|
moduleOperators?: ModuleOperator[];
|
|
102
|
+
readLine?: () => string | undefined;
|
|
102
103
|
}
|
|
103
104
|
|
|
104
105
|
export interface ResolvedModuleOperator extends ModuleOperator {
|
|
@@ -260,6 +261,7 @@ export const createEnvironment = (
|
|
|
260
261
|
runtime.isWarningEnabled = options.isWarningEnabled ?? true;
|
|
261
262
|
runtime.isTool = options.isTool ?? false;
|
|
262
263
|
runtime.version = options.version ?? "master";
|
|
264
|
+
runtime.readLine = options.readLine;
|
|
263
265
|
const linkedModules = new Map<string, LinkedModule>();
|
|
264
266
|
const checkedModules = new Map<string, LinkedModule>();
|
|
265
267
|
const linkOrder: LinkedModule[] = [];
|
|
@@ -586,8 +588,11 @@ export const createEnvironment = (
|
|
|
586
588
|
);
|
|
587
589
|
};
|
|
588
590
|
|
|
589
|
-
const createArgumentParams = (arity: number) =>
|
|
590
|
-
Array.from({ length: arity }, (_value, index) => ({
|
|
591
|
+
const createArgumentParams = (arity: number, params: number[] | undefined) =>
|
|
592
|
+
Array.from({ length: arity }, (_value, index) => ({
|
|
593
|
+
name: `argument${index}`,
|
|
594
|
+
arity: params?.[index] ?? 0,
|
|
595
|
+
}));
|
|
591
596
|
|
|
592
597
|
const getSubstitutionBody = (
|
|
593
598
|
replacement: Expression,
|
|
@@ -601,7 +606,7 @@ export const createEnvironment = (
|
|
|
601
606
|
body: replacement.body,
|
|
602
607
|
};
|
|
603
608
|
}
|
|
604
|
-
const params = createArgumentParams(declaration.arity);
|
|
609
|
+
const params = createArgumentParams(declaration.arity, undefined);
|
|
605
610
|
const operator =
|
|
606
611
|
replacement.kind === "Identifier"
|
|
607
612
|
? replacement.name
|
|
@@ -625,7 +630,7 @@ export const createEnvironment = (
|
|
|
625
630
|
if (standardSymbols) {
|
|
626
631
|
if (instance.name === undefined) return [];
|
|
627
632
|
return [...standardSymbols].map(([name, symbol]) => {
|
|
628
|
-
const forwarded = createArgumentParams(symbol.arity);
|
|
633
|
+
const forwarded = createArgumentParams(symbol.arity, symbol.params);
|
|
629
634
|
return createLocalAlias(
|
|
630
635
|
`${instance.name}!${name}`,
|
|
631
636
|
symbol.key,
|
|
@@ -712,7 +717,7 @@ export const createEnvironment = (
|
|
|
712
717
|
.filter(([name]) => !declared.has(name))
|
|
713
718
|
.map(([name, symbol]) => {
|
|
714
719
|
const key = instantiation.getKey(symbol.key);
|
|
715
|
-
const ownParams = createArgumentParams(symbol.arity);
|
|
720
|
+
const ownParams = createArgumentParams(symbol.arity, symbol.params);
|
|
716
721
|
const params = [...instance.params, ...ownParams];
|
|
717
722
|
return createLocalAlias(
|
|
718
723
|
instance.name === undefined ? name : `${instance.name}!${name}`,
|
package/src/resolve.ts
CHANGED
|
@@ -850,7 +850,7 @@ const resolveDefinitions = (
|
|
|
850
850
|
range: definition.location.range,
|
|
851
851
|
parent: current,
|
|
852
852
|
};
|
|
853
|
-
if (isInstantiated(definition)) return local;
|
|
853
|
+
if (isInstantiated(definition)) return { ...local, params: getParamArities(definition) };
|
|
854
854
|
const isInstanced = instances.some((instance) => instance.location === definition.location);
|
|
855
855
|
const isGenerated = unit.isGenerated || definition.isLocal || isKey(definition.name);
|
|
856
856
|
const inner = isInstanced
|
|
@@ -899,7 +899,6 @@ const isInstanceArityReported = (
|
|
|
899
899
|
return true;
|
|
900
900
|
};
|
|
901
901
|
|
|
902
|
-
// Deviation from SANY: an operator whose parameters tla-ts does not know takes any argument.
|
|
903
902
|
const resolveApply = (
|
|
904
903
|
expression: Expression & { kind: "Apply" },
|
|
905
904
|
scope: LocalName | undefined,
|
package/src/runtime.ts
CHANGED
|
@@ -19,6 +19,7 @@ export interface CheckerRuntime {
|
|
|
19
19
|
| undefined;
|
|
20
20
|
evaluateAtStartup: <Result>(evaluate: () => Result) => Result;
|
|
21
21
|
pause: (() => void) | undefined;
|
|
22
|
+
readLine: (() => string | undefined) | undefined;
|
|
22
23
|
warn: (code: number, text: string) => void;
|
|
23
24
|
isWarningEnabled: boolean;
|
|
24
25
|
isTool: boolean;
|
|
@@ -26,6 +27,7 @@ export interface CheckerRuntime {
|
|
|
26
27
|
seed: bigint;
|
|
27
28
|
isSeen: (state: Value[]) => boolean;
|
|
28
29
|
getSuccessorAction: (state: Value[], next: Value[]) => SpecAction | undefined;
|
|
30
|
+
toRecord: (state: Value[]) => Record<string, Value>;
|
|
29
31
|
generatedStates: number;
|
|
30
32
|
distinctStates: number;
|
|
31
33
|
initialStates: number;
|
|
@@ -54,6 +56,7 @@ export const createRuntime = (checkDeadlock: boolean, seed = 0n): CheckerRuntime
|
|
|
54
56
|
deferred: undefined,
|
|
55
57
|
isSeen: () => false,
|
|
56
58
|
getSuccessorAction: () => undefined,
|
|
59
|
+
toRecord: () => ({}),
|
|
57
60
|
setLivenessSource: () => {},
|
|
58
61
|
getCurrentState: () => undefined,
|
|
59
62
|
getFingerprint: getTlcFingerprint,
|
|
@@ -77,6 +80,7 @@ export const createRuntime = (checkDeadlock: boolean, seed = 0n): CheckerRuntime
|
|
|
77
80
|
}
|
|
78
81
|
},
|
|
79
82
|
pause: undefined,
|
|
83
|
+
readLine: undefined,
|
|
80
84
|
warn: () => {},
|
|
81
85
|
isWarningEnabled: true,
|
|
82
86
|
isTool: false,
|
package/src/search.ts
CHANGED
|
@@ -95,26 +95,33 @@ import {
|
|
|
95
95
|
type Value,
|
|
96
96
|
} from "./values";
|
|
97
97
|
|
|
98
|
-
interface
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
98
|
+
export interface StandardInput {
|
|
99
|
+
readLine?: () => string | undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
interface EnvironmentSettings
|
|
103
|
+
extends
|
|
104
|
+
Pick<
|
|
105
|
+
CheckOptions,
|
|
106
|
+
| "source"
|
|
107
|
+
| "loadModule"
|
|
108
|
+
| "loadClass"
|
|
109
|
+
| "readFile"
|
|
110
|
+
| "writeFile"
|
|
111
|
+
| "makeDirectory"
|
|
112
|
+
| "seed"
|
|
113
|
+
| "isTool"
|
|
114
|
+
| "traceSpec"
|
|
115
|
+
| "isSanyReported"
|
|
116
|
+
| "isWarningEnabled"
|
|
117
|
+
| "version"
|
|
118
|
+
| "moduleOperators"
|
|
119
|
+
| "fingerprintPolynomial"
|
|
120
|
+
| "maxSetSize"
|
|
121
|
+
| "isLazyValueExpanded"
|
|
122
|
+
| "isViewPrinted"
|
|
123
|
+
>,
|
|
124
|
+
StandardInput {}
|
|
118
125
|
|
|
119
126
|
interface NamedExpression {
|
|
120
127
|
name: string;
|
|
@@ -875,6 +882,7 @@ export const createCheckEnvironment = (
|
|
|
875
882
|
isWarningEnabled: options.isWarningEnabled,
|
|
876
883
|
version: options.version,
|
|
877
884
|
moduleOperators: options.moduleOperators,
|
|
885
|
+
readLine: options.readLine,
|
|
878
886
|
});
|
|
879
887
|
return { order, specification };
|
|
880
888
|
};
|
|
@@ -1186,6 +1194,7 @@ export const createSearch = (
|
|
|
1186
1194
|
? record
|
|
1187
1195
|
: setViewText(record, () => getViewText(view.expression, state));
|
|
1188
1196
|
};
|
|
1197
|
+
runtime.toRecord = toRecord;
|
|
1189
1198
|
return {
|
|
1190
1199
|
properties,
|
|
1191
1200
|
spec,
|
package/src/simulate.ts
CHANGED
|
@@ -249,6 +249,8 @@ export const simulate = (options: SimulationOptions): number => {
|
|
|
249
249
|
const nextActions = description.actions;
|
|
250
250
|
let traceCount = 0;
|
|
251
251
|
let currentTrace = 0;
|
|
252
|
+
let evaluatedAction: SpecAction | undefined;
|
|
253
|
+
runtime.getSuccessorAction = () => evaluatedAction;
|
|
252
254
|
runtime.getLevel = (state) => nodes.get(state)?.level ?? 0;
|
|
253
255
|
runtime.getBehavior = (state) => {
|
|
254
256
|
const node = nodes.get(state);
|
|
@@ -486,6 +488,7 @@ export const simulate = (options: SimulationOptions): number => {
|
|
|
486
488
|
const successors: TraceNode[] = [];
|
|
487
489
|
let failure: WorkerError | undefined;
|
|
488
490
|
runtime.deferred = undefined;
|
|
491
|
+
evaluatedAction = action;
|
|
489
492
|
try {
|
|
490
493
|
forEachSuccessor(
|
|
491
494
|
action.expression,
|
|
@@ -81,6 +81,10 @@ const SIGNATURES: Signature[] = [
|
|
|
81
81
|
["RandomSubset", 0, [0, 0], [2, 2], [1, 1]],
|
|
82
82
|
["RandomSetOfSubsets", 0, [0, 0, 0], [2, 3, 2], [1, 0, 1]],
|
|
83
83
|
["TestRandomSetOfSubsets", 0, [0, 0, 0], [2, 3, 2], [1, 0, 1]],
|
|
84
|
+
["_Track", 0, [0, 0], [3, 2], [0, 0]],
|
|
85
|
+
["_Counts", 0, [], [], []],
|
|
86
|
+
["_CheckName", 0, [0], [2], [1]],
|
|
87
|
+
["_PrintCounts", 0, [], [], []],
|
|
84
88
|
];
|
|
85
89
|
|
|
86
90
|
export const STANDARD_LEVELS = new Map(
|
|
@@ -7,7 +7,13 @@ import {
|
|
|
7
7
|
getThunk,
|
|
8
8
|
getValue,
|
|
9
9
|
} from "../builtins";
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
formatRange,
|
|
12
|
+
TlaEndOfInputError,
|
|
13
|
+
TlaEvaluationError,
|
|
14
|
+
TlaModuleError,
|
|
15
|
+
TlaUnsupportedError,
|
|
16
|
+
} from "../errors";
|
|
11
17
|
import { getTlcFingerprint } from "./fingerprint";
|
|
12
18
|
import { formatMessage, formatNestedMessage, MESSAGE_CODE, MESSAGE_LEVEL } from "./messages";
|
|
13
19
|
import {
|
|
@@ -31,6 +37,7 @@ import {
|
|
|
31
37
|
createRecord,
|
|
32
38
|
createSet,
|
|
33
39
|
createTuple,
|
|
40
|
+
formatState,
|
|
34
41
|
formatValue,
|
|
35
42
|
getFingerprintError,
|
|
36
43
|
getSequenceElements,
|
|
@@ -270,17 +277,42 @@ export const createTlcExtOperators = (
|
|
|
270
277
|
if (isPicked || !context?.next || !context.state || !isCompleteState(context.state)) {
|
|
271
278
|
return true;
|
|
272
279
|
}
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
280
|
+
const state = context.state;
|
|
281
|
+
const action = runtime.getSuccessorAction(state, next);
|
|
282
|
+
const printOverride = (text: string) =>
|
|
283
|
+
print(
|
|
284
|
+
formatMessage(
|
|
285
|
+
runtime.isTool,
|
|
286
|
+
MESSAGE_CODE.moduleOverrideStdout,
|
|
287
|
+
MESSAGE_LEVEL.none,
|
|
288
|
+
text,
|
|
289
|
+
),
|
|
290
|
+
);
|
|
291
|
+
while (true) {
|
|
292
|
+
printOverride(
|
|
293
|
+
`Extend behavior of length ${runtime.getLevel(state)} with a "${action?.name}" step [<Action ${action?.location.range && formatRange(action.location.range)}>]? (Yes/no/explored/states/diff):`,
|
|
294
|
+
);
|
|
295
|
+
const answer = runtime.readLine?.();
|
|
296
|
+
// Deviation from TLC: at the end of standard input, TLC's Scanner leaks a NoSuchElementException.
|
|
297
|
+
if (answer === undefined) throw new TlaEndOfInputError();
|
|
298
|
+
if (/^[\0-\x20]*$/.test(answer) || answer.toLowerCase().startsWith("y")) return true;
|
|
299
|
+
if (answer[0] === "s") {
|
|
300
|
+
printOverride(
|
|
301
|
+
`${formatState(runtime.toRecord(state)).trimEnd()}\n~>\n${formatState(runtime.toRecord(next)).trimEnd()}`,
|
|
302
|
+
);
|
|
303
|
+
} else if (answer[0] === "d") {
|
|
304
|
+
printOverride(formatState(runtime.toRecord(next), runtime.toRecord(state)));
|
|
305
|
+
} else if (answer[0] === "e") {
|
|
306
|
+
if (runtime.getSimulationValue === undefined) {
|
|
307
|
+
throw new TlaUnsupportedError(
|
|
308
|
+
"tla-ts can't mark a state explored while it checks a model.",
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
printOverride(
|
|
312
|
+
"Marking a state explored is unsupported by the current TLC mode. Is TLC running in simulation mode?",
|
|
313
|
+
);
|
|
314
|
+
} else if (answer[0] === "n") return false;
|
|
315
|
+
}
|
|
284
316
|
}),
|
|
285
317
|
isActionLevel: true,
|
|
286
318
|
},
|