tla-ts 0.0.10-dev.a4b81b6d0 → 0.0.10-dev.a5705bfbf
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 +31 -31
- package/dist/deciders.js +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove.cjs +42 -42
- package/dist/prove.js +30 -30
- package/dist/run.cjs +42 -42
- package/dist/run.js +42 -42
- package/dist/transfer.cjs +31 -29
- package/dist/transfer.js +43 -41
- package/dist/worker.cjs +4 -4
- package/dist/worker.js +4 -4
- package/package.json +1 -1
- package/src/ast.ts +10 -1
- package/src/check-failure.ts +5 -6
- package/src/check-trace.ts +4 -4
- package/src/check.ts +78 -90
- package/src/cli/tlc-output.ts +16 -2
- package/src/cli/tlc.ts +2 -2
- package/src/codegen.ts +10 -16
- package/src/coverage.ts +190 -1
- package/src/dependencies.ts +14 -2
- package/src/dfid.ts +80 -27
- package/src/environment.ts +30 -1
- package/src/evaluate.ts +223 -47
- package/src/exit-codes.ts +3 -4
- package/src/instances.ts +11 -1
- package/src/levels.ts +48 -7
- package/src/liveness-checker.ts +123 -70
- package/src/liveness.ts +4 -1
- package/src/obligations/source.ts +2 -0
- package/src/parser.ts +3 -0
- package/src/prover/smt/solver/card2bv.ts +7 -4
- package/src/prover/smt/solver/context.ts +20 -4
- package/src/prover/smt/solver/dependent-expr-state.ts +18 -12
- package/src/prover/smt/solver/dt2bv-tactic.ts +36 -20
- package/src/prover/smt/solver/fd-solver.ts +146 -39
- package/src/prover/smt/solver/maxcore.ts +2 -1
- package/src/prover/smt/solver/maxsmt-base.ts +1 -0
- package/src/prover/smt/solver/model-checker.ts +1 -1
- package/src/prover/smt/solver/muz/dl-context.ts +12 -40
- package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +1 -1
- package/src/prover/smt/solver/muz/dl-rule.ts +6 -7
- package/src/prover/smt/solver/muz/hnf.ts +2 -2
- package/src/prover/smt/solver/muz/horn-tactic.ts +14 -1
- package/src/prover/smt/solver/muz/rule-properties.ts +22 -0
- package/src/prover/smt/solver/muz/spacer-prop-solver.ts +1 -1
- package/src/prover/smt/solver/opt-context.ts +1 -0
- package/src/prover/smt/solver/opt-solver.ts +1 -1
- package/src/prover/smt/solver/parallel-tactic.ts +1 -1
- package/src/prover/smt/solver/qsat.ts +7 -2
- package/src/prover/smt/solver/rewriter-tpl.ts +7 -6
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +45 -26
- package/src/prover/smt/solver/sat/sat-tactic.ts +4 -2
- package/src/prover/smt/solver/sat/sat2goal.ts +10 -7
- package/src/prover/smt/solver/smt-consequences.ts +1 -1
- package/src/prover/smt/solver/smt-kernel.ts +9 -2
- package/src/prover/smt/solver/smtlib-parser.ts +6 -2
- package/src/prover/smt/solver/smtlib-script.ts +197 -73
- package/src/prover/smt/solver/tactic.ts +64 -37
- package/src/resolve.ts +143 -39
- package/src/sany/generator-expressions.ts +2 -0
- package/src/sany/generator-proofs.ts +1 -0
- package/src/search.ts +109 -23
- package/src/simulate.ts +114 -124
- package/src/spec-description.ts +3 -0
- package/src/subexpressions.ts +168 -63
- package/src/successors.ts +30 -10
- package/src/tlc/replay.ts +45 -29
- package/src/trace-liveness.ts +529 -0
- package/src/typed-tier.ts +14 -4
- package/src/values.ts +15 -1
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
import { isSameState } from "./fingerprints";
|
|
2
|
+
import { evaluateLive, type LiveAtoms } from "./liveness";
|
|
3
|
+
import { isFulfilling, type LiveExpression, type Solution } from "./tableau";
|
|
4
|
+
import type { Value } from "./values";
|
|
5
|
+
|
|
6
|
+
interface GraphNode {
|
|
7
|
+
fingerprint: bigint;
|
|
8
|
+
tableau: number;
|
|
9
|
+
position: number;
|
|
10
|
+
stateChecks: boolean[];
|
|
11
|
+
successors: GraphNode[];
|
|
12
|
+
actionChecks: boolean[][];
|
|
13
|
+
stepPositions: number[];
|
|
14
|
+
number: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface TraceChecks {
|
|
18
|
+
getStates: (position: number) => boolean[];
|
|
19
|
+
getSteps: (position: number) => boolean[];
|
|
20
|
+
getStutters: (position: number) => boolean[];
|
|
21
|
+
isConsistent: (tableauNode: number, position: number) => boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface BehaviorGraph {
|
|
25
|
+
initial: GraphNode[];
|
|
26
|
+
isPartial: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface TraceLasso {
|
|
30
|
+
positions: number[];
|
|
31
|
+
cyclePosition: number;
|
|
32
|
+
backPosition: number | undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const MAX_FIRST = 2 ** 50;
|
|
36
|
+
const MAX_SECOND = 2 ** 51;
|
|
37
|
+
|
|
38
|
+
const createNode = (
|
|
39
|
+
fingerprint: bigint,
|
|
40
|
+
tableau: number,
|
|
41
|
+
position: number,
|
|
42
|
+
stateChecks: boolean[],
|
|
43
|
+
): GraphNode => ({
|
|
44
|
+
fingerprint,
|
|
45
|
+
tableau,
|
|
46
|
+
position,
|
|
47
|
+
stateChecks,
|
|
48
|
+
successors: [],
|
|
49
|
+
actionChecks: [],
|
|
50
|
+
stepPositions: [],
|
|
51
|
+
number: 0,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const addTransition = (
|
|
55
|
+
source: GraphNode,
|
|
56
|
+
target: GraphNode,
|
|
57
|
+
actionChecks: boolean[],
|
|
58
|
+
position: number,
|
|
59
|
+
) => {
|
|
60
|
+
source.successors.push(target);
|
|
61
|
+
source.actionChecks.push(actionChecks);
|
|
62
|
+
source.stepPositions.push(position);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const getStepTo = (source: GraphNode, target: GraphNode) =>
|
|
66
|
+
source.stepPositions[source.successors.indexOf(target)];
|
|
67
|
+
|
|
68
|
+
const pop = (nodes: GraphNode[]) => {
|
|
69
|
+
const top = nodes[nodes.length - 1];
|
|
70
|
+
nodes.length -= 1;
|
|
71
|
+
return top;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const createGraph = (
|
|
75
|
+
fingerprints: bigint[],
|
|
76
|
+
solution: Solution,
|
|
77
|
+
checks: TraceChecks,
|
|
78
|
+
isComplete: boolean,
|
|
79
|
+
): BehaviorGraph => {
|
|
80
|
+
const graph: BehaviorGraph = { initial: [], isPartial: false };
|
|
81
|
+
const tableau = solution.tableau;
|
|
82
|
+
if (!tableau) {
|
|
83
|
+
const nodes = new Map<bigint, GraphNode>();
|
|
84
|
+
let source = createNode(fingerprints[0], -1, 0, checks.getStates(0));
|
|
85
|
+
addTransition(source, source, checks.getStutters(0), 0);
|
|
86
|
+
nodes.set(fingerprints[0], source);
|
|
87
|
+
graph.initial.push(source);
|
|
88
|
+
for (let position = 1; position < fingerprints.length; position++) {
|
|
89
|
+
const existing = nodes.get(fingerprints[position]);
|
|
90
|
+
if (existing === undefined) {
|
|
91
|
+
const target = createNode(fingerprints[position], -1, position, checks.getStates(position));
|
|
92
|
+
addTransition(target, target, checks.getStutters(position), position);
|
|
93
|
+
addTransition(source, target, checks.getSteps(position), position);
|
|
94
|
+
nodes.set(fingerprints[position], target);
|
|
95
|
+
source = target;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (!source.successors.includes(existing)) {
|
|
99
|
+
addTransition(source, existing, checks.getSteps(position), position);
|
|
100
|
+
}
|
|
101
|
+
source = existing;
|
|
102
|
+
}
|
|
103
|
+
return graph;
|
|
104
|
+
}
|
|
105
|
+
const rows = new Map<bigint, GraphNode[]>();
|
|
106
|
+
const getRow = (fingerprint: bigint) => {
|
|
107
|
+
const row = rows.get(fingerprint) ?? [];
|
|
108
|
+
rows.set(fingerprint, row);
|
|
109
|
+
return row;
|
|
110
|
+
};
|
|
111
|
+
const extend = (
|
|
112
|
+
sources: GraphNode[],
|
|
113
|
+
targets: GraphNode[],
|
|
114
|
+
row: GraphNode[],
|
|
115
|
+
position: number,
|
|
116
|
+
stateChecks: boolean[],
|
|
117
|
+
actionChecks: boolean[],
|
|
118
|
+
) => {
|
|
119
|
+
for (let index = 0; index < sources.length; index++) {
|
|
120
|
+
const source = sources[index];
|
|
121
|
+
const successors = tableau.nodes[source.tableau].successors;
|
|
122
|
+
for (let successor = 0; successor < successors.length; successor++) {
|
|
123
|
+
const tableauNode = successors[successor];
|
|
124
|
+
const existing = row[tableauNode];
|
|
125
|
+
if (existing === undefined) {
|
|
126
|
+
if (!checks.isConsistent(tableauNode, position)) continue;
|
|
127
|
+
const target = createNode(fingerprints[position], tableauNode, position, stateChecks);
|
|
128
|
+
addTransition(source, target, actionChecks, position);
|
|
129
|
+
targets.push(target);
|
|
130
|
+
row[tableauNode] = target;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (!source.successors.includes(existing)) {
|
|
134
|
+
addTransition(source, existing, actionChecks, position);
|
|
135
|
+
}
|
|
136
|
+
if (existing.position === position) continue;
|
|
137
|
+
graph.isPartial = true;
|
|
138
|
+
if (isComplete && !targets.includes(existing)) targets.push(existing);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
const initialRow = getRow(fingerprints[0]);
|
|
143
|
+
const initialChecks = checks.getStates(0);
|
|
144
|
+
const initialStutters = checks.getStutters(0);
|
|
145
|
+
for (let tableauNode = 0; tableauNode < tableau.initialCount; tableauNode++) {
|
|
146
|
+
if (!checks.isConsistent(tableauNode, 0)) continue;
|
|
147
|
+
const node = createNode(fingerprints[0], tableauNode, 0, initialChecks);
|
|
148
|
+
graph.initial.push(node);
|
|
149
|
+
initialRow[tableauNode] = node;
|
|
150
|
+
}
|
|
151
|
+
for (const source of graph.initial) {
|
|
152
|
+
for (const tableauNode of tableau.nodes[source.tableau].successors) {
|
|
153
|
+
const target = initialRow[tableauNode];
|
|
154
|
+
if (!target) {
|
|
155
|
+
graph.isPartial = true;
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
addTransition(source, target, initialStutters, 0);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
let sources = [...graph.initial];
|
|
162
|
+
if (isComplete) extend(sources, sources, initialRow, 0, initialChecks, initialStutters);
|
|
163
|
+
for (let position = 1; position < fingerprints.length; position++) {
|
|
164
|
+
const row = getRow(fingerprints[position]);
|
|
165
|
+
const stateChecks = checks.getStates(position);
|
|
166
|
+
const targets: GraphNode[] = [];
|
|
167
|
+
extend(sources, targets, row, position, stateChecks, checks.getSteps(position));
|
|
168
|
+
extend(targets, targets, row, position, stateChecks, checks.getStutters(position));
|
|
169
|
+
sources = targets;
|
|
170
|
+
}
|
|
171
|
+
return graph;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const findLasso = (
|
|
175
|
+
fingerprints: bigint[],
|
|
176
|
+
solution: Solution,
|
|
177
|
+
initial: GraphNode[],
|
|
178
|
+
): TraceLasso | undefined => {
|
|
179
|
+
const promises = solution.promises;
|
|
180
|
+
const tableauNodes = solution.tableau?.nodes ?? [];
|
|
181
|
+
const stack: GraphNode[] = [];
|
|
182
|
+
let firstNumber = 1;
|
|
183
|
+
let secondNumber = MAX_FIRST + 1;
|
|
184
|
+
let thirdNumber = MAX_SECOND + 1;
|
|
185
|
+
let startSecondNumber = secondNumber;
|
|
186
|
+
let startThirdNumber = thirdNumber;
|
|
187
|
+
let firstComponentNumber = secondNumber;
|
|
188
|
+
let secondComponentNumber = thirdNumber;
|
|
189
|
+
let model = solution.models[0];
|
|
190
|
+
let lasso: TraceLasso | undefined;
|
|
191
|
+
|
|
192
|
+
const isEventuallyAlways = (node: GraphNode, transition: number) => {
|
|
193
|
+
const actionChecks = node.actionChecks[transition];
|
|
194
|
+
const checks = model.eventuallyAlways;
|
|
195
|
+
for (let index = 0; index < checks.length; index++) {
|
|
196
|
+
if (!actionChecks[checks[index]]) return false;
|
|
197
|
+
}
|
|
198
|
+
return true;
|
|
199
|
+
};
|
|
200
|
+
const getLasso = (node: GraphNode): TraceLasso => {
|
|
201
|
+
const cycle: GraphNode[] = [];
|
|
202
|
+
const lowNumber = thirdNumber - 1;
|
|
203
|
+
const states = model.infinitelyOftenStates;
|
|
204
|
+
const actions = model.infinitelyOftenActions;
|
|
205
|
+
const isStateFound = states.map(() => false);
|
|
206
|
+
const isActionFound = actions.map(() => false);
|
|
207
|
+
const isPromiseFound = promises.map(() => false);
|
|
208
|
+
let count = states.length + actions.length + promises.length;
|
|
209
|
+
let current = node;
|
|
210
|
+
while (count > 0) {
|
|
211
|
+
current.number = thirdNumber;
|
|
212
|
+
const countBefore = count;
|
|
213
|
+
search: while (true) {
|
|
214
|
+
for (let index = 0; index < states.length; index++) {
|
|
215
|
+
if (!isStateFound[index] && current.stateChecks[states[index]]) {
|
|
216
|
+
isStateFound[index] = true;
|
|
217
|
+
count--;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
for (let index = 0; index < promises.length; index++) {
|
|
221
|
+
if (
|
|
222
|
+
!isPromiseFound[index] &&
|
|
223
|
+
isFulfilling(tableauNodes[current.tableau].particle, promises[index])
|
|
224
|
+
) {
|
|
225
|
+
isPromiseFound[index] = true;
|
|
226
|
+
count--;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (count <= 0) break;
|
|
230
|
+
let inComponent: GraphNode | undefined;
|
|
231
|
+
let unvisited: GraphNode | undefined;
|
|
232
|
+
const countBeforeActions = count;
|
|
233
|
+
for (let index = 0; index < current.successors.length; index++) {
|
|
234
|
+
const target = current.successors[index];
|
|
235
|
+
const targetNumber = target.number;
|
|
236
|
+
if (lowNumber <= targetNumber && targetNumber <= thirdNumber) {
|
|
237
|
+
inComponent = target;
|
|
238
|
+
for (let action = 0; action < actions.length; action++) {
|
|
239
|
+
if (!isActionFound[action] && current.actionChecks[index][actions[action]]) {
|
|
240
|
+
isActionFound[action] = true;
|
|
241
|
+
count--;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (count < countBeforeActions) {
|
|
246
|
+
cycle.push(current);
|
|
247
|
+
current = target;
|
|
248
|
+
thirdNumber++;
|
|
249
|
+
break search;
|
|
250
|
+
}
|
|
251
|
+
if (lowNumber <= targetNumber && targetNumber < thirdNumber) unvisited = target;
|
|
252
|
+
}
|
|
253
|
+
if (count < countBefore && inComponent) {
|
|
254
|
+
cycle.push(current);
|
|
255
|
+
current = inComponent;
|
|
256
|
+
thirdNumber++;
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
while (unvisited === undefined) {
|
|
260
|
+
current = pop(cycle);
|
|
261
|
+
for (let index = 0; index < current.successors.length; index++) {
|
|
262
|
+
const target = current.successors[index];
|
|
263
|
+
if (lowNumber <= target.number && target.number < thirdNumber) {
|
|
264
|
+
cycle.push(current);
|
|
265
|
+
unvisited = target;
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
cycle.push(current);
|
|
271
|
+
current = unvisited;
|
|
272
|
+
current.number = thirdNumber;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
thirdNumber++;
|
|
276
|
+
current.number = thirdNumber;
|
|
277
|
+
close: while (current !== node) {
|
|
278
|
+
let isFound = false;
|
|
279
|
+
for (let index = 0; index < current.successors.length; index++) {
|
|
280
|
+
const target = current.successors[index];
|
|
281
|
+
if (lowNumber <= target.number && target.number < thirdNumber) {
|
|
282
|
+
cycle.push(current);
|
|
283
|
+
if (target === node) break close;
|
|
284
|
+
isFound = true;
|
|
285
|
+
current = target;
|
|
286
|
+
current.number = thirdNumber;
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (!isFound) current = pop(cycle);
|
|
291
|
+
}
|
|
292
|
+
if (cycle.length === 0) cycle.push(current);
|
|
293
|
+
// Deviation from TLC: LiveCheck1#printErrorTrace shows the behavior's states in order, not those of the lasso it found, which differ once the behavior revisits a state.
|
|
294
|
+
const positions: number[] = [];
|
|
295
|
+
for (let position = 0; position <= node.position; position++) {
|
|
296
|
+
if (position === 0 || fingerprints[position] !== fingerprints[position - 1]) {
|
|
297
|
+
positions.push(position);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
const cyclePosition = positions.length;
|
|
301
|
+
for (let index = 1; index < cycle.length; index++) {
|
|
302
|
+
if (cycle[index].fingerprint !== cycle[index - 1].fingerprint) {
|
|
303
|
+
positions.push(getStepTo(cycle[index - 1], cycle[index]));
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
const last = cycle[cycle.length - 1];
|
|
307
|
+
return {
|
|
308
|
+
positions,
|
|
309
|
+
cyclePosition,
|
|
310
|
+
backPosition: last.fingerprint === node.fingerprint ? undefined : getStepTo(last, node),
|
|
311
|
+
};
|
|
312
|
+
};
|
|
313
|
+
const checkSubcomponent = (node: GraphNode) => {
|
|
314
|
+
const states = model.infinitelyOftenStates;
|
|
315
|
+
const actions = model.infinitelyOftenActions;
|
|
316
|
+
const isStateFound = states.map(() => false);
|
|
317
|
+
const isActionFound = actions.map(() => false);
|
|
318
|
+
const isPromiseFound = promises.map(() => false);
|
|
319
|
+
const pending = [node];
|
|
320
|
+
node.number++;
|
|
321
|
+
while (pending.length > 0) {
|
|
322
|
+
const current = pop(pending);
|
|
323
|
+
for (let index = 0; index < states.length; index++) {
|
|
324
|
+
if (!isStateFound[index]) isStateFound[index] = current.stateChecks[states[index]];
|
|
325
|
+
}
|
|
326
|
+
for (let index = 0; index < current.successors.length; index++) {
|
|
327
|
+
const target = current.successors[index];
|
|
328
|
+
const targetNumber = target.number;
|
|
329
|
+
if (targetNumber >= thirdNumber) {
|
|
330
|
+
for (let action = 0; action < actions.length; action++) {
|
|
331
|
+
if (!isActionFound[action]) {
|
|
332
|
+
isActionFound[action] = current.actionChecks[index][actions[action]];
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (targetNumber === thirdNumber) {
|
|
337
|
+
target.number++;
|
|
338
|
+
pending.push(target);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
for (let index = 0; index < promises.length; index++) {
|
|
342
|
+
if (isFulfilling(tableauNodes[current.tableau].particle, promises[index])) {
|
|
343
|
+
isPromiseFound[index] = true;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
thirdNumber += 2;
|
|
348
|
+
if (
|
|
349
|
+
lasso === undefined &&
|
|
350
|
+
!isStateFound.includes(false) &&
|
|
351
|
+
!isActionFound.includes(false) &&
|
|
352
|
+
!isPromiseFound.includes(false)
|
|
353
|
+
) {
|
|
354
|
+
lasso = getLasso(node);
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
const canStutter = (node: GraphNode) => {
|
|
358
|
+
const stutter = node.successors.indexOf(node);
|
|
359
|
+
return (
|
|
360
|
+
stutter !== -1 && firstComponentNumber <= node.number && isEventuallyAlways(node, stutter)
|
|
361
|
+
);
|
|
362
|
+
};
|
|
363
|
+
const extractSubcomponent = (node: GraphNode) => {
|
|
364
|
+
let popped = pop(stack);
|
|
365
|
+
if (popped === node && !canStutter(node)) {
|
|
366
|
+
node.number = thirdNumber++;
|
|
367
|
+
return false;
|
|
368
|
+
}
|
|
369
|
+
popped.number = thirdNumber;
|
|
370
|
+
while (popped !== node) {
|
|
371
|
+
popped = pop(stack);
|
|
372
|
+
popped.number = thirdNumber;
|
|
373
|
+
}
|
|
374
|
+
return true;
|
|
375
|
+
};
|
|
376
|
+
const checkSubcomponents = (node: GraphNode): number => {
|
|
377
|
+
let lowlink = secondNumber++;
|
|
378
|
+
node.number = lowlink;
|
|
379
|
+
stack.push(node);
|
|
380
|
+
for (let index = 0; index < node.successors.length; index++) {
|
|
381
|
+
const target = node.successors[index];
|
|
382
|
+
let targetNumber = target.number;
|
|
383
|
+
if (firstComponentNumber <= targetNumber && isEventuallyAlways(node, index)) {
|
|
384
|
+
if (
|
|
385
|
+
targetNumber < startSecondNumber ||
|
|
386
|
+
(secondComponentNumber <= targetNumber && targetNumber < startThirdNumber)
|
|
387
|
+
) {
|
|
388
|
+
targetNumber = checkSubcomponents(target);
|
|
389
|
+
}
|
|
390
|
+
if (targetNumber < lowlink) lowlink = targetNumber;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
if (lowlink === node.number && extractSubcomponent(node)) checkSubcomponent(node);
|
|
394
|
+
return lowlink;
|
|
395
|
+
};
|
|
396
|
+
const extractComponent = (node: GraphNode) => {
|
|
397
|
+
let popped = pop(stack);
|
|
398
|
+
if (popped === node && !node.successors.includes(node)) {
|
|
399
|
+
node.number = MAX_FIRST;
|
|
400
|
+
return undefined;
|
|
401
|
+
}
|
|
402
|
+
const nodes: GraphNode[] = [];
|
|
403
|
+
firstComponentNumber = secondNumber++;
|
|
404
|
+
secondComponentNumber = thirdNumber;
|
|
405
|
+
popped.number = firstComponentNumber;
|
|
406
|
+
nodes.push(popped);
|
|
407
|
+
while (popped !== node) {
|
|
408
|
+
popped = pop(stack);
|
|
409
|
+
popped.number = firstComponentNumber;
|
|
410
|
+
nodes.push(popped);
|
|
411
|
+
}
|
|
412
|
+
return nodes;
|
|
413
|
+
};
|
|
414
|
+
const checkComponent = (node: GraphNode) => {
|
|
415
|
+
const nodes = extractComponent(node);
|
|
416
|
+
if (!nodes) return;
|
|
417
|
+
for (const errorModel of solution.models) {
|
|
418
|
+
model = errorModel;
|
|
419
|
+
startSecondNumber = secondNumber;
|
|
420
|
+
startThirdNumber = thirdNumber;
|
|
421
|
+
for (let index = nodes.length - 1; index >= 0; index--) {
|
|
422
|
+
if (nodes[index].number < startThirdNumber) checkSubcomponents(nodes[index]);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
const checkComponents = (node: GraphNode): number => {
|
|
427
|
+
let lowlink = firstNumber++;
|
|
428
|
+
node.number = lowlink;
|
|
429
|
+
stack.push(node);
|
|
430
|
+
for (let index = 0; index < node.successors.length; index++) {
|
|
431
|
+
const target = node.successors[index];
|
|
432
|
+
const targetNumber = target.number === 0 ? checkComponents(target) : target.number;
|
|
433
|
+
if (targetNumber < lowlink) lowlink = targetNumber;
|
|
434
|
+
}
|
|
435
|
+
if (lowlink === node.number) checkComponent(node);
|
|
436
|
+
return lowlink;
|
|
437
|
+
};
|
|
438
|
+
for (const node of initial) {
|
|
439
|
+
if (node.number === 0) checkComponents(node);
|
|
440
|
+
if (lasso) return lasso;
|
|
441
|
+
}
|
|
442
|
+
return undefined;
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
export const findTraceLasso = (
|
|
446
|
+
trace: Value[][],
|
|
447
|
+
fingerprints: bigint[],
|
|
448
|
+
solutions: Solution[],
|
|
449
|
+
atoms: LiveAtoms<Value[]>,
|
|
450
|
+
isShared: boolean,
|
|
451
|
+
): TraceLasso | undefined => {
|
|
452
|
+
const stateCache = new Map<LiveExpression, boolean>();
|
|
453
|
+
const holds = (check: LiveExpression, position: number, next: number | undefined) => {
|
|
454
|
+
stateCache.clear();
|
|
455
|
+
return evaluateLive(
|
|
456
|
+
check,
|
|
457
|
+
trace[position],
|
|
458
|
+
next === undefined ? undefined : trace[next],
|
|
459
|
+
atoms,
|
|
460
|
+
stateCache,
|
|
461
|
+
);
|
|
462
|
+
};
|
|
463
|
+
const statePositions = trace.map((_state, position) => position);
|
|
464
|
+
const stepPositions = trace.map((_state, position) => position);
|
|
465
|
+
if (isShared) {
|
|
466
|
+
const firstStates = new Map<bigint, number>();
|
|
467
|
+
const firstSteps = new Map<number, number>();
|
|
468
|
+
for (let position = 0; position < trace.length; position++) {
|
|
469
|
+
const first = firstStates.get(fingerprints[position]) ?? position;
|
|
470
|
+
firstStates.set(fingerprints[position], first);
|
|
471
|
+
if (isSameState(trace[first], trace[position])) statePositions[position] = first;
|
|
472
|
+
if (position === 0) continue;
|
|
473
|
+
const key = statePositions[position - 1] * trace.length + statePositions[position];
|
|
474
|
+
stepPositions[position] = firstSteps.get(key) ?? position;
|
|
475
|
+
firstSteps.set(key, stepPositions[position]);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
const solutionChecks = solutions.map((solution): TraceChecks => {
|
|
479
|
+
const states: boolean[][] = [];
|
|
480
|
+
const steps: boolean[][] = [];
|
|
481
|
+
const stutters: boolean[][] = [];
|
|
482
|
+
const consistent: boolean[][] = [];
|
|
483
|
+
const statePredicates = solution.tableau?.nodes.map((node) => node.statePredicates) ?? [];
|
|
484
|
+
return {
|
|
485
|
+
getStates: (position) => {
|
|
486
|
+
const first = statePositions[position];
|
|
487
|
+
return (states[first] ??= solution.stateChecks.map((check) =>
|
|
488
|
+
holds(check, first, undefined),
|
|
489
|
+
));
|
|
490
|
+
},
|
|
491
|
+
getSteps: (position) => {
|
|
492
|
+
const first = stepPositions[position];
|
|
493
|
+
return (steps[first] ??= solution.actionChecks.map((check) =>
|
|
494
|
+
holds(check, first - 1, first),
|
|
495
|
+
));
|
|
496
|
+
},
|
|
497
|
+
getStutters: (position) => {
|
|
498
|
+
const first = statePositions[position];
|
|
499
|
+
return (stutters[first] ??= solution.actionChecks.map((check) =>
|
|
500
|
+
holds(check, first, first),
|
|
501
|
+
));
|
|
502
|
+
},
|
|
503
|
+
isConsistent: (tableauNode, position) => {
|
|
504
|
+
const first = statePositions[position];
|
|
505
|
+
const row = (consistent[first] ??= []);
|
|
506
|
+
const known = isShared ? row[tableauNode] : undefined;
|
|
507
|
+
if (known !== undefined) return known;
|
|
508
|
+
row[tableauNode] = statePredicates[tableauNode].every((predicate) =>
|
|
509
|
+
holds(predicate, first, undefined),
|
|
510
|
+
);
|
|
511
|
+
return row[tableauNode];
|
|
512
|
+
},
|
|
513
|
+
};
|
|
514
|
+
});
|
|
515
|
+
const partial: number[] = [];
|
|
516
|
+
for (let index = 0; index < solutions.length; index++) {
|
|
517
|
+
const graph = createGraph(fingerprints, solutions[index], solutionChecks[index], false);
|
|
518
|
+
const lasso = findLasso(fingerprints, solutions[index], graph.initial);
|
|
519
|
+
if (lasso) return lasso;
|
|
520
|
+
if (graph.isPartial) partial.push(index);
|
|
521
|
+
}
|
|
522
|
+
// Deviation from TLC: LiveCheck1#constructBEGraph gives the initial state no stuttering step to a tableau node that isn't initial and goes on from no node a revisited state reaches, so it misses a violation past them.
|
|
523
|
+
for (const index of partial) {
|
|
524
|
+
const graph = createGraph(fingerprints, solutions[index], solutionChecks[index], true);
|
|
525
|
+
const lasso = findLasso(fingerprints, solutions[index], graph.initial);
|
|
526
|
+
if (lasso) return lasso;
|
|
527
|
+
}
|
|
528
|
+
return undefined;
|
|
529
|
+
};
|
package/src/typed-tier.ts
CHANGED
|
@@ -107,8 +107,7 @@ interface TupType {
|
|
|
107
107
|
interface SeqType {
|
|
108
108
|
kind: "Seq";
|
|
109
109
|
element: Type;
|
|
110
|
-
|
|
111
|
-
target?: MapType;
|
|
110
|
+
target?: SeqType | MapType;
|
|
112
111
|
}
|
|
113
112
|
|
|
114
113
|
// A record of several shapes starts with the position of its shape.
|
|
@@ -529,6 +528,7 @@ const unify = (left: Type, right: Type): void => {
|
|
|
529
528
|
return unify(leftType.values, rightType.values);
|
|
530
529
|
}
|
|
531
530
|
if (leftType.kind === "Seq" && rightType.kind === "Seq") {
|
|
531
|
+
rightType.target = leftType;
|
|
532
532
|
return unify(leftType.element, rightType.element);
|
|
533
533
|
}
|
|
534
534
|
if (leftType.kind === "Set" && rightType.kind === "Set") {
|
|
@@ -3262,6 +3262,8 @@ const compileBuiltin = (
|
|
|
3262
3262
|
|
|
3263
3263
|
const compileValue = (program: Program, expression: Expression, frame: Frame): Compiled => {
|
|
3264
3264
|
switch (expression.kind) {
|
|
3265
|
+
case "Selection":
|
|
3266
|
+
return compileValue(program, expression.expression, frame);
|
|
3265
3267
|
case "Number":
|
|
3266
3268
|
return expression.value <= MAXIMUM_INTEGER
|
|
3267
3269
|
? { type: createInt(), emit: () => String(expression.value) }
|
|
@@ -3948,6 +3950,8 @@ const compileWays = (program: Program, expression: Expression, frame: Frame): Co
|
|
|
3948
3950
|
compileWays(program, inner, { ...frame, scope });
|
|
3949
3951
|
const counted = (emit: () => string): Compiled => ({ type: createInt(), emit });
|
|
3950
3952
|
switch (expression.kind) {
|
|
3953
|
+
case "Selection":
|
|
3954
|
+
return getWays(expression.expression, frame.scope);
|
|
3951
3955
|
case "Or": {
|
|
3952
3956
|
const operands = expression.operands.map((operand) => getWays(operand, frame.scope));
|
|
3953
3957
|
return counted(() => `(${operands.map((operand) => operand.emit()).join(" + ")})`);
|
|
@@ -4068,8 +4072,12 @@ const compileStep = (
|
|
|
4068
4072
|
if (!isEnabled && primed.some((code) => code === undefined)) return () => "H.deopt();";
|
|
4069
4073
|
return () => getEmitCode(primed);
|
|
4070
4074
|
}
|
|
4071
|
-
// With warnings on, TLC evaluates what is left once every variable is assigned, without branching.
|
|
4072
|
-
if (
|
|
4075
|
+
// With warnings on, TLC evaluates what is left of a step once every variable is assigned, without branching, but not under ENABLED.
|
|
4076
|
+
if (
|
|
4077
|
+
!isEnabled &&
|
|
4078
|
+
program.environment.runtime.isWarningEnabled &&
|
|
4079
|
+
primed.every((code) => code !== undefined)
|
|
4080
|
+
) {
|
|
4073
4081
|
const guards = pending.map((item) => {
|
|
4074
4082
|
if (item.expression.kind !== "Unchanged") {
|
|
4075
4083
|
return expectBool(
|
|
@@ -4107,6 +4115,8 @@ const compileStep = (
|
|
|
4107
4115
|
? unsupported()
|
|
4108
4116
|
: continueWith(scope, [body], [...first.inlining, definition]);
|
|
4109
4117
|
switch (expression.kind) {
|
|
4118
|
+
case "Selection":
|
|
4119
|
+
return continueWith(first.scope, [expression.expression]);
|
|
4110
4120
|
case "And":
|
|
4111
4121
|
return continueWith(first.scope, expression.operands);
|
|
4112
4122
|
case "Or": {
|
package/src/values.ts
CHANGED
|
@@ -107,6 +107,7 @@ export interface FilteredSetValue extends LazySet {
|
|
|
107
107
|
kind: "FilteredSet";
|
|
108
108
|
base: Value;
|
|
109
109
|
test: (element: Value, isMember: boolean) => boolean;
|
|
110
|
+
startPass?: (isMaterialized: boolean) => (element: Value) => boolean;
|
|
110
111
|
source?: FilteredSetSource;
|
|
111
112
|
}
|
|
112
113
|
|
|
@@ -288,6 +289,13 @@ const forgetWrittenOrder = (value: Value): void => {
|
|
|
288
289
|
value.range.forEach(forgetWrittenOrder);
|
|
289
290
|
};
|
|
290
291
|
|
|
292
|
+
// TLC's SetOfRcdsValue#member and SetOfFcnsValue#member normalize the record or function they check in place.
|
|
293
|
+
const forgetOwnWrittenOrder = (value: Value) => {
|
|
294
|
+
if (isWrittenOrderUsed && typeof value === "object" && value.kind === "Function") {
|
|
295
|
+
value.writtenKeys = undefined;
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
|
|
291
299
|
const isRecordDomain = (domain: Value[]) => domain.every((key) => typeof key === "string");
|
|
292
300
|
|
|
293
301
|
const isRecordMismatch = (left: Value[], right: Value[]) =>
|
|
@@ -1588,7 +1596,9 @@ const enumerateSet = (
|
|
|
1588
1596
|
}
|
|
1589
1597
|
return toFiniteSet(
|
|
1590
1598
|
createEnumeratedSet(
|
|
1591
|
-
getStreamedElements(value.base).filter(
|
|
1599
|
+
getStreamedElements(value.base).filter(
|
|
1600
|
+
value.startPass?.(true) ?? ((element) => value.test(element, false)),
|
|
1601
|
+
),
|
|
1592
1602
|
),
|
|
1593
1603
|
).elements;
|
|
1594
1604
|
case "Union": {
|
|
@@ -1814,6 +1824,8 @@ const someElementOfStream = (value: ObjectValue, visit: (element: Value) => bool
|
|
|
1814
1824
|
);
|
|
1815
1825
|
}
|
|
1816
1826
|
if (value.kind === "FilteredSet" && isTlcEnumerable(value.base)) {
|
|
1827
|
+
const test = value.startPass?.(false);
|
|
1828
|
+
if (test) return someStreamedElement(value.base, (element) => test(element) && visit(element));
|
|
1817
1829
|
return someStreamedElement(
|
|
1818
1830
|
value.base,
|
|
1819
1831
|
(element) => value.test(element, false) && visit(element),
|
|
@@ -2213,6 +2225,7 @@ const isElementOfAnySet = (element: Value, set: Value): boolean => {
|
|
|
2213
2225
|
`Attempted to check if \n${formatValue(element)}\nwhich is not a TLC function value, is in the set of functions:\n${prettyPrint(formatValue(set))}`,
|
|
2214
2226
|
);
|
|
2215
2227
|
}
|
|
2228
|
+
forgetOwnWrittenOrder(element);
|
|
2216
2229
|
const functionValue = toFiniteFunction(element);
|
|
2217
2230
|
const low = getIntervalLow(element, functionValue.domain);
|
|
2218
2231
|
const isDomain =
|
|
@@ -2225,6 +2238,7 @@ const isElementOfAnySet = (element: Value, set: Value): boolean => {
|
|
|
2225
2238
|
return isDomain && functionValue.range.every((item) => isElementOf(item, set.range));
|
|
2226
2239
|
}
|
|
2227
2240
|
case "RecordSet": {
|
|
2241
|
+
forgetOwnWrittenOrder(element);
|
|
2228
2242
|
const functionValue = isFunctionValue(element) ? toFiniteFunction(element) : undefined;
|
|
2229
2243
|
if (!functionValue || !isRecordDomain(functionValue.domain)) {
|
|
2230
2244
|
if (isModelValue(element)) return isModelValueMember(element, set);
|