tla-ts 0.0.3-dev.4c8c06c → 0.0.3-dev.4fdd845
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/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +157 -8
- package/dist/index.d.ts +157 -8
- 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 -19
- package/dist/run-cli.js +1351 -19
- package/dist/transfer.cjs +86 -16
- package/dist/transfer.js +86 -16
- package/package.json +5 -1
- package/src/ast.ts +142 -6
- package/src/bags.ts +4 -7
- package/src/builtins.ts +29 -11
- package/src/bundled-modules.ts +3 -3
- package/src/canonical.ts +4 -3
- package/src/check.ts +1539 -235
- package/src/cli-options.ts +11 -5
- package/src/cli.ts +8 -1
- package/src/codegen.ts +77 -37
- package/src/config.ts +252 -179
- package/src/dependencies.ts +2 -2
- package/src/environment.ts +518 -137
- package/src/errors.ts +224 -3
- package/src/evaluate.ts +796 -246
- package/src/exit-codes.ts +22 -43
- package/src/index.ts +1 -0
- package/src/instances.ts +19 -16
- package/src/java-overrides.ts +104 -25
- package/src/levels.ts +191 -45
- package/src/lexer.ts +32 -4
- package/src/live-check.ts +828 -0
- package/src/liveness.ts +218 -572
- package/src/obligation-expression.ts +2 -2
- package/src/obligation-source.ts +2 -0
- package/src/parallel-worker.ts +13 -4
- package/src/parallel.ts +73 -6
- package/src/parser.ts +447 -128
- 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 +1380 -420
- package/src/run-cli.ts +1200 -143
- package/src/runtime.ts +19 -1
- package/src/sany-builtins.ts +147 -0
- package/src/sany-generator.ts +3112 -0
- package/src/sany-levels.ts +1208 -0
- package/src/sany-lexer.ts +545 -0
- 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 +2161 -0
- package/src/sany-report.ts +354 -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 +42 -11
- package/src/standard-modules.ts +200 -148
- package/src/standard-ranges.ts +116 -0
- package/src/state-graph.ts +180 -0
- package/src/subexpressions.ts +231 -171
- package/src/substitution-levels.ts +38 -17
- package/src/successors.ts +219 -107
- package/src/symmetry.ts +180 -52
- package/src/tableau.ts +54 -25
- package/src/tlc-ext.ts +42 -29
- package/src/tlc-messages.ts +329 -0
- package/src/tlc-module.ts +52 -43
- package/src/tlc-order.ts +73 -9
- package/src/tlc-random.ts +37 -9
- package/src/tlc-replay.ts +655 -0
- package/src/tlc-summary.ts +20 -5
- package/src/tlc-version.ts +18 -0
- package/src/transfer.ts +15 -3
- package/src/value-sources.ts +29 -0
- package/src/values.ts +708 -180
|
@@ -874,7 +874,7 @@ export const mapSelectorArgs = (selector: Selector, map: (arg: Expr) => Expr): S
|
|
|
874
874
|
? { ...selector, args: selector.args.map(map) }
|
|
875
875
|
: selector;
|
|
876
876
|
|
|
877
|
-
|
|
877
|
+
const mapExceptSpecs = (specs: ExceptSpec[], map: (inner: Expr) => Expr): ExceptSpec[] =>
|
|
878
878
|
specs.map((spec) => {
|
|
879
879
|
const value = map(spec.value);
|
|
880
880
|
const trail = spec.trail.map((point): ExceptPoint =>
|
|
@@ -883,7 +883,7 @@ export const mapExceptSpecs = (specs: ExceptSpec[], map: (inner: Expr) => Expr):
|
|
|
883
883
|
return { trail, value };
|
|
884
884
|
});
|
|
885
885
|
|
|
886
|
-
|
|
886
|
+
const mapDefnBody = (definition: Defn, map: (body: Expr) => Expr): Defn =>
|
|
887
887
|
definition.kind === "Operator" || definition.kind === "Bpragma"
|
|
888
888
|
? { ...definition, body: map(definition.body) }
|
|
889
889
|
: definition;
|
package/src/obligation-source.ts
CHANGED
|
@@ -609,6 +609,8 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
|
|
|
609
609
|
);
|
|
610
610
|
case "ExceptAt":
|
|
611
611
|
return at({ kind: "At", isExcept }, { location });
|
|
612
|
+
case "Bracket":
|
|
613
|
+
throw new TlaProofError("Unexpected [ without a function or subscript");
|
|
612
614
|
case "FunctionApplication":
|
|
613
615
|
return at(
|
|
614
616
|
{
|
package/src/parallel-worker.ts
CHANGED
|
@@ -15,10 +15,10 @@ import type {
|
|
|
15
15
|
WorkerMessage,
|
|
16
16
|
} from "./parallel";
|
|
17
17
|
import { getSuccessors, type Successor } from "./successors";
|
|
18
|
-
import { getTlcStringOrder,
|
|
18
|
+
import { getTlcStringOrder, getTlcDeclarationOrder } from "./tlc-order";
|
|
19
19
|
import { OUT_DEGREE_BUCKETS } from "./tlc-summary";
|
|
20
20
|
import { createStateDecoder, createStateEncoder, type EncodedStates } from "./transfer";
|
|
21
|
-
import { getRankedStringCount, setStringOrder, type Value } from "./values";
|
|
21
|
+
import { getRankedStringCount, setStringOrder, setValueVersion, type Value } from "./values";
|
|
22
22
|
|
|
23
23
|
const WORKER_THREADS_MODULE = "node:worker_threads";
|
|
24
24
|
const LOCKED = -1;
|
|
@@ -51,6 +51,7 @@ const run = (start: StartMessage, parent: Port) => {
|
|
|
51
51
|
const loadModule = (name: string) => modules.get(name);
|
|
52
52
|
const classes = new Map(start.classes);
|
|
53
53
|
setStringOrder(getTlcStringOrder(start.source, start.config, loadModule));
|
|
54
|
+
setValueVersion(start.version);
|
|
54
55
|
const startupStrings = getRankedStringCount();
|
|
55
56
|
const specification = createEnvironment(start.config, {
|
|
56
57
|
source: start.source,
|
|
@@ -58,10 +59,14 @@ const run = (start: StartMessage, parent: Port) => {
|
|
|
58
59
|
loadClass: (name) => classes.get(name),
|
|
59
60
|
print: () => {},
|
|
60
61
|
files: { readFile: undefined, writeFile: undefined },
|
|
62
|
+
isTool: start.isTool,
|
|
63
|
+
isTraceRecorded: start.isTraceRecorded,
|
|
64
|
+
isWarningEnabled: start.isWarningEnabled,
|
|
65
|
+
version: start.version,
|
|
61
66
|
});
|
|
62
67
|
const environment = specification.environment;
|
|
63
68
|
const search = createSearch(start.config, environment, () =>
|
|
64
|
-
|
|
69
|
+
getTlcDeclarationOrder(start.source, loadModule, "variable"),
|
|
65
70
|
);
|
|
66
71
|
const nextAction = search?.spec.next;
|
|
67
72
|
if (!search || nextAction === undefined)
|
|
@@ -128,7 +133,11 @@ const run = (start: StartMessage, parent: Port) => {
|
|
|
128
133
|
if (isSharedFingerprintsFull(shared.fingerprints)) return "paused";
|
|
129
134
|
const successor = successors[expansion.index];
|
|
130
135
|
if (search.findViolatedActionProperty(state, successor.state)) return undefined;
|
|
131
|
-
if (!search.satisfiesActionConstraints(state, successor.state))
|
|
136
|
+
if (!search.satisfiesActionConstraints(state, successor.state)) {
|
|
137
|
+
// TLC checks the invariants of every successor it has not seen, even outside the model.
|
|
138
|
+
if (search.findViolatedInvariant(successor.state, state)) return undefined;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
132
141
|
if (generatedStates) {
|
|
133
142
|
writeStateFingerprint(successor.state, fingerprint);
|
|
134
143
|
if (!generatedStates.insert(fingerprint[0], fingerprint[1])) continue;
|
package/src/parallel.ts
CHANGED
|
@@ -4,8 +4,12 @@ import {
|
|
|
4
4
|
checkSequentially,
|
|
5
5
|
createSearch,
|
|
6
6
|
findAssumptionViolation,
|
|
7
|
+
reportInitialStatesProgress,
|
|
8
|
+
reportStartup,
|
|
7
9
|
type CheckOptions,
|
|
10
|
+
type CheckProgress,
|
|
8
11
|
type CheckResult,
|
|
12
|
+
type InitialStates,
|
|
9
13
|
} from "./check";
|
|
10
14
|
import { parseConfig, type ModelConfig } from "./config";
|
|
11
15
|
import { createEnvironment } from "./environment";
|
|
@@ -23,7 +27,8 @@ import { getInitialStates } from "./successors";
|
|
|
23
27
|
import { getTlcStringOrder, getTlcVariableOrder } from "./tlc-order";
|
|
24
28
|
import { getFingerprintDistance, OUT_DEGREE_BUCKETS } from "./tlc-summary";
|
|
25
29
|
import { createStateEncoder, type EncodedStates } from "./transfer";
|
|
26
|
-
import {
|
|
30
|
+
import type { TlcVersion } from "./tlc-version";
|
|
31
|
+
import { getRankedStringCount, setStringOrder, setValueVersion, type Value } from "./values";
|
|
27
32
|
|
|
28
33
|
const WORKER_THREADS_MODULE = "node:worker_threads";
|
|
29
34
|
|
|
@@ -43,6 +48,10 @@ export interface StartMessage {
|
|
|
43
48
|
index: number;
|
|
44
49
|
ports: (Port | undefined)[];
|
|
45
50
|
seed: EncodedStates;
|
|
51
|
+
isTool: boolean | undefined;
|
|
52
|
+
isTraceRecorded: boolean | undefined;
|
|
53
|
+
isWarningEnabled: boolean | undefined;
|
|
54
|
+
version: TlcVersion | undefined;
|
|
46
55
|
fingerprints: SharedFingerprints;
|
|
47
56
|
requests: Int32Array;
|
|
48
57
|
remaining: Int32Array;
|
|
@@ -101,12 +110,45 @@ const spawnWorker = async (onMessage: (message: WorkerMessage) => void): Promise
|
|
|
101
110
|
};
|
|
102
111
|
|
|
103
112
|
export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
104
|
-
const config =
|
|
105
|
-
|
|
113
|
+
const config =
|
|
114
|
+
typeof options.config === "string"
|
|
115
|
+
? parseConfig(options.config, options.version)
|
|
116
|
+
: options.config;
|
|
117
|
+
const print = options.onPrint ?? console.log;
|
|
118
|
+
const printed = { count: 0 };
|
|
119
|
+
// What each point the search reports is about, such as the invariant TLC warns about.
|
|
120
|
+
const getKey = (progress: CheckProgress) =>
|
|
121
|
+
[
|
|
122
|
+
progress.kind,
|
|
123
|
+
"name" in progress ? progress.name : "",
|
|
124
|
+
"count" in progress ? progress.count : "",
|
|
125
|
+
"text" in progress ? progress.text : "",
|
|
126
|
+
].join(" ");
|
|
127
|
+
const reported = new Set<string>();
|
|
128
|
+
const report = (progress: CheckProgress) => {
|
|
129
|
+
reported.add(getKey(progress));
|
|
130
|
+
options.onProgress?.(progress);
|
|
131
|
+
};
|
|
132
|
+
// The search on the calling thread prints and reports what this one did while it started, so it
|
|
133
|
+
// skips that.
|
|
134
|
+
const fallBack = () => {
|
|
135
|
+
const skipped = { count: printed.count };
|
|
136
|
+
return checkSequentially({
|
|
137
|
+
...options,
|
|
138
|
+
config,
|
|
139
|
+
onPrint: (text) => (skipped.count-- > 0 ? undefined : print(text)),
|
|
140
|
+
onProgress: (progress) => {
|
|
141
|
+
if (!reported.has(getKey(progress))) options.onProgress?.(progress);
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
};
|
|
106
145
|
const count = options.workers ?? 1;
|
|
146
|
+
// TLC's workers write the -dump state graph in whichever order they find it, so one worker
|
|
147
|
+
// writes the graph a single TLC worker does.
|
|
107
148
|
const isSequential =
|
|
108
149
|
count < 2 ||
|
|
109
150
|
typeof SharedArrayBuffer !== "function" ||
|
|
151
|
+
options.dump !== undefined ||
|
|
110
152
|
config.view !== undefined ||
|
|
111
153
|
config.postconditions.length > 0 ||
|
|
112
154
|
config.possible.length > 0;
|
|
@@ -124,17 +166,30 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
124
166
|
return bytes;
|
|
125
167
|
};
|
|
126
168
|
setStringOrder(getTlcStringOrder(options.source, config, loadModule));
|
|
169
|
+
setValueVersion(options.version);
|
|
127
170
|
const startupStrings = getRankedStringCount();
|
|
128
171
|
const specification = createEnvironment(config, {
|
|
129
172
|
source: options.source,
|
|
130
173
|
loadModule,
|
|
131
174
|
loadClass,
|
|
132
|
-
print:
|
|
175
|
+
print: (text) => {
|
|
176
|
+
printed.count++;
|
|
177
|
+
print(text);
|
|
178
|
+
},
|
|
133
179
|
files: { readFile: options.readFile, writeFile: options.writeFile },
|
|
180
|
+
isTool: options.isTool,
|
|
181
|
+
isTraceRecorded: options.isTraceRecorded,
|
|
182
|
+
isSanyReported: options.isSanyReported,
|
|
183
|
+
isWarningEnabled: options.isWarningEnabled,
|
|
184
|
+
version: options.version,
|
|
134
185
|
});
|
|
186
|
+
reportStartup(specification, config, report);
|
|
135
187
|
const environment = specification.environment;
|
|
136
|
-
const search = createSearch(
|
|
137
|
-
|
|
188
|
+
const search = createSearch(
|
|
189
|
+
config,
|
|
190
|
+
environment,
|
|
191
|
+
() => getTlcVariableOrder(options.source, loadModule),
|
|
192
|
+
report,
|
|
138
193
|
);
|
|
139
194
|
if (findAssumptionViolation(specification.assumptions, environment)) return fallBack();
|
|
140
195
|
if (
|
|
@@ -156,6 +211,7 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
156
211
|
distinctStates: 0,
|
|
157
212
|
queuedStates: 0,
|
|
158
213
|
depth: 0,
|
|
214
|
+
initialStates: undefined as InitialStates | undefined,
|
|
159
215
|
outDegrees: Array.from({ length: OUT_DEGREE_BUCKETS }, () => 0),
|
|
160
216
|
};
|
|
161
217
|
const tlcFingerprints: BigInt64Array[] = [];
|
|
@@ -180,6 +236,7 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
180
236
|
const seedInitialStates = (init: Expression) => {
|
|
181
237
|
const seeded: Value[][] = [];
|
|
182
238
|
for (const state of getInitialStates(init, environment, search.spec.scope)) {
|
|
239
|
+
reportInitialStatesProgress(statistics.generatedStates, report);
|
|
183
240
|
canonicalize(state);
|
|
184
241
|
statistics.generatedStates++;
|
|
185
242
|
writeStateFingerprint(search.getFingerprintState(state), fingerprint);
|
|
@@ -201,6 +258,7 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
201
258
|
return true;
|
|
202
259
|
};
|
|
203
260
|
// The sequential search reports a violation or a failed evaluation in the initial states.
|
|
261
|
+
report({ kind: "initial-states-started" });
|
|
204
262
|
try {
|
|
205
263
|
if (!seedInitialStates(search.spec.init)) return fallBack();
|
|
206
264
|
} catch (error) {
|
|
@@ -209,6 +267,11 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
209
267
|
}
|
|
210
268
|
if (getRankedStringCount() !== startupStrings) return fallBack();
|
|
211
269
|
statistics.depth = statistics.generatedStates === 0 ? 0 : 1;
|
|
270
|
+
statistics.initialStates = {
|
|
271
|
+
generated: statistics.generatedStates,
|
|
272
|
+
distinct: statistics.distinctStates,
|
|
273
|
+
};
|
|
274
|
+
report({ kind: "initial-states-computed", initialStates: statistics.initialStates });
|
|
212
275
|
if (statistics.distinctStates === 0) return createSuccess();
|
|
213
276
|
|
|
214
277
|
const reports: WorkerMessage[] = [];
|
|
@@ -250,6 +313,10 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
250
313
|
index,
|
|
251
314
|
ports,
|
|
252
315
|
seed,
|
|
316
|
+
isTool: options.isTool,
|
|
317
|
+
isTraceRecorded: options.isTraceRecorded,
|
|
318
|
+
isWarningEnabled: options.isWarningEnabled,
|
|
319
|
+
version: options.version,
|
|
253
320
|
fingerprints: shared.fingerprints,
|
|
254
321
|
requests,
|
|
255
322
|
remaining,
|