tla-ts 0.0.4-dev.8fefa42 → 0.0.4-dev.a11a30a
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 +27 -130
- package/dist/deciders.cjs +1 -1
- package/dist/deciders.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -1
- package/dist/prove-worker.cjs +1 -1
- package/dist/prove-worker.js +1 -1
- package/dist/prove.cjs +506 -25
- package/dist/prove.js +506 -25
- package/dist/run-cli.cjs +35 -28
- package/dist/run-cli.js +35 -28
- package/dist/tlapm.cjs +2 -2
- package/dist/tlapm.js +2 -2
- package/package.json +1 -1
- package/src/obligations/action.ts +56 -99
- package/src/obligations/anon.ts +37 -41
- package/src/obligations/deref.ts +49 -90
- package/src/obligations/expression.ts +63 -49
- package/src/obligations/format.ts +7 -8
- package/src/obligations/generate.ts +60 -155
- package/src/obligations/index.ts +6 -4
- package/src/obligations/levels.ts +20 -32
- package/src/obligations/module.ts +93 -127
- package/src/obligations/pickle.ts +1 -3
- package/src/obligations/pragma.ts +14 -14
- package/src/obligations/printer.ts +17 -21
- package/src/obligations/proof.ts +0 -1
- package/src/obligations/source.ts +72 -73
- package/src/obligations/temporal.ts +29 -27
- package/src/obligations/tuples.ts +37 -53
- package/src/ocaml-marshal.ts +166 -0
- package/src/prove/decide-pool.ts +12 -17
- package/src/prove/deciders.ts +7 -1
- package/src/prove/first-order.ts +78 -0
- package/src/prove/isabelle/encode.ts +96 -127
- package/src/prove/ocaml.ts +1 -1
- package/src/prove/prep/action.ts +39 -51
- package/src/prove/prep/defs.ts +19 -13
- package/src/prove/prep/elab.ts +1 -1
- package/src/prove/prep/level-comparison.ts +15 -38
- package/src/prove/prep/pragma.ts +4 -4
- package/src/prove/prove-worker.ts +4 -11
- package/src/prove/prove.ts +230 -149
- package/src/prove/ptl/encode.ts +5 -6
- package/src/prove/smt/axioms.ts +78 -79
- package/src/prove/smt/data.ts +16 -45
- package/src/prove/smt/encode.ts +18 -23
- package/src/prove/smt/extensionality.ts +14 -12
- package/src/prove/smt/flatten.ts +3 -18
- package/src/prove/smt/format.ts +14 -3
- package/src/prove/smt/instances.ts +4 -5
- package/src/prove/smt/rewrite.ts +36 -48
- package/src/prove/smt/simplify.ts +10 -10
- package/src/prove/tlapm/tlapm.ts +13 -13
- package/src/prove/verdict.ts +5 -0
- package/src/prove/zenon/encode.ts +36 -101
- package/src/run-cli.ts +264 -115
- package/src/tlapm-cache.ts +236 -0
package/src/run-cli.ts
CHANGED
|
@@ -5,9 +5,9 @@ import {
|
|
|
5
5
|
readFileSync,
|
|
6
6
|
readSync,
|
|
7
7
|
realpathSync,
|
|
8
|
+
rmSync,
|
|
8
9
|
writeFileSync,
|
|
9
10
|
} from "node:fs";
|
|
10
|
-
import { spawnSync } from "node:child_process";
|
|
11
11
|
import { basename, delimiter, dirname, isAbsolute, join, resolve } from "node:path";
|
|
12
12
|
import { arch, availableParallelism, release, tmpdir, type } from "node:os";
|
|
13
13
|
import { pathToFileURL } from "node:url";
|
|
@@ -44,10 +44,24 @@ import {
|
|
|
44
44
|
import { EXIT_STATUS, setExitCode } from "./exit-codes";
|
|
45
45
|
import type { LineRange } from "./obligations/generate";
|
|
46
46
|
import { getAtPrefix, getLocusText } from "./obligations/expression";
|
|
47
|
-
import {
|
|
47
|
+
import {
|
|
48
|
+
formatSummary,
|
|
49
|
+
getObligations,
|
|
50
|
+
WHOLE_MODULE,
|
|
51
|
+
type ModuleObligations,
|
|
52
|
+
type PrintedObligation,
|
|
53
|
+
} from "./obligations";
|
|
54
|
+
import { format, renderDoc } from "./obligations/format";
|
|
55
|
+
import { printSequent } from "./obligations/printer";
|
|
48
56
|
import { check } from "./parallel";
|
|
49
57
|
import { parseModule } from "./parser";
|
|
50
|
-
import {
|
|
58
|
+
import {
|
|
59
|
+
encodeProofTheory,
|
|
60
|
+
formatNormalized,
|
|
61
|
+
proveObligations,
|
|
62
|
+
type ProofAttempt,
|
|
63
|
+
} from "./prove/prove";
|
|
64
|
+
import { TLAPS_MODULE } from "./prove/tlaps-module";
|
|
51
65
|
import type { StateDump } from "./state-graph";
|
|
52
66
|
import {
|
|
53
67
|
formatProbability,
|
|
@@ -56,6 +70,12 @@ import {
|
|
|
56
70
|
getOutDegreeSummary,
|
|
57
71
|
} from "./tlc-summary";
|
|
58
72
|
import { getTlapmPaths } from "./prove/tlapm/tlapm";
|
|
73
|
+
import {
|
|
74
|
+
getKnownResults,
|
|
75
|
+
loadFingerprints,
|
|
76
|
+
saveHistory,
|
|
77
|
+
type FingerprintTable,
|
|
78
|
+
} from "./tlapm-cache";
|
|
59
79
|
import type { SanySpecification } from "./sany-generator";
|
|
60
80
|
import { SANY_174_STANDARD_MODULES, SANY_STANDARD_MODULES } from "./sany-modules";
|
|
61
81
|
import { getSanyModuleName, getSanyReport, type SanyModuleOrigin } from "./sany-report";
|
|
@@ -103,21 +123,27 @@ const CHECK_COMMAND = defineCommand("tla-ts <Spec.tla|Spec.cfg|glob>... {options
|
|
|
103
123
|
{ flag: "-workers <count|auto>" },
|
|
104
124
|
]);
|
|
105
125
|
|
|
106
|
-
const
|
|
107
|
-
{ flag: "-N"
|
|
126
|
+
const TLAPM_COMMAND = defineCommand("tla-ts tlapm {options} <Module.tla|glob>...", [
|
|
127
|
+
{ flag: "-N" },
|
|
128
|
+
{ flag: "--summary" },
|
|
129
|
+
{ flag: "--strict" },
|
|
108
130
|
{ flag: "--toolbox <start> <end>" },
|
|
109
131
|
{ flag: "--line <num>" },
|
|
110
132
|
{ flag: "--printallobs" },
|
|
111
|
-
{ flag: "--
|
|
112
|
-
{ flag: "--
|
|
133
|
+
{ flag: "--threads <num>" },
|
|
134
|
+
{ flag: "--version" },
|
|
113
135
|
{ flag: "-I <directory>", isRepeatable: true },
|
|
136
|
+
{ flag: "-k" },
|
|
137
|
+
{ flag: "--noproving" },
|
|
138
|
+
{ flag: "--nofp" },
|
|
139
|
+
{ flag: "--nofpl <start> <end>" },
|
|
140
|
+
{ flag: "--safefp" },
|
|
141
|
+
{ flag: "--cleanfp" },
|
|
142
|
+
{ flag: "--usefp <file>" },
|
|
143
|
+
{ flag: "--cache-dir <directory>" },
|
|
114
144
|
]);
|
|
115
145
|
|
|
116
|
-
const
|
|
117
|
-
{ flag: `--backend <${PROVE_BACKENDS.join("|")}>`, isRequired: true },
|
|
118
|
-
{ flag: "-I <directory>", isRepeatable: true },
|
|
119
|
-
{ flag: "-workers <count|auto>" },
|
|
120
|
-
]);
|
|
146
|
+
const TLAPM_INTEGER_OPTIONS = new Set(["--toolbox", "--line", "--threads", "--nofpl"]);
|
|
121
147
|
|
|
122
148
|
const XML_EXPORT_FLAGS = new Set(["-o", "-t", "-r", "-u"]);
|
|
123
149
|
|
|
@@ -173,9 +199,7 @@ const XML_EXPORT_USAGE = (() => {
|
|
|
173
199
|
|
|
174
200
|
const USAGE = [
|
|
175
201
|
`Usage: ${CHECK_COMMAND.usage}`,
|
|
176
|
-
` ${
|
|
177
|
-
` ${BACKEND_COMMAND.usage}`,
|
|
178
|
-
" tla-ts prove [<tlapm option>]... <Module.tla|glob>...",
|
|
202
|
+
` ${TLAPM_COMMAND.usage}`,
|
|
179
203
|
" tla-ts [<JVM option>]... tlc2.TLC <TLC option>... <Spec>",
|
|
180
204
|
" (-cp tla2tools.jar or -Dtla-ts.tlc=1.7.4 picks the TLC to reproduce)",
|
|
181
205
|
" tla-ts [<JVM option>]... tla2sany.xml.XMLExporter [-I <directory>]... [-o] [-t] [-r] [-u] <Module.tla>",
|
|
@@ -1050,45 +1074,42 @@ const runEach = async (
|
|
|
1050
1074
|
return exitCodes.find((exitCode) => exitCode !== EXIT_STATUS.success) ?? EXIT_STATUS.success;
|
|
1051
1075
|
};
|
|
1052
1076
|
|
|
1053
|
-
// tlapm
|
|
1054
|
-
// bin/tlapm.
|
|
1055
|
-
const
|
|
1056
|
-
|
|
1077
|
+
// tlapm searches the current directory, then its standard library at lib/tlapm/stdlib beside
|
|
1078
|
+
// bin/tlapm, then each -I directory, the last given first.
|
|
1079
|
+
const getLibraryDirectories = (parsed: ParsedArgs) => [
|
|
1080
|
+
".",
|
|
1081
|
+
...getTlapmPaths()
|
|
1057
1082
|
.map((path) => join(dirname(dirname(realpathSync(path))), "lib/tlapm/stdlib"))
|
|
1058
|
-
.
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
const proveWithTlapm = (args: string[]) => {
|
|
1064
|
-
const tlapm = getTlapmPaths()[0];
|
|
1065
|
-
if (tlapm === undefined) {
|
|
1066
|
-
console.error(
|
|
1067
|
-
"Error: tla-ts prove runs tlapm to prove obligations, but tlapm isn't on your PATH. Install tlapm, or pass -N to only generate the obligations.",
|
|
1068
|
-
);
|
|
1069
|
-
return 1;
|
|
1070
|
-
}
|
|
1071
|
-
return spawnSync(tlapm, expandGlobs(args), { stdio: "inherit" }).status ?? 1;
|
|
1072
|
-
};
|
|
1073
|
-
|
|
1074
|
-
const readModule = (path: string) =>
|
|
1075
|
-
existsSync(path) ? { file: path, source: readFileSync(path, "utf8") } : undefined;
|
|
1083
|
+
.filter((path) => existsSync(path))
|
|
1084
|
+
.slice(0, 1),
|
|
1085
|
+
...parsed.options.flatMap((option) => (option.name === "-I" ? option.values : [])).toReversed(),
|
|
1086
|
+
];
|
|
1076
1087
|
|
|
1077
1088
|
// A message of tlapm's toolbox protocol, which it writes to stderr.
|
|
1078
1089
|
const printToolboxMessage = (fields: string[]) =>
|
|
1079
1090
|
console.error(`@!!BEGIN\n${fields.map((field) => `@!!${field}\n`).join("")}@!!END\n`);
|
|
1080
1091
|
|
|
1081
|
-
const
|
|
1092
|
+
const printObligationMessage = (obligation: PrintedObligation, status: string, fields: string[]) =>
|
|
1093
|
+
printToolboxMessage([
|
|
1094
|
+
"type:obligation",
|
|
1095
|
+
`id:${obligation.id}`,
|
|
1096
|
+
`loc:${obligation.location}`,
|
|
1097
|
+
`status:${status}`,
|
|
1098
|
+
...fields,
|
|
1099
|
+
]);
|
|
1100
|
+
|
|
1101
|
+
const TLAPM_VERSION = "9ed0376";
|
|
1082
1102
|
|
|
1083
1103
|
const quoteArgument = (arg: string) =>
|
|
1084
1104
|
/^[+,\-./0-9:=@A-Z_a-z]+$/.test(arg) ? arg : `'${arg.replaceAll("'", "'\\''")}'`;
|
|
1085
1105
|
|
|
1086
1106
|
const printToolboxHeader = (args: string[]) =>
|
|
1087
1107
|
console.log(
|
|
1088
|
-
`\n\\* TLAPM version ${TLAPM_VERSION}\n\\* launched at ${formatTlcDate(new Date())} with command line:\n\\* ${["tla-ts", "
|
|
1108
|
+
`\n\\* TLAPM version ${TLAPM_VERSION}\n\\* launched at ${formatTlcDate(new Date())} with command line:\n\\* ${["tla-ts", "tlapm", ...args].map(quoteArgument).join(" ")}\n`,
|
|
1089
1109
|
);
|
|
1090
1110
|
|
|
1091
|
-
|
|
1111
|
+
// The most severe first.
|
|
1112
|
+
const STRICT_EXIT_STATUS = { failed: 10, incomplete: 11, emptyTarget: 12 };
|
|
1092
1113
|
|
|
1093
1114
|
const checkStrictly = (result: ModuleObligations, isTargeted: boolean, isSummary: boolean) => {
|
|
1094
1115
|
const summary = result.summary;
|
|
@@ -1116,6 +1137,17 @@ const checkStrictly = (result: ModuleObligations, isTargeted: boolean, isSummary
|
|
|
1116
1137
|
|
|
1117
1138
|
const TLAPM_FAILURE_STATUS = 3;
|
|
1118
1139
|
|
|
1140
|
+
const UNPROVED_ENDING = [
|
|
1141
|
+
' tlapm ending abnormally with Failure("backend errors: there are unproved obligations")',
|
|
1142
|
+
'Raised at Stdlib.failwith in file "stdlib.ml", line 29, characters 17-33',
|
|
1143
|
+
'Called from Tlapm_lib.process_module in file "src/tlapm_lib.ml", lines 492-493, characters 12-37',
|
|
1144
|
+
'Called from Tlapm_lib.main.f in file "src/tlapm_lib.ml", line 640, characters 23-43',
|
|
1145
|
+
'Called from Stdlib__List.fold_left in file "list.ml", line 125, characters 24-34',
|
|
1146
|
+
'Called from Tlapm_lib.main in file "src/tlapm_lib.ml", line 643, characters 13-40',
|
|
1147
|
+
'Called from Tlapm_lib.init in file "src/tlapm_lib.ml", line 659, characters 8-59',
|
|
1148
|
+
"",
|
|
1149
|
+
].join("\n");
|
|
1150
|
+
|
|
1119
1151
|
const generateObligations = (generate: () => ModuleObligations[]) => {
|
|
1120
1152
|
try {
|
|
1121
1153
|
return generate();
|
|
@@ -1126,62 +1158,114 @@ const generateObligations = (generate: () => ModuleObligations[]) => {
|
|
|
1126
1158
|
}
|
|
1127
1159
|
};
|
|
1128
1160
|
|
|
1129
|
-
//
|
|
1130
|
-
const
|
|
1131
|
-
const
|
|
1132
|
-
const
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1161
|
+
// Toolbox.print_res_aux.
|
|
1162
|
+
const printAttempt = (obligation: PrintedObligation, attempt: ProofAttempt) => {
|
|
1163
|
+
const limit = attempt.method.timeLimitMs;
|
|
1164
|
+
const used =
|
|
1165
|
+
attempt.timeUsedMs === undefined
|
|
1166
|
+
? ""
|
|
1167
|
+
: `; time-used: ${(attempt.timeUsedMs / 1000).toFixed(1)} (${Math.round((100 * attempt.timeUsedMs) / limit)}%)`;
|
|
1168
|
+
const times =
|
|
1169
|
+
limit === 0
|
|
1170
|
+
? ""
|
|
1171
|
+
: `time-limit: ${limit === Infinity ? "inf" : Number((limit / 1000).toPrecision(6))}${used}`;
|
|
1172
|
+
const method = [attempt.method.tactic, times].filter(Boolean).join("; ");
|
|
1173
|
+
const isSmt = attempt.method.prover === "smt" || attempt.method.prover === "z3";
|
|
1174
|
+
const note =
|
|
1175
|
+
isSmt && attempt.reason === "false" && attempt.verdict
|
|
1176
|
+
? `(* SMT failed with status = ${attempt.verdict}\n *)\n`
|
|
1177
|
+
: "";
|
|
1178
|
+
printObligationMessage(obligation, attempt.isProved ? "proved" : "failed", [
|
|
1179
|
+
`prover:${attempt.method.prover}`,
|
|
1180
|
+
...(method === "" ? [] : [`meth:${method}`]),
|
|
1181
|
+
...(attempt.reason === undefined ? [] : [`reason:${attempt.reason}`]),
|
|
1182
|
+
`already:${attempt.isReused}`,
|
|
1183
|
+
...(attempt.isProved
|
|
1184
|
+
? []
|
|
1185
|
+
: [
|
|
1186
|
+
`obl:${attempt.isReused ? "" : `\n${note}`}${formatNormalized(obligation, attempt.isReused)}`,
|
|
1187
|
+
]),
|
|
1188
|
+
]);
|
|
1189
|
+
};
|
|
1190
|
+
|
|
1191
|
+
// Method.Fail, for an error obligation or one no method was tried on.
|
|
1192
|
+
const printFailure = (obligation: PrintedObligation, reason: string) =>
|
|
1193
|
+
printObligationMessage(obligation, "failed", [
|
|
1194
|
+
"prover:fail",
|
|
1195
|
+
"meth:time-limit: inf",
|
|
1196
|
+
`reason:${reason}`,
|
|
1197
|
+
"already:false",
|
|
1198
|
+
`obl:${obligation.text}`,
|
|
1199
|
+
]);
|
|
1200
|
+
|
|
1201
|
+
interface ProvingSettings {
|
|
1202
|
+
isToolbox: boolean;
|
|
1203
|
+
isProving: boolean;
|
|
1204
|
+
workers: number;
|
|
1205
|
+
isFingerprinted: (obligation: PrintedObligation) => boolean;
|
|
1206
|
+
fingerprints: FingerprintTable;
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
// Tlapm_lib.process_obs. Returns whether some obligation failed.
|
|
1210
|
+
const proveModule = async (
|
|
1211
|
+
result: ModuleObligations,
|
|
1212
|
+
theoryPath: string,
|
|
1213
|
+
fingerprintsPath: string,
|
|
1214
|
+
settings: ProvingSettings,
|
|
1215
|
+
) => {
|
|
1216
|
+
const known = getKnownResults(settings.fingerprints);
|
|
1217
|
+
const reports = await proveObligations(result.obligations, {
|
|
1218
|
+
workers: settings.workers,
|
|
1219
|
+
results: known.results,
|
|
1220
|
+
isFingerprinted: settings.isFingerprinted,
|
|
1221
|
+
isProving: settings.isProving,
|
|
1222
|
+
onReport: (report, obligation) => {
|
|
1223
|
+
if (!settings.isToolbox) return;
|
|
1224
|
+
if (report.obligation.status === "trivial")
|
|
1225
|
+
return printObligationMessage(obligation, "trivial", ["prover:tlapm", "already:false"]);
|
|
1226
|
+
if (obligation.kind.kind === "Error") return printFailure(obligation, "user error");
|
|
1227
|
+
report.attempts.forEach((attempt) => printAttempt(obligation, attempt));
|
|
1228
|
+
},
|
|
1229
|
+
});
|
|
1230
|
+
writeFileSync(theoryPath, encodeProofTheory(result.name, reports, result.obligations));
|
|
1231
|
+
console.log(`(* created new ${JSON.stringify(theoryPath)} *)`);
|
|
1232
|
+
known.save(fingerprintsPath);
|
|
1233
|
+
console.log(`(* fingerprints written in ${JSON.stringify(fingerprintsPath)} *)`);
|
|
1234
|
+
if (!settings.isProving) return false;
|
|
1235
|
+
const unproved = reports.flatMap((report, index) =>
|
|
1236
|
+
"reason" in report.obligation ? [{ report, obligation: result.obligations[index] }] : [],
|
|
1139
1237
|
);
|
|
1140
|
-
if (
|
|
1141
|
-
|
|
1142
|
-
|
|
1238
|
+
if (settings.isToolbox) {
|
|
1239
|
+
unproved
|
|
1240
|
+
.filter(
|
|
1241
|
+
(entry) => entry.report.attempts.length === 0 && entry.obligation.kind.kind !== "Error",
|
|
1242
|
+
)
|
|
1243
|
+
.forEach((entry) => printFailure(entry.obligation, "unexpected error"));
|
|
1143
1244
|
}
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
]
|
|
1155
|
-
|
|
1156
|
-
source: readFileSync(path, "utf8"),
|
|
1157
|
-
loadModule: (name) =>
|
|
1158
|
-
directories.map((directory) => readModule(`${directory}/${name}.tla`)).find(Boolean)
|
|
1159
|
-
?.source,
|
|
1160
|
-
backend,
|
|
1161
|
-
workers: getWorkerCount(parsed.get("-workers")),
|
|
1162
|
-
onObligation: (obligation) =>
|
|
1163
|
-
console.log(
|
|
1164
|
-
`${path}:${obligation.location}: ${obligation.status}${obligation.status === "proved" ? ` by ${obligation.prover}` : ""}${obligation.status === "failed" || obligation.status === "unsupported" ? ` (${obligation.reason})` : ""}`,
|
|
1165
|
-
),
|
|
1166
|
-
});
|
|
1167
|
-
const counts = Map.groupBy(result.obligations, (obligation) => obligation.status);
|
|
1168
|
-
const getCount = (status: ProofStatus) => counts.get(status)?.length ?? 0;
|
|
1169
|
-
console.log(
|
|
1170
|
-
`${result.obligations.length} obligations: ${getCount("proved")} proved, ${getCount("trivial")} trivial, ${getCount("failed")} failed, ${getCount("unsupported")} unsupported`,
|
|
1171
|
-
);
|
|
1172
|
-
return getCount("failed") + getCount("unsupported") === 0 ? EXIT_STATUS.success : 1;
|
|
1173
|
-
},
|
|
1174
|
-
() => createMessagePrinter(false),
|
|
1245
|
+
unproved
|
|
1246
|
+
.toReversed()
|
|
1247
|
+
.forEach((entry) =>
|
|
1248
|
+
console.error(
|
|
1249
|
+
`${getAtPrefix(entry.obligation.locus)}${renderDoc(format("[ERROR]: @[<v2>Could not prove or check:@,%a@]", printSequent(entry.obligation.sequent)), 35)}`,
|
|
1250
|
+
),
|
|
1251
|
+
);
|
|
1252
|
+
const total = `${result.obligations.length} obligation${result.obligations.length > 1 ? "s" : ""}`;
|
|
1253
|
+
console.error(
|
|
1254
|
+
unproved.length === 0
|
|
1255
|
+
? `${getAtPrefix(result.location)}[INFO]: All ${total} proved.`
|
|
1256
|
+
: `${getAtPrefix(result.location)}[ERROR]: ${unproved.length}/${total} failed.\nThere were backend errors processing module \`${JSON.stringify(result.name)}\`.`,
|
|
1175
1257
|
);
|
|
1258
|
+
return unproved.length > 0;
|
|
1176
1259
|
};
|
|
1177
1260
|
|
|
1178
|
-
const
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
const
|
|
1182
|
-
|
|
1261
|
+
const runTlapm = async (args: string[]) => {
|
|
1262
|
+
const parsed = TLAPM_COMMAND.parse(args);
|
|
1263
|
+
const isProcessing = !parsed.has("-N") && !parsed.has("--summary");
|
|
1264
|
+
const unsupported =
|
|
1265
|
+
parsed.unknown[0] ??
|
|
1266
|
+
(isProcessing && parsed.has("--printallobs") ? "--printallobs" : undefined);
|
|
1183
1267
|
if (unsupported !== undefined) {
|
|
1184
|
-
console.error(`Error: tla-ts
|
|
1268
|
+
console.error(`Error: tla-ts tlapm does not support the tlapm option ${unsupported}.`);
|
|
1185
1269
|
return 1;
|
|
1186
1270
|
}
|
|
1187
1271
|
if (parsed.incomplete) {
|
|
@@ -1189,13 +1273,19 @@ const runProve = (args: string[]) => {
|
|
|
1189
1273
|
return 1;
|
|
1190
1274
|
}
|
|
1191
1275
|
const nonInteger = parsed.options.find(
|
|
1192
|
-
(option) =>
|
|
1276
|
+
(option) =>
|
|
1277
|
+
TLAPM_INTEGER_OPTIONS.has(option.name) &&
|
|
1278
|
+
option.values.some((value) => !/^-?\d+$/.test(value)),
|
|
1193
1279
|
);
|
|
1194
1280
|
if (nonInteger) {
|
|
1195
1281
|
console.error(`Error: option '${nonInteger.name}' expects an integer.`);
|
|
1196
1282
|
return 1;
|
|
1197
1283
|
}
|
|
1198
|
-
|
|
1284
|
+
if (parsed.has("--version")) {
|
|
1285
|
+
console.log(TLAPM_VERSION);
|
|
1286
|
+
return EXIT_STATUS.success;
|
|
1287
|
+
}
|
|
1288
|
+
const files = getInputPaths(parsed.positionals).map((input) => input.path);
|
|
1199
1289
|
const modulePaths = files.map((path) => (path.endsWith(".tla") ? path : `${path}.tla`));
|
|
1200
1290
|
if (modulePaths.length === 0) {
|
|
1201
1291
|
console.error(USAGE);
|
|
@@ -1210,15 +1300,12 @@ const runProve = (args: string[]) => {
|
|
|
1210
1300
|
if (option.name === "--line") return start === 0 ? WHOLE_MODULE : { start, end: start };
|
|
1211
1301
|
return range;
|
|
1212
1302
|
}, WHOLE_MODULE);
|
|
1213
|
-
// tlapm searches
|
|
1214
|
-
// directory, the last given first.
|
|
1215
|
-
const tlapmLibrary = getTlapmLibrary();
|
|
1216
|
-
const includes = parsed.options.flatMap((option) => (option.name === "-I" ? option.values : []));
|
|
1303
|
+
// tlapm also searches each module's directory. Without tlapm, TLAPS is tla-ts's copy.
|
|
1217
1304
|
const directories = modulePaths.reduce(
|
|
1218
1305
|
(found, path) => (found.includes(dirname(path)) ? found : [dirname(path), ...found]),
|
|
1219
|
-
|
|
1306
|
+
getLibraryDirectories(parsed),
|
|
1220
1307
|
);
|
|
1221
|
-
|
|
1308
|
+
const moduleNames = new Set<string>();
|
|
1222
1309
|
const results = generateObligations(() => {
|
|
1223
1310
|
const missingIndex = modulePaths.findIndex((path) => !existsSync(path));
|
|
1224
1311
|
if (missingIndex !== -1) {
|
|
@@ -1228,8 +1315,16 @@ const runProve = (args: string[]) => {
|
|
|
1228
1315
|
}
|
|
1229
1316
|
return getObligations(
|
|
1230
1317
|
modulePaths.map((path) => ({ file: `./${path}`, source: readFileSync(path, "utf8") })),
|
|
1231
|
-
(name) =>
|
|
1232
|
-
|
|
1318
|
+
(name) => {
|
|
1319
|
+
moduleNames.add(name);
|
|
1320
|
+
// tlapm names each file it reads by joining a search directory and the name, as in
|
|
1321
|
+
// ./Module.tla.
|
|
1322
|
+
const file = directories
|
|
1323
|
+
.map((directory) => `${directory}/${name}.tla`)
|
|
1324
|
+
.find((path) => existsSync(path));
|
|
1325
|
+
if (file !== undefined) return { file, source: readFileSync(file, "utf8") };
|
|
1326
|
+
return name === "TLAPS" ? { file: "TLAPS.tla", source: TLAPS_MODULE } : undefined;
|
|
1327
|
+
},
|
|
1233
1328
|
{
|
|
1234
1329
|
lines,
|
|
1235
1330
|
onWarning: (warning) => {
|
|
@@ -1244,26 +1339,80 @@ const runProve = (args: string[]) => {
|
|
|
1244
1339
|
);
|
|
1245
1340
|
});
|
|
1246
1341
|
if (!results) return TLAPM_FAILURE_STATUS;
|
|
1247
|
-
const
|
|
1342
|
+
const cacheDirectory =
|
|
1343
|
+
parsed.get("--cache-dir")?.[0] ?? process.env.TLAPM_CACHE_DIR ?? ".tlacache";
|
|
1344
|
+
const forgottenLines = parsed.get("--nofpl")?.map(Number) ?? [0, 0];
|
|
1345
|
+
const settings: ProvingSettings = {
|
|
1346
|
+
isToolbox,
|
|
1347
|
+
isProving: !parsed.has("--noproving"),
|
|
1348
|
+
workers: Math.max(1, Number(parsed.get("--threads")?.[0] ?? availableParallelism())),
|
|
1349
|
+
isFingerprinted: (obligation) =>
|
|
1350
|
+
!parsed.has("--nofp") &&
|
|
1351
|
+
!(
|
|
1352
|
+
obligation.locus &&
|
|
1353
|
+
obligation.locus.startLine >= forgottenLines[0] &&
|
|
1354
|
+
obligation.locus.endLine <= forgottenLines[1]
|
|
1355
|
+
),
|
|
1356
|
+
fingerprints: new Map(),
|
|
1357
|
+
};
|
|
1358
|
+
const statuses: number[] = [];
|
|
1359
|
+
for (const [index, result] of results.entries()) {
|
|
1360
|
+
// Tlapm_lib.mkdir_tlaps.
|
|
1361
|
+
const directory = `${cacheDirectory}/${result.name}.tlaps`;
|
|
1362
|
+
const fingerprintsPath = `${directory}/fingerprints`;
|
|
1363
|
+
const loadedPath = parsed.get("--usefp")?.[0] ?? fingerprintsPath;
|
|
1364
|
+
mkdirSync(directory, { recursive: true });
|
|
1365
|
+
if (parsed.has("--cleanfp") && existsSync(fingerprintsPath)) {
|
|
1366
|
+
rmSync(fingerprintsPath);
|
|
1367
|
+
console.log(`(* fingerprints file ${JSON.stringify(fingerprintsPath)} removed *)`);
|
|
1368
|
+
}
|
|
1369
|
+
if (!parsed.has("--cleanfp") && existsSync(loadedPath) && result.summary.total !== 0) {
|
|
1370
|
+
console.log(
|
|
1371
|
+
parsed.has("--nofp")
|
|
1372
|
+
? `(* will not use fingerprints (because of option \`--nofp\`), but will now load fingerprints from the file \`${loadedPath}\`, in order to overwrite with the new fingerprints, and then save the results at the end. *)`
|
|
1373
|
+
: `(* loading fingerprints in ${JSON.stringify(loadedPath)} *)`,
|
|
1374
|
+
);
|
|
1375
|
+
loadFingerprints(settings.fingerprints, loadedPath, parsed.has("--safefp"));
|
|
1376
|
+
}
|
|
1248
1377
|
if (parsed.has("--summary")) console.log(formatSummary(result));
|
|
1249
1378
|
if (isToolbox) {
|
|
1250
1379
|
result.obligations.forEach((obligation) =>
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
`
|
|
1255
|
-
|
|
1256
|
-
...(parsed.has("--printallobs") ? [`obl:${obligation.text}`] : []),
|
|
1257
|
-
]),
|
|
1380
|
+
printObligationMessage(
|
|
1381
|
+
obligation,
|
|
1382
|
+
"to be proved",
|
|
1383
|
+
parsed.has("--printallobs") ? [`obl:${obligation.text}`] : [],
|
|
1384
|
+
),
|
|
1258
1385
|
);
|
|
1259
1386
|
printToolboxMessage(["type:obligationsnumber", `count:${result.obligations.length}`]);
|
|
1260
1387
|
}
|
|
1261
|
-
if (
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1388
|
+
if (parsed.has("--strict"))
|
|
1389
|
+
statuses.push(
|
|
1390
|
+
...checkStrictly(result, lines.start > 0 || lines.end < Infinity, parsed.has("--summary")),
|
|
1391
|
+
);
|
|
1392
|
+
if (!isProcessing) continue;
|
|
1393
|
+
// tlapm's history holds the source of each module read so far.
|
|
1394
|
+
saveHistory(
|
|
1395
|
+
fingerprintsPath,
|
|
1396
|
+
[...moduleNames, ...results.slice(0, index + 1).map((innerResult) => innerResult.name)].map(
|
|
1397
|
+
(name) => `${name}.tla`,
|
|
1398
|
+
),
|
|
1399
|
+
);
|
|
1400
|
+
const isFailed = await proveModule(
|
|
1401
|
+
result,
|
|
1402
|
+
`${directory}/${result.name}.thy`,
|
|
1403
|
+
fingerprintsPath,
|
|
1404
|
+
settings,
|
|
1405
|
+
);
|
|
1406
|
+
if (isFailed && parsed.has("--strict")) statuses.push(STRICT_EXIT_STATUS.failed);
|
|
1407
|
+
if (isFailed && !parsed.has("--strict") && !isToolbox) {
|
|
1408
|
+
console.error(UNPROVED_ENDING);
|
|
1409
|
+
return TLAPM_FAILURE_STATUS;
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
return (
|
|
1413
|
+
Object.values(STRICT_EXIT_STATUS).find((status) => statuses.includes(status)) ??
|
|
1414
|
+
EXIT_STATUS.success
|
|
1415
|
+
);
|
|
1267
1416
|
};
|
|
1268
1417
|
|
|
1269
1418
|
const checkSpecs = async (args: string[], java: JavaProperties) => {
|
|
@@ -1587,7 +1736,7 @@ const runJavaClass = (launch: JavaLaunch) => {
|
|
|
1587
1736
|
};
|
|
1588
1737
|
|
|
1589
1738
|
const run = async (args: string[]) => {
|
|
1590
|
-
if (args[0] === "
|
|
1739
|
+
if (args[0] === "tlapm") return reportErrors(() => runTlapm(args.slice(1)));
|
|
1591
1740
|
const launch = getJavaLaunch(args);
|
|
1592
1741
|
if (launch === undefined) return checkSpecs(args, { libraries: [] });
|
|
1593
1742
|
// The TLC that -Dtla-ts.tlc names, or else the one of the jar on the class path.
|