tla-ts 0.0.2 → 0.0.3-dev.07eab97
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 +78 -12
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +98 -15
- package/dist/index.d.ts +98 -15
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +2 -2
- package/dist/parallel-worker.js +2 -2
- package/dist/parallel.cjs +1 -1
- package/dist/parallel.js +2 -2
- package/dist/run-cli.cjs +23 -2
- package/dist/run-cli.js +23 -2
- package/dist/transfer.cjs +36 -16
- package/dist/transfer.js +36 -16
- package/package.json +3 -1
- package/src/ast.ts +139 -4
- package/src/builtins.ts +9 -3
- package/src/check.ts +555 -107
- package/src/cli-options.ts +64 -0
- package/src/codegen.ts +15 -22
- package/src/config.ts +224 -170
- package/src/dependencies.ts +2 -2
- package/src/environment.ts +156 -48
- package/src/errors.ts +123 -3
- package/src/evaluate.ts +258 -160
- package/src/exit-codes.ts +39 -42
- package/src/fingerprints.ts +48 -12
- package/src/instances.ts +16 -15
- package/src/levels.ts +181 -45
- package/src/lexer.ts +11 -2
- package/src/live-check.ts +772 -0
- package/src/liveness.ts +120 -543
- package/src/obligation-action.ts +384 -0
- package/src/obligation-anon.ts +575 -0
- package/src/obligation-deref.ts +637 -0
- package/src/obligation-expression.ts +1060 -0
- package/src/obligation-format.ts +406 -0
- package/src/obligation-generate.ts +1074 -0
- package/src/obligation-levels.ts +329 -0
- package/src/obligation-module.ts +1042 -0
- package/src/obligation-printer.ts +889 -0
- package/src/obligation-proof.ts +76 -0
- package/src/obligation-source.ts +1084 -0
- package/src/obligation-tuples.ts +184 -0
- package/src/obligations.ts +316 -0
- package/src/parallel-worker.ts +168 -212
- package/src/parallel.ts +78 -37
- package/src/parser.ts +350 -63
- package/src/resolve.ts +124 -44
- package/src/run-cli.ts +405 -45
- package/src/runtime.ts +3 -1
- package/src/spec-description.ts +19 -8
- package/src/standard-levels.ts +3 -3
- package/src/standard-modules.ts +54 -45
- package/src/state-graph.ts +157 -0
- package/src/subexpressions.ts +10 -10
- package/src/substitution-levels.ts +38 -17
- package/src/successors.ts +183 -39
- package/src/symmetry.ts +30 -8
- 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/transfer.ts +22 -1
- package/src/value-sources.ts +29 -0
- package/src/values.ts +300 -83
package/src/environment.ts
CHANGED
|
@@ -1,23 +1,30 @@
|
|
|
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 {
|
|
15
|
+
import {
|
|
16
|
+
createSanyError,
|
|
17
|
+
TlaConfigError,
|
|
18
|
+
TlaEvaluationError,
|
|
19
|
+
TlaModuleError,
|
|
20
|
+
TlaSyntaxError,
|
|
21
|
+
} from "./errors";
|
|
15
22
|
import { EXIT_STATUS, setExitCode } from "./exit-codes";
|
|
16
23
|
import {
|
|
17
24
|
createBigNumberError,
|
|
18
25
|
createRealNumberError,
|
|
19
|
-
|
|
20
|
-
|
|
26
|
+
evaluate,
|
|
27
|
+
getDefinition,
|
|
21
28
|
isTlcInteger,
|
|
22
29
|
type Builtin,
|
|
23
30
|
type Environment,
|
|
@@ -44,8 +51,9 @@ import {
|
|
|
44
51
|
import { createRuntime } from "./runtime";
|
|
45
52
|
import { CORE_OPERATORS, getStandardModule, STANDARD_DEPENDENCIES } from "./standard-modules";
|
|
46
53
|
import { resolveInstanceSubexpressions, resolveModuleSubexpressions } from "./subexpressions";
|
|
47
|
-
import { checkModuleLevels } from "./levels";
|
|
48
|
-
import {
|
|
54
|
+
import { checkModuleLevels, createLevelAnalyzer } from "./levels";
|
|
55
|
+
import { createInstanceChecker, type InstanceCheck } from "./substitution-levels";
|
|
56
|
+
import { getTlcDeclarationOrder } from "./tlc-order";
|
|
49
57
|
import {
|
|
50
58
|
checkInteger,
|
|
51
59
|
createModelValue,
|
|
@@ -212,6 +220,8 @@ export const createEnvironment = (
|
|
|
212
220
|
const root = parseModule(options.source);
|
|
213
221
|
const definitions = new Map<string, Definition>();
|
|
214
222
|
const parameterized = new Map<string, boolean>();
|
|
223
|
+
// The definition each instance copy came from, and the instance parameters the copy adds.
|
|
224
|
+
const copySources = new Map<string, { source: string; prefix: number }>();
|
|
215
225
|
const builtins = new Map<string, Builtin>(
|
|
216
226
|
CORE_OPERATORS.map((operator) => [operator.name, operator]),
|
|
217
227
|
);
|
|
@@ -219,6 +229,8 @@ export const createEnvironment = (
|
|
|
219
229
|
const runtime = createRuntime(config.checkDeadlock, options.seed);
|
|
220
230
|
const linkedModules = new Map<string, LinkedModule>();
|
|
221
231
|
const nestedModules = new Map<string, LinkedModule>();
|
|
232
|
+
// Each module by name, from the time its level checks run.
|
|
233
|
+
const checkedModules = new Map<string, LinkedModule>();
|
|
222
234
|
const linkedList: LinkedModule[] = [];
|
|
223
235
|
const dependencies = new Map<string, Set<string>>();
|
|
224
236
|
const loading: Set<string>[] = [];
|
|
@@ -233,7 +245,23 @@ export const createEnvironment = (
|
|
|
233
245
|
const copyCount = { value: 0 };
|
|
234
246
|
const createName = (name: string) => `${name}#${copyCount.value++}`;
|
|
235
247
|
const instanceChecks: InstanceCheck[] = [];
|
|
248
|
+
const checkInstance = createInstanceChecker((name) => {
|
|
249
|
+
const linked = checkedModules.get(name) ?? getLinkedModule(name, name);
|
|
250
|
+
return {
|
|
251
|
+
constants: linked.constants,
|
|
252
|
+
variables: linked.variables,
|
|
253
|
+
definitions: [
|
|
254
|
+
...new Set(
|
|
255
|
+
[...linked.visible.values()].flatMap((symbol) => definitions.get(symbol.key) ?? []),
|
|
256
|
+
),
|
|
257
|
+
],
|
|
258
|
+
assumptions: linked.module.assumptions.map((assumption) => assumption.expression),
|
|
259
|
+
theorems: linked.module.theorems,
|
|
260
|
+
getDefinition: (symbol) => definitions.get(linked.visible.get(symbol)?.key ?? symbol),
|
|
261
|
+
};
|
|
262
|
+
});
|
|
236
263
|
const instanceActions = new Map<string, InstanceAction>();
|
|
264
|
+
const qualifiedNames = new Map<string, string>();
|
|
237
265
|
|
|
238
266
|
const addStandardModule = (name: string): Symbols | undefined => {
|
|
239
267
|
const cached = standardExports.get(name);
|
|
@@ -256,7 +284,11 @@ export const createEnvironment = (
|
|
|
256
284
|
|
|
257
285
|
const getStandardSymbols = (name: string) => {
|
|
258
286
|
const symbols = addStandardModule(name);
|
|
259
|
-
|
|
287
|
+
const dependencies = STANDARD_DEPENDENCIES.get(name) ?? [];
|
|
288
|
+
if (symbols) useModule(name, dependencies);
|
|
289
|
+
// TLC loads the Java class of each module a standard module uses, so one that uses Integers
|
|
290
|
+
// overrides the arithmetic of Naturals.
|
|
291
|
+
if (symbols && dependencies.includes("Integers")) addStandardModule("Integers");
|
|
260
292
|
return symbols;
|
|
261
293
|
};
|
|
262
294
|
|
|
@@ -285,13 +317,25 @@ export const createEnvironment = (
|
|
|
285
317
|
BUNDLED_MODULES.get(name) ??
|
|
286
318
|
extractModule(options.source, name);
|
|
287
319
|
if (source === undefined)
|
|
288
|
-
throw
|
|
289
|
-
|
|
320
|
+
throw createSanyError(
|
|
321
|
+
[
|
|
322
|
+
{
|
|
323
|
+
location: `In module ${importer}`,
|
|
324
|
+
message: `Cannot find source file for module ${name} imported in module ${importer}.`,
|
|
325
|
+
},
|
|
326
|
+
],
|
|
327
|
+
true,
|
|
290
328
|
);
|
|
291
329
|
const module = parseModule(source);
|
|
292
330
|
if (module.name !== name) {
|
|
293
|
-
throw
|
|
294
|
-
|
|
331
|
+
throw createSanyError(
|
|
332
|
+
[
|
|
333
|
+
{
|
|
334
|
+
location: "Unknown location",
|
|
335
|
+
message: `File name '${name}' does not match the name '${module.name}' of the top level module it contains.`,
|
|
336
|
+
},
|
|
337
|
+
],
|
|
338
|
+
true,
|
|
295
339
|
);
|
|
296
340
|
}
|
|
297
341
|
return rejectModuleLiterals(module);
|
|
@@ -379,10 +423,11 @@ export const createEnvironment = (
|
|
|
379
423
|
variables: new Set(linked.variables),
|
|
380
424
|
getDefinition: (key) => definitions.get(key),
|
|
381
425
|
isParameterized: (key) => parameterized.get(key) === true,
|
|
382
|
-
addDefinition: (name, create) => {
|
|
426
|
+
addDefinition: (source, name, create) => {
|
|
383
427
|
const key = createName(`${name}@${module.name}`);
|
|
384
428
|
definitions.set(key, create(key));
|
|
385
429
|
parameterized.set(key, !isParameterFree);
|
|
430
|
+
copySources.set(key, { source, prefix: instance.params.length });
|
|
386
431
|
return key;
|
|
387
432
|
},
|
|
388
433
|
createName,
|
|
@@ -402,6 +447,7 @@ export const createEnvironment = (
|
|
|
402
447
|
if (declarations.length > 0) {
|
|
403
448
|
instanceActions.set(key, { name: `${instance.name}!${name}`, location: instance.location });
|
|
404
449
|
}
|
|
450
|
+
qualifiedNames.set(key, `${instance.name}!${name}`);
|
|
405
451
|
symbols.set(`${instance.name}!${name}`, {
|
|
406
452
|
key,
|
|
407
453
|
arity: symbol.arity + instance.params.length,
|
|
@@ -544,7 +590,7 @@ export const createEnvironment = (
|
|
|
544
590
|
variables: new Set(linked.variables),
|
|
545
591
|
getDefinition: (key) => definitions.get(key),
|
|
546
592
|
isParameterized: (key) => parameterized.get(key) === true,
|
|
547
|
-
addDefinition: (name, create) => {
|
|
593
|
+
addDefinition: (_source, name, create) => {
|
|
548
594
|
const key = `${name}${KEY_SEPARATOR}${instance.module}${suffix}.${copies.length}`;
|
|
549
595
|
const definition = create(key);
|
|
550
596
|
copies.push(
|
|
@@ -582,6 +628,7 @@ export const createEnvironment = (
|
|
|
582
628
|
|
|
583
629
|
const linkModule = (unlinked: Module, scope: ModuleScope): LinkedModule => {
|
|
584
630
|
const parsed = overrideDefinitions(unlinked, options.loadClass?.(unlinked.name));
|
|
631
|
+
const firstCheck = instanceChecks.length;
|
|
585
632
|
const visible: Symbols = new Map([
|
|
586
633
|
...CORE_OPERATORS.map((operator): [string, ModuleSymbol] => [
|
|
587
634
|
operator.name,
|
|
@@ -724,11 +771,6 @@ export const createEnvironment = (
|
|
|
724
771
|
visible.set(definition.name, symbol);
|
|
725
772
|
if (!definition.isLocal) exported.set(definition.name, symbol);
|
|
726
773
|
});
|
|
727
|
-
checkModuleLevels(module, {
|
|
728
|
-
constants: new Set(constants.map((constant) => constant.name)),
|
|
729
|
-
variables: new Set(variables),
|
|
730
|
-
getDefinition: (symbol) => definitions.get(visible.get(symbol)?.key ?? symbol),
|
|
731
|
-
});
|
|
732
774
|
const linked = {
|
|
733
775
|
module,
|
|
734
776
|
constants,
|
|
@@ -739,6 +781,21 @@ export const createEnvironment = (
|
|
|
739
781
|
modules,
|
|
740
782
|
extended,
|
|
741
783
|
};
|
|
784
|
+
if (!checkedModules.has(parsed.name)) checkedModules.set(parsed.name, linked);
|
|
785
|
+
// SANY checks the instances of a module with its definitions and theorems, so it reports their
|
|
786
|
+
// errors together.
|
|
787
|
+
checkModuleLevels(
|
|
788
|
+
module,
|
|
789
|
+
{
|
|
790
|
+
constants: new Set(constants.map((constant) => constant.name)),
|
|
791
|
+
variables: new Set(variables),
|
|
792
|
+
getDefinition: (symbol) => definitions.get(visible.get(symbol)?.key ?? symbol),
|
|
793
|
+
getQualifiedName: (symbol) => qualifiedNames.get(visible.get(symbol)?.key ?? symbol),
|
|
794
|
+
},
|
|
795
|
+
instanceChecks
|
|
796
|
+
.splice(firstCheck)
|
|
797
|
+
.map((check) => ({ location: check.location, check: () => checkInstance(check) })),
|
|
798
|
+
);
|
|
742
799
|
linkedList.push(linked);
|
|
743
800
|
return linked;
|
|
744
801
|
};
|
|
@@ -872,11 +929,51 @@ export const createEnvironment = (
|
|
|
872
929
|
);
|
|
873
930
|
}
|
|
874
931
|
});
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
932
|
+
// TLC sets a module-scoped entry on the body of the module's definition, which every instance of
|
|
933
|
+
// the module shares.
|
|
934
|
+
const scopedKeys = new Set(
|
|
935
|
+
[...config.constants, ...config.substitutions]
|
|
936
|
+
.filter((item) => item.module !== undefined)
|
|
937
|
+
.flatMap(getScopedKeys),
|
|
938
|
+
);
|
|
939
|
+
const getOverride = (
|
|
940
|
+
key: string,
|
|
941
|
+
prefix: number,
|
|
942
|
+
): { key: string; prefix: number } | undefined => {
|
|
943
|
+
if (scopedKeys.has(key)) return { key, prefix };
|
|
944
|
+
const copy = copySources.get(key);
|
|
945
|
+
return copy && getOverride(copy.source, prefix + copy.prefix);
|
|
946
|
+
};
|
|
947
|
+
copySources.forEach((copy, key) => {
|
|
948
|
+
const override = getOverride(copy.source, copy.prefix);
|
|
949
|
+
const definition = definitions.get(key);
|
|
950
|
+
if (!override || !definition) return;
|
|
951
|
+
const params = definition.kind === "Operator" ? definition.params : [];
|
|
952
|
+
const alias = createLocalAlias(
|
|
953
|
+
key,
|
|
954
|
+
override.key,
|
|
955
|
+
params,
|
|
956
|
+
params.slice(override.prefix),
|
|
957
|
+
definition.location,
|
|
958
|
+
);
|
|
959
|
+
definitions.set(key, alias);
|
|
960
|
+
linkedRoot.visible.forEach((symbol, name) => {
|
|
961
|
+
if (symbol.key === key && name !== key) definitions.set(name, alias);
|
|
962
|
+
});
|
|
879
963
|
});
|
|
964
|
+
const unassigned = declaredConstants.filter(
|
|
965
|
+
(name) => !constants.has(name) && !substitutions.has(name) && !operatorKeys.has(name),
|
|
966
|
+
);
|
|
967
|
+
if (unassigned.length > 0) {
|
|
968
|
+
// TLC reports the first constant it finds unassigned in SANY's order of declarations.
|
|
969
|
+
const name =
|
|
970
|
+
getTlcDeclarationOrder(options.source, options.loadModule, "constant").find((constant) =>
|
|
971
|
+
unassigned.includes(constant),
|
|
972
|
+
) ?? unassigned[0];
|
|
973
|
+
throw new TlaConfigError(
|
|
974
|
+
`The constant parameter ${name} is not assigned a value by the configuration file.`,
|
|
975
|
+
);
|
|
976
|
+
}
|
|
880
977
|
|
|
881
978
|
const environment: Environment = {
|
|
882
979
|
runtime,
|
|
@@ -893,32 +990,43 @@ export const createEnvironment = (
|
|
|
893
990
|
constantLevels: new Map(),
|
|
894
991
|
evaluators: new WeakMap(),
|
|
895
992
|
};
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
assumptions: linked.module.assumptions.map((assumption) => assumption.expression),
|
|
907
|
-
getDefinition: (symbol) => definitions.get(linked.visible.get(symbol)?.key ?? symbol),
|
|
908
|
-
};
|
|
993
|
+
// TLC evaluates a substitute at startup and rejects it only when that fails and the level bound it
|
|
994
|
+
// computes is above constant. The bound counts the operators that TLC's Java code overrides with
|
|
995
|
+
// a minimum level as state-level, so the analyzer takes them for variables.
|
|
996
|
+
const analyzer = createLevelAnalyzer({
|
|
997
|
+
constants: new Set(constants.keys()),
|
|
998
|
+
variables: new Set([
|
|
999
|
+
...variables,
|
|
1000
|
+
...["TLCGet", "Trace", "CounterExample"].filter((name) => builtins.has(name)),
|
|
1001
|
+
]),
|
|
1002
|
+
getDefinition: (name) => getDefinition(name, environment),
|
|
909
1003
|
});
|
|
1004
|
+
const getEvaluationError = (body: Expression) => {
|
|
1005
|
+
try {
|
|
1006
|
+
evaluate(body, { environment, scope: undefined, state: undefined, next: undefined });
|
|
1007
|
+
return undefined;
|
|
1008
|
+
} catch (error) {
|
|
1009
|
+
if (error instanceof TlaEvaluationError) return error;
|
|
1010
|
+
throw error;
|
|
1011
|
+
}
|
|
1012
|
+
};
|
|
910
1013
|
substitutions.forEach((target, name) => {
|
|
911
1014
|
const definition = definitions.get(target);
|
|
912
|
-
|
|
1015
|
+
const error =
|
|
913
1016
|
declaredConstants.includes(name) &&
|
|
914
|
-
definition &&
|
|
915
|
-
|
|
916
|
-
|
|
1017
|
+
definition?.kind === "Operator" &&
|
|
1018
|
+
definition.params.length === 0 &&
|
|
1019
|
+
analyzer.analyzeDefinition(definition, new Map()).level > 0
|
|
1020
|
+
? getEvaluationError(definition.body)
|
|
1021
|
+
: undefined;
|
|
1022
|
+
// TLC adds the reason unless a standard module's Java code failed.
|
|
1023
|
+
if (error) {
|
|
917
1024
|
throw new TlaConfigError(
|
|
918
|
-
`The configuration file substitutes constant ${name} with non-constant ${target}`,
|
|
1025
|
+
`The configuration file substitutes constant ${name} with non-constant ${target}${error instanceof TlaModuleError ? "" : ` - specifically: ${error.message}`}`,
|
|
919
1026
|
);
|
|
920
1027
|
}
|
|
921
1028
|
});
|
|
1029
|
+
runtime.isStarted = true;
|
|
922
1030
|
return {
|
|
923
1031
|
environment,
|
|
924
1032
|
assumptions,
|
package/src/errors.ts
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { SourceRange } from "./ast";
|
|
2
|
+
import { EXIT_STATUS, getExitCode } from "./exit-codes";
|
|
3
|
+
import type { Value } from "./values";
|
|
4
|
+
|
|
5
|
+
// How TLC reports a RuntimeException it did not expect, such as one raised while computing next
|
|
6
|
+
// states.
|
|
7
|
+
export const UNEXPECTED_EXCEPTION =
|
|
8
|
+
"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: ";
|
|
9
|
+
|
|
10
|
+
// How TLC reports a Java StackOverflowError, which V8 raises as this RangeError.
|
|
11
|
+
export const STACK_OVERFLOW =
|
|
12
|
+
"This was a Java StackOverflowError. It was probably the result\nof an incorrect recursive function definition that caused TLC to enter\nan infinite loop when trying to compute the function or its application\nto an element in its putative domain.";
|
|
13
|
+
|
|
14
|
+
export const isStackOverflow = (error: unknown) =>
|
|
15
|
+
error instanceof RangeError && error.message === "Maximum call stack size exceeded";
|
|
2
16
|
|
|
3
17
|
export class TlaError extends Error {
|
|
4
18
|
constructor(message: string, cause?: unknown) {
|
|
@@ -7,13 +21,51 @@ export class TlaError extends Error {
|
|
|
7
21
|
}
|
|
8
22
|
}
|
|
9
23
|
|
|
24
|
+
export interface SyntaxFailure {
|
|
25
|
+
reason: string;
|
|
26
|
+
line: number;
|
|
27
|
+
column: number;
|
|
28
|
+
isEnd: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// An error SANY reports at a location, such as "In module M" or a range in a module.
|
|
32
|
+
export interface SanyError {
|
|
33
|
+
location: string;
|
|
34
|
+
message: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// The errors SANY reports for a spec. A fatal error stops it before semantic analysis.
|
|
38
|
+
export interface SanyReport {
|
|
39
|
+
errors: SanyError[];
|
|
40
|
+
isFatal: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
10
43
|
export class TlaSyntaxError extends TlaError {
|
|
11
|
-
|
|
44
|
+
failure: SyntaxFailure | undefined;
|
|
45
|
+
sany: SanyReport | undefined;
|
|
46
|
+
|
|
47
|
+
constructor(message: string, cause?: unknown, failure?: SyntaxFailure, sany?: SanyReport) {
|
|
12
48
|
super(message, cause);
|
|
13
49
|
this.name = "TlaSyntaxError";
|
|
50
|
+
this.failure = failure;
|
|
51
|
+
this.sany = sany;
|
|
14
52
|
}
|
|
15
53
|
}
|
|
16
54
|
|
|
55
|
+
export const createSanyError = (errors: SanyError[], isFatal = false) =>
|
|
56
|
+
new TlaSyntaxError(
|
|
57
|
+
errors.map((error) => `${error.location}\n\n${error.message}`).join("\n\n"),
|
|
58
|
+
undefined,
|
|
59
|
+
undefined,
|
|
60
|
+
{ errors, isFatal },
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
export const formatRange = (range: SourceRange) =>
|
|
64
|
+
`line ${range.start.line}, col ${range.start.column} to line ${range.end.line}, col ${range.end.column} of module ${range.module}`;
|
|
65
|
+
|
|
66
|
+
export const createSemanticError = (message: string, range: SourceRange) =>
|
|
67
|
+
createSanyError([{ location: formatRange(range), message }]);
|
|
68
|
+
|
|
17
69
|
export class TlaConfigError extends TlaError {
|
|
18
70
|
constructor(message: string, cause?: unknown) {
|
|
19
71
|
super(message, cause);
|
|
@@ -31,10 +83,78 @@ export class TlaEvaluationError extends TlaError {
|
|
|
31
83
|
// An evaluation error that TLC raises as an EvalException from a standard module's Java code. It
|
|
32
84
|
// keeps the name TlaEvaluationError, and index.ts doesn't export it.
|
|
33
85
|
export class TlaModuleError extends TlaEvaluationError {
|
|
86
|
+
exitCode: number;
|
|
87
|
+
|
|
34
88
|
constructor(message: string, exitCode: number = EXIT_STATUS.error) {
|
|
35
89
|
super(message);
|
|
36
90
|
this.name = "TlaEvaluationError";
|
|
37
|
-
|
|
91
|
+
this.exitCode = exitCode;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// A variable that a partial state leaves without a value.
|
|
96
|
+
export class TlaUnassignedError extends TlaEvaluationError {
|
|
97
|
+
variable: string;
|
|
98
|
+
|
|
99
|
+
constructor(message: string, variable: string) {
|
|
100
|
+
super(message);
|
|
101
|
+
this.name = "TlaEvaluationError";
|
|
102
|
+
this.variable = variable;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// TLC reports a successor state that the next-state relation leaves incomplete as an error of its
|
|
107
|
+
// own, not as an exception. It keeps the name TlaEvaluationError, and index.ts doesn't export it.
|
|
108
|
+
export class TlaIncompleteStateError extends TlaEvaluationError {
|
|
109
|
+
state: (Value | undefined)[];
|
|
110
|
+
action: string | undefined;
|
|
111
|
+
missing: string[];
|
|
112
|
+
|
|
113
|
+
constructor(state: (Value | undefined)[], action: string | undefined, missing: string[]) {
|
|
114
|
+
super(
|
|
115
|
+
`Successor state is not completely specified by the next-state action. The following variable${missing.length > 1 ? "s are" : " is"} not defined: ${missing.join(", ")}.\n`,
|
|
116
|
+
);
|
|
117
|
+
this.name = "TlaEvaluationError";
|
|
118
|
+
this.state = state;
|
|
119
|
+
this.action = action;
|
|
120
|
+
this.missing = missing;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// TLC reports an initial state that the initial predicate leaves incomplete as an illegal state.
|
|
125
|
+
export class TlaIllegalStateError extends TlaEvaluationError {
|
|
126
|
+
state: (Value | undefined)[];
|
|
127
|
+
|
|
128
|
+
constructor(state: (Value | undefined)[]) {
|
|
129
|
+
super("current state is not a legal state");
|
|
130
|
+
this.name = "TlaEvaluationError";
|
|
131
|
+
this.state = state;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface TlapmReport {
|
|
136
|
+
failure?: string;
|
|
137
|
+
exception?: string;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export class TlaProofError extends TlaError {
|
|
141
|
+
failure: string | undefined;
|
|
142
|
+
exception: string;
|
|
143
|
+
|
|
144
|
+
constructor(message: string, report: TlapmReport = {}) {
|
|
145
|
+
super(message);
|
|
146
|
+
this.name = "TlaProofError";
|
|
147
|
+
this.failure = report.exception === undefined ? (report.failure ?? message) : undefined;
|
|
148
|
+
this.exception = report.exception ?? `Failure(${JSON.stringify(this.failure)})`;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// tlapm fails one of its own assertions, which it reports as a bug in itself. It keeps the name
|
|
153
|
+
// TlaProofError, and index.ts doesn't export it.
|
|
154
|
+
export class TlapmBugError extends TlaProofError {
|
|
155
|
+
constructor(exception = "Assert_failure") {
|
|
156
|
+
super("Oops, this seems to be a bug in TLAPM.", { exception });
|
|
157
|
+
this.name = "TlaProofError";
|
|
38
158
|
}
|
|
39
159
|
}
|
|
40
160
|
|