tla-ts 0.0.10-dev.8aec06f77 → 0.0.10-dev.94c3dd828
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 +37 -36
- package/dist/deciders.js +55 -54
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +146 -58
- package/dist/prove.js +142 -54
- package/dist/run.cjs +45 -43
- package/dist/run.js +47 -45
- package/dist/transfer.cjs +39 -36
- package/dist/transfer.js +23 -20
- package/dist/worker.cjs +1 -1
- package/dist/worker.js +1 -1
- package/package.json +1 -1
- package/src/ast.ts +3 -3
- package/src/check.ts +203 -33
- package/src/cli/tlapm.ts +261 -68
- package/src/dependencies.ts +23 -2
- package/src/errors.ts +1 -1
- package/src/exit-codes.ts +1 -0
- package/src/liveness-checker.ts +530 -201
- package/src/liveness.ts +47 -32
- package/src/obligations/anonymize.ts +2 -4
- package/src/obligations/index.ts +5 -3
- package/src/obligations/pragma.ts +2 -2
- package/src/parallel.ts +2 -2
- package/src/parser.ts +151 -42
- package/src/prover/deciders.ts +1 -8
- package/src/prover/isabelle/isar/attrib.ts +86 -45
- package/src/prover/isabelle/isar/context.ts +25 -22
- package/src/prover/isabelle/isar/induct.ts +2 -5
- package/src/prover/isabelle/isar/method.ts +5 -7
- package/src/prover/isabelle/isar/proof.ts +33 -16
- package/src/prover/isabelle/isar/rule-cases.ts +6 -14
- package/src/prover/isabelle/isar/theory.ts +16 -17
- package/src/prover/isabelle/isar/toplevel.ts +46 -52
- package/src/prover/isabelle/provers/classical.ts +1 -1
- package/src/prover/ocaml.ts +4 -1
- package/src/prover/prep/action.ts +1 -0
- package/src/prover/prep/methods.ts +50 -3
- package/src/prover/prep/normalize.ts +4 -1
- package/src/prover/prove.ts +58 -32
- package/src/prover/ptl/decide.ts +43 -63
- package/src/prover/smt/data.ts +51 -45
- package/src/prover/smt/encode.ts +1 -2
- package/src/prover/smt/rewrite.ts +1 -0
- package/src/prover/smt/solver/aig-tactic.ts +25 -15
- package/src/prover/smt/solver/arith-rewriter.ts +3 -5
- package/src/prover/smt/solver/asserted-formulas.ts +1 -1
- package/src/prover/smt/solver/ast-util.ts +3 -1
- package/src/prover/smt/solver/ast.ts +110 -152
- package/src/prover/smt/solver/bound-manager.ts +39 -28
- package/src/prover/smt/solver/bv-bound-chk.ts +2 -8
- package/src/prover/smt/solver/bv-rewriter.ts +14 -16
- package/src/prover/smt/solver/bv1-blast.ts +1 -9
- package/src/prover/smt/solver/cg-table.ts +19 -14
- package/src/prover/smt/solver/check-logic.ts +6 -1
- package/src/prover/smt/solver/context.ts +20 -10
- package/src/prover/smt/solver/demodulator.ts +2 -2
- package/src/prover/smt/solver/dependent-expr-state.ts +16 -0
- package/src/prover/smt/solver/distribute-forall.ts +1 -10
- package/src/prover/smt/solver/dom-simplify.ts +1 -1
- package/src/prover/smt/solver/dt2bv-tactic.ts +2 -7
- package/src/prover/smt/solver/e-matching.ts +6 -6
- package/src/prover/smt/solver/elim-uncnstr.ts +3 -14
- package/src/prover/smt/solver/enode.ts +15 -1
- package/src/prover/smt/solver/euf/array-internalize.ts +19 -8
- package/src/prover/smt/solver/euf/dt-solver.ts +19 -19
- package/src/prover/smt/solver/euf/egraph.ts +65 -32
- package/src/prover/smt/solver/euf/euf-solver.ts +35 -18
- package/src/prover/smt/solver/euf/fpa-solver.ts +37 -51
- package/src/prover/smt/solver/euf/mam.ts +6 -48
- package/src/prover/smt/solver/euf/q-ematch.ts +21 -94
- package/src/prover/smt/solver/euf/q-mbi.ts +4 -2
- package/src/prover/smt/solver/euf/q-model-fixer.ts +1 -1
- package/src/prover/smt/solver/euf/q-solver.ts +2 -0
- package/src/prover/smt/solver/euf/th-solver.ts +1 -1
- package/src/prover/smt/solver/factor.ts +1 -11
- package/src/prover/smt/solver/fd-solver.ts +1 -2
- package/src/prover/smt/solver/fm-tactic.ts +19 -13
- package/src/prover/smt/solver/fpa-rewriter.ts +3 -1
- package/src/prover/smt/solver/fpa2bv-converter.ts +10 -6
- package/src/prover/smt/solver/internalizer.ts +41 -2
- package/src/prover/smt/solver/lia2pb.ts +18 -4
- package/src/prover/smt/solver/lp/lar-solver.ts +1 -1
- package/src/prover/smt/solver/lp/nla-powers.ts +144 -107
- package/src/prover/smt/solver/lp/nla-transcendentals.ts +50 -17
- package/src/prover/smt/solver/macro-finder.ts +1 -1
- package/src/prover/smt/solver/mam-compiler.ts +13 -13
- package/src/prover/smt/solver/max-bv-sharing-tactic.ts +1 -11
- package/src/prover/smt/solver/maxcore.ts +4 -12
- package/src/prover/smt/solver/maxlex.ts +0 -7
- package/src/prover/smt/solver/maxsmt-base.ts +7 -0
- package/src/prover/smt/solver/mbp/mbp-arith.ts +2 -11
- package/src/prover/smt/solver/mbp/mbp-plugin.ts +9 -0
- package/src/prover/smt/solver/mbp/mbp-solve-plugin.ts +1 -9
- package/src/prover/smt/solver/model-evaluator.ts +9 -5
- package/src/prover/smt/solver/model-macro-solver.ts +3 -3
- package/src/prover/smt/solver/muz/dl-context.ts +57 -3
- package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +68 -20
- package/src/prover/smt/solver/muz/dl-mk-elim-term-ite.ts +7 -1
- package/src/prover/smt/solver/muz/dl-mk-rule-inliner.ts +39 -10
- package/src/prover/smt/solver/muz/dl-mk-slice.ts +76 -13
- package/src/prover/smt/solver/muz/dl-mk-subsumption-checker.ts +9 -2
- package/src/prover/smt/solver/muz/dl-rule-transformer.ts +0 -2
- package/src/prover/smt/solver/muz/dl-rule.ts +93 -29
- package/src/prover/smt/solver/muz/hnf.ts +6 -5
- package/src/prover/smt/solver/muz/horn-subsume-model-converter.ts +178 -0
- package/src/prover/smt/solver/muz/horn-tactic.ts +14 -3
- package/src/prover/smt/solver/muz/rule-properties.ts +194 -36
- package/src/prover/smt/solver/muz/spacer-context.ts +102 -84
- package/src/prover/smt/solver/muz/spacer-dl-interface.ts +15 -2
- package/src/prover/smt/solver/muz/spacer-pdr.ts +3 -3
- package/src/prover/smt/solver/muz/spacer-prop-solver.ts +2 -7
- package/src/prover/smt/solver/muz/spacer-util.ts +2 -2
- package/src/prover/smt/solver/muz/substitution.ts +88 -37
- package/src/prover/smt/solver/nlqsat.ts +2 -2
- package/src/prover/smt/solver/nlsat/algebraic.ts +1 -2
- package/src/prover/smt/solver/nlsat/explain.ts +5 -0
- package/src/prover/smt/solver/nlsat/solver.ts +36 -25
- package/src/prover/smt/solver/opt-context.ts +9 -8
- package/src/prover/smt/solver/opt-nlsat.ts +68 -58
- package/src/prover/smt/solver/opt-solver.ts +16 -7
- package/src/prover/smt/solver/optsmt.ts +12 -9
- package/src/prover/smt/solver/pattern-inference.ts +2 -2
- package/src/prover/smt/solver/pb-rewriter.ts +13 -13
- package/src/prover/smt/solver/poly-rewriter.ts +2 -2
- package/src/prover/smt/solver/probes.ts +1 -1
- package/src/prover/smt/solver/propagate-values.ts +4 -0
- package/src/prover/smt/solver/proto-model.ts +5 -5
- package/src/prover/smt/solver/purify-arith.ts +50 -15
- package/src/prover/smt/solver/qe-arith-plugin.ts +2 -1
- package/src/prover/smt/solver/qe-mbp.ts +13 -23
- package/src/prover/smt/solver/qe.ts +45 -53
- package/src/prover/smt/solver/qsat.ts +70 -90
- package/src/prover/smt/solver/quantifier-analyzer.ts +9 -9
- package/src/prover/smt/solver/quasi-macros.ts +9 -18
- package/src/prover/smt/solver/rational.ts +17 -0
- package/src/prover/smt/solver/recfun-decl-plugin.ts +33 -19
- package/src/prover/smt/solver/recfun-rewriter.ts +1 -1
- package/src/prover/smt/solver/rewriter-tpl.ts +6 -2
- package/src/prover/smt/solver/rewriter.ts +1 -1
- package/src/prover/smt/solver/sat/asymm-branch.ts +59 -46
- package/src/prover/smt/solver/sat/clause-use-list.ts +0 -6
- package/src/prover/smt/solver/sat/clause.ts +1 -3
- package/src/prover/smt/solver/sat/config.ts +3 -3
- package/src/prover/smt/solver/sat/consequences.ts +1 -1
- package/src/prover/smt/solver/sat/goal2sat.ts +1 -1
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +4 -12
- package/src/prover/smt/solver/sat/model-converter.ts +1 -15
- package/src/prover/smt/solver/sat/pb-solver.ts +49 -23
- package/src/prover/smt/solver/sat/probing.ts +22 -19
- package/src/prover/smt/solver/sat/sat2goal.ts +9 -10
- package/src/prover/smt/solver/sat/simplifier.ts +15 -56
- package/src/prover/smt/solver/sat/solver.ts +20 -19
- package/src/prover/smt/solver/sat/watch-list.ts +7 -0
- package/src/prover/smt/solver/seq-decl-plugin.ts +7 -7
- package/src/prover/smt/solver/seq-derive.ts +6 -7
- package/src/prover/smt/solver/seq-eq-solver.ts +7 -7
- package/src/prover/smt/solver/seq-range-predicate.ts +14 -1
- package/src/prover/smt/solver/seq-re-rewriter.ts +1 -10
- package/src/prover/smt/solver/seq-re-util.ts +1 -2
- package/src/prover/smt/solver/seq-regex-bisim.ts +1 -1
- package/src/prover/smt/solver/seq-regex-live.ts +4 -4
- package/src/prover/smt/solver/seq-rewriter.ts +1 -4
- package/src/prover/smt/solver/smt-setup.ts +15 -9
- package/src/prover/smt/solver/smtlib-parser.ts +1174 -579
- package/src/prover/smt/solver/smtlib-script.ts +866 -728
- package/src/prover/smt/solver/tactic.ts +66 -14
- package/src/prover/smt/solver/theory-array.ts +25 -58
- package/src/prover/smt/solver/theory-bv.ts +13 -50
- package/src/prover/smt/solver/theory-fpa.ts +46 -78
- package/src/prover/smt/solver/theory-pb.ts +10 -6
- package/src/prover/smt/solver/theory-recfun.ts +2 -2
- package/src/prover/smt/solver/theory-seq-regex.ts +3 -6
- package/src/prover/smt/solver/theory-seq-solve.ts +5 -5
- package/src/prover/smt/solver/theory-seq-state.ts +6 -3
- package/src/prover/smt/solver/theory-seq.ts +32 -54
- package/src/prover/smt/solver/theory.ts +16 -1
- package/src/prover/smt/solver/tseitin-cnf.ts +3 -3
- package/src/prover/smt/solver/var-subst.ts +2 -2
- package/src/prover/smt/table.ts +3 -2
- package/src/prover/zenon/decide.ts +9 -11
- package/src/prover/zenon/node.ts +12 -11
- package/src/prover/zenon/tla/sets.ts +1 -1
- package/src/search.ts +131 -16
- package/src/successors.ts +1 -1
- package/src/symmetry.ts +2 -2
- package/src/tableau.ts +2 -2
- package/src/tlc/fingerprint.ts +81 -9
- package/src/tlc/summary.ts +29 -14
- package/src/typed-tier.ts +6535 -0
- package/src/prover/smt/solver/seq-regex-witness.ts +0 -100
package/src/liveness-checker.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { TlaEvaluationError } from "./errors";
|
|
2
|
+
import { isExpressionImpure } from "./dependencies";
|
|
2
3
|
import { hasRepeatedEffects, type Environment } from "./evaluate";
|
|
3
4
|
import {
|
|
4
|
-
evaluateLive,
|
|
5
5
|
evaluateOnLasso,
|
|
6
|
+
getInterpretedAtoms,
|
|
6
7
|
toLiveExpression,
|
|
8
|
+
type LiveAtoms,
|
|
7
9
|
type ScopedExpression,
|
|
8
10
|
type TemporalProperty,
|
|
9
11
|
} from "./liveness";
|
|
@@ -13,15 +15,18 @@ import {
|
|
|
13
15
|
getSolutions,
|
|
14
16
|
getTermKey,
|
|
15
17
|
isFulfilling,
|
|
18
|
+
type LiveAction,
|
|
19
|
+
type LiveEnabled,
|
|
16
20
|
type LiveExpression,
|
|
21
|
+
type LiveState,
|
|
17
22
|
type Solution,
|
|
18
23
|
type Tableau,
|
|
19
24
|
} from "./tableau";
|
|
20
25
|
import { isSameValue, type Value } from "./values";
|
|
21
26
|
|
|
22
|
-
export interface LiveSuccessor {
|
|
27
|
+
export interface LiveSuccessor<State = Value[]> {
|
|
23
28
|
index: number;
|
|
24
|
-
state:
|
|
29
|
+
state: State;
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
export interface Lasso {
|
|
@@ -32,6 +37,7 @@ export interface Lasso {
|
|
|
32
37
|
|
|
33
38
|
export interface LivenessChecker {
|
|
34
39
|
branches: number;
|
|
40
|
+
solutions: Solution[];
|
|
35
41
|
addInitialState: (index: number, state: Value[], tracing?: Environment) => void;
|
|
36
42
|
addState: (
|
|
37
43
|
index: number,
|
|
@@ -43,9 +49,30 @@ export interface LivenessChecker {
|
|
|
43
49
|
getViolatedProperties: (path: Value[][], cycleStart: number) => string[];
|
|
44
50
|
}
|
|
45
51
|
|
|
46
|
-
interface
|
|
47
|
-
|
|
48
|
-
|
|
52
|
+
export interface LiveGraph<State> {
|
|
53
|
+
branches: number;
|
|
54
|
+
addInitialState: (index: number, state: State) => void;
|
|
55
|
+
// The path to an accepting node the state reaches, if any.
|
|
56
|
+
addState: (
|
|
57
|
+
index: number,
|
|
58
|
+
state: State,
|
|
59
|
+
successors: LiveSuccessor<State>[],
|
|
60
|
+
) => number[] | undefined;
|
|
61
|
+
findViolation: () => Lasso | undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface SearchGraph<State> {
|
|
65
|
+
getFingerprint: (successor: LiveSuccessor<State>) => number;
|
|
66
|
+
getSuccessors: (index: number, state: State) => LiveSuccessor<State>[];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface LiveEvaluation<State> {
|
|
70
|
+
atoms: LiveAtoms<State>;
|
|
71
|
+
// Whether a check's result for a state holds for every step from it.
|
|
72
|
+
isShared: boolean;
|
|
73
|
+
isSame: (left: State, right: State) => boolean;
|
|
74
|
+
// Evaluates the checks of a state the search found from the state at source.
|
|
75
|
+
evaluateFrom: <Result>(source: number | undefined, evaluate: () => Result) => Result;
|
|
49
76
|
}
|
|
50
77
|
|
|
51
78
|
interface Pool<Data extends Int32Array | Uint8Array> {
|
|
@@ -54,8 +81,25 @@ interface Pool<Data extends Int32Array | Uint8Array> {
|
|
|
54
81
|
create: (length: number) => Data;
|
|
55
82
|
}
|
|
56
83
|
|
|
57
|
-
|
|
84
|
+
// A check reads and fills the state atoms of a state in its row, which starts at offset.
|
|
85
|
+
type Check<State> = (
|
|
86
|
+
state: State,
|
|
87
|
+
row: Int8Array,
|
|
88
|
+
offset: number,
|
|
89
|
+
next: State | undefined,
|
|
90
|
+
) => boolean;
|
|
91
|
+
|
|
92
|
+
interface BehaviorChecks<State> {
|
|
93
|
+
states: Check<State>[];
|
|
94
|
+
actions: Check<State>[];
|
|
95
|
+
// The state predicates of each tableau node, or, where its checks share results and it has only
|
|
96
|
+
// state atoms and their negations, each atom's id * 2 plus 1 if it must hold.
|
|
97
|
+
nodes: (Check<State>[] | Int32Array)[];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
interface BehaviorGraph<State> {
|
|
58
101
|
solution: Solution;
|
|
102
|
+
checks: BehaviorChecks<State>;
|
|
59
103
|
actionIds: Int32Array;
|
|
60
104
|
nodeStates: number[];
|
|
61
105
|
nodeTableaux: number[];
|
|
@@ -112,14 +156,18 @@ const writeToPool = <Data extends Int32Array | Uint8Array>(
|
|
|
112
156
|
pool: Pool<Data>,
|
|
113
157
|
offset: number,
|
|
114
158
|
values: ArrayLike<number>,
|
|
159
|
+
start = 0,
|
|
160
|
+
length = values.length - start,
|
|
115
161
|
) => {
|
|
116
|
-
const end = offset +
|
|
162
|
+
const end = offset + length;
|
|
117
163
|
if (end > pool.data.length) {
|
|
118
164
|
const data = pool.create(Math.max(2 * pool.data.length, end));
|
|
119
165
|
data.set(pool.data);
|
|
120
166
|
pool.data = data;
|
|
121
167
|
}
|
|
122
|
-
|
|
168
|
+
for (let position = 0; position < length; position++) {
|
|
169
|
+
pool.data[offset + position] = values[start + position];
|
|
170
|
+
}
|
|
123
171
|
pool.length = Math.max(pool.length, end);
|
|
124
172
|
};
|
|
125
173
|
|
|
@@ -148,20 +196,20 @@ const createNodes = (length: number) => new Int32Array(length).fill(NO_NODE);
|
|
|
148
196
|
|
|
149
197
|
const UNWRITTEN = -1;
|
|
150
198
|
|
|
151
|
-
const isWritten = (behavior: BehaviorGraph
|
|
199
|
+
const isWritten = <State>(behavior: BehaviorGraph<State>, node: number) =>
|
|
152
200
|
(behavior.edgeStarts[node] ?? UNWRITTEN) !== UNWRITTEN;
|
|
153
201
|
|
|
154
|
-
const getNodeSuccessors = (behavior: BehaviorGraph
|
|
202
|
+
const getNodeSuccessors = <State>(behavior: BehaviorGraph<State>, node: number) => {
|
|
155
203
|
const start = behavior.edgeStarts[node];
|
|
156
204
|
return behavior.edgeTargets.data.subarray(start, start + behavior.edgeCounts[node]);
|
|
157
205
|
};
|
|
158
206
|
|
|
159
|
-
const getStateResult = (behavior: BehaviorGraph
|
|
207
|
+
const getStateResult = <State>(behavior: BehaviorGraph<State>, node: number, position: number) =>
|
|
160
208
|
behavior.stateResults.data[
|
|
161
209
|
behavior.nodeStates[node] * behavior.solution.stateChecks.length + position
|
|
162
210
|
] === 1;
|
|
163
211
|
|
|
164
|
-
const pushNode = (behavior: BehaviorGraph
|
|
212
|
+
const pushNode = <State>(behavior: BehaviorGraph<State>, state: number, tableauNode: number) => {
|
|
165
213
|
behavior.nodeStates.push(state);
|
|
166
214
|
behavior.nodeTableaux.push(tableauNode);
|
|
167
215
|
behavior.edgeStarts.push(UNWRITTEN);
|
|
@@ -170,7 +218,7 @@ const pushNode = (behavior: BehaviorGraph, state: number, tableauNode: number) =
|
|
|
170
218
|
return behavior.nodeStates.length - 1;
|
|
171
219
|
};
|
|
172
220
|
|
|
173
|
-
const getStateNodes = (behavior: BehaviorGraph
|
|
221
|
+
const getStateNodes = <State>(behavior: BehaviorGraph<State>, state: number) => {
|
|
174
222
|
const nodes: number[] = [];
|
|
175
223
|
for (
|
|
176
224
|
let node = behavior.firstNodes.data[state] ?? NO_NODE;
|
|
@@ -190,13 +238,11 @@ const UNVISITED = -1;
|
|
|
190
238
|
|
|
191
239
|
const MAXIMUM_LINK = Number.MAX_SAFE_INTEGER;
|
|
192
240
|
|
|
193
|
-
|
|
241
|
+
const getLiveFormula = (
|
|
194
242
|
properties: TemporalProperty[],
|
|
195
243
|
temporals: ScopedExpression[],
|
|
196
244
|
environment: Environment,
|
|
197
|
-
|
|
198
|
-
): LivenessChecker | undefined => {
|
|
199
|
-
if (properties.length === 0) return undefined;
|
|
245
|
+
) => {
|
|
200
246
|
const fairness = temporals.map((item) =>
|
|
201
247
|
toLiveExpression(item.expression, item.scope, environment),
|
|
202
248
|
);
|
|
@@ -206,10 +252,240 @@ export const createLivenessChecker = (
|
|
|
206
252
|
const violation = negations.length === 1 ? negations[0] : createJunction("Or", negations);
|
|
207
253
|
const formula =
|
|
208
254
|
fairness.length === 0 ? violation : createJunction("And", [...fairness, violation]);
|
|
209
|
-
|
|
255
|
+
return { formula, negations };
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
export type LiveAtom = LiveState | LiveEnabled | LiveAction;
|
|
259
|
+
|
|
260
|
+
const getAtomExpressions = (atom: LiveAtom): ScopedExpression[] => {
|
|
261
|
+
switch (atom.kind) {
|
|
262
|
+
case "State":
|
|
263
|
+
return [atom];
|
|
264
|
+
case "Enabled":
|
|
265
|
+
return [{ expression: atom.step, scope: atom.scope }];
|
|
266
|
+
case "Action":
|
|
267
|
+
return [atom.expression, atom.subscript].flatMap((inner) =>
|
|
268
|
+
inner ? [{ expression: inner, scope: atom.scope }] : [],
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
const collectAtoms = (expression: LiveExpression, atoms: Set<LiveAtom>) => {
|
|
274
|
+
switch (expression.kind) {
|
|
275
|
+
case "Boolean":
|
|
276
|
+
return;
|
|
277
|
+
case "State":
|
|
278
|
+
case "Enabled":
|
|
279
|
+
case "Action":
|
|
280
|
+
atoms.add(expression);
|
|
281
|
+
return;
|
|
282
|
+
case "And":
|
|
283
|
+
case "Or":
|
|
284
|
+
expression.operands.forEach((operand) => collectAtoms(operand, atoms));
|
|
285
|
+
return;
|
|
286
|
+
default:
|
|
287
|
+
collectAtoms(expression.body, atoms);
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
// The atoms the checks of the solutions evaluate.
|
|
292
|
+
export const getLiveAtoms = (solutions: Solution[]) => {
|
|
293
|
+
const atoms = new Set<LiveAtom>();
|
|
294
|
+
for (const solution of solutions) {
|
|
295
|
+
[
|
|
296
|
+
...solution.stateChecks,
|
|
297
|
+
...solution.actionChecks,
|
|
298
|
+
...(solution.tableau?.nodes.flatMap((node) => node.statePredicates) ?? []),
|
|
299
|
+
].forEach((check) => collectAtoms(check, atoms));
|
|
300
|
+
}
|
|
301
|
+
return [...atoms];
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
// The expressions the checks of the solutions evaluate.
|
|
305
|
+
export const getLiveExpressions = (solutions: Solution[]) =>
|
|
306
|
+
getLiveAtoms(solutions).flatMap((atom) =>
|
|
307
|
+
getAtomExpressions(atom).map((item) => item.expression),
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
export const createLivenessChecker = (
|
|
311
|
+
properties: TemporalProperty[],
|
|
312
|
+
temporals: ScopedExpression[],
|
|
313
|
+
environment: Environment,
|
|
314
|
+
search: SearchGraph<Value[]>,
|
|
315
|
+
): LivenessChecker | undefined => {
|
|
316
|
+
if (properties.length === 0) return undefined;
|
|
317
|
+
const live = getLiveFormula(properties, temporals, environment);
|
|
318
|
+
// A check evaluated once for a state shows what TLC shows when no check repeats an effect. A
|
|
319
|
+
// definition TLC evaluates as it starts repeats nothing, but a scope can bind any definition.
|
|
320
|
+
const formulaAtoms = new Set<LiveAtom>();
|
|
321
|
+
collectAtoms(live.formula, formulaAtoms);
|
|
322
|
+
const checked = [...formulaAtoms].flatMap(getAtomExpressions);
|
|
323
|
+
const isShared = checked.every((item) => item.scope === undefined)
|
|
324
|
+
? !isExpressionImpure(
|
|
325
|
+
checked.map((item) => item.expression),
|
|
326
|
+
environment,
|
|
327
|
+
"repeated",
|
|
328
|
+
)
|
|
329
|
+
: !hasRepeatedEffects(environment);
|
|
330
|
+
const tracing = { environment, atoms: getInterpretedAtoms(environment) };
|
|
331
|
+
const solutions = getSolutions(live.formula);
|
|
332
|
+
const graph = createLiveGraph(
|
|
333
|
+
solutions,
|
|
334
|
+
{
|
|
335
|
+
atoms: {
|
|
336
|
+
holdsState: (atom, state) => tracing.atoms.holdsState(atom, state),
|
|
337
|
+
holdsAction: (atom, state, next) => tracing.atoms.holdsAction(atom, state, next),
|
|
338
|
+
},
|
|
339
|
+
isShared,
|
|
340
|
+
isSame: isSameState,
|
|
341
|
+
evaluateFrom: (source, evaluate) => {
|
|
342
|
+
environment.runtime.setLivenessSource(source);
|
|
343
|
+
try {
|
|
344
|
+
return evaluate();
|
|
345
|
+
} finally {
|
|
346
|
+
environment.runtime.setLivenessSource(undefined);
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
},
|
|
350
|
+
search,
|
|
351
|
+
environment.runtime.version !== "1.7.4",
|
|
352
|
+
);
|
|
353
|
+
const traceWith = <Result>(replay: Environment | undefined, run: () => Result) => {
|
|
354
|
+
if (replay === undefined) return run();
|
|
355
|
+
tracing.atoms = getInterpretedAtoms(replay);
|
|
356
|
+
try {
|
|
357
|
+
return run();
|
|
358
|
+
} finally {
|
|
359
|
+
tracing.atoms = getInterpretedAtoms(environment);
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
return {
|
|
363
|
+
branches: graph.branches,
|
|
364
|
+
solutions,
|
|
365
|
+
addInitialState: (index, state, replay) =>
|
|
366
|
+
traceWith(replay, () => graph.addInitialState(index, state)),
|
|
367
|
+
addState: (index, state, successors, replay) =>
|
|
368
|
+
traceWith(replay, () => graph.addState(index, state, successors)),
|
|
369
|
+
findViolation: graph.findViolation,
|
|
370
|
+
getViolatedProperties: (path, cycleStart) => [
|
|
371
|
+
...new Set(
|
|
372
|
+
properties
|
|
373
|
+
.filter(
|
|
374
|
+
(_property, position) =>
|
|
375
|
+
!evaluateOnLasso(live.negations[position].body, path, cycleStart, 0, environment),
|
|
376
|
+
)
|
|
377
|
+
.map((property) => property.name),
|
|
378
|
+
),
|
|
379
|
+
],
|
|
380
|
+
};
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
export const createLiveGraph = <State>(
|
|
384
|
+
solutions: Solution[],
|
|
385
|
+
evaluation: LiveEvaluation<State>,
|
|
386
|
+
search: SearchGraph<State>,
|
|
387
|
+
isAcceptingFound: boolean,
|
|
388
|
+
): LiveGraph<State> => {
|
|
210
389
|
const actionIds = new Map<string, number>();
|
|
211
|
-
|
|
390
|
+
let capacityMultiplier = 1;
|
|
391
|
+
const isShared = evaluation.isShared;
|
|
392
|
+
const atoms = evaluation.atoms;
|
|
393
|
+
const evaluateFrom = evaluation.evaluateFrom;
|
|
394
|
+
const stateAtoms = new Map<LiveState | LiveEnabled, number>();
|
|
395
|
+
const atomsById: (LiveState | LiveEnabled)[] = [];
|
|
396
|
+
const getAtomId = (atom: LiveState | LiveEnabled) => {
|
|
397
|
+
const id = stateAtoms.get(atom) ?? stateAtoms.size;
|
|
398
|
+
stateAtoms.set(atom, id);
|
|
399
|
+
atomsById[id] = atom;
|
|
400
|
+
return id;
|
|
401
|
+
};
|
|
402
|
+
const getLiterals = (expression: LiveExpression): number[] | undefined => {
|
|
403
|
+
if (expression.kind === "State" || expression.kind === "Enabled") {
|
|
404
|
+
return [getAtomId(expression) * 2 + 1];
|
|
405
|
+
}
|
|
406
|
+
if (expression.kind === "Not") {
|
|
407
|
+
const body = expression.body;
|
|
408
|
+
return body.kind === "State" || body.kind === "Enabled" ? [getAtomId(body) * 2] : undefined;
|
|
409
|
+
}
|
|
410
|
+
if (expression.kind !== "And") return undefined;
|
|
411
|
+
const operands = expression.operands.map(getLiterals);
|
|
412
|
+
return operands.every((operand) => operand !== undefined) ? operands.flat() : undefined;
|
|
413
|
+
};
|
|
414
|
+
// The rows of states, one after another, hold whether each state atom holds of a state: 1 or 0,
|
|
415
|
+
// or -1 before it is evaluated.
|
|
416
|
+
const createRows = (count: number) => new Int8Array(count * stateAtoms.size).fill(-1);
|
|
417
|
+
// The edge rows of steps hold the result of each action check, shared by the behaviors that
|
|
418
|
+
// check it.
|
|
419
|
+
const createEdgeRows = (count: number) => new Int8Array(count * actionIds.size).fill(-1);
|
|
420
|
+
// Unless the checks share results, each check evaluates its atoms afresh.
|
|
421
|
+
const runCheck = (
|
|
422
|
+
check: Check<State>,
|
|
423
|
+
state: State,
|
|
424
|
+
row: Int8Array,
|
|
425
|
+
offset: number,
|
|
426
|
+
next?: State,
|
|
427
|
+
) => (isShared ? check(state, row, offset, next) : check(state, createRows(1), 0, next));
|
|
428
|
+
const compileCheck = (expression: LiveExpression): Check<State> => {
|
|
429
|
+
switch (expression.kind) {
|
|
430
|
+
case "Boolean": {
|
|
431
|
+
const value = expression.value;
|
|
432
|
+
return () => value;
|
|
433
|
+
}
|
|
434
|
+
case "State":
|
|
435
|
+
case "Enabled": {
|
|
436
|
+
const id = getAtomId(expression);
|
|
437
|
+
return (state, row, offset) => {
|
|
438
|
+
if (row[offset + id] === -1) {
|
|
439
|
+
row[offset + id] = atoms.holdsState(expression, state) ? 1 : 0;
|
|
440
|
+
}
|
|
441
|
+
return row[offset + id] === 1;
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
case "Action": {
|
|
445
|
+
const enabled = expression.enabled && getAtomId(expression.enabled);
|
|
446
|
+
return (state, row, offset, next) =>
|
|
447
|
+
!(enabled !== undefined && row[offset + enabled] === 0) &&
|
|
448
|
+
next !== undefined &&
|
|
449
|
+
atoms.holdsAction(expression, state, next);
|
|
450
|
+
}
|
|
451
|
+
case "Not": {
|
|
452
|
+
const body = compileCheck(expression.body);
|
|
453
|
+
return (state, row, offset, next) => !body(state, row, offset, next);
|
|
454
|
+
}
|
|
455
|
+
case "And": {
|
|
456
|
+
const operands = expression.operands.map(compileCheck);
|
|
457
|
+
return (state, row, offset, next) =>
|
|
458
|
+
operands.every((operand) => operand(state, row, offset, next));
|
|
459
|
+
}
|
|
460
|
+
case "Or": {
|
|
461
|
+
const operands = expression.operands.map(compileCheck);
|
|
462
|
+
return (state, row, offset, next) =>
|
|
463
|
+
operands.some((operand) => operand(state, row, offset, next));
|
|
464
|
+
}
|
|
465
|
+
case "Next": {
|
|
466
|
+
const body = compileCheck(expression.body);
|
|
467
|
+
return (state, _row, _offset, next) => body(next ?? state, createRows(1), 0, undefined);
|
|
468
|
+
}
|
|
469
|
+
case "Always":
|
|
470
|
+
case "Eventually":
|
|
471
|
+
return () => {
|
|
472
|
+
throw new TlaEvaluationError("TLC cannot evaluate a temporal formula in a single step");
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
const behaviors = solutions.map((solution): BehaviorGraph<State> => ({
|
|
212
477
|
solution,
|
|
478
|
+
checks: {
|
|
479
|
+
states: solution.stateChecks.map(compileCheck),
|
|
480
|
+
actions: solution.actionChecks.map(compileCheck),
|
|
481
|
+
nodes:
|
|
482
|
+
solution.tableau?.nodes.map((node) => {
|
|
483
|
+
const literals = isShared
|
|
484
|
+
? getLiterals({ kind: "And", operands: node.statePredicates })
|
|
485
|
+
: undefined;
|
|
486
|
+
return literals ? Int32Array.from(literals) : node.statePredicates.map(compileCheck);
|
|
487
|
+
}) ?? [],
|
|
488
|
+
},
|
|
213
489
|
actionIds: Int32Array.from(solution.actionChecks, (predicate) => {
|
|
214
490
|
const key = getTermKey(predicate);
|
|
215
491
|
const actionId = actionIds.get(key) ?? actionIds.size;
|
|
@@ -231,83 +507,85 @@ export const createLivenessChecker = (
|
|
|
231
507
|
isDone: [],
|
|
232
508
|
errorNode: undefined,
|
|
233
509
|
}));
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
environment.runtime.setLivenessSource(undefined);
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
|
-
const evaluateState = (predicate: LiveExpression, state: Value[]) =>
|
|
254
|
-
evaluateLive(
|
|
255
|
-
predicate,
|
|
256
|
-
state,
|
|
257
|
-
undefined,
|
|
258
|
-
evaluationEnvironment,
|
|
259
|
-
isShared ? getStateCache(state) : new Map(),
|
|
260
|
-
);
|
|
261
|
-
const checkState = (behavior: BehaviorGraph, source: number, state: Value[]) =>
|
|
262
|
-
evaluateFrom(source, () =>
|
|
263
|
-
Uint8Array.from(behavior.solution.stateChecks, (predicate) =>
|
|
264
|
-
evaluateState(predicate, state) ? 1 : 0,
|
|
265
|
-
),
|
|
266
|
-
);
|
|
510
|
+
const checkState = (
|
|
511
|
+
behavior: BehaviorGraph<State>,
|
|
512
|
+
source: number,
|
|
513
|
+
state: State,
|
|
514
|
+
row: Int8Array,
|
|
515
|
+
offset: number,
|
|
516
|
+
) =>
|
|
517
|
+
evaluateFrom(source, () => {
|
|
518
|
+
const checks = behavior.checks.states;
|
|
519
|
+
const results = new Uint8Array(checks.length);
|
|
520
|
+
checks.forEach((check, position) => {
|
|
521
|
+
results[position] = runCheck(check, state, row, offset) ? 1 : 0;
|
|
522
|
+
});
|
|
523
|
+
return results;
|
|
524
|
+
});
|
|
525
|
+
// Writes the result of each action check of the step to successor at resultOffset in results.
|
|
267
526
|
const checkAction = (
|
|
268
|
-
behavior: BehaviorGraph
|
|
527
|
+
behavior: BehaviorGraph<State>,
|
|
269
528
|
source: number,
|
|
270
|
-
state:
|
|
271
|
-
|
|
529
|
+
state: State,
|
|
530
|
+
row: Int8Array,
|
|
531
|
+
offset: number,
|
|
532
|
+
successor: State,
|
|
533
|
+
edges: Int8Array,
|
|
534
|
+
edgeOffset: number,
|
|
535
|
+
results: Uint8Array,
|
|
536
|
+
resultOffset: number,
|
|
272
537
|
) =>
|
|
273
538
|
evaluateFrom(source, () => {
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}
|
|
280
|
-
const stateCache = getStateCache(state);
|
|
281
|
-
const results = sharedActions.get(state) ?? new Map<Value[], Int8Array>();
|
|
282
|
-
sharedActions.set(state, results);
|
|
283
|
-
const known = results.get(successor) ?? new Int8Array(actionIds.size).fill(-1);
|
|
284
|
-
results.set(successor, known);
|
|
285
|
-
return Uint8Array.from(behavior.actionIds, (actionId, position) => {
|
|
286
|
-
if (known[actionId] === -1) {
|
|
287
|
-
known[actionId] = evaluateLive(
|
|
288
|
-
predicates[position],
|
|
539
|
+
const actions = behavior.checks.actions;
|
|
540
|
+
for (let position = 0; position < actions.length; position++) {
|
|
541
|
+
if (!isShared) {
|
|
542
|
+
results[resultOffset + position] = runCheck(
|
|
543
|
+
actions[position],
|
|
289
544
|
state,
|
|
545
|
+
row,
|
|
546
|
+
offset,
|
|
290
547
|
successor,
|
|
291
|
-
evaluationEnvironment,
|
|
292
|
-
stateCache,
|
|
293
548
|
)
|
|
294
549
|
? 1
|
|
295
550
|
: 0;
|
|
551
|
+
continue;
|
|
296
552
|
}
|
|
297
|
-
|
|
298
|
-
|
|
553
|
+
const edge = edgeOffset + behavior.actionIds[position];
|
|
554
|
+
if (edges[edge] === -1)
|
|
555
|
+
edges[edge] = actions[position](state, row, offset, successor) ? 1 : 0;
|
|
556
|
+
results[resultOffset + position] = edges[edge];
|
|
557
|
+
}
|
|
299
558
|
});
|
|
559
|
+
const holdsNode = (
|
|
560
|
+
behavior: BehaviorGraph<State>,
|
|
561
|
+
node: number,
|
|
562
|
+
state: State,
|
|
563
|
+
row: Int8Array,
|
|
564
|
+
offset: number,
|
|
565
|
+
) => {
|
|
566
|
+
const checks = behavior.checks.nodes[node];
|
|
567
|
+
if (!(checks instanceof Int32Array)) {
|
|
568
|
+
return checks.every((check) => runCheck(check, state, row, offset));
|
|
569
|
+
}
|
|
570
|
+
for (let position = 0; position < checks.length; position++) {
|
|
571
|
+
const literal: number = checks[position];
|
|
572
|
+
const cell = offset + (literal >> 1);
|
|
573
|
+
if (row[cell] === -1) row[cell] = atoms.holdsState(atomsById[literal >> 1], state) ? 1 : 0;
|
|
574
|
+
if (row[cell] !== (literal & 1)) return false;
|
|
575
|
+
}
|
|
576
|
+
return true;
|
|
577
|
+
};
|
|
300
578
|
const isConsistent = (
|
|
301
|
-
|
|
579
|
+
behavior: BehaviorGraph<State>,
|
|
302
580
|
node: number,
|
|
303
581
|
source: number | undefined,
|
|
304
|
-
state:
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
582
|
+
state: State,
|
|
583
|
+
row: Int8Array,
|
|
584
|
+
offset: number,
|
|
585
|
+
) => evaluateFrom(source, () => holdsNode(behavior, node, state, row, offset));
|
|
586
|
+
|
|
309
587
|
const isAccepting = (tableau: Tableau, node: number) => {
|
|
310
|
-
if (
|
|
588
|
+
if (!isAcceptingFound) return false;
|
|
311
589
|
const tableauNode = tableau.nodes[node];
|
|
312
590
|
return (
|
|
313
591
|
tableauNode.particle.length === 0 &&
|
|
@@ -316,13 +594,13 @@ export const createLivenessChecker = (
|
|
|
316
594
|
);
|
|
317
595
|
};
|
|
318
596
|
|
|
319
|
-
const getNodeId = (behavior: BehaviorGraph
|
|
597
|
+
const getNodeId = (behavior: BehaviorGraph<State>, state: number, tableauNode: number) => {
|
|
320
598
|
if (!behavior.solution.tableau) return state;
|
|
321
599
|
const slots = behavior.nodeIds.slots;
|
|
322
600
|
const slot = getNodeSlot(behavior.nodeIds, state, tableauNode);
|
|
323
601
|
return slots[slot] === 0 ? undefined : slots[slot + 2];
|
|
324
602
|
};
|
|
325
|
-
const recordNode = (behavior: BehaviorGraph
|
|
603
|
+
const recordNode = (behavior: BehaviorGraph<State>, state: number, tableauNode: number) => {
|
|
326
604
|
const node = pushNode(behavior, state, tableauNode);
|
|
327
605
|
const table = behavior.nodeIds;
|
|
328
606
|
if (++table.size * 2 > table.slots.length / 3) {
|
|
@@ -345,18 +623,26 @@ export const createLivenessChecker = (
|
|
|
345
623
|
writeToPool(behavior.lastNodes, state, [node]);
|
|
346
624
|
return node;
|
|
347
625
|
};
|
|
626
|
+
// The action results of the edge to each target are at its position in actions.
|
|
348
627
|
const writeNode = (
|
|
349
|
-
behavior: BehaviorGraph
|
|
628
|
+
behavior: BehaviorGraph<State>,
|
|
350
629
|
node: number,
|
|
351
630
|
targets: number[],
|
|
352
|
-
|
|
631
|
+
actionResults: Uint8Array,
|
|
632
|
+
actions: number[],
|
|
353
633
|
stateResults: Uint8Array,
|
|
354
634
|
) => {
|
|
355
635
|
const start = behavior.edgeTargets.length;
|
|
356
636
|
const actionCount = behavior.solution.actionChecks.length;
|
|
357
637
|
writeToPool(behavior.edgeTargets, start, targets);
|
|
358
|
-
actions.forEach((
|
|
359
|
-
writeToPool(
|
|
638
|
+
actions.forEach((position, edge) =>
|
|
639
|
+
writeToPool(
|
|
640
|
+
behavior.edgeActions,
|
|
641
|
+
(start + edge) * actionCount,
|
|
642
|
+
actionResults,
|
|
643
|
+
position * actionCount,
|
|
644
|
+
actionCount,
|
|
645
|
+
),
|
|
360
646
|
);
|
|
361
647
|
writeToPool(
|
|
362
648
|
behavior.stateResults,
|
|
@@ -368,57 +654,68 @@ export const createLivenessChecker = (
|
|
|
368
654
|
};
|
|
369
655
|
|
|
370
656
|
// TLC iterates a state's successors and the state itself in the slot order of a SetOfStates, a hash set whose capacity grows with every set that outgrows it.
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
|
|
657
|
+
// Each slot holds a candidate's position plus one, or 0 when it is empty.
|
|
658
|
+
const successorSet = { slots: new Int32Array(0) };
|
|
659
|
+
const getSuccessorSet = (index: number, state: State, successors: LiveSuccessor<State>[]) => {
|
|
660
|
+
const candidates = [...successors, { index, state }];
|
|
661
|
+
const capacity = SUCCESSOR_CAPACITY * capacityMultiplier;
|
|
662
|
+
successorSet.slots =
|
|
663
|
+
successorSet.slots.length === capacity
|
|
664
|
+
? successorSet.slots.fill(0)
|
|
665
|
+
: new Int32Array(capacity);
|
|
666
|
+
const insert = (position: number) => {
|
|
667
|
+
const slots = successorSet.slots;
|
|
668
|
+
const candidate = candidates[position];
|
|
377
669
|
for (
|
|
378
|
-
let slot = (search.getFingerprint(
|
|
670
|
+
let slot = (search.getFingerprint(candidate) & 0x7fffffff) % slots.length;
|
|
379
671
|
;
|
|
380
672
|
slot = (slot + 1) % slots.length
|
|
381
673
|
) {
|
|
382
674
|
const entry = slots[slot];
|
|
383
|
-
if (entry ===
|
|
384
|
-
slots[slot] =
|
|
675
|
+
if (entry === 0) {
|
|
676
|
+
slots[slot] = position + 1;
|
|
385
677
|
return true;
|
|
386
678
|
}
|
|
387
|
-
|
|
679
|
+
const stored = candidates[entry - 1];
|
|
680
|
+
if (stored.index === candidate.index && evaluation.isSame(stored.state, candidate.state))
|
|
388
681
|
return false;
|
|
389
682
|
}
|
|
390
683
|
};
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
684
|
+
let count = 0;
|
|
685
|
+
for (let position = 0; position < candidates.length; position++) {
|
|
686
|
+
if (count >= successorSet.slots.length >> 1) {
|
|
687
|
+
const old = successorSet.slots;
|
|
688
|
+
successorSet.slots = new Int32Array(2 * old.length + 1);
|
|
689
|
+
for (const entry of old) if (entry !== 0) insert(entry - 1);
|
|
396
690
|
}
|
|
397
|
-
if (
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
return
|
|
691
|
+
if (insert(position)) count++;
|
|
692
|
+
}
|
|
693
|
+
if (successorSet.slots.length > capacity) capacityMultiplier++;
|
|
694
|
+
const set: LiveSuccessor<State>[] = [];
|
|
695
|
+
for (const entry of successorSet.slots) if (entry !== 0) set.push(candidates[entry - 1]);
|
|
696
|
+
return set;
|
|
403
697
|
};
|
|
404
698
|
|
|
405
699
|
const expandLate = (
|
|
406
|
-
behavior: BehaviorGraph
|
|
700
|
+
behavior: BehaviorGraph<State>,
|
|
407
701
|
tableau: Tableau,
|
|
408
|
-
state:
|
|
702
|
+
state: State,
|
|
409
703
|
index: number,
|
|
410
704
|
node: number,
|
|
705
|
+
row: Int8Array,
|
|
706
|
+
offset: number,
|
|
411
707
|
) => {
|
|
412
|
-
const stateResults = checkState(behavior, index, state);
|
|
708
|
+
const stateResults = checkState(behavior, index, state, row, offset);
|
|
413
709
|
const tableauNode = tableau.nodes[behavior.nodeTableaux[node]];
|
|
414
|
-
const
|
|
710
|
+
const actionCount = behavior.checks.actions.length;
|
|
711
|
+
const actions: number[] = [];
|
|
415
712
|
const successors: number[] = [];
|
|
416
|
-
const
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
713
|
+
const selfResults = new Uint8Array(actionCount);
|
|
714
|
+
if (tableauNode.successors.length > 0) {
|
|
715
|
+
checkAction(behavior, index, state, row, offset, state, createEdgeRows(1), 0, selfResults, 0);
|
|
716
|
+
}
|
|
420
717
|
for (const next of tableauNode.successors) {
|
|
421
|
-
if (!isConsistent(
|
|
718
|
+
if (!isConsistent(behavior, next, index, state, row, offset)) continue;
|
|
422
719
|
if (
|
|
423
720
|
isAccepting(tableau, next) &&
|
|
424
721
|
behavior.errorNode === undefined &&
|
|
@@ -431,60 +728,97 @@ export const createLivenessChecker = (
|
|
|
431
728
|
if (existing !== undefined && successors.includes(existing)) continue;
|
|
432
729
|
const target = existing ?? recordNode(behavior, index, next);
|
|
433
730
|
successors.push(target);
|
|
434
|
-
actions.push(
|
|
435
|
-
if (existing === undefined) expandLate(behavior, tableau, state, index, target);
|
|
731
|
+
actions.push(0);
|
|
732
|
+
if (existing === undefined) expandLate(behavior, tableau, state, index, target, row, offset);
|
|
436
733
|
}
|
|
437
|
-
|
|
438
|
-
|
|
734
|
+
const nextStates = search.getSuccessors(index, state);
|
|
735
|
+
// The results of the step to the state itself come first, then those of each successor.
|
|
736
|
+
const actionResults = new Uint8Array((nextStates.length + 1) * actionCount);
|
|
737
|
+
actionResults.set(selfResults);
|
|
738
|
+
const edges = createEdgeRows(nextStates.length);
|
|
739
|
+
nextStates.forEach((successor, position) => {
|
|
740
|
+
const successorRow = createRows(1);
|
|
741
|
+
checkAction(
|
|
742
|
+
behavior,
|
|
743
|
+
index,
|
|
744
|
+
state,
|
|
745
|
+
row,
|
|
746
|
+
offset,
|
|
747
|
+
successor.state,
|
|
748
|
+
edges,
|
|
749
|
+
position * actionIds.size,
|
|
750
|
+
actionResults,
|
|
751
|
+
(position + 1) * actionCount,
|
|
752
|
+
);
|
|
439
753
|
const isDone = behavior.isDone[successor.index] === true;
|
|
440
754
|
for (const next of tableauNode.successors) {
|
|
441
|
-
if (!isConsistent(
|
|
755
|
+
if (!isConsistent(behavior, next, index, successor.state, successorRow, 0)) continue;
|
|
442
756
|
// Deviation from TLC: TLC records the node of a successor the search never stored, which it never expands.
|
|
443
757
|
if (successor.index === -1) continue;
|
|
444
758
|
const existing = getNodeId(behavior, successor.index, next);
|
|
445
759
|
if (existing !== undefined && successors.includes(existing)) continue;
|
|
446
760
|
const target = existing ?? recordNode(behavior, successor.index, next);
|
|
447
761
|
successors.push(target);
|
|
448
|
-
actions.push(
|
|
762
|
+
actions.push(position + 1);
|
|
449
763
|
if (existing === undefined && isDone) {
|
|
450
|
-
expandLate(behavior, tableau, successor.state, successor.index, target);
|
|
764
|
+
expandLate(behavior, tableau, successor.state, successor.index, target, successorRow, 0);
|
|
451
765
|
}
|
|
452
766
|
}
|
|
767
|
+
});
|
|
768
|
+
if (successors.length > 0) {
|
|
769
|
+
writeNode(behavior, node, successors, actionResults, actions, stateResults);
|
|
453
770
|
}
|
|
454
|
-
if (successors.length > 0) writeNode(behavior, node, successors, actions, stateResults);
|
|
455
771
|
};
|
|
456
772
|
|
|
457
773
|
const addTableauState = (
|
|
458
|
-
behavior: BehaviorGraph
|
|
774
|
+
behavior: BehaviorGraph<State>,
|
|
459
775
|
tableau: Tableau,
|
|
460
|
-
set: LiveSuccessor[],
|
|
461
|
-
|
|
776
|
+
set: LiveSuccessor<State>[],
|
|
777
|
+
rows: Int8Array,
|
|
778
|
+
actionResults: Uint8Array,
|
|
462
779
|
stateResults: Uint8Array,
|
|
463
780
|
index: number,
|
|
464
781
|
) => {
|
|
465
|
-
const
|
|
466
|
-
|
|
467
|
-
);
|
|
782
|
+
const atomCount = stateAtoms.size;
|
|
783
|
+
// Whether each successor is consistent with each tableau node, node by node.
|
|
784
|
+
const consistency = new Uint8Array(tableau.nodes.length * set.length);
|
|
785
|
+
evaluateFrom(index, () => {
|
|
786
|
+
for (let node = 0; node < tableau.nodes.length; node++) {
|
|
787
|
+
for (let position = 0; position < set.length; position++) {
|
|
788
|
+
if (holdsNode(behavior, node, set[position].state, rows, position * atomCount)) {
|
|
789
|
+
consistency[node * set.length + position] = 1;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
});
|
|
468
794
|
behavior.isDone[index] = true;
|
|
469
795
|
// TLC expands the nodes recorded before the loop, not the ones the loop records.
|
|
470
796
|
for (const node of getStateNodes(behavior, index)) {
|
|
471
797
|
const successors: number[] = [];
|
|
472
|
-
const actions:
|
|
798
|
+
const actions: number[] = [];
|
|
473
799
|
set.forEach((successor, position) => {
|
|
474
800
|
const isDone = behavior.isDone[successor.index] === true;
|
|
475
801
|
for (const next of tableau.nodes[behavior.nodeTableaux[node]].successors) {
|
|
476
|
-
if (
|
|
802
|
+
if (consistency[next * set.length + position] === 0) continue;
|
|
477
803
|
const existing = getNodeId(behavior, successor.index, next);
|
|
478
804
|
if (existing !== undefined && successors.includes(existing)) continue;
|
|
479
805
|
const target = existing ?? recordNode(behavior, successor.index, next);
|
|
480
806
|
successors.push(target);
|
|
481
|
-
actions.push(
|
|
807
|
+
actions.push(position);
|
|
482
808
|
if (existing === undefined && isDone) {
|
|
483
|
-
expandLate(
|
|
809
|
+
expandLate(
|
|
810
|
+
behavior,
|
|
811
|
+
tableau,
|
|
812
|
+
successor.state,
|
|
813
|
+
successor.index,
|
|
814
|
+
target,
|
|
815
|
+
rows,
|
|
816
|
+
position * atomCount,
|
|
817
|
+
);
|
|
484
818
|
}
|
|
485
819
|
}
|
|
486
820
|
});
|
|
487
|
-
writeNode(behavior, node, successors, actions, stateResults);
|
|
821
|
+
writeNode(behavior, node, successors, actionResults, actions, stateResults);
|
|
488
822
|
}
|
|
489
823
|
return behavior.errorNode === undefined
|
|
490
824
|
? undefined
|
|
@@ -492,24 +826,24 @@ export const createLivenessChecker = (
|
|
|
492
826
|
};
|
|
493
827
|
|
|
494
828
|
const addPlainState = (
|
|
495
|
-
behavior: BehaviorGraph
|
|
496
|
-
set: LiveSuccessor[],
|
|
497
|
-
actionResults: Uint8Array
|
|
829
|
+
behavior: BehaviorGraph<State>,
|
|
830
|
+
set: LiveSuccessor<State>[],
|
|
831
|
+
actionResults: Uint8Array,
|
|
498
832
|
stateResults: Uint8Array,
|
|
499
833
|
index: number,
|
|
500
834
|
) => {
|
|
501
835
|
while (behavior.nodeStates.length <= index) pushNode(behavior, behavior.nodeStates.length, -1);
|
|
502
836
|
const successors: number[] = [];
|
|
503
|
-
const actions:
|
|
837
|
+
const actions: number[] = [];
|
|
504
838
|
set.forEach((successor, position) => {
|
|
505
839
|
if (isWritten(behavior, successor.index) && successors.includes(successor.index)) return;
|
|
506
840
|
successors.push(successor.index);
|
|
507
|
-
actions.push(
|
|
841
|
+
actions.push(position);
|
|
508
842
|
});
|
|
509
|
-
writeNode(behavior, index, successors, actions, stateResults);
|
|
843
|
+
writeNode(behavior, index, successors, actionResults, actions, stateResults);
|
|
510
844
|
};
|
|
511
845
|
|
|
512
|
-
const getPath = (behavior: BehaviorGraph
|
|
846
|
+
const getPath = (behavior: BehaviorGraph<State>, target: number) => {
|
|
513
847
|
if (behavior.initial.includes(target)) return [target];
|
|
514
848
|
const parents = new Map<number, number>();
|
|
515
849
|
const queue: number[] = [];
|
|
@@ -535,7 +869,7 @@ export const createLivenessChecker = (
|
|
|
535
869
|
throw new TlaEvaluationError(`Couldn't re-create liveness trace (path) starting at: ${target}`);
|
|
536
870
|
};
|
|
537
871
|
|
|
538
|
-
const getStatePath = (behavior: BehaviorGraph
|
|
872
|
+
const getStatePath = (behavior: BehaviorGraph<State>, target: number) =>
|
|
539
873
|
removeRepeats(
|
|
540
874
|
getPath(behavior, target)
|
|
541
875
|
.reverse()
|
|
@@ -543,7 +877,7 @@ export const createLivenessChecker = (
|
|
|
543
877
|
);
|
|
544
878
|
|
|
545
879
|
const findLassoInModel = (
|
|
546
|
-
behavior: BehaviorGraph
|
|
880
|
+
behavior: BehaviorGraph<State>,
|
|
547
881
|
model: Solution["models"][number],
|
|
548
882
|
): Lasso | undefined => {
|
|
549
883
|
const solution = behavior.solution;
|
|
@@ -768,58 +1102,63 @@ export const createLivenessChecker = (
|
|
|
768
1102
|
|
|
769
1103
|
return {
|
|
770
1104
|
branches: behaviors.length,
|
|
771
|
-
addInitialState: (index, state
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
behavior.initial.push(
|
|
785
|
-
getNodeId(behavior, index, node) ?? recordNode(behavior, index, node),
|
|
786
|
-
);
|
|
787
|
-
}
|
|
1105
|
+
addInitialState: (index, state) => {
|
|
1106
|
+
const row = createRows(1);
|
|
1107
|
+
for (const behavior of behaviors) {
|
|
1108
|
+
const tableau = behavior.solution.tableau;
|
|
1109
|
+
if (!tableau) {
|
|
1110
|
+
behavior.initial.push(index);
|
|
1111
|
+
continue;
|
|
1112
|
+
}
|
|
1113
|
+
for (let node = 0; node < tableau.initialCount; node++) {
|
|
1114
|
+
if (!isConsistent(behavior, node, undefined, state, row, 0)) continue;
|
|
1115
|
+
behavior.initial.push(
|
|
1116
|
+
getNodeId(behavior, index, node) ?? recordNode(behavior, index, node),
|
|
1117
|
+
);
|
|
788
1118
|
}
|
|
789
|
-
} finally {
|
|
790
|
-
evaluationEnvironment = environment;
|
|
791
1119
|
}
|
|
792
1120
|
},
|
|
793
|
-
addState: (index, state, successors
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
const tableau = behavior.solution.tableau;
|
|
805
|
-
if (!tableau) {
|
|
806
|
-
addPlainState(behavior, set, actionResults, stateResults, index);
|
|
807
|
-
continue;
|
|
808
|
-
}
|
|
809
|
-
const accepted = addTableauState(
|
|
1121
|
+
addState: (index, state, successors) => {
|
|
1122
|
+
const set = getSuccessorSet(index, state, successors);
|
|
1123
|
+
const rows = createRows(set.length);
|
|
1124
|
+
// The set holds the state itself, as a successor of the same index.
|
|
1125
|
+
const offset = set.findIndex((successor) => successor.index === index) * stateAtoms.size;
|
|
1126
|
+
const edges = createEdgeRows(set.length);
|
|
1127
|
+
for (const behavior of behaviors) {
|
|
1128
|
+
const actionCount = behavior.checks.actions.length;
|
|
1129
|
+
const actionResults = new Uint8Array(set.length * actionCount);
|
|
1130
|
+
set.forEach((successor, position) =>
|
|
1131
|
+
checkAction(
|
|
810
1132
|
behavior,
|
|
811
|
-
tableau,
|
|
812
|
-
set,
|
|
813
|
-
actionResults,
|
|
814
|
-
stateResults,
|
|
815
1133
|
index,
|
|
816
|
-
|
|
817
|
-
|
|
1134
|
+
state,
|
|
1135
|
+
rows,
|
|
1136
|
+
offset,
|
|
1137
|
+
successor.state,
|
|
1138
|
+
edges,
|
|
1139
|
+
position * actionIds.size,
|
|
1140
|
+
actionResults,
|
|
1141
|
+
position * actionCount,
|
|
1142
|
+
),
|
|
1143
|
+
);
|
|
1144
|
+
const stateResults = checkState(behavior, index, state, rows, offset);
|
|
1145
|
+
const tableau = behavior.solution.tableau;
|
|
1146
|
+
if (!tableau) {
|
|
1147
|
+
addPlainState(behavior, set, actionResults, stateResults, index);
|
|
1148
|
+
continue;
|
|
818
1149
|
}
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
1150
|
+
const accepted = addTableauState(
|
|
1151
|
+
behavior,
|
|
1152
|
+
tableau,
|
|
1153
|
+
set,
|
|
1154
|
+
rows,
|
|
1155
|
+
actionResults,
|
|
1156
|
+
stateResults,
|
|
1157
|
+
index,
|
|
1158
|
+
);
|
|
1159
|
+
if (accepted) return accepted;
|
|
822
1160
|
}
|
|
1161
|
+
return undefined;
|
|
823
1162
|
},
|
|
824
1163
|
findViolation: () => {
|
|
825
1164
|
for (const behavior of behaviors) {
|
|
@@ -830,15 +1169,5 @@ export const createLivenessChecker = (
|
|
|
830
1169
|
}
|
|
831
1170
|
return undefined;
|
|
832
1171
|
},
|
|
833
|
-
getViolatedProperties: (path, cycleStart) => [
|
|
834
|
-
...new Set(
|
|
835
|
-
properties
|
|
836
|
-
.filter(
|
|
837
|
-
(_property, position) =>
|
|
838
|
-
!evaluateOnLasso(negations[position].body, path, cycleStart, 0, environment),
|
|
839
|
-
)
|
|
840
|
-
.map((property) => property.name),
|
|
841
|
-
),
|
|
842
|
-
],
|
|
843
1172
|
};
|
|
844
1173
|
};
|