everystate 0.1.0 → 0.3.0
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/README.md +111 -86
- package/bin/everystate.mjs +35 -0
- package/native/darwin-arm64/everystate +0 -0
- package/native/darwin-x64/everystate +0 -0
- package/native/linux-arm64/everystate +0 -0
- package/native/linux-x64/everystate +0 -0
- package/native/win32-x64/everystate.exe +0 -0
- package/package.json +23 -24
- package/wasm/cli.mjs +26 -0
- package/wasm/everystate.d.ts +33 -0
- package/wasm/everystate.mjs +112 -0
- package/wasm/everystate.wasm +0 -0
- package/CONFORMANCE.md +0 -64
- package/dist/bundled.d.ts +0 -1
- package/dist/bundled.js +0 -2
- package/dist/cfg.d.ts +0 -24
- package/dist/cfg.js +0 -252
- package/dist/checker.d.ts +0 -96
- package/dist/checker.js +0 -520
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -4
- package/dist/community.d.ts +0 -17
- package/dist/community.js +0 -1381
- package/dist/entry.d.ts +0 -2
- package/dist/entry.js +0 -39
- package/dist/eval.d.ts +0 -119
- package/dist/eval.js +0 -1533
- package/dist/index.d.ts +0 -33
- package/dist/index.js +0 -24
- package/dist/java.d.ts +0 -2
- package/dist/java.js +0 -6
- package/dist/lexer.d.ts +0 -17
- package/dist/lexer.js +0 -255
- package/dist/liveness.d.ts +0 -80
- package/dist/liveness.js +0 -855
- package/dist/main.d.ts +0 -40
- package/dist/main.js +0 -494
- package/dist/model.d.ts +0 -56
- package/dist/model.js +0 -582
- package/dist/modules.d.ts +0 -91
- package/dist/modules.js +0 -649
- package/dist/node-host.d.ts +0 -2
- package/dist/node-host.js +0 -25
- package/dist/parser.d.ts +0 -30
- package/dist/parser.js +0 -1114
- package/dist/pprint.d.ts +0 -7
- package/dist/pprint.js +0 -647
- package/dist/stdlib.d.ts +0 -14
- package/dist/stdlib.js +0 -588
- package/dist/values.d.ts +0 -150
- package/dist/values.js +0 -822
package/dist/checker.js
DELETED
|
@@ -1,520 +0,0 @@
|
|
|
1
|
-
import { locStr } from "./model.js";
|
|
2
|
-
import { TlaError } from "./lexer.js";
|
|
3
|
-
import { Hasher, SetBase, SetV, TupleV, RecordV, FcnV, ModelValue, compare, mkSet, makeFcnFromPairs, IntervalV, makeRecord, } from "./values.js";
|
|
4
|
-
// Open-addressing hash set of 64-bit fingerprints (two int32 halves) mapping to state ids.
|
|
5
|
-
export class FpSet {
|
|
6
|
-
cap = 1 << 16;
|
|
7
|
-
k1 = new Int32Array(this.cap);
|
|
8
|
-
k2 = new Int32Array(this.cap);
|
|
9
|
-
ids = new Int32Array(this.cap); // id + 1; 0 = empty
|
|
10
|
-
size = 0;
|
|
11
|
-
// Returns the existing id, or -1 after inserting `id`.
|
|
12
|
-
put(h1, h2, id) {
|
|
13
|
-
if (this.size * 2 >= this.cap)
|
|
14
|
-
this.grow();
|
|
15
|
-
const mask = this.cap - 1;
|
|
16
|
-
let i = (h1 ^ Math.imul(h2, 0x9e3779b1)) & mask;
|
|
17
|
-
for (;;) {
|
|
18
|
-
const v = this.ids[i];
|
|
19
|
-
if (v === 0) {
|
|
20
|
-
this.k1[i] = h1;
|
|
21
|
-
this.k2[i] = h2;
|
|
22
|
-
this.ids[i] = id + 1;
|
|
23
|
-
this.size++;
|
|
24
|
-
return -1;
|
|
25
|
-
}
|
|
26
|
-
if (this.k1[i] === h1 && this.k2[i] === h2)
|
|
27
|
-
return v - 1;
|
|
28
|
-
i = (i + 1) & mask;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
grow() {
|
|
32
|
-
const ok1 = this.k1, ok2 = this.k2, oids = this.ids, ocap = this.cap;
|
|
33
|
-
this.cap = ocap * 2;
|
|
34
|
-
this.k1 = new Int32Array(this.cap);
|
|
35
|
-
this.k2 = new Int32Array(this.cap);
|
|
36
|
-
this.ids = new Int32Array(this.cap);
|
|
37
|
-
const mask = this.cap - 1;
|
|
38
|
-
for (let j = 0; j < ocap; j++) {
|
|
39
|
-
if (oids[j] === 0)
|
|
40
|
-
continue;
|
|
41
|
-
let i = (ok1[j] ^ Math.imul(ok2[j], 0x9e3779b1)) & mask;
|
|
42
|
-
while (this.ids[i] !== 0)
|
|
43
|
-
i = (i + 1) & mask;
|
|
44
|
-
this.k1[i] = ok1[j];
|
|
45
|
-
this.k2[i] = ok2[j];
|
|
46
|
-
this.ids[i] = oids[j];
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
export function permute(v, m) {
|
|
51
|
-
if (typeof v !== 'object')
|
|
52
|
-
return v;
|
|
53
|
-
if (v instanceof ModelValue)
|
|
54
|
-
return m.get(v) ?? v;
|
|
55
|
-
if (v instanceof TupleV)
|
|
56
|
-
return new TupleV(v.e.map(x => permute(x, m)));
|
|
57
|
-
if (v instanceof RecordV)
|
|
58
|
-
return new RecordV(v.names, v.vals.map(x => permute(x, m)));
|
|
59
|
-
if (v instanceof FcnV)
|
|
60
|
-
return makeFcnFromPairs(v.dom.map((d, i) => [permute(d, m), permute(v.vals[i], m)]));
|
|
61
|
-
if (v instanceof IntervalV)
|
|
62
|
-
return v;
|
|
63
|
-
if (v instanceof SetBase)
|
|
64
|
-
return mkSet(v.elems().map(x => permute(x, m)));
|
|
65
|
-
return v;
|
|
66
|
-
}
|
|
67
|
-
export class CheckError extends Error {
|
|
68
|
-
result;
|
|
69
|
-
constructor(result) { super(result.message ?? result.status); this.result = result; }
|
|
70
|
-
}
|
|
71
|
-
export class Checker {
|
|
72
|
-
model;
|
|
73
|
-
ev;
|
|
74
|
-
opts;
|
|
75
|
-
states = [];
|
|
76
|
-
parent = [];
|
|
77
|
-
level = [];
|
|
78
|
-
act = [];
|
|
79
|
-
succ = []; // recorded graph: successor ids per state (if recordGraph)
|
|
80
|
-
succAct = [];
|
|
81
|
-
succState = null; // actual successor states per edge (only with VIEW/SYMMETRY + liveness)
|
|
82
|
-
inits = [];
|
|
83
|
-
fps = new FpSet();
|
|
84
|
-
hasher = new Hasher();
|
|
85
|
-
generated = 0;
|
|
86
|
-
initGenerated = 0;
|
|
87
|
-
initDistinct = 0;
|
|
88
|
-
head = 0;
|
|
89
|
-
depth = 0;
|
|
90
|
-
nvars;
|
|
91
|
-
outdeg = [];
|
|
92
|
-
constructor(model, opts) {
|
|
93
|
-
this.model = model;
|
|
94
|
-
this.ev = model.ev;
|
|
95
|
-
this.opts = opts;
|
|
96
|
-
this.nvars = model.vars.length;
|
|
97
|
-
this.ev.hooks.tlcGet = (k) => this.tlcGet(k);
|
|
98
|
-
this.ev.hooks.tlcSet = (k, v) => { if (k === 'exit' && v === true)
|
|
99
|
-
this.stopRequested = true; };
|
|
100
|
-
if (!this.ev.hooks.random)
|
|
101
|
-
this.ev.hooks.random = Math.random;
|
|
102
|
-
}
|
|
103
|
-
curLevel = 0; // level of the state `ev.cur` refers to (0 before/during the initial predicate)
|
|
104
|
-
stopRequested = false; // TLCSet("exit", TRUE): finish the current state, then stop
|
|
105
|
-
tlcGet(k) {
|
|
106
|
-
switch (k) {
|
|
107
|
-
case 'level': return this.curLevel + (this.ev.primeDepth > 0 ? 1 : 0);
|
|
108
|
-
case 'distinct': return this.states.length;
|
|
109
|
-
case 'generated': return this.generated;
|
|
110
|
-
case 'queue': return this.states.length - this.head;
|
|
111
|
-
case 'diameter': return this.depth;
|
|
112
|
-
case 'duration': return 0;
|
|
113
|
-
case 'config': return makeRecord(['mode', 'depth', 'deadlock', 'worker', 'traces', 'seed', 'fingerprint'], ['bfs', -1, this.opts.checkDeadlock, 1, 0, 0, 0]);
|
|
114
|
-
case 'stats': return makeRecord(['distinct', 'generated', 'queue', 'diameter', 'duration'], [this.states.length, this.generated, this.states.length - this.head, this.depth, 0]);
|
|
115
|
-
}
|
|
116
|
-
if (k === 'revision')
|
|
117
|
-
return makeRecord(['tag', 'count', 'timestamp', 'date', 'calver'], ['development', 0, 0, '', 'everystate']);
|
|
118
|
-
if (k === 'spec') {
|
|
119
|
-
// structure of TLC's TLCGet("spec"), without coverage statistics
|
|
120
|
-
const m = this.model;
|
|
121
|
-
const item = (name, loc, module) => makeRecord(['name', 'location'], [name,
|
|
122
|
-
makeRecord(['beginLine', 'beginColumn', 'endLine', 'endColumn', 'module'], [loc?.[0] ?? 0, loc?.[1] ?? 0, loc?.[2] ?? 0, loc?.[3] ?? 0, module ?? m.rootName])]);
|
|
123
|
-
const preds = (ps) => mkSet(ps.map(p => item(p.name, p.e.loc, p.e.mod)));
|
|
124
|
-
return makeRecord(['inits', 'actions', 'invariants', 'impliedinits', 'impliedactions', 'impliedtemporals', 'temporals', 'constraints', 'actionconstraints', 'variables'], [preds(m.inits), mkSet(m.actions.map(a => item(a.name, a.loc, a.module))), preds(m.invariants), preds(m.impliedInits), preds(m.impliedActions),
|
|
125
|
-
preds(m.liveProps), preds(m.fairness), preds(m.constraints), preds(m.actionConstraints), mkSet(m.vars.map(v => item(v.name, undefined, v.module)))]);
|
|
126
|
-
}
|
|
127
|
-
if (k.startsWith('-D'))
|
|
128
|
-
return k.endsWith('.cdot') ? 'true' : 'false';
|
|
129
|
-
return undefined;
|
|
130
|
-
}
|
|
131
|
-
fingerprint(s) {
|
|
132
|
-
const h = this.hasher;
|
|
133
|
-
h.reset();
|
|
134
|
-
const m = this.model;
|
|
135
|
-
let t = s;
|
|
136
|
-
if (m.symmetry) {
|
|
137
|
-
for (const p of m.symmetry) {
|
|
138
|
-
const u = s.map(v => permute(v, p));
|
|
139
|
-
if (this.stateLess(u, t))
|
|
140
|
-
t = u;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
if (m.view) {
|
|
144
|
-
this.ev.cur = t;
|
|
145
|
-
this.ev.nxt = null;
|
|
146
|
-
this.ev.initMode = false;
|
|
147
|
-
h.value(this.ev.eval(m.view.e, m.view.ctx));
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
for (let i = 0; i < t.length; i++)
|
|
151
|
-
h.value(t[i]);
|
|
152
|
-
}
|
|
153
|
-
h.finish();
|
|
154
|
-
}
|
|
155
|
-
stateLess(a, b) {
|
|
156
|
-
for (let i = 0; i < a.length; i++) {
|
|
157
|
-
const c = compare(a[i], b[i]);
|
|
158
|
-
if (c !== 0)
|
|
159
|
-
return c < 0;
|
|
160
|
-
}
|
|
161
|
-
return false;
|
|
162
|
-
}
|
|
163
|
-
result(status, extra = {}) {
|
|
164
|
-
return {
|
|
165
|
-
status, generated: this.generated, distinct: this.states.length, queue: Math.max(0, this.states.length - this.head),
|
|
166
|
-
depth: this.depth, initGenerated: this.initGenerated, initDistinct: this.initDistinct, printSummary: true,
|
|
167
|
-
outdegree: this.outdegree(), ...extra,
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
outdegree() {
|
|
171
|
-
if (!this.outdeg.length)
|
|
172
|
-
return undefined;
|
|
173
|
-
const d = this.outdeg.slice().sort((x, y) => x - y);
|
|
174
|
-
return { min: d[0], avg: Math.round(d.reduce((x, y) => x + y, 0) / d.length), p95: d[Math.min(d.length - 1, Math.ceil(d.length * 0.95) - 1)], max: d[d.length - 1] };
|
|
175
|
-
}
|
|
176
|
-
traceTo(id) {
|
|
177
|
-
const out = [];
|
|
178
|
-
for (let i = id; i >= 0; i = this.parent[i]) {
|
|
179
|
-
out.push({ state: this.states[i], action: this.act[i] >= 0 ? this.model.actions[this.act[i]] : null, id: i });
|
|
180
|
-
}
|
|
181
|
-
return out.reverse();
|
|
182
|
-
}
|
|
183
|
-
evalPred(p, s, t) {
|
|
184
|
-
const ev = this.ev;
|
|
185
|
-
ev.cur = s;
|
|
186
|
-
ev.nxt = t;
|
|
187
|
-
ev.initMode = false;
|
|
188
|
-
ev.primeDepth = 0;
|
|
189
|
-
ev.callDepth = 0;
|
|
190
|
-
ev.nAssigned = 0;
|
|
191
|
-
return ev.evalBool(p.e, p.ctx);
|
|
192
|
-
}
|
|
193
|
-
// Re-run a failing evaluation while recording the chain of nested expressions being evaluated.
|
|
194
|
-
nestedExpressions(p, s, t) {
|
|
195
|
-
const ev = this.ev;
|
|
196
|
-
const stack = [];
|
|
197
|
-
const proto = Object.getPrototypeOf(ev);
|
|
198
|
-
ev.eval = function (n, ctx) {
|
|
199
|
-
stack.push(n);
|
|
200
|
-
const v = proto.eval.call(this, n, ctx);
|
|
201
|
-
stack.pop();
|
|
202
|
-
return v;
|
|
203
|
-
};
|
|
204
|
-
try {
|
|
205
|
-
this.evalPred(p, s, t);
|
|
206
|
-
}
|
|
207
|
-
catch { /* expected */ }
|
|
208
|
-
finally {
|
|
209
|
-
delete ev.eval;
|
|
210
|
-
}
|
|
211
|
-
const lines = [];
|
|
212
|
-
let last = null;
|
|
213
|
-
for (const n of stack) {
|
|
214
|
-
if (n === p.e || n === last || !n.loc || n.loc[0] === 0 || n.k === 'num' || n.k === 'str')
|
|
215
|
-
continue;
|
|
216
|
-
last = n;
|
|
217
|
-
lines.push(`${lines.length}. Line ${n.loc[0]}, column ${n.loc[1]} to line ${n.loc[2]}, column ${n.loc[3]} in ${n.mod ?? this.model.rootName}`);
|
|
218
|
-
}
|
|
219
|
-
return lines.length ? lines.join('\n') + '\n' : ' The error call stack is empty.\n';
|
|
220
|
-
}
|
|
221
|
-
checkAssumptions() {
|
|
222
|
-
const ev = this.ev;
|
|
223
|
-
for (const a of this.model.root.assumes) {
|
|
224
|
-
ev.cur = [];
|
|
225
|
-
ev.nxt = null;
|
|
226
|
-
ev.initMode = false;
|
|
227
|
-
let ok;
|
|
228
|
-
try {
|
|
229
|
-
ok = ev.eval(a.e, null);
|
|
230
|
-
}
|
|
231
|
-
catch (e) {
|
|
232
|
-
if (e instanceof TlaError)
|
|
233
|
-
return this.result('error', { code: 2105, message: `Evaluating assumption ${locStr(a.e.loc, a.module)} failed.\n${e.message}`, printSummary: false });
|
|
234
|
-
throw e;
|
|
235
|
-
}
|
|
236
|
-
if (typeof ok !== 'boolean')
|
|
237
|
-
return this.result('error', { message: `The assumption ${locStr(a.e.loc, a.module)} was not a boolean.`, printSummary: false });
|
|
238
|
-
if (!ok)
|
|
239
|
-
return this.result('assumption', { message: `Assumption ${locStr(a.e.loc, a.module)} is false.`, printSummary: false });
|
|
240
|
-
}
|
|
241
|
-
return null;
|
|
242
|
-
}
|
|
243
|
-
describeErr(e, withLoc = true) {
|
|
244
|
-
if (e instanceof RangeError)
|
|
245
|
-
return 'Stack overflow while evaluating the specification (recursion too deep). Re-run with a larger stack.';
|
|
246
|
-
if (e instanceof TlaError) {
|
|
247
|
-
let m = e.message;
|
|
248
|
-
if (withLoc && e.loc && e.loc[0] > 0)
|
|
249
|
-
m += `\n(evaluating the expression at line ${e.loc[0]}, col ${e.loc[1]} to line ${e.loc[2]}, col ${e.loc[3]} of module ${e.module ?? '?'})`;
|
|
250
|
-
return m;
|
|
251
|
-
}
|
|
252
|
-
throw e;
|
|
253
|
-
}
|
|
254
|
-
// Enumerate initial states.
|
|
255
|
-
computeInit() {
|
|
256
|
-
const ev = this.ev, m = this.model;
|
|
257
|
-
const found = [];
|
|
258
|
-
ev.cur = new Array(this.nvars);
|
|
259
|
-
ev.nxt = null;
|
|
260
|
-
ev.initMode = true;
|
|
261
|
-
ev.primeDepth = 0;
|
|
262
|
-
ev.nAssigned = 0;
|
|
263
|
-
const preds = m.inits;
|
|
264
|
-
if (preds.length === 0)
|
|
265
|
-
return null;
|
|
266
|
-
const go = (i) => {
|
|
267
|
-
if (i === preds.length) {
|
|
268
|
-
const s = ev.cur;
|
|
269
|
-
for (let k = 0; k < this.nvars; k++) {
|
|
270
|
-
if (s[k] === undefined) {
|
|
271
|
-
const missing = m.vars.filter((_, j) => s[j] === undefined).map(v => v.name).sort();
|
|
272
|
-
throw new CheckError(this.result('init-error', { message: `current state is not a legal state\nWhile working on the initial state:\n` + `The variable${missing.length > 1 ? 's' : ''} ${missing.join(', ')} ${missing.length > 1 ? 'are' : 'is'} not assigned a value by the initial predicate.` }));
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
found.push(s.slice());
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
ev.enumerate(preds[i].e, preds[i].ctx, () => go(i + 1));
|
|
279
|
-
};
|
|
280
|
-
try {
|
|
281
|
-
go(0);
|
|
282
|
-
}
|
|
283
|
-
catch (e) {
|
|
284
|
-
ev.initMode = false;
|
|
285
|
-
if (e instanceof CheckError)
|
|
286
|
-
return e.result;
|
|
287
|
-
return this.result('error', { message: this.describeErr(e) });
|
|
288
|
-
}
|
|
289
|
-
ev.initMode = false;
|
|
290
|
-
this.curLevel = 1;
|
|
291
|
-
for (const s of found) {
|
|
292
|
-
this.generated++;
|
|
293
|
-
this.initGenerated++;
|
|
294
|
-
let inModel, unseen = true, id = -1;
|
|
295
|
-
try {
|
|
296
|
-
inModel = m.constraints.every(c => this.evalPred(c, s, null));
|
|
297
|
-
if (inModel) {
|
|
298
|
-
this.fingerprint(s);
|
|
299
|
-
id = this.states.length;
|
|
300
|
-
unseen = this.fps.put(this.hasher.h1, this.hasher.h2, id) < 0;
|
|
301
|
-
if (unseen) {
|
|
302
|
-
this.states.push(s);
|
|
303
|
-
this.parent.push(-1);
|
|
304
|
-
this.level.push(1);
|
|
305
|
-
this.act.push(-1);
|
|
306
|
-
this.inits.push(id);
|
|
307
|
-
if (this.opts.recordGraph) {
|
|
308
|
-
this.succ.push([]);
|
|
309
|
-
this.succAct.push([]);
|
|
310
|
-
}
|
|
311
|
-
this.depth = Math.max(this.depth, 1);
|
|
312
|
-
this.initDistinct++;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
catch (e) {
|
|
317
|
-
return this.result('error', { message: this.describeErr(e), trace: [{ state: s, action: null, id: -1 }] });
|
|
318
|
-
}
|
|
319
|
-
if (unseen) {
|
|
320
|
-
for (const inv of m.invariants) {
|
|
321
|
-
let ok;
|
|
322
|
-
try {
|
|
323
|
-
ok = this.evalPred(inv, s, null);
|
|
324
|
-
}
|
|
325
|
-
catch (e) {
|
|
326
|
-
return this.result('error', { code: 2111, message: `Evaluating invariant ${inv.name} failed.\n${this.describeErr(e)}`, trace: [{ state: s, action: null, id: -1 }] });
|
|
327
|
-
}
|
|
328
|
-
if (!ok)
|
|
329
|
-
return this.result('invariant-init', { name: inv.name, trace: [{ state: s, action: null, id }], printSummary: false });
|
|
330
|
-
}
|
|
331
|
-
for (const p of m.impliedInits) {
|
|
332
|
-
let ok;
|
|
333
|
-
try {
|
|
334
|
-
ok = this.evalPred(p, s, null);
|
|
335
|
-
}
|
|
336
|
-
catch (e) {
|
|
337
|
-
return this.result('error', { message: `Evaluating property ${p.name} failed.\n${this.describeErr(e)}`, trace: [{ state: s, action: null, id: -1 }] });
|
|
338
|
-
}
|
|
339
|
-
if (!ok)
|
|
340
|
-
return this.result('implied-init', { name: p.name, trace: [{ state: s, action: null, id }], printSummary: false });
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
return null;
|
|
345
|
-
}
|
|
346
|
-
// Successors of one state, as (state, action index) pairs in action order.
|
|
347
|
-
successors(s, out, outAct) {
|
|
348
|
-
const ev = this.ev, m = this.model, n = this.nvars;
|
|
349
|
-
const actions = m.actions;
|
|
350
|
-
for (let ai = 0; ai < actions.length; ai++) {
|
|
351
|
-
const a = actions[ai];
|
|
352
|
-
ev.cur = s;
|
|
353
|
-
ev.nxt = new Array(n);
|
|
354
|
-
ev.initMode = false;
|
|
355
|
-
ev.primeDepth = 0;
|
|
356
|
-
ev.callDepth = 0;
|
|
357
|
-
ev.nAssigned = 0;
|
|
358
|
-
const nxt = ev.nxt;
|
|
359
|
-
ev.enumerate(a.e, a.ctx, () => {
|
|
360
|
-
for (let k = 0; k < n; k++) {
|
|
361
|
-
if (nxt[k] === undefined) {
|
|
362
|
-
const missing = m.vars.filter((_, j) => nxt[j] === undefined).map(v => v.name).sort();
|
|
363
|
-
const which = actions.length === 1 ? 'the next-state action' : `action ${a.name} of the next-state relation`;
|
|
364
|
-
throw new CheckError(this.result('incomplete', {
|
|
365
|
-
message: `Successor state is not completely specified by ${which}. The following variable${missing.length > 1 ? 's are' : ' is'} not defined: ${missing.join(', ')}.`,
|
|
366
|
-
}));
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
out.push(nxt.slice());
|
|
370
|
-
outAct.push(ai);
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
run() {
|
|
375
|
-
const m = this.model;
|
|
376
|
-
const a0 = this.checkAssumptions();
|
|
377
|
-
if (a0)
|
|
378
|
-
return a0;
|
|
379
|
-
const i0 = this.computeInit();
|
|
380
|
-
if (i0)
|
|
381
|
-
return i0;
|
|
382
|
-
this.opts.onProgress?.(-1, this.initDistinct, 0);
|
|
383
|
-
const succs = [], succAct = [];
|
|
384
|
-
const record = !!this.opts.recordGraph;
|
|
385
|
-
let lastProgress = Date.now();
|
|
386
|
-
if (m.inits.length === 0)
|
|
387
|
-
return this.result('ok');
|
|
388
|
-
if (m.actions.length === 0)
|
|
389
|
-
return this.result('error', { code: 2115, message: 'No next state actions defined to generate successor states from.', printSummary: false });
|
|
390
|
-
while (this.head < this.states.length && !this.stopRequested) {
|
|
391
|
-
const sid = this.head++;
|
|
392
|
-
const s = this.states[sid];
|
|
393
|
-
this.curLevel = this.level[sid];
|
|
394
|
-
succs.length = 0;
|
|
395
|
-
succAct.length = 0;
|
|
396
|
-
try {
|
|
397
|
-
this.successors(s, succs, succAct);
|
|
398
|
-
}
|
|
399
|
-
catch (e) {
|
|
400
|
-
if (e instanceof CheckError) {
|
|
401
|
-
e.result.trace = this.traceTo(sid);
|
|
402
|
-
e.result.queue = this.states.length - this.head;
|
|
403
|
-
return e.result;
|
|
404
|
-
}
|
|
405
|
-
return this.result('error', { message: this.describeErr(e), trace: this.traceTo(sid) });
|
|
406
|
-
}
|
|
407
|
-
if (this.ev.extraGenerated) {
|
|
408
|
-
this.generated += this.ev.extraGenerated;
|
|
409
|
-
this.ev.extraGenerated = 0;
|
|
410
|
-
}
|
|
411
|
-
let fresh = 0;
|
|
412
|
-
const lvl = this.curLevel;
|
|
413
|
-
for (let i = 0; i < succs.length; i++) {
|
|
414
|
-
const t = succs[i];
|
|
415
|
-
this.generated++;
|
|
416
|
-
let inModel = true, unseen = true, id = -1;
|
|
417
|
-
try {
|
|
418
|
-
this.curLevel = lvl + 1;
|
|
419
|
-
for (const c of m.constraints)
|
|
420
|
-
if (!this.evalPred(c, t, null)) {
|
|
421
|
-
inModel = false;
|
|
422
|
-
break;
|
|
423
|
-
}
|
|
424
|
-
this.curLevel = lvl;
|
|
425
|
-
if (inModel)
|
|
426
|
-
for (const c of m.actionConstraints)
|
|
427
|
-
if (!this.evalPred(c, s, t)) {
|
|
428
|
-
inModel = false;
|
|
429
|
-
break;
|
|
430
|
-
}
|
|
431
|
-
this.curLevel = lvl + 1;
|
|
432
|
-
if (inModel) {
|
|
433
|
-
this.fingerprint(t);
|
|
434
|
-
const nid = this.states.length;
|
|
435
|
-
const ex = this.fps.put(this.hasher.h1, this.hasher.h2, nid);
|
|
436
|
-
if (ex < 0) {
|
|
437
|
-
id = nid;
|
|
438
|
-
this.states.push(t);
|
|
439
|
-
this.parent.push(sid);
|
|
440
|
-
this.level.push(this.level[sid] + 1);
|
|
441
|
-
this.act.push(succAct[i]);
|
|
442
|
-
if (record) {
|
|
443
|
-
this.succ.push([]);
|
|
444
|
-
this.succAct.push([]);
|
|
445
|
-
}
|
|
446
|
-
if (this.level[sid] + 1 > this.depth)
|
|
447
|
-
this.depth = this.level[sid] + 1;
|
|
448
|
-
fresh++;
|
|
449
|
-
}
|
|
450
|
-
else {
|
|
451
|
-
unseen = false;
|
|
452
|
-
id = ex;
|
|
453
|
-
}
|
|
454
|
-
if (record) {
|
|
455
|
-
this.succ[sid].push(id);
|
|
456
|
-
this.succAct[sid].push(succAct[i]);
|
|
457
|
-
if (this.succState)
|
|
458
|
-
(this.succState[sid] ??= []).push(t);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
catch (e) {
|
|
463
|
-
return this.result('error', { message: this.describeErr(e), trace: [...this.traceTo(sid), { state: t, action: m.actions[succAct[i]], id: -1 }] });
|
|
464
|
-
}
|
|
465
|
-
if (unseen) {
|
|
466
|
-
for (const inv of m.invariants) {
|
|
467
|
-
let ok;
|
|
468
|
-
try {
|
|
469
|
-
ok = this.evalPred(inv, t, null);
|
|
470
|
-
}
|
|
471
|
-
catch (e) {
|
|
472
|
-
const r = this.result('error', { code: 2111, message: `Evaluating invariant ${inv.name} failed.\n${this.describeErr(e, false)}`,
|
|
473
|
-
callStack: inModel ? undefined : this.nestedExpressions(inv, t, null),
|
|
474
|
-
trace: [...this.traceTo(sid), { state: t, action: m.actions[succAct[i]], id }] });
|
|
475
|
-
if (inModel)
|
|
476
|
-
r.queue = Math.max(0, r.queue - 1); // the new state has not been enqueued yet
|
|
477
|
-
return r;
|
|
478
|
-
}
|
|
479
|
-
if (!ok) {
|
|
480
|
-
const r = this.result('invariant', { name: inv.name, trace: [...this.traceTo(sid), { state: t, action: m.actions[succAct[i]], id }] });
|
|
481
|
-
if (inModel)
|
|
482
|
-
r.queue = Math.max(0, r.queue - 1);
|
|
483
|
-
return r;
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
this.curLevel = lvl;
|
|
488
|
-
for (const p of m.impliedActions) {
|
|
489
|
-
let ok;
|
|
490
|
-
try {
|
|
491
|
-
ok = this.evalPred(p, s, t);
|
|
492
|
-
}
|
|
493
|
-
catch (e) {
|
|
494
|
-
return this.result('error', { message: `Evaluating action property ${p.name} failed.\n${this.describeErr(e)}`, trace: [...this.traceTo(sid), { state: t, action: m.actions[succAct[i]], id }] });
|
|
495
|
-
}
|
|
496
|
-
if (!ok) {
|
|
497
|
-
const r = this.result('action-property', { name: p.name, trace: [...this.traceTo(sid), { state: t, action: m.actions[succAct[i]], id }] });
|
|
498
|
-
if (inModel && unseen)
|
|
499
|
-
r.queue = Math.max(0, r.queue - 1);
|
|
500
|
-
return r;
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
this.outdeg.push(fresh);
|
|
505
|
-
if (succs.length === 0 && this.opts.checkDeadlock) {
|
|
506
|
-
return this.result('deadlock', { trace: this.traceTo(sid) });
|
|
507
|
-
}
|
|
508
|
-
if (this.opts.onProgress && (sid & 1023) === 0) {
|
|
509
|
-
const now = Date.now();
|
|
510
|
-
if (now - lastProgress > 60000) {
|
|
511
|
-
lastProgress = now;
|
|
512
|
-
this.opts.onProgress(this.generated, this.states.length, this.states.length - this.head);
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
const r = this.result('ok');
|
|
517
|
-
return r;
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
export { SetV };
|
package/dist/cli.d.ts
DELETED
package/dist/cli.js
DELETED
package/dist/community.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Builtin } from './modules.ts';
|
|
2
|
-
import type { Fn } from './stdlib.ts';
|
|
3
|
-
export interface HostIO {
|
|
4
|
-
readFile(path: string): string;
|
|
5
|
-
writeFile(path: string, data: string): void;
|
|
6
|
-
appendFile(path: string, data: string): void;
|
|
7
|
-
exists(path: string): boolean;
|
|
8
|
-
env: Record<string, string>;
|
|
9
|
-
readBytes?(path: string): Uint8Array;
|
|
10
|
-
writeBytes?(path: string, data: Uint8Array): void;
|
|
11
|
-
exec?(command: string[], env?: Record<string, string>): {
|
|
12
|
-
exitValue: number;
|
|
13
|
-
stdout: string;
|
|
14
|
-
stderr: string;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
export declare const OVERRIDES: Record<string, Record<string, [Fn, Partial<Builtin>?]>>;
|