tla-ts 0.0.10-dev.b4a856304 → 0.0.10-dev.f16792fed
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/index.cjs +1 -1
- package/dist/index.d.cts +34 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +48 -48
- package/dist/prove.js +29 -29
- package/dist/run.cjs +40 -40
- package/dist/run.js +31 -31
- package/dist/transfer.cjs +36 -36
- package/dist/transfer.js +40 -40
- package/package.json +1 -1
- package/src/ast.ts +0 -5
- package/src/bags.ts +2 -5
- package/src/builtins.ts +1 -8
- package/src/check.ts +128 -193
- package/src/cli/options.ts +1 -1
- package/src/cli/run.ts +0 -2
- package/src/cli/runtime-invariants.ts +8 -7
- package/src/cli/shared.ts +0 -4
- package/src/cli/tlc-arguments.ts +24 -30
- package/src/cli/tlc-usage.ts +2 -3
- package/src/coverage.ts +3 -8
- package/src/evaluate.ts +26 -102
- package/src/java-hash.ts +7 -0
- package/src/java-overrides.ts +4 -9
- package/src/json-reader.ts +1 -2
- package/src/json.ts +4 -11
- package/src/levels.ts +7 -15
- package/src/lexer.ts +72 -83
- package/src/liveness-checker.ts +77 -106
- package/src/liveness.ts +10 -34
- package/src/parallel.ts +26 -33
- package/src/parser.ts +163 -226
- package/src/pcal/ast.ts +53 -65
- package/src/pcal/parse.ts +144 -191
- package/src/pcal/tokenize.ts +91 -115
- package/src/pcal/translate.ts +83 -98
- package/src/pcal/validate.ts +48 -50
- package/src/pretty-print.ts +6 -6
- package/src/randomization.ts +1 -4
- package/src/resolve.ts +12 -70
- package/src/runtime.ts +11 -18
- package/src/sany/builtins.ts +1 -3
- package/src/sany/generator.ts +74 -127
- package/src/sany/levels.ts +5 -9
- package/src/sany/lexer.ts +40 -44
- package/src/sany/linter.ts +0 -1
- package/src/sany/nodes.ts +4 -10
- package/src/search.ts +1 -1
- package/src/simulate.ts +50 -59
- package/src/spec-description.ts +23 -34
- package/src/standard-definitions.ts +0 -3
- package/src/standard-modules.ts +1 -12
- package/src/state-graph.ts +3 -15
- package/src/subexpressions.ts +38 -47
- package/src/successors.ts +14 -35
- package/src/symmetry.ts +4 -19
- package/src/tlc/fingerprint.ts +15 -21
- package/src/tlc/jar-data.ts +0 -1
- package/src/tlc/messages.ts +2 -21
- package/src/tlc/order.ts +22 -47
- package/src/tlc/random.ts +18 -30
- package/src/tlc/replay.ts +13 -33
- package/src/tlc/summary.ts +36 -45
- package/src/tlc/tlc-operators.ts +4 -14
- package/src/tlc/tlcext-operators.ts +11 -15
- package/src/tlc/trace-spec.ts +4 -9
- package/src/tlc/value-stream.ts +9 -13
- package/src/tlc/version.ts +0 -1
- package/src/values.ts +74 -186
package/src/cli/options.ts
CHANGED
|
@@ -60,7 +60,7 @@ export const defineCommand = (usage: string, specs: OptionSpec[]) => {
|
|
|
60
60
|
};
|
|
61
61
|
};
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
const CHECK_COMMAND = defineCommand("tla-ts <Spec.tla|Spec.cfg|spec.ts|glob>... {options}", [
|
|
64
64
|
{ flag: "-config <Spec.cfg>" },
|
|
65
65
|
{ flag: "-continue" },
|
|
66
66
|
{ flag: "-deadlock" },
|
package/src/cli/run.ts
CHANGED
|
@@ -5,8 +5,6 @@ import { runTlapm } from "./tlapm";
|
|
|
5
5
|
import { checkSpecs } from "./tlc";
|
|
6
6
|
import { exportXml, exportXml174 } from "./xml-exporter";
|
|
7
7
|
|
|
8
|
-
// Tools that run TLC with Java can run tla-ts in place of java, as in
|
|
9
|
-
// `tla-ts -DTLA-Library=lib -cp tla2tools.jar tlc2.TLC Spec`. Other JVM options are ignored.
|
|
10
8
|
const JAVA_MAIN_CLASSES = ["tlc2.TLC", "tla2sany.xml.XMLExporter"];
|
|
11
9
|
|
|
12
10
|
const TLA_LIBRARY_PROPERTY = "-DTLA-Library=";
|
|
@@ -50,7 +50,8 @@ const getDebuggerExpressionLevel = (
|
|
|
50
50
|
if (!(error instanceof TlaSyntaxError)) throw error;
|
|
51
51
|
throw createParsingFailure(`Syntax error while parsing breakpoint expression "${expression}"`);
|
|
52
52
|
}
|
|
53
|
-
|
|
53
|
+
let isSemanticCorrect = false;
|
|
54
|
+
let isLevelCorrect = false;
|
|
54
55
|
const specification = (() => {
|
|
55
56
|
try {
|
|
56
57
|
return generateSanySpecification(text, loadModule, {
|
|
@@ -58,13 +59,13 @@ const getDebuggerExpressionLevel = (
|
|
|
58
59
|
onModule: (module, messages) => {
|
|
59
60
|
const isCorrect = () => messages.every((message) => message.isWarning);
|
|
60
61
|
if (!isCorrect()) return;
|
|
61
|
-
const
|
|
62
|
+
const isLevelChecked = checkModuleLevels(module, {
|
|
62
63
|
messages,
|
|
63
64
|
isTlc174: version === "1.7.4",
|
|
64
65
|
});
|
|
65
66
|
if (module.name !== moduleName) return;
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
isSemanticCorrect = true;
|
|
68
|
+
isLevelCorrect = isLevelChecked && isCorrect();
|
|
68
69
|
},
|
|
69
70
|
});
|
|
70
71
|
} catch (error) {
|
|
@@ -72,8 +73,8 @@ const getDebuggerExpressionLevel = (
|
|
|
72
73
|
throw createFailure("Semantic error");
|
|
73
74
|
}
|
|
74
75
|
})();
|
|
75
|
-
if (!
|
|
76
|
-
if (!
|
|
76
|
+
if (!isSemanticCorrect) throw createFailure("Semantic error");
|
|
77
|
+
if (!isLevelCorrect) throw createFailure("Level-checking error");
|
|
77
78
|
const level = findDefinition(specification.root, name)?.level ?? CONSTANT_LEVEL;
|
|
78
79
|
if (level === TEMPORAL_LEVEL) {
|
|
79
80
|
throw createParsingFailure(
|
|
@@ -83,7 +84,7 @@ const getDebuggerExpressionLevel = (
|
|
|
83
84
|
return level;
|
|
84
85
|
};
|
|
85
86
|
|
|
86
|
-
// TLC puts a generated operator in a module that extends the root module
|
|
87
|
+
// Deviation from TLC: TLC puts a generated operator in a module that extends the root module.
|
|
87
88
|
export const addRuntimeInvariants = (
|
|
88
89
|
source: string,
|
|
89
90
|
root: ModuleNode,
|
package/src/cli/shared.ts
CHANGED
|
@@ -86,18 +86,14 @@ export const reportErrors = async (
|
|
|
86
86
|
}
|
|
87
87
|
};
|
|
88
88
|
|
|
89
|
-
// TLC 1.7.4 names the last file SimpleFilenameToStream looked for, and the directories it looked
|
|
90
|
-
// in, the jar's standard modules last.
|
|
91
89
|
export const printMissingFile174 = (path: string, libraries: string[], jar: string | undefined) =>
|
|
92
90
|
console.error(
|
|
93
91
|
`File does not exist: ${isAbsolute(path) ? path : `${process.cwd()}/${path}`} while looking in these directories: ${[...libraries, ...(jar === undefined ? [] : [getStandardModulesUrl(jar)])].join(", ")}`,
|
|
94
92
|
);
|
|
95
93
|
|
|
96
|
-
// SimpleFilenameToStream ends a library directory with a separator.
|
|
97
94
|
export const toLibraryPath = (directory: string) =>
|
|
98
95
|
directory.endsWith("/") ? directory : `${directory}/`;
|
|
99
96
|
|
|
100
|
-
// TLC 1.7.4's SANY reports each module it can't find as it looks for it.
|
|
101
97
|
export const reportMissingModules174 =
|
|
102
98
|
(loadModule: (name: string) => string | undefined, onMissing: (fileName: string) => void) =>
|
|
103
99
|
(name: string) => {
|
package/src/cli/tlc-arguments.ts
CHANGED
|
@@ -44,8 +44,6 @@ export interface RuntimeInvariant {
|
|
|
44
44
|
expression: string;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
// TLC prints a command line error as -tool asks only if -tool came first. An argument TLC reads
|
|
48
|
-
// past the end, or can't parse without catching the exception, ends TLC with that exception.
|
|
49
47
|
export interface TlcArgumentsError {
|
|
50
48
|
error: string;
|
|
51
49
|
isTool: boolean;
|
|
@@ -147,10 +145,9 @@ const LOADED_TRACES: Record<string, TraceFormat> = {
|
|
|
147
145
|
const isInRanges = (ranges: number[][], code: number) =>
|
|
148
146
|
ranges.some((range) => code >= range[0] && code <= range[1]);
|
|
149
147
|
|
|
150
|
-
|
|
151
|
-
const splitLikeJava = (text: string) => {
|
|
148
|
+
const splitLikeJava = (text: string, separator: string) => {
|
|
152
149
|
if (text === "") return [text];
|
|
153
|
-
const parts = text.split(
|
|
150
|
+
const parts = text.split(separator);
|
|
154
151
|
while (parts.at(-1) === "") parts.pop();
|
|
155
152
|
return parts;
|
|
156
153
|
};
|
|
@@ -238,7 +235,7 @@ const SWITCHES: Record<string, (parsed: TlcArguments) => void> = {
|
|
|
238
235
|
|
|
239
236
|
export const parseTlcArguments = (args: string[]): TlcArguments | TlcArgumentsError => {
|
|
240
237
|
const parsed = createDefaults();
|
|
241
|
-
|
|
238
|
+
let argumentIndex = 0;
|
|
242
239
|
const reject = (error: string): TlcArgumentsError => ({ error, isTool: parsed.isTool });
|
|
243
240
|
const getMissing = (): TlcArgumentsError => ({
|
|
244
241
|
error: `java.lang.ArrayIndexOutOfBoundsException: Index ${args.length} out of bounds for length ${args.length}`,
|
|
@@ -247,20 +244,19 @@ export const parseTlcArguments = (args: string[]): TlcArguments | TlcArgumentsEr
|
|
|
247
244
|
});
|
|
248
245
|
const suppressedCodes: MessageCodes = { tlc: [], sany: [] };
|
|
249
246
|
const errorCodes: MessageCodes = { tlc: [], sany: [] };
|
|
250
|
-
const peek = () => args[
|
|
251
|
-
const take = () => args[
|
|
247
|
+
const peek = () => args[argumentIndex];
|
|
248
|
+
const take = () => args[argumentIndex++];
|
|
252
249
|
const readInteger = (bits: 32 | 64, missing: string, malformed: string) => {
|
|
253
250
|
const text = peek();
|
|
254
251
|
if (text === undefined) return reject(missing);
|
|
255
252
|
const value = parseJavaInteger(text, bits);
|
|
256
253
|
if (value === undefined) return reject(`${malformed} But encountered ${text}`);
|
|
257
|
-
|
|
254
|
+
argumentIndex++;
|
|
258
255
|
return value;
|
|
259
256
|
};
|
|
260
|
-
while (
|
|
257
|
+
while (argumentIndex < args.length) {
|
|
261
258
|
const flag = take();
|
|
262
|
-
|
|
263
|
-
if (isSwitch) {
|
|
259
|
+
if (Object.hasOwn(SWITCHES, flag)) {
|
|
264
260
|
SWITCHES[flag](parsed);
|
|
265
261
|
continue;
|
|
266
262
|
}
|
|
@@ -273,7 +269,7 @@ export const parseTlcArguments = (args: string[]): TlcArguments | TlcArgumentsEr
|
|
|
273
269
|
) {
|
|
274
270
|
continue;
|
|
275
271
|
}
|
|
276
|
-
|
|
272
|
+
argumentIndex++;
|
|
277
273
|
const hasFile = options.split(",").some((option) => option.startsWith("file="));
|
|
278
274
|
parsed.scheduler = options.split(",").includes("sched=rl")
|
|
279
275
|
? "rl"
|
|
@@ -304,21 +300,22 @@ export const parseTlcArguments = (args: string[]): TlcArguments | TlcArgumentsEr
|
|
|
304
300
|
return reject(`Error: ${flag} requires a comma-separated list of message codes.`);
|
|
305
301
|
}
|
|
306
302
|
const codes = flag === "-suppressMessages" ? suppressedCodes : errorCodes;
|
|
307
|
-
for (const item of splitLikeJava(text)) {
|
|
303
|
+
for (const item of splitLikeJava(text, ",")) {
|
|
308
304
|
const trimmed = item.replace(/^[^!-\uffff]+|[^!-\uffff]+$/g, "");
|
|
309
305
|
const parsedCode = parseJavaInteger(trimmed, 32);
|
|
310
306
|
if (parsedCode === undefined) return reject(`Error: For input string: "${trimmed}"`);
|
|
311
307
|
const code = Number(parsedCode);
|
|
312
308
|
if (isInRanges(TLC_MESSAGE_CODES, code)) {
|
|
313
309
|
codes.tlc.push(code);
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
}
|
|
318
|
-
codes.sany.push(code);
|
|
319
|
-
} else {
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
if (!SANY_WARNING_CODES.has(code) && !isInRanges(SANY_ERROR_CODES, code)) {
|
|
320
313
|
return reject(`Error: unknown message code: ${code}`);
|
|
321
314
|
}
|
|
315
|
+
if (codes === suppressedCodes && !SANY_WARNING_CODES.has(code)) {
|
|
316
|
+
return reject(`Error: code ${code} is an error and cannot be suppressed.`);
|
|
317
|
+
}
|
|
318
|
+
codes.sany.push(code);
|
|
322
319
|
}
|
|
323
320
|
continue;
|
|
324
321
|
}
|
|
@@ -370,13 +367,13 @@ export const parseTlcArguments = (args: string[]): TlcArguments | TlcArgumentsEr
|
|
|
370
367
|
options.includes(option),
|
|
371
368
|
)
|
|
372
369
|
) {
|
|
373
|
-
|
|
370
|
+
argumentIndex++;
|
|
374
371
|
}
|
|
375
372
|
continue;
|
|
376
373
|
}
|
|
377
374
|
if (flag === "-generateSpecTE") {
|
|
378
375
|
parsed.isTraceSpecForced = true;
|
|
379
|
-
if (peek() === "nomonolith")
|
|
376
|
+
if (peek() === "nomonolith") argumentIndex++;
|
|
380
377
|
continue;
|
|
381
378
|
}
|
|
382
379
|
if (flag === "-noGenerateSpecTE" || flag.toLowerCase() === "-note") {
|
|
@@ -410,17 +407,16 @@ export const parseTlcArguments = (args: string[]): TlcArguments | TlcArgumentsEr
|
|
|
410
407
|
`Trying to instantiate a custom IStateWriter implementation ${format.replaceAll("class,", "")}.`,
|
|
411
408
|
);
|
|
412
409
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
cursor.index += arity;
|
|
410
|
+
const arity = format?.startsWith("dot") && argumentIndex + 1 < args.length ? 2 : 1;
|
|
411
|
+
parsed.dump = args.slice(argumentIndex, argumentIndex + arity);
|
|
412
|
+
argumentIndex += arity;
|
|
417
413
|
if (parsed.dump.length === 0)
|
|
418
414
|
return reject("Error: A file name for dumping states required.");
|
|
419
415
|
continue;
|
|
420
416
|
}
|
|
421
417
|
if (flag.toLowerCase() === "-loadtrace" || flag.toLowerCase() === "-dumptrace") {
|
|
422
418
|
const name = flag.toLowerCase() === "-loadtrace" ? "-loadTrace" : "-dumpTrace";
|
|
423
|
-
if (
|
|
419
|
+
if (argumentIndex + 1 >= args.length) {
|
|
424
420
|
return reject(
|
|
425
421
|
name === "-loadTrace"
|
|
426
422
|
? "Error: A format and a file name for loading traces required."
|
|
@@ -449,9 +445,7 @@ export const parseTlcArguments = (args: string[]): TlcArguments | TlcArgumentsEr
|
|
|
449
445
|
if (!target.includes("!")) {
|
|
450
446
|
return reject(`Module!Operator for postCondition required. Encountered: ${target}`);
|
|
451
447
|
}
|
|
452
|
-
|
|
453
|
-
const parts = target.split("!");
|
|
454
|
-
while (parts.length > 0 && parts[parts.length - 1] === "") parts.pop();
|
|
448
|
+
const parts = splitLikeJava(target, "!");
|
|
455
449
|
if (parts.length !== 2) {
|
|
456
450
|
return reject(
|
|
457
451
|
`Module!Operator for postCondition must be of the form module!operator. Encountered: ${target}`,
|
package/src/cli/tlc-usage.ts
CHANGED
|
@@ -322,7 +322,6 @@ const getVariantSynopsis = (variant: UsageArgument[]) => {
|
|
|
322
322
|
].join(" ");
|
|
323
323
|
};
|
|
324
324
|
|
|
325
|
-
// TLC names its build by its UTC timestamp, or by the current time when it has no manifest.
|
|
326
325
|
const getBuildVersion = () =>
|
|
327
326
|
new Date()
|
|
328
327
|
.toISOString()
|
|
@@ -330,8 +329,8 @@ const getBuildVersion = () =>
|
|
|
330
329
|
|
|
331
330
|
export const getTlcUsage = () => {
|
|
332
331
|
const options = [
|
|
333
|
-
...new Map(
|
|
334
|
-
COMMAND_VARIANTS.flat().map((argument) => [argument.name, argument]
|
|
332
|
+
...new Map<string, UsageArgument>(
|
|
333
|
+
COMMAND_VARIANTS.flat().map((argument) => [argument.name, argument]),
|
|
335
334
|
).values(),
|
|
336
335
|
]
|
|
337
336
|
.sort(compareNames)
|
package/src/coverage.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from "./ast";
|
|
9
9
|
import { formatRange } from "./errors";
|
|
10
10
|
import type { Environment, Scope } from "./evaluate";
|
|
11
|
+
import { getJavaHashCode } from "./java-hash";
|
|
11
12
|
import { getTlcFingerprint } from "./tlc/fingerprint";
|
|
12
13
|
import type { Value } from "./values";
|
|
13
14
|
|
|
@@ -204,12 +205,6 @@ const getStartRange = (location: SourceLocation, last: SourceRange | undefined)
|
|
|
204
205
|
end: last.end,
|
|
205
206
|
};
|
|
206
207
|
|
|
207
|
-
const getJavaHashCode = (text: string) =>
|
|
208
|
-
Array.from({ length: text.length }, (_value, index) => text.charCodeAt(index)).reduce(
|
|
209
|
-
(hash, code) => (Math.imul(hash, 31) + code) | 0,
|
|
210
|
-
0,
|
|
211
|
-
) & 0x7fffffff;
|
|
212
|
-
|
|
213
208
|
const getHashtableOrder = (definitions: Definition[]) => {
|
|
214
209
|
let buckets = Array.from({ length: 11 }, (): Definition[] => []);
|
|
215
210
|
definitions.forEach((definition, count) => {
|
|
@@ -217,12 +212,12 @@ const getHashtableOrder = (definitions: Definition[]) => {
|
|
|
217
212
|
const grown = Array.from({ length: buckets.length * 2 + 1 }, (): Definition[] => []);
|
|
218
213
|
for (let index = buckets.length - 1; index >= 0; index--) {
|
|
219
214
|
buckets[index].forEach((entry) =>
|
|
220
|
-
grown[getJavaHashCode(entry.name) % grown.length].unshift(entry),
|
|
215
|
+
grown[(getJavaHashCode(entry.name) & 0x7fffffff) % grown.length].unshift(entry),
|
|
221
216
|
);
|
|
222
217
|
}
|
|
223
218
|
buckets = grown;
|
|
224
219
|
}
|
|
225
|
-
buckets[getJavaHashCode(definition.name) % buckets.length].unshift(definition);
|
|
220
|
+
buckets[(getJavaHashCode(definition.name) & 0x7fffffff) % buckets.length].unshift(definition);
|
|
226
221
|
});
|
|
227
222
|
return buckets.toReversed().flat();
|
|
228
223
|
};
|