tla-ts 0.0.10-dev.09e53c2a6 → 0.0.10-dev.11307be75
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/dist/compile.cjs +3 -3
- package/dist/compile.js +1 -1
- package/dist/deciders.cjs +36 -36
- package/dist/deciders.js +54 -54
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +1 -1
- package/dist/prove-worker.cjs +1 -1
- package/dist/prove-worker.js +1 -1
- package/dist/prove.cjs +43 -43
- package/dist/prove.js +78 -78
- package/dist/run.cjs +33 -35
- package/dist/run.js +44 -46
- package/dist/tlapm.cjs +1 -1
- package/dist/tlapm.js +2 -2
- package/dist/transfer.cjs +43 -43
- package/dist/transfer.js +38 -38
- package/dist/worker.cjs +6 -6
- package/dist/worker.js +6 -6
- package/package.json +1 -1
- package/src/ast.ts +1 -0
- package/src/bags.ts +46 -28
- package/src/check-trace.ts +2 -16
- package/src/check.ts +152 -64
- package/src/cli/runtime-invariants.ts +20 -56
- package/src/cli/tlc-arguments.ts +2 -2
- package/src/cli/tlc-output.ts +1 -2
- package/src/cli/tlc.ts +13 -8
- package/src/cli/xml-exporter.ts +1 -1
- package/src/codegen.ts +9 -5
- package/src/dependencies.ts +49 -9
- package/src/dfid.ts +9 -2
- package/src/environment.ts +57 -33
- package/src/errors.ts +7 -0
- package/src/evaluate.ts +92 -32
- package/src/exit-codes.ts +4 -2
- package/src/instances.ts +5 -5
- package/src/java-overrides.ts +2 -2
- package/src/levels.ts +138 -90
- package/src/liveness-checker.ts +43 -4
- package/src/liveness.ts +1 -1
- package/src/obligations/index.ts +1 -1
- package/src/obligations/normalize.ts +1 -4
- package/src/obligations/printer.ts +5 -5
- package/src/parallel-worker.ts +8 -2
- package/src/parallel.ts +5 -0
- package/src/parser.ts +106 -144
- package/src/prover/isabelle/isar/attrib.ts +4 -4
- package/src/prover/isabelle/isar/rule-cases.ts +8 -6
- package/src/prover/isabelle/provers/clasimp.ts +1 -1
- package/src/prover/isabelle/provers/hypsubst.ts +2 -2
- package/src/prover/isabelle/pure/rewriter.ts +3 -3
- package/src/prover/isabelle/pure/term.ts +3 -3
- package/src/prover/prep/md5.ts +26 -29
- package/src/prover/smt/rewrite.ts +2 -7
- package/src/prover/smt/simplify.ts +1 -1
- package/src/prover/smt/solver/asserted-formulas.ts +66 -1
- package/src/prover/smt/solver/ast-lt.ts +1 -1
- package/src/prover/smt/solver/ast.ts +58 -11
- package/src/prover/smt/solver/blast-term-ite.ts +47 -0
- package/src/prover/smt/solver/bound-simplifier.ts +2 -3
- package/src/prover/smt/solver/bv-decl-plugin.ts +13 -10
- package/src/prover/smt/solver/bv-rewriter.ts +1 -1
- package/src/prover/smt/solver/card2bv.ts +3 -5
- package/src/prover/smt/solver/cofactor-elim-term-ite.ts +2 -3
- package/src/prover/smt/solver/context.ts +24 -3
- package/src/prover/smt/solver/ctx-simplify.ts +1 -2
- package/src/prover/smt/solver/datatype-decl-plugin.ts +15 -7
- package/src/prover/smt/solver/dependent-expr-state.ts +9 -4
- package/src/prover/smt/solver/diff-neq.ts +1 -2
- package/src/prover/smt/solver/elim-term-ite-tactic.ts +48 -0
- package/src/prover/smt/solver/elim-uncnstr.ts +4 -7
- package/src/prover/smt/solver/euf/arith-internalize.ts +1 -1
- package/src/prover/smt/solver/euf/array-internalize.ts +1 -1
- package/src/prover/smt/solver/euf/bv-internalize.ts +1 -1
- package/src/prover/smt/solver/euf/egraph.ts +4 -10
- package/src/prover/smt/solver/euf/euf-solver.ts +1 -2
- package/src/prover/smt/solver/euf/mam.ts +1 -5
- package/src/prover/smt/solver/euf/q-ematch.ts +1 -2
- package/src/prover/smt/solver/euf/th-solver.ts +0 -7
- package/src/prover/smt/solver/expr2polynomial.ts +204 -79
- package/src/prover/smt/solver/factor.ts +36 -14
- package/src/prover/smt/solver/fd-solver.ts +2 -0
- package/src/prover/smt/solver/fix-dl-var.ts +1 -2
- package/src/prover/smt/solver/fpa-rewriter.ts +1 -2
- package/src/prover/smt/solver/fpa2bv-converter.ts +3 -1
- package/src/prover/smt/solver/fpa2bv-rewriter.ts +1 -0
- package/src/prover/smt/solver/goal.ts +6 -3
- package/src/prover/smt/solver/goal2nlsat.ts +57 -30
- package/src/prover/smt/solver/hashtable.ts +4 -0
- package/src/prover/smt/solver/logic-tactics.ts +9 -2
- package/src/prover/smt/solver/lp/containers.ts +7 -1
- package/src/prover/smt/solver/lp/cross-nested.ts +1 -3
- package/src/prover/smt/solver/lp/lp-settings.ts +1 -1
- package/src/prover/smt/solver/lp/nex-creator.ts +3 -2
- package/src/prover/smt/solver/lp/nex.ts +2 -1
- package/src/prover/smt/solver/lp/nla-core.ts +1 -1
- package/src/prover/smt/solver/lp/nla-grobner.ts +158 -80
- package/src/prover/smt/solver/lp/nra-solver.ts +45 -39
- package/src/prover/smt/solver/lp/pdd-interval.ts +6 -2
- package/src/prover/smt/solver/lp/pdd-simplifier.ts +60 -20
- package/src/prover/smt/solver/lp/pdd-solver.ts +72 -39
- package/src/prover/smt/solver/lp/pdd.ts +725 -290
- package/src/prover/smt/solver/lp/union-find.ts +1 -1
- package/src/prover/smt/solver/mam-compiler.ts +1 -1
- package/src/prover/smt/solver/model-based-opt.ts +1 -1
- package/src/prover/smt/solver/model-generator.ts +3 -1
- package/src/prover/smt/solver/mpf.ts +2 -4
- package/src/prover/smt/solver/mus.ts +2 -3
- package/src/prover/smt/solver/muz/dl-context.ts +10 -4
- package/src/prover/smt/solver/muz/dl-mk-slice.ts +3 -3
- package/src/prover/smt/solver/muz/dl-rule.ts +2 -2
- package/src/prover/smt/solver/muz/horn-subsume-model-converter.ts +1 -1
- package/src/prover/smt/solver/muz/horn-tactic.ts +1 -1
- package/src/prover/smt/solver/muz/spacer-context.ts +2 -4
- package/src/prover/smt/solver/muz/spacer-pdr.ts +1 -0
- package/src/prover/smt/solver/nlqsat.ts +1 -1
- package/src/prover/smt/solver/nlsat/algebraic.ts +196 -92
- package/src/prover/smt/solver/nlsat/atoms.ts +52 -33
- package/src/prover/smt/solver/nlsat/explain.ts +375 -217
- package/src/prover/smt/solver/nlsat/levelwise.ts +460 -240
- package/src/prover/smt/solver/nlsat/polynomial.ts +2366 -681
- package/src/prover/smt/solver/nlsat/solver.ts +74 -64
- package/src/prover/smt/solver/nlsat/transcendentals.ts +41 -17
- package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +8 -4
- package/src/prover/smt/solver/nlsat/upolynomial.ts +41 -18
- package/src/prover/smt/solver/nlsat-tactic.ts +1 -1
- package/src/prover/smt/solver/nnf.ts +6 -2
- package/src/prover/smt/solver/opt-context.ts +9 -3
- package/src/prover/smt/solver/opt-nlsat.ts +29 -18
- package/src/prover/smt/solver/opt-preprocess.ts +1 -1
- package/src/prover/smt/solver/opt-solver.ts +6 -3
- package/src/prover/smt/solver/optsmt.ts +1 -1
- package/src/prover/smt/solver/pb-rewriter.ts +1 -4
- package/src/prover/smt/solver/poly-rewriter.ts +74 -18
- package/src/prover/smt/solver/probes.ts +88 -23
- package/src/prover/smt/solver/proto-model.ts +4 -6
- package/src/prover/smt/solver/qe-arith-plugin.ts +2 -4
- package/src/prover/smt/solver/qe-lite.ts +2 -2
- package/src/prover/smt/solver/qe.ts +3 -2
- package/src/prover/smt/solver/quantifier-manager.ts +14 -9
- package/src/prover/smt/solver/recfun-decl-plugin.ts +2 -1
- package/src/prover/smt/solver/rlimit.ts +4 -0
- package/src/prover/smt/solver/sat/config.ts +1 -1
- package/src/prover/smt/solver/sat/inc-sat-solver.ts +26 -1
- package/src/prover/smt/solver/sat/model-converter.ts +1 -1
- package/src/prover/smt/solver/sat/pb-solver.ts +1 -1
- package/src/prover/smt/solver/sat/sat-tactic.ts +4 -3
- package/src/prover/smt/solver/sat/simplifier.ts +1 -1
- package/src/prover/smt/solver/sat/solver.ts +25 -47
- package/src/prover/smt/solver/seq-axioms.ts +20 -35
- package/src/prover/smt/solver/seq-decl-plugin.ts +1 -1
- package/src/prover/smt/solver/seq-derive.ts +4 -7
- package/src/prover/smt/solver/seq-eq-solver.ts +2 -2
- package/src/prover/smt/solver/seq-monadic.ts +7 -5
- package/src/prover/smt/solver/seq-re-rewriter.ts +2 -1
- package/src/prover/smt/solver/seq-re-util.ts +1 -1
- package/src/prover/smt/solver/seq-regex-bisim.ts +1 -1
- package/src/prover/smt/solver/seq-regex-live.ts +2 -2
- package/src/prover/smt/solver/seq-rewriter.ts +31 -29
- package/src/prover/smt/solver/seq-skolem.ts +0 -23
- package/src/prover/smt/solver/seq-view-witness.ts +4 -4
- package/src/prover/smt/solver/smt-kernel.ts +9 -3
- package/src/prover/smt/solver/smt-setup.ts +68 -6
- package/src/prover/smt/solver/smtlib-parser.ts +558 -220
- package/src/prover/smt/solver/smtlib-script.ts +495 -153
- package/src/prover/smt/solver/solve-eqs.ts +13 -21
- package/src/prover/smt/solver/tactic.ts +219 -130
- package/src/prover/smt/solver/theory-bv.ts +2 -2
- package/src/prover/smt/solver/theory-lra-final-check.ts +1 -1
- package/src/prover/smt/solver/theory-lra-internalize.ts +1 -0
- package/src/prover/smt/solver/theory-lra-propagate.ts +6 -4
- package/src/prover/smt/solver/theory-lra.ts +0 -1
- package/src/prover/smt/solver/theory-pb.ts +24 -7
- package/src/prover/smt/solver/theory-seq-solve.ts +1 -1
- package/src/prover/smt/solver/theory-seq-state.ts +2 -21
- package/src/prover/tlapm/cache.ts +8 -8
- package/src/prover/zenon/equality-rules.ts +24 -0
- package/src/prover/zenon/expr.ts +21 -0
- package/src/prover/zenon/index-table.ts +7 -2
- package/src/prover/zenon/isar-case.ts +1 -1
- package/src/prover/zenon/isar.ts +2 -2
- package/src/prover/zenon/phrase.ts +1 -1
- package/src/prover/zenon/rules.ts +2 -1
- package/src/resolve.ts +779 -225
- package/src/runtime.ts +3 -1
- package/src/sany/builtins.ts +10 -10
- package/src/sany/generation.ts +2 -13
- package/src/sany/generator-definitions.ts +3 -1
- package/src/sany/generator-expressions.ts +36 -30
- package/src/sany/generator-proofs.ts +5 -3
- package/src/sany/generator.ts +2 -1
- package/src/sany/lexer.ts +3 -3
- package/src/sany/modules.ts +4 -2
- package/src/sany/nodes.ts +1 -1
- package/src/sany/selectors.ts +11 -6
- package/src/sany/xml.ts +2 -3
- package/src/search.ts +51 -22
- package/src/spec-description.ts +2 -2
- package/src/subexpressions.ts +337 -102
- package/src/successors.ts +1 -0
- package/src/symmetry.ts +1 -1
- package/src/tlc/jar-data.ts +10 -0
- package/src/tlc/messages.ts +3 -3
- package/src/tlc/order.ts +14 -3
- package/src/tlc/tlc-operators.ts +3 -1
- package/src/tlc/tlcext-operators.ts +18 -5
- package/src/tlc/trace-spec.ts +5 -5
- package/src/typed-tier.ts +29 -23
- package/src/typescript/types.ts +2 -2
- package/src/values.ts +46 -27
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
isStackOverflow,
|
|
4
4
|
SmtCanceledError,
|
|
5
5
|
SmtParseError,
|
|
6
|
+
SmtDefaultError,
|
|
6
7
|
SmtTacticError,
|
|
7
8
|
SmtUnsupportedError,
|
|
8
9
|
} from "../../../errors";
|
|
@@ -38,19 +39,24 @@ import {
|
|
|
38
39
|
createCommandReader,
|
|
39
40
|
createSmtlibReader,
|
|
40
41
|
DECLARATIONS,
|
|
42
|
+
expectClosed,
|
|
41
43
|
isSymbol,
|
|
44
|
+
isUnsigned,
|
|
42
45
|
type SExpr,
|
|
43
46
|
type SmtList,
|
|
44
47
|
type SmtlibReader,
|
|
48
|
+
type SmtToken,
|
|
45
49
|
} from "./smtlib-parser";
|
|
46
50
|
import { O_MAXIMIZE, O_MAXSMT, O_MINIMIZE, OptContext, type OptObjective } from "./opt-context";
|
|
47
51
|
import { getLogicStrategy } from "./logic-tactics";
|
|
48
52
|
import { isMbqiByFeatures, isMbqiByLogic } from "./smt-setup";
|
|
49
|
-
import { isSupportedLogic } from "./smt-logics";
|
|
53
|
+
import { isSupportedLogic, logicHasSeq } from "./smt-logics";
|
|
50
54
|
import { getVerdict, solveAssertions, solveAssuming } from "./solver";
|
|
51
55
|
import { getConsequences } from "./smt-consequences";
|
|
52
56
|
import { getFdConsequences } from "./fd-solver";
|
|
53
57
|
import { SmtKernel } from "./smt-kernel";
|
|
58
|
+
import { Mus } from "./mus";
|
|
59
|
+
import { RefVector } from "./ref-vector";
|
|
54
60
|
import { IncSatSolver } from "./sat/inc-sat-solver";
|
|
55
61
|
import { mkThSolver } from "./euf/th-solvers";
|
|
56
62
|
import { isAstLess } from "./ast-lt";
|
|
@@ -69,9 +75,62 @@ import {
|
|
|
69
75
|
compileTactic,
|
|
70
76
|
getRewriterOptions,
|
|
71
77
|
getSatParams,
|
|
78
|
+
getSmtTacticFailure,
|
|
72
79
|
type TacticParam,
|
|
73
80
|
} from "./tactic";
|
|
74
81
|
|
|
82
|
+
const UNPORTED_COMMANDS = new Set([
|
|
83
|
+
"assert-not",
|
|
84
|
+
"assume",
|
|
85
|
+
"dbg-bool-rewriter",
|
|
86
|
+
"dbg-elim-and",
|
|
87
|
+
"dbg-get-qbody",
|
|
88
|
+
"dbg-params",
|
|
89
|
+
"dbg-pp-var",
|
|
90
|
+
"dbg-set",
|
|
91
|
+
"dbg-set-next-id",
|
|
92
|
+
"dbg-sexpr",
|
|
93
|
+
"dbg-shift-vars",
|
|
94
|
+
"dbg-size",
|
|
95
|
+
"dbg-subst",
|
|
96
|
+
"dbg-th-rewriter",
|
|
97
|
+
"dbg-translator",
|
|
98
|
+
"declare-map",
|
|
99
|
+
"declare-tactic",
|
|
100
|
+
"declare-type-var",
|
|
101
|
+
"del",
|
|
102
|
+
"display-dimacs",
|
|
103
|
+
"euf-project",
|
|
104
|
+
"eufi",
|
|
105
|
+
"ff-boolean-certify",
|
|
106
|
+
"ff-certify",
|
|
107
|
+
"ff-check-native-proof",
|
|
108
|
+
"ff-integrated-certify",
|
|
109
|
+
"get-assignment",
|
|
110
|
+
"get-interpolant",
|
|
111
|
+
"get-proof",
|
|
112
|
+
"get-proof-graph",
|
|
113
|
+
"get-unsat-assumptions",
|
|
114
|
+
"get-user-tactics",
|
|
115
|
+
"help",
|
|
116
|
+
"help-simplifier",
|
|
117
|
+
"help-tactic",
|
|
118
|
+
"include",
|
|
119
|
+
"infer",
|
|
120
|
+
"labels",
|
|
121
|
+
"mbi",
|
|
122
|
+
"mbp",
|
|
123
|
+
"mbp-qel",
|
|
124
|
+
"model-add",
|
|
125
|
+
"model-del",
|
|
126
|
+
"prefer",
|
|
127
|
+
"qe-lite",
|
|
128
|
+
"qel",
|
|
129
|
+
"reset-preferences",
|
|
130
|
+
"set-initial-value",
|
|
131
|
+
"set-simplifier",
|
|
132
|
+
]);
|
|
133
|
+
|
|
75
134
|
const SILENT_COMMANDS = new Set([
|
|
76
135
|
...DECLARATIONS,
|
|
77
136
|
"assert",
|
|
@@ -81,8 +140,6 @@ const SILENT_COMMANDS = new Set([
|
|
|
81
140
|
"reset-assertions",
|
|
82
141
|
"set-option",
|
|
83
142
|
"set-info",
|
|
84
|
-
"minimize",
|
|
85
|
-
"maximize",
|
|
86
143
|
"assert-soft",
|
|
87
144
|
"declare-rel",
|
|
88
145
|
"declare-var",
|
|
@@ -175,7 +232,9 @@ const getSoftParameters = (items: SExpr[]) => {
|
|
|
175
232
|
const parameters = { weight: Rational.one, id: null as string | null };
|
|
176
233
|
for (let index = 0; index < items.length; index += 2) {
|
|
177
234
|
const keyword = items[index];
|
|
178
|
-
|
|
235
|
+
if (keyword.kind !== "keyword")
|
|
236
|
+
throw new SmtParseError("invalid command argument, keyword expected", keyword);
|
|
237
|
+
const name = getParameterName(keyword.text);
|
|
179
238
|
const value = items[index + 1];
|
|
180
239
|
if (name === "weight" && (value?.kind === "numeral" || value?.kind === "decimal")) {
|
|
181
240
|
const [whole, fraction = ""] = value.text.split(".");
|
|
@@ -193,7 +252,9 @@ const getSimplifyParams = (items: SExpr[]) => {
|
|
|
193
252
|
const params = new Map<string, TacticParam>();
|
|
194
253
|
for (let index = 0; index < items.length; index += 2) {
|
|
195
254
|
const keyword = items[index];
|
|
196
|
-
|
|
255
|
+
if (keyword.kind !== "keyword")
|
|
256
|
+
throw new SmtParseError("invalid command argument, keyword expected", keyword);
|
|
257
|
+
const name = getParameterName(keyword.text);
|
|
197
258
|
const value = items[index + 1];
|
|
198
259
|
if (SIMPLIFY_UINT_PARAMETERS.has(name) && value?.kind === "numeral") {
|
|
199
260
|
params.set(name, Number(value.text));
|
|
@@ -245,12 +306,29 @@ const getCommandParams = (items: SExpr[], isBooleans: ReadonlyMap<string, boolea
|
|
|
245
306
|
"invalid command argument, unsigned integer expected",
|
|
246
307
|
value ?? keyword,
|
|
247
308
|
);
|
|
309
|
+
if (!isUnsigned(value.text))
|
|
310
|
+
throw new SmtParseError(
|
|
311
|
+
"invalid indexed identifier, index is too big to fit in an unsigned machine integer",
|
|
312
|
+
value,
|
|
313
|
+
);
|
|
248
314
|
params.set(name, Number(value.text));
|
|
249
315
|
}
|
|
250
316
|
}
|
|
251
317
|
return params;
|
|
252
318
|
};
|
|
253
319
|
|
|
320
|
+
const getFirstArgument = (list: SmtList) => {
|
|
321
|
+
const argument = list.items[1];
|
|
322
|
+
if (argument === undefined)
|
|
323
|
+
throw new SmtParseError("invalid command, argument(s) missing", list.end);
|
|
324
|
+
return argument;
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
const checkArgumentCount = (list: SmtList, count: number) => {
|
|
328
|
+
const extra = list.items[count + 1];
|
|
329
|
+
if (extra !== undefined) throw new SmtParseError("invalid command, too many arguments", extra);
|
|
330
|
+
};
|
|
331
|
+
|
|
254
332
|
// Z3's parse_opt_unsigned names the push command for pop as well.
|
|
255
333
|
const getScopeCount = (list: SmtList) => {
|
|
256
334
|
const argument = list.items[1];
|
|
@@ -272,12 +350,19 @@ interface CheckResult {
|
|
|
272
350
|
status: number;
|
|
273
351
|
context: Context | undefined;
|
|
274
352
|
isOptimizing: boolean;
|
|
353
|
+
isFromTactic: boolean;
|
|
275
354
|
model: ProtoModel | undefined;
|
|
276
355
|
core: number[] | undefined;
|
|
277
356
|
// check_sat_result::reason_unknown, where the port tracks it.
|
|
278
357
|
reasonUnknown?: string;
|
|
279
358
|
}
|
|
280
359
|
|
|
360
|
+
interface SolverAnswer {
|
|
361
|
+
result: number;
|
|
362
|
+
context: Context | undefined;
|
|
363
|
+
reasonUnknown: string | undefined;
|
|
364
|
+
}
|
|
365
|
+
|
|
281
366
|
interface ScriptState {
|
|
282
367
|
manager: AstManager;
|
|
283
368
|
logic: string | undefined;
|
|
@@ -299,9 +384,7 @@ interface ScriptState {
|
|
|
299
384
|
// combined_solver's incremental smt kernel, which keeps one context across the checks, or
|
|
300
385
|
// undefined while Z3 has made no such kernel.
|
|
301
386
|
kernel: SmtKernel | undefined;
|
|
302
|
-
|
|
303
|
-
// an unported theory and the smt kernel answers in its place.
|
|
304
|
-
eufSolver: IncSatSolver | undefined;
|
|
387
|
+
satSolver: IncSatSolver | undefined;
|
|
305
388
|
}
|
|
306
389
|
|
|
307
390
|
// Z3 fixes the proof mode at the first command that needs terms.
|
|
@@ -311,6 +394,7 @@ const MANAGERLESS_COMMANDS = new Set([
|
|
|
311
394
|
"set-logic",
|
|
312
395
|
"get-option",
|
|
313
396
|
"get-info",
|
|
397
|
+
"get-assertions",
|
|
314
398
|
"echo",
|
|
315
399
|
]);
|
|
316
400
|
|
|
@@ -343,11 +427,11 @@ export const runSmtlibScript = (
|
|
|
343
427
|
rlimit: 0,
|
|
344
428
|
printOptions: { ...DEFAULT_PRINT_OPTIONS },
|
|
345
429
|
parserOptions: { isIgnoringBadPatterns: true },
|
|
430
|
+
// Z3 keeps set-info's :status across reset.
|
|
431
|
+
status: L_UNDEF,
|
|
346
432
|
};
|
|
347
433
|
const createState = (): ScriptState => {
|
|
348
|
-
const manager = new AstManager(
|
|
349
|
-
new ResourceLimit(Date.now() + options.timeLimitMs, options.signal),
|
|
350
|
-
);
|
|
434
|
+
const manager = new AstManager(new ResourceLimit(Infinity, options.signal));
|
|
351
435
|
manager.isHiDiv0 = settings.isHiDiv0;
|
|
352
436
|
manager.maxChar = settings.encoding.maxChar;
|
|
353
437
|
manager.charBits = settings.encoding.charBits;
|
|
@@ -368,7 +452,7 @@ export const runSmtlibScript = (
|
|
|
368
452
|
hasChecked: false,
|
|
369
453
|
datalog: undefined,
|
|
370
454
|
kernel: undefined,
|
|
371
|
-
|
|
455
|
+
satSolver: undefined,
|
|
372
456
|
};
|
|
373
457
|
};
|
|
374
458
|
let state = createState();
|
|
@@ -409,7 +493,7 @@ export const runSmtlibScript = (
|
|
|
409
493
|
paretoMaxLemmas: Number(parameters.get("opt.pareto_nlsat_max_lemmas") ?? 128),
|
|
410
494
|
};
|
|
411
495
|
};
|
|
412
|
-
const optimize = (extra: number[]) => {
|
|
496
|
+
const optimize = (extra: number[], end: SmtToken) => {
|
|
413
497
|
const manager = state.manager;
|
|
414
498
|
const objectives = state.objectives;
|
|
415
499
|
const hard = [...getNamedAssertions(), ...state.names.filter((name) => name !== -1), ...extra];
|
|
@@ -452,7 +536,11 @@ export const runSmtlibScript = (
|
|
|
452
536
|
!hasAssumptions &&
|
|
453
537
|
settings.parameters.get("opt.incremental") !== "true",
|
|
454
538
|
});
|
|
455
|
-
setCheck(status, {
|
|
539
|
+
setCheck(status, {
|
|
540
|
+
isOptimizing: true,
|
|
541
|
+
model: optimizer.model ?? undefined,
|
|
542
|
+
reasonUnknown: optimizer.getReasonUnknown(),
|
|
543
|
+
});
|
|
456
544
|
print(getVerdict(status));
|
|
457
545
|
return true;
|
|
458
546
|
} catch (error) {
|
|
@@ -461,9 +549,15 @@ export const runSmtlibScript = (
|
|
|
461
549
|
resetOptimizer();
|
|
462
550
|
return false;
|
|
463
551
|
}
|
|
552
|
+
if (error instanceof SmtDefaultError) {
|
|
553
|
+
optimizer.release();
|
|
554
|
+
setCheck(L_UNDEF, { isOptimizing: true, reasonUnknown: "unknown" });
|
|
555
|
+
throw new SmtParseError(error.message, end);
|
|
556
|
+
}
|
|
464
557
|
if (!(error instanceof SmtCanceledError || isStackOverflow(error))) throw error;
|
|
558
|
+
const reasonUnknown = optimizer.getReasonUnknown();
|
|
465
559
|
optimizer.release();
|
|
466
|
-
setCheck(L_UNDEF, { isOptimizing: true });
|
|
560
|
+
setCheck(L_UNDEF, { isOptimizing: true, reasonUnknown });
|
|
467
561
|
print("unknown");
|
|
468
562
|
return true;
|
|
469
563
|
} finally {
|
|
@@ -483,25 +577,53 @@ export const runSmtlibScript = (
|
|
|
483
577
|
getLogicStrategy(state.logic, goal.isProofsEnabled);
|
|
484
578
|
try {
|
|
485
579
|
const checked = checkSatUsing(compileInternalTactic(getTacticEnvironment(), strategy), goal);
|
|
486
|
-
return {
|
|
580
|
+
return {
|
|
581
|
+
result: checked.status,
|
|
582
|
+
context: undefined,
|
|
583
|
+
model: checked.model,
|
|
584
|
+
// The finite-domain solver is an inc_sat_solver, whose reason stays "no reason given" after an answer.
|
|
585
|
+
reasonUnknown:
|
|
586
|
+
isUsingFdSolver() && checked.status !== L_UNDEF
|
|
587
|
+
? "no reason given"
|
|
588
|
+
: checked.reasonUnknown,
|
|
589
|
+
};
|
|
487
590
|
} catch (error) {
|
|
488
591
|
if (!(error instanceof SmtUnsupportedError)) throw error;
|
|
489
592
|
const hasQuantifiers = state.assertions.some(
|
|
490
593
|
(assertion) => state.manager.hasQuantifierFlags[assertion],
|
|
491
594
|
);
|
|
595
|
+
const solved = solveAssertions(state.manager, state.assertions, {
|
|
596
|
+
isMbqi: settings.isMbqi || isMbqiByFeatures(getSetup(), hasQuantifiers),
|
|
597
|
+
mbqiMaxIterations: settings.mbqiMaxIterations,
|
|
598
|
+
isFindingMacros: settings.isFindingMacros,
|
|
599
|
+
setup: getSetup(),
|
|
600
|
+
});
|
|
492
601
|
return {
|
|
493
|
-
...
|
|
494
|
-
isMbqi: settings.isMbqi || isMbqiByFeatures(getSetup(), hasQuantifiers),
|
|
495
|
-
mbqiMaxIterations: settings.mbqiMaxIterations,
|
|
496
|
-
isFindingMacros: settings.isFindingMacros,
|
|
497
|
-
setup: getSetup(),
|
|
498
|
-
}),
|
|
602
|
+
...solved,
|
|
499
603
|
model: undefined,
|
|
604
|
+
reasonUnknown:
|
|
605
|
+
solved.result === L_UNDEF && solved.context !== undefined
|
|
606
|
+
? getSmtTacticFailure(solved.context)
|
|
607
|
+
: "",
|
|
500
608
|
};
|
|
501
609
|
}
|
|
502
610
|
};
|
|
503
|
-
|
|
504
|
-
|
|
611
|
+
// Deviation from Z3: the heap guard and a stack overflow, which Z3 lacks, read as an exhausted rlimit.
|
|
612
|
+
const getCancelMessage = (deadline: number) =>
|
|
613
|
+
Date.now() > deadline || options.signal?.aborted === true
|
|
614
|
+
? "canceled"
|
|
615
|
+
: "max. resource limit exceeded";
|
|
616
|
+
// As in Z3, a timeout leaves "timeout" in the kernel, which reports it while its last search hasn't failed.
|
|
617
|
+
const getReasonUnknown = (solved: SolverAnswer, deadline: number) => {
|
|
618
|
+
const isTimedOut = solved.result === L_UNDEF && Date.now() > deadline;
|
|
619
|
+
const context = state.kernel?.context;
|
|
620
|
+
if (isTimedOut && context !== undefined) context.reasonUnknown = "timeout";
|
|
621
|
+
if (context !== undefined && solved.context === context) return context.getLastFailureMessage();
|
|
622
|
+
return isTimedOut ? "timeout" : (solved.reasonUnknown ?? getCancelMessage(deadline));
|
|
623
|
+
};
|
|
624
|
+
// As in Z3, a kernel loses the mbqi its logic turned on once it reads the parameters again.
|
|
625
|
+
const getKernelParams = (isSetUp = false) => ({
|
|
626
|
+
isMbqi: settings.isMbqi || (!isSetUp && isMbqiByLogic(getSetup())),
|
|
505
627
|
mbqiMaxIterations: settings.mbqiMaxIterations,
|
|
506
628
|
isFindingMacros: settings.isFindingMacros,
|
|
507
629
|
setup: getSetup(),
|
|
@@ -511,45 +633,60 @@ export const runSmtlibScript = (
|
|
|
511
633
|
(state.logic === "QF_FD" || state.logic === "SAT") &&
|
|
512
634
|
!settings.isProducingProofs &&
|
|
513
635
|
!settings.parameters.has("tactic.default_tactic");
|
|
514
|
-
const checkSat = (extra: number[]) => {
|
|
515
|
-
|
|
636
|
+
const checkSat = (extra: number[], end: SmtToken) => {
|
|
637
|
+
const deadline = Date.now() + options.timeLimitMs;
|
|
638
|
+
state.manager.limit.restart(deadline);
|
|
516
639
|
// opt::context::optimize answers as the search of the hard constraints does: once they are
|
|
517
640
|
// satisfiable, optsmt and maxsmt only improve the model. The unported parts of optimization
|
|
518
641
|
// only get that answer.
|
|
519
|
-
if (state.objectives.length > 0 && optimize(extra)) return;
|
|
642
|
+
if (state.objectives.length > 0 && optimize(extra, end)) return;
|
|
520
643
|
state.manager.limit.push(settings.rlimit);
|
|
521
644
|
const isOptimizing = state.objectives.length > 0;
|
|
645
|
+
const manager = state.manager;
|
|
646
|
+
const names = state.names.filter((name) => name !== -1);
|
|
647
|
+
const isNamed = names.length > 0;
|
|
648
|
+
const isAssuming = isNamed || extra.length > 0;
|
|
649
|
+
if (isAssuming) state.isIncremental = true;
|
|
650
|
+
if (!isOptimizing) state.hasChecked = true;
|
|
651
|
+
const isKernelChecking =
|
|
652
|
+
isAssuming || (state.isIncremental && !isOptimizing && !isUsingFdSolver());
|
|
522
653
|
try {
|
|
523
|
-
const
|
|
524
|
-
const names = state.names.filter((name) => name !== -1);
|
|
525
|
-
const isNamed = names.length > 0;
|
|
526
|
-
const isAssuming = isNamed || extra.length > 0;
|
|
527
|
-
if (isAssuming) state.isIncremental = true;
|
|
528
|
-
if (!isOptimizing) state.hasChecked = true;
|
|
529
|
-
const assumptions = isNamed ? [...names, ...extra] : extra;
|
|
530
|
-
const kernel =
|
|
531
|
-
isAssuming || (state.isIncremental && !isOptimizing && !isUsingFdSolver())
|
|
532
|
-
? checkKernel(assumptions)
|
|
533
|
-
: undefined;
|
|
654
|
+
const kernel = isKernelChecking ? checkKernel(names, extra) : undefined;
|
|
534
655
|
// Z3 retries a quantifier-free problem with its tactic when the incremental kernel gives up.
|
|
535
|
-
const
|
|
656
|
+
const isFromTactic =
|
|
536
657
|
kernel === undefined ||
|
|
537
658
|
(!isAssuming &&
|
|
538
659
|
kernel.result === L_UNDEF &&
|
|
539
660
|
!state.assertions.some((assertion) => manager.hasQuantifierFlags[assertion]) &&
|
|
540
|
-
manager.limit.inc())
|
|
541
|
-
|
|
542
|
-
: kernel;
|
|
661
|
+
manager.limit.inc());
|
|
662
|
+
const solved = isFromTactic ? { ...solveWithStrategy(), core: undefined } : kernel;
|
|
543
663
|
setCheck(solved.result, {
|
|
544
664
|
context: solved.context,
|
|
545
665
|
isOptimizing,
|
|
666
|
+
isFromTactic: isFromTactic && !isUsingFdSolver(),
|
|
546
667
|
model: solved.model,
|
|
547
668
|
core: solved.core ?? solved.context?.unsatCore ?? [],
|
|
669
|
+
reasonUnknown: getReasonUnknown(solved, deadline),
|
|
548
670
|
});
|
|
549
671
|
print(getVerdict(solved.result));
|
|
550
672
|
} catch (error) {
|
|
551
|
-
if (
|
|
552
|
-
|
|
673
|
+
if (
|
|
674
|
+
!(
|
|
675
|
+
error instanceof SmtCanceledError ||
|
|
676
|
+
error instanceof SmtDefaultError ||
|
|
677
|
+
isStackOverflow(error)
|
|
678
|
+
)
|
|
679
|
+
)
|
|
680
|
+
throw error;
|
|
681
|
+
const context = isKernelChecking ? state.kernel?.context : undefined;
|
|
682
|
+
setCheck(L_UNDEF, {
|
|
683
|
+
isOptimizing,
|
|
684
|
+
isFromTactic: !isKernelChecking && !isUsingFdSolver(),
|
|
685
|
+
reasonUnknown:
|
|
686
|
+
error instanceof SmtDefaultError
|
|
687
|
+
? error.message
|
|
688
|
+
: getReasonUnknown({ result: L_UNDEF, context, reasonUnknown: undefined }, deadline),
|
|
689
|
+
});
|
|
553
690
|
print("unknown");
|
|
554
691
|
} finally {
|
|
555
692
|
state.manager.limit.release();
|
|
@@ -563,7 +700,9 @@ export const runSmtlibScript = (
|
|
|
563
700
|
if (check.model !== undefined) return check.model;
|
|
564
701
|
if (check.isOptimizing) throw new SmtUnsupportedError("the models of optimization");
|
|
565
702
|
if (check.context === undefined && check.status !== L_TRUE)
|
|
566
|
-
throw
|
|
703
|
+
throw check.isFromTactic
|
|
704
|
+
? new SmtParseError("model is not available", list.end)
|
|
705
|
+
: new SmtUnsupportedError("the model of a canceled search");
|
|
567
706
|
const model = check.context?.getModel() ?? new ProtoModel(state.manager);
|
|
568
707
|
model.incRef();
|
|
569
708
|
check.model = model;
|
|
@@ -573,6 +712,12 @@ export const runSmtlibScript = (
|
|
|
573
712
|
state.check?.model?.decRef();
|
|
574
713
|
state.check = undefined;
|
|
575
714
|
};
|
|
715
|
+
// cmd_context::validate_check_sat_result runs after the answer is printed.
|
|
716
|
+
const validateCheck = (end: SmtToken) => {
|
|
717
|
+
const status = state.check?.status ?? L_UNDEF;
|
|
718
|
+
if (status !== L_UNDEF && settings.status !== L_UNDEF && status !== settings.status)
|
|
719
|
+
throw new SmtParseError(`check annotation that says ${getVerdict(settings.status)}`, end);
|
|
720
|
+
};
|
|
576
721
|
// The check holds a reference to its model until clearCheck.
|
|
577
722
|
const setCheck = (status: number, result: Partial<Omit<CheckResult, "status">> = {}) => {
|
|
578
723
|
result.model?.incRef();
|
|
@@ -580,14 +725,12 @@ export const runSmtlibScript = (
|
|
|
580
725
|
status,
|
|
581
726
|
context: undefined,
|
|
582
727
|
isOptimizing: false,
|
|
728
|
+
isFromTactic: false,
|
|
583
729
|
model: undefined,
|
|
584
730
|
core: undefined,
|
|
585
731
|
...result,
|
|
586
732
|
};
|
|
587
733
|
};
|
|
588
|
-
// cmd_context::mk_solver: mk_solver_for_logic makes the incremental solver the smt kernel unless
|
|
589
|
-
// the logic, the default tactic or the sat parameters pick a sat solver. Under sat.euf that
|
|
590
|
-
// solver is inc_sat_solver in euf mode; the other sat solvers only store their assertions.
|
|
591
734
|
const resetKernel = () => {
|
|
592
735
|
const logic = state.logic;
|
|
593
736
|
const parameters = settings.parameters;
|
|
@@ -601,48 +744,54 @@ export const runSmtlibScript = (
|
|
|
601
744
|
parameters.get("tactic.default_tactic") === "sat" ||
|
|
602
745
|
parameters.get("sat.smt") === "true" ||
|
|
603
746
|
isEuf;
|
|
604
|
-
state.
|
|
747
|
+
state.satSolver?.release();
|
|
605
748
|
state.kernel = isSatSolver ? undefined : new SmtKernel(state.manager, getKernelParams());
|
|
606
|
-
state.
|
|
607
|
-
|
|
608
|
-
? new IncSatSolver(state.manager, getSatParams(parameters), true, mkThSolver)
|
|
749
|
+
state.satSolver =
|
|
750
|
+
isSatSolver && !isFdSolver && parameters.get("sat.smt") !== "true"
|
|
751
|
+
? new IncSatSolver(state.manager, getSatParams(parameters), true, isEuf ? mkThSolver : null)
|
|
609
752
|
: undefined;
|
|
610
753
|
for (let index = 0; index < state.scopes.length; index++) {
|
|
611
754
|
state.kernel?.push();
|
|
612
|
-
|
|
755
|
+
useSatSolver((solver) => solver.push());
|
|
613
756
|
}
|
|
614
757
|
};
|
|
615
|
-
// The parts of
|
|
616
|
-
const
|
|
617
|
-
const solver = state.
|
|
758
|
+
// The parts of inc_sat_solver that are not ported leave its answers to the smt kernel.
|
|
759
|
+
const useSatSolver = <Result>(action: (solver: IncSatSolver) => Result) => {
|
|
760
|
+
const solver = state.satSolver;
|
|
618
761
|
if (solver === undefined) return undefined;
|
|
619
762
|
try {
|
|
620
763
|
return action(solver);
|
|
621
764
|
} catch (error) {
|
|
622
765
|
if (!(error instanceof SmtUnsupportedError)) throw error;
|
|
623
766
|
solver.release();
|
|
624
|
-
state.
|
|
767
|
+
state.satSolver = undefined;
|
|
625
768
|
return undefined;
|
|
626
769
|
}
|
|
627
770
|
};
|
|
628
771
|
// solver_na2as asserts a named assertion as an implication from its name.
|
|
629
772
|
const assertInKernel = (formula: number, name: number) => {
|
|
630
773
|
const manager = state.manager;
|
|
774
|
+
useSatSolver((solver) =>
|
|
775
|
+
name === -1 ? solver.assertExpr(formula) : solver.assertNamed(formula, name),
|
|
776
|
+
);
|
|
777
|
+
const kernel = state.kernel;
|
|
778
|
+
if (kernel === undefined) return;
|
|
631
779
|
const asserted = name === -1 ? formula : manager.mkApp(OP_IMPLIES, [name, formula], SORT_BOOL);
|
|
632
780
|
manager.incRef(asserted);
|
|
633
|
-
|
|
634
|
-
useEufSolver((solver) => solver.assertExpr(asserted));
|
|
781
|
+
kernel.assertExpr(asserted);
|
|
635
782
|
manager.decRef(asserted);
|
|
636
783
|
};
|
|
637
|
-
const checkKernel = (
|
|
784
|
+
const checkKernel = (names: number[], extra: number[]) => {
|
|
638
785
|
const kernel = state.kernel;
|
|
639
|
-
const
|
|
640
|
-
|
|
786
|
+
const assumptions = [...names, ...extra];
|
|
787
|
+
const found = useSatSolver((solver) => {
|
|
788
|
+
const result = solver.check(extra);
|
|
641
789
|
return {
|
|
642
790
|
result,
|
|
643
791
|
context: undefined,
|
|
644
792
|
model: result === L_TRUE ? (solver.getModel() ?? undefined) : undefined,
|
|
645
793
|
core: result === L_FALSE ? [...solver.getUnsatCore()] : undefined,
|
|
794
|
+
reasonUnknown: solver.reasonUnknown,
|
|
646
795
|
};
|
|
647
796
|
});
|
|
648
797
|
if (found !== undefined) return found;
|
|
@@ -652,11 +801,21 @@ export const runSmtlibScript = (
|
|
|
652
801
|
context: kernel.context,
|
|
653
802
|
model: undefined,
|
|
654
803
|
core: undefined,
|
|
804
|
+
reasonUnknown: undefined,
|
|
655
805
|
};
|
|
806
|
+
const solved = solveAssuming(
|
|
807
|
+
state.manager,
|
|
808
|
+
getNamedAssertions(),
|
|
809
|
+
assumptions,
|
|
810
|
+
getKernelParams(),
|
|
811
|
+
);
|
|
656
812
|
return {
|
|
657
|
-
...
|
|
813
|
+
...solved,
|
|
658
814
|
model: undefined,
|
|
659
815
|
core: undefined,
|
|
816
|
+
// inc_sat_solver, which these logics use, keeps "no reason given" after an answer.
|
|
817
|
+
reasonUnknown:
|
|
818
|
+
solved.result === L_UNDEF ? solved.context.getLastFailureMessage() : "no reason given",
|
|
660
819
|
};
|
|
661
820
|
};
|
|
662
821
|
const printDiagnostic = (line: string) => print(line, !settings.isDiagnosticOnStdout);
|
|
@@ -690,11 +849,10 @@ export const runSmtlibScript = (
|
|
|
690
849
|
);
|
|
691
850
|
return state.datalog;
|
|
692
851
|
};
|
|
693
|
-
const getTactic = (sexpr: SExpr, end: SmtList["end"]) =>
|
|
694
|
-
compileTactic(getTacticEnvironment(), sexpr, end);
|
|
695
852
|
const getGoal = (isTrackingDependencies = false) => {
|
|
696
853
|
const goal = new Goal(state.manager);
|
|
697
854
|
goal.isProofsEnabled = settings.isProducingProofs || state.isProofsEnabled === true;
|
|
855
|
+
goal.isModelsEnabled = settings.isProducingModels;
|
|
698
856
|
goal.isCoresEnabled = settings.isProducingUnsatCores;
|
|
699
857
|
for (const [index, assertion] of state.assertions.entries())
|
|
700
858
|
goal.assert(
|
|
@@ -705,22 +863,43 @@ export const runSmtlibScript = (
|
|
|
705
863
|
);
|
|
706
864
|
return goal;
|
|
707
865
|
};
|
|
866
|
+
const getCommandGoal = (isTrackingDependencies: boolean, end: SmtToken) => {
|
|
867
|
+
if (
|
|
868
|
+
settings.isProducingUnsatCores &&
|
|
869
|
+
(settings.isProducingProofs || state.isProofsEnabled === true)
|
|
870
|
+
)
|
|
871
|
+
throw new SmtParseError(
|
|
872
|
+
"Frontend does not support simultaneous generation of proofs and unsat cores",
|
|
873
|
+
end,
|
|
874
|
+
);
|
|
875
|
+
return getGoal(isTrackingDependencies);
|
|
876
|
+
};
|
|
708
877
|
const hasNames = () => state.names.some((name) => name !== -1);
|
|
709
878
|
// parse_check_sat shrinks the expression stack once the check has run.
|
|
710
|
-
const checkSatAssuming = (items: SmtList["items"]) => {
|
|
879
|
+
const checkSatAssuming = (items: SmtList["items"], itemsEnd: SmtToken, end: SmtToken) => {
|
|
711
880
|
const literals: number[] = [];
|
|
712
881
|
try {
|
|
713
|
-
for (const item of items
|
|
714
|
-
|
|
882
|
+
for (const [index, item] of items.entries())
|
|
883
|
+
literals.push(
|
|
884
|
+
state.reader.parseFormula(
|
|
885
|
+
item,
|
|
886
|
+
items[index + 1] ?? itemsEnd,
|
|
887
|
+
"invalid check-sat command, argument must be a Boolean literal",
|
|
888
|
+
),
|
|
889
|
+
);
|
|
890
|
+
checkSat(literals, end);
|
|
715
891
|
} finally {
|
|
716
892
|
for (const literal of literals) state.manager.decRef(literal);
|
|
717
893
|
}
|
|
718
894
|
};
|
|
719
895
|
const addObjective = (list: SmtList, isMax: boolean) => {
|
|
720
|
-
const term = state.reader.parseTerm(list
|
|
896
|
+
const term = state.reader.parseTerm(getFirstArgument(list));
|
|
721
897
|
const sort = state.manager.sorts[term];
|
|
722
898
|
if (sort !== SORT_INT && sort !== SORT_REAL && !state.manager.isBvSort(sort))
|
|
723
|
-
throw new SmtParseError(
|
|
899
|
+
throw new SmtParseError(
|
|
900
|
+
"Objective must be bit-vector, integer or real",
|
|
901
|
+
list.items[2] ?? list.end,
|
|
902
|
+
);
|
|
724
903
|
resetOptimizer();
|
|
725
904
|
state.manager.incRef(term);
|
|
726
905
|
state.objectives.push({
|
|
@@ -730,6 +909,8 @@ export const runSmtlibScript = (
|
|
|
730
909
|
weights: [],
|
|
731
910
|
id: null,
|
|
732
911
|
});
|
|
912
|
+
if (settings.isPrintingSuccess) print("success");
|
|
913
|
+
checkArgumentCount(list, 1);
|
|
733
914
|
};
|
|
734
915
|
const releaseObjectives = (size: number, softSize: number) => {
|
|
735
916
|
for (const index of state.softTrail.splice(softSize).reverse()) {
|
|
@@ -798,14 +979,14 @@ export const runSmtlibScript = (
|
|
|
798
979
|
if (name.kind === "list")
|
|
799
980
|
throw new SmtUnsupportedError("an indexed function declaration reference");
|
|
800
981
|
throw new SmtParseError(
|
|
801
|
-
|
|
982
|
+
`invalid function declaration reference, symbol or '(' expected got ${name.lastId}`,
|
|
802
983
|
name,
|
|
803
984
|
);
|
|
804
985
|
}
|
|
805
986
|
const domain = reference.items[1] ?? reference.end;
|
|
806
987
|
if (domain.kind !== "list")
|
|
807
988
|
throw new SmtParseError(
|
|
808
|
-
`Invalid function name. Expecting sort list starting with '(' to disambiguate function name got ${domain.
|
|
989
|
+
`Invalid function name. Expecting sort list starting with '(' to disambiguate function name got ${domain.lastId}`,
|
|
809
990
|
domain,
|
|
810
991
|
);
|
|
811
992
|
const sorts = domain.items.map((sort) => state.reader.parseSort(sort));
|
|
@@ -835,11 +1016,12 @@ export const runSmtlibScript = (
|
|
|
835
1016
|
"assert",
|
|
836
1017
|
(list) => {
|
|
837
1018
|
const term = list.items[1] ?? list.end;
|
|
838
|
-
const
|
|
1019
|
+
const follower = list.items[2] ?? list.end;
|
|
1020
|
+
const assertion = state.reader.parseAssertion(term, follower);
|
|
839
1021
|
const logicError = state.reader.getLogicError(assertion.formula);
|
|
840
1022
|
if (logicError !== undefined) {
|
|
841
1023
|
state.manager.decRef(assertion.formula);
|
|
842
|
-
throw new SmtParseError(logicError,
|
|
1024
|
+
throw new SmtParseError(logicError, follower);
|
|
843
1025
|
}
|
|
844
1026
|
state.assertions.push(assertion.formula);
|
|
845
1027
|
state.assertionTexts.push(
|
|
@@ -860,9 +1042,17 @@ export const runSmtlibScript = (
|
|
|
860
1042
|
}
|
|
861
1043
|
assertInKernel(assertion.formula, state.names[state.names.length - 1]);
|
|
862
1044
|
clearCheck();
|
|
1045
|
+
if (follower !== list.end)
|
|
1046
|
+
throw new SmtParseError("invalid assert command, ')' expected", follower);
|
|
1047
|
+
},
|
|
1048
|
+
],
|
|
1049
|
+
[
|
|
1050
|
+
"check-sat",
|
|
1051
|
+
(list) => {
|
|
1052
|
+
checkSatAssuming(list.items.slice(1), list.end, list.end);
|
|
1053
|
+
validateCheck(list.end);
|
|
863
1054
|
},
|
|
864
1055
|
],
|
|
865
|
-
["check-sat", (list) => checkSatAssuming(list.items.slice(1))],
|
|
866
1056
|
[
|
|
867
1057
|
"declare-rel",
|
|
868
1058
|
(list) => {
|
|
@@ -902,7 +1092,10 @@ export const runSmtlibScript = (
|
|
|
902
1092
|
const rule = list.items[1];
|
|
903
1093
|
if (rule === undefined) throw new SmtParseError("invalid rule, expected formula", list.end);
|
|
904
1094
|
const name = list.items[2];
|
|
905
|
-
getDatalog().addRule(
|
|
1095
|
+
getDatalog().addRule(
|
|
1096
|
+
state.reader.parseFormula(rule, rule),
|
|
1097
|
+
isSymbol(name) ? name.text : "",
|
|
1098
|
+
);
|
|
906
1099
|
},
|
|
907
1100
|
],
|
|
908
1101
|
[
|
|
@@ -924,15 +1117,17 @@ export const runSmtlibScript = (
|
|
|
924
1117
|
for (const assertion of state.assertions) datalog.assertExpr(assertion);
|
|
925
1118
|
state.manager.limit.restart(Date.now() + options.timeLimitMs);
|
|
926
1119
|
state.manager.limit.push(settings.rlimit);
|
|
1120
|
+
let status = L_UNDEF;
|
|
927
1121
|
try {
|
|
928
|
-
|
|
1122
|
+
status = datalog.relQuery(relation);
|
|
929
1123
|
} catch (error) {
|
|
930
1124
|
if (!(error instanceof SmtTacticError)) throw error;
|
|
931
1125
|
print(`(error "query failed: ${error.message}")`);
|
|
932
|
-
print("unknown");
|
|
933
1126
|
} finally {
|
|
934
1127
|
state.manager.limit.pop();
|
|
935
1128
|
}
|
|
1129
|
+
print(status === L_UNDEF && datalog.isBounded ? "bounded" : getVerdict(status));
|
|
1130
|
+
datalog.isBounded = false;
|
|
936
1131
|
},
|
|
937
1132
|
],
|
|
938
1133
|
[
|
|
@@ -941,37 +1136,43 @@ export const runSmtlibScript = (
|
|
|
941
1136
|
const params = getCommandParams(list.items, CHECK_SAT_USING_PARAMETERS);
|
|
942
1137
|
if (list.items[1] === undefined)
|
|
943
1138
|
throw new SmtParseError("check-sat-using needs a tactic argument", list.end);
|
|
944
|
-
|
|
1139
|
+
expectClosed(list.items[1]);
|
|
1140
|
+
const builder = compileTactic(getTacticEnvironment(), list.items[1]);
|
|
945
1141
|
const tactic = builder.build(params);
|
|
1142
|
+
const goal = getCommandGoal(builder.isTrackingDependencies, list.end);
|
|
946
1143
|
clearCheck();
|
|
947
|
-
|
|
1144
|
+
const deadline = Date.now() + options.timeLimitMs;
|
|
1145
|
+
state.manager.limit.restart(deadline);
|
|
948
1146
|
state.manager.limit.push(settings.rlimit);
|
|
949
1147
|
try {
|
|
950
|
-
const checked = checkSatUsing(tactic,
|
|
1148
|
+
const checked = checkSatUsing(tactic, goal);
|
|
951
1149
|
setCheck(checked.status, {
|
|
1150
|
+
isFromTactic: true,
|
|
952
1151
|
model: checked.model,
|
|
953
1152
|
core:
|
|
954
1153
|
builder.isTrackingDependencies || !hasNames()
|
|
955
1154
|
? getDependencyValues(checked.core)
|
|
956
1155
|
: undefined,
|
|
957
|
-
reasonUnknown: checked.reasonUnknown,
|
|
1156
|
+
reasonUnknown: checked.reasonUnknown ?? getCancelMessage(deadline),
|
|
958
1157
|
});
|
|
959
1158
|
print(getVerdict(checked.status));
|
|
960
1159
|
} finally {
|
|
961
1160
|
state.manager.limit.pop();
|
|
962
1161
|
}
|
|
1162
|
+
validateCheck(list.end);
|
|
963
1163
|
},
|
|
964
1164
|
],
|
|
965
1165
|
[
|
|
966
1166
|
"check-sat-assuming",
|
|
967
1167
|
(list) => {
|
|
968
|
-
const literals = list.items[1];
|
|
969
|
-
if (literals
|
|
1168
|
+
const literals = list.items[1] ?? list.end;
|
|
1169
|
+
if (literals.kind !== "list")
|
|
970
1170
|
throw new SmtParseError(
|
|
971
|
-
|
|
972
|
-
literals
|
|
1171
|
+
`invalid check-sat-assuming command, '(', expected got ${literals.lastId}`,
|
|
1172
|
+
literals,
|
|
973
1173
|
);
|
|
974
|
-
checkSatAssuming(literals.items);
|
|
1174
|
+
checkSatAssuming(literals.items, literals.end, list.end);
|
|
1175
|
+
validateCheck(list.end);
|
|
975
1176
|
},
|
|
976
1177
|
],
|
|
977
1178
|
[
|
|
@@ -982,13 +1183,17 @@ export const runSmtlibScript = (
|
|
|
982
1183
|
if (terms === undefined)
|
|
983
1184
|
throw new SmtParseError("invalid command, argument(s) missing", list.end);
|
|
984
1185
|
if (terms.kind !== "list")
|
|
985
|
-
throw new SmtParseError(
|
|
1186
|
+
throw new SmtParseError(
|
|
1187
|
+
`invalid list of terms, '(' expected got ${terms.lastId}`,
|
|
1188
|
+
terms,
|
|
1189
|
+
);
|
|
986
1190
|
return terms.items.map((item) => state.reader.parseTerm(item));
|
|
987
1191
|
});
|
|
988
1192
|
if (list.items.length > 3)
|
|
989
1193
|
throw new SmtParseError("invalid command, too many arguments", list.items[3]);
|
|
990
1194
|
clearCheck();
|
|
991
|
-
|
|
1195
|
+
const deadline = Date.now() + options.timeLimitMs;
|
|
1196
|
+
manager.limit.restart(deadline);
|
|
992
1197
|
manager.limit.push(settings.rlimit);
|
|
993
1198
|
const names = state.names.filter((name) => name !== -1);
|
|
994
1199
|
try {
|
|
@@ -1002,7 +1207,11 @@ export const runSmtlibScript = (
|
|
|
1002
1207
|
assumptions,
|
|
1003
1208
|
vars,
|
|
1004
1209
|
);
|
|
1005
|
-
setCheck(found.result, {
|
|
1210
|
+
setCheck(found.result, {
|
|
1211
|
+
model: found.model,
|
|
1212
|
+
core: found.core,
|
|
1213
|
+
reasonUnknown: found.reasonUnknown,
|
|
1214
|
+
});
|
|
1006
1215
|
print(getVerdict(found.result));
|
|
1007
1216
|
print("");
|
|
1008
1217
|
for (const consequence of found.consequences.items) display(consequence);
|
|
@@ -1013,11 +1222,22 @@ export const runSmtlibScript = (
|
|
|
1013
1222
|
if (state.kernel === undefined)
|
|
1014
1223
|
for (const assertion of getNamedAssertions()) kernel.assertExpr(assertion);
|
|
1015
1224
|
const found = getConsequences(kernel, [...names, ...assumptions], vars);
|
|
1016
|
-
setCheck(found.result, {
|
|
1225
|
+
setCheck(found.result, {
|
|
1226
|
+
context: kernel.context,
|
|
1227
|
+
core: kernel.context.unsatCore,
|
|
1228
|
+
reasonUnknown: kernel.context.getLastFailureMessage(),
|
|
1229
|
+
});
|
|
1017
1230
|
print(getVerdict(found.result));
|
|
1018
1231
|
print("");
|
|
1019
1232
|
for (const consequence of found.consequences.items) display(consequence);
|
|
1020
1233
|
found.consequences.reset();
|
|
1234
|
+
} catch (error) {
|
|
1235
|
+
if (!(error instanceof SmtCanceledError || isStackOverflow(error))) throw error;
|
|
1236
|
+
const reasonUnknown = getCancelMessage(deadline);
|
|
1237
|
+
if (state.kernel !== undefined) state.kernel.context.reasonUnknown = reasonUnknown;
|
|
1238
|
+
setCheck(L_UNDEF, { reasonUnknown });
|
|
1239
|
+
print("unknown");
|
|
1240
|
+
print("");
|
|
1021
1241
|
} finally {
|
|
1022
1242
|
manager.limit.pop();
|
|
1023
1243
|
}
|
|
@@ -1065,35 +1285,43 @@ export const runSmtlibScript = (
|
|
|
1065
1285
|
state.reader.push();
|
|
1066
1286
|
state.isIncremental = true;
|
|
1067
1287
|
state.kernel?.push();
|
|
1068
|
-
|
|
1288
|
+
useSatSolver((solver) => solver.push());
|
|
1069
1289
|
}
|
|
1290
|
+
if (list.items[2] !== undefined)
|
|
1291
|
+
throw new SmtParseError("invalid push command, ')' expected", list.items[2]);
|
|
1070
1292
|
},
|
|
1071
1293
|
],
|
|
1072
1294
|
[
|
|
1073
1295
|
"pop",
|
|
1074
1296
|
(list) => {
|
|
1075
1297
|
const count = getScopeCount(list);
|
|
1298
|
+
const follower = list.items[2] ?? list.end;
|
|
1299
|
+
clearCheck();
|
|
1076
1300
|
if (count > state.scopes.length)
|
|
1077
1301
|
throw new SmtParseError(
|
|
1078
1302
|
"invalid pop command, argument is greater than the current stack depth",
|
|
1079
|
-
|
|
1303
|
+
follower,
|
|
1080
1304
|
);
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1305
|
+
if (count > 0) {
|
|
1306
|
+
state.isIncremental = true;
|
|
1307
|
+
const scope = state.scopes[state.scopes.length - count];
|
|
1308
|
+
state.kernel?.pop(count);
|
|
1309
|
+
useSatSolver((solver) => solver.pop(count));
|
|
1310
|
+
state.reader.pop(count);
|
|
1311
|
+
restoreAssertions(scope.assertions);
|
|
1312
|
+
resetOptimizer();
|
|
1313
|
+
releaseObjectives(scope.objectives, scope.softTrail);
|
|
1314
|
+
state.scopes.length -= count;
|
|
1315
|
+
}
|
|
1316
|
+
if (follower !== list.end)
|
|
1317
|
+
throw new SmtParseError("invalid pop command, ')' expected", follower);
|
|
1092
1318
|
},
|
|
1093
1319
|
],
|
|
1094
1320
|
[
|
|
1095
1321
|
"reset",
|
|
1096
|
-
() => {
|
|
1322
|
+
(list) => {
|
|
1323
|
+
if (list.items[1] !== undefined)
|
|
1324
|
+
throw new SmtParseError("invalid reset command, ')' expected", list.items[1]);
|
|
1097
1325
|
clearCheck();
|
|
1098
1326
|
resetOptimizer();
|
|
1099
1327
|
state = createState();
|
|
@@ -1101,8 +1329,8 @@ export const runSmtlibScript = (
|
|
|
1101
1329
|
],
|
|
1102
1330
|
[
|
|
1103
1331
|
"reset-assertions",
|
|
1104
|
-
() => {
|
|
1105
|
-
|
|
1332
|
+
(list) => {
|
|
1333
|
+
checkArgumentCount(list, 0);
|
|
1106
1334
|
restoreAssertions(0);
|
|
1107
1335
|
resetOptimizer();
|
|
1108
1336
|
releaseObjectives(0, 0);
|
|
@@ -1124,7 +1352,17 @@ export const runSmtlibScript = (
|
|
|
1124
1352
|
manager,
|
|
1125
1353
|
getRewriterOptions(manager, getSimplifyParams(list.items.slice(2))),
|
|
1126
1354
|
);
|
|
1127
|
-
|
|
1355
|
+
// simplify_cmd prints a failure of the rewriter and then the term as it was.
|
|
1356
|
+
const simplified = (() => {
|
|
1357
|
+
try {
|
|
1358
|
+
return rewriter.rewrite(term);
|
|
1359
|
+
} catch (error) {
|
|
1360
|
+
if (!(error instanceof SmtDefaultError)) throw error;
|
|
1361
|
+
print(`(error "simplifier failed: ${error.message}")`);
|
|
1362
|
+
manager.incRef(term);
|
|
1363
|
+
return term;
|
|
1364
|
+
}
|
|
1365
|
+
})();
|
|
1128
1366
|
rewriter.cleanup();
|
|
1129
1367
|
display(simplified);
|
|
1130
1368
|
rewriter.release();
|
|
@@ -1143,8 +1381,7 @@ export const runSmtlibScript = (
|
|
|
1143
1381
|
manager.incRef(term);
|
|
1144
1382
|
const visited = new Set<number>();
|
|
1145
1383
|
const todo = [term];
|
|
1146
|
-
|
|
1147
|
-
const expr = todo.pop() as number;
|
|
1384
|
+
for (let expr = todo.pop(); expr !== undefined; expr = todo.pop()) {
|
|
1148
1385
|
if (visited.has(expr)) continue;
|
|
1149
1386
|
visited.add(expr);
|
|
1150
1387
|
const family = manager.kinds[expr] === KIND_APP ? manager.getFamily(expr) : -1;
|
|
@@ -1168,13 +1405,18 @@ export const runSmtlibScript = (
|
|
|
1168
1405
|
const params = getCommandParams(list.items, APPLY_PARAMETERS);
|
|
1169
1406
|
if (list.items[1] === undefined)
|
|
1170
1407
|
throw new SmtParseError("apply needs a tactic argument", list.end);
|
|
1171
|
-
|
|
1408
|
+
expectClosed(list.items[1]);
|
|
1409
|
+
// apply_tactic_cmd, unlike check-sat-using, gives the tactic no logic.
|
|
1410
|
+
const builder = compileTactic(
|
|
1411
|
+
{ ...getTacticEnvironment(), setup: { ...getSetup(), logic: undefined } },
|
|
1412
|
+
list.items[1],
|
|
1413
|
+
);
|
|
1172
1414
|
const tactic = builder.build(params);
|
|
1415
|
+
const input = getCommandGoal(builder.isTrackingDependencies, list.end);
|
|
1173
1416
|
const isPrintingDependencies = params.get("print_dependencies") === true;
|
|
1174
1417
|
if (isPrintingDependencies && !builder.isTrackingDependencies && hasNames())
|
|
1175
1418
|
throw new SmtUnsupportedError("the dependencies of a tactic that drops dependencies");
|
|
1176
1419
|
state.manager.limit.restart(Date.now() + options.timeLimitMs);
|
|
1177
|
-
const input = getGoal(builder.isTrackingDependencies);
|
|
1178
1420
|
const goals = (() => {
|
|
1179
1421
|
try {
|
|
1180
1422
|
return applyTactic(tactic, input);
|
|
@@ -1239,8 +1481,7 @@ export const runSmtlibScript = (
|
|
|
1239
1481
|
const decls = new Set<number>();
|
|
1240
1482
|
for (const assertion of assertions) {
|
|
1241
1483
|
const todo = [assertion];
|
|
1242
|
-
|
|
1243
|
-
const expr = todo.pop() as number;
|
|
1484
|
+
for (let expr = todo.pop(); expr !== undefined; expr = todo.pop()) {
|
|
1244
1485
|
if (visited.has(expr)) continue;
|
|
1245
1486
|
visited.add(expr);
|
|
1246
1487
|
if (manager.kinds[expr] === KIND_QUANTIFIER) {
|
|
@@ -1281,6 +1522,7 @@ export const runSmtlibScript = (
|
|
|
1281
1522
|
[
|
|
1282
1523
|
"get-assertions",
|
|
1283
1524
|
(list) => {
|
|
1525
|
+
checkArgumentCount(list, 0);
|
|
1284
1526
|
if (!settings.isInteractive)
|
|
1285
1527
|
throw new SmtParseError(
|
|
1286
1528
|
"command is only available in interactive mode, use command (set-option :interactive-mode true)",
|
|
@@ -1292,6 +1534,7 @@ export const runSmtlibScript = (
|
|
|
1292
1534
|
[
|
|
1293
1535
|
"get-unsat-core",
|
|
1294
1536
|
(list) => {
|
|
1537
|
+
checkArgumentCount(list, 0);
|
|
1295
1538
|
if (!settings.isProducingUnsatCores)
|
|
1296
1539
|
throw new SmtParseError(
|
|
1297
1540
|
"unsat core construction is not enabled, use command (set-option :produce-unsat-cores true)",
|
|
@@ -1302,7 +1545,27 @@ export const runSmtlibScript = (
|
|
|
1302
1545
|
throw new SmtParseError("unsat core is not available", list.end);
|
|
1303
1546
|
if (check.core === undefined)
|
|
1304
1547
|
throw new SmtUnsupportedError("the unsat core of a tactic that drops dependencies");
|
|
1305
|
-
|
|
1548
|
+
const kernel = state.kernel;
|
|
1549
|
+
if (
|
|
1550
|
+
kernel === undefined ||
|
|
1551
|
+
check.context !== kernel.context ||
|
|
1552
|
+
settings.parameters.get("smt.core.minimize") !== "true"
|
|
1553
|
+
) {
|
|
1554
|
+
print(`(${check.core.map(format).join(" ")})`);
|
|
1555
|
+
return;
|
|
1556
|
+
}
|
|
1557
|
+
const mus = new Mus(state.manager, {
|
|
1558
|
+
checkSat: (assumptions) => kernel.check(assumptions),
|
|
1559
|
+
getUnsatCore: () => kernel.context.unsatCore,
|
|
1560
|
+
});
|
|
1561
|
+
const core = [...kernel.context.unsatCore];
|
|
1562
|
+
for (const literal of core) mus.addSoft(literal);
|
|
1563
|
+
const minimized = new RefVector(state.manager);
|
|
1564
|
+
state.manager.limit.restart(Date.now() + options.timeLimitMs);
|
|
1565
|
+
const status = mus.getMus(minimized);
|
|
1566
|
+
print(`(${(status === L_TRUE ? minimized.items : core).map(format).join(" ")})`);
|
|
1567
|
+
minimized.reset();
|
|
1568
|
+
mus.reset();
|
|
1306
1569
|
},
|
|
1307
1570
|
],
|
|
1308
1571
|
[
|
|
@@ -1310,7 +1573,10 @@ export const runSmtlibScript = (
|
|
|
1310
1573
|
(list) => {
|
|
1311
1574
|
const target = list.items[1];
|
|
1312
1575
|
const term = target === undefined ? -1 : state.reader.parseTerm(target);
|
|
1313
|
-
|
|
1576
|
+
const parameter = list.items[2];
|
|
1577
|
+
if (parameter !== undefined && parameter.kind !== "keyword")
|
|
1578
|
+
throw new SmtParseError("invalid command argument, keyword expected", parameter);
|
|
1579
|
+
if (parameter !== undefined) throw new SmtUnsupportedError("the parameters of eval");
|
|
1314
1580
|
const model = getModel(list);
|
|
1315
1581
|
if (term === -1) throw new SmtParseError("no arguments passed to eval", list.end);
|
|
1316
1582
|
const manager = state.manager;
|
|
@@ -1324,30 +1590,40 @@ export const runSmtlibScript = (
|
|
|
1324
1590
|
[
|
|
1325
1591
|
"get-value",
|
|
1326
1592
|
(list) => {
|
|
1327
|
-
const terms = list.items[1];
|
|
1328
|
-
if (terms
|
|
1329
|
-
throw new SmtParseError(
|
|
1593
|
+
const terms = list.items[1] ?? list.end;
|
|
1594
|
+
if (terms.kind !== "list")
|
|
1595
|
+
throw new SmtParseError(
|
|
1596
|
+
`invalid get-value command, '(' expected got ${terms.lastId}`,
|
|
1597
|
+
terms,
|
|
1598
|
+
);
|
|
1330
1599
|
const manager = state.manager;
|
|
1331
1600
|
const exprs = terms.items.map((item) => state.reader.parseTerm(item));
|
|
1332
1601
|
if (exprs.length === 0)
|
|
1333
1602
|
throw new SmtParseError("invalid get-value command, empty list of terms", terms.end);
|
|
1334
|
-
|
|
1603
|
+
const extra = list.items[2];
|
|
1604
|
+
if (
|
|
1605
|
+
extra?.kind === "keyword" &&
|
|
1606
|
+
(extra.text === ":model-index" || extra.text === ":model_index")
|
|
1607
|
+
)
|
|
1608
|
+
throw new SmtUnsupportedError("the model index of get-value");
|
|
1609
|
+
if (extra !== undefined)
|
|
1610
|
+
throw new SmtParseError("invalid get-value command, ')' expected", extra);
|
|
1335
1611
|
const model = getModel(list);
|
|
1612
|
+
pendingText += "(";
|
|
1336
1613
|
model.compact();
|
|
1337
1614
|
// Z3 prints each term as the script spells it, from the end of the term before.
|
|
1338
1615
|
const offsets = [
|
|
1339
1616
|
terms.offset + 1,
|
|
1340
1617
|
...terms.items.map((item) => (item.kind === "list" ? item.end : item).endOffset),
|
|
1341
1618
|
];
|
|
1342
|
-
|
|
1619
|
+
exprs.forEach((expr, index) => {
|
|
1343
1620
|
manager.incRef(expr);
|
|
1344
1621
|
const value = model.eval(expr, true);
|
|
1345
|
-
|
|
1622
|
+
pendingText += `${index > 0 ? "\n " : ""}(${text.slice(offsets[index], offsets[index + 1]).trim()} ${format(value)})`;
|
|
1346
1623
|
manager.decRef(value);
|
|
1347
1624
|
manager.decRef(expr);
|
|
1348
|
-
return line;
|
|
1349
1625
|
});
|
|
1350
|
-
print(
|
|
1626
|
+
print(")");
|
|
1351
1627
|
},
|
|
1352
1628
|
],
|
|
1353
1629
|
[
|
|
@@ -1362,14 +1638,27 @@ export const runSmtlibScript = (
|
|
|
1362
1638
|
[
|
|
1363
1639
|
"get-model",
|
|
1364
1640
|
(list) => {
|
|
1365
|
-
|
|
1641
|
+
for (const index of list.items.slice(1)) {
|
|
1642
|
+
if (index.kind !== "numeral")
|
|
1643
|
+
throw new SmtParseError("invalid command argument, unsigned integer expected", index);
|
|
1644
|
+
if (!isUnsigned(index.text))
|
|
1645
|
+
throw new SmtParseError(
|
|
1646
|
+
"invalid indexed identifier, index is too big to fit in an unsigned machine integer",
|
|
1647
|
+
index,
|
|
1648
|
+
);
|
|
1649
|
+
}
|
|
1366
1650
|
const manager = state.manager;
|
|
1367
1651
|
const model = getModel(list);
|
|
1652
|
+
const last = list.items[list.items.length - 1];
|
|
1653
|
+
// get_model_cmd takes any number of indices and keeps the last.
|
|
1654
|
+
if (last.kind === "numeral" && BigInt(last.text) > 0n)
|
|
1655
|
+
throw new SmtUnsupportedError("the index of get-model");
|
|
1368
1656
|
model.compact();
|
|
1369
1657
|
for (const decl of state.reader.getDeclaredFuncs()) {
|
|
1370
1658
|
const funcDecl = manager.funcDecls[decl];
|
|
1371
1659
|
if (
|
|
1372
1660
|
funcDecl.family !== FAMILY_USER ||
|
|
1661
|
+
manager.macros.has(decl) ||
|
|
1373
1662
|
model.constInterps.has(decl) ||
|
|
1374
1663
|
model.funcInterps.has(decl)
|
|
1375
1664
|
)
|
|
@@ -1387,7 +1676,13 @@ export const runSmtlibScript = (
|
|
|
1387
1676
|
print(`(\n${printModel(manager, getPrintEnvironment(), model, 2)})`);
|
|
1388
1677
|
},
|
|
1389
1678
|
],
|
|
1390
|
-
[
|
|
1679
|
+
[
|
|
1680
|
+
"display",
|
|
1681
|
+
(list) => {
|
|
1682
|
+
display(state.reader.parseTerm(getFirstArgument(list)));
|
|
1683
|
+
checkArgumentCount(list, 1);
|
|
1684
|
+
},
|
|
1685
|
+
],
|
|
1391
1686
|
[
|
|
1392
1687
|
"dbg-lt",
|
|
1393
1688
|
(list) => {
|
|
@@ -1436,10 +1731,11 @@ export const runSmtlibScript = (
|
|
|
1436
1731
|
[
|
|
1437
1732
|
"echo",
|
|
1438
1733
|
(list) => {
|
|
1439
|
-
const message = list
|
|
1440
|
-
if (message
|
|
1441
|
-
throw new SmtParseError("invalid
|
|
1734
|
+
const message = getFirstArgument(list);
|
|
1735
|
+
if (message.kind !== "string")
|
|
1736
|
+
throw new SmtParseError("invalid command argument, string expected", message);
|
|
1442
1737
|
print(message.text);
|
|
1738
|
+
checkArgumentCount(list, 1);
|
|
1443
1739
|
},
|
|
1444
1740
|
],
|
|
1445
1741
|
[
|
|
@@ -1453,7 +1749,14 @@ export const runSmtlibScript = (
|
|
|
1453
1749
|
if (keyword === ":produce-models") settings.isProducingModels = isTrue;
|
|
1454
1750
|
if (keyword === ":produce-unsat-cores") settings.isProducingUnsatCores = isTrue;
|
|
1455
1751
|
if (keyword === ":produce-proofs") settings.isProducingProofs = isTrue;
|
|
1456
|
-
if (keyword === ":interactive-mode"
|
|
1752
|
+
if (keyword === ":interactive-mode" || keyword === ":produce-assertions") {
|
|
1753
|
+
if (state.isProofsEnabled !== undefined)
|
|
1754
|
+
throw new SmtParseError(
|
|
1755
|
+
"error setting ':produce-assertions', option value cannot be modified after initialization",
|
|
1756
|
+
value ?? list.end,
|
|
1757
|
+
);
|
|
1758
|
+
settings.isInteractive = isTrue;
|
|
1759
|
+
}
|
|
1457
1760
|
if (keyword === ":diagnostic-output-channel")
|
|
1458
1761
|
settings.isDiagnosticOnStdout = value?.kind === "string" && value.text === "stdout";
|
|
1459
1762
|
if (keyword === ":int-real-coercions" && !isTrue)
|
|
@@ -1466,13 +1769,12 @@ export const runSmtlibScript = (
|
|
|
1466
1769
|
);
|
|
1467
1770
|
settings.isExitingOnError = isSymbol(value, "immediate-exit");
|
|
1468
1771
|
}
|
|
1469
|
-
|
|
1772
|
+
const isParameter =
|
|
1470
1773
|
keyword !== "" &&
|
|
1471
1774
|
!BUILTIN_OPTIONS.has(keyword) &&
|
|
1472
1775
|
value !== undefined &&
|
|
1473
|
-
value.kind !== "list"
|
|
1474
|
-
)
|
|
1475
|
-
settings.parameters.set(getParameterName(keyword), value.text);
|
|
1776
|
+
value.kind !== "list";
|
|
1777
|
+
if (isParameter) settings.parameters.set(getParameterName(keyword), value.text);
|
|
1476
1778
|
if (optionName === ":print_success") settings.isPrintingSuccess = isTrue;
|
|
1477
1779
|
if (
|
|
1478
1780
|
!BUILTIN_OPTIONS.has(keyword) &&
|
|
@@ -1485,6 +1787,9 @@ export const runSmtlibScript = (
|
|
|
1485
1787
|
settings.mbqiMaxIterations = Number(value.text);
|
|
1486
1788
|
if (optionName === ":rlimit" && value?.kind === "numeral")
|
|
1487
1789
|
settings.rlimit = Number(value.text);
|
|
1790
|
+
const kernel = state.kernel;
|
|
1791
|
+
if (isParameter && kernel !== undefined)
|
|
1792
|
+
kernel.updateParams(getKernelParams(kernel.isSetUp));
|
|
1488
1793
|
if (optionName === ":rewriter.hi_div0") {
|
|
1489
1794
|
settings.isHiDiv0 = isTrue;
|
|
1490
1795
|
state.manager.isHiDiv0 = isTrue;
|
|
@@ -1519,6 +1824,8 @@ export const runSmtlibScript = (
|
|
|
1519
1824
|
[":print-success", settings.isPrintingSuccess],
|
|
1520
1825
|
[":produce-models", settings.isProducingModels],
|
|
1521
1826
|
[":produce-unsat-cores", settings.isProducingUnsatCores],
|
|
1827
|
+
[":interactive-mode", settings.isInteractive],
|
|
1828
|
+
[":produce-assertions", settings.isInteractive],
|
|
1522
1829
|
[":int-real-coercions", true],
|
|
1523
1830
|
[":error-behavior", settings.isExitingOnError ? "immediate-exit" : "continued-execution"],
|
|
1524
1831
|
]);
|
|
@@ -1538,17 +1845,7 @@ export const runSmtlibScript = (
|
|
|
1538
1845
|
const info = list.items[1];
|
|
1539
1846
|
if (info?.kind !== "keyword")
|
|
1540
1847
|
throw new SmtParseError("invalid command argument, keyword expected", info ?? list.end);
|
|
1541
|
-
const optimizer = state.optimizer;
|
|
1542
1848
|
const check = state.check;
|
|
1543
|
-
if (
|
|
1544
|
-
info.text === ":reason-unknown" &&
|
|
1545
|
-
check?.status === L_UNDEF &&
|
|
1546
|
-
optimizer !== undefined &&
|
|
1547
|
-
optimizer.reasonUnknown !== ""
|
|
1548
|
-
) {
|
|
1549
|
-
print(`(:reason-unknown "${optimizer.reasonUnknown}")`);
|
|
1550
|
-
return;
|
|
1551
|
-
}
|
|
1552
1849
|
const reasonUnknown =
|
|
1553
1850
|
check === undefined
|
|
1554
1851
|
? "state of the most recent check-sat command is not known"
|
|
@@ -1571,9 +1868,9 @@ export const runSmtlibScript = (
|
|
|
1571
1868
|
[
|
|
1572
1869
|
"set-logic",
|
|
1573
1870
|
(list) => {
|
|
1574
|
-
const logic = list
|
|
1871
|
+
const logic = getFirstArgument(list);
|
|
1575
1872
|
if (!isSymbol(logic))
|
|
1576
|
-
throw new SmtParseError("invalid
|
|
1873
|
+
throw new SmtParseError("invalid command argument, symbol expected", logic);
|
|
1577
1874
|
if (state.logic !== undefined)
|
|
1578
1875
|
throw new SmtParseError("the logic has already been set", logic);
|
|
1579
1876
|
if (state.assertions.length > 0)
|
|
@@ -1583,6 +1880,7 @@ export const runSmtlibScript = (
|
|
|
1583
1880
|
printDiagnostic(
|
|
1584
1881
|
`; ignoring unsupported logic ${logic.text} line: ${list.line} position: ${list.column}`,
|
|
1585
1882
|
);
|
|
1883
|
+
checkArgumentCount(list, 1);
|
|
1586
1884
|
return;
|
|
1587
1885
|
}
|
|
1588
1886
|
state.logic = logic.text;
|
|
@@ -1590,14 +1888,37 @@ export const runSmtlibScript = (
|
|
|
1590
1888
|
state.reader = createSmtlibReader(state.manager, logic.text, settings.parserOptions);
|
|
1591
1889
|
else {
|
|
1592
1890
|
state.reader.restrictSorts(logic.text);
|
|
1593
|
-
// Deviation from Z3: its new solver starts without the open scopes, so it ignores their pop
|
|
1594
|
-
// and keeps what they asserted.
|
|
1891
|
+
// Deviation from Z3: its new solver starts without the open scopes, so it ignores their pop and keeps what they asserted.
|
|
1595
1892
|
resetKernel();
|
|
1596
1893
|
}
|
|
1597
1894
|
if (settings.isPrintingSuccess) print("success");
|
|
1895
|
+
checkArgumentCount(list, 1);
|
|
1896
|
+
},
|
|
1897
|
+
],
|
|
1898
|
+
[
|
|
1899
|
+
"set-info",
|
|
1900
|
+
(list) => {
|
|
1901
|
+
const info = list.items[1];
|
|
1902
|
+
if (info === undefined)
|
|
1903
|
+
throw new SmtParseError("invalid command, argument(s) missing", list.end);
|
|
1904
|
+
if (info.kind !== "keyword")
|
|
1905
|
+
throw new SmtParseError("invalid command argument, keyword expected", info);
|
|
1906
|
+
const value = list.items[2];
|
|
1907
|
+
if (value === undefined)
|
|
1908
|
+
throw new SmtParseError("invalid command, argument(s) missing", list.end);
|
|
1909
|
+
if (value.kind === "list" || value.kind === "keyword" || value.kind === "eof")
|
|
1910
|
+
throw new SmtParseError("invalid option value", value);
|
|
1911
|
+
if (info.text === ":status" && value.kind === "symbol") {
|
|
1912
|
+
const status = [L_TRUE, L_FALSE, L_UNDEF].find(
|
|
1913
|
+
(innerStatus) => getVerdict(innerStatus) === value.text,
|
|
1914
|
+
);
|
|
1915
|
+
if (status === undefined) throw new SmtParseError("invalid ':status' attribute", value);
|
|
1916
|
+
settings.status = status;
|
|
1917
|
+
}
|
|
1918
|
+
if (list.items[3] !== undefined)
|
|
1919
|
+
throw new SmtParseError("invalid command, too many arguments", list.items[3]);
|
|
1598
1920
|
},
|
|
1599
1921
|
],
|
|
1600
|
-
["set-info", () => {}],
|
|
1601
1922
|
]);
|
|
1602
1923
|
const run = (list: SmtList) => {
|
|
1603
1924
|
const head = list.items[0];
|
|
@@ -1606,18 +1927,39 @@ export const runSmtlibScript = (
|
|
|
1606
1927
|
const command = DECLARATIONS.has(head.text)
|
|
1607
1928
|
? (declaration: SmtList) => state.reader.declareCommand(declaration)
|
|
1608
1929
|
: runCommand.get(head.text);
|
|
1609
|
-
if (command === undefined
|
|
1930
|
+
if (command === undefined && UNPORTED_COMMANDS.has(head.text))
|
|
1931
|
+
throw new SmtUnsupportedError(`the command ${head.text}`);
|
|
1932
|
+
if (command === undefined) {
|
|
1933
|
+
expectClosed(list);
|
|
1934
|
+
print("unsupported");
|
|
1935
|
+
printDiagnostic(`; ${head.text} line: ${list.end.line} position: ${list.end.column}`);
|
|
1936
|
+
return;
|
|
1937
|
+
}
|
|
1938
|
+
// Z3's scoped_timer ends with the command that set it, so a command starts without one.
|
|
1939
|
+
state.manager.limit.restart(Infinity);
|
|
1610
1940
|
if (!MANAGERLESS_COMMANDS.has(head.text) && state.isProofsEnabled === undefined) {
|
|
1611
1941
|
state.isProofsEnabled = settings.parameters.get("proof") === "true";
|
|
1942
|
+
if (state.logic === undefined || logicHasSeq(state.logic)) state.manager.initSeqPlugin();
|
|
1943
|
+
if (state.logic === undefined) state.reader.registerList();
|
|
1612
1944
|
resetKernel();
|
|
1613
1945
|
}
|
|
1614
|
-
|
|
1946
|
+
try {
|
|
1947
|
+
command(list);
|
|
1948
|
+
} catch (error) {
|
|
1949
|
+
if (!(error instanceof SmtDefaultError)) throw error;
|
|
1950
|
+
throw new SmtParseError(error.message, list.end);
|
|
1951
|
+
}
|
|
1615
1952
|
if (settings.isPrintingSuccess && SILENT_COMMANDS.has(head.text)) print("success");
|
|
1616
1953
|
};
|
|
1617
1954
|
for (;;) {
|
|
1618
1955
|
try {
|
|
1619
|
-
const list = commands.
|
|
1620
|
-
if (list === undefined
|
|
1956
|
+
const list = commands.readCommand();
|
|
1957
|
+
if (list === undefined) break;
|
|
1958
|
+
if (isSymbol(list.items[0], "exit")) {
|
|
1959
|
+
checkArgumentCount(list, 0);
|
|
1960
|
+
if (settings.isPrintingSuccess) print("success");
|
|
1961
|
+
break;
|
|
1962
|
+
}
|
|
1621
1963
|
run(list);
|
|
1622
1964
|
} catch (error) {
|
|
1623
1965
|
if (!(error instanceof SmtParseError)) throw error;
|