everystate 0.0.0-stage → 0.1.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/CONFORMANCE.md +64 -0
- package/LICENSE +21 -0
- package/README.md +124 -2
- package/dist/bundled.d.ts +1 -0
- package/dist/bundled.js +2 -0
- package/dist/cfg.d.ts +24 -0
- package/dist/cfg.js +252 -0
- package/dist/checker.d.ts +96 -0
- package/dist/checker.js +520 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +4 -0
- package/dist/community.d.ts +17 -0
- package/dist/community.js +1381 -0
- package/dist/entry.d.ts +2 -0
- package/dist/entry.js +39 -0
- package/dist/eval.d.ts +119 -0
- package/dist/eval.js +1533 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +24 -0
- package/dist/java.d.ts +2 -0
- package/dist/java.js +6 -0
- package/dist/lexer.d.ts +17 -0
- package/dist/lexer.js +255 -0
- package/dist/liveness.d.ts +80 -0
- package/dist/liveness.js +855 -0
- package/dist/main.d.ts +40 -0
- package/dist/main.js +494 -0
- package/dist/model.d.ts +56 -0
- package/dist/model.js +582 -0
- package/dist/modules.d.ts +91 -0
- package/dist/modules.js +649 -0
- package/dist/node-host.d.ts +2 -0
- package/dist/node-host.js +25 -0
- package/dist/parser.d.ts +30 -0
- package/dist/parser.js +1114 -0
- package/dist/pprint.d.ts +7 -0
- package/dist/pprint.js +647 -0
- package/dist/stdlib.d.ts +14 -0
- package/dist/stdlib.js +588 -0
- package/dist/values.d.ts +150 -0
- package/dist/values.js +822 -0
- package/package.json +51 -4
package/dist/cfg.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Value } from './values.ts';
|
|
2
|
+
export interface Config {
|
|
3
|
+
constants: {
|
|
4
|
+
name: string;
|
|
5
|
+
value?: Value;
|
|
6
|
+
subst?: string;
|
|
7
|
+
module?: string;
|
|
8
|
+
args?: Value[];
|
|
9
|
+
}[];
|
|
10
|
+
init?: string;
|
|
11
|
+
next?: string;
|
|
12
|
+
spec?: string;
|
|
13
|
+
invariants: string[];
|
|
14
|
+
properties: string[];
|
|
15
|
+
constraints: string[];
|
|
16
|
+
actionConstraints: string[];
|
|
17
|
+
symmetry?: string;
|
|
18
|
+
view?: string;
|
|
19
|
+
alias?: string;
|
|
20
|
+
postconditions: string[];
|
|
21
|
+
possible: string[];
|
|
22
|
+
checkDeadlock?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare function parseConfig(src: string): Config;
|
package/dist/cfg.js
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
// TLC configuration (.cfg) file parser.
|
|
2
|
+
import { TlaError } from "./lexer.js";
|
|
3
|
+
import { modelValue, mkSet, strId } from "./values.js";
|
|
4
|
+
const SECTIONS = new Set(['CONSTANT', 'CONSTANTS', 'INIT', 'NEXT', 'SPECIFICATION', 'INVARIANT', 'INVARIANTS',
|
|
5
|
+
'PROPERTY', 'PROPERTIES', 'CONSTRAINT', 'CONSTRAINTS', 'ACTION_CONSTRAINT', 'ACTION_CONSTRAINTS', 'SYMMETRY',
|
|
6
|
+
'VIEW', 'CHECK_DEADLOCK', 'ALIAS', 'POSTCONDITION', 'POSTCONDITIONS', '_POSSIBLE', '_PERIODIC', '_RL_REWARD', 'TYPE', 'TYPE_CONSTRAINT']);
|
|
7
|
+
const OPCHARS = '+-*/^&|%$#?@<>:.~=';
|
|
8
|
+
const OPCANON = { '\\circ': '\\o', '\\leq': '<=', '=<': '<=', '\\geq': '>=', '#': '/=', '\\neq': '/=', '\\union': '\\cup', '\\intersect': '\\cap' };
|
|
9
|
+
function tokenize(src) {
|
|
10
|
+
const out = [];
|
|
11
|
+
let i = 0, line = 1;
|
|
12
|
+
const n = src.length;
|
|
13
|
+
while (i < n) {
|
|
14
|
+
const c = src[i];
|
|
15
|
+
if (c === '\n') {
|
|
16
|
+
line++;
|
|
17
|
+
i++;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (/\s/.test(c)) {
|
|
21
|
+
i++;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (c === '\\' && src[i + 1] === '*') {
|
|
25
|
+
while (i < n && src[i] !== '\n')
|
|
26
|
+
i++;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (c === '(' && src[i + 1] === '*') {
|
|
30
|
+
let depth = 1;
|
|
31
|
+
i += 2;
|
|
32
|
+
while (i < n && depth > 0) {
|
|
33
|
+
if (src[i] === '\n')
|
|
34
|
+
line++;
|
|
35
|
+
if (src[i] === '(' && src[i + 1] === '*') {
|
|
36
|
+
depth++;
|
|
37
|
+
i += 2;
|
|
38
|
+
}
|
|
39
|
+
else if (src[i] === '*' && src[i + 1] === ')') {
|
|
40
|
+
depth--;
|
|
41
|
+
i += 2;
|
|
42
|
+
}
|
|
43
|
+
else
|
|
44
|
+
i++;
|
|
45
|
+
}
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (c === '"') {
|
|
49
|
+
let j = i + 1, s = '';
|
|
50
|
+
while (j < n && src[j] !== '"') {
|
|
51
|
+
if (src[j] === '\\') {
|
|
52
|
+
j++;
|
|
53
|
+
}
|
|
54
|
+
s += src[j++];
|
|
55
|
+
}
|
|
56
|
+
out.push({ t: 'str', v: s, line });
|
|
57
|
+
i = j + 1;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
let m = /^-?\d+(?![A-Za-z_])/.exec(src.slice(i, i + 40));
|
|
61
|
+
if (m) {
|
|
62
|
+
out.push({ t: 'num', v: m[0], line });
|
|
63
|
+
i += m[0].length;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
m = /^[A-Za-z0-9_!]+/.exec(src.slice(i, i + 400));
|
|
67
|
+
if (m) {
|
|
68
|
+
out.push({ t: 'id', v: m[0], line });
|
|
69
|
+
i += m[0].length;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (src.startsWith('<-', i)) {
|
|
73
|
+
out.push({ t: 'sym', v: '<-', line });
|
|
74
|
+
i += 2;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
// operator symbols (e.g. `++ <- PlusPlus`, `\\o <- +`)
|
|
78
|
+
m = /^\\[A-Za-z]+/.exec(src.slice(i, i + 40));
|
|
79
|
+
if (m) {
|
|
80
|
+
out.push({ t: 'id', v: OPCANON[m[0]] ?? m[0], line });
|
|
81
|
+
i += m[0].length;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (c !== '=' && OPCHARS.includes(c)) {
|
|
85
|
+
let j = i;
|
|
86
|
+
while (j < n && OPCHARS.includes(src[j]) && !(src.startsWith('<-', j) && j > i))
|
|
87
|
+
j++;
|
|
88
|
+
const sym = src.slice(i, j);
|
|
89
|
+
if (sym !== '<' || src[j] !== '-') {
|
|
90
|
+
out.push({ t: 'id', v: OPCANON[sym] ?? sym, line });
|
|
91
|
+
i = j;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
out.push({ t: 'sym', v: c, line });
|
|
96
|
+
i++;
|
|
97
|
+
}
|
|
98
|
+
out.push({ t: 'eof', v: '<EOF>', line });
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
export function parseConfig(src) {
|
|
102
|
+
const toks = tokenize(src);
|
|
103
|
+
let p = 0;
|
|
104
|
+
const cfg = { constants: [], invariants: [], properties: [], constraints: [], actionConstraints: [], postconditions: [], possible: [] };
|
|
105
|
+
const fail = (msg) => {
|
|
106
|
+
throw new TlaError(`TLC found an error in the configuration file at line ${toks[p].line}\n${msg}`, undefined, undefined, 'config');
|
|
107
|
+
};
|
|
108
|
+
const isSection = () => toks[p].t === 'id' && SECTIONS.has(toks[p].v);
|
|
109
|
+
const parseValue = () => {
|
|
110
|
+
const t = toks[p++];
|
|
111
|
+
if (t.t === 'num')
|
|
112
|
+
return Number(t.v);
|
|
113
|
+
if (t.t === 'str') {
|
|
114
|
+
strId(t.v);
|
|
115
|
+
return t.v;
|
|
116
|
+
}
|
|
117
|
+
if (t.t === 'id') {
|
|
118
|
+
if (t.v === 'TRUE')
|
|
119
|
+
return true;
|
|
120
|
+
if (t.v === 'FALSE')
|
|
121
|
+
return false;
|
|
122
|
+
return modelValue(t.v);
|
|
123
|
+
}
|
|
124
|
+
if (t.t === 'sym' && t.v === '{') {
|
|
125
|
+
const items = [];
|
|
126
|
+
if (toks[p].v === '}' && toks[p].t === 'sym') {
|
|
127
|
+
p++;
|
|
128
|
+
return mkSet(items);
|
|
129
|
+
}
|
|
130
|
+
for (;;) {
|
|
131
|
+
items.push(parseValue());
|
|
132
|
+
const s = toks[p++];
|
|
133
|
+
if (s.t === 'sym' && s.v === '}')
|
|
134
|
+
break;
|
|
135
|
+
if (!(s.t === 'sym' && s.v === ',')) {
|
|
136
|
+
p--;
|
|
137
|
+
fail(`Expected ',' or '}' but found '${s.v}'`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return mkSet(items);
|
|
141
|
+
}
|
|
142
|
+
p--;
|
|
143
|
+
return fail(`Unexpected token '${t.v}' in a constant value`);
|
|
144
|
+
};
|
|
145
|
+
const names = (into) => { while (toks[p].t === 'id' && !isSection())
|
|
146
|
+
into.push(toks[p++].v); };
|
|
147
|
+
const one = (what) => {
|
|
148
|
+
if (toks[p].t !== 'id' || isSection())
|
|
149
|
+
fail(`Expected an identifier after ${what}`);
|
|
150
|
+
return toks[p++].v;
|
|
151
|
+
};
|
|
152
|
+
while (toks[p].t !== 'eof') {
|
|
153
|
+
const t = toks[p];
|
|
154
|
+
if (!isSection())
|
|
155
|
+
fail(`Unexpected token '${t.v}'; expected a configuration keyword`);
|
|
156
|
+
p++;
|
|
157
|
+
switch (t.v) {
|
|
158
|
+
case 'CONSTANT':
|
|
159
|
+
case 'CONSTANTS':
|
|
160
|
+
while (toks[p].t === 'id' && !isSection()) {
|
|
161
|
+
const name = toks[p++].v;
|
|
162
|
+
let args;
|
|
163
|
+
if (toks[p].t === 'sym' && toks[p].v === '(') {
|
|
164
|
+
p++;
|
|
165
|
+
args = [];
|
|
166
|
+
for (;;) {
|
|
167
|
+
args.push(parseValue());
|
|
168
|
+
const s = toks[p++];
|
|
169
|
+
if (s.t === 'sym' && s.v === ')')
|
|
170
|
+
break;
|
|
171
|
+
if (!(s.t === 'sym' && s.v === ',')) {
|
|
172
|
+
p--;
|
|
173
|
+
fail(`Expected ',' or ')' but found '${s.v}'`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const op = toks[p++];
|
|
178
|
+
if (op.t === 'sym' && op.v === '=') {
|
|
179
|
+
let module;
|
|
180
|
+
if (toks[p].t === 'sym' && toks[p].v === '[') {
|
|
181
|
+
p++;
|
|
182
|
+
module = toks[p++].v;
|
|
183
|
+
p++;
|
|
184
|
+
}
|
|
185
|
+
cfg.constants.push({ name, value: parseValue(), module, args });
|
|
186
|
+
}
|
|
187
|
+
else if (op.t === 'sym' && op.v === '<-') {
|
|
188
|
+
let module;
|
|
189
|
+
if (toks[p].t === 'sym' && toks[p].v === '[') {
|
|
190
|
+
p++;
|
|
191
|
+
module = toks[p++].v;
|
|
192
|
+
p++;
|
|
193
|
+
}
|
|
194
|
+
cfg.constants.push({ name, subst: toks[p++].v, module });
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
p--;
|
|
198
|
+
fail(`Expected '=' or '<-' after constant ${name} but found '${op.v}'`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
break;
|
|
202
|
+
case 'INIT':
|
|
203
|
+
cfg.init = one('INIT');
|
|
204
|
+
break;
|
|
205
|
+
case 'NEXT':
|
|
206
|
+
cfg.next = one('NEXT');
|
|
207
|
+
break;
|
|
208
|
+
case 'SPECIFICATION':
|
|
209
|
+
cfg.spec = one('SPECIFICATION');
|
|
210
|
+
break;
|
|
211
|
+
case 'INVARIANT':
|
|
212
|
+
case 'INVARIANTS':
|
|
213
|
+
names(cfg.invariants);
|
|
214
|
+
break;
|
|
215
|
+
case 'PROPERTY':
|
|
216
|
+
case 'PROPERTIES':
|
|
217
|
+
names(cfg.properties);
|
|
218
|
+
break;
|
|
219
|
+
case 'CONSTRAINT':
|
|
220
|
+
case 'CONSTRAINTS':
|
|
221
|
+
names(cfg.constraints);
|
|
222
|
+
break;
|
|
223
|
+
case 'ACTION_CONSTRAINT':
|
|
224
|
+
case 'ACTION_CONSTRAINTS':
|
|
225
|
+
names(cfg.actionConstraints);
|
|
226
|
+
break;
|
|
227
|
+
case 'SYMMETRY':
|
|
228
|
+
cfg.symmetry = one('SYMMETRY');
|
|
229
|
+
break;
|
|
230
|
+
case 'VIEW':
|
|
231
|
+
cfg.view = one('VIEW');
|
|
232
|
+
break;
|
|
233
|
+
case 'ALIAS':
|
|
234
|
+
cfg.alias = one('ALIAS');
|
|
235
|
+
break;
|
|
236
|
+
case 'POSTCONDITION':
|
|
237
|
+
case 'POSTCONDITIONS':
|
|
238
|
+
names(cfg.postconditions);
|
|
239
|
+
break;
|
|
240
|
+
case '_POSSIBLE':
|
|
241
|
+
names(cfg.possible);
|
|
242
|
+
break;
|
|
243
|
+
case 'CHECK_DEADLOCK': {
|
|
244
|
+
const v = one('CHECK_DEADLOCK');
|
|
245
|
+
cfg.checkDeadlock = v === 'TRUE';
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
default: names([]);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return cfg;
|
|
252
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { Model, Pred, Action } from './model.ts';
|
|
2
|
+
import type { Evaluator } from './eval.ts';
|
|
3
|
+
import { Hasher, SetV, ModelValue } from './values.ts';
|
|
4
|
+
import type { Value } from './values.ts';
|
|
5
|
+
export type State = Value[];
|
|
6
|
+
export interface TraceStep {
|
|
7
|
+
state: State;
|
|
8
|
+
action: Action | null;
|
|
9
|
+
id: number;
|
|
10
|
+
}
|
|
11
|
+
export interface CheckResult {
|
|
12
|
+
status: 'ok' | 'invariant' | 'invariant-init' | 'deadlock' | 'action-property' | 'implied-init' | 'liveness' | 'error' | 'assumption' | 'incomplete' | 'init-error';
|
|
13
|
+
name?: string;
|
|
14
|
+
message?: string;
|
|
15
|
+
trace?: TraceStep[];
|
|
16
|
+
loopTo?: number;
|
|
17
|
+
loopAction?: Action | null;
|
|
18
|
+
errorLoc?: string;
|
|
19
|
+
liveBranches?: number;
|
|
20
|
+
callStack?: string;
|
|
21
|
+
code?: number;
|
|
22
|
+
generated: number;
|
|
23
|
+
distinct: number;
|
|
24
|
+
queue: number;
|
|
25
|
+
depth: number;
|
|
26
|
+
initGenerated: number;
|
|
27
|
+
initDistinct: number;
|
|
28
|
+
printSummary: boolean;
|
|
29
|
+
outdegree?: {
|
|
30
|
+
min: number;
|
|
31
|
+
avg: number;
|
|
32
|
+
p95: number;
|
|
33
|
+
max: number;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export interface CheckOptions {
|
|
37
|
+
checkDeadlock: boolean;
|
|
38
|
+
recordGraph?: boolean;
|
|
39
|
+
onProgress?: (generated: number, distinct: number, queue: number) => void;
|
|
40
|
+
maxDepth?: number;
|
|
41
|
+
onChecker?: (c: Checker) => void;
|
|
42
|
+
onLiveness?: (phase: 'branches' | 'start' | 'end', branches: number) => void;
|
|
43
|
+
}
|
|
44
|
+
export declare class FpSet {
|
|
45
|
+
cap: number;
|
|
46
|
+
k1: Int32Array<ArrayBuffer>;
|
|
47
|
+
k2: Int32Array<ArrayBuffer>;
|
|
48
|
+
ids: Int32Array<ArrayBuffer>;
|
|
49
|
+
size: number;
|
|
50
|
+
put(h1: number, h2: number, id: number): number;
|
|
51
|
+
grow(): void;
|
|
52
|
+
}
|
|
53
|
+
export declare function permute(v: Value, m: Map<ModelValue, ModelValue>): Value;
|
|
54
|
+
export declare class CheckError extends Error {
|
|
55
|
+
result: CheckResult;
|
|
56
|
+
constructor(result: CheckResult);
|
|
57
|
+
}
|
|
58
|
+
export declare class Checker {
|
|
59
|
+
model: Model;
|
|
60
|
+
ev: Evaluator;
|
|
61
|
+
opts: CheckOptions;
|
|
62
|
+
states: State[];
|
|
63
|
+
parent: number[];
|
|
64
|
+
level: number[];
|
|
65
|
+
act: number[];
|
|
66
|
+
succ: number[][];
|
|
67
|
+
succAct: number[][];
|
|
68
|
+
succState: State[][] | null;
|
|
69
|
+
inits: number[];
|
|
70
|
+
fps: FpSet;
|
|
71
|
+
hasher: Hasher;
|
|
72
|
+
generated: number;
|
|
73
|
+
initGenerated: number;
|
|
74
|
+
initDistinct: number;
|
|
75
|
+
head: number;
|
|
76
|
+
depth: number;
|
|
77
|
+
nvars: number;
|
|
78
|
+
outdeg: number[];
|
|
79
|
+
constructor(model: Model, opts: CheckOptions);
|
|
80
|
+
curLevel: number;
|
|
81
|
+
stopRequested: boolean;
|
|
82
|
+
tlcGet(k: string): Value;
|
|
83
|
+
fingerprint(s: State): void;
|
|
84
|
+
stateLess(a: State, b: State): boolean;
|
|
85
|
+
result(status: CheckResult['status'], extra?: Partial<CheckResult>): CheckResult;
|
|
86
|
+
outdegree(): CheckResult['outdegree'];
|
|
87
|
+
traceTo(id: number): TraceStep[];
|
|
88
|
+
evalPred(p: Pred, s: State, t: State | null): boolean;
|
|
89
|
+
nestedExpressions(p: Pred, s: State, t: State | null): string;
|
|
90
|
+
checkAssumptions(): CheckResult | null;
|
|
91
|
+
describeErr(e: unknown, withLoc?: boolean): string;
|
|
92
|
+
computeInit(): CheckResult | null;
|
|
93
|
+
successors(s: State, out: State[], outAct: number[]): void;
|
|
94
|
+
run(): CheckResult;
|
|
95
|
+
}
|
|
96
|
+
export { SetV };
|