tla-ts 0.0.3-dev.52c5b61 → 0.0.3-dev.5ea4534
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/transfer.cjs +9 -9
- package/dist/transfer.js +9 -9
- package/package.json +1 -1
- package/src/check.ts +3 -1
- package/src/environment.ts +28 -4
- package/src/runtime.ts +2 -0
- package/src/tlc-module.ts +6 -0
package/package.json
CHANGED
package/src/check.ts
CHANGED
|
@@ -528,7 +528,9 @@ const getMembership = (
|
|
|
528
528
|
const getStateChecks = (named: NamedExpression[], environment: Environment): StateCheck[] =>
|
|
529
529
|
named.flatMap((item) =>
|
|
530
530
|
getConjuncts(item.expression, environment).map((expression) => {
|
|
531
|
-
|
|
531
|
+
// A LET or an argument in the scope can read variables the expression doesn't name.
|
|
532
|
+
const variables =
|
|
533
|
+
item.scope === undefined ? getReadVariables(expression, environment) : undefined;
|
|
532
534
|
return {
|
|
533
535
|
name: item.name,
|
|
534
536
|
expression,
|
package/src/environment.ts
CHANGED
|
@@ -17,7 +17,8 @@ import { EXIT_STATUS, setExitCode } from "./exit-codes";
|
|
|
17
17
|
import {
|
|
18
18
|
createBigNumberError,
|
|
19
19
|
createRealNumberError,
|
|
20
|
-
|
|
20
|
+
evaluate,
|
|
21
|
+
getDefinition,
|
|
21
22
|
isTlcInteger,
|
|
22
23
|
type Builtin,
|
|
23
24
|
type Environment,
|
|
@@ -44,7 +45,7 @@ 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";
|
|
49
50
|
import {
|
|
50
51
|
checkInteger,
|
|
@@ -942,18 +943,41 @@ export const createEnvironment = (
|
|
|
942
943
|
getDefinition: (symbol) => definitions.get(linked.visible.get(symbol)?.key ?? symbol),
|
|
943
944
|
};
|
|
944
945
|
});
|
|
946
|
+
// TLC evaluates a substitute at startup and rejects it only when that fails and the level bound it
|
|
947
|
+
// computes is above constant. The bound counts the operators that TLC's Java code overrides with
|
|
948
|
+
// a minimum level as state-level, so the analyzer takes them for variables.
|
|
949
|
+
const analyzer = createLevelAnalyzer({
|
|
950
|
+
constants: new Set(constants.keys()),
|
|
951
|
+
variables: new Set([
|
|
952
|
+
...variables,
|
|
953
|
+
...["TLCGet", "Trace", "CounterExample"].filter((name) => builtins.has(name)),
|
|
954
|
+
]),
|
|
955
|
+
getDefinition: (name) => getDefinition(name, environment),
|
|
956
|
+
});
|
|
957
|
+
const isEvaluable = (body: Expression) => {
|
|
958
|
+
try {
|
|
959
|
+
evaluate(body, { environment, scope: undefined, state: undefined, next: undefined });
|
|
960
|
+
return true;
|
|
961
|
+
} catch (error) {
|
|
962
|
+
if (error instanceof TlaEvaluationError) return false;
|
|
963
|
+
throw error;
|
|
964
|
+
}
|
|
965
|
+
};
|
|
945
966
|
substitutions.forEach((target, name) => {
|
|
946
967
|
const definition = definitions.get(target);
|
|
947
968
|
if (
|
|
948
969
|
declaredConstants.includes(name) &&
|
|
949
|
-
definition &&
|
|
950
|
-
|
|
970
|
+
definition?.kind === "Operator" &&
|
|
971
|
+
definition.params.length === 0 &&
|
|
972
|
+
analyzer.analyzeDefinition(definition, new Map()).level > 0 &&
|
|
973
|
+
!isEvaluable(definition.body)
|
|
951
974
|
) {
|
|
952
975
|
throw new TlaConfigError(
|
|
953
976
|
`The configuration file substitutes constant ${name} with non-constant ${target}`,
|
|
954
977
|
);
|
|
955
978
|
}
|
|
956
979
|
});
|
|
980
|
+
runtime.isStarted = true;
|
|
957
981
|
return {
|
|
958
982
|
environment,
|
|
959
983
|
assumptions,
|
package/src/runtime.ts
CHANGED
|
@@ -24,6 +24,7 @@ export interface CheckerRuntime {
|
|
|
24
24
|
properties: Map<string, string>;
|
|
25
25
|
possibleCounts: Map<string, number>;
|
|
26
26
|
isStopped: boolean;
|
|
27
|
+
isStarted: boolean;
|
|
27
28
|
checkDeadlock: boolean;
|
|
28
29
|
startedAt: number;
|
|
29
30
|
}
|
|
@@ -75,6 +76,7 @@ export const createRuntime = (checkDeadlock: boolean, seed = 0n): CheckerRuntime
|
|
|
75
76
|
properties: new Map(),
|
|
76
77
|
possibleCounts: new Map(),
|
|
77
78
|
isStopped: false,
|
|
79
|
+
isStarted: false,
|
|
78
80
|
checkDeadlock,
|
|
79
81
|
startedAt: Date.now(),
|
|
80
82
|
};
|
package/src/tlc-module.ts
CHANGED
|
@@ -39,11 +39,17 @@ const formatCalendarVersion = (date: Date) =>
|
|
|
39
39
|
const getRegisterFunction = <Key extends Value>(registers: Map<Key, Value>) =>
|
|
40
40
|
createFunction([...registers].map(([key, value]): [Value, Value] => [key, createTuple([value])]));
|
|
41
41
|
|
|
42
|
+
// TLC creates its model checker after it processes the spec, so these are undefined before then.
|
|
43
|
+
const CHECKER_KEYS = new Set(["diameter", "generated", "distinct", "queue", "stats", "config"]);
|
|
44
|
+
|
|
42
45
|
const getRuntimeValue = (
|
|
43
46
|
runtime: CheckerRuntime,
|
|
44
47
|
key: string,
|
|
45
48
|
state: (Value | undefined)[] | undefined,
|
|
46
49
|
) => {
|
|
50
|
+
if (!runtime.isStarted && CHECKER_KEYS.has(key)) {
|
|
51
|
+
throw new TlaModuleError(`TLCGet(${key}) was undefined.`);
|
|
52
|
+
}
|
|
47
53
|
const duration = Math.floor((Date.now() - runtime.startedAt) / 1000);
|
|
48
54
|
switch (key) {
|
|
49
55
|
case "level":
|