tla-ts 0.0.10-dev.4a2a53c48 → 0.0.10-dev.5ffc55ce5
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/deciders.cjs +35 -35
- package/dist/deciders.js +29 -29
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +25 -25
- package/dist/prove.js +57 -57
- package/dist/run.cjs +26 -28
- package/dist/run.js +42 -44
- package/dist/transfer.cjs +35 -35
- package/dist/transfer.js +28 -28
- package/dist/worker.cjs +1 -1
- package/dist/worker.js +1 -1
- package/package.json +1 -1
- package/src/bags.ts +47 -28
- package/src/check-trace.ts +2 -16
- package/src/check.ts +143 -61
- package/src/cli/runtime-invariants.ts +20 -56
- package/src/cli/tlc-arguments.ts +2 -2
- package/src/cli/tlc-output.ts +1 -2
- package/src/cli/tlc.ts +13 -8
- package/src/dfid.ts +9 -2
- package/src/environment.ts +18 -0
- package/src/evaluate.ts +9 -3
- package/src/exit-codes.ts +2 -0
- package/src/liveness-checker.ts +45 -4
- package/src/parallel-worker.ts +8 -2
- package/src/parallel.ts +5 -0
- package/src/prover/smt/solver/ast.ts +1 -1
- package/src/prover/smt/solver/context.ts +6 -2
- package/src/prover/smt/solver/euf/egraph.ts +1 -1
- package/src/prover/smt/solver/expr2polynomial.ts +204 -79
- package/src/prover/smt/solver/factor.ts +36 -14
- package/src/prover/smt/solver/fpa-rewriter.ts +1 -2
- package/src/prover/smt/solver/fpa2bv-converter.ts +3 -1
- package/src/prover/smt/solver/goal.ts +2 -0
- package/src/prover/smt/solver/goal2nlsat.ts +57 -30
- package/src/prover/smt/solver/lp/containers.ts +7 -1
- package/src/prover/smt/solver/lp/cross-nested.ts +1 -3
- package/src/prover/smt/solver/lp/nex-creator.ts +3 -2
- package/src/prover/smt/solver/lp/nex.ts +2 -1
- package/src/prover/smt/solver/lp/nla-basics.ts +46 -1
- package/src/prover/smt/solver/lp/nla-core.ts +26 -6
- package/src/prover/smt/solver/lp/nla-grobner.ts +156 -79
- package/src/prover/smt/solver/lp/nra-solver.ts +138 -95
- package/src/prover/smt/solver/lp/pdd-interval.ts +6 -2
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +60 -20
- package/src/prover/smt/solver/lp/pdd-solver.ts +72 -39
- package/src/prover/smt/solver/lp/pdd.ts +725 -289
- package/src/prover/smt/solver/muz/dl-context.ts +8 -2
- package/src/prover/smt/solver/muz/spacer-context.ts +1 -0
- package/src/prover/smt/solver/muz/spacer-pdr.ts +1 -0
- package/src/prover/smt/solver/nlsat/algebraic.ts +194 -89
- package/src/prover/smt/solver/nlsat/atoms.ts +52 -33
- package/src/prover/smt/solver/nlsat/explain.ts +375 -217
- package/src/prover/smt/solver/nlsat/levelwise.ts +464 -240
- package/src/prover/smt/solver/nlsat/polynomial.ts +2400 -680
- package/src/prover/smt/solver/nlsat/solver.ts +74 -71
- package/src/prover/smt/solver/nlsat/transcendentals.ts +41 -17
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +8 -4
- package/src/prover/smt/solver/nlsat/upolynomial.ts +40 -17
- package/src/prover/smt/solver/opt-nlsat.ts +29 -18
- package/src/prover/smt/solver/opt-solver.ts +2 -3
- package/src/prover/smt/solver/rlimit.ts +13 -0
- package/src/prover/smt/solver/sat/sat-tactic.ts +2 -1
- package/src/prover/smt/solver/seq-derive.ts +3 -6
- package/src/prover/smt/solver/smtlib-parser.ts +10 -10
- package/src/prover/smt/solver/smtlib-script.ts +91 -28
- package/src/prover/smt/solver/tactic.ts +14 -5
- package/src/prover/smt/solver/theory-lra-internalize.ts +8 -0
- package/src/prover/zenon/equality-rules.ts +24 -0
- package/src/prover/zenon/expr.ts +21 -0
- package/src/prover/zenon/index-table.ts +2 -0
- package/src/prover/zenon/rules.ts +2 -1
- package/src/resolve.ts +1 -1
- package/src/runtime.ts +2 -0
- package/src/sany/generator-expressions.ts +6 -13
- package/src/search.ts +40 -11
- package/src/tlc/order.ts +14 -3
- package/src/tlc/tlcext-operators.ts +18 -5
- package/src/tlc/trace-spec.ts +2 -3
|
@@ -3,14 +3,9 @@ import { EXIT_STATUS, setExitCode } from "../exit-codes";
|
|
|
3
3
|
import { parseModule } from "../parser";
|
|
4
4
|
import { generateSanySpecification } from "../sany/generator";
|
|
5
5
|
import { checkModuleLevels } from "../sany/levels";
|
|
6
|
-
import {
|
|
7
|
-
VARIABLE_DECL_KIND,
|
|
8
|
-
type ModuleNode,
|
|
9
|
-
type OpDefNode,
|
|
10
|
-
type SymbolNode,
|
|
11
|
-
} from "../sany/nodes";
|
|
6
|
+
import type { ModuleNode, OpDefNode, SymbolNode } from "../sany/nodes";
|
|
12
7
|
import type { TlcVersion } from "../tlc/version";
|
|
13
|
-
import type {
|
|
8
|
+
import type { RuntimeInvariantTemplate } from "./tlc-arguments";
|
|
14
9
|
|
|
15
10
|
const CONSTANT_LEVEL = 0;
|
|
16
11
|
const TEMPORAL_LEVEL = 3;
|
|
@@ -31,21 +26,20 @@ const createParsingFailure = (detail: string) =>
|
|
|
31
26
|
EXIT_STATUS.specParseError,
|
|
32
27
|
);
|
|
33
28
|
|
|
34
|
-
const
|
|
35
|
-
|
|
29
|
+
const checkDebuggerExpression = (
|
|
30
|
+
source: string,
|
|
31
|
+
moduleName: string,
|
|
36
32
|
name: string,
|
|
37
33
|
expression: string,
|
|
38
34
|
loadModule: (name: string) => string | undefined,
|
|
39
35
|
version: TlcVersion,
|
|
40
36
|
) => {
|
|
41
|
-
const moduleName = name.replace("__DebuggerExpr__", "__DebuggerModule__");
|
|
42
|
-
const text = `---- MODULE ${moduleName} ----\nEXTENDS ${root}\n\n${name} == ${expression}\n====`;
|
|
43
37
|
const createFailure = (message: string) =>
|
|
44
38
|
createParsingFailure(
|
|
45
39
|
`Unknown location\n\n${message} while parsing breakpoint expression "${expression}"`,
|
|
46
40
|
);
|
|
47
41
|
try {
|
|
48
|
-
parseModule(
|
|
42
|
+
parseModule(source);
|
|
49
43
|
} catch (error) {
|
|
50
44
|
if (!(error instanceof TlaSyntaxError)) throw error;
|
|
51
45
|
throw createParsingFailure(`Syntax error while parsing breakpoint expression "${expression}"`);
|
|
@@ -54,7 +48,7 @@ const getDebuggerExpressionLevel = (
|
|
|
54
48
|
let isLevelCorrect = false;
|
|
55
49
|
const specification = (() => {
|
|
56
50
|
try {
|
|
57
|
-
return generateSanySpecification(
|
|
51
|
+
return generateSanySpecification(source, loadModule, {
|
|
58
52
|
version,
|
|
59
53
|
onModule: (module, messages) => {
|
|
60
54
|
const isCorrect = () => messages.every((message) => message.isWarning);
|
|
@@ -81,56 +75,26 @@ const getDebuggerExpressionLevel = (
|
|
|
81
75
|
`Unknown location\n\nDebug expressions must be action-level or below; actual level: ${level} (Temporal)`,
|
|
82
76
|
);
|
|
83
77
|
}
|
|
84
|
-
return level;
|
|
85
78
|
};
|
|
86
79
|
|
|
87
|
-
|
|
88
|
-
export const addRuntimeInvariants = (
|
|
80
|
+
export const getRuntimeInvariants = (
|
|
89
81
|
source: string,
|
|
90
82
|
root: ModuleNode,
|
|
91
|
-
invariants:
|
|
83
|
+
invariants: RuntimeInvariantTemplate[],
|
|
92
84
|
loadModule: (name: string) => string | undefined,
|
|
93
85
|
version: TlcVersion,
|
|
94
86
|
) => {
|
|
95
|
-
const stamp = Date.now();
|
|
96
|
-
const named = invariants.map((invariant, index) => ({
|
|
97
|
-
expression: invariant.expression,
|
|
98
|
-
name: findDefinition(root, invariant.expression)
|
|
99
|
-
? invariant.expression
|
|
100
|
-
: `__DebuggerExpr__${stamp + index}`,
|
|
101
|
-
}));
|
|
102
|
-
const names = named.map((invariant) => invariant.name);
|
|
103
|
-
const generated = named.filter((invariant) => invariant.name !== invariant.expression);
|
|
104
|
-
if (generated.length === 0) return { names, source };
|
|
105
87
|
const loadDependency = (name: string) => (name === root.name ? source : loadModule(name));
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
)
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
);
|
|
118
|
-
// HACK: TLC checks a constant-level -inv in every state, so an unused LET makes it depend on one.
|
|
119
|
-
return level === CONSTANT_LEVEL && variable
|
|
120
|
-
? `${invariant.name} ==\nLET ${invariant.name}State == ${variable.name} IN\n${" ".repeat(head.length)}${invariant.expression}`
|
|
121
|
-
: `${head}${invariant.expression}`;
|
|
88
|
+
// Deviation from TLC: TLC reads the clock for each name, which no fixed output can match; one reading plus an index keeps the names apart.
|
|
89
|
+
const stamp = Date.now();
|
|
90
|
+
return invariants.map((invariant, index) => {
|
|
91
|
+
if (findDefinition(root, invariant.expression)) {
|
|
92
|
+
return { name: invariant.expression, module: undefined, source: undefined };
|
|
93
|
+
}
|
|
94
|
+
const module = `__DebuggerModule__${stamp + index}`;
|
|
95
|
+
const name = `__DebuggerExpr__${stamp + index}`;
|
|
96
|
+
const text = `---- MODULE ${module} ----\nEXTENDS ${root.name}\n\n${name} == ${invariant.expression}\n====`;
|
|
97
|
+
checkDebuggerExpression(text, module, name, invariant.expression, loadDependency, version);
|
|
98
|
+
return { name, module, source: text };
|
|
122
99
|
});
|
|
123
|
-
const lines = source.split("\n");
|
|
124
|
-
const end = (parseModule(source).location.range?.end.line ?? lines.length) - 1;
|
|
125
|
-
const terminator = lines[end].search(/={4,}/);
|
|
126
|
-
return {
|
|
127
|
-
names,
|
|
128
|
-
source: [
|
|
129
|
-
...lines.slice(0, end),
|
|
130
|
-
lines[end].slice(0, terminator),
|
|
131
|
-
...definitions,
|
|
132
|
-
lines[end].slice(terminator),
|
|
133
|
-
...lines.slice(end + 1),
|
|
134
|
-
].join("\n"),
|
|
135
|
-
};
|
|
136
100
|
};
|
package/src/cli/tlc-arguments.ts
CHANGED
|
@@ -35,11 +35,11 @@ export interface TlcArguments {
|
|
|
35
35
|
suppressedCodes: number[];
|
|
36
36
|
errorCodes: number[];
|
|
37
37
|
userFile: string | undefined;
|
|
38
|
-
invariants:
|
|
38
|
+
invariants: RuntimeInvariantTemplate[];
|
|
39
39
|
moduleOperators: ModuleOperator[];
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
export interface
|
|
42
|
+
export interface RuntimeInvariantTemplate {
|
|
43
43
|
modules: string[];
|
|
44
44
|
expression: string;
|
|
45
45
|
}
|
package/src/cli/tlc-output.ts
CHANGED
|
@@ -320,11 +320,10 @@ export const printCheckProgress = (
|
|
|
320
320
|
timing.livenessStartTime = Date.now();
|
|
321
321
|
if (progress.isComplete) printProgress(printer, progress.statistics);
|
|
322
322
|
const branches = progress.branches > 1 ? `${progress.branches} branches of ` : "";
|
|
323
|
-
const states = progress.branches * progress.states;
|
|
324
323
|
print(
|
|
325
324
|
MESSAGE_CODE.checkingTemporal,
|
|
326
325
|
MESSAGE_LEVEL.none,
|
|
327
|
-
`Checking ${branches}temporal properties for the ${progress.isComplete ? "complete" : "current"} state space with ${states} total distinct states at (${formatTlcDate(new Date())})`,
|
|
326
|
+
`Checking ${branches}temporal properties for the ${progress.isComplete ? "complete" : "current"} state space with ${progress.states} total distinct states at (${formatTlcDate(new Date())})`,
|
|
328
327
|
);
|
|
329
328
|
return;
|
|
330
329
|
}
|
package/src/cli/tlc.ts
CHANGED
|
@@ -29,7 +29,7 @@ import { EXIT_STATUS } from "../exit-codes";
|
|
|
29
29
|
import { check } from "../parallel";
|
|
30
30
|
import { extractModule, parseModule } from "../parser";
|
|
31
31
|
import { simulate } from "../simulate";
|
|
32
|
-
import type {
|
|
32
|
+
import type { CliSettings } from "../search";
|
|
33
33
|
import type { StateDump } from "../state-graph";
|
|
34
34
|
import {
|
|
35
35
|
getSanyStandardModules,
|
|
@@ -49,7 +49,7 @@ import {
|
|
|
49
49
|
type MessagePrinter,
|
|
50
50
|
zeroPad,
|
|
51
51
|
} from "../tlc/messages";
|
|
52
|
-
import {
|
|
52
|
+
import { getRuntimeInvariants } from "./runtime-invariants";
|
|
53
53
|
import { parseTlcArguments, type TlcArguments } from "./tlc-arguments";
|
|
54
54
|
import {
|
|
55
55
|
getClassPath,
|
|
@@ -378,15 +378,14 @@ const checkSpec = async (
|
|
|
378
378
|
}
|
|
379
379
|
const userFile = args.userFile;
|
|
380
380
|
const standardModules = getSanyStandardModules(version);
|
|
381
|
-
const
|
|
381
|
+
const runtimeInvariants = getRuntimeInvariants(
|
|
382
382
|
source,
|
|
383
383
|
specification.root,
|
|
384
384
|
args.invariants,
|
|
385
385
|
(name) => loadModule(name) ?? standardModules.get(name) ?? extractModule(source, name),
|
|
386
386
|
version,
|
|
387
387
|
);
|
|
388
|
-
|
|
389
|
-
const options: CheckOptions & StandardInput = {
|
|
388
|
+
const options: CheckOptions & CliSettings = {
|
|
390
389
|
workers: args.workers,
|
|
391
390
|
livenessCheck:
|
|
392
391
|
livenessCheck === "off"
|
|
@@ -410,11 +409,17 @@ const checkSpec = async (
|
|
|
410
409
|
version,
|
|
411
410
|
onProgress: (progress) => printCheckProgress(printer, progress, timing, directory),
|
|
412
411
|
onPrint: userFile === undefined ? undefined : (text) => appendFileSync(userFile, `${text}\n`),
|
|
413
|
-
source
|
|
412
|
+
source,
|
|
414
413
|
config,
|
|
415
414
|
onPause: () => readSync(0, Buffer.alloc(1)),
|
|
416
415
|
readLine: readStandardInputLine,
|
|
417
|
-
|
|
416
|
+
runtimeInvariants: runtimeInvariants.map((invariant) => ({
|
|
417
|
+
name: invariant.name,
|
|
418
|
+
module: invariant.module,
|
|
419
|
+
})),
|
|
420
|
+
loadModule: (name) =>
|
|
421
|
+
runtimeInvariants.find((invariant) => invariant.module === name)?.source ??
|
|
422
|
+
loadModule(name),
|
|
418
423
|
loadClass: (name) => {
|
|
419
424
|
const classPath = getClassPath(directory, name);
|
|
420
425
|
return existsSync(classPath) ? readFileSync(classPath) : undefined;
|
|
@@ -586,7 +591,7 @@ export const checkSpecs = async (args: string[], java: JavaProperties) => {
|
|
|
586
591
|
exitCodes.push(
|
|
587
592
|
await reportErrors(async () => {
|
|
588
593
|
const specPath = path.endsWith(".ts") ? await writeTypeScriptSpec(path) : path;
|
|
589
|
-
//
|
|
594
|
+
// An extension: TLC refuses more than one spec, and tla-ts checks each one under its name.
|
|
590
595
|
if (paths.length > 1) {
|
|
591
596
|
console.log(`Checking ${basename(specPath)} with ${basename(specPath, ".tla")}.cfg`);
|
|
592
597
|
}
|
package/src/dfid.ts
CHANGED
|
@@ -15,7 +15,7 @@ import { EXIT_STATUS, getMessageExitStatus, withLivenessExitCode } from "./exit-
|
|
|
15
15
|
import { createLivenessChecker } from "./liveness-checker";
|
|
16
16
|
import { getIncompleteSuccessorMessage, prepareSearch, reportAssumptionViolation } from "./search";
|
|
17
17
|
import type { SpecAction } from "./spec-description";
|
|
18
|
-
import { forEachInitialState, forEachSuccessor } from "./successors";
|
|
18
|
+
import { forEachInitialState, forEachSuccessor, getSuccessors } from "./successors";
|
|
19
19
|
import {
|
|
20
20
|
formatNestedMessage,
|
|
21
21
|
formatTlcDate,
|
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
import { getTlcFingerprint } from "./tlc/fingerprint";
|
|
29
29
|
import { replaySuccessors } from "./tlc/replay";
|
|
30
30
|
import { getOptimisticProbability, getActualProbability } from "./tlc/summary";
|
|
31
|
-
import { createModelValue, formatState, getSetBound, type Value } from "./values";
|
|
31
|
+
import { createModelValue, formatState, getSetBound, isSameValue, type Value } from "./values";
|
|
32
32
|
|
|
33
33
|
export interface DepthFirstOptions extends CheckOptions {
|
|
34
34
|
maxDepth: number;
|
|
@@ -165,6 +165,13 @@ export const checkDepthFirst = (options: DepthFirstOptions): number => {
|
|
|
165
165
|
if (assumptionStatus !== undefined) return assumptionStatus;
|
|
166
166
|
|
|
167
167
|
const nextActions = prepared.getDescription().actions;
|
|
168
|
+
// Deviation from TLC: TLCExt#pickSuccessor casts the DFID checker to ModelChecker and fails, so tla-ts asks as model checking does.
|
|
169
|
+
runtime.getSuccessorAction = (state, next) =>
|
|
170
|
+
nextActions.find((action) =>
|
|
171
|
+
getSuccessors(action.expression, state, environment, action.scope).some((successor) =>
|
|
172
|
+
successor.state.every((value, index) => isSameValue(value, next[index])),
|
|
173
|
+
),
|
|
174
|
+
);
|
|
168
175
|
const statuses = new Map<bigint, number>();
|
|
169
176
|
const fingerprintSet = { level: 1, leveled: 0, buckets: INITIAL_BUCKETS };
|
|
170
177
|
const setStatus = (fingerprint: bigint, status: number) => {
|
package/src/environment.ts
CHANGED
|
@@ -100,6 +100,13 @@ interface EnvironmentOptions {
|
|
|
100
100
|
version?: TlcVersion;
|
|
101
101
|
moduleOperators?: ModuleOperator[];
|
|
102
102
|
readLine?: () => string | undefined;
|
|
103
|
+
runtimeInvariants?: RuntimeInvariant[];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface RuntimeInvariant {
|
|
107
|
+
name: string;
|
|
108
|
+
/** Undefined when the invariant names a definition of the root module. */
|
|
109
|
+
module: string | undefined;
|
|
103
110
|
}
|
|
104
111
|
|
|
105
112
|
export interface ResolvedModuleOperator extends ModuleOperator {
|
|
@@ -114,6 +121,7 @@ export interface Specification {
|
|
|
114
121
|
startupDefinitions: Definition[];
|
|
115
122
|
javaOverrides: JavaOverride[];
|
|
116
123
|
moduleOperators: ResolvedModuleOperator[];
|
|
124
|
+
runtimeInvariants: RuntimeInvariant[];
|
|
117
125
|
rootName: string;
|
|
118
126
|
}
|
|
119
127
|
|
|
@@ -1031,6 +1039,15 @@ export const createEnvironment = (
|
|
|
1031
1039
|
);
|
|
1032
1040
|
linkOrder.push(...linkOrder.splice(linkOrder.indexOf(linkedRoot), 1));
|
|
1033
1041
|
if (warnings.length > 0 && !options.isSanyReported) options.print(formatSanyWarnings(warnings));
|
|
1042
|
+
const runtimeInvariants = options.runtimeInvariants ?? [];
|
|
1043
|
+
runtimeInvariants.forEach((invariant) => {
|
|
1044
|
+
if (invariant.module === undefined) return;
|
|
1045
|
+
linkedModules.set(root.name, linkedRoot);
|
|
1046
|
+
const linked = getLinkedModule(invariant.module, root.name);
|
|
1047
|
+
linkOrder.splice(linkOrder.indexOf(linked), 1);
|
|
1048
|
+
const definition = definitions.get(linked.visible.get(invariant.name)?.key ?? invariant.name);
|
|
1049
|
+
if (definition) definitions.set(invariant.name, definition);
|
|
1050
|
+
});
|
|
1034
1051
|
linkedRoot.visible.forEach((symbol, name) => {
|
|
1035
1052
|
const definition = definitions.get(symbol.key);
|
|
1036
1053
|
if (definition && symbol.key !== name) definitions.set(name, definition);
|
|
@@ -1171,6 +1188,7 @@ export const createEnvironment = (
|
|
|
1171
1188
|
),
|
|
1172
1189
|
javaOverrides: linkOrder.flatMap((linked) => javaOverrides.get(linked.module.name) ?? []),
|
|
1173
1190
|
moduleOperators,
|
|
1191
|
+
runtimeInvariants,
|
|
1174
1192
|
rootName: root.name,
|
|
1175
1193
|
};
|
|
1176
1194
|
};
|
package/src/evaluate.ts
CHANGED
|
@@ -615,12 +615,16 @@ export const bindLazyArguments = (
|
|
|
615
615
|
typeof value.domain === "object" && value.domain.kind === "ProductSet"
|
|
616
616
|
? value.domain.factors
|
|
617
617
|
: [];
|
|
618
|
-
|
|
618
|
+
if (elements === undefined) {
|
|
619
|
+
throw new TlaEvaluationError(
|
|
620
|
+
`Attempted to apply a function to an argument not in its domain.\n${describeRange(expression.function)}`,
|
|
621
|
+
);
|
|
622
|
+
}
|
|
623
|
+
// Deviation from TLC: Tool#getFcnContext indexes past an argument tuple shorter than the bounds and ignores a longer one.
|
|
619
624
|
const createListError = () =>
|
|
620
625
|
new TlaEvaluationError(
|
|
621
626
|
`In applying the function\n${prettyPrint(formatValue(value))},\nthe argument list is:\n${prettyPrint(formatValue(argument))}\nwhich does not match its formal parameter.\n`,
|
|
622
627
|
);
|
|
623
|
-
if (elements === undefined) throw createListError();
|
|
624
628
|
bounds.forEach((bound, index) => {
|
|
625
629
|
if (index >= elements.length) throw createListError();
|
|
626
630
|
const element = elements[index];
|
|
@@ -1177,7 +1181,9 @@ const evaluateLocalIdentifier = (name: string, expression: Expression, context:
|
|
|
1177
1181
|
}
|
|
1178
1182
|
const builtin = context.environment.builtins.get(name);
|
|
1179
1183
|
if (builtin?.arity === 0) return builtin.evaluate([], context);
|
|
1180
|
-
throw new TlaEvaluationError(
|
|
1184
|
+
throw new TlaEvaluationError(
|
|
1185
|
+
`In evaluation, the identifier ${name} is either undefined or not an operator.\n${describeRange(expression)}`,
|
|
1186
|
+
);
|
|
1181
1187
|
};
|
|
1182
1188
|
|
|
1183
1189
|
export const getReevaluatedDefinitions = (
|
package/src/exit-codes.ts
CHANGED
|
@@ -81,6 +81,8 @@ export const withLivenessExitCode = (
|
|
|
81
81
|
withErrorExitCode(() => checker.addInitialState(index, state, tracing)),
|
|
82
82
|
addState: (index, state, successors, tracing) =>
|
|
83
83
|
withErrorExitCode(() => checker.addState(index, state, successors, tracing)),
|
|
84
|
+
storeState: checker.storeState,
|
|
85
|
+
getStateCounts: checker.getStateCounts,
|
|
84
86
|
findViolation: () => withErrorExitCode(() => checker.findViolation()),
|
|
85
87
|
getViolatedProperties: (path, cycleStart) =>
|
|
86
88
|
withErrorExitCode(() => checker.getViolatedProperties(path, cycleStart)),
|
package/src/liveness-checker.ts
CHANGED
|
@@ -45,6 +45,8 @@ export interface LivenessChecker {
|
|
|
45
45
|
successors: LiveSuccessor[],
|
|
46
46
|
tracing?: Environment,
|
|
47
47
|
) => number[] | undefined;
|
|
48
|
+
storeState: (pending: number, index: number) => void;
|
|
49
|
+
getStateCounts: () => number[];
|
|
48
50
|
findViolation: () => Lasso | undefined;
|
|
49
51
|
getViolatedProperties: (path: Value[][], cycleStart: number) => string[];
|
|
50
52
|
}
|
|
@@ -58,6 +60,9 @@ export interface LiveGraph<State> {
|
|
|
58
60
|
state: State,
|
|
59
61
|
successors: LiveSuccessor<State>[],
|
|
60
62
|
) => number[] | undefined;
|
|
63
|
+
storeState: (pending: number, index: number) => void;
|
|
64
|
+
// How many states the graph of each branch has, which TLC counts as the fingerprints of its nodes.
|
|
65
|
+
getStateCounts: () => number[];
|
|
61
66
|
findViolation: () => Lasso | undefined;
|
|
62
67
|
}
|
|
63
68
|
|
|
@@ -114,6 +119,7 @@ interface BehaviorGraph<State> {
|
|
|
114
119
|
nextSiblings: number[];
|
|
115
120
|
nodeIds: NodeTable;
|
|
116
121
|
isDone: boolean[];
|
|
122
|
+
stateCount: number;
|
|
117
123
|
errorNode: number | undefined;
|
|
118
124
|
}
|
|
119
125
|
|
|
@@ -366,6 +372,8 @@ export const createLivenessChecker = (
|
|
|
366
372
|
traceWith(replay, () => graph.addInitialState(index, state)),
|
|
367
373
|
addState: (index, state, successors, replay) =>
|
|
368
374
|
traceWith(replay, () => graph.addState(index, state, successors)),
|
|
375
|
+
storeState: graph.storeState,
|
|
376
|
+
getStateCounts: graph.getStateCounts,
|
|
369
377
|
findViolation: graph.findViolation,
|
|
370
378
|
getViolatedProperties: (path, cycleStart) => [
|
|
371
379
|
...new Set(
|
|
@@ -505,6 +513,7 @@ export const createLiveGraph = <State>(
|
|
|
505
513
|
nextSiblings: [],
|
|
506
514
|
nodeIds: { slots: new Int32Array(3 << 10), size: 0, shift: 22 },
|
|
507
515
|
isDone: [],
|
|
516
|
+
stateCount: 0,
|
|
508
517
|
errorNode: undefined,
|
|
509
518
|
}));
|
|
510
519
|
const checkState = (
|
|
@@ -600,8 +609,12 @@ export const createLiveGraph = <State>(
|
|
|
600
609
|
const slot = getNodeSlot(behavior.nodeIds, state, tableauNode);
|
|
601
610
|
return slots[slot] === 0 ? undefined : slots[slot + 2];
|
|
602
611
|
};
|
|
603
|
-
const
|
|
604
|
-
|
|
612
|
+
const linkNode = (
|
|
613
|
+
behavior: BehaviorGraph<State>,
|
|
614
|
+
state: number,
|
|
615
|
+
tableauNode: number,
|
|
616
|
+
node: number,
|
|
617
|
+
) => {
|
|
605
618
|
const table = behavior.nodeIds;
|
|
606
619
|
if (++table.size * 2 > table.slots.length / 3) {
|
|
607
620
|
const old = table.slots;
|
|
@@ -617,12 +630,24 @@ export const createLiveGraph = <State>(
|
|
|
617
630
|
}
|
|
618
631
|
}
|
|
619
632
|
table.slots.set([state + 1, tableauNode, node], getNodeSlot(table, state, tableauNode));
|
|
633
|
+
if (state < 0) return node;
|
|
620
634
|
const last = behavior.lastNodes.data[state] ?? NO_NODE;
|
|
621
635
|
if (last === NO_NODE) writeToPool(behavior.firstNodes, state, [node]);
|
|
622
636
|
else behavior.nextSiblings[last] = node;
|
|
623
637
|
writeToPool(behavior.lastNodes, state, [node]);
|
|
624
638
|
return node;
|
|
625
639
|
};
|
|
640
|
+
// TLC's table of tableau nodes has a state once the search expands it or it has a node.
|
|
641
|
+
const hasState = (behavior: BehaviorGraph<State>, state: number) =>
|
|
642
|
+
state < 0
|
|
643
|
+
? behavior.checks.nodes.some(
|
|
644
|
+
(_checks, tableauNode) => getNodeId(behavior, state, tableauNode) !== undefined,
|
|
645
|
+
)
|
|
646
|
+
: behavior.isDone[state] === true || (behavior.firstNodes.data[state] ?? NO_NODE) !== NO_NODE;
|
|
647
|
+
const recordNode = (behavior: BehaviorGraph<State>, state: number, tableauNode: number) => {
|
|
648
|
+
if (!hasState(behavior, state)) behavior.stateCount++;
|
|
649
|
+
return linkNode(behavior, state, tableauNode, pushNode(behavior, state, tableauNode));
|
|
650
|
+
};
|
|
626
651
|
// The action results of the edge to each target are at its position in actions.
|
|
627
652
|
const writeNode = (
|
|
628
653
|
behavior: BehaviorGraph<State>,
|
|
@@ -753,8 +778,6 @@ export const createLiveGraph = <State>(
|
|
|
753
778
|
const isDone = behavior.isDone[successor.index] === true;
|
|
754
779
|
for (const next of tableauNode.successors) {
|
|
755
780
|
if (!isConsistent(behavior, next, index, successor.state, successorRow, 0)) continue;
|
|
756
|
-
// Deviation from TLC: TLC records the node of a successor the search never stored, which it never expands.
|
|
757
|
-
if (successor.index === -1) continue;
|
|
758
781
|
const existing = getNodeId(behavior, successor.index, next);
|
|
759
782
|
if (existing !== undefined && successors.includes(existing)) continue;
|
|
760
783
|
const target = existing ?? recordNode(behavior, successor.index, next);
|
|
@@ -791,6 +814,7 @@ export const createLiveGraph = <State>(
|
|
|
791
814
|
}
|
|
792
815
|
}
|
|
793
816
|
});
|
|
817
|
+
if (!hasState(behavior, index)) behavior.stateCount++;
|
|
794
818
|
behavior.isDone[index] = true;
|
|
795
819
|
// TLC expands the nodes recorded before the loop, not the ones the loop records.
|
|
796
820
|
for (const node of getStateNodes(behavior, index)) {
|
|
@@ -840,6 +864,7 @@ export const createLiveGraph = <State>(
|
|
|
840
864
|
successors.push(successor.index);
|
|
841
865
|
actions.push(position);
|
|
842
866
|
});
|
|
867
|
+
if (!isWritten(behavior, index)) behavior.stateCount++;
|
|
843
868
|
writeNode(behavior, index, successors, actionResults, actions, stateResults);
|
|
844
869
|
};
|
|
845
870
|
|
|
@@ -1160,6 +1185,22 @@ export const createLiveGraph = <State>(
|
|
|
1160
1185
|
}
|
|
1161
1186
|
return undefined;
|
|
1162
1187
|
},
|
|
1188
|
+
storeState: (pending, index) => {
|
|
1189
|
+
for (const behavior of behaviors) {
|
|
1190
|
+
const tableau = behavior.solution.tableau;
|
|
1191
|
+
if (!tableau) continue;
|
|
1192
|
+
const nodes: number[] = [];
|
|
1193
|
+
for (let tableauNode = 0; tableauNode < tableau.nodes.length; tableauNode++) {
|
|
1194
|
+
const node = getNodeId(behavior, pending, tableauNode);
|
|
1195
|
+
if (node !== undefined) nodes.push(node);
|
|
1196
|
+
}
|
|
1197
|
+
for (const node of nodes.sort((left, right) => left - right)) {
|
|
1198
|
+
behavior.nodeStates[node] = index;
|
|
1199
|
+
linkNode(behavior, index, behavior.nodeTableaux[node], node);
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
},
|
|
1203
|
+
getStateCounts: () => behaviors.map((behavior) => behavior.stateCount),
|
|
1163
1204
|
findViolation: () => {
|
|
1164
1205
|
for (const behavior of behaviors) {
|
|
1165
1206
|
for (const model of behavior.solution.models) {
|
package/src/parallel-worker.ts
CHANGED
|
@@ -41,8 +41,14 @@ const runWorker = (start: StartMessage, parent: Port) => {
|
|
|
41
41
|
);
|
|
42
42
|
const specification = created.specification;
|
|
43
43
|
const environment = specification.environment;
|
|
44
|
-
const search = createSearch(
|
|
45
|
-
|
|
44
|
+
const search = createSearch(
|
|
45
|
+
start.config,
|
|
46
|
+
environment,
|
|
47
|
+
specification.variableLocations,
|
|
48
|
+
() => created.order.getDeclarationOrder("variable"),
|
|
49
|
+
undefined,
|
|
50
|
+
[],
|
|
51
|
+
specification.runtimeInvariants,
|
|
46
52
|
);
|
|
47
53
|
const nextAction = search?.spec.next;
|
|
48
54
|
if (!search || nextAction === undefined)
|
package/src/parallel.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from "./check";
|
|
9
9
|
import { parseConfig, type ModelConfig } from "./config";
|
|
10
10
|
import { TlaEvaluationError } from "./errors";
|
|
11
|
+
import type { RuntimeInvariant } from "./environment";
|
|
11
12
|
import { isImpure } from "./evaluate";
|
|
12
13
|
import {
|
|
13
14
|
createSharedFingerprints,
|
|
@@ -43,6 +44,7 @@ export interface StartMessage extends Pick<
|
|
|
43
44
|
> {
|
|
44
45
|
type: "start";
|
|
45
46
|
config: ModelConfig;
|
|
47
|
+
runtimeInvariants: RuntimeInvariant[];
|
|
46
48
|
modules: [string, string | undefined][];
|
|
47
49
|
classes: [string, Uint8Array | undefined][];
|
|
48
50
|
index: number;
|
|
@@ -146,6 +148,8 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
146
148
|
specification.variableLocations,
|
|
147
149
|
() => created.order.getDeclarationOrder("variable"),
|
|
148
150
|
report,
|
|
151
|
+
[],
|
|
152
|
+
specification.runtimeInvariants,
|
|
149
153
|
);
|
|
150
154
|
if (findAssumptionViolation(specification.assumptions, environment)) return fallBack();
|
|
151
155
|
if (
|
|
@@ -273,6 +277,7 @@ export const check = async (options: CheckOptions): Promise<CheckResult> => {
|
|
|
273
277
|
type: "start",
|
|
274
278
|
source: options.source,
|
|
275
279
|
config,
|
|
280
|
+
runtimeInvariants: specification.runtimeInvariants,
|
|
276
281
|
modules: [...modules],
|
|
277
282
|
classes: [...classes],
|
|
278
283
|
index,
|
|
@@ -191,6 +191,8 @@ export class Context extends Internalizer {
|
|
|
191
191
|
private r1ParentGenerations = new Map<Enode, number>();
|
|
192
192
|
private erasedGenerations = new Map<Enode, number>();
|
|
193
193
|
private lastSearchFailure: SearchFailure = FAILURE_OK;
|
|
194
|
+
// As in Z3, a new search doesn't reset it.
|
|
195
|
+
reasonUnknown = "unknown";
|
|
194
196
|
private hasCaseSplit = true;
|
|
195
197
|
private incompleteTheories: Theory[] = [];
|
|
196
198
|
private modelState: ModelState = { kind: "none" };
|
|
@@ -244,7 +246,9 @@ export class Context extends Internalizer {
|
|
|
244
246
|
}
|
|
245
247
|
|
|
246
248
|
checkCanceled() {
|
|
247
|
-
|
|
249
|
+
if (this.manager.limit.inc()) return false;
|
|
250
|
+
this.lastSearchFailure = FAILURE_CANCELED;
|
|
251
|
+
return true;
|
|
248
252
|
}
|
|
249
253
|
|
|
250
254
|
assign(literal: Literal, justification: BJustification, isDecision = false) {
|
|
@@ -1277,7 +1281,7 @@ export class Context extends Internalizer {
|
|
|
1277
1281
|
if (this.lastSearchFailure === FAILURE_QUANTIFIERS) return "(incomplete quantifiers)";
|
|
1278
1282
|
if (this.lastSearchFailure === FAILURE_THEORY)
|
|
1279
1283
|
return `(incomplete (theory${this.incompleteTheories.map((theory) => ` ${theory.name}`).join("")}))`;
|
|
1280
|
-
return
|
|
1284
|
+
return this.reasonUnknown;
|
|
1281
1285
|
}
|
|
1282
1286
|
|
|
1283
1287
|
private hasCaseSplits() {
|
|
@@ -490,7 +490,7 @@ export class Egraph {
|
|
|
490
490
|
}
|
|
491
491
|
const rootVar = root.getThVar(id);
|
|
492
492
|
node.replaceThVar(thVar, id);
|
|
493
|
-
// Deviation from Z3: the undo
|
|
493
|
+
// Deviation from Z3: the undo gives the node back its own variable, where Z3 gives it the root's and later equates the wrong terms.
|
|
494
494
|
this.updates.push({
|
|
495
495
|
tag: U_REPLACE_TH_VAR,
|
|
496
496
|
r1: node,
|