tla-ts 0.0.3-dev.bffbba3 → 0.0.3-dev.c2b256f
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/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +150 -8
- package/dist/index.d.ts +150 -8
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +2 -2
- package/dist/parallel.cjs +1 -1
- package/dist/parallel.js +2 -2
- package/dist/run-cli.cjs +1351 -20
- package/dist/run-cli.js +1351 -20
- package/dist/transfer.cjs +86 -28
- package/dist/transfer.js +86 -28
- package/package.json +5 -1
- package/src/ast.ts +57 -6
- package/src/bags.ts +4 -7
- package/src/builtins.ts +29 -11
- package/src/bundled-modules.ts +3 -3
- package/src/canonical.ts +4 -3
- package/src/check.ts +1358 -219
- package/src/cli.ts +8 -1
- package/src/codegen.ts +68 -18
- package/src/config.ts +252 -179
- package/src/environment.ts +457 -132
- package/src/errors.ts +217 -3
- package/src/evaluate.ts +724 -117
- package/src/exit-codes.ts +5 -4
- package/src/index.ts +1 -0
- package/src/instances.ts +4 -2
- package/src/java-overrides.ts +104 -25
- package/src/levels.ts +183 -37
- package/src/lexer.ts +112 -29
- package/src/live-check.ts +220 -84
- package/src/liveness.ts +192 -65
- package/src/obligation-expression.ts +2 -2
- package/src/obligation-source.ts +2 -0
- package/src/parallel-worker.ts +8 -3
- package/src/parallel.ts +56 -5
- package/src/parser.ts +445 -147
- package/src/pcal-ast.ts +770 -0
- package/src/pcal-parse.ts +1523 -0
- package/src/pcal-tokenize.ts +516 -0
- package/src/pcal-translate.ts +1230 -0
- package/src/pcal-validate.ts +454 -0
- package/src/randomization.ts +24 -7
- package/src/resolve.ts +1439 -411
- package/src/run-cli.ts +1167 -155
- package/src/runtime.ts +16 -0
- package/src/sany-builtins.ts +147 -0
- package/src/sany-generator.ts +3112 -0
- package/src/sany-levels.ts +1208 -0
- package/src/sany-lexer.ts +545 -0
- package/src/sany-linter.ts +122 -0
- package/src/sany-modules.ts +1398 -0
- package/src/sany-nodes.ts +463 -0
- package/src/sany-parse-error.ts +2161 -0
- package/src/sany-report.ts +354 -0
- package/src/sany-selectors.ts +738 -0
- package/src/sany-source.ts +248 -0
- package/src/sany-xml.ts +1017 -0
- package/src/spec-description.ts +26 -7
- package/src/standard-modules.ts +203 -146
- package/src/standard-ranges.ts +116 -0
- package/src/state-graph.ts +29 -6
- package/src/subexpressions.ts +221 -161
- package/src/substitution-levels.ts +38 -17
- package/src/successors.ts +162 -114
- package/src/symmetry.ts +180 -52
- package/src/tableau.ts +4 -2
- package/src/tlc-ext.ts +13 -17
- package/src/tlc-messages.ts +329 -0
- package/src/tlc-module.ts +46 -18
- package/src/tlc-order.ts +56 -6
- package/src/tlc-random.ts +37 -9
- package/src/tlc-replay.ts +655 -0
- package/src/tlc-summary.ts +20 -5
- package/src/tlc-version.ts +18 -0
- package/src/transfer.ts +15 -3
- package/src/value-sources.ts +29 -0
- package/src/values.ts +684 -204
package/src/live-check.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TlaEvaluationError } from "./errors";
|
|
2
2
|
import { hasRepeatedEffects, type Environment } from "./evaluate";
|
|
3
3
|
import {
|
|
4
|
+
createTautologyError,
|
|
4
5
|
evaluateLive,
|
|
5
|
-
TAUTOLOGY_MESSAGE,
|
|
6
6
|
evaluateOnLasso,
|
|
7
7
|
toLiveExpression,
|
|
8
8
|
type ScopedExpression,
|
|
@@ -28,18 +28,38 @@ export interface LiveSuccessor {
|
|
|
28
28
|
export interface Lasso {
|
|
29
29
|
prefix: number[];
|
|
30
30
|
cycle: number[];
|
|
31
|
+
// Whether the solution that the lasso violates constrains the cycle, as a liveness property does.
|
|
32
|
+
// TLC warns that a stuttering counterexample to one may come from a missing fairness constraint.
|
|
33
|
+
isCycleConstrained: boolean;
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
export interface LivenessChecker {
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
// How many solutions of the negated properties TLC checks, which it calls branches.
|
|
38
|
+
branches: number;
|
|
39
|
+
// With a tracing environment, the checks record their call stack as TLC's replay of a failed
|
|
40
|
+
// check does.
|
|
41
|
+
addInitialState: (index: number, state: Value[], tracing?: Environment) => void;
|
|
42
|
+
addState: (
|
|
43
|
+
index: number,
|
|
44
|
+
state: Value[],
|
|
45
|
+
successors: LiveSuccessor[],
|
|
46
|
+
tracing?: Environment,
|
|
47
|
+
) => number[] | undefined;
|
|
36
48
|
findViolation: () => Lasso | undefined;
|
|
37
49
|
getViolatedProperties: (path: Value[][], cycleStart: number) => string[];
|
|
38
50
|
}
|
|
39
51
|
|
|
40
52
|
export interface LiveGraph {
|
|
41
|
-
getFingerprint: (
|
|
42
|
-
getSuccessors: (state: Value[]) => LiveSuccessor[];
|
|
53
|
+
getFingerprint: (successor: LiveSuccessor) => number;
|
|
54
|
+
getSuccessors: (index: number, state: Value[]) => LiveSuccessor[];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Numbers in a typed array that doubles as it fills, so a graph of millions of nodes takes a few
|
|
58
|
+
// bytes for each.
|
|
59
|
+
interface Pool<Data extends Int32Array | Uint8Array> {
|
|
60
|
+
data: Data;
|
|
61
|
+
length: number;
|
|
62
|
+
create: (length: number) => Data;
|
|
43
63
|
}
|
|
44
64
|
|
|
45
65
|
// TLC's behavior graph for one solution: a node per state, or per state and tableau node.
|
|
@@ -49,34 +69,116 @@ interface Check {
|
|
|
49
69
|
actionIds: Int32Array;
|
|
50
70
|
nodeStates: number[];
|
|
51
71
|
nodeTableaux: number[];
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
72
|
+
// Where a node's edges start in edgeTargets, or UNWRITTEN until TLC writes the node with its
|
|
73
|
+
// successors, and how many it has.
|
|
74
|
+
edgeStarts: number[];
|
|
75
|
+
edgeCounts: number[];
|
|
76
|
+
edgeTargets: Pool<Int32Array>;
|
|
77
|
+
// The results of the action checks on each edge, and of the state checks on each state, which
|
|
78
|
+
// are the same for every node of the state.
|
|
79
|
+
edgeActions: Pool<Uint8Array>;
|
|
80
|
+
stateResults: Pool<Uint8Array>;
|
|
56
81
|
initial: number[];
|
|
57
|
-
|
|
58
|
-
|
|
82
|
+
// The nodes of each state in the order the check records them, a list through nextSiblings.
|
|
83
|
+
firstNodes: Pool<Int32Array>;
|
|
84
|
+
lastNodes: Pool<Int32Array>;
|
|
85
|
+
nextSiblings: number[];
|
|
59
86
|
isDone: boolean[];
|
|
60
87
|
errorNode: number | undefined;
|
|
61
88
|
}
|
|
62
89
|
|
|
90
|
+
const containsAlways = (expression: LiveExpression): boolean => {
|
|
91
|
+
switch (expression.kind) {
|
|
92
|
+
case "Always":
|
|
93
|
+
return true;
|
|
94
|
+
case "Eventually":
|
|
95
|
+
case "Not":
|
|
96
|
+
case "Next":
|
|
97
|
+
return containsAlways(expression.body);
|
|
98
|
+
case "And":
|
|
99
|
+
case "Or":
|
|
100
|
+
return expression.operands.some(containsAlways);
|
|
101
|
+
default:
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// TLC's OrderOfSolution#hasEmptyPEMAndBoxFreePromises, negated.
|
|
107
|
+
const isCycleConstrained = (solution: Solution) =>
|
|
108
|
+
solution.promises.some((promise) => containsAlways(promise.body)) ||
|
|
109
|
+
solution.models.some(
|
|
110
|
+
(model) =>
|
|
111
|
+
model.eventuallyAlways.length > 0 ||
|
|
112
|
+
model.infinitelyOftenStates.length > 0 ||
|
|
113
|
+
model.infinitelyOftenActions.length > 0,
|
|
114
|
+
);
|
|
115
|
+
|
|
63
116
|
const isSameState = (left: Value[], right: Value[]) =>
|
|
64
117
|
left.every((value, position) => isSameValue(value, right[position]));
|
|
65
118
|
|
|
66
119
|
const removeRepeats = (path: number[]) =>
|
|
67
120
|
path.filter((node, position) => position === 0 || path[position - 1] !== node);
|
|
68
121
|
|
|
122
|
+
const createPool = <Data extends Int32Array | Uint8Array>(
|
|
123
|
+
create: (length: number) => Data,
|
|
124
|
+
): Pool<Data> => ({ data: create(1024), length: 0, create });
|
|
125
|
+
|
|
126
|
+
const writeToPool = <Data extends Int32Array | Uint8Array>(
|
|
127
|
+
pool: Pool<Data>,
|
|
128
|
+
offset: number,
|
|
129
|
+
values: ArrayLike<number>,
|
|
130
|
+
) => {
|
|
131
|
+
const end = offset + values.length;
|
|
132
|
+
if (end > pool.data.length) {
|
|
133
|
+
const data = pool.create(Math.max(2 * pool.data.length, end));
|
|
134
|
+
data.set(pool.data);
|
|
135
|
+
pool.data = data;
|
|
136
|
+
}
|
|
137
|
+
pool.data.set(values, offset);
|
|
138
|
+
pool.length = Math.max(pool.length, end);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const NO_NODE = -1;
|
|
142
|
+
|
|
143
|
+
const createNodes = (length: number) => new Int32Array(length).fill(NO_NODE);
|
|
144
|
+
|
|
145
|
+
const UNWRITTEN = -1;
|
|
146
|
+
|
|
147
|
+
const isWritten = (check: Check, node: number) =>
|
|
148
|
+
(check.edgeStarts[node] ?? UNWRITTEN) !== UNWRITTEN;
|
|
149
|
+
|
|
150
|
+
const getSuccessors = (check: Check, node: number) => {
|
|
151
|
+
const start = check.edgeStarts[node];
|
|
152
|
+
return check.edgeTargets.data.subarray(start, start + check.edgeCounts[node]);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const getStateResult = (check: Check, node: number, position: number) =>
|
|
156
|
+
check.stateResults.data[check.nodeStates[node] * check.solution.stateChecks.length + position] ===
|
|
157
|
+
1;
|
|
158
|
+
|
|
69
159
|
// A node owns one entry in each of its check's per-node arrays.
|
|
70
160
|
const pushNode = (check: Check, state: number, tableauNode: number) => {
|
|
71
161
|
check.nodeStates.push(state);
|
|
72
162
|
check.nodeTableaux.push(tableauNode);
|
|
73
|
-
check.
|
|
74
|
-
check.
|
|
75
|
-
check.
|
|
76
|
-
check.isWritten.push(false);
|
|
163
|
+
check.edgeStarts.push(UNWRITTEN);
|
|
164
|
+
check.edgeCounts.push(0);
|
|
165
|
+
check.nextSiblings.push(NO_NODE);
|
|
77
166
|
return check.nodeStates.length - 1;
|
|
78
167
|
};
|
|
79
168
|
|
|
169
|
+
// The nodes of the state, in the order the check recorded them.
|
|
170
|
+
const getStateNodes = (check: Check, state: number) => {
|
|
171
|
+
const nodes: number[] = [];
|
|
172
|
+
for (
|
|
173
|
+
let node = check.firstNodes.data[state] ?? NO_NODE;
|
|
174
|
+
node !== NO_NODE;
|
|
175
|
+
node = check.nextSiblings[node]
|
|
176
|
+
) {
|
|
177
|
+
nodes.push(node);
|
|
178
|
+
}
|
|
179
|
+
return nodes;
|
|
180
|
+
};
|
|
181
|
+
|
|
80
182
|
const SUCCESSOR_CAPACITY = 16;
|
|
81
183
|
|
|
82
184
|
const SCC_MARKER = -42;
|
|
@@ -103,7 +205,7 @@ export const createLivenessChecker = (
|
|
|
103
205
|
fairness.length === 0 ? violation : createJunction("And", [...fairness, violation]);
|
|
104
206
|
const solutions = getSolutions(formula);
|
|
105
207
|
if (solutions.length === 0) {
|
|
106
|
-
throw
|
|
208
|
+
throw createTautologyError();
|
|
107
209
|
}
|
|
108
210
|
const actionIds = new Map<string, number>();
|
|
109
211
|
const checks = solutions.map((solution): Check => ({
|
|
@@ -116,13 +218,15 @@ export const createLivenessChecker = (
|
|
|
116
218
|
}),
|
|
117
219
|
nodeStates: [],
|
|
118
220
|
nodeTableaux: [],
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
221
|
+
edgeStarts: [],
|
|
222
|
+
edgeCounts: [],
|
|
223
|
+
edgeTargets: createPool((length) => new Int32Array(length)),
|
|
224
|
+
edgeActions: createPool((length) => new Uint8Array(length)),
|
|
225
|
+
stateResults: createPool((length) => new Uint8Array(length)),
|
|
123
226
|
initial: [],
|
|
124
|
-
|
|
125
|
-
|
|
227
|
+
firstNodes: createPool(createNodes),
|
|
228
|
+
lastNodes: createPool(createNodes),
|
|
229
|
+
nextSiblings: [],
|
|
126
230
|
isDone: [],
|
|
127
231
|
errorNode: undefined,
|
|
128
232
|
}));
|
|
@@ -131,6 +235,7 @@ export const createLivenessChecker = (
|
|
|
131
235
|
// TLC evaluates every check on its own. Without side effects the order can't show, so the
|
|
132
236
|
// checks of one state share their results.
|
|
133
237
|
const isShared = !hasRepeatedEffects(environment);
|
|
238
|
+
const evaluation = { environment };
|
|
134
239
|
const shared = {
|
|
135
240
|
states: new Map<Value[], Map<LiveExpression, boolean>>(),
|
|
136
241
|
actions: new Map<Value[], Map<Value[], Int8Array>>(),
|
|
@@ -152,7 +257,7 @@ export const createLivenessChecker = (
|
|
|
152
257
|
predicate,
|
|
153
258
|
state,
|
|
154
259
|
undefined,
|
|
155
|
-
environment,
|
|
260
|
+
evaluation.environment,
|
|
156
261
|
isShared ? getStateCache(state) : new Map(),
|
|
157
262
|
);
|
|
158
263
|
const checkState = (check: Check, source: number, state: Value[]) =>
|
|
@@ -166,7 +271,7 @@ export const createLivenessChecker = (
|
|
|
166
271
|
const predicates = check.solution.actionChecks;
|
|
167
272
|
if (!isShared) {
|
|
168
273
|
return Uint8Array.from(predicates, (predicate) =>
|
|
169
|
-
evaluateLive(predicate, state, successor, environment, new Map()) ? 1 : 0,
|
|
274
|
+
evaluateLive(predicate, state, successor, evaluation.environment, new Map()) ? 1 : 0,
|
|
170
275
|
);
|
|
171
276
|
}
|
|
172
277
|
const stateCache = getStateCache(state);
|
|
@@ -176,7 +281,13 @@ export const createLivenessChecker = (
|
|
|
176
281
|
results.set(successor, known);
|
|
177
282
|
return Uint8Array.from(check.actionIds, (id, position) => {
|
|
178
283
|
if (known[id] === -1) {
|
|
179
|
-
known[id] = evaluateLive(
|
|
284
|
+
known[id] = evaluateLive(
|
|
285
|
+
predicates[position],
|
|
286
|
+
state,
|
|
287
|
+
successor,
|
|
288
|
+
evaluation.environment,
|
|
289
|
+
stateCache,
|
|
290
|
+
)
|
|
180
291
|
? 1
|
|
181
292
|
: 0;
|
|
182
293
|
}
|
|
@@ -192,7 +303,10 @@ export const createLivenessChecker = (
|
|
|
192
303
|
evaluateFrom(source, () =>
|
|
193
304
|
tableau.nodes[node].statePredicates.every((predicate) => evaluateState(predicate, state)),
|
|
194
305
|
);
|
|
306
|
+
// TLC 1.7.4 doesn't stop at a tableau node that accepts every behavior, so it finds a violation
|
|
307
|
+
// of a property like a safety property only in its liveness checks.
|
|
195
308
|
const isAccepting = (tableau: Tableau, node: number) => {
|
|
309
|
+
if (environment.runtime.version === "1.7.4") return false;
|
|
196
310
|
const tableauNode = tableau.nodes[node];
|
|
197
311
|
return (
|
|
198
312
|
tableauNode.particle.length === 0 &&
|
|
@@ -210,28 +324,32 @@ export const createLivenessChecker = (
|
|
|
210
324
|
|
|
211
325
|
const getNodeId = (check: Check, state: number, tableauNode: number) =>
|
|
212
326
|
check.solution.tableau
|
|
213
|
-
? check.
|
|
327
|
+
? getStateNodes(check, state).find((node) => check.nodeTableaux[node] === tableauNode)
|
|
214
328
|
: state;
|
|
215
329
|
const recordNode = (check: Check, state: number, tableauNode: number) => {
|
|
216
330
|
const node = pushNode(check, state, tableauNode);
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
331
|
+
const last = check.lastNodes.data[state] ?? NO_NODE;
|
|
332
|
+
if (last === NO_NODE) writeToPool(check.firstNodes, state, [node]);
|
|
333
|
+
else check.nextSiblings[last] = node;
|
|
334
|
+
writeToPool(check.lastNodes, state, [node]);
|
|
221
335
|
return node;
|
|
222
336
|
};
|
|
223
337
|
const writeNode = (
|
|
224
338
|
check: Check,
|
|
225
339
|
node: number,
|
|
340
|
+
targets: number[],
|
|
226
341
|
actions: Uint8Array[],
|
|
227
342
|
stateResults: Uint8Array,
|
|
228
343
|
) => {
|
|
344
|
+
const start = check.edgeTargets.length;
|
|
229
345
|
const actionCount = check.solution.actionChecks.length;
|
|
230
|
-
|
|
231
|
-
actions.forEach((results, position) =>
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
check.
|
|
346
|
+
writeToPool(check.edgeTargets, start, targets);
|
|
347
|
+
actions.forEach((results, position) =>
|
|
348
|
+
writeToPool(check.edgeActions, (start + position) * actionCount, results),
|
|
349
|
+
);
|
|
350
|
+
writeToPool(check.stateResults, check.nodeStates[node] * stateResults.length, stateResults);
|
|
351
|
+
check.edgeStarts[node] = start;
|
|
352
|
+
check.edgeCounts[node] = targets.length;
|
|
235
353
|
};
|
|
236
354
|
|
|
237
355
|
// TLC collects a state's successors and the state itself in a SetOfStates, a hash set it
|
|
@@ -246,7 +364,7 @@ export const createLivenessChecker = (
|
|
|
246
364
|
};
|
|
247
365
|
const insert = (slots: (LiveSuccessor | undefined)[], successor: LiveSuccessor) => {
|
|
248
366
|
for (
|
|
249
|
-
let slot = (graph.getFingerprint(successor
|
|
367
|
+
let slot = (graph.getFingerprint(successor) & 0x7fffffff) % slots.length;
|
|
250
368
|
;
|
|
251
369
|
slot = (slot + 1) % slots.length
|
|
252
370
|
) {
|
|
@@ -284,7 +402,7 @@ export const createLivenessChecker = (
|
|
|
284
402
|
const stateResults = checkState(check, index, state);
|
|
285
403
|
const tableauNode = tableau.nodes[check.nodeTableaux[node]];
|
|
286
404
|
const actions: Uint8Array[] = [];
|
|
287
|
-
const successors =
|
|
405
|
+
const successors: number[] = [];
|
|
288
406
|
const selfActions =
|
|
289
407
|
tableauNode.successors.length > 0
|
|
290
408
|
? checkAction(check, index, state, state)
|
|
@@ -302,11 +420,14 @@ export const createLivenessChecker = (
|
|
|
302
420
|
actions.push(selfActions);
|
|
303
421
|
if (existing === undefined) expandLate(check, tableau, state, index, target);
|
|
304
422
|
}
|
|
305
|
-
for (const successor of graph.getSuccessors(state)) {
|
|
423
|
+
for (const successor of graph.getSuccessors(index, state)) {
|
|
306
424
|
const successorActions = checkAction(check, index, state, successor.state);
|
|
307
425
|
const isDone = check.isDone[successor.index] === true;
|
|
308
426
|
for (const next of tableauNode.successors) {
|
|
309
427
|
if (!isConsistent(tableau, next, index, successor.state)) continue;
|
|
428
|
+
// A successor the search never stored follows a violation or an error, after which nothing
|
|
429
|
+
// checks the graph. TLC records its node, which it never expands.
|
|
430
|
+
if (successor.index === -1) continue;
|
|
310
431
|
const existing = getNodeId(check, successor.index, next);
|
|
311
432
|
if (existing !== undefined && successors.includes(existing)) continue;
|
|
312
433
|
const target = existing ?? recordNode(check, successor.index, next);
|
|
@@ -317,7 +438,7 @@ export const createLivenessChecker = (
|
|
|
317
438
|
}
|
|
318
439
|
}
|
|
319
440
|
}
|
|
320
|
-
if (successors.length > 0) writeNode(check, node, actions, stateResults);
|
|
441
|
+
if (successors.length > 0) writeNode(check, node, successors, actions, stateResults);
|
|
321
442
|
};
|
|
322
443
|
|
|
323
444
|
const addTableauState = (
|
|
@@ -333,8 +454,8 @@ export const createLivenessChecker = (
|
|
|
333
454
|
);
|
|
334
455
|
check.isDone[index] = true;
|
|
335
456
|
// TLC expands the nodes recorded before the loop, not the ones the loop records.
|
|
336
|
-
for (const node of (check
|
|
337
|
-
const successors =
|
|
457
|
+
for (const node of getStateNodes(check, index)) {
|
|
458
|
+
const successors: number[] = [];
|
|
338
459
|
const actions: Uint8Array[] = [];
|
|
339
460
|
set.forEach((successor, position) => {
|
|
340
461
|
const isDone = check.isDone[successor.index] === true;
|
|
@@ -350,7 +471,7 @@ export const createLivenessChecker = (
|
|
|
350
471
|
}
|
|
351
472
|
}
|
|
352
473
|
});
|
|
353
|
-
writeNode(check, node, actions, stateResults);
|
|
474
|
+
writeNode(check, node, successors, actions, stateResults);
|
|
354
475
|
}
|
|
355
476
|
if (check.errorNode === undefined) return undefined;
|
|
356
477
|
return removeRepeats(
|
|
@@ -368,14 +489,14 @@ export const createLivenessChecker = (
|
|
|
368
489
|
index: number,
|
|
369
490
|
) => {
|
|
370
491
|
while (check.nodeStates.length <= index) pushNode(check, check.nodeStates.length, -1);
|
|
371
|
-
const successors =
|
|
492
|
+
const successors: number[] = [];
|
|
372
493
|
const actions: Uint8Array[] = [];
|
|
373
494
|
set.forEach((successor, position) => {
|
|
374
|
-
if (check
|
|
495
|
+
if (isWritten(check, successor.index) && successors.includes(successor.index)) return;
|
|
375
496
|
successors.push(successor.index);
|
|
376
497
|
actions.push(actionResults[position]);
|
|
377
498
|
});
|
|
378
|
-
writeNode(check, index, actions, stateResults);
|
|
499
|
+
writeNode(check, index, successors, actions, stateResults);
|
|
379
500
|
return undefined;
|
|
380
501
|
};
|
|
381
502
|
|
|
@@ -385,20 +506,20 @@ export const createLivenessChecker = (
|
|
|
385
506
|
const parents = new Map<number, number>();
|
|
386
507
|
const queue: number[] = [];
|
|
387
508
|
for (const node of check.initial) {
|
|
388
|
-
if (!check
|
|
509
|
+
if (!isWritten(check, node)) continue;
|
|
389
510
|
queue.push(node);
|
|
390
511
|
parents.set(node, -1);
|
|
391
512
|
}
|
|
392
513
|
for (let position = 0; position < queue.length; position++) {
|
|
393
514
|
const current = queue[position];
|
|
394
|
-
for (const next of check
|
|
515
|
+
for (const next of getSuccessors(check, current)) {
|
|
395
516
|
if (next === current && check.solution.tableau) continue;
|
|
396
517
|
if (next === target) {
|
|
397
518
|
const path = [target];
|
|
398
519
|
for (let node = current; node !== -1; node = parents.get(node) ?? -1) path.push(node);
|
|
399
520
|
return path;
|
|
400
521
|
}
|
|
401
|
-
if (!check
|
|
522
|
+
if (!isWritten(check, next) || parents.has(next)) continue;
|
|
402
523
|
parents.set(next, current);
|
|
403
524
|
queue.push(next);
|
|
404
525
|
}
|
|
@@ -411,15 +532,15 @@ export const createLivenessChecker = (
|
|
|
411
532
|
const solution = check.solution;
|
|
412
533
|
const actionCount = solution.actionChecks.length;
|
|
413
534
|
const getAction = (node: number, edge: number, position: number) =>
|
|
414
|
-
check.
|
|
535
|
+
check.edgeActions.data[(check.edgeStarts[node] + edge) * actionCount + position] === 1;
|
|
415
536
|
const isAllowed = (node: number, edge: number) =>
|
|
416
537
|
model.eventuallyAlways.every((position) => getAction(node, edge, position));
|
|
417
538
|
const links = new Float64Array(check.nodeStates.length).fill(UNVISITED);
|
|
418
|
-
const queue = check.initial.filter((node) => check
|
|
539
|
+
const queue = check.initial.filter((node) => isWritten(check, node));
|
|
419
540
|
const components: number[] = [];
|
|
420
541
|
|
|
421
542
|
const isStuttering = (node: number) => {
|
|
422
|
-
const edge = check
|
|
543
|
+
const edge = getSuccessors(check, node).indexOf(node);
|
|
423
544
|
return edge !== -1 && isAllowed(node, edge);
|
|
424
545
|
};
|
|
425
546
|
const isFulfilled = (node: number, promise: Solution["promises"][number]) =>
|
|
@@ -443,11 +564,11 @@ export const createLivenessChecker = (
|
|
|
443
564
|
if (member === root) break;
|
|
444
565
|
}
|
|
445
566
|
const isStateSatisfied = model.infinitelyOftenStates.every((position) =>
|
|
446
|
-
[...members].some((node) => check
|
|
567
|
+
[...members].some((node) => getStateResult(check, node, position)),
|
|
447
568
|
);
|
|
448
569
|
const isActionSatisfied = model.infinitelyOftenActions.every((position) =>
|
|
449
570
|
[...members].some((node) =>
|
|
450
|
-
check
|
|
571
|
+
getSuccessors(check, node).some(
|
|
451
572
|
(next, edge) =>
|
|
452
573
|
members.has(next) && isAllowed(node, edge) && getAction(node, edge, position),
|
|
453
574
|
),
|
|
@@ -488,7 +609,7 @@ export const createLivenessChecker = (
|
|
|
488
609
|
const countAtStart = remaining.count;
|
|
489
610
|
while (true) {
|
|
490
611
|
model.infinitelyOftenStates.forEach((position, slot) => {
|
|
491
|
-
if (!stateDone[slot] && check
|
|
612
|
+
if (!stateDone[slot] && getStateResult(check, current.node, position)) {
|
|
492
613
|
stateDone[slot] = true;
|
|
493
614
|
remaining.count--;
|
|
494
615
|
}
|
|
@@ -502,8 +623,7 @@ export const createLivenessChecker = (
|
|
|
502
623
|
if (remaining.count <= 0) break;
|
|
503
624
|
const step = { last: -1, unvisited: -1 };
|
|
504
625
|
const countBeforeActions = remaining.count;
|
|
505
|
-
const
|
|
506
|
-
const taken = successors.some((next, edge) => {
|
|
626
|
+
const taken = getSuccessors(check, current.node).some((next, edge) => {
|
|
507
627
|
if (membersByState.has(check.nodeStates[next])) {
|
|
508
628
|
if (!isMember(next) || !isAllowed(current.node, edge)) return false;
|
|
509
629
|
step.last = next;
|
|
@@ -537,7 +657,8 @@ export const createLivenessChecker = (
|
|
|
537
657
|
}
|
|
538
658
|
current.node = previous;
|
|
539
659
|
step.unvisited =
|
|
540
|
-
check
|
|
660
|
+
getSuccessors(check, previous).find((next) => isMember(next) && !seen.has(next)) ??
|
|
661
|
+
-1;
|
|
541
662
|
}
|
|
542
663
|
take(step.unvisited);
|
|
543
664
|
seen.add(step.unvisited);
|
|
@@ -550,7 +671,11 @@ export const createLivenessChecker = (
|
|
|
550
671
|
}
|
|
551
672
|
const cycleState = prefix[prefix.length - 1];
|
|
552
673
|
if (postfix[postfix.length - 1] === cycleState) postfix.pop();
|
|
553
|
-
return {
|
|
674
|
+
return {
|
|
675
|
+
prefix: prefix.slice(0, -1),
|
|
676
|
+
cycle: [cycleState, ...postfix.reverse()],
|
|
677
|
+
isCycleConstrained: isCycleConstrained(solution),
|
|
678
|
+
};
|
|
554
679
|
};
|
|
555
680
|
|
|
556
681
|
// TLC's LiveWorker#bfsPostFix, the states from the walk's end back to the root, last first.
|
|
@@ -567,7 +692,7 @@ export const createLivenessChecker = (
|
|
|
567
692
|
const queue: [number, number][] = [];
|
|
568
693
|
for (let state = start, parent = -1, position = 0; ; position++) {
|
|
569
694
|
for (const node of membersByState.get(state) ?? []) {
|
|
570
|
-
for (const [edge, next] of check
|
|
695
|
+
for (const [edge, next] of getSuccessors(check, node).entries()) {
|
|
571
696
|
if (next === node || !isAllowedEdge(node, edge)) continue;
|
|
572
697
|
if (next === root) {
|
|
573
698
|
const path: number[] = [];
|
|
@@ -620,8 +745,8 @@ export const createLivenessChecker = (
|
|
|
620
745
|
stack.push(lowLink, node, SCC_MARKER);
|
|
621
746
|
components.push(node);
|
|
622
747
|
const nextLowLink = { value: counter.link++ };
|
|
623
|
-
check
|
|
624
|
-
if (!check
|
|
748
|
+
getSuccessors(check, node).forEach((next, edge) => {
|
|
749
|
+
if (!isWritten(check, next)) return;
|
|
625
750
|
if (!isAllowed(node, edge)) {
|
|
626
751
|
if (links[next] === UNVISITED) queue.push(next);
|
|
627
752
|
return;
|
|
@@ -636,37 +761,48 @@ export const createLivenessChecker = (
|
|
|
636
761
|
};
|
|
637
762
|
|
|
638
763
|
return {
|
|
639
|
-
|
|
764
|
+
branches: checks.length,
|
|
765
|
+
addInitialState: (index, state, tracing) => {
|
|
766
|
+
evaluation.environment = tracing ?? environment;
|
|
640
767
|
shared.states.clear();
|
|
641
768
|
shared.actions.clear();
|
|
642
|
-
|
|
643
|
-
const
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
769
|
+
try {
|
|
770
|
+
for (const check of checks) {
|
|
771
|
+
const tableau = check.solution.tableau;
|
|
772
|
+
if (!tableau) {
|
|
773
|
+
check.initial.push(index);
|
|
774
|
+
continue;
|
|
775
|
+
}
|
|
776
|
+
for (let node = 0; node < tableau.initialCount; node++) {
|
|
777
|
+
if (!isConsistent(tableau, node, undefined, state)) continue;
|
|
778
|
+
check.initial.push(getNodeId(check, index, node) ?? recordNode(check, index, node));
|
|
779
|
+
}
|
|
651
780
|
}
|
|
781
|
+
} finally {
|
|
782
|
+
evaluation.environment = environment;
|
|
652
783
|
}
|
|
653
784
|
},
|
|
654
|
-
addState: (index, state, successors) => {
|
|
785
|
+
addState: (index, state, successors, tracing) => {
|
|
786
|
+
evaluation.environment = tracing ?? environment;
|
|
655
787
|
shared.states.clear();
|
|
656
788
|
shared.actions.clear();
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
const
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
789
|
+
try {
|
|
790
|
+
const set = getSuccessorSet(index, state, successors);
|
|
791
|
+
for (const check of checks) {
|
|
792
|
+
const actionResults = set.map((successor) =>
|
|
793
|
+
checkAction(check, index, state, successor.state),
|
|
794
|
+
);
|
|
795
|
+
const stateResults = checkState(check, index, state);
|
|
796
|
+
const tableau = check.solution.tableau;
|
|
797
|
+
const accepted = tableau
|
|
798
|
+
? addTableauState(check, tableau, set, actionResults, stateResults, index)
|
|
799
|
+
: addPlainState(check, set, actionResults, stateResults, index);
|
|
800
|
+
if (accepted) return accepted;
|
|
801
|
+
}
|
|
802
|
+
return undefined;
|
|
803
|
+
} finally {
|
|
804
|
+
evaluation.environment = environment;
|
|
668
805
|
}
|
|
669
|
-
return undefined;
|
|
670
806
|
},
|
|
671
807
|
findViolation: () => {
|
|
672
808
|
for (const check of checks) {
|