@milkenjoyer/toolchain 0.11.0 → 0.12.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 +98 -14
- package/dist/conformance.d.mts +18 -0
- package/dist/conformance.mjs +31 -0
- package/dist/effect-plugin.mjs +1 -1
- package/dist/exceptions-Dybl9xpc.mjs +11 -0
- package/dist/exceptions.mjs +1 -1
- package/dist/foldkit-plugin.mjs +1 -1
- package/dist/formal.d.mts +131 -3
- package/dist/formal.mjs +716 -65
- package/dist/guard.mjs +2 -2
- package/dist/{lint-JSnPsGO1.mjs → lint-IhmtnBbx.mjs} +3 -3
- package/dist/lint.mjs +1 -1
- package/dist/plugin.mjs +1 -1
- package/dist/proof.mjs +1 -1
- package/dist/trace-file-KuPRWgwt.mjs +17 -0
- package/dist/verdict.d.mts +1 -1
- package/dist/verdict.mjs +1 -1
- package/dist/{verification-p2rSx5lc.d.mts → verification-FgQFU1YN.d.mts} +1 -1
- package/dist/verification.d.mts +1 -1
- package/dist/verification.mjs +1 -1
- package/package.json +6 -2
- package/src/formal/cfg.ts +58 -1
- package/src/formal/checks.ts +39 -52
- package/src/formal/coverage.ts +79 -0
- package/src/formal/gate.ts +74 -0
- package/src/formal/git.ts +38 -0
- package/src/formal/proofs.ts +217 -0
- package/src/formal/semantics.ts +110 -0
- package/src/formal/specs.ts +80 -34
- package/src/formal/tla.ts +24 -2
- package/src/formal/trace-file.ts +35 -0
- package/src/formal/traces.ts +293 -0
- package/src/formal/violations.ts +76 -0
- package/src/formal.ts +9 -2
- package/dist/exceptions-Bq-9MxoR.mjs +0 -3
- package/dist/{effect-plugin-kYxB-5LJ.mjs → effect-plugin-BXUx9PPu.mjs} +1 -1
- package/dist/{plugin-BoBRGtGf.mjs → plugin-CwxhPtui.mjs} +1 -1
- package/dist/{verification-6s2chr4X.mjs → verification-oAc1Q6I9.mjs} +1 -1
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { dirname, join } from "node:path";
|
|
2
|
+
|
|
3
|
+
import * as Console from "effect/Console";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import { FileSystem } from "effect/FileSystem";
|
|
6
|
+
|
|
7
|
+
import type { Check } from "./checks.ts";
|
|
8
|
+
import { Gate } from "./gate.ts";
|
|
9
|
+
import { changes } from "./git.ts";
|
|
10
|
+
import { FormalError } from "./tla.ts";
|
|
11
|
+
import { held, violate } from "./violations.ts";
|
|
12
|
+
const matches = (glob: string, file: string) => new Bun.Glob(glob).match(file);
|
|
13
|
+
export const critical: Check = (repo) =>
|
|
14
|
+
Effect.succeed([
|
|
15
|
+
...repo.file.critical.flatMap((glob) =>
|
|
16
|
+
repo.tracked.some((f) => matches(glob, f))
|
|
17
|
+
? []
|
|
18
|
+
: [
|
|
19
|
+
{
|
|
20
|
+
file: "specs.json",
|
|
21
|
+
message: `critical glob ${glob} matches no tracked file`,
|
|
22
|
+
},
|
|
23
|
+
]
|
|
24
|
+
),
|
|
25
|
+
...Object.entries({ ...repo.file.specs, ...repo.file.kani }).flatMap(
|
|
26
|
+
([file, e]) =>
|
|
27
|
+
e.covers.flatMap((glob) =>
|
|
28
|
+
repo.tracked.some((f) => matches(glob, f))
|
|
29
|
+
? []
|
|
30
|
+
: [{ file, message: `covers glob ${glob} matches no tracked file` }]
|
|
31
|
+
)
|
|
32
|
+
),
|
|
33
|
+
...repo.tracked.flatMap((file) => {
|
|
34
|
+
const glob = repo.file.critical.find((g) => matches(g, file));
|
|
35
|
+
return glob !== undefined &&
|
|
36
|
+
!Object.values({ ...repo.file.specs, ...repo.file.kani }).some(
|
|
37
|
+
(e) => e.mode !== "library" && e.covers.some((g) => matches(g, file))
|
|
38
|
+
)
|
|
39
|
+
? [
|
|
40
|
+
{
|
|
41
|
+
file,
|
|
42
|
+
message: `matches critical glob ${glob} but no spec covers it`,
|
|
43
|
+
},
|
|
44
|
+
]
|
|
45
|
+
: [];
|
|
46
|
+
}),
|
|
47
|
+
]);
|
|
48
|
+
export const fairness: Check = (repo) =>
|
|
49
|
+
Effect.succeed(
|
|
50
|
+
repo.specs.flatMap((s) =>
|
|
51
|
+
s.analysis._tag === "Parsed"
|
|
52
|
+
? s.analysis.semantics.fairness
|
|
53
|
+
.filter((f) => !f.valid)
|
|
54
|
+
.map((f) => ({
|
|
55
|
+
file: s.path,
|
|
56
|
+
message: `${f.kind} at line ${f.line}; fairness must be WF_vars or SF_vars`,
|
|
57
|
+
}))
|
|
58
|
+
: []
|
|
59
|
+
)
|
|
60
|
+
);
|
|
61
|
+
export const coverageCheck: Check = (repo) =>
|
|
62
|
+
Effect.gen(function* () {
|
|
63
|
+
const gate = yield* Gate;
|
|
64
|
+
const fs = yield* FileSystem;
|
|
65
|
+
const problems: { file: string; message: string }[] = [];
|
|
66
|
+
for (const m of repo.models.filter((m) => m.entry.mode === "gate")) {
|
|
67
|
+
const result = yield* gate.run(m);
|
|
68
|
+
if (result._tag === "Failed") continue;
|
|
69
|
+
const start = problems.length;
|
|
70
|
+
for (const a of result.coverage.actions.filter((a) => a.generated === 0n))
|
|
71
|
+
problems.push({
|
|
72
|
+
file: m.path,
|
|
73
|
+
message: `action ${a.name} (line ${a.span.line}) is never enabled`,
|
|
74
|
+
});
|
|
75
|
+
for (const z of result.coverage.zeros) {
|
|
76
|
+
const candidate = join(dirname(m.path), `${z.span.module}.tla`);
|
|
77
|
+
const file = repo.tracked.includes(candidate) ? candidate : m.path;
|
|
78
|
+
const source = (yield* fs.readFileString(`${repo.root}/${file}`))
|
|
79
|
+
.split("\n")
|
|
80
|
+
.slice(z.span.line - 1, z.span.endLine)
|
|
81
|
+
.join("\n")
|
|
82
|
+
.slice(
|
|
83
|
+
z.span.col - 1,
|
|
84
|
+
z.span.endLine === z.span.line ? z.span.endCol : undefined
|
|
85
|
+
)
|
|
86
|
+
.slice(0, 60);
|
|
87
|
+
problems.push({
|
|
88
|
+
file,
|
|
89
|
+
message: `line ${z.span.line}, col ${z.span.col} to line ${z.span.endLine}, col ${z.span.endCol} never runs in ${z.scope}: ${source}`,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
if (problems.length === start)
|
|
93
|
+
yield* Console.log(`coverage: ${m.path}: no dead logic`);
|
|
94
|
+
}
|
|
95
|
+
return problems;
|
|
96
|
+
}).pipe(Effect.mapError((e) => new FormalError({ message: String(e) })));
|
|
97
|
+
export const witnesses: Check = (repo) =>
|
|
98
|
+
Effect.gen(function* () {
|
|
99
|
+
const gate = yield* Gate;
|
|
100
|
+
const problems: { file: string; message: string }[] = [];
|
|
101
|
+
for (const m of repo.models) {
|
|
102
|
+
for (const name of m.entry.witnesses) {
|
|
103
|
+
const op = m.semantics.operators.get(name);
|
|
104
|
+
const message = !op
|
|
105
|
+
? `${name} is not defined`
|
|
106
|
+
: op.level === 2
|
|
107
|
+
? `${name} is an action; check [][${name}]_vars instead`
|
|
108
|
+
: op.params.length
|
|
109
|
+
? `${name} must have zero arguments`
|
|
110
|
+
: [
|
|
111
|
+
...m.config.cfg.invariants,
|
|
112
|
+
...m.config.cfg.properties,
|
|
113
|
+
].includes(name)
|
|
114
|
+
? `${name} is already checked by ${m.config.path}`
|
|
115
|
+
: undefined;
|
|
116
|
+
if (message !== undefined) {
|
|
117
|
+
problems.push({ file: m.path, message });
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (m.entry.mode !== "gate" || (yield* gate.run(m))._tag === "Failed")
|
|
121
|
+
continue;
|
|
122
|
+
const result = yield* violate(repo, m, name);
|
|
123
|
+
if (result !== undefined)
|
|
124
|
+
problems.push({
|
|
125
|
+
file: m.path,
|
|
126
|
+
message:
|
|
127
|
+
result === held
|
|
128
|
+
? `${name} holds; a witness must be violated`
|
|
129
|
+
: result,
|
|
130
|
+
});
|
|
131
|
+
else yield* Console.log(`witnesses: ${m.path}: ${name} violated`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return problems;
|
|
135
|
+
}).pipe(Effect.mapError((e) => new FormalError({ message: String(e) })));
|
|
136
|
+
export const breaks: Check = (repo) =>
|
|
137
|
+
Effect.gen(function* () {
|
|
138
|
+
const gate = yield* Gate;
|
|
139
|
+
const fs = yield* FileSystem;
|
|
140
|
+
const changed = yield* changes(repo.root);
|
|
141
|
+
const problems: { file: string; message: string }[] = [];
|
|
142
|
+
if (changed._tag === "All")
|
|
143
|
+
yield* Console.log(
|
|
144
|
+
`breaks: BASE ${changed.base} does not resolve; running every break`
|
|
145
|
+
);
|
|
146
|
+
for (const m of repo.models) {
|
|
147
|
+
const targets = [...m.config.cfg.invariants, ...m.config.cfg.properties];
|
|
148
|
+
for (const target of targets)
|
|
149
|
+
if (!m.entry.breaks.some((b) => b.violates === target))
|
|
150
|
+
problems.push({
|
|
151
|
+
file: m.config.path,
|
|
152
|
+
message: `${target} has no break`,
|
|
153
|
+
});
|
|
154
|
+
const dirty =
|
|
155
|
+
changed._tag === "All" ||
|
|
156
|
+
changed.files.some(
|
|
157
|
+
(f) =>
|
|
158
|
+
f === "specs.json" ||
|
|
159
|
+
(dirname(f) === dirname(m.path) && /\.(?:tla|cfg)$/u.test(f)) ||
|
|
160
|
+
m.entry.breaks.some((b) => b.file === f)
|
|
161
|
+
);
|
|
162
|
+
if (!dirty && m.entry.mode === "gate")
|
|
163
|
+
yield* Console.log(
|
|
164
|
+
`breaks: ${m.path}: unchanged since ${changed.sha.slice(0, 7)}, not run`
|
|
165
|
+
);
|
|
166
|
+
for (const [index, b] of m.entry.breaks.entries()) {
|
|
167
|
+
const label = `break ${index + 1}`;
|
|
168
|
+
const file = b.file ?? m.path;
|
|
169
|
+
if (!targets.includes(b.violates)) {
|
|
170
|
+
problems.push({
|
|
171
|
+
file: m.path,
|
|
172
|
+
message: `${label}: ${b.violates} is not checked by ${m.config.path}`,
|
|
173
|
+
});
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
if (
|
|
177
|
+
!repo.tracked.includes(file) ||
|
|
178
|
+
!(
|
|
179
|
+
file === m.config.path ||
|
|
180
|
+
(dirname(file) === dirname(m.path) && file.endsWith(".tla"))
|
|
181
|
+
)
|
|
182
|
+
) {
|
|
183
|
+
problems.push({
|
|
184
|
+
file: m.path,
|
|
185
|
+
message: `${label}: ${file} must be a tracked module in the spec directory or its config`,
|
|
186
|
+
});
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
const text = yield* fs.readFileString(`${repo.root}/${file}`);
|
|
190
|
+
const count = text.split(b.find).length - 1;
|
|
191
|
+
if (count !== 1) {
|
|
192
|
+
problems.push({
|
|
193
|
+
file: m.path,
|
|
194
|
+
message: `${label} find matches ${count} times in ${file}`,
|
|
195
|
+
});
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
if (
|
|
199
|
+
!dirty ||
|
|
200
|
+
m.entry.mode !== "gate" ||
|
|
201
|
+
(yield* gate.run(m))._tag === "Failed"
|
|
202
|
+
)
|
|
203
|
+
continue;
|
|
204
|
+
const result = yield* violate(repo, m, b.violates, b);
|
|
205
|
+
if (result !== undefined)
|
|
206
|
+
problems.push({
|
|
207
|
+
file: m.path,
|
|
208
|
+
message: `${label} (${b.violates}): ${result === held ? `${b.violates} still holds after the edit` : result}`,
|
|
209
|
+
});
|
|
210
|
+
else
|
|
211
|
+
yield* Console.log(
|
|
212
|
+
`breaks: ${m.path}: ${label} violated ${b.violates}`
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return problems;
|
|
217
|
+
}).pipe(Effect.mapError((e) => new FormalError({ message: String(e) })));
|
package/src/formal/semantics.ts
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
|
+
type Operator = {
|
|
2
|
+
readonly name: string;
|
|
3
|
+
readonly level: number;
|
|
4
|
+
readonly params: ReadonlyArray<{
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly arity: number;
|
|
7
|
+
}>;
|
|
8
|
+
readonly module: string;
|
|
9
|
+
};
|
|
1
10
|
export type Semantics = {
|
|
11
|
+
readonly operators: ReadonlyMap<string, Operator>;
|
|
12
|
+
readonly fairness: ReadonlyArray<{
|
|
13
|
+
readonly kind: string;
|
|
14
|
+
readonly line: string;
|
|
15
|
+
readonly valid: boolean;
|
|
16
|
+
}>;
|
|
17
|
+
readonly specifications: ReadonlyMap<
|
|
18
|
+
string,
|
|
19
|
+
{ readonly init: string; readonly next: string }
|
|
20
|
+
>;
|
|
2
21
|
readonly variables: ReadonlyArray<string>;
|
|
3
22
|
readonly typeOK: ReadonlySet<string> | undefined;
|
|
4
23
|
};
|
|
@@ -138,7 +157,98 @@ export const fromXml = (xml: string): Semantics => {
|
|
|
138
157
|
(node) => node !== undefined && value(node, "uniquename") === "TypeOK"
|
|
139
158
|
);
|
|
140
159
|
const body = typeOK && child(typeOK, "body")?.children[0];
|
|
160
|
+
const definitions = [...entries.values()].filter(
|
|
161
|
+
(n): n is Node =>
|
|
162
|
+
n?.tag === "UserDefinedOpKind" &&
|
|
163
|
+
closure.has(value(child(n, "location") ?? n, "filename"))
|
|
164
|
+
);
|
|
165
|
+
const operators = new Map<string, Operator>();
|
|
166
|
+
const fairness: { kind: string; line: string; valid: boolean }[] = [];
|
|
167
|
+
const specifications = new Map<string, { init: string; next: string }>();
|
|
168
|
+
const opName = (n: Node) => {
|
|
169
|
+
const t = target(n);
|
|
170
|
+
return t ? value(entries.get(t.uid) ?? n, "uniquename") : "";
|
|
171
|
+
};
|
|
172
|
+
for (const n of definitions) {
|
|
173
|
+
const name = value(n, "uniquename");
|
|
174
|
+
const params = (child(n, "params")?.children ?? [])
|
|
175
|
+
.map(
|
|
176
|
+
(ref) =>
|
|
177
|
+
entries.get(value(child(ref, "FormalParamNodeRef") ?? ref, "UID")) ??
|
|
178
|
+
ref
|
|
179
|
+
)
|
|
180
|
+
.map((p) => ({
|
|
181
|
+
name: value(p, "uniquename"),
|
|
182
|
+
arity: Number(value(p, "arity")),
|
|
183
|
+
}));
|
|
184
|
+
operators.set(name, {
|
|
185
|
+
name,
|
|
186
|
+
level: Number(value(n, "level")),
|
|
187
|
+
params,
|
|
188
|
+
module: value(child(n, "location") ?? n, "filename"),
|
|
189
|
+
});
|
|
190
|
+
if (
|
|
191
|
+
value(child(n, "location") ?? n, "filename") ===
|
|
192
|
+
value(modules, "RootModule")
|
|
193
|
+
)
|
|
194
|
+
for (const a of descendants(child(n, "body") ?? n)) {
|
|
195
|
+
const kind = opName(a);
|
|
196
|
+
if (!["$WF", "$SF"].includes(kind)) continue;
|
|
197
|
+
const sub = operands(a)[0];
|
|
198
|
+
fairness.push({
|
|
199
|
+
kind: `${kind.slice(1)}_${sub && opName(sub) === "$Tuple" ? `<< ${operands(sub).map(opName).join(", ")} >>` : sub ? opName(sub) : "?"}`,
|
|
200
|
+
line: value(child(child(a, "location") ?? a, "line") ?? a, "begin"),
|
|
201
|
+
valid:
|
|
202
|
+
sub !== undefined &&
|
|
203
|
+
opName(sub) === "vars" &&
|
|
204
|
+
operands(sub).length === 0,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
const flatten = (a: Node, seen = new Set<string>()): Node[] => {
|
|
208
|
+
const t = target(a);
|
|
209
|
+
if (["$ConjList", "\\land"].includes(opName(a)))
|
|
210
|
+
return operands(a).flatMap((x) => flatten(x, new Set(seen)));
|
|
211
|
+
if (
|
|
212
|
+
t &&
|
|
213
|
+
t.ref.tag === "UserDefinedOpKindRef" &&
|
|
214
|
+
Number(value(a, "level")) === 3 &&
|
|
215
|
+
operands(a).length === 0 &&
|
|
216
|
+
!seen.has(t.uid)
|
|
217
|
+
) {
|
|
218
|
+
const b = child(entries.get(t.uid) ?? a, "body")?.children[0];
|
|
219
|
+
if (b) {
|
|
220
|
+
seen.add(t.uid);
|
|
221
|
+
return flatten(b, seen);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return [a];
|
|
225
|
+
};
|
|
226
|
+
const body = child(n, "body")?.children[0];
|
|
227
|
+
if (!body) continue;
|
|
228
|
+
const conjuncts = flatten(body);
|
|
229
|
+
const state = conjuncts.filter((a) => Number(value(a, "level")) === 1);
|
|
230
|
+
const boxes = conjuncts.filter((a) => opName(a) === "[]");
|
|
231
|
+
const box = boxes[0] && operands(boxes[0])[0];
|
|
232
|
+
const next =
|
|
233
|
+
box && opName(box) === "$SquareAct" ? operands(box)[0] : undefined;
|
|
234
|
+
if (
|
|
235
|
+
state.length === 1 &&
|
|
236
|
+
boxes.length === 1 &&
|
|
237
|
+
next &&
|
|
238
|
+
operands(next).length === 0
|
|
239
|
+
) {
|
|
240
|
+
const init =
|
|
241
|
+
state[0] && operands(state[0]).length === 0
|
|
242
|
+
? opName(state[0])
|
|
243
|
+
: undefined;
|
|
244
|
+
if (init !== undefined && init !== "")
|
|
245
|
+
specifications.set(name, { init, next: opName(next) });
|
|
246
|
+
}
|
|
247
|
+
}
|
|
141
248
|
return {
|
|
249
|
+
operators,
|
|
250
|
+
fairness,
|
|
251
|
+
specifications,
|
|
142
252
|
variables: [...new Set(variables.values())],
|
|
143
253
|
typeOK: typeOK && new Set(body ? typed(body, new Set()) : []),
|
|
144
254
|
};
|
package/src/formal/specs.ts
CHANGED
|
@@ -18,15 +18,23 @@ const RepoPath = Schema.String.check(
|
|
|
18
18
|
const OperatorName = Schema.String.check(
|
|
19
19
|
Schema.isPattern(/^[A-Za-z_][A-Za-z0-9_]*$/u)
|
|
20
20
|
);
|
|
21
|
-
const
|
|
21
|
+
const Common = {
|
|
22
22
|
synced: Schema.String.check(Schema.isPattern(/^[0-9a-f]{40}$/u)),
|
|
23
23
|
covers: Schema.NonEmptyArray(Schema.NonEmptyString),
|
|
24
|
-
|
|
24
|
+
};
|
|
25
|
+
const Runtime = {
|
|
26
|
+
...Common,
|
|
25
27
|
timeoutSeconds: Schema.Int.check(
|
|
26
28
|
Schema.isBetween({ minimum: 1, maximum: 1800 })
|
|
27
29
|
).pipe(Schema.withDecodingDefaultKey(Effect.succeed(60))),
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
};
|
|
31
|
+
const Proof = {
|
|
32
|
+
...Runtime,
|
|
33
|
+
witnesses: Schema.NonEmptyArray(OperatorName).check(
|
|
34
|
+
Schema.makeFilter(
|
|
35
|
+
(names) =>
|
|
36
|
+
new Set(names).size === names.length || "witnesses must be unique"
|
|
37
|
+
)
|
|
30
38
|
),
|
|
31
39
|
breaks: Schema.Array(
|
|
32
40
|
Schema.Struct({
|
|
@@ -36,28 +44,44 @@ const Entry = Schema.Struct({
|
|
|
36
44
|
file: Schema.optionalKey(RepoPath),
|
|
37
45
|
})
|
|
38
46
|
).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
47
|
+
};
|
|
48
|
+
const Entry = Schema.Union([
|
|
49
|
+
Schema.Struct({
|
|
50
|
+
...Proof,
|
|
51
|
+
mode: Schema.Literal("gate"),
|
|
52
|
+
traces: Schema.optionalKey(
|
|
53
|
+
Schema.Struct({
|
|
54
|
+
seed: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
55
|
+
depth: Schema.Int.check(
|
|
56
|
+
Schema.isBetween({ minimum: 1, maximum: 10000 })
|
|
57
|
+
),
|
|
58
|
+
count: Schema.Int.check(
|
|
59
|
+
Schema.isBetween({ minimum: 1, maximum: 100000 })
|
|
60
|
+
),
|
|
61
|
+
steer: Schema.optionalKey(
|
|
62
|
+
Schema.Record(
|
|
63
|
+
OperatorName,
|
|
64
|
+
Schema.Int.check(Schema.isBetween({ minimum: 2, maximum: 1000 }))
|
|
65
|
+
)
|
|
66
|
+
),
|
|
67
|
+
conformance: RepoPath,
|
|
68
|
+
})
|
|
69
|
+
),
|
|
70
|
+
}),
|
|
71
|
+
Schema.Struct({ ...Proof, mode: Schema.Literal("manual") }),
|
|
72
|
+
Schema.Struct({ ...Common, mode: Schema.Literal("library") }),
|
|
73
|
+
]);
|
|
74
|
+
const SpecsFile = Schema.Struct({
|
|
75
|
+
critical: Schema.NonEmptyArray(Schema.NonEmptyString),
|
|
76
|
+
specs: Schema.Record(RepoPath.check(Schema.isPattern(/\.tla$/u)), Entry),
|
|
77
|
+
kani: Schema.Record(
|
|
78
|
+
RepoPath.check(Schema.isPattern(/\.rs$/u)),
|
|
79
|
+
Schema.Struct({ ...Runtime, mode: Schema.Literals(["gate", "manual"]) })
|
|
80
|
+
).pipe(Schema.withDecodingDefaultKey(Effect.succeed({}))),
|
|
81
|
+
});
|
|
82
|
+
type SpecsFile = Omit<typeof SpecsFile.Type, "critical"> & {
|
|
83
|
+
readonly critical: ReadonlyArray<string>;
|
|
84
|
+
};
|
|
61
85
|
export type Analysis =
|
|
62
86
|
| { readonly _tag: "Parsed"; readonly semantics: Semantics }
|
|
63
87
|
| { readonly _tag: "Unparsed"; readonly output: string };
|
|
@@ -76,6 +100,7 @@ export type Repo = {
|
|
|
76
100
|
readonly tracked: ReadonlyArray<string>;
|
|
77
101
|
readonly file: SpecsFile;
|
|
78
102
|
readonly specs: ReadonlyArray<Spec>;
|
|
103
|
+
readonly models: ReadonlyArray<Model>;
|
|
79
104
|
readonly orphans: ReadonlyArray<string>;
|
|
80
105
|
readonly decodeErrors: ReadonlyArray<string>;
|
|
81
106
|
};
|
|
@@ -98,7 +123,7 @@ export const load = Effect.fn("formal.load")(function* (root: string) {
|
|
|
98
123
|
files.split("\0").filter(Boolean),
|
|
99
124
|
(file) => fs.exists(path.join(root, file))
|
|
100
125
|
);
|
|
101
|
-
let file: SpecsFile = {};
|
|
126
|
+
let file: SpecsFile = { critical: [], specs: {}, kani: {} };
|
|
102
127
|
let decodeErrors: ReadonlyArray<string> = [];
|
|
103
128
|
if (yield* fs.exists(path.join(root, "specs.json"))) {
|
|
104
129
|
const raw = yield* fs.readFileString(path.join(root, "specs.json"));
|
|
@@ -128,12 +153,7 @@ export const load = Effect.fn("formal.load")(function* (root: string) {
|
|
|
128
153
|
(module) =>
|
|
129
154
|
Effect.gen(function* () {
|
|
130
155
|
const stem = module.slice(0, -4);
|
|
131
|
-
const matches = configs.filter(
|
|
132
|
-
(c) =>
|
|
133
|
-
c === `${stem}.cfg` ||
|
|
134
|
-
(c.startsWith(`${stem}.`) &&
|
|
135
|
-
path.dirname(c) === path.dirname(module))
|
|
136
|
-
);
|
|
156
|
+
const matches = configs.filter((c) => c === `${stem}.cfg`);
|
|
137
157
|
const parsed = yield* Effect.forEach(
|
|
138
158
|
matches,
|
|
139
159
|
(c) =>
|
|
@@ -148,7 +168,7 @@ export const load = Effect.fn("formal.load")(function* (root: string) {
|
|
|
148
168
|
);
|
|
149
169
|
return {
|
|
150
170
|
path: module,
|
|
151
|
-
entry: file[module],
|
|
171
|
+
entry: file.specs[module],
|
|
152
172
|
analysis: yield* tla.analyze(path.join(root, module)),
|
|
153
173
|
configs: parsed,
|
|
154
174
|
};
|
|
@@ -160,7 +180,33 @@ export const load = Effect.fn("formal.load")(function* (root: string) {
|
|
|
160
180
|
tracked,
|
|
161
181
|
file,
|
|
162
182
|
specs,
|
|
183
|
+
models: specs.flatMap((s) => {
|
|
184
|
+
const c = s.configs[0];
|
|
185
|
+
return s.analysis._tag === "Parsed" &&
|
|
186
|
+
s.entry &&
|
|
187
|
+
s.entry.mode !== "library" &&
|
|
188
|
+
c &&
|
|
189
|
+
!("_tag" in c.cfg)
|
|
190
|
+
? [
|
|
191
|
+
{
|
|
192
|
+
root,
|
|
193
|
+
path: s.path,
|
|
194
|
+
entry: s.entry,
|
|
195
|
+
semantics: s.analysis.semantics,
|
|
196
|
+
config: { path: c.path, cfg: c.cfg },
|
|
197
|
+
},
|
|
198
|
+
]
|
|
199
|
+
: [];
|
|
200
|
+
}),
|
|
163
201
|
orphans: configs.filter((c) => !paired.has(c)),
|
|
164
202
|
decodeErrors,
|
|
165
203
|
} satisfies Repo;
|
|
166
204
|
});
|
|
205
|
+
|
|
206
|
+
export type Model = {
|
|
207
|
+
readonly root: string;
|
|
208
|
+
readonly path: string;
|
|
209
|
+
readonly entry: Exclude<typeof Entry.Type, { readonly mode: "library" }>;
|
|
210
|
+
readonly semantics: Semantics;
|
|
211
|
+
readonly config: { readonly path: string; readonly cfg: Cfg };
|
|
212
|
+
};
|
package/src/formal/tla.ts
CHANGED
|
@@ -19,7 +19,7 @@ import type { Analysis } from "./specs.ts";
|
|
|
19
19
|
export class FormalError extends Data.TaggedError("FormalError")<{
|
|
20
20
|
readonly message: string;
|
|
21
21
|
}> {}
|
|
22
|
-
type ToolMessage = {
|
|
22
|
+
export type ToolMessage = {
|
|
23
23
|
readonly code: number;
|
|
24
24
|
readonly severity: number;
|
|
25
25
|
readonly text: string;
|
|
@@ -33,6 +33,14 @@ type TlcRun =
|
|
|
33
33
|
}
|
|
34
34
|
| { readonly _tag: "TimedOut" };
|
|
35
35
|
type TlcInput = {
|
|
36
|
+
readonly mode:
|
|
37
|
+
| { readonly _tag: "Check"; readonly coverage: boolean }
|
|
38
|
+
| {
|
|
39
|
+
readonly _tag: "Simulate";
|
|
40
|
+
readonly num: number;
|
|
41
|
+
readonly depth: number;
|
|
42
|
+
readonly seed: number;
|
|
43
|
+
};
|
|
36
44
|
readonly spec: string;
|
|
37
45
|
readonly config: string;
|
|
38
46
|
readonly timeoutSeconds: number;
|
|
@@ -252,7 +260,21 @@ const make = Effect.gen(function* () {
|
|
|
252
260
|
"tlc2.TLC",
|
|
253
261
|
"-tool",
|
|
254
262
|
"-workers",
|
|
255
|
-
"auto",
|
|
263
|
+
input.mode._tag === "Simulate" ? "1" : "auto",
|
|
264
|
+
...(input.mode._tag === "Simulate"
|
|
265
|
+
? [
|
|
266
|
+
"-simulate",
|
|
267
|
+
`num=${input.mode.num}`,
|
|
268
|
+
"-depth",
|
|
269
|
+
String(input.mode.depth),
|
|
270
|
+
"-seed",
|
|
271
|
+
String(input.mode.seed),
|
|
272
|
+
]
|
|
273
|
+
: [
|
|
274
|
+
"-lncheck",
|
|
275
|
+
"final",
|
|
276
|
+
...(input.mode.coverage ? ["-coverage", "60"] : []),
|
|
277
|
+
]),
|
|
256
278
|
"-metadir",
|
|
257
279
|
temp,
|
|
258
280
|
"-noGenerateSpecTE",
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
export const FORMAL_TRACES = "FORMAL_TRACES";
|
|
3
|
+
const ObjectValue = Schema.Record(Schema.String, Schema.Json);
|
|
4
|
+
export const Trace = Schema.Struct({
|
|
5
|
+
index: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
6
|
+
constants: ObjectValue,
|
|
7
|
+
steps: Schema.NonEmptyArray(
|
|
8
|
+
Schema.Struct({
|
|
9
|
+
action: Schema.NonEmptyString,
|
|
10
|
+
args: ObjectValue,
|
|
11
|
+
state: ObjectValue,
|
|
12
|
+
})
|
|
13
|
+
),
|
|
14
|
+
});
|
|
15
|
+
export type Trace = typeof Trace.Type;
|
|
16
|
+
export const receiptPath = (file: string) => `${file}.replayed`;
|
|
17
|
+
export const readTraces = (text: string): ReadonlyArray<Trace> =>
|
|
18
|
+
text
|
|
19
|
+
.trimEnd()
|
|
20
|
+
.split("\n")
|
|
21
|
+
.map((line) =>
|
|
22
|
+
Schema.decodeSync(Schema.fromJsonString(Trace))(line, {
|
|
23
|
+
onExcessProperty: "error",
|
|
24
|
+
})
|
|
25
|
+
);
|
|
26
|
+
export const sorted = (value: Schema.Json): Schema.Json =>
|
|
27
|
+
Array.isArray(value)
|
|
28
|
+
? value.map(sorted)
|
|
29
|
+
: value !== null && typeof value === "object"
|
|
30
|
+
? Object.fromEntries(
|
|
31
|
+
Object.entries(value)
|
|
32
|
+
.toSorted(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
|
33
|
+
.map(([key, v]) => [key, sorted(v)])
|
|
34
|
+
)
|
|
35
|
+
: value;
|