tla-ts 0.0.8-dev.d9bffda → 0.0.9-dev.0dd11f695
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 +30 -0
- package/dist/compile.cjs +23 -0
- package/dist/compile.js +23 -0
- package/dist/deciders.cjs +15 -15
- package/dist/deciders.js +40 -40
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +80 -10
- package/dist/index.d.ts +80 -10
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove-worker.cjs +1 -1
- package/dist/prove-worker.js +1 -1
- package/dist/prove.cjs +116 -36
- package/dist/prove.js +116 -36
- package/dist/run.cjs +143 -31
- package/dist/run.js +143 -31
- package/dist/tlapm.cjs +2 -2
- package/dist/tlapm.js +1 -1
- package/dist/transfer.cjs +128 -103
- package/dist/transfer.js +128 -103
- package/dist/worker.cjs +7 -7
- package/dist/worker.js +7 -7
- package/package.json +3 -1
- package/src/ast.ts +7 -21
- package/src/bags.ts +99 -99
- package/src/builtins.ts +44 -75
- package/src/bundled-modules.ts +1 -8
- package/src/check.ts +605 -311
- package/src/cli/options.ts +12 -3
- package/src/cli/run.ts +2 -2
- package/src/cli/runtime-invariants.ts +135 -0
- package/src/cli/shared.ts +20 -9
- package/src/cli/tlc-arguments.ts +646 -0
- package/src/cli/tlc-usage.ts +362 -0
- package/src/cli/tlc.ts +571 -185
- package/src/cli/typescript.ts +26 -0
- package/src/cli/xml-exporter.ts +4 -10
- package/src/codegen.ts +190 -46
- package/src/config.ts +101 -68
- package/src/coverage.ts +855 -0
- package/src/dependencies.ts +20 -28
- package/src/dfid.ts +636 -0
- package/src/environment.ts +266 -98
- package/src/errors.ts +142 -45
- package/src/evaluate.ts +632 -298
- package/src/exit-codes.ts +37 -1
- package/src/index.ts +3 -0
- package/src/instances.ts +85 -9
- package/src/java-overrides.ts +2 -12
- package/src/json-reader.ts +456 -0
- package/src/json.ts +262 -139
- package/src/levels.ts +2 -3
- package/src/lexer.ts +17 -26
- package/src/liveness-checker.ts +10 -18
- package/src/liveness.ts +121 -49
- package/src/parallel-worker.ts +14 -10
- package/src/parallel.ts +41 -17
- package/src/parser.ts +436 -90
- package/src/pcal/ast.ts +7 -28
- package/src/pcal/parse.ts +11 -39
- package/src/pcal/tokenize.ts +4 -20
- package/src/pcal/translate.ts +10 -42
- package/src/pcal/validate.ts +3 -21
- package/src/pretty-print.ts +1 -2
- package/src/prover/smt/solver/solver.ts +31 -27
- package/src/randomization.ts +84 -35
- package/src/resolve.ts +18 -60
- package/src/runtime.ts +11 -4
- package/src/sany/builtins.ts +3 -4
- package/src/sany/generator.ts +128 -176
- package/src/sany/levels.ts +6 -30
- package/src/sany/lexer.ts +7 -23
- package/src/sany/linter.ts +31 -29
- package/src/sany/modules.ts +1 -5
- package/src/sany/nodes.ts +4 -28
- package/src/sany/parse-error.ts +44 -100
- package/src/sany/report.ts +25 -40
- package/src/sany/selectors.ts +8 -22
- package/src/sany/source.ts +8 -15
- package/src/sany/xml.ts +11 -42
- package/src/search.ts +547 -144
- package/src/simulate.ts +694 -0
- package/src/spec-description.ts +166 -48
- package/src/standard-definitions.ts +2 -3
- package/src/standard-modules.ts +264 -68
- package/src/state-graph.ts +51 -18
- package/src/subexpressions.ts +31 -5
- package/src/successors.ts +267 -77
- package/src/symmetry.ts +31 -8
- package/src/tableau.ts +1 -2
- package/src/tlc/fingerprint.ts +183 -61
- package/src/tlc/jar-data.ts +113 -6
- package/src/tlc/messages.ts +122 -37
- package/src/tlc/order.ts +33 -38
- package/src/tlc/random.ts +16 -16
- package/src/tlc/replay.ts +563 -211
- package/src/tlc/summary.ts +2 -4
- package/src/tlc/tlc-operators.ts +81 -36
- package/src/tlc/tlcext-operators.ts +138 -117
- package/src/tlc/trace-spec.ts +273 -0
- package/src/tlc/value-stream.ts +143 -0
- package/src/tlc/version.ts +2 -4
- package/src/typescript/actions.ts +494 -0
- package/src/typescript/collections.ts +615 -0
- package/src/typescript/compile.ts +70 -0
- package/src/typescript/context.ts +106 -0
- package/src/typescript/emit.ts +122 -0
- package/src/typescript/expressions.ts +508 -0
- package/src/typescript/formula.ts +160 -0
- package/src/typescript/functions.ts +295 -0
- package/src/typescript/model.ts +164 -0
- package/src/typescript/names.ts +116 -0
- package/src/typescript/program.ts +51 -0
- package/src/typescript/properties.ts +148 -0
- package/src/typescript/scope.ts +117 -0
- package/src/typescript/steps.ts +175 -0
- package/src/typescript/types.ts +178 -0
- package/src/values.ts +832 -255
package/src/exit-codes.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { LivenessChecker } from "./liveness-checker";
|
|
2
2
|
|
|
3
|
-
// TLC's exit statuses, from EC.ExitStatus.
|
|
4
3
|
export const EXIT_STATUS = {
|
|
5
4
|
success: 0,
|
|
6
5
|
assumptionViolation: 10,
|
|
@@ -16,6 +15,43 @@ export const EXIT_STATUS = {
|
|
|
16
15
|
error: 255,
|
|
17
16
|
} as const;
|
|
18
17
|
|
|
18
|
+
const MESSAGE_EXIT_STATUSES = new Map<number, number>([
|
|
19
|
+
...[
|
|
20
|
+
...Array.from({ length: 24 }, (_, index) => 2222 + index),
|
|
21
|
+
2272,
|
|
22
|
+
2273,
|
|
23
|
+
2274,
|
|
24
|
+
2280,
|
|
25
|
+
2281,
|
|
26
|
+
...Array.from({ length: 7 }, (_, index) => 5001 + index),
|
|
27
|
+
].map((code): [number, number] => [code, EXIT_STATUS.configParseError]),
|
|
28
|
+
[2253, EXIT_STATUS.livenessEvaluationFailure],
|
|
29
|
+
[2109, EXIT_STATUS.specEvaluationFailure],
|
|
30
|
+
[2115, EXIT_STATUS.specEvaluationFailure],
|
|
31
|
+
[2103, EXIT_STATUS.specEvaluationFailure],
|
|
32
|
+
[2147, EXIT_STATUS.specEvaluationFailure],
|
|
33
|
+
[2111, EXIT_STATUS.safetyEvaluationFailure],
|
|
34
|
+
[2146, EXIT_STATUS.safetyEvaluationFailure],
|
|
35
|
+
[2107, EXIT_STATUS.safetyViolation],
|
|
36
|
+
[2110, EXIT_STATUS.safetyViolation],
|
|
37
|
+
[2112, EXIT_STATUS.livenessViolation],
|
|
38
|
+
[2113, EXIT_STATUS.livenessViolation],
|
|
39
|
+
[2116, EXIT_STATUS.livenessViolation],
|
|
40
|
+
[2108, EXIT_STATUS.livenessViolation],
|
|
41
|
+
[2114, EXIT_STATUS.deadlock],
|
|
42
|
+
[2104, EXIT_STATUS.assumptionViolation],
|
|
43
|
+
[2105, EXIT_STATUS.assumptionViolation],
|
|
44
|
+
[2404, EXIT_STATUS.assumptionViolation],
|
|
45
|
+
[2405, EXIT_STATUS.assumptionViolation],
|
|
46
|
+
[2780, EXIT_STATUS.assumptionViolation],
|
|
47
|
+
[2132, EXIT_STATUS.assertViolation],
|
|
48
|
+
[2171, EXIT_STATUS.specParseError],
|
|
49
|
+
[3002, EXIT_STATUS.specParseError],
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
export const getMessageExitStatus = (code: number) =>
|
|
53
|
+
MESSAGE_EXIT_STATUSES.get(code) ?? EXIT_STATUS.error;
|
|
54
|
+
|
|
19
55
|
const exitCodes = new WeakMap<Error, number>();
|
|
20
56
|
|
|
21
57
|
// The innermost site that knows TLC's exit status for an error sets it first and wins.
|
package/src/index.ts
CHANGED
|
@@ -4,10 +4,13 @@ export type {
|
|
|
4
4
|
CheckResult,
|
|
5
5
|
CheckStatus,
|
|
6
6
|
EvaluationFailure,
|
|
7
|
+
ModuleOperator,
|
|
8
|
+
TraceSpecOptions,
|
|
7
9
|
TraceStep,
|
|
8
10
|
Violation,
|
|
9
11
|
} from "./check";
|
|
10
12
|
export { parseConfig } from "./config";
|
|
13
|
+
export type { CoverageReport } from "./coverage";
|
|
11
14
|
export type { ConfigValue, ConstantAssignment, ModelConfig, Substitution } from "./config";
|
|
12
15
|
export {
|
|
13
16
|
TlaConfigError,
|
package/src/instances.ts
CHANGED
|
@@ -14,12 +14,18 @@ import {
|
|
|
14
14
|
import { TlaSyntaxError } from "./errors";
|
|
15
15
|
import { getArity, getBoundNames, getPatternNames, isBefore, LOCAL_RESOLUTION } from "./resolve";
|
|
16
16
|
|
|
17
|
-
export const substitutedExpressions = new WeakSet<Expression>();
|
|
18
|
-
|
|
19
|
-
// Applications inside an instance with substitutions or parameters, which TLC evaluates in a
|
|
20
|
-
// context that binds them.
|
|
21
17
|
export const contextualApplications = new WeakSet<Expression>();
|
|
22
18
|
|
|
19
|
+
export const substitutionFrames = new WeakMap<Expression, Expression[]>();
|
|
20
|
+
|
|
21
|
+
export const withSubstitutionFrames = (expression: Expression, frames: Expression[]) => {
|
|
22
|
+
if (frames.length === 0) return expression;
|
|
23
|
+
const copy = { ...expression };
|
|
24
|
+
if (contextualApplications.has(expression)) contextualApplications.add(copy);
|
|
25
|
+
substitutionFrames.set(copy, [...frames, ...(substitutionFrames.get(expression) ?? [])]);
|
|
26
|
+
return copy;
|
|
27
|
+
};
|
|
28
|
+
|
|
23
29
|
export const renameLocals = (
|
|
24
30
|
expression: Expression,
|
|
25
31
|
names: Map<string, string>,
|
|
@@ -38,6 +44,9 @@ export const renameLocals = (
|
|
|
38
44
|
if (mapped.kind === "Apply" && isLocallyResolved(mapped) && !bound.has(mapped.operator)) {
|
|
39
45
|
return { ...mapped, operator: names.get(mapped.operator) ?? mapped.operator };
|
|
40
46
|
}
|
|
47
|
+
if (mapped.kind === "OperatorReference" && !bound.has(mapped.operator)) {
|
|
48
|
+
return { ...mapped, operator: names.get(mapped.operator) ?? mapped.operator };
|
|
49
|
+
}
|
|
41
50
|
return mapped;
|
|
42
51
|
};
|
|
43
52
|
|
|
@@ -224,9 +233,12 @@ interface Instantiation {
|
|
|
224
233
|
substitutions: Map<string, Expression>;
|
|
225
234
|
variables: Set<string>;
|
|
226
235
|
getDefinition: (key: string) => Definition | undefined;
|
|
236
|
+
// A definition of the instantiating module that a substitution names.
|
|
237
|
+
getOuterDefinition: (name: string) => Definition | undefined;
|
|
227
238
|
isParameterized: (key: string) => boolean;
|
|
228
239
|
addDefinition: (source: string, name: string, create: (key: string) => Definition) => string;
|
|
229
240
|
createName: (name: string) => string;
|
|
241
|
+
frame?: Expression;
|
|
230
242
|
}
|
|
231
243
|
|
|
232
244
|
// LAMBDA is a keyword, so no name bound inside the instance can capture it.
|
|
@@ -240,8 +252,40 @@ interface Rewrite {
|
|
|
240
252
|
copies: Map<string, string>;
|
|
241
253
|
mode: RewriteMode;
|
|
242
254
|
modes: Map<RewriteMode, Rewrite>;
|
|
255
|
+
// The substitutions an operator's copy reads, which it binds once, as TLC binds each to a lazy
|
|
256
|
+
// value when it evaluates the operator's body.
|
|
257
|
+
bindings?: Map<string, Expression>;
|
|
243
258
|
}
|
|
244
259
|
|
|
260
|
+
const getSubstitutionName = (name: string) => `${name}@SUBSTITUTION`;
|
|
261
|
+
|
|
262
|
+
const isVariableAlias = (expression: Expression): boolean =>
|
|
263
|
+
expression.kind === "Identifier" ||
|
|
264
|
+
(expression.kind === "Tuple" && expression.elements.every(isVariableAlias));
|
|
265
|
+
|
|
266
|
+
// A name, or a tuple of names, stays in place, so a step can assign it or leave it unchanged as
|
|
267
|
+
// TLC does through its lazy value. An operator or a literal costs nothing to evaluate again. A name
|
|
268
|
+
// of a definition that isn't such an alias is bound once.
|
|
269
|
+
const isBoundOnce = (replacement: Expression, instantiation: Instantiation) => {
|
|
270
|
+
if (replacement.kind !== "Identifier") {
|
|
271
|
+
return (
|
|
272
|
+
!isVariableAlias(replacement) &&
|
|
273
|
+
replacement.kind !== "OperatorReference" &&
|
|
274
|
+
replacement.kind !== "Lambda" &&
|
|
275
|
+
replacement.kind !== "Number" &&
|
|
276
|
+
replacement.kind !== "String"
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
const definition = isLocallyResolved(replacement)
|
|
280
|
+
? undefined
|
|
281
|
+
: instantiation.getOuterDefinition(replacement.name);
|
|
282
|
+
return (
|
|
283
|
+
definition?.kind === "Operator" &&
|
|
284
|
+
definition.params.length === 0 &&
|
|
285
|
+
!isVariableAlias(definition.body)
|
|
286
|
+
);
|
|
287
|
+
};
|
|
288
|
+
|
|
245
289
|
const getFreeNames = (expression: Expression, bound = new Set<string>()): string[] => {
|
|
246
290
|
const name =
|
|
247
291
|
expression.kind === "Identifier"
|
|
@@ -515,9 +559,14 @@ const substitute = (
|
|
|
515
559
|
if (enabled) return enabled;
|
|
516
560
|
if (expression.kind === "Identifier" && isFree(expression.name)) {
|
|
517
561
|
const replacement = instantiation.substitutions.get(expression.name);
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
return replacement;
|
|
562
|
+
const bindings = rewrite.bindings;
|
|
563
|
+
if (replacement && (bindings === undefined || !isBoundOnce(replacement, instantiation))) {
|
|
564
|
+
return withSubstitutionFrames(replacement, [expression]);
|
|
565
|
+
}
|
|
566
|
+
if (replacement && bindings) {
|
|
567
|
+
const name = getSubstitutionName(expression.name);
|
|
568
|
+
bindings.set(name, replacement);
|
|
569
|
+
return createLocalIdentifier(name, expression.location);
|
|
521
570
|
}
|
|
522
571
|
const copy = getCopy(rewrite, expression.name);
|
|
523
572
|
if (copy === undefined) return expression;
|
|
@@ -649,13 +698,40 @@ const copyDefinition = (rewrite: Rewrite, key: string): string => {
|
|
|
649
698
|
return instantiation.addDefinition(key, definition.name, (copyKey) => {
|
|
650
699
|
rewrite.copies.set(key, copyKey);
|
|
651
700
|
const rename = createRenamer(rewrite);
|
|
701
|
+
const bindings = new Map<string, Expression>();
|
|
702
|
+
const bodyRewrite =
|
|
703
|
+
definition.kind === "Operator" && rewrite.mode === "Normal"
|
|
704
|
+
? { ...rewrite, bindings }
|
|
705
|
+
: rewrite;
|
|
652
706
|
const mapped = renameParams(
|
|
653
707
|
mapDefinition(definition, (child, bound) =>
|
|
654
|
-
substitute(child,
|
|
708
|
+
substitute(child, bodyRewrite, bindNames(new Map(), bound, rename)),
|
|
655
709
|
),
|
|
656
710
|
rename,
|
|
657
711
|
);
|
|
658
|
-
|
|
712
|
+
const body: Expression =
|
|
713
|
+
mapped.kind !== "Operator" || bindings.size === 0
|
|
714
|
+
? mapped.body
|
|
715
|
+
: {
|
|
716
|
+
kind: "Let",
|
|
717
|
+
definitions: [...bindings].map(([name, replacement]): Definition => ({
|
|
718
|
+
kind: "Operator",
|
|
719
|
+
name,
|
|
720
|
+
params: [],
|
|
721
|
+
body: replacement,
|
|
722
|
+
isLocal: true,
|
|
723
|
+
isRecursive: false,
|
|
724
|
+
location: replacement.location,
|
|
725
|
+
})),
|
|
726
|
+
body: mapped.body,
|
|
727
|
+
// TLC has no such LET, so the call stack it prints has no position for it.
|
|
728
|
+
location: { line: mapped.body.location.line, column: mapped.body.location.column },
|
|
729
|
+
};
|
|
730
|
+
const frame = instantiation.frame;
|
|
731
|
+
// TLC's call stack holds the SubstInNode an instance puts around each definition it copies.
|
|
732
|
+
if (frame)
|
|
733
|
+
substitutionFrames.set(body, [frame, ...(substitutionFrames.get(definition.body) ?? [])]);
|
|
734
|
+
return withInstanceParams({ ...mapped, body }, instantiation.params, definition.location);
|
|
659
735
|
});
|
|
660
736
|
};
|
|
661
737
|
|
package/src/java-overrides.ts
CHANGED
|
@@ -12,13 +12,10 @@ interface PoolEntry {
|
|
|
12
12
|
interface JavaMethod {
|
|
13
13
|
name: string;
|
|
14
14
|
arity: number;
|
|
15
|
-
// Method#toString, which TLC prints as the signature of an override.
|
|
16
15
|
signature: string;
|
|
17
16
|
code: Uint8Array | undefined;
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
// A public static method of the class named after a module, which TLC reports as it loads the
|
|
21
|
-
// class, with whether it overrides an operator.
|
|
22
19
|
export interface JavaOverride {
|
|
23
20
|
module: string;
|
|
24
21
|
operator: string;
|
|
@@ -53,7 +50,6 @@ const POOL_TAG = {
|
|
|
53
50
|
package: 20,
|
|
54
51
|
};
|
|
55
52
|
|
|
56
|
-
// The JVM opcodes that an override returning a constant value uses.
|
|
57
53
|
const OPCODE = {
|
|
58
54
|
iconstM1: 0x02,
|
|
59
55
|
iconst0: 0x03,
|
|
@@ -123,8 +119,8 @@ const getClassName = (pool: PoolEntry[], index: number) => pool[pool[index].firs
|
|
|
123
119
|
const getJavaClassName = (pool: PoolEntry[], index: number) =>
|
|
124
120
|
getClassName(pool, index).replaceAll("/", ".");
|
|
125
121
|
|
|
126
|
-
//
|
|
127
|
-
//
|
|
122
|
+
// In the order of the class file. Class#getDeclaredMethods orders them by where HotSpot allocated
|
|
123
|
+
// the symbols of their names.
|
|
128
124
|
const readClassFile = (bytes: Uint8Array) => {
|
|
129
125
|
const reader = createReader(bytes);
|
|
130
126
|
if (reader.readUint32() !== CLASS_MAGIC)
|
|
@@ -217,9 +213,6 @@ const getMemberReference = (pool: PoolEntry[], index: number) => {
|
|
|
217
213
|
};
|
|
218
214
|
};
|
|
219
215
|
|
|
220
|
-
// Runs the bytecode of an override that returns a constant TLC value, such as
|
|
221
|
-
// BoolValue.ValTrue, IntValue.gen(3), or new StringValue("a"), and returns that value as a
|
|
222
|
-
// literal.
|
|
223
216
|
const getReturnedLiteral = (
|
|
224
217
|
method: JavaMethod,
|
|
225
218
|
pool: PoolEntry[],
|
|
@@ -316,9 +309,6 @@ const getReturnedLiteral = (
|
|
|
316
309
|
throw createUnsupportedError();
|
|
317
310
|
};
|
|
318
311
|
|
|
319
|
-
// TLC loads a class named after each module and replaces each operator of the module that the
|
|
320
|
-
// root module sees with the public static method of the same name and arity. It reports whether
|
|
321
|
-
// each method matched an operator.
|
|
322
312
|
export const overrideDefinitions = (
|
|
323
313
|
module: Module,
|
|
324
314
|
bytes: Uint8Array | undefined,
|