@milkenjoyer/toolchain 0.10.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 +117 -0
- 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 +188 -0
- package/dist/formal.mjs +1279 -0
- package/dist/guard.mjs +2 -2
- package/dist/hooks.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 +6 -6
- package/dist/trace-file-KuPRWgwt.mjs +17 -0
- package/dist/verdict.d.mts +1 -1
- package/dist/verdict.mjs +2 -2
- package/dist/{verification-MNG9WKEH.d.mts → verification-FgQFU1YN.d.mts} +2 -2
- package/dist/verification.d.mts +1 -1
- package/dist/verification.mjs +1 -1
- package/package.json +9 -2
- package/src/formal/cfg.ts +168 -0
- package/src/formal/checks.ts +190 -0
- 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 +255 -0
- package/src/formal/specs.ts +212 -0
- package/src/formal/tla.ts +306 -0
- 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 +82 -0
- 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-2bhNnJr-.mjs → verification-oAc1Q6I9.mjs} +4 -4
package/dist/guard.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { d as otherTags, l as latestOf, u as onLatestLine } from "./compatible-D8n_sQHa.mjs";
|
|
2
2
|
import { i as enforcedTsgoRules } from "./effect-tsgo-D0QfeKGD.mjs";
|
|
3
|
-
import { t as exceptions } from "./exceptions-
|
|
4
|
-
import { a as toolchainScopes, n as effectRules, r as foldkitPreset, t as birbprophetRules } from "./lint-
|
|
3
|
+
import { t as exceptions } from "./exceptions-Dybl9xpc.mjs";
|
|
4
|
+
import { a as toolchainScopes, n as effectRules, r as foldkitPreset, t as birbprophetRules } from "./lint-IhmtnBbx.mjs";
|
|
5
5
|
import { c as lead, f as versionOf } from "./versions-C7LKZGr3.mjs";
|
|
6
6
|
import * as Arr from "effect/Array";
|
|
7
7
|
import { dual } from "effect/Function";
|
package/dist/hooks.mjs
CHANGED
|
@@ -2,10 +2,10 @@ import * as Arr from "effect/Array";
|
|
|
2
2
|
import * as Schema from "effect/Schema";
|
|
3
3
|
import * as Str from "effect/String";
|
|
4
4
|
import * as Effect from "effect/Effect";
|
|
5
|
-
import { FileSystem } from "effect/FileSystem";
|
|
6
|
-
import { Path } from "effect/Path";
|
|
7
5
|
import { ChildProcess } from "effect/process";
|
|
8
6
|
import * as Stream from "effect/Stream";
|
|
7
|
+
import { FileSystem } from "effect/FileSystem";
|
|
8
|
+
import { Path } from "effect/Path";
|
|
9
9
|
// src/hooks.ts
|
|
10
10
|
const worktreePrePush = `#!/bin/sh
|
|
11
11
|
if ! root=$(git rev-parse --show-toplevel); then
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as plugin } from "./effect-plugin-
|
|
1
|
+
import { t as plugin } from "./effect-plugin-BXUx9PPu.mjs";
|
|
2
2
|
import { n as effectTsgoPlugin, r as effectTsgoRules } from "./effect-tsgo-D0QfeKGD.mjs";
|
|
3
|
-
import { t as exceptions } from "./exceptions-
|
|
4
|
-
import { t as plugin$1 } from "./plugin-
|
|
3
|
+
import { t as exceptions } from "./exceptions-Dybl9xpc.mjs";
|
|
4
|
+
import { t as plugin$1 } from "./plugin-CwxhPtui.mjs";
|
|
5
5
|
import { t as staticRules } from "./rules-vHmNoAU0.mjs";
|
|
6
6
|
import * as Arr from "effect/Array";
|
|
7
7
|
import * as Option from "effect/Option";
|
package/dist/lint.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as birbprophetRules, n as effectRules, r as foldkitPreset, i as lint, a as toolchainScopes } from "./lint-
|
|
1
|
+
export { t as birbprophetRules, n as effectRules, r as foldkitPreset, i as lint, a as toolchainScopes } from "./lint-IhmtnBbx.mjs";
|
package/dist/plugin.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as default } from "./plugin-
|
|
1
|
+
export { t as default } from "./plugin-CwxhPtui.mjs";
|
package/dist/proof.mjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
import * as Data from "effect/Data";
|
|
3
3
|
import * as Schema from "effect/Schema";
|
|
4
|
+
import * as Config from "effect/Config";
|
|
4
5
|
import * as Effect from "effect/Effect";
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
6
|
+
import { NodeServices } from "@effect/platform-node";
|
|
7
|
+
import * as Cause from "effect/Cause";
|
|
8
|
+
import * as Exit from "effect/Exit";
|
|
7
9
|
import { ChildProcess } from "effect/process";
|
|
8
10
|
import * as Stream from "effect/Stream";
|
|
9
|
-
import {
|
|
11
|
+
import { FileSystem } from "effect/FileSystem";
|
|
12
|
+
import { Path } from "effect/Path";
|
|
10
13
|
import { Octokit } from "@octokit/rest";
|
|
11
|
-
import * as Cause from "effect/Cause";
|
|
12
|
-
import * as Config from "effect/Config";
|
|
13
14
|
import { Base64 } from "effect/encoding";
|
|
14
|
-
import * as Exit from "effect/Exit";
|
|
15
15
|
import * as Redacted from "effect/Redacted";
|
|
16
16
|
// src/proof.ts
|
|
17
17
|
var ProofError = class extends Data.TaggedError("ProofError") {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
// src/formal/trace-file.ts
|
|
3
|
+
const FORMAL_TRACES = "FORMAL_TRACES";
|
|
4
|
+
const ObjectValue = Schema.Record(Schema.String, Schema.Json);
|
|
5
|
+
const Trace = Schema.Struct({
|
|
6
|
+
index: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
7
|
+
constants: ObjectValue,
|
|
8
|
+
steps: Schema.NonEmptyArray(Schema.Struct({
|
|
9
|
+
action: Schema.NonEmptyString,
|
|
10
|
+
args: ObjectValue,
|
|
11
|
+
state: ObjectValue
|
|
12
|
+
}))
|
|
13
|
+
});
|
|
14
|
+
const receiptPath = (file) => `${file}.replayed`;
|
|
15
|
+
const readTraces = (text) => text.trimEnd().split("\n").map((line) => Schema.decodeSync(Schema.fromJsonString(Trace))(line, { onExcessProperty: "error" }));
|
|
16
|
+
const sorted = (value) => Array.isArray(value) ? value.map(sorted) : value !== null && typeof value === "object" ? Object.fromEntries(Object.entries(value).toSorted(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, v]) => [key, sorted(v)])) : value;
|
|
17
|
+
export { sorted as i, readTraces as n, receiptPath as r, FORMAL_TRACES as t };
|
package/dist/verdict.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { i as VerificationError } from "./verification-
|
|
1
|
+
import { i as VerificationError } from "./verification-FgQFU1YN.mjs";
|
|
2
2
|
import * as Effect from "effect/Effect";
|
|
3
3
|
export declare const checkVerdict: Effect.Effect<number, import("effect/Config").ConfigError | import("effect/PlatformError").PlatformError | import("effect/Schema").SchemaError | VerificationError, import("effect/FileSystem").FileSystem>;
|
package/dist/verdict.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import { a as readPullRequest, i as github, n as autoPass } from "./verification-
|
|
2
|
+
import { a as readPullRequest, i as github, n as autoPass } from "./verification-oAc1Q6I9.mjs";
|
|
3
3
|
import * as Effect from "effect/Effect";
|
|
4
4
|
import { NodeServices } from "@effect/platform-node";
|
|
5
5
|
import * as Cause from "effect/Cause";
|
|
6
|
-
import * as Exit from "effect/Exit";
|
|
7
6
|
import * as Console from "effect/Console";
|
|
7
|
+
import * as Exit from "effect/Exit";
|
|
8
8
|
// src/verdict.ts
|
|
9
9
|
const checkVerdict = Effect.gen(function* () {
|
|
10
10
|
const request = yield* readPullRequest;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as Schema from "effect/Schema";
|
|
2
|
+
import * as Config from "effect/Config";
|
|
2
3
|
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Cause from "effect/Cause";
|
|
3
5
|
import { FileSystem } from "effect/FileSystem";
|
|
4
6
|
import { Octokit } from "@octokit/rest";
|
|
5
|
-
import * as Cause from "effect/Cause";
|
|
6
|
-
import * as Config from "effect/Config";
|
|
7
7
|
type PullRequest = {
|
|
8
8
|
readonly author: string;
|
|
9
9
|
readonly body: string | null;
|
package/dist/verification.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as autoPass, c as readPullRequest, i as VerificationError, l as verdict, n as PullRequestContext, o as checkVerification, r as Verdict, s as github, t as PullRequest } from "./verification-
|
|
1
|
+
import { a as autoPass, c as readPullRequest, i as VerificationError, l as verdict, n as PullRequestContext, o as checkVerification, r as Verdict, s as github, t as PullRequest } from "./verification-FgQFU1YN.mjs";
|
|
2
2
|
export { PullRequest, PullRequestContext, Verdict, VerificationError, autoPass, checkVerification, github, readPullRequest, verdict };
|
package/dist/verification.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
export { t as VerificationError, n as autoPass, r as checkVerification, i as github, a as readPullRequest, o as verdict } from "./verification-
|
|
2
|
+
export { t as VerificationError, n as autoPass, r as checkVerification, i as github, a as readPullRequest, o as verdict } from "./verification-oAc1Q6I9.mjs";
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milkenjoyer/toolchain",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/birbprophet/agent-kit.git",
|
|
7
7
|
"directory": "packages/toolchain"
|
|
8
8
|
},
|
|
9
9
|
"bin": {
|
|
10
|
+
"formal": "./src/formal.ts",
|
|
10
11
|
"proof": "./src/proof.ts",
|
|
11
12
|
"verdict": "./src/verdict.ts",
|
|
12
13
|
"verification": "./src/verification.ts"
|
|
@@ -16,6 +17,8 @@
|
|
|
16
17
|
"licenses",
|
|
17
18
|
"node-version",
|
|
18
19
|
"renovate.json",
|
|
20
|
+
"src/formal.ts",
|
|
21
|
+
"src/formal/",
|
|
19
22
|
"src/proof.ts",
|
|
20
23
|
"src/verdict.ts",
|
|
21
24
|
"src/verification.ts",
|
|
@@ -85,7 +88,11 @@
|
|
|
85
88
|
"./renovate.json": "./renovate.json",
|
|
86
89
|
"./tsconfig.base.json": "./tsconfig.base.json",
|
|
87
90
|
"./vscode/settings.json": "./vscode/settings.json",
|
|
88
|
-
"./vscode/extensions.json": "./vscode/extensions.json"
|
|
91
|
+
"./vscode/extensions.json": "./vscode/extensions.json",
|
|
92
|
+
"./conformance": {
|
|
93
|
+
"types": "./dist/conformance.d.mts",
|
|
94
|
+
"default": "./dist/conformance.mjs"
|
|
95
|
+
}
|
|
89
96
|
},
|
|
90
97
|
"publishConfig": {
|
|
91
98
|
"access": "public"
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
export type CfgConstant =
|
|
2
|
+
| { readonly _tag: "Value"; readonly name: string; readonly value: string }
|
|
3
|
+
| {
|
|
4
|
+
readonly _tag: "Substitution";
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly by: string;
|
|
7
|
+
};
|
|
8
|
+
export type Cfg = {
|
|
9
|
+
readonly constants: ReadonlyArray<CfgConstant>;
|
|
10
|
+
readonly sections: ReadonlyArray<{
|
|
11
|
+
readonly keyword: string;
|
|
12
|
+
readonly text: string;
|
|
13
|
+
}>;
|
|
14
|
+
readonly properties: ReadonlyArray<string>;
|
|
15
|
+
readonly invariants: ReadonlyArray<string>;
|
|
16
|
+
readonly checkDeadlock: ReadonlyArray<boolean>;
|
|
17
|
+
};
|
|
18
|
+
export type CfgError = { readonly _tag: "CfgError"; readonly message: string };
|
|
19
|
+
|
|
20
|
+
const keywords = new Set([
|
|
21
|
+
"CONSTANT",
|
|
22
|
+
"CONSTANTS",
|
|
23
|
+
"INIT",
|
|
24
|
+
"NEXT",
|
|
25
|
+
"SPECIFICATION",
|
|
26
|
+
"INVARIANT",
|
|
27
|
+
"INVARIANTS",
|
|
28
|
+
"PROPERTY",
|
|
29
|
+
"PROPERTIES",
|
|
30
|
+
"CONSTRAINT",
|
|
31
|
+
"CONSTRAINTS",
|
|
32
|
+
"ACTION_CONSTRAINT",
|
|
33
|
+
"ACTION_CONSTRAINTS",
|
|
34
|
+
"SYMMETRY",
|
|
35
|
+
"VIEW",
|
|
36
|
+
"ALIAS",
|
|
37
|
+
"POSTCONDITION",
|
|
38
|
+
"CHECK_DEADLOCK",
|
|
39
|
+
]);
|
|
40
|
+
export const parseCfg = (source: string): Cfg | CfgError => {
|
|
41
|
+
const text = source.replaceAll(/\(\*[\s\S]*?\*\)|\\\*[^\n]*/gu, " ");
|
|
42
|
+
const tokens =
|
|
43
|
+
text.match(/"(?:\\.|[^"\\])*"|<-|[A-Za-z_][A-Za-z0-9_!]*|-?\d+|[^\s]/gu) ??
|
|
44
|
+
[];
|
|
45
|
+
const sections: { keyword: string; text: string }[] = [];
|
|
46
|
+
const properties: string[] = [];
|
|
47
|
+
const constants: CfgConstant[] = [];
|
|
48
|
+
const invariants: string[] = [];
|
|
49
|
+
const checkDeadlock: boolean[] = [];
|
|
50
|
+
const fail = (message: string): CfgError => ({ _tag: "CfgError", message });
|
|
51
|
+
let i = 0;
|
|
52
|
+
while (i < tokens.length) {
|
|
53
|
+
const keyword = tokens[i++];
|
|
54
|
+
if (keyword === undefined || !keywords.has(keyword))
|
|
55
|
+
return fail(`unknown config keyword ${keyword}`);
|
|
56
|
+
const operands: string[] = [];
|
|
57
|
+
while (i < tokens.length && !keywords.has(tokens[i] ?? ""))
|
|
58
|
+
operands.push(tokens[i++] ?? "");
|
|
59
|
+
sections.push({ keyword, text: operands.join(" ") });
|
|
60
|
+
if (operands.length === 0) return fail(`missing operand for ${keyword}`);
|
|
61
|
+
if (keyword === "CONSTANT" || keyword === "CONSTANTS") {
|
|
62
|
+
let j = 0;
|
|
63
|
+
while (j < operands.length) {
|
|
64
|
+
const name = operands[j++];
|
|
65
|
+
const assignment = operands[j++];
|
|
66
|
+
if (
|
|
67
|
+
name === undefined ||
|
|
68
|
+
!/^[A-Za-z_][A-Za-z0-9_!]*$/u.test(name) ||
|
|
69
|
+
(assignment !== "=" && assignment !== "<-")
|
|
70
|
+
)
|
|
71
|
+
return fail(`unparseable constant ${name}`);
|
|
72
|
+
const value: string[] = [];
|
|
73
|
+
let depth = 0;
|
|
74
|
+
while (j < operands.length) {
|
|
75
|
+
const token = operands[j] ?? "";
|
|
76
|
+
if (
|
|
77
|
+
depth === 0 &&
|
|
78
|
+
value.length > 0 &&
|
|
79
|
+
["=", "<-"].includes(operands[j + 1] ?? "")
|
|
80
|
+
)
|
|
81
|
+
break;
|
|
82
|
+
if (token === "{") depth++;
|
|
83
|
+
if (token === "}") depth--;
|
|
84
|
+
value.push(token);
|
|
85
|
+
j++;
|
|
86
|
+
}
|
|
87
|
+
const raw = value.join(" ");
|
|
88
|
+
if (
|
|
89
|
+
depth !== 0 ||
|
|
90
|
+
!/^(?:-?\d+|[A-Za-z_][A-Za-z0-9_!]*|"(?:\\.|[^"\\])*"|\{[\s\S]*\})$/u.test(
|
|
91
|
+
raw
|
|
92
|
+
)
|
|
93
|
+
)
|
|
94
|
+
return fail(`unparseable constant ${name} ${assignment} ${raw}`);
|
|
95
|
+
constants.push(
|
|
96
|
+
assignment === "="
|
|
97
|
+
? { _tag: "Value", name, value: raw }
|
|
98
|
+
: { _tag: "Substitution", name, by: raw }
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
} else if (keyword === "CHECK_DEADLOCK") {
|
|
102
|
+
if (
|
|
103
|
+
operands.length !== 1 ||
|
|
104
|
+
!["TRUE", "FALSE"].includes(operands[0] ?? "")
|
|
105
|
+
)
|
|
106
|
+
return fail("CHECK_DEADLOCK needs TRUE or FALSE");
|
|
107
|
+
checkDeadlock.push(operands[0] === "TRUE");
|
|
108
|
+
} else {
|
|
109
|
+
if (!operands.every((token) => /^[A-Za-z_][A-Za-z0-9_!]*$/u.test(token)))
|
|
110
|
+
return fail(`invalid operands for ${keyword}`);
|
|
111
|
+
if (keyword.startsWith("PROPERT")) properties.push(...operands);
|
|
112
|
+
if (keyword.startsWith("INVARIANT")) invariants.push(...operands);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return { sections, constants, invariants, properties, checkDeadlock };
|
|
116
|
+
};
|
|
117
|
+
export const integer = (constant: CfgConstant): bigint | undefined =>
|
|
118
|
+
constant._tag === "Value" && /^-?\d+$/u.test(constant.value)
|
|
119
|
+
? BigInt(constant.value)
|
|
120
|
+
: undefined;
|
|
121
|
+
|
|
122
|
+
export type Plan = {
|
|
123
|
+
readonly target?: { readonly name: string; readonly level: number };
|
|
124
|
+
readonly simulation?: {
|
|
125
|
+
readonly init: string;
|
|
126
|
+
readonly next: string;
|
|
127
|
+
readonly overrides: ReadonlyArray<string>;
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
export const derive = (cfg: Cfg, plan: Plan): string => {
|
|
131
|
+
const removed = new Set([
|
|
132
|
+
"INVARIANT",
|
|
133
|
+
"INVARIANTS",
|
|
134
|
+
"PROPERTY",
|
|
135
|
+
"PROPERTIES",
|
|
136
|
+
]);
|
|
137
|
+
if (plan.simulation)
|
|
138
|
+
for (const k of [
|
|
139
|
+
"INIT",
|
|
140
|
+
"NEXT",
|
|
141
|
+
"SPECIFICATION",
|
|
142
|
+
"SYMMETRY",
|
|
143
|
+
"VIEW",
|
|
144
|
+
"ALIAS",
|
|
145
|
+
"POSTCONDITION",
|
|
146
|
+
"CHECK_DEADLOCK",
|
|
147
|
+
])
|
|
148
|
+
removed.add(k);
|
|
149
|
+
const lines = cfg.sections
|
|
150
|
+
.filter((s) => !removed.has(s.keyword))
|
|
151
|
+
.map((s) => s.keyword + " " + s.text);
|
|
152
|
+
if (plan.target)
|
|
153
|
+
lines.push(
|
|
154
|
+
(plan.target.level < 2 ? "INVARIANT " : "PROPERTY ") + plan.target.name
|
|
155
|
+
);
|
|
156
|
+
if (plan.simulation) {
|
|
157
|
+
const s = plan.simulation;
|
|
158
|
+
lines.push(
|
|
159
|
+
"CONSTANTS",
|
|
160
|
+
...s.overrides,
|
|
161
|
+
"INIT " + s.init,
|
|
162
|
+
"NEXT " + s.next,
|
|
163
|
+
"INVARIANT Formal_Export",
|
|
164
|
+
"CHECK_DEADLOCK FALSE"
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
return lines.join("\n") + "\n";
|
|
168
|
+
};
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import * as Console from "effect/Console";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import { FileSystem } from "effect/FileSystem";
|
|
4
|
+
import { ChildProcessSpawner } from "effect/process";
|
|
5
|
+
|
|
6
|
+
import { integer } from "./cfg.ts";
|
|
7
|
+
import { Gate } from "./gate.ts";
|
|
8
|
+
import {
|
|
9
|
+
critical,
|
|
10
|
+
fairness,
|
|
11
|
+
coverageCheck,
|
|
12
|
+
witnesses,
|
|
13
|
+
breaks,
|
|
14
|
+
} from "./proofs.ts";
|
|
15
|
+
import type { Repo } from "./specs.ts";
|
|
16
|
+
import { FormalError, Tla } from "./tla.ts";
|
|
17
|
+
import { traces } from "./traces.ts";
|
|
18
|
+
|
|
19
|
+
type Problem = { readonly file: string; readonly message: string };
|
|
20
|
+
export type Check = (
|
|
21
|
+
repo: Repo
|
|
22
|
+
) => Effect.Effect<
|
|
23
|
+
ReadonlyArray<Problem>,
|
|
24
|
+
FormalError,
|
|
25
|
+
Tla | Gate | FileSystem | ChildProcessSpawner.ChildProcessSpawner
|
|
26
|
+
>;
|
|
27
|
+
export type Finding = Problem & { readonly check: keyof typeof checks };
|
|
28
|
+
|
|
29
|
+
const configs = (repo: Repo) =>
|
|
30
|
+
repo.specs
|
|
31
|
+
.filter((s) => s.analysis._tag === "Parsed")
|
|
32
|
+
.flatMap((s) => s.configs)
|
|
33
|
+
.flatMap((c) => ("_tag" in c.cfg ? [] : [{ path: c.path, cfg: c.cfg }]));
|
|
34
|
+
const specs: Check = (repo) =>
|
|
35
|
+
Effect.succeed([
|
|
36
|
+
...repo.decodeErrors.map((message) => ({ file: "specs.json", message })),
|
|
37
|
+
...repo.specs.flatMap((s) => [
|
|
38
|
+
...(!s.entry && repo.decodeErrors.length === 0
|
|
39
|
+
? [{ file: s.path, message: "tracked spec has no specs.json entry" }]
|
|
40
|
+
: []),
|
|
41
|
+
...(s.entry &&
|
|
42
|
+
s.entry.mode !== "library" &&
|
|
43
|
+
!s.configs.some((c) => c.path === s.path.replace(/\.tla$/u, ".cfg"))
|
|
44
|
+
? [{ file: s.path, message: "runnable spec has no matching .cfg" }]
|
|
45
|
+
: []),
|
|
46
|
+
...(s.entry?.mode === "library" && s.configs.length
|
|
47
|
+
? [{ file: s.path, message: "library spec must not have a config" }]
|
|
48
|
+
: []),
|
|
49
|
+
...s.configs.flatMap((c) =>
|
|
50
|
+
"_tag" in c.cfg ? [{ file: c.path, message: c.cfg.message }] : []
|
|
51
|
+
),
|
|
52
|
+
]),
|
|
53
|
+
...Object.keys({ ...repo.file.specs, ...repo.file.kani })
|
|
54
|
+
.filter((f) => !repo.tracked.includes(f))
|
|
55
|
+
.map((file) => ({ file, message: "entry names no tracked file" })),
|
|
56
|
+
...repo.orphans.map((file) => ({
|
|
57
|
+
file,
|
|
58
|
+
message:
|
|
59
|
+
"config pairs with no module; give a variant its own module that EXTENDS X",
|
|
60
|
+
})),
|
|
61
|
+
]);
|
|
62
|
+
const sany: Check = (repo) =>
|
|
63
|
+
Effect.succeed(
|
|
64
|
+
repo.specs.flatMap((s) =>
|
|
65
|
+
s.analysis._tag === "Unparsed"
|
|
66
|
+
? [{ file: s.path, message: s.analysis.output }]
|
|
67
|
+
: []
|
|
68
|
+
)
|
|
69
|
+
);
|
|
70
|
+
const typeok: Check = (repo) =>
|
|
71
|
+
Effect.succeed([
|
|
72
|
+
...configs(repo)
|
|
73
|
+
.filter((c) => !c.cfg.invariants.includes("TypeOK"))
|
|
74
|
+
.map((c) => ({
|
|
75
|
+
file: c.path,
|
|
76
|
+
message: "does not check INVARIANT TypeOK",
|
|
77
|
+
})),
|
|
78
|
+
...repo.specs.flatMap((s) => {
|
|
79
|
+
if (s.analysis._tag !== "Parsed" || s.configs.length === 0) return [];
|
|
80
|
+
const typed = s.analysis.semantics.typeOK;
|
|
81
|
+
if (!typed)
|
|
82
|
+
return s.configs.some(
|
|
83
|
+
(c) => !("_tag" in c.cfg) && c.cfg.invariants.includes("TypeOK")
|
|
84
|
+
)
|
|
85
|
+
? [{ file: s.path, message: "TypeOK is not defined" }]
|
|
86
|
+
: [];
|
|
87
|
+
const missing = s.analysis.semantics.variables.filter(
|
|
88
|
+
(v) => !typed.has(v)
|
|
89
|
+
);
|
|
90
|
+
return missing.length
|
|
91
|
+
? [
|
|
92
|
+
{
|
|
93
|
+
file: s.path,
|
|
94
|
+
message: `TypeOK does not constrain ${missing.join(", ")}; give each a conjunct such as ${missing[0]} \\in S`,
|
|
95
|
+
},
|
|
96
|
+
]
|
|
97
|
+
: [];
|
|
98
|
+
}),
|
|
99
|
+
]);
|
|
100
|
+
const deadlock: Check = (repo) =>
|
|
101
|
+
Effect.succeed(
|
|
102
|
+
configs(repo)
|
|
103
|
+
.filter((c) => c.cfg.checkDeadlock.includes(false))
|
|
104
|
+
.map((c) => ({
|
|
105
|
+
file: c.path,
|
|
106
|
+
message:
|
|
107
|
+
"CHECK_DEADLOCK FALSE; give the bounded spec an explicit finished step",
|
|
108
|
+
}))
|
|
109
|
+
);
|
|
110
|
+
const constants: Check = (repo) =>
|
|
111
|
+
Effect.succeed(
|
|
112
|
+
configs(repo).flatMap((c) => {
|
|
113
|
+
const groups = new Map<bigint, string[]>();
|
|
114
|
+
for (const constant of c.cfg.constants) {
|
|
115
|
+
const n = integer(constant);
|
|
116
|
+
if (n === undefined) continue;
|
|
117
|
+
groups.set(n, [...(groups.get(n) ?? []), constant.name]);
|
|
118
|
+
}
|
|
119
|
+
return [...groups]
|
|
120
|
+
.filter(([, names]) => names.length > 1)
|
|
121
|
+
.map(([n, names]) => ({
|
|
122
|
+
file: c.path,
|
|
123
|
+
message: `${names.length === 2 ? names.join(" and ") : `${names.slice(0, -1).join(", ")} and ${names.at(-1)}`} ${names.length === 2 ? "both" : "all"} equal ${n}`,
|
|
124
|
+
}));
|
|
125
|
+
})
|
|
126
|
+
);
|
|
127
|
+
const format: Check = (repo) =>
|
|
128
|
+
Effect.gen(function* () {
|
|
129
|
+
const tla = yield* Tla;
|
|
130
|
+
const fs = yield* FileSystem;
|
|
131
|
+
return (yield* Effect.forEach(
|
|
132
|
+
repo.specs.filter((s) => s.analysis._tag === "Parsed"),
|
|
133
|
+
(s) =>
|
|
134
|
+
Effect.gen(function* () {
|
|
135
|
+
const result = yield* tla.format(`${repo.root}/${s.path}`);
|
|
136
|
+
if (result._tag === "Failed")
|
|
137
|
+
return [{ file: s.path, message: result.output }];
|
|
138
|
+
const text = yield* fs.readFileString(`${repo.root}/${s.path}`);
|
|
139
|
+
if (text === result.text) return [];
|
|
140
|
+
const lines = text.split("\n");
|
|
141
|
+
const expected = result.text.split("\n");
|
|
142
|
+
let line = 0;
|
|
143
|
+
while (
|
|
144
|
+
line < Math.max(lines.length, expected.length) &&
|
|
145
|
+
lines[line] === expected[line]
|
|
146
|
+
)
|
|
147
|
+
line++;
|
|
148
|
+
return [
|
|
149
|
+
{
|
|
150
|
+
file: s.path,
|
|
151
|
+
message: `differs from formatter.Main at line ${line + 1}; run ${tla.fixCommand(s.path)}`,
|
|
152
|
+
},
|
|
153
|
+
];
|
|
154
|
+
}),
|
|
155
|
+
{ concurrency: 4 }
|
|
156
|
+
)).flat();
|
|
157
|
+
}).pipe(
|
|
158
|
+
Effect.mapError((cause) => new FormalError({ message: String(cause) }))
|
|
159
|
+
);
|
|
160
|
+
const tlc: Check = (repo) =>
|
|
161
|
+
Effect.gen(function* () {
|
|
162
|
+
const gate = yield* Gate;
|
|
163
|
+
const problems: Problem[] = [];
|
|
164
|
+
for (const m of repo.models.filter((m) => m.entry.mode === "gate")) {
|
|
165
|
+
const result = yield* gate.run(m);
|
|
166
|
+
if (result._tag === "Failed")
|
|
167
|
+
problems.push({ file: m.config.path, message: result.message });
|
|
168
|
+
else
|
|
169
|
+
yield* Console.log(
|
|
170
|
+
`tlc: ${m.config.path}: ${result.states} distinct states in ${result.seconds} s`
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
return problems;
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
export const checks = {
|
|
177
|
+
specs,
|
|
178
|
+
critical,
|
|
179
|
+
sany,
|
|
180
|
+
typeok,
|
|
181
|
+
deadlock,
|
|
182
|
+
fairness,
|
|
183
|
+
constants,
|
|
184
|
+
format,
|
|
185
|
+
tlc,
|
|
186
|
+
coverage: coverageCheck,
|
|
187
|
+
witnesses,
|
|
188
|
+
breaks,
|
|
189
|
+
traces,
|
|
190
|
+
} satisfies Record<string, Check>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { ToolMessage } from "./tla.ts";
|
|
2
|
+
|
|
3
|
+
type Span = {
|
|
4
|
+
readonly module: string;
|
|
5
|
+
readonly line: number;
|
|
6
|
+
readonly col: number;
|
|
7
|
+
readonly endLine: number;
|
|
8
|
+
readonly endCol: number;
|
|
9
|
+
};
|
|
10
|
+
export type Coverage = {
|
|
11
|
+
readonly actions: ReadonlyArray<{
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly span: Span;
|
|
14
|
+
readonly generated: bigint;
|
|
15
|
+
}>;
|
|
16
|
+
readonly zeros: ReadonlyArray<{
|
|
17
|
+
readonly scope: string;
|
|
18
|
+
readonly span: Span;
|
|
19
|
+
}>;
|
|
20
|
+
};
|
|
21
|
+
const span = (text: string): Span | undefined => {
|
|
22
|
+
const m =
|
|
23
|
+
/line (\d+), col (\d+) to line (\d+), col (\d+) of module (\w+)/u.exec(
|
|
24
|
+
text
|
|
25
|
+
);
|
|
26
|
+
return m
|
|
27
|
+
? {
|
|
28
|
+
line: Number(m[1]),
|
|
29
|
+
col: Number(m[2]),
|
|
30
|
+
endLine: Number(m[3]),
|
|
31
|
+
endCol: Number(m[4]),
|
|
32
|
+
module: m[5] ?? "",
|
|
33
|
+
}
|
|
34
|
+
: undefined;
|
|
35
|
+
};
|
|
36
|
+
export const coverage = (
|
|
37
|
+
messages: ReadonlyArray<ToolMessage>
|
|
38
|
+
): Coverage | string => {
|
|
39
|
+
const start = messages.findLastIndex((m) => m.code === 2201);
|
|
40
|
+
const end = messages.findIndex(
|
|
41
|
+
(m, i) => i > start && (m.code === 2202 || m.code === 2777)
|
|
42
|
+
);
|
|
43
|
+
if (start < 0 || end < 0) return "missing final coverage report";
|
|
44
|
+
const actions: { name: string; span: Span; generated: bigint }[] = [];
|
|
45
|
+
const zeros: { scope: string; span: Span }[] = [];
|
|
46
|
+
let scope: { name: string; enabled: boolean } | undefined;
|
|
47
|
+
let zeroDepth: number | undefined;
|
|
48
|
+
for (const m of messages.slice(start + 1, end)) {
|
|
49
|
+
if (m.code === 2779) continue;
|
|
50
|
+
if (m.code === 2772 || m.code === 2773) {
|
|
51
|
+
const loc = span(m.text);
|
|
52
|
+
const match = /^<(\w+) .*: ([\d,]+):([\d,]+)$/u.exec(m.text);
|
|
53
|
+
if (!loc || !match) return `unparseable coverage ${m.code}: ${m.text}`;
|
|
54
|
+
const name = match[1] ?? "";
|
|
55
|
+
const generated = BigInt((match[3] ?? "0").replaceAll(",", ""));
|
|
56
|
+
scope = { name, enabled: generated > 0n };
|
|
57
|
+
zeroDepth = undefined;
|
|
58
|
+
if (m.code === 2772) actions.push({ name, span: loc, generated });
|
|
59
|
+
} else if (m.code === 2221 || m.code === 2775) {
|
|
60
|
+
const loc = span(m.text);
|
|
61
|
+
const count = /: ([\d,]+)(?::[\d,]+)?$/u.exec(m.text);
|
|
62
|
+
if (!loc || !count) return `unparseable coverage ${m.code}: ${m.text}`;
|
|
63
|
+
const depth = m.text.indexOf("line");
|
|
64
|
+
if (zeroDepth !== undefined && depth <= zeroDepth) zeroDepth = undefined;
|
|
65
|
+
if (
|
|
66
|
+
scope?.enabled === true &&
|
|
67
|
+
BigInt((count[1] ?? "0").replaceAll(",", "")) === 0n &&
|
|
68
|
+
zeroDepth === undefined
|
|
69
|
+
) {
|
|
70
|
+
zeros.push({ scope: scope.name, span: loc });
|
|
71
|
+
zeroDepth = depth;
|
|
72
|
+
}
|
|
73
|
+
} else if (m.code === 2774 || m.code === 2778) {
|
|
74
|
+
scope = undefined;
|
|
75
|
+
zeroDepth = undefined;
|
|
76
|
+
} else return `unparseable coverage ${m.code}: ${m.text}`;
|
|
77
|
+
}
|
|
78
|
+
return { actions, zeros };
|
|
79
|
+
};
|