tla-ts 0.0.3-dev.3cf2ad0 → 0.0.3-dev.45d0f50
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/index.cjs +1 -1
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- 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 +17 -16
- package/dist/run-cli.js +6 -5
- package/dist/transfer.cjs +27 -15
- package/dist/transfer.js +27 -15
- package/package.json +1 -1
- package/src/ast.ts +90 -0
- package/src/check.ts +264 -78
- package/src/cli-options.ts +11 -5
- package/src/codegen.ts +15 -22
- package/src/dependencies.ts +2 -2
- package/src/environment.ts +94 -24
- package/src/errors.ts +18 -2
- package/src/evaluate.ts +122 -147
- package/src/exit-codes.ts +21 -43
- package/src/instances.ts +15 -14
- package/src/levels.ts +8 -8
- package/src/lexer.ts +5 -1
- package/src/live-check.ts +770 -0
- package/src/liveness.ts +54 -535
- package/src/parallel-worker.ts +7 -3
- package/src/parallel.ts +20 -4
- package/src/parser.ts +12 -1
- package/src/resolve.ts +16 -15
- package/src/run-cli.ts +58 -13
- package/src/runtime.ts +3 -1
- package/src/spec-description.ts +18 -6
- package/src/standard-modules.ts +2 -7
- package/src/state-graph.ts +157 -0
- package/src/subexpressions.ts +10 -10
- package/src/successors.ts +79 -15
- package/src/symmetry.ts +25 -7
- package/src/tableau.ts +51 -24
- package/src/tlc-ext.ts +29 -12
- package/src/tlc-module.ts +14 -33
- package/src/tlc-modules.ts +4 -0
- package/src/tlc-order.ts +25 -7
- package/src/tlc-random.ts +9 -6
- package/src/tlc-summary.ts +20 -5
- package/src/values.ts +121 -20
package/src/codegen.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { TlaEvaluationError } from "./errors";
|
|
1
|
+
import { getChildren, isLocallyResolved, type Expression } from "./ast";
|
|
3
2
|
import {
|
|
4
|
-
describeLocation,
|
|
5
3
|
bindValue,
|
|
6
4
|
expectBoolean,
|
|
7
5
|
findGlobalName,
|
|
8
|
-
getChildren,
|
|
9
6
|
getEnumeratedElements,
|
|
10
7
|
getConditionError,
|
|
11
8
|
getConjunctError,
|
|
@@ -13,20 +10,24 @@ import {
|
|
|
13
10
|
getSubsetOperator,
|
|
14
11
|
getEvaluator,
|
|
15
12
|
getFieldError,
|
|
13
|
+
getNonFunctionError,
|
|
14
|
+
getNonRecordError,
|
|
16
15
|
isClosedConstant,
|
|
17
|
-
isLocallyResolved,
|
|
18
16
|
isTlcInteger,
|
|
19
17
|
isValueArgument,
|
|
20
18
|
isWorthCaching,
|
|
21
19
|
keepLazy,
|
|
22
20
|
resolveGlobalOperator,
|
|
21
|
+
createPrimeOutsideActionError,
|
|
22
|
+
createUnassignedError,
|
|
23
|
+
getSortedFields,
|
|
24
|
+
hasDuplicateFields,
|
|
23
25
|
type Context,
|
|
24
26
|
type Environment,
|
|
25
27
|
type Evaluator,
|
|
26
28
|
} from "./evaluate";
|
|
27
29
|
import {
|
|
28
30
|
applyFunction,
|
|
29
|
-
compareValues,
|
|
30
31
|
createEnumeratedSet,
|
|
31
32
|
createSortedFunction,
|
|
32
33
|
createTuple,
|
|
@@ -84,14 +85,10 @@ const createRuntime = () => ({
|
|
|
84
85
|
equal: valuesEqual,
|
|
85
86
|
enumerate: getEnumeratedElements,
|
|
86
87
|
unassigned: (name: string, expression: Expression): never => {
|
|
87
|
-
throw
|
|
88
|
-
`The variable ${name} is not assigned at ${describeLocation(expression)}`,
|
|
89
|
-
);
|
|
88
|
+
throw createUnassignedError(name, expression);
|
|
90
89
|
},
|
|
91
90
|
primeOutsideAction: (expression: Expression): never => {
|
|
92
|
-
throw
|
|
93
|
-
`A primed expression appears outside an action at ${describeLocation(expression)}`,
|
|
94
|
-
);
|
|
91
|
+
throw createPrimeOutsideActionError(expression);
|
|
95
92
|
},
|
|
96
93
|
prime: (context: Context): Context => ({
|
|
97
94
|
environment: context.environment,
|
|
@@ -255,20 +252,16 @@ const generateExpression = (generator: Generator, expression: Expression, frame:
|
|
|
255
252
|
case "FunctionApplication": {
|
|
256
253
|
keepLazy(expression.function);
|
|
257
254
|
const functionCode = generate(expression.function);
|
|
255
|
+
const describeNonFunction = addReference(generator, getNonFunctionError(expression));
|
|
258
256
|
if (expression.args.length === 1)
|
|
259
|
-
return `apply(${functionCode}, ${generate(expression.args[0])})`;
|
|
260
|
-
return `apply(${functionCode}, tuple([${expression.args.map((arg) => generate(arg)).join(", ")}]))`;
|
|
257
|
+
return `apply(${functionCode}, ${generate(expression.args[0])}, undefined, ${describeNonFunction})`;
|
|
258
|
+
return `apply(${functionCode}, tuple([${expression.args.map((arg) => generate(arg)).join(", ")}]), undefined, ${describeNonFunction})`;
|
|
261
259
|
}
|
|
262
260
|
case "FieldAccess":
|
|
263
|
-
return `apply(${generate(expression.record)}, ${JSON.stringify(expression.field)}, ${addReference(generator, getFieldError(expression))})`;
|
|
261
|
+
return `apply(${generate(expression.record)}, ${JSON.stringify(expression.field)}, ${addReference(generator, getFieldError(expression))}, ${addReference(generator, getNonRecordError(expression))})`;
|
|
264
262
|
case "Record": {
|
|
265
|
-
const fields =
|
|
266
|
-
|
|
267
|
-
);
|
|
268
|
-
const hasDuplicates = fields.some(
|
|
269
|
-
(field, index) => index > 0 && fields[index - 1].name === field.name,
|
|
270
|
-
);
|
|
271
|
-
if (hasDuplicates) return generateDelegate(generator, expression, frame);
|
|
263
|
+
const fields = getSortedFields(expression.fields);
|
|
264
|
+
if (hasDuplicateFields(fields)) return generateDelegate(generator, expression, frame);
|
|
272
265
|
const names = addReference(
|
|
273
266
|
generator,
|
|
274
267
|
fields.map((field) => field.name),
|
package/src/dependencies.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import {
|
|
1
|
+
import { getChildren, type Definition, type Expression } from "./ast";
|
|
2
|
+
import { isImpureBuiltin, type Environment } from "./evaluate";
|
|
3
3
|
|
|
4
4
|
const STATE_INDEPENDENT_KINDS = new Set([
|
|
5
5
|
"Prime",
|
package/src/environment.ts
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import {
|
|
2
|
+
getChildren,
|
|
3
|
+
type Assumption,
|
|
4
|
+
type Declaration,
|
|
5
|
+
type Definition,
|
|
6
|
+
type Expression,
|
|
7
|
+
type Instance,
|
|
8
|
+
type Module,
|
|
9
|
+
type OperatorParam,
|
|
10
|
+
type SourceLocation,
|
|
10
11
|
} from "./ast";
|
|
11
12
|
import { BUNDLED_MODULES } from "./bundled-modules";
|
|
12
13
|
import type { ConfigValue, ModelConfig } from "./config";
|
|
13
14
|
import type { FileSystem } from "./json";
|
|
14
|
-
import { TlaConfigError, TlaEvaluationError, TlaSyntaxError } from "./errors";
|
|
15
|
+
import { TlaConfigError, TlaEvaluationError, TlaModuleError, TlaSyntaxError } from "./errors";
|
|
15
16
|
import { EXIT_STATUS, setExitCode } from "./exit-codes";
|
|
16
17
|
import {
|
|
17
18
|
createBigNumberError,
|
|
18
19
|
createRealNumberError,
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
evaluate,
|
|
21
|
+
getDefinition,
|
|
21
22
|
isTlcInteger,
|
|
22
23
|
type Builtin,
|
|
23
24
|
type Environment,
|
|
@@ -44,8 +45,9 @@ import {
|
|
|
44
45
|
import { createRuntime } from "./runtime";
|
|
45
46
|
import { CORE_OPERATORS, getStandardModule, STANDARD_DEPENDENCIES } from "./standard-modules";
|
|
46
47
|
import { resolveInstanceSubexpressions, resolveModuleSubexpressions } from "./subexpressions";
|
|
47
|
-
import { checkModuleLevels } from "./levels";
|
|
48
|
+
import { checkModuleLevels, createLevelAnalyzer } from "./levels";
|
|
48
49
|
import { checkInstances, type InstanceCheck } from "./substitution-levels";
|
|
50
|
+
import { getTlcDeclarationOrder } from "./tlc-order";
|
|
49
51
|
import {
|
|
50
52
|
checkInteger,
|
|
51
53
|
createModelValue,
|
|
@@ -212,6 +214,8 @@ export const createEnvironment = (
|
|
|
212
214
|
const root = parseModule(options.source);
|
|
213
215
|
const definitions = new Map<string, Definition>();
|
|
214
216
|
const parameterized = new Map<string, boolean>();
|
|
217
|
+
// The definition each instance copy came from, and the instance parameters the copy adds.
|
|
218
|
+
const copySources = new Map<string, { source: string; prefix: number }>();
|
|
215
219
|
const builtins = new Map<string, Builtin>(
|
|
216
220
|
CORE_OPERATORS.map((operator) => [operator.name, operator]),
|
|
217
221
|
);
|
|
@@ -379,10 +383,11 @@ export const createEnvironment = (
|
|
|
379
383
|
variables: new Set(linked.variables),
|
|
380
384
|
getDefinition: (key) => definitions.get(key),
|
|
381
385
|
isParameterized: (key) => parameterized.get(key) === true,
|
|
382
|
-
addDefinition: (name, create) => {
|
|
386
|
+
addDefinition: (source, name, create) => {
|
|
383
387
|
const key = createName(`${name}@${module.name}`);
|
|
384
388
|
definitions.set(key, create(key));
|
|
385
389
|
parameterized.set(key, !isParameterFree);
|
|
390
|
+
copySources.set(key, { source, prefix: instance.params.length });
|
|
386
391
|
return key;
|
|
387
392
|
},
|
|
388
393
|
createName,
|
|
@@ -544,7 +549,7 @@ export const createEnvironment = (
|
|
|
544
549
|
variables: new Set(linked.variables),
|
|
545
550
|
getDefinition: (key) => definitions.get(key),
|
|
546
551
|
isParameterized: (key) => parameterized.get(key) === true,
|
|
547
|
-
addDefinition: (name, create) => {
|
|
552
|
+
addDefinition: (_source, name, create) => {
|
|
548
553
|
const key = `${name}${KEY_SEPARATOR}${instance.module}${suffix}.${copies.length}`;
|
|
549
554
|
const definition = create(key);
|
|
550
555
|
copies.push(
|
|
@@ -872,11 +877,51 @@ export const createEnvironment = (
|
|
|
872
877
|
);
|
|
873
878
|
}
|
|
874
879
|
});
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
880
|
+
// TLC sets a module-scoped entry on the body of the module's definition, which every instance of
|
|
881
|
+
// the module shares.
|
|
882
|
+
const scopedKeys = new Set(
|
|
883
|
+
[...config.constants, ...config.substitutions]
|
|
884
|
+
.filter((item) => item.module !== undefined)
|
|
885
|
+
.flatMap(getScopedKeys),
|
|
886
|
+
);
|
|
887
|
+
const getOverride = (
|
|
888
|
+
key: string,
|
|
889
|
+
prefix: number,
|
|
890
|
+
): { key: string; prefix: number } | undefined => {
|
|
891
|
+
if (scopedKeys.has(key)) return { key, prefix };
|
|
892
|
+
const copy = copySources.get(key);
|
|
893
|
+
return copy && getOverride(copy.source, prefix + copy.prefix);
|
|
894
|
+
};
|
|
895
|
+
copySources.forEach((copy, key) => {
|
|
896
|
+
const override = getOverride(copy.source, copy.prefix);
|
|
897
|
+
const definition = definitions.get(key);
|
|
898
|
+
if (!override || !definition) return;
|
|
899
|
+
const params = definition.kind === "Operator" ? definition.params : [];
|
|
900
|
+
const alias = createLocalAlias(
|
|
901
|
+
key,
|
|
902
|
+
override.key,
|
|
903
|
+
params,
|
|
904
|
+
params.slice(override.prefix),
|
|
905
|
+
definition.location,
|
|
906
|
+
);
|
|
907
|
+
definitions.set(key, alias);
|
|
908
|
+
linkedRoot.visible.forEach((symbol, name) => {
|
|
909
|
+
if (symbol.key === key && name !== key) definitions.set(name, alias);
|
|
910
|
+
});
|
|
879
911
|
});
|
|
912
|
+
const unassigned = declaredConstants.filter(
|
|
913
|
+
(name) => !constants.has(name) && !substitutions.has(name) && !operatorKeys.has(name),
|
|
914
|
+
);
|
|
915
|
+
if (unassigned.length > 0) {
|
|
916
|
+
// TLC reports the first constant it finds unassigned in SANY's order of declarations.
|
|
917
|
+
const name =
|
|
918
|
+
getTlcDeclarationOrder(options.source, options.loadModule, "constant").find((constant) =>
|
|
919
|
+
unassigned.includes(constant),
|
|
920
|
+
) ?? unassigned[0];
|
|
921
|
+
throw new TlaConfigError(
|
|
922
|
+
`The constant parameter ${name} is not assigned a value by the configuration file.`,
|
|
923
|
+
);
|
|
924
|
+
}
|
|
880
925
|
|
|
881
926
|
const environment: Environment = {
|
|
882
927
|
runtime,
|
|
@@ -907,18 +952,43 @@ export const createEnvironment = (
|
|
|
907
952
|
getDefinition: (symbol) => definitions.get(linked.visible.get(symbol)?.key ?? symbol),
|
|
908
953
|
};
|
|
909
954
|
});
|
|
955
|
+
// TLC evaluates a substitute at startup and rejects it only when that fails and the level bound it
|
|
956
|
+
// computes is above constant. The bound counts the operators that TLC's Java code overrides with
|
|
957
|
+
// a minimum level as state-level, so the analyzer takes them for variables.
|
|
958
|
+
const analyzer = createLevelAnalyzer({
|
|
959
|
+
constants: new Set(constants.keys()),
|
|
960
|
+
variables: new Set([
|
|
961
|
+
...variables,
|
|
962
|
+
...["TLCGet", "Trace", "CounterExample"].filter((name) => builtins.has(name)),
|
|
963
|
+
]),
|
|
964
|
+
getDefinition: (name) => getDefinition(name, environment),
|
|
965
|
+
});
|
|
966
|
+
const getEvaluationError = (body: Expression) => {
|
|
967
|
+
try {
|
|
968
|
+
evaluate(body, { environment, scope: undefined, state: undefined, next: undefined });
|
|
969
|
+
return undefined;
|
|
970
|
+
} catch (error) {
|
|
971
|
+
if (error instanceof TlaEvaluationError) return error;
|
|
972
|
+
throw error;
|
|
973
|
+
}
|
|
974
|
+
};
|
|
910
975
|
substitutions.forEach((target, name) => {
|
|
911
976
|
const definition = definitions.get(target);
|
|
912
|
-
|
|
977
|
+
const error =
|
|
913
978
|
declaredConstants.includes(name) &&
|
|
914
|
-
definition &&
|
|
915
|
-
|
|
916
|
-
|
|
979
|
+
definition?.kind === "Operator" &&
|
|
980
|
+
definition.params.length === 0 &&
|
|
981
|
+
analyzer.analyzeDefinition(definition, new Map()).level > 0
|
|
982
|
+
? getEvaluationError(definition.body)
|
|
983
|
+
: undefined;
|
|
984
|
+
// TLC adds the reason unless a standard module's Java code failed.
|
|
985
|
+
if (error) {
|
|
917
986
|
throw new TlaConfigError(
|
|
918
|
-
`The configuration file substitutes constant ${name} with non-constant ${target}`,
|
|
987
|
+
`The configuration file substitutes constant ${name} with non-constant ${target}${error instanceof TlaModuleError ? "" : ` - specifically: ${error.message}`}`,
|
|
919
988
|
);
|
|
920
989
|
}
|
|
921
990
|
});
|
|
991
|
+
runtime.isStarted = true;
|
|
922
992
|
return {
|
|
923
993
|
environment,
|
|
924
994
|
assumptions,
|
package/src/errors.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import { EXIT_STATUS, getExitCode
|
|
1
|
+
import { EXIT_STATUS, getExitCode } from "./exit-codes";
|
|
2
|
+
|
|
3
|
+
// How TLC reports a RuntimeException it did not expect, such as one raised while computing next
|
|
4
|
+
// states.
|
|
5
|
+
export const UNEXPECTED_EXCEPTION =
|
|
6
|
+
"TLC threw an unexpected exception.\nThis was probably caused by an error in the spec or model.\nSee the User Output or TLC Console for clues to what happened.\nThe exception was a java.lang.RuntimeException\n: ";
|
|
2
7
|
|
|
3
8
|
export class TlaError extends Error {
|
|
4
9
|
constructor(message: string, cause?: unknown) {
|
|
@@ -41,10 +46,21 @@ export class TlaEvaluationError extends TlaError {
|
|
|
41
46
|
// An evaluation error that TLC raises as an EvalException from a standard module's Java code. It
|
|
42
47
|
// keeps the name TlaEvaluationError, and index.ts doesn't export it.
|
|
43
48
|
export class TlaModuleError extends TlaEvaluationError {
|
|
49
|
+
exitCode: number;
|
|
50
|
+
|
|
44
51
|
constructor(message: string, exitCode: number = EXIT_STATUS.error) {
|
|
45
52
|
super(message);
|
|
46
53
|
this.name = "TlaEvaluationError";
|
|
47
|
-
|
|
54
|
+
this.exitCode = exitCode;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// TLC reports a successor state that the next-state relation leaves incomplete as an error of its
|
|
59
|
+
// own, not as an exception. It keeps the name TlaEvaluationError, and index.ts doesn't export it.
|
|
60
|
+
export class TlaIncompleteStateError extends TlaEvaluationError {
|
|
61
|
+
constructor(message: string) {
|
|
62
|
+
super(message);
|
|
63
|
+
this.name = "TlaEvaluationError";
|
|
48
64
|
}
|
|
49
65
|
}
|
|
50
66
|
|